Demo app camera width modification

pull/1/head
Dylan McIntyre 8 years ago
parent 6be4e9659e
commit c20a7c3218
  1. 66
      demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java
  2. 127
      demo/src/main/res/layout/activity_main.xml

@ -4,6 +4,9 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -14,6 +17,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import butterknife.OnTextChanged;
public class MainActivity extends AppCompatActivity {
@ -26,9 +30,21 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.screenWidth)
TextView screenWidth;
@BindView(R.id.width)
EditText width;
@BindView(R.id.widthWrapContent)
CheckBox widthWrapContent;
@BindView(R.id.widthMatchParent)
CheckBox widthMatchParent;
@BindView(R.id.screenHeight)
TextView screenHeight;
@BindView(R.id.height)
EditText height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -40,12 +56,35 @@ public class MainActivity extends AppCompatActivity {
public void onGlobalLayout() {
screenWidth.setText("screen: " + parent.getWidth() + "px");
screenHeight.setText("screen: " + parent.getHeight() + "px");
if (!widthMatchParent.isChecked() && !widthWrapContent.isChecked()) {
width.setText(String.valueOf(camera.getWidth()));
width.setHint("pixels");
} else if (widthMatchParent.isChecked()) {
width.setHint("match_parent");
width.setText("");
} else if (widthWrapContent.isChecked()) {
width.setHint("wrap_content");
width.setText("");
}
height.setText(String.valueOf(camera.getHeight()));
}
});
}
@Override
protected void onResume() {
super.onResume();
camera.start();
}
@Override
protected void onPause() {
camera.stop();
super.onPause();
}
@OnClick(R.id.capturePhoto)
void capturePhoto() {
@ -86,13 +125,35 @@ public class MainActivity extends AppCompatActivity {
}
}
@OnTextChanged(value = R.id.width, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void widthChanged() {
}
@OnCheckedChanged(R.id.widthWrapContent)
void widthWrapContent() {
void widthWrapContent(CompoundButton buttonCompat, boolean checked) {
if (checked) {
ViewGroup.LayoutParams layoutParams = camera.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
camera.setLayoutParams(layoutParams);
widthMatchParent.setChecked(false);
}
}
@OnCheckedChanged(R.id.widthMatchParent)
void widthMatchParent() {
void widthMatchParent(CompoundButton buttonCompat, boolean checked) {
if (checked) {
ViewGroup.LayoutParams layoutParams = camera.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
camera.setLayoutParams(layoutParams);
widthWrapContent.setChecked(false);
}
}
@OnTextChanged(value = R.id.height, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void heightChanged() {
}
@ -106,5 +167,4 @@ public class MainActivity extends AppCompatActivity {
}
}

@ -13,10 +13,12 @@
android:focusableInTouchMode="true"
android:orientation="vertical">
<com.wonderkiln.camerakit.CameraView
<com.wonderkiln.camerakit.CameraView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="400dp" />
android:layout_width="300dp"
android:layout_height="400dp"
android:layout_gravity="center_horizontal"
app:ckFacing="back" />
<LinearLayout
android:layout_width="match_parent"
@ -78,6 +80,104 @@
android:layout_marginTop="10dp"
android:background="#cccccc" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="PICTURE MODE"
android:textColor="@android:color/black"
android:textSize="14dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Quality" />
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Speed" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="OUTPUT"
android:textColor="@android:color/black"
android:textSize="14dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Crop to visible" />
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Full size" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -113,14 +213,16 @@
android:textSize="11dp" />
<EditText
android:id="@+id/width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="pixels" />
android:hint="pixels"
android:inputType="number" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:orientation="horizontal">
@ -178,14 +280,16 @@
android:textSize="11dp" />
<EditText
android:id="@+id/height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="pixels" />
android:hint="pixels"
android:inputType="number" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:orientation="horizontal">
@ -208,15 +312,6 @@
</FrameLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:backgroundTint="@color/colorPrimary"
android:text="Update parameters"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>

Loading…
Cancel
Save