crop toggling in demo

pull/1/head
Dylan McIntyre 8 years ago
parent 7e3899bc2e
commit cce7661ab2
  1. 68
      demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java
  2. 6
      demo/src/main/res/layout/activity_main.xml

@ -9,9 +9,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -24,12 +22,9 @@ import java.io.File;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import static com.flurgle.camerakit.demo.R.id.widthCustom;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@BindView(R.id.activity_main) @BindView(R.id.activity_main)
@ -40,10 +35,13 @@ public class MainActivity extends AppCompatActivity {
// Capture Mode: // Capture Mode:
@BindView(R.id.modeCaptureQuality) @BindView(R.id.captureModeRadioGroup)
RadioButton modeQuality; RadioGroup captureModeRadioGroup;
@BindView(R.id.modeCaptureSpeed)
RadioButton modeSpeed; // Crop Mode:
@BindView(R.id.cropModeRadioGroup)
RadioGroup cropModeRadioGroup;
// Width: // Width:
@ -53,8 +51,8 @@ public class MainActivity extends AppCompatActivity {
EditText width; EditText width;
@BindView(R.id.widthUpdate) @BindView(R.id.widthUpdate)
Button widthUpdate; Button widthUpdate;
@BindView(R.id.widthRadioGroup) @BindView(R.id.widthModeRadioGroup)
RadioGroup widthRadioGroup; RadioGroup widthModeRadioGroup;
// Height: // Height:
@ -64,8 +62,8 @@ public class MainActivity extends AppCompatActivity {
EditText height; EditText height;
@BindView(R.id.heightUpdate) @BindView(R.id.heightUpdate)
Button heightUpdate; Button heightUpdate;
@BindView(R.id.heightRadioGroup) @BindView(R.id.heightModeRadioGroup)
RadioGroup heightRadioGroup; RadioGroup heightModeRadioGroup;
private int mCameraWidth; private int mCameraWidth;
private int mCameraHeight; private int mCameraHeight;
@ -96,6 +94,9 @@ public class MainActivity extends AppCompatActivity {
camera.removeOnLayoutChangeListener(this); camera.removeOnLayoutChangeListener(this);
} }
}); });
captureModeRadioGroup.setOnCheckedChangeListener(captureModeChangedListener);
cropModeRadioGroup.setOnCheckedChangeListener(cropModeChangedListener);
} }
@Override @Override
@ -178,14 +179,25 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@OnCheckedChanged({R.id.modeCaptureQuality, R.id.modeCaptureSpeed}) RadioGroup.OnCheckedChangeListener captureModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
void pictureModeChanged(CompoundButton buttonCompat, boolean checked) { @Override
camera.setPictureMode( public void onCheckedChanged(RadioGroup group, int checkedId) {
modeQuality.isChecked() ? camera.setPictureMode(
CameraKit.Constants.PICTURE_MODE_QUALITY : checkedId == R.id.modeCaptureQuality ?
CameraKit.Constants.PICTURE_MODE_SPEED CameraKit.Constants.PICTURE_MODE_QUALITY :
); CameraKit.Constants.PICTURE_MODE_SPEED
} );
}
};
RadioGroup.OnCheckedChangeListener cropModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
camera.setCropOutput(
checkedId == R.id.modeCropVisible
);
}
};
@OnTextChanged(value = R.id.width, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) @OnTextChanged(value = R.id.width, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void widthChanged() { void widthChanged() {
@ -203,11 +215,6 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@OnCheckedChanged({widthCustom, R.id.widthWrapContent, R.id.widthMatchParent})
void widthModeChanged(CompoundButton buttonCompat, boolean checked) {
}
@OnTextChanged(value = R.id.height) @OnTextChanged(value = R.id.height)
void heightChanged() { void heightChanged() {
if (String.valueOf(mCameraHeight).equals(height.getText().toString())) { if (String.valueOf(mCameraHeight).equals(height.getText().toString())) {
@ -224,18 +231,13 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@OnCheckedChanged({R.id.heightCustom, R.id.heightWrapContent, R.id.heightMatchParent})
void heightModeChanged() {
}
private void updateCamera(boolean updateWidth, boolean updateHeight) { private void updateCamera(boolean updateWidth, boolean updateHeight) {
ViewGroup.LayoutParams cameraLayoutParams = camera.getLayoutParams(); ViewGroup.LayoutParams cameraLayoutParams = camera.getLayoutParams();
int width = cameraLayoutParams.width; int width = cameraLayoutParams.width;
int height = cameraLayoutParams.height; int height = cameraLayoutParams.height;
if (updateWidth) { if (updateWidth) {
switch (widthRadioGroup.getCheckedRadioButtonId()) { switch (widthModeRadioGroup.getCheckedRadioButtonId()) {
case R.id.widthCustom: case R.id.widthCustom:
String widthInput = this.width.getText().toString(); String widthInput = this.width.getText().toString();
if (widthInput.length() > 0) { if (widthInput.length() > 0) {
@ -259,7 +261,7 @@ public class MainActivity extends AppCompatActivity {
} }
if (updateHeight) { if (updateHeight) {
switch (heightRadioGroup.getCheckedRadioButtonId()) { switch (heightModeRadioGroup.getCheckedRadioButtonId()) {
case R.id.heightCustom: case R.id.heightCustom:
String heightInput = this.height.getText().toString(); String heightInput = this.height.getText().toString();
if (heightInput.length() > 0) { if (heightInput.length() > 0) {

@ -110,6 +110,7 @@
android:textStyle="bold" /> android:textStyle="bold" />
<RadioGroup <RadioGroup
android:id="@+id/captureModeRadioGroup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
@ -161,6 +162,7 @@
android:textStyle="bold" /> android:textStyle="bold" />
<RadioGroup <RadioGroup
android:id="@+id/cropModeRadioGroup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
@ -309,7 +311,7 @@
</FrameLayout> </FrameLayout>
<RadioGroup <RadioGroup
android:id="@+id/widthRadioGroup" android:id="@+id/widthModeRadioGroup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
@ -407,7 +409,7 @@
</FrameLayout> </FrameLayout>
<RadioGroup <RadioGroup
android:id="@+id/heightRadioGroup" android:id="@+id/heightModeRadioGroup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"

Loading…
Cancel
Save