Demo buffs, setup XML attrs for cameraview

pull/1/head
Dylan McIntyre 8 years ago
parent be41269264
commit 6be4e9659e
  1. 33
      camerakit/src/main/java/com/wonderkiln/camerakit/CameraView.java
  2. 21
      camerakit/src/main/res/values/attrs.xml
  3. 4
      demo/build.gradle
  4. 2
      demo/src/main/AndroidManifest.xml
  5. BIN
      demo/src/main/ic_launcher-web.png
  6. 93
      demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java
  7. 15
      demo/src/main/res/layout/activity_main.xml
  8. BIN
      demo/src/main/res/mipmap-hdpi/ic_launcher.png
  9. BIN
      demo/src/main/res/mipmap-mdpi/ic_launcher.png
  10. BIN
      demo/src/main/res/mipmap-xhdpi/ic_launcher.png
  11. BIN
      demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
  12. BIN
      demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  13. 2
      demo/src/main/res/values/strings.xml

@ -1,6 +1,7 @@
package com.wonderkiln.camerakit;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;
@ -52,6 +53,8 @@ public class CameraView extends FrameLayout {
private int mPictureMode;
private boolean mCropOutput;
private boolean mAdjustViewBounds;
private CameraListener mCameraListener;
@ -63,9 +66,39 @@ public class CameraView extends FrameLayout {
super(context, null);
}
@SuppressWarnings("all")
public CameraView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CameraView);
final int n = a.getIndexCount();
for (int i = 0; i < n; ++i) {
int attr = a.getIndex(i);
if (attr == R.styleable.CameraView_ckFacing) {
mFacing = a.getInteger(R.styleable.CameraView_ckFacing, 0);
}
if (attr == R.styleable.CameraView_ckFlash) {
mFlash = a.getInteger(R.styleable.CameraView_ckFlash, 0);
}
if (attr == R.styleable.CameraView_ckPictureMode) {
mPictureMode = a.getInteger(R.styleable.CameraView_ckPictureMode, 0);
}
if (attr == R.styleable.CameraView_ckCropOutput) {
mCropOutput = a.getBoolean(R.styleable.CameraView_ckCropOutput, false);
}
if (attr == R.styleable.CameraView_android_adjustViewBounds) {
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, false);
}
}
a.recycle();
}
final PreviewImpl preview = new TextureViewPreview(context, this);
mCameraImpl = new Camera2(context, mCameraListener, preview);

@ -3,6 +3,27 @@
<declare-styleable name="CameraView">
<attr name="ckFacing" format="enum">
<enum name="back" value="0" />
<enum name="front" value="1" />
</attr>
<attr name="ckFlash" format="enum">
<enum name="off" value="0" />
<enum name="on" value="1" />
<enum name="auto" value="2" />
</attr>
<attr name="ckPictureMode" format="enum">
<enum name="quality" value="0" />
<enum name="speed" value="1" />
<enum name="auto" value="2" />
</attr>
<attr name="ckCropOutput" format="boolean" />
<attr name="android:adjustViewBounds" />
</declare-styleable>
</resources>

@ -20,6 +20,8 @@ android {
}
dependencies {
compile 'com.android.support:appcompat-v7:25.0.1'
compile project(':camerakit')
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

@ -6,7 +6,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@ -2,20 +2,109 @@ package com.wonderkiln.camerakit.demo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.TextView;
import android.widget.Toast;
import com.wonderkiln.camerakit.CameraView;
import com.wonderkiln.camerakit.Constants;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
private CameraView camera;
@BindView(R.id.activity_main)
ViewGroup parent;
@BindView(R.id.camera)
CameraView camera;
@BindView(R.id.screenWidth)
TextView screenWidth;
@BindView(R.id.screenHeight)
TextView screenHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
screenWidth.setText("screen: " + parent.getWidth() + "px");
screenHeight.setText("screen: " + parent.getHeight() + "px");
}
});
camera = (CameraView) findViewById(R.id.camera);
camera.start();
}
@OnClick(R.id.capturePhoto)
void capturePhoto() {
}
@OnClick(R.id.captureVideo)
void captureVideo() {
}
@OnClick(R.id.toggleCamera)
void toggleCamera() {
switch (camera.toggleFacing()) {
case Constants.FACING_BACK:
Toast.makeText(this, "Switched to back camera!", Toast.LENGTH_SHORT).show();
break;
case Constants.FACING_FRONT:
Toast.makeText(this, "Switched to front camera!", Toast.LENGTH_SHORT).show();
break;
}
}
@OnClick(R.id.toggleFlash)
void toggleFlash() {
switch (camera.toggleFlash()) {
case Constants.FLASH_ON:
Toast.makeText(this, "Flash on!", Toast.LENGTH_SHORT).show();
break;
case Constants.FLASH_OFF:
Toast.makeText(this, "Flash off!", Toast.LENGTH_SHORT).show();
break;
case Constants.FLASH_AUTO:
Toast.makeText(this, "Flash auto!", Toast.LENGTH_SHORT).show();
break;
}
}
@OnCheckedChanged(R.id.widthWrapContent)
void widthWrapContent() {
}
@OnCheckedChanged(R.id.widthMatchParent)
void widthMatchParent() {
}
@OnCheckedChanged(R.id.heightWrapContent)
void heightWrapContent() {
}
@OnCheckedChanged(R.id.heightMatchParent)
void heightMatchParent() {
}
}

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
@ -30,6 +31,7 @@
android:weightSum="4">
<ImageButton
android:id="@+id/capturePhoto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
@ -39,15 +41,17 @@
android:tint="@android:color/white" />
<ImageButton
android:id="@+id/captureVideo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimaryDark"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_video"
android:tint="@android:color/white" />
<ImageButton
android:id="@+id/toggleFlash"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
@ -57,11 +61,12 @@
android:tint="@android:color/white" />
<ImageButton
android:id="@+id/toggleCamera"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimaryDark"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_switch"
android:tint="@android:color/white" />
@ -99,6 +104,7 @@
android:textStyle="bold" />
<TextView
android:id="@+id/screenWidth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
@ -119,11 +125,13 @@
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/widthWrapContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WRAP_CONTENT" />
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/widthMatchParent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -161,6 +169,7 @@
android:textStyle="bold" />
<TextView
android:id="@+id/screenHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
@ -181,11 +190,13 @@
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/heightWrapContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WRAP_CONTENT" />
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/heightMatchParent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

@ -1,3 +1,3 @@
<resources>
<string name="app_name">CameraKit-Android</string>
<string name="app_name">CameraKit Demo</string>
</resources>

Loading…
Cancel
Save