|
|
@ -1,7 +1,11 @@ |
|
|
|
package com.wonderkiln.camerakit.demo; |
|
|
|
package com.wonderkiln.camerakit.demo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Bitmap; |
|
|
|
|
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
|
|
|
|
import android.os.Handler; |
|
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
|
|
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewTreeObserver; |
|
|
|
import android.view.ViewTreeObserver; |
|
|
|
import android.widget.CheckBox; |
|
|
|
import android.widget.CheckBox; |
|
|
@ -10,6 +14,7 @@ import android.widget.EditText; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.wonderkiln.camerakit.CameraListener; |
|
|
|
import com.wonderkiln.camerakit.CameraView; |
|
|
|
import com.wonderkiln.camerakit.CameraView; |
|
|
|
import com.wonderkiln.camerakit.Constants; |
|
|
|
import com.wonderkiln.camerakit.Constants; |
|
|
|
|
|
|
|
|
|
|
@ -17,6 +22,7 @@ import butterknife.BindView; |
|
|
|
import butterknife.ButterKnife; |
|
|
|
import butterknife.ButterKnife; |
|
|
|
import butterknife.OnCheckedChanged; |
|
|
|
import butterknife.OnCheckedChanged; |
|
|
|
import butterknife.OnClick; |
|
|
|
import butterknife.OnClick; |
|
|
|
|
|
|
|
import butterknife.OnFocusChange; |
|
|
|
import butterknife.OnTextChanged; |
|
|
|
import butterknife.OnTextChanged; |
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
@ -27,6 +33,12 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
@BindView(R.id.camera) |
|
|
|
@BindView(R.id.camera) |
|
|
|
CameraView camera; |
|
|
|
CameraView camera; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BindView(R.id.modeQuality) |
|
|
|
|
|
|
|
CheckBox modeQuality; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BindView(R.id.modeSpeed) |
|
|
|
|
|
|
|
CheckBox modeSpeed; |
|
|
|
|
|
|
|
|
|
|
|
@BindView(R.id.screenWidth) |
|
|
|
@BindView(R.id.screenWidth) |
|
|
|
TextView screenWidth; |
|
|
|
TextView screenWidth; |
|
|
|
|
|
|
|
|
|
|
@ -45,6 +57,8 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
@BindView(R.id.height) |
|
|
|
@BindView(R.id.height) |
|
|
|
EditText height; |
|
|
|
EditText height; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean blockInvalidation; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
@ -56,19 +70,13 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
public void onGlobalLayout() { |
|
|
|
public void onGlobalLayout() { |
|
|
|
screenWidth.setText("screen: " + parent.getWidth() + "px"); |
|
|
|
screenWidth.setText("screen: " + parent.getWidth() + "px"); |
|
|
|
screenHeight.setText("screen: " + parent.getHeight() + "px"); |
|
|
|
screenHeight.setText("screen: " + parent.getHeight() + "px"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!widthMatchParent.isChecked() && !widthWrapContent.isChecked()) { |
|
|
|
camera.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
|
|
|
width.setText(String.valueOf(camera.getWidth())); |
|
|
|
@Override |
|
|
|
width.setHint("pixels"); |
|
|
|
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
|
|
|
} else if (widthMatchParent.isChecked()) { |
|
|
|
invalidateParameters(); |
|
|
|
width.setHint("match_parent"); |
|
|
|
|
|
|
|
width.setText(""); |
|
|
|
|
|
|
|
} else if (widthWrapContent.isChecked()) { |
|
|
|
|
|
|
|
width.setHint("wrap_content"); |
|
|
|
|
|
|
|
width.setText(""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
height.setText(String.valueOf(camera.getHeight())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -87,7 +95,15 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
@OnClick(R.id.capturePhoto) |
|
|
|
@OnClick(R.id.capturePhoto) |
|
|
|
void capturePhoto() { |
|
|
|
void capturePhoto() { |
|
|
|
|
|
|
|
camera.setCameraListener(new CameraListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onPictureTaken(byte[] picture) { |
|
|
|
|
|
|
|
super.onPictureTaken(picture); |
|
|
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(picture, 0, picture.length); |
|
|
|
|
|
|
|
new PreviewDialog(MainActivity.this, bitmap).show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
camera.capturePicture(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnClick(R.id.captureVideo) |
|
|
|
@OnClick(R.id.captureVideo) |
|
|
@ -125,9 +141,36 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.modeQuality) |
|
|
|
|
|
|
|
void modeQuality(CompoundButton buttonCompat, boolean checked) { |
|
|
|
|
|
|
|
modeSpeed.setChecked(false); |
|
|
|
|
|
|
|
if (checked) { |
|
|
|
|
|
|
|
camera.setPictureMode(CameraView.PICTURE_MODE_QUALITY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.modeSpeed) |
|
|
|
|
|
|
|
void modeSpeed(CompoundButton buttonCompat, boolean checked) { |
|
|
|
|
|
|
|
modeQuality.setChecked(false); |
|
|
|
|
|
|
|
if (checked) { |
|
|
|
|
|
|
|
camera.setPictureMode(CameraView.PICTURE_MODE_SPEED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OnFocusChange({ R.id.width, R.id.height }) |
|
|
|
|
|
|
|
void inputFocusChanged(View view, boolean f) { |
|
|
|
|
|
|
|
blockInvalidation = view.isFocused(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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() { |
|
|
|
|
|
|
|
if (width.isFocused()) { |
|
|
|
|
|
|
|
new Handler().postDelayed(new UpdateCameraRunnable(width), 2000); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.widthWrapContent) |
|
|
|
@OnCheckedChanged(R.id.widthWrapContent) |
|
|
@ -139,6 +182,8 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
widthMatchParent.setChecked(false); |
|
|
|
widthMatchParent.setChecked(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.widthMatchParent) |
|
|
|
@OnCheckedChanged(R.id.widthMatchParent) |
|
|
@ -150,20 +195,75 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
widthWrapContent.setChecked(false); |
|
|
|
widthWrapContent.setChecked(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnTextChanged(value = R.id.height, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) |
|
|
|
@OnTextChanged(value = R.id.height, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) |
|
|
|
void heightChanged() { |
|
|
|
void heightChanged() { |
|
|
|
|
|
|
|
if (height.isFocused()) { |
|
|
|
|
|
|
|
new Handler().postDelayed(new UpdateCameraRunnable(height), 2000); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.heightWrapContent) |
|
|
|
@OnCheckedChanged(R.id.heightWrapContent) |
|
|
|
void heightWrapContent() { |
|
|
|
void heightWrapContent() { |
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnCheckedChanged(R.id.heightMatchParent) |
|
|
|
@OnCheckedChanged(R.id.heightMatchParent) |
|
|
|
void heightMatchParent() { |
|
|
|
void heightMatchParent() { |
|
|
|
|
|
|
|
invalidateParameters(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void invalidateParameters() { |
|
|
|
|
|
|
|
if (blockInvalidation) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blockInvalidation = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blockInvalidation = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class UpdateCameraRunnable implements Runnable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EditText editText; |
|
|
|
|
|
|
|
private String startText; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UpdateCameraRunnable(EditText editText) { |
|
|
|
|
|
|
|
this.startText = editText.getText().toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
if (startText.equals(editText.getText().toString())) { |
|
|
|
|
|
|
|
ViewGroup.LayoutParams layoutParams = camera.getLayoutParams(); |
|
|
|
|
|
|
|
switch (editText.getId()) { |
|
|
|
|
|
|
|
case R.id.width: |
|
|
|
|
|
|
|
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.height: |
|
|
|
|
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera.setLayoutParams(layoutParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|