From 7fbda858dcaa6a3134cced0e3553cd9481b3f6a9 Mon Sep 17 00:00:00 2001 From: Dylan McIntyre Date: Wed, 18 Jan 2017 11:15:56 -0500 Subject: [PATCH] rename to demo, automatically centerCrop camera preview based on size --- .idea/compiler.xml | 22 +++++++++++ .idea/copyright/profiles_settings.xml | 3 ++ .idea/gradle.xml | 19 +++++++++ .../animated_vector_drawable_25_0_1.xml | 12 ++++++ .idea/libraries/appcompat_v7_25_0_1.xml | 15 ++++++++ .../libraries/support_annotations_25_0_1.xml | 14 +++++++ .idea/libraries/support_compat_25_0_1.xml | 16 ++++++++ .idea/libraries/support_core_ui_25_0_1.xml | 16 ++++++++ .idea/libraries/support_core_utils_25_0_1.xml | 16 ++++++++ .idea/libraries/support_fragment_25_0_1.xml | 16 ++++++++ .../libraries/support_media_compat_25_0_1.xml | 16 ++++++++ .idea/libraries/support_v4_25_0_1.xml | 10 +++++ .../support_vector_drawable_25_0_1.xml | 12 ++++++ .idea/misc.xml | 36 ++++++++++++++++++ .idea/modules.xml | 10 +++++ .idea/runConfigurations.xml | 12 ++++++ camerakit/build.gradle | 14 +++++-- .../com/wonderkiln/camerakit/Camera2.java | 1 + .../com/wonderkiln/camerakit/CameraView.java | 5 --- .../com/wonderkiln/camerakit/PreviewImpl.java | 8 ++++ .../camerakit/TextureViewPreview.java | 1 + {app => demo}/.gitignore | 0 {app => demo}/build.gradle | 0 {app => demo}/proguard-rules.pro | 0 .../demo/ExampleInstrumentedTest.java | 0 {app => demo}/src/main/AndroidManifest.xml | 0 .../camerakit/demo/MainActivity.java | 9 ++++- .../src/main/res/layout/activity_main.xml | 5 ++- .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../res/mipmap-hdpi/ic_launcher_round.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../res/mipmap-mdpi/ic_launcher_round.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../res/mipmap-xhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin {app => demo}/src/main/res/values/colors.xml | 0 {app => demo}/src/main/res/values/strings.xml | 0 {app => demo}/src/main/res/values/styles.xml | 0 .../camerakit/demo/ExampleUnitTest.java | 0 settings.gradle | 2 +- 43 files changed, 278 insertions(+), 12 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/libraries/animated_vector_drawable_25_0_1.xml create mode 100644 .idea/libraries/appcompat_v7_25_0_1.xml create mode 100644 .idea/libraries/support_annotations_25_0_1.xml create mode 100644 .idea/libraries/support_compat_25_0_1.xml create mode 100644 .idea/libraries/support_core_ui_25_0_1.xml create mode 100644 .idea/libraries/support_core_utils_25_0_1.xml create mode 100644 .idea/libraries/support_fragment_25_0_1.xml create mode 100644 .idea/libraries/support_media_compat_25_0_1.xml create mode 100644 .idea/libraries/support_v4_25_0_1.xml create mode 100644 .idea/libraries/support_vector_drawable_25_0_1.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml rename {app => demo}/.gitignore (100%) rename {app => demo}/build.gradle (100%) rename {app => demo}/proguard-rules.pro (100%) rename {app => demo}/src/androidTest/java/com/wonderkiln/camerakit/demo/ExampleInstrumentedTest.java (100%) rename {app => demo}/src/main/AndroidManifest.xml (100%) rename {app => demo}/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java (68%) rename {app => demo}/src/main/res/layout/activity_main.xml (55%) rename {app => demo}/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename {app => demo}/src/main/res/mipmap-hdpi/ic_launcher_round.png (100%) rename {app => demo}/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename {app => demo}/src/main/res/mipmap-mdpi/ic_launcher_round.png (100%) rename {app => demo}/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename {app => demo}/src/main/res/mipmap-xhdpi/ic_launcher_round.png (100%) rename {app => demo}/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename {app => demo}/src/main/res/mipmap-xxhdpi/ic_launcher_round.png (100%) rename {app => demo}/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename {app => demo}/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png (100%) rename {app => demo}/src/main/res/values/colors.xml (100%) rename {app => demo}/src/main/res/values/strings.xml (100%) rename {app => demo}/src/main/res/values/styles.xml (100%) rename {app => demo}/src/test/java/com/wonderkiln/camerakit/demo/ExampleUnitTest.java (100%) diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..96cc43ef --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..f8d85214 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_25_0_1.xml b/.idea/libraries/animated_vector_drawable_25_0_1.xml new file mode 100644 index 00000000..fe16fa13 --- /dev/null +++ b/.idea/libraries/animated_vector_drawable_25_0_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_25_0_1.xml b/.idea/libraries/appcompat_v7_25_0_1.xml new file mode 100644 index 00000000..0542cb3e --- /dev/null +++ b/.idea/libraries/appcompat_v7_25_0_1.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_25_0_1.xml b/.idea/libraries/support_annotations_25_0_1.xml new file mode 100644 index 00000000..acd07a56 --- /dev/null +++ b/.idea/libraries/support_annotations_25_0_1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_compat_25_0_1.xml b/.idea/libraries/support_compat_25_0_1.xml new file mode 100644 index 00000000..43444f64 --- /dev/null +++ b/.idea/libraries/support_compat_25_0_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_ui_25_0_1.xml b/.idea/libraries/support_core_ui_25_0_1.xml new file mode 100644 index 00000000..22c38740 --- /dev/null +++ b/.idea/libraries/support_core_ui_25_0_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_utils_25_0_1.xml b/.idea/libraries/support_core_utils_25_0_1.xml new file mode 100644 index 00000000..dd8f5046 --- /dev/null +++ b/.idea/libraries/support_core_utils_25_0_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_fragment_25_0_1.xml b/.idea/libraries/support_fragment_25_0_1.xml new file mode 100644 index 00000000..6253632e --- /dev/null +++ b/.idea/libraries/support_fragment_25_0_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_media_compat_25_0_1.xml b/.idea/libraries/support_media_compat_25_0_1.xml new file mode 100644 index 00000000..1a995e80 --- /dev/null +++ b/.idea/libraries/support_media_compat_25_0_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_25_0_1.xml b/.idea/libraries/support_v4_25_0_1.xml new file mode 100644 index 00000000..05bc81d7 --- /dev/null +++ b/.idea/libraries/support_v4_25_0_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_25_0_1.xml b/.idea/libraries/support_vector_drawable_25_0_1.xml new file mode 100644 index 00000000..3bb8f3d7 --- /dev/null +++ b/.idea/libraries/support_vector_drawable_25_0_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..9fc28d4d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..1925ad5c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/camerakit/build.gradle b/camerakit/build.gradle index af4beef5..8c061a94 100644 --- a/camerakit/build.gradle +++ b/camerakit/build.gradle @@ -1,5 +1,11 @@ apply plugin: 'com.android.library' +ext { + PUBLISH_GROUP_ID = 'com.wonderkiln' + PUBLISH_ARTIFACT_ID = 'camerakit' + PUBLISH_VERSION = '0.9.0' +} + android { compileSdkVersion 25 buildToolsVersion "25.0.2" @@ -9,9 +15,6 @@ android { targetSdkVersion 25 versionCode 1 versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -22,5 +25,8 @@ android { } dependencies { - + compile 'com.android.support:appcompat-v7:25.0.1' } + +apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' + diff --git a/camerakit/src/main/java/com/wonderkiln/camerakit/Camera2.java b/camerakit/src/main/java/com/wonderkiln/camerakit/Camera2.java index cb41faed..acc765f5 100644 --- a/camerakit/src/main/java/com/wonderkiln/camerakit/Camera2.java +++ b/camerakit/src/main/java/com/wonderkiln/camerakit/Camera2.java @@ -371,6 +371,7 @@ public class Camera2 extends CameraViewImpl { } Size previewSize = getOptimalPreviewSize(); + mPreview.setBufferSize(previewSize.getWidth(), previewSize.getHeight()); Surface surface = mPreview.getSurface(); try { diff --git a/camerakit/src/main/java/com/wonderkiln/camerakit/CameraView.java b/camerakit/src/main/java/com/wonderkiln/camerakit/CameraView.java index 008e8e18..6b9ef4b7 100644 --- a/camerakit/src/main/java/com/wonderkiln/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/wonderkiln/camerakit/CameraView.java @@ -97,11 +97,6 @@ public class CameraView extends FrameLayout { super.onDetachedFromWindow(); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - @Override protected Parcelable onSaveInstanceState() { SavedState state = new SavedState(super.onSaveInstanceState()); diff --git a/camerakit/src/main/java/com/wonderkiln/camerakit/PreviewImpl.java b/camerakit/src/main/java/com/wonderkiln/camerakit/PreviewImpl.java index 36584d6d..50b667a0 100644 --- a/camerakit/src/main/java/com/wonderkiln/camerakit/PreviewImpl.java +++ b/camerakit/src/main/java/com/wonderkiln/camerakit/PreviewImpl.java @@ -44,6 +44,14 @@ abstract class PreviewImpl { } void setBufferSize(int width, int height) { + AspectRatio aspectRatio = AspectRatio.of(width, height); + int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat()); + float scaleY = (float) targetHeight / (float) getView().getHeight(); + if (scaleY > 1) { + getView().setScaleY(scaleY); + } else { + getView().setScaleX(1 / scaleY); + } } void setSize(int width, int height) { diff --git a/camerakit/src/main/java/com/wonderkiln/camerakit/TextureViewPreview.java b/camerakit/src/main/java/com/wonderkiln/camerakit/TextureViewPreview.java index ce62850c..5ed96ede 100644 --- a/camerakit/src/main/java/com/wonderkiln/camerakit/TextureViewPreview.java +++ b/camerakit/src/main/java/com/wonderkiln/camerakit/TextureViewPreview.java @@ -91,6 +91,7 @@ public class TextureViewPreview extends PreviewImpl { @TargetApi(15) @Override void setBufferSize(int width, int height) { + super.setBufferSize(width, height); mTextureView.getSurfaceTexture().setDefaultBufferSize(width, height); } diff --git a/app/.gitignore b/demo/.gitignore similarity index 100% rename from app/.gitignore rename to demo/.gitignore diff --git a/app/build.gradle b/demo/build.gradle similarity index 100% rename from app/build.gradle rename to demo/build.gradle diff --git a/app/proguard-rules.pro b/demo/proguard-rules.pro similarity index 100% rename from app/proguard-rules.pro rename to demo/proguard-rules.pro diff --git a/app/src/androidTest/java/com/wonderkiln/camerakit/demo/ExampleInstrumentedTest.java b/demo/src/androidTest/java/com/wonderkiln/camerakit/demo/ExampleInstrumentedTest.java similarity index 100% rename from app/src/androidTest/java/com/wonderkiln/camerakit/demo/ExampleInstrumentedTest.java rename to demo/src/androidTest/java/com/wonderkiln/camerakit/demo/ExampleInstrumentedTest.java diff --git a/app/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml similarity index 100% rename from app/src/main/AndroidManifest.xml rename to demo/src/main/AndroidManifest.xml diff --git a/app/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java b/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java similarity index 68% rename from app/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java rename to demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java index 5361c9c9..d56d779b 100644 --- a/app/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java +++ b/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java @@ -1,14 +1,21 @@ package com.wonderkiln.camerakit.demo; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import com.wonderkiln.camerakit.CameraView; public class MainActivity extends AppCompatActivity { + private CameraView camera; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + camera = (CameraView) findViewById(R.id.camera); + camera.start(); } } diff --git a/app/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml similarity index 55% rename from app/src/main/res/layout/activity_main.xml rename to demo/src/main/res/layout/activity_main.xml index d705dc74..168ab541 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -3,6 +3,9 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/mipmap-hdpi/ic_launcher.png rename to demo/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from app/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to demo/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/demo/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/mipmap-mdpi/ic_launcher.png rename to demo/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from app/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to demo/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to demo/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to demo/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/app/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml similarity index 100% rename from app/src/main/res/values/colors.xml rename to demo/src/main/res/values/colors.xml diff --git a/app/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml similarity index 100% rename from app/src/main/res/values/strings.xml rename to demo/src/main/res/values/strings.xml diff --git a/app/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml similarity index 100% rename from app/src/main/res/values/styles.xml rename to demo/src/main/res/values/styles.xml diff --git a/app/src/test/java/com/wonderkiln/camerakit/demo/ExampleUnitTest.java b/demo/src/test/java/com/wonderkiln/camerakit/demo/ExampleUnitTest.java similarity index 100% rename from app/src/test/java/com/wonderkiln/camerakit/demo/ExampleUnitTest.java rename to demo/src/test/java/com/wonderkiln/camerakit/demo/ExampleUnitTest.java diff --git a/settings.gradle b/settings.gradle index 711670b0..6956bfac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':camerakit' +include ':demo', ':camerakit'