diff --git a/app/build.gradle b/app/build.gradle index a9cedef..bbdd34d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ android { // arguments "-DANDROID_STL=c++_shared" // arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DNCNN_ROOT=" + ncnnroot arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" - abiFilters 'arm64-v8a', 'armeabi-v7a' + abiFilters 'arm64-v8a' // setAbiFilters(['arm64-v8a']) } } @@ -36,11 +36,11 @@ android { } } - sourceSets { - main{ - jniLibs.srcDirs=['src/main/jniLibs'] - } - } +// sourceSets { +// main{ +// jniLibs.srcDirs=['src/main/jniLibs'] +// } +// } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9460cc0..c18b6ea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,9 +5,7 @@ - - - + @@ -22,7 +20,10 @@ android:theme="@style/Theme.MpPreview" tools:targetApi="31"> + @@ -30,6 +31,17 @@ + + + \ No newline at end of file diff --git a/app/src/main/cpp/MpPreview.cpp b/app/src/main/cpp/MpPreview.cpp index 7a88998..2af011b 100644 --- a/app/src/main/cpp/MpPreview.cpp +++ b/app/src/main/cpp/MpPreview.cpp @@ -79,7 +79,7 @@ bool makeHdr(std::vector& times, std::vector& paths, cv::Mat extern "C" JNIEXPORT jboolean JNICALL -Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLjava_lang_String_2Ljava_lang_String_2( +Java_com_xypower_mppreview_Camera2RawFragment_makeHdr( JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2, jstring path2, jstring outputPath) { @@ -107,7 +107,7 @@ Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLja extern "C" JNIEXPORT jboolean JNICALL -Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLjava_lang_String_2JLjava_lang_String_2Ljava_lang_String_2( +Java_com_xypower_mppreview_Camera2RawFragment_makeHdr2( JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2, jstring path2, jlong exposureTime3, jstring path3, jstring outputPath) { diff --git a/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java b/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java index b715acd..79f8919 100644 --- a/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java +++ b/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java @@ -1,5 +1,7 @@ package com.xypower.mppreview; +import static java.lang.System.loadLibrary; + import android.Manifest; import android.app.Activity; import android.app.Dialog; @@ -28,8 +30,6 @@ import android.hardware.camera2.params.MeteringRectangle; import android.hardware.camera2.params.StreamConfigurationMap; import android.media.Image; import android.media.ImageReader; -import android.media.MediaScannerConnection; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -86,6 +86,12 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class Camera2RawFragment extends Fragment { + private static int covertNum; + + static { + loadLibrary("mppreview"); + } + /** * Conversion from screen rotation to JPEG orientation. */ @@ -162,8 +168,10 @@ public class Camera2RawFragment extends Fragment { */ private OrientationEventListener mOrientationListener; - private native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, String outputPath); - private native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, long exposureTime3, String path3, String outputPath); + public static native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, String outputPath); + + public static native boolean makeHdr2(long exposureTime1, String path1, long exposureTime2, String path2, long exposureTime3, String path3, String outputPath); + private int mExposureComp = MainActivity.ExposureComp; @@ -392,7 +400,7 @@ public class Camera2RawFragment extends Fragment { private Long exposetime; private Integer sensitivity; /** - /** + * /** * A {@link CameraCaptureSession.CaptureCallback} that handles events for the preview and * pre-capture sequence. */ @@ -614,21 +622,51 @@ public class Camera2RawFragment extends Fragment { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { +// File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); +// List strings = RawToJpgConverter.listFiles(directory); +// if (strings != null && strings.size() > 0) { +// for (String item : strings) { +// if (item.contains("create")) { +// File file1 = new File(directory, item); +// File file2 = new File(directory, "create_" + item + ".jpg"); +// try { +// RawToJpgConverter.convertRawToJpg(file1.getPath(), file2.getPath()); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// } +// } +// } + + File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); + String dcimpath = directory.getPath(); List strings = RawToJpgConverter.listFiles(directory); + long t1; + long t2; + String p1; + String p2; + ArrayList list = new ArrayList(); if (strings != null && strings.size() > 0) { for (String item : strings) { - if (item.contains("RAW")) { + if (item.contains("create")) { + String[] s = item.split("_"); File file1 = new File(directory, item); - File file2 = new File(directory, "create_" + item + ".jpg"); - try { - RawToJpgConverter.convertRawToJpg(file1.getPath(), file2.getPath()); - } catch (IOException e) { - throw new RuntimeException(e); + PngPhotoBean bean = new PngPhotoBean(); + bean.etime = Long.parseLong(s[1]); + bean.path = file1.getPath(); + list.add(bean); + if (list.size() == 2) { + break; } } } } + if (list.size() == 2) { + PngPhotoBean bean = list.get(0); + PngPhotoBean bean1 = list.get(1); + makeHdr(bean.etime, bean.path, bean1.etime, bean1.path, dcimpath + "/" + "hdr_" + generateTimestamp() + ".png"); + } } }); @@ -1130,7 +1168,7 @@ public class Camera2RawFragment extends Fragment { // Find the best preview size for these view dimensions and configured JPEG size. // Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg); - Size previewSize = new Size(3840,2160); + Size previewSize = new Size(3840, 2160); if (swappedDimensions) { mTextureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); @@ -1270,10 +1308,10 @@ public class Camera2RawFragment extends Fragment { Rational rational = mCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP); double step = rational.doubleValue(); - // mCharacteristics.get(CameraMetadata.CONTROL_AE_COMPENSATION_STEP) List requests = new ArrayList<>(); - for (int idx = 0; idx < 10; idx++) { + double v = 0; + for (int idx = 0; idx < 2; idx++) { // Set request tag to easily track results in callbacks. captureBuilder.setTag(mRequestCounter.getAndIncrement()); @@ -1284,7 +1322,7 @@ public class Camera2RawFragment extends Fragment { if (isHandTakePic) { captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); if (exposureTime > 0) { - double v = exposureTime * pic1; + v = exposureTime * pic1; captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); } if (sensitivity > 0) { @@ -1300,142 +1338,7 @@ public class Camera2RawFragment extends Fragment { if (isHandTakePic) { captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); if (exposureTime > 0) { - double v = exposureTime * 2; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 2) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 3; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 3) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 4; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 4) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 5; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 5) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 6; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 6) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 7; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 7) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 8; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 8) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 9; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 9) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 10; - captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); - } - if (sensitivity > 0) { - captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100); - } - } - } - if (idx == 10) { -// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4)); - // 设置曝光时间,例如设置为1000微秒 -// long exposureTime = 1000 000000L; // 1000微秒 - if (isHandTakePic) { - captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); - if (exposureTime > 0) { - double v = exposureTime * 11; + v = exposureTime * 7; captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); } if (sensitivity > 0) { @@ -1451,6 +1354,8 @@ public class Camera2RawFragment extends Fragment { ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics); ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics); + rawBuilder.setExposetime((long) v); + mJpegResultQueue.put((int) request.getTag(), jpegBuilder); mRawResultQueue.put((int) request.getTag(), rawBuilder); @@ -1591,14 +1496,16 @@ public class Camera2RawFragment extends Fragment { * A reference counted wrapper for the ImageReader that owns the given image. */ private final RefCountedAutoCloseable mReader; + private final long mExpostime; - private ImageSaver(Image image, File file, CaptureResult result, CameraCharacteristics characteristics, Context context, RefCountedAutoCloseable reader) { + private ImageSaver(Image image, File file, CaptureResult result, CameraCharacteristics characteristics, Context context, RefCountedAutoCloseable reader, long mexpostime) { mImage = image; mFile = file; mCaptureResult = result; mCharacteristics = characteristics; mContext = context; mReader = reader; + mExpostime = mexpostime; } @Override @@ -1649,19 +1556,28 @@ public class Camera2RawFragment extends Fragment { // If saving the file succeeded, update MediaStore. if (success) { - MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()}, - /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() { - @Override - public void onMediaScannerConnected() { - // Do nothing - } + File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); + File file = new File(directory, "create_" + mExpostime + "_" + generateTimestamp() + ".png"); + try { + RawToJpgConverter.convertRawToJpg(mFile.getPath(), file.getPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } - @Override - public void onScanCompleted(String path, Uri uri) { - Log.i(TAG, "Scanned " + path + ":"); - Log.i(TAG, "-> uri=" + uri); - } - }); +// covertNum++; +// MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()}, +// /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() { +// @Override +// public void onMediaScannerConnected() { +// // Do nothing +// } +// +// @Override +// public void onScanCompleted(String path, Uri uri) { +// Log.i(TAG, "Scanned " + path + ":"); +// Log.i(TAG, "-> uri=" + uri); +// } +// }); } } @@ -1676,6 +1592,8 @@ public class Camera2RawFragment extends Fragment { private CaptureResult mCaptureResult; private CameraCharacteristics mCharacteristics; private Context mContext; + + private long mexpostime; private RefCountedAutoCloseable mReader; /** @@ -1688,6 +1606,12 @@ public class Camera2RawFragment extends Fragment { mContext = context; } + public synchronized ImageSaverBuilder setExposetime(long time) { + + mexpostime = time; + return this; + } + public synchronized ImageSaverBuilder setRefCountedReader(RefCountedAutoCloseable reader) { if (reader == null) throw new NullPointerException(); @@ -1723,7 +1647,7 @@ public class Camera2RawFragment extends Fragment { if (!isComplete()) { return null; } - return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mContext, mReader); + return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mContext, mReader, mexpostime); } public synchronized String getSaveLocation() { diff --git a/app/src/main/java/com/xypower/mppreview/CameraActivity.java b/app/src/main/java/com/xypower/mppreview/CameraActivity.java new file mode 100644 index 0000000..831dc4f --- /dev/null +++ b/app/src/main/java/com/xypower/mppreview/CameraActivity.java @@ -0,0 +1,17 @@ +package com.xypower.mppreview; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +public class CameraActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_camera); + if (null == savedInstanceState) { + getSupportFragmentManager().beginTransaction().setReorderingAllowed(true).replace(R.id.container, Camera2RawFragment.class, null).commit(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xypower/mppreview/HdrUtil.java b/app/src/main/java/com/xypower/mppreview/HdrUtil.java new file mode 100644 index 0000000..bb33fa0 --- /dev/null +++ b/app/src/main/java/com/xypower/mppreview/HdrUtil.java @@ -0,0 +1,8 @@ +package com.xypower.mppreview; + +import static java.lang.System.loadLibrary; + +public class HdrUtil { + + +} diff --git a/app/src/main/java/com/xypower/mppreview/MainActivity.java b/app/src/main/java/com/xypower/mppreview/MainActivity.java index 9418568..0943868 100644 --- a/app/src/main/java/com/xypower/mppreview/MainActivity.java +++ b/app/src/main/java/com/xypower/mppreview/MainActivity.java @@ -1,22 +1,57 @@ package com.xypower.mppreview; -import androidx.appcompat.app.AlertDialog; +import static java.lang.System.loadLibrary; + +import androidx.activity.result.ActivityResult; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.AppCompatActivity; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -//import org.opencv.android.OpenCVLoader; +import android.text.Editable; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements View.OnClickListener { public static int ExposureComp = 0; + private EditText hdrnum; + private Button systakepic; + private Button hdrtakepic; + private ActivityResultLauncher photoResultLauncher; + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + + initView(); + initActivityResult(); + } + + private void initView() { + hdrtakepic = findViewById(R.id.hdrtakepic); + systakepic = findViewById(R.id.systakepic); + hdrnum = findViewById(R.id.hdr_num); + + hdrtakepic.setOnClickListener(this); + systakepic.setOnClickListener(this); + } + + private void initActivityResult() { + photoResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() { + @Override + public void onActivityResult(ActivityResult result) { + + } + }); } @Override @@ -29,85 +64,41 @@ public class MainActivity extends AppCompatActivity { // } } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - int comp = -1000; - switch (id) { - case R.id.action_picture: - takePicture(); - break; - case R.id.action_focus: - doFocus(); - break; - case R.id.action_comp0: - comp = 0; - break; - case R.id.action_comp1: - comp = 1; - break; - case R.id.action_comp2: - comp = 2; - break; - case R.id.action_comp3: - comp = 3; - break; - case R.id.action_comp4: - comp = 4; - break; - case R.id.action_comp_1: - comp = -1; - break; - case R.id.action_comp_2: - comp = -2; - break; - case R.id.action_comp_3: - comp = -3; - break; - case R.id.action_comp_4: - comp = -4; - break; - case R.id.action_info: - new AlertDialog.Builder(this) - .setMessage(R.string.intro_message) - .setPositiveButton(android.R.string.ok, null) - .show(); - - break; - default: - break; - } - - if (comp> -1000) { - ExposureComp = comp; - restartFragment(); - } - - return super.onOptionsItemSelected(item); - } - private void restartFragment() { - - getSupportFragmentManager().beginTransaction() - .replace(R.id.container, Camera2RawFragment.newInstance()) - .commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.container, Camera2RawFragment.newInstance()).commit(); } private void doFocus() { - Camera2RawFragment fragment = (Camera2RawFragment)getSupportFragmentManager().findFragmentById(R.id.container); + Camera2RawFragment fragment = (Camera2RawFragment) getSupportFragmentManager().findFragmentById(R.id.container); fragment.doFocus(); } private void takePicture() { - Camera2RawFragment fragment = (Camera2RawFragment)getSupportFragmentManager().findFragmentById(R.id.container); + Camera2RawFragment fragment = (Camera2RawFragment) getSupportFragmentManager().findFragmentById(R.id.container); fragment.isHandTakePic = false; fragment.takePicture(); } + + @Override + public void onClick(View view) { + int id = view.getId(); + switch (id) { + case R.id.hdrtakepic: + Intent intent = new Intent(this, CameraActivity.class); + Editable text = hdrnum.getText(); + String s = text.toString(); + if (s != null && !s.equals("")) { + double v = Double.parseDouble(s); + intent.putExtra("hdrnum", v); + } + startActivity(intent); + break; + case R.id.systakepic: + PhotoUtil.openCamera(this, photoResultLauncher); + break; + } + + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/xypower/mppreview/PhotoUtil.java b/app/src/main/java/com/xypower/mppreview/PhotoUtil.java new file mode 100644 index 0000000..aafa9ff --- /dev/null +++ b/app/src/main/java/com/xypower/mppreview/PhotoUtil.java @@ -0,0 +1,83 @@ +package com.xypower.mppreview; + + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; +import android.provider.MediaStore; + +import androidx.activity.result.ActivityResultLauncher; +import androidx.core.content.FileProvider; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class PhotoUtil { + /** + * 保存 photoUri + */ + private static Uri photoUri; + + /** + * 打开相机 + */ + public static void openCamera(Context context, ActivityResultLauncher photoResultLauncher) { + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + //确保有相机来处理Intent + if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) { + File photoFile = saveFileName(context); + if (photoFile != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri + photoUri = FileProvider.getUriForFile(context.getApplicationContext(), "com.stg.rouge.activity.fileprovider", photoFile); + } else { + photoUri = getDestinationUri(context); + } + takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); + photoResultLauncher.launch(takePictureIntent); + } + } + } + + /** + * 获取 Uri + * + * @return + */ + private static Uri getDestinationUri(Context context) { + String fileName = String.format("winetalk_%s.jpg", System.currentTimeMillis()); + File cropFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName); + return Uri.fromFile(cropFile); + } + + //当前路径,拍照回调后需要使用 + private String currentPath = null; + + /** + * 保存照片路径 + * + * @return + */ + private static File saveFileName(Context context) { + File newFolder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); + Date date = new Date(System.currentTimeMillis()); + String name = format.format(date) + ".jpg"; + + File ji = null; + try { + ji = new File(newFolder + "/" + name); + ji.createNewFile(); +// currentPath = ji.getAbsolutePath(); + } catch (Exception e) { + e.printStackTrace(); + } + return ji; + } + + +} diff --git a/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java b/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java new file mode 100644 index 0000000..34f57af --- /dev/null +++ b/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java @@ -0,0 +1,10 @@ +package com.xypower.mppreview; + +public class PngPhotoBean { + + public long etime; + public String path; + + + +} diff --git a/app/src/main/jniLibls/arm64-v8a/libopencv_java4.so b/app/src/main/jniLibls/arm64-v8a/libopencv_java4.so deleted file mode 100644 index 58021b4..0000000 Binary files a/app/src/main/jniLibls/arm64-v8a/libopencv_java4.so and /dev/null differ diff --git a/app/src/main/jniLibls/armeabi-v7a/libopencv_java4.so b/app/src/main/jniLibls/armeabi-v7a/libopencv_java4.so deleted file mode 100644 index 1bd816d..0000000 Binary files a/app/src/main/jniLibls/armeabi-v7a/libopencv_java4.so and /dev/null differ diff --git a/app/src/main/jniLibls/x86/libopencv_java4.so b/app/src/main/jniLibls/x86/libopencv_java4.so deleted file mode 100644 index 8ea596b..0000000 Binary files a/app/src/main/jniLibls/x86/libopencv_java4.so and /dev/null differ diff --git a/app/src/main/jniLibls/x86_64/libopencv_java4.so b/app/src/main/jniLibls/x86_64/libopencv_java4.so deleted file mode 100644 index b385299..0000000 Binary files a/app/src/main/jniLibls/x86_64/libopencv_java4.so and /dev/null differ diff --git a/app/src/main/res/layout/activity_camera.xml b/app/src/main/res/layout/activity_camera.xml new file mode 100644 index 0000000..4fefecb --- /dev/null +++ b/app/src/main/res/layout/activity_camera.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0be498a..44acd19 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,13 +4,54 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingLeft="15dp" + android:paddingTop="20dp" + android:paddingRight="15dp" tools:context=".MainActivity"> - + + + + + + + + + + + + + + +