Commit 4b1c599e by Yu_Tung

version_1.0.1

parent f8c10c4f
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -9,7 +9,7 @@ android {
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionName "1.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
......@@ -27,8 +27,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.main.MainActivity"
android:screenOrientation="portrait"/>
<activity android:name=".ui.main.MainActivity" />
<provider
android:name="androidx.core.content.FileProvider"
......
......@@ -11,9 +11,9 @@ import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.example.audiovisualrecord.ui.main.MainActivity;
import com.example.audiovisualrecord.R;
import com.example.audiovisualrecord.base.BaseActivity;
import com.example.audiovisualrecord.ui.main.MainActivity;
public class LoginActivity extends BaseActivity implements LoginContract.View, View.OnClickListener {
EditText editAccount, editPassword;
......
......@@ -5,6 +5,8 @@ import androidx.annotation.RequiresApi;
import androidx.core.content.FileProvider;
import androidx.core.os.EnvironmentCompat;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
......@@ -15,11 +17,13 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.audiovisualrecord.FileUtil;
import com.example.audiovisualrecord.MagicFileChooser;
......@@ -37,6 +41,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
......@@ -65,20 +70,33 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
private static final int PICK_FILE_REQUEST_CODE = 500;
private Button btnCapturePicture, btnRecordVideo, btnGetImageFromGallery, btnGetVideoFromGallery, btnDeviceEdit, btnCentralCloud, btnChoseDevice, btnBasicInformation;
private File photoFile;
private String pathCompany = "";
private String pathFactoryArea= "";
private String pathFactoryClass= "";
private String pathClass= "";
private String pathFactoryArea = "";
private String pathFactoryClass = "";
private String pathClass = "";
private String pathShootType = "";
private String uploadPath = "";
/**
* 用于保存拍照图片的uri
*/
private Uri mCameraUri;
/**
* 用于保存图片的文件路径,Android 10以下使用图片路径访问图片
*/
private String mCameraImagePath;
/**
* 是否是Android 10以上手机
*/
private boolean isAndroidQ = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
Bundle bag;
String token, imageFilePath;
int countFile = 0;
private TextView tvCompany, tvFactory, tvClass, tvUnit, tvShootType;
private TextView textCompany, textFactory, textClass, textUnit, textShootType;
private MainPresenter mPresenter;
......@@ -89,8 +107,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
private List<String> filepath = new ArrayList<>();
private List<String> filename = new ArrayList<>();
String sidData ="";
String sidData = "";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
......@@ -104,18 +121,18 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
mMainData = new MainData();
mChooseDeviceItemData = new ChooseDeviceItemData();
createSegVideoFolder();
createSegVideoFolder();
}
private void createSegVideoFolder() {
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator +"Seg_Video");
File.separator + "Seg_Video");
boolean success = true;
if (!folder.exists()) {
success = folder.mkdirs();
}else {
Log.e("wer","folder exists");
} else {
Log.e("wer", "folder exists");
}
}
......@@ -172,47 +189,109 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
}
private Uri createImageUri() {
String status = Environment.getExternalStorageState();
// 判断是否有SD卡,优先使用SD卡存储,当没有SD卡时使用手机存储
if (status.equals(Environment.MEDIA_MOUNTED)) {
return getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
} else {
return getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, new ContentValues());
}
}
private void openCameraIntent() {
Intent pictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
settingSystemCamera(pictureIntent);
if (pictureIntent.resolveActivity(getPackageManager()) != null) {
//Create a file to store the image
photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
File photoFile = null;
Uri photoUri = null;
if (isAndroidQ) {
photoUri = createImageUri();
} else {
try {
photoFile = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
}
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this, "com.example.audiovisualrecord.provider", photoFile);
// Uri photoURI = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", photoFile);
// pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
// photoURI);
// startActivityForResult(pictureIntent,
// REQUEST_CAPTURE_IMAGE);
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
pictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(pictureIntent, REQUEST_CAPTURE_IMAGE);
}
mCameraImagePath = photoFile.getAbsolutePath();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
photoUri = FileProvider.getUriForFile(this, "com.example.audiovisualrecord.provider", photoFile);
} else {
photoUri = Uri.fromFile(photoFile);
}
mCameraUri = photoUri;
if (photoUri != null) {
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
pictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(pictureIntent, REQUEST_CAPTURE_IMAGE);
}
}
}
}
/**
* 保存位图到本地
*
* @param bitmap
* @param path 本地路径
* @return void
*/
public void SavaImage(Bitmap bitmap, String path) {
File file = new File(path);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
intent.setData(uri);
this.sendBroadcast(intent);
FileOutputStream fileOutputStream = null;
String filePhth;
String fileName;
//文件夹不存在,则创建它
if (!file.exists()) {
file.mkdir();
}
try {
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH_mm_ss");
String formattedDate = df.format(c);
filePhth = path + "/" + formattedDate + ".png";
fileName = System.currentTimeMillis() + "";
Log.e("filepath", filePhth);
File file1 = new File(filePhth);
fileOutputStream = new FileOutputStream(file1.getPath());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.close();
//图片路径
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
// filePhth,fileName , null);
MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "", "");
this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file1.getAbsolutePath())));
Log.d("aaa", file1.getAbsolutePath() + "-----" + path);
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
} catch (Exception e) {
// ToastUtil.showToast("保存失败");
Log.e("error", e.getMessage());
e.printStackTrace();
}
}
private void openRecordVideoIntent() {
String timeStamp =
new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
PackageManager packageManager = this.getPackageManager();
List<ResolveInfo> listCam = packageManager.queryIntentActivities(takeVideoIntent, 0);
takeVideoIntent.setPackage(listCam.get(0).activityInfo.packageName);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Environment.getExternalStorageDirectory().getPath()+timeStamp+".mp4");
// takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 10996480L); //限制影片大小
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
......@@ -220,21 +299,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
}
private File createImageFile() throws IOException {
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH:mm");
String formattedDate = df.format(c);
// String imageFileName =formattedDate;
String imageName =new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
Log.e("time",imageName);
String imageName = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Log.e("storageDir",getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString());
// File image = File.createTempFile(
// imageFileName, /* prefix */
// ".jpg", /* suffix */
// storageDir /* directory */
// );
// imageFilePath = image.getAbsolutePath();
// return image;
if (!storageDir.exists()) {
storageDir.mkdir();
}
......@@ -242,8 +308,6 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
if (!Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(tempFile))) {
return null;
}
imageFilePath = tempFile .getAbsolutePath();
return tempFile;
}
......@@ -258,39 +322,28 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH:mm:ss");
String formattedDate = df.format(c);
if (requestCode == REQUEST_CAPTURE_IMAGE && resultCode == RESULT_OK) {
File imgFile = new File(imageFilePath);
Log.e("imagePath", imageFilePath);
//照片的檔案
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
try {
FileOutputStream out = new FileOutputStream(imgFile);
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
Bitmap myBitmap = BitmapFactory.decodeFile(mCameraImagePath);
String path1 = Environment.getExternalStorageDirectory().toString() + "/Pictures";
SavaImage(myBitmap, path1);
MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, "", "");
// Log.e("fileName", imgFile.getName());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(imageFilePath))));
// Log.e("picture", Environment.getExternalStorageDirectory().getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
//影片的uri
Uri videoUri = data.getData();
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH_mm_ss");
String formattedDate = df.format(c);
try {
DocumentsContract.renameDocument(getContentResolver(), videoUri, formattedDate + ".mp4");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
if (requestCode == PICK_IMAGE_FROM_GALLERY_REQUEST_CODE && resultCode == RESULT_OK) {
......@@ -305,7 +358,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
uriList.add(getPath(data.getData()));
}
//照片的uri
mPresenter.onGetSid(uriList,getResourceString(R.string.on_upload_image));
mPresenter.onGetSid(uriList, getResourceString(R.string.on_upload_image));
}
if (requestCode == PICK_VIDEO_FROM_GALLERY_REQUEST_CODE && resultCode == RESULT_OK) {
......@@ -373,20 +426,20 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCaptureImage:
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea,pathFactoryClass,pathClass,pathShootType);
if ("".equals(uploadPath)){
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
if ("".equals(uploadPath)) {
showDialogCaveatMessage("請選擇路徑");
}else {
} else {
openCameraIntent();
}
break;
case R.id.btnGetImageFromGallery:
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea,pathFactoryClass,pathClass,pathShootType);
if ("".equals(uploadPath)){
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
if ("".equals(uploadPath)) {
showDialogCaveatMessage("請選擇路徑");
}else {
} else {
pickImageFromGallery();
}
......@@ -394,20 +447,20 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
break;
case R.id.btnGetVideoFromGallery:
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea,pathFactoryClass,pathClass,pathShootType);
if ("".equals(uploadPath)){
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
if ("".equals(uploadPath)) {
showDialogCaveatMessage("請選擇路徑");
}else {
} else {
pickVideoFromGallery();
}
break;
case R.id.btnRecordVideo:
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea,pathFactoryClass,pathClass,pathShootType);
if ("".equals(uploadPath)){
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
if ("".equals(uploadPath)) {
showDialogCaveatMessage("請選擇路徑");
}else {
} else {
openRecordVideoIntent();
}
......@@ -514,17 +567,13 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
//如果能改成用retrofit加rxjava最好,已經嘗試過,可能有缺什麼,不過緊急所以先求功能
@Override
public void onUploadFile(final ArrayList<String> uriList, String type, final String sid) {
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea,pathFactoryClass,pathClass,pathShootType);
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
dismissProgressDialog();
showProgressDialog(type);
new Thread(new Runnable() {
@Override
public void run() {
String path1 = uploadPath;
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH_mm_ss");
String formattedDate = df.format(c);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(60, TimeUnit.SECONDS)
......@@ -535,23 +584,18 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
MultipartBody.Builder buildernew = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("_sid", sid)
.addFormDataPart("path",path1);
Log.e("file5555555", uriList.size() + "");
File uploadFile1 = new File(uriList.get(0));
Log.e("file555eer5555", uploadFile1.length() + "");
.addFormDataPart("path", path1);
for (String path : uriList) {
File uploadFile = new File(path);
Log.e("file5555555", uploadFile.getName());
Log.e("file5555555", uploadFile.length() / 1024 / 1024 + "mb");
buildernew.addFormDataPart("file", uploadFile.getName(),
RequestBody.create(MediaType.parse("application/octet-stream"), uploadFile));
}
RequestBody body = buildernew.build();
Request request = new Request.Builder()
.addHeader("Accept","*/*")
.addHeader("Accept", "*/*")
.url("https://webapp.fpcitc.com.tw/SOP/api/FileUpload/fileUpload")
.method("POST", body)
.build();
......@@ -569,7 +613,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
Log.e("response", responsebody);
// dismissProgressDialog();
if (json.get("success").equals("true")){
if (json.get("success").equals("true")) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -577,7 +621,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
showDialogMessage("上傳完成");
}
});
}else{
} else {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
......
......@@ -39,7 +39,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:hint="@string/login_account_hint"
android:text="N000158385"
android:textColorHint="@color/white"
android:paddingStart="100dp"
app:layout_constraintWidth_percent="0.9"
......@@ -55,7 +55,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:hint="@string/login_password_hint"
android:text="781122222"
android:textColorHint="@color/white"
android:paddingStart="100dp"
android:background="@drawable/bg_login_password"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment