From 13feba24696e96f4773b1c76a28c7056092045a2 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Thu, 3 Aug 2017 20:58:17 +0200 Subject: [PATCH] Refactored demo app --- camerakit/build.gradle | 8 --- .../com/flurgle/camerakit/CameraUtils.java | 3 +- camerakit/src/main/res/values/attrs.xml | 2 - demo/build.gradle | 9 +-- .../flurgle/camerakit/demo/MainActivity.java | 3 +- .../demo/PicturePreviewActivity.java | 33 ++++++----- demo/src/main/res/drawable/background.xml | 6 ++ demo/src/main/res/drawable/ic_flash.xml | 2 +- demo/src/main/res/drawable/ic_photo.xml | 4 +- demo/src/main/res/drawable/ic_switch.xml | 2 +- demo/src/main/res/drawable/ic_video.xml | 2 +- demo/src/main/res/drawable/launch_bg.xml | 56 ------------------- demo/src/main/res/layout/activity_main.xml | 40 ++++++------- demo/src/main/res/values/colors.xml | 6 +- demo/src/main/res/values/styles.xml | 1 - 15 files changed, 60 insertions(+), 117 deletions(-) create mode 100644 demo/src/main/res/drawable/background.xml delete mode 100644 demo/src/main/res/drawable/launch_bg.xml diff --git a/camerakit/build.gradle b/camerakit/build.gradle index 8209d6c8..ffeec354 100644 --- a/camerakit/build.gradle +++ b/camerakit/build.gradle @@ -1,11 +1,5 @@ apply plugin: 'com.android.library' -ext { - PUBLISH_GROUP_ID = 'com.flurgle' - PUBLISH_ARTIFACT_ID = 'camerakit' - PUBLISH_VERSION = '0.9.18' -} - android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion @@ -39,5 +33,3 @@ dependencies { annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1' } -// apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' - diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java index edeed560..47c4ecd0 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.os.Handler; +import android.support.annotation.UiThread; import android.support.media.ExifInterface; import java.io.ByteArrayInputStream; @@ -111,6 +112,6 @@ public class CameraUtils { public interface BitmapCallback { - void onBitmapReady(Bitmap bitmap); + @UiThread void onBitmapReady(Bitmap bitmap); } } diff --git a/camerakit/src/main/res/values/attrs.xml b/camerakit/src/main/res/values/attrs.xml index 63a65b84..97e58b73 100644 --- a/camerakit/src/main/res/values/attrs.xml +++ b/camerakit/src/main/res/values/attrs.xml @@ -67,8 +67,6 @@ - - \ No newline at end of file diff --git a/demo/build.gradle b/demo/build.gradle index a50894c8..333d851f 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,15 +1,16 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { applicationId "com.flurgle.camerakit.demo" - minSdkVersion 15 - targetSdkVersion 25 + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion versionCode 4 versionName "1.0.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true } buildTypes { release { diff --git a/demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java b/demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java index d19ad9b9..b9497d8c 100644 --- a/demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java +++ b/demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java @@ -121,8 +121,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan super.onPictureTaken(jpeg); mCapturing = false; long callbackTime = System.currentTimeMillis(); - Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length); - PicturePreviewActivity.setImage(bitmap); + PicturePreviewActivity.setImage(jpeg); Intent intent = new Intent(MainActivity.this, PicturePreviewActivity.class); intent.putExtra("delay", callbackTime-startTime); startActivity(intent); diff --git a/demo/src/main/java/com/flurgle/camerakit/demo/PicturePreviewActivity.java b/demo/src/main/java/com/flurgle/camerakit/demo/PicturePreviewActivity.java index 6c4c1f48..faa58d93 100644 --- a/demo/src/main/java/com/flurgle/camerakit/demo/PicturePreviewActivity.java +++ b/demo/src/main/java/com/flurgle/camerakit/demo/PicturePreviewActivity.java @@ -8,6 +8,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.flurgle.camerakit.AspectRatio; +import com.flurgle.camerakit.CameraUtils; import com.flurgle.camerakit.Size; import java.lang.ref.WeakReference; @@ -32,9 +33,9 @@ public class PicturePreviewActivity extends Activity { @BindView(R.id.captureLatency) TextView captureLatency; - private static WeakReference image; + private static WeakReference image; - public static void setImage(@Nullable Bitmap im) { + public static void setImage(@Nullable byte[] im) { image = im != null ? new WeakReference<>(im) : null; } @@ -44,23 +45,29 @@ public class PicturePreviewActivity extends Activity { setContentView(R.layout.activity_picture_preview); ButterKnife.bind(this); - long delay = getIntent().getLongExtra("delay", 0); - Bitmap bitmap = image == null ? null : image.get(); - if (bitmap == null) { + final long delay = getIntent().getLongExtra("delay", 0); + byte[] b = image == null ? null : image.get(); + if (b == null) { finish(); return; } - imageView.setImageBitmap(bitmap); + CameraUtils.decodeBitmap(b, new CameraUtils.BitmapCallback() { + @Override + public void onBitmapReady(Bitmap bitmap) { + imageView.setImageBitmap(bitmap); - // Native sizes are landscape, activity might now. <- not clear what this means but OK - // TODO: ncr and ar might be different when cropOutput is true. - AspectRatio aspectRatio = AspectRatio.of(bitmap.getHeight(), bitmap.getWidth()); - nativeCaptureResolution.setText(bitmap.getHeight() + " x " + bitmap.getWidth() + " (" + aspectRatio.toString() + ")"); + // Native sizes are landscape, activity might now. <- not clear what this means but OK + // TODO: ncr and ar might be different when cropOutput is true. + AspectRatio aspectRatio = AspectRatio.of(bitmap.getHeight(), bitmap.getWidth()); + nativeCaptureResolution.setText(bitmap.getHeight() + " x " + bitmap.getWidth() + " (" + aspectRatio.toString() + ")"); + + actualResolution.setText(bitmap.getWidth() + " x " + bitmap.getHeight()); + approxUncompressedSize.setText(getApproximateFileMegabytes(bitmap) + "MB"); + captureLatency.setText(delay + " milliseconds"); + } + }); - actualResolution.setText(bitmap.getWidth() + " x " + bitmap.getHeight()); - approxUncompressedSize.setText(getApproximateFileMegabytes(bitmap) + "MB"); - captureLatency.setText(delay + " milliseconds"); } private static float getApproximateFileMegabytes(Bitmap bitmap) { diff --git a/demo/src/main/res/drawable/background.xml b/demo/src/main/res/drawable/background.xml new file mode 100644 index 00000000..558ef21c --- /dev/null +++ b/demo/src/main/res/drawable/background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/demo/src/main/res/drawable/ic_flash.xml b/demo/src/main/res/drawable/ic_flash.xml index a3c81cc3..e9364686 100644 --- a/demo/src/main/res/drawable/ic_flash.xml +++ b/demo/src/main/res/drawable/ic_flash.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/demo/src/main/res/drawable/ic_photo.xml b/demo/src/main/res/drawable/ic_photo.xml index c872f167..4fa7158a 100644 --- a/demo/src/main/res/drawable/ic_photo.xml +++ b/demo/src/main/res/drawable/ic_photo.xml @@ -4,9 +4,9 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/demo/src/main/res/drawable/ic_switch.xml b/demo/src/main/res/drawable/ic_switch.xml index d49ce20e..e364c2d2 100644 --- a/demo/src/main/res/drawable/ic_switch.xml +++ b/demo/src/main/res/drawable/ic_switch.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/demo/src/main/res/drawable/ic_video.xml b/demo/src/main/res/drawable/ic_video.xml index e23eac81..4f58f22a 100644 --- a/demo/src/main/res/drawable/ic_video.xml +++ b/demo/src/main/res/drawable/ic_video.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/demo/src/main/res/drawable/launch_bg.xml b/demo/src/main/res/drawable/launch_bg.xml deleted file mode 100644 index 00b7dffc..00000000 --- a/demo/src/main/res/drawable/launch_bg.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index 25f6fe9b..01d0bd8b 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -51,9 +51,9 @@ android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="1" - android:backgroundTint="@color/colorPrimary" - android:src="@drawable/ic_photo" - android:tint="@android:color/white" /> + android:padding="8dp" + android:background="@drawable/background" + app:srcCompat="@drawable/ic_photo" /> + android:padding="8dp" + android:background="@drawable/background" + app:srcCompat="@drawable/ic_video" /> + android:padding="8dp" + android:background="@drawable/background" + app:srcCompat="@drawable/ic_flash" /> + android:padding="8dp" + android:background="@drawable/background" + app:srcCompat="@drawable/ic_switch" /> - - @@ -347,12 +342,13 @@