Refactored demo app

pull/1/head
Mattia Iavarone 7 years ago
parent 1e5563e833
commit 13feba2469
  1. 8
      camerakit/build.gradle
  2. 3
      camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java
  3. 2
      camerakit/src/main/res/values/attrs.xml
  4. 9
      demo/build.gradle
  5. 3
      demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java
  6. 33
      demo/src/main/java/com/flurgle/camerakit/demo/PicturePreviewActivity.java
  7. 6
      demo/src/main/res/drawable/background.xml
  8. 2
      demo/src/main/res/drawable/ic_flash.xml
  9. 4
      demo/src/main/res/drawable/ic_photo.xml
  10. 2
      demo/src/main/res/drawable/ic_switch.xml
  11. 2
      demo/src/main/res/drawable/ic_video.xml
  12. 56
      demo/src/main/res/drawable/launch_bg.xml
  13. 40
      demo/src/main/res/layout/activity_main.xml
  14. 6
      demo/src/main/res/values/colors.xml
  15. 1
      demo/src/main/res/values/styles.xml

@ -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'

@ -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);
}
}

@ -67,8 +67,6 @@
<attr name="cameraCropOutput" format="boolean" />
<attr name="android:adjustViewBounds" />
</declare-styleable>
</resources>

@ -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 {

@ -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);

@ -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<Bitmap> image;
private static WeakReference<byte[]> 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) {

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorPrimary"/>
<corners android:radius="10dp"/>
</shape>

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M7,2v11h3v9l7,-12h-4l4,-8z"/>
</vector>

@ -4,9 +4,9 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20,4h-3.17L15,2L9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM15,15.5L15,13L9,13v2.5L5.5,12 9,8.5L9,11h6L15,8.5l3.5,3.5 -3.5,3.5z"/>
</vector>

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
</vector>

@ -1,56 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1080dp"
android:height="1919dp"
android:viewportWidth="1080.0"
android:viewportHeight="1919.0">
<path
android:pathData="M0,0h1080v1920h-1080z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M291,960a249,247.1 0,1 0,498 0a249,247.1 0,1 0,-498 0z"
android:strokeColor="#00000000"
android:fillColor="#FFFFFF"
android:strokeWidth="1"/>
<path
android:pathData="M582.4,920L582.4,920A28.2,28.2 0,0 1,610.6 948.2L610.6,974.4A28.2,28.2 0,0 1,582.4 1002.6L582.4,1002.6A28.2,28.2 0,0 1,554.1 974.4L554.1,948.2A28.2,28.2 0,0 1,582.4 920z"
android:strokeColor="#00000000"
android:fillColor="#26C6DA"
android:strokeWidth="1"/>
<path
android:pathData="M497.6,920L497.6,920A28.2,28.2 0,0 1,525.9 948.2L525.9,974.4A28.2,28.2 0,0 1,497.6 1002.6L497.6,1002.6A28.2,28.2 0,0 1,469.4 974.4L469.4,948.2A28.2,28.2 0,0 1,497.6 920z"
android:strokeColor="#00000000"
android:fillColor="#26C6DA"
android:strokeWidth="1"/>
<path
android:pathData="M441,968.8C441,968.8 418.7,1040.2 411.9,1086.7C410,1099.9 409.4,1111.1 410.9,1118.1C445.5,1141.2 507.3,1179.7 597.8,1150.5C566.4,1123.6 528.5,1097.3 505,1069.9C481.5,1042.5 441,968.8 441,968.8Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M477.6,881.2C477.6,881.2 404.6,897.6 361,915C348.6,920 338.6,925 333.3,929.8C330.6,971.3 328.1,1044.1 398.7,1107.8C406.3,1067.2 410.1,1021.2 422,987.2C434,953.1 477.6,881.2 477.6,881.2Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M601.6,1039.3C601.6,1039.3 674.6,1023 718.2,1005.5C730.6,1000.6 740.6,995.6 745.9,990.8C748.6,949.2 751.1,876.4 680.5,812.8C673,853.3 669.1,899.3 657.2,933.4C645.2,967.4 601.6,1039.3 601.6,1039.3Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M637.5,950.8C637.5,950.8 659.9,879.4 666.6,832.9C668.5,819.7 669.1,808.5 667.6,801.5C633,778.4 571.2,739.9 480.8,769.1C512.1,796 550,822.3 573.5,849.7C597.1,877 637.5,950.8 637.5,950.8Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M575.5,871.5C575.5,871.5 524.9,816.4 488,787.4C477.5,779.1 468.1,773 461.4,770.8C424,789.2 359.7,823.5 339.9,916.4C378.8,902.7 420.5,883 456,876.3C491.4,869.6 575.5,871.5 575.5,871.5Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
<path
android:pathData="M503,1049.2C503,1049.2 553.7,1104.3 590.6,1133.3C601,1141.6 610.4,1147.7 617.2,1149.9C654.5,1131.5 718.8,1097.2 738.7,1004.3C699.7,1018 658,1037.7 622.6,1044.4C587.1,1051.1 503,1049.2 503,1049.2Z"
android:strokeColor="#00000000"
android:fillColor="#FF4444"
android:strokeWidth="1"/>
</vector>

@ -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" />
<ImageButton
android:id="@+id/captureVideo"
@ -61,9 +61,9 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_video"
android:tint="@android:color/white" />
android:padding="8dp"
android:background="@drawable/background"
app:srcCompat="@drawable/ic_video" />
<ImageButton
android:id="@+id/toggleFlash"
@ -71,9 +71,9 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_flash"
android:tint="@android:color/white" />
android:padding="8dp"
android:background="@drawable/background"
app:srcCompat="@drawable/ic_flash" />
<ImageButton
android:id="@+id/toggleCamera"
@ -81,18 +81,12 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_switch"
android:tint="@android:color/white" />
android:padding="8dp"
android:background="@drawable/background"
app:srcCompat="@drawable/ic_switch" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -249,12 +243,13 @@
<Button
android:id="@+id/widthUpdate"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="15dp"
android:backgroundTint="@color/colorPrimary"
android:background="@drawable/background"
android:gravity="center"
android:text="UPDATE"
android:stateListAnimator="@null"
android:textColor="@android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
@ -347,12 +342,13 @@
<Button
android:id="@+id/heightUpdate"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="15dp"
android:backgroundTint="@color/colorPrimary"
android:background="@drawable/background"
android:gravity="center"
android:text="UPDATE"
android:stateListAnimator="@null"
android:textColor="@android:color/white"
android:textSize="14sp"
android:textStyle="bold" />

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FF4444</color>
<color name="colorPrimaryDark">#D74141</color>
<color name="colorAccent">#2BCFE5</color>
<color name="colorPrimary">#29aaca</color>
<color name="colorPrimaryDark">#1f8199</color>
<color name="colorAccent">#4ed728</color>
</resources>

@ -9,7 +9,6 @@
</style>
<style name="Theme.MainActivity" parent="AppTheme">
<item name="android:windowBackground">@drawable/launch_bg</item>
</style>
<style name="Theme.PreviewActivity" parent="Theme.AppCompat.NoActionBar">

Loading…
Cancel
Save