diff --git a/Application/build.gradle b/Application/build.gradle
index 4277b77..265b3ae 100644
--- a/Application/build.gradle
+++ b/Application/build.gradle
@@ -20,8 +20,8 @@ repositories {
}
dependencies {
- implementation 'com.android.support:appcompat-v7:28.0.0'
- implementation 'com.android.support.constraint:constraint-layout:2.0.4'
+ implementation 'androidx.appcompat:appcompat:1.0.0'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
// The sample build uses multiple directories to
@@ -37,12 +37,10 @@ android {
defaultConfig {
minSdkVersion 24
+ //noinspection ExpiredTargetSdkVersion
targetSdkVersion 27
}
- lint {
- baseline = file("lint-baseline.xml")
- }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
diff --git a/Application/lint-baseline.xml b/Application/lint-baseline.xml
new file mode 100644
index 0000000..c290ffd
--- /dev/null
+++ b/Application/lint-baseline.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
diff --git a/Application/src/main/AndroidManifest.xml b/Application/src/main/AndroidManifest.xml
index 3441f94..d74b84c 100644
--- a/Application/src/main/AndroidManifest.xml
+++ b/Application/src/main/AndroidManifest.xml
@@ -1,47 +1,34 @@
-
-
-
+
-
-
-
-
+
-
-
-
+
+
+
-
+
\ No newline at end of file
diff --git a/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java b/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java
index 92e479c..55628d2 100644
--- a/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java
+++ b/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java
@@ -24,12 +24,17 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
+import android.graphics.drawable.Drawable;
import android.hardware.SensorManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
@@ -55,7 +60,7 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
-import android.support.v4.app.ActivityCompat;
+import androidx.core.app.ActivityCompat;
import android.text.TextUtils;
import android.util.Log;
import android.util.Size;
@@ -66,6 +71,7 @@ import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.Switch;
import android.widget.Toast;
@@ -556,8 +562,12 @@ public class Camera2RawFragment extends Fragment
}
};
- public static Camera2RawFragment newInstance() {
- return new Camera2RawFragment();
+ public static Camera2RawFragment newInstance(final boolean hdr) {
+
+ Camera2RawFragment fragment = new Camera2RawFragment();
+ Bundle bundle = new Bundle();
+
+ return fragment;
}
@Override
@@ -568,18 +578,22 @@ public class Camera2RawFragment extends Fragment
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
+
+ Resources resources = getResources();
+ ImageView imageView = (ImageView)view.findViewById(R.id.picture);
+ imageView.setImageDrawable(resources.getDrawable(R.drawable.ic_take_photo));
+ imageView = (ImageView)view.findViewById(R.id.backMain);
+ imageView.setImageDrawable(resources.getDrawable(R.drawable.ic_back));
+
view.findViewById(R.id.picture).setOnClickListener(this);
// view.findViewById(R.id.info).setOnClickListener(this);
mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture);
- view.findViewById(R.id.hdr).setOnClickListener(new View.OnClickListener() {
+ view.findViewById(R.id.backMain).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- closeCamera();
- // stopBackgroundThread();
- // startBackgroundThread();
- openCamera();
+ getActivity().finish();
}
});
@@ -673,11 +687,9 @@ public class Camera2RawFragment extends Fragment
return false;
}
- View rootView = getView();
- Switch hdrSwitch = (Switch)(rootView.findViewById(R.id.hdr));
+ Intent intent = activity.getIntent();
+ String expectedCameraId = Integer.toString(intent.getIntExtra("cameraId", 0));
- boolean hdrChecked = hdrSwitch.isChecked();
- final String expectedCameraId = hdrChecked ? "1" : "0";
try {
// Find a CameraDevice that supports RAW captures, and configure state.
for (String cameraId : manager.getCameraIdList()) {
@@ -1017,7 +1029,7 @@ public class Camera2RawFragment extends Fragment
activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
// Find the rotation of the device relative to the camera sensor's orientation.
- int totalRotation = sensorToDeviceRotation(mCharacteristics, deviceRotation);
+ int totalRotation = sensorToDeviceRotation(mCharacteristics, deviceRotation, getRotationAdjustment());
// Swap the view dimensions for calculation as needed if they are rotated relative to
// the sensor.
@@ -1060,8 +1072,8 @@ public class Camera2RawFragment extends Fragment
// cameras).
int rotation = (mCharacteristics.get(CameraCharacteristics.LENS_FACING) ==
CameraCharacteristics.LENS_FACING_FRONT) ?
- (360 + ORIENTATIONS.get(deviceRotation)) % 360 :
- (360 - ORIENTATIONS.get(deviceRotation)) % 360;
+ (360 + ORIENTATIONS.get(deviceRotation + getRotationAdjustment() / 90)) % 360 :
+ (360 - ORIENTATIONS.get(deviceRotation + getRotationAdjustment() / 90)) % 360;
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
@@ -1183,7 +1195,7 @@ public class Camera2RawFragment extends Fragment
// Set orientation.
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
- sensorToDeviceRotation(mCharacteristics, rotation));
+ sensorToDeviceRotation(mCharacteristics, rotation, getRotationAdjustment()));
// Set request tag to easily track results in callbacks.
captureBuilder.setTag(mRequestCounter.getAndIncrement());
@@ -1329,20 +1341,32 @@ public class Camera2RawFragment extends Fragment
int format = mImage.getFormat();
switch (format) {
case ImageFormat.JPEG: {
+
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
+
FileOutputStream output = null;
try {
output = new FileOutputStream(mFile);
- output.write(bytes);
- success = true;
+ if (mCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
+ Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
+ Bitmap bm2 = flipBitmap(bm);
+ bm.recycle();
+ success = bm2.compress(Bitmap.CompressFormat.JPEG, 95, output);
+ bm2.recycle();
+ } else {
+ output.write(bytes);
+ success = true;
+ }
} catch (IOException e) {
e.printStackTrace();
} finally {
mImage.close();
closeOutput(output);
}
+
+
break;
}
case ImageFormat.RAW_SENSOR: {
@@ -1387,6 +1411,20 @@ public class Camera2RawFragment extends Fragment
}
}
+ private Bitmap flipBitmap(Bitmap bitmap) {
+ if (null == bitmap) {
+ return null;
+ }
+ int width = bitmap.getWidth();
+ int height = bitmap.getHeight();
+ Matrix m = new Matrix();
+ m.postScale(-1, 1); //镜像水平翻转
+ //m.postScale(1, -1); //镜像垂直翻转
+ //m.postRotate(-90); //旋转-90度
+ Bitmap new2 = Bitmap.createBitmap(bitmap, 0, 0, width, height, m, true);
+ return new2;
+ }
+
/**
* Builder class for constructing {@link ImageSaver}s.
*
@@ -1679,6 +1717,10 @@ public class Camera2RawFragment extends Fragment
return Math.abs(aAspect - bAspect) <= ASPECT_RATIO_TOLERANCE;
}
+ private int getRotationAdjustment() {
+ return TextUtils.equals(mCameraId, "1") ? 90 : 0;
+ }
+
/**
* Rotation need to transform from the camera sensor orientation to the device's current
* orientation.
@@ -1689,11 +1731,11 @@ public class Camera2RawFragment extends Fragment
* orientation.
* @return the total rotation from the sensor orientation to the current device orientation.
*/
- private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
+ private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation, int adjustment) {
int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Get device orientation in degrees
- deviceOrientation = ORIENTATIONS.get(deviceOrientation);
+ deviceOrientation = ORIENTATIONS.get((deviceOrientation + (adjustment / 90)) % ORIENTATIONS.size());
// Reverse device orientation for front-facing cameras
if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
@@ -1702,6 +1744,7 @@ public class Camera2RawFragment extends Fragment
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
+
return (sensorOrientation - deviceOrientation + 360) % 360;
}
diff --git a/Application/src/main/java/com/xypower/mppreview/CameraActivity.java b/Application/src/main/java/com/xypower/mppreview/CameraActivity.java
index b1d7d1c..2abcbe2 100644
--- a/Application/src/main/java/com/xypower/mppreview/CameraActivity.java
+++ b/Application/src/main/java/com/xypower/mppreview/CameraActivity.java
@@ -18,21 +18,38 @@ package com.xypower.mppreview;
import android.app.Activity;
import android.os.Bundle;
+import android.os.Handler;
/**
* Activity displaying a fragment that implements RAW photo captures.
*/
public class CameraActivity extends Activity {
+ Handler mHandler;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ mHandler = new Handler();
setContentView(R.layout.activity_camera);
if (null == savedInstanceState) {
getFragmentManager().beginTransaction()
- .replace(R.id.container, Camera2RawFragment.newInstance())
+ .replace(R.id.container, Camera2RawFragment.newInstance(false))
.commit();
}
}
+
+ public void reopenFragment(final boolean hdr) {
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ getFragmentManager().beginTransaction()
+ .replace(R.id.container, Camera2RawFragment.newInstance(hdr))
+ .commit();
+ }
+ }, 0);
+ }
+
}
diff --git a/Application/src/main/java/com/xypower/mppreview/MainActivity.java b/Application/src/main/java/com/xypower/mppreview/MainActivity.java
new file mode 100644
index 0000000..257dacd
--- /dev/null
+++ b/Application/src/main/java/com/xypower/mppreview/MainActivity.java
@@ -0,0 +1,54 @@
+package com.xypower.mppreview;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Switch;
+
+public class MainActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ ((Button)findViewById(R.id.channel1)).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ takePhoto(1);
+ }
+ });
+ ((Button)findViewById(R.id.channel2)).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ takePhoto(2);
+ }
+ });
+ ((Button)findViewById(R.id.channel3)).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ takePhoto(3);
+ }
+ });
+ }
+
+ protected void takePhoto(int channel) {
+ Switch hdrSwitch = (Switch) findViewById(R.id.hdr);
+ takePhoto(channel, hdrSwitch.isChecked());
+ }
+
+ protected void takePhoto(int channel, boolean hdr) {
+ int cameraId = channel - 1;
+ if (channel == 1 && hdr) {
+ cameraId = 1;
+ }
+
+ Intent intent = new Intent(MainActivity.this, CameraActivity.class);
+ intent.putExtra("cameraId", cameraId);
+ startActivity(intent);
+ }
+}
\ No newline at end of file
diff --git a/Application/src/main/res/drawable/ic_action_info.png b/Application/src/main/res/drawable/ic_action_info.png
new file mode 100644
index 0000000..32bd1aa
Binary files /dev/null and b/Application/src/main/res/drawable/ic_action_info.png differ
diff --git a/Application/src/main/res/drawable/ic_back.xml b/Application/src/main/res/drawable/ic_back.xml
new file mode 100644
index 0000000..0dbdb8a
--- /dev/null
+++ b/Application/src/main/res/drawable/ic_back.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/Application/src/main/res/drawable/ic_launcher.png b/Application/src/main/res/drawable/ic_launcher.png
new file mode 100644
index 0000000..bba1165
Binary files /dev/null and b/Application/src/main/res/drawable/ic_launcher.png differ
diff --git a/Application/src/main/res/drawable/ic_take_photo.xml b/Application/src/main/res/drawable/ic_take_photo.xml
new file mode 100644
index 0000000..f944387
--- /dev/null
+++ b/Application/src/main/res/drawable/ic_take_photo.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/Application/src/main/res/drawable/tile.9.png b/Application/src/main/res/drawable/tile.9.png
new file mode 100644
index 0000000..1358628
Binary files /dev/null and b/Application/src/main/res/drawable/tile.9.png differ
diff --git a/Application/src/main/res/layout-land/fragment_camera2_basic.xml b/Application/src/main/res/layout-land/fragment_camera2_basic.xml
index e2747b9..76e78de 100644
--- a/Application/src/main/res/layout-land/fragment_camera2_basic.xml
+++ b/Application/src/main/res/layout-land/fragment_camera2_basic.xml
@@ -13,48 +13,55 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-
-
+
+
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
-
-
-
-
+ android:scaleType="fitXY"
+ app:layout_constraintBottom_toTopOf="@+id/backMain"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.5"
+ app:srcCompat="@drawable/ic_take_photo"
+ />
+
-
+
-
+
diff --git a/Application/src/main/res/layout/activity_main.xml b/Application/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..d6fe279
--- /dev/null
+++ b/Application/src/main/res/layout/activity_main.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..5465fec
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,2 @@
+android.enableJetifier=true
+android.useAndroidX=true
\ No newline at end of file