From c20a7c32187a9fc4b367ce34a81b50de24d8bdeb Mon Sep 17 00:00:00 2001 From: Dylan McIntyre Date: Thu, 19 Jan 2017 14:04:06 -0500 Subject: [PATCH] Demo app camera width modification --- .../camerakit/demo/MainActivity.java | 66 ++++++++- demo/src/main/res/layout/activity_main.xml | 127 +++++++++++++++--- 2 files changed, 174 insertions(+), 19 deletions(-) diff --git a/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java b/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java index 912bda37..46ae68fb 100644 --- a/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java +++ b/demo/src/main/java/com/wonderkiln/camerakit/demo/MainActivity.java @@ -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 { } - } diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index 12331cbc..d570f88e 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -13,10 +13,12 @@ android:focusableInTouchMode="true" android:orientation="vertical"> - + android:layout_width="300dp" + android:layout_height="400dp" + android:layout_gravity="center_horizontal" + app:ckFacing="back" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:hint="pixels" + android:inputType="number" /> @@ -178,14 +280,16 @@ android:textSize="11dp" /> + android:hint="pixels" + android:inputType="number" /> @@ -208,15 +312,6 @@ -