mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-17 03:40:38 +01:00
display the flash icon only when its really available
This commit is contained in:
parent
faa72cf25c
commit
dff62f66d9
@ -19,11 +19,13 @@ import android.widget.ImageView;
|
|||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.camera.Preview.PreviewListener;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements SensorEventListener {
|
public class MainActivity extends AppCompatActivity implements SensorEventListener, PreviewListener {
|
||||||
@BindView(R.id.viewHolder) RelativeLayout viewHolder;
|
@BindView(R.id.viewHolder) RelativeLayout viewHolder;
|
||||||
@BindView(R.id.toggle_camera) ImageView toggleCameraBtn;
|
@BindView(R.id.toggle_camera) ImageView toggleCameraBtn;
|
||||||
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
|
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
|
||||||
@ -49,7 +51,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
currCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
|
currCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||||
preview = new Preview(this, (SurfaceView) findViewById(R.id.surfaceView));
|
preview = new Preview(this, (SurfaceView) findViewById(R.id.surfaceView), this);
|
||||||
preview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
preview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
viewHolder.addView(preview);
|
viewHolder.addView(preview);
|
||||||
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
@ -77,9 +79,8 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
public void toggleFlash() {
|
public void toggleFlash() {
|
||||||
if (isFlashEnabled) {
|
if (isFlashEnabled) {
|
||||||
disableFlash();
|
disableFlash();
|
||||||
} else if (preview.enableFlash()) {
|
} else {
|
||||||
isFlashEnabled = preview.enableFlash();
|
enableFlash();
|
||||||
toggleFlashBtn.setImageResource(R.mipmap.flash_on);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +90,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
toggleFlashBtn.setImageResource(R.mipmap.flash_off);
|
toggleFlashBtn.setImageResource(R.mipmap.flash_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableFlash() {
|
||||||
|
preview.enableFlash();
|
||||||
|
isFlashEnabled = true;
|
||||||
|
toggleFlashBtn.setImageResource(R.mipmap.flash_on);
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.shutter)
|
@OnClick(R.id.shutter)
|
||||||
public void shutterPressed() {
|
public void shutterPressed() {
|
||||||
if (isPhoto) {
|
if (isPhoto) {
|
||||||
@ -215,4 +222,14 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFlashAvailable(boolean available) {
|
||||||
|
if (available) {
|
||||||
|
toggleFlashBtn.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
toggleFlashBtn.setVisibility(View.INVISIBLE);
|
||||||
|
disableFlash();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
private static int currCameraId;
|
private static int currCameraId;
|
||||||
private static boolean isFlashEnabled;
|
private static boolean isFlashEnabled;
|
||||||
private static Camera.Parameters parameters;
|
private static Camera.Parameters parameters;
|
||||||
|
private static PreviewListener callback;
|
||||||
private static MediaRecorder recorder;
|
private static MediaRecorder recorder;
|
||||||
private static boolean isRecording;
|
private static boolean isRecording;
|
||||||
private static boolean isVideoMode;
|
private static boolean isVideoMode;
|
||||||
@ -45,10 +45,11 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Preview(Activity act, SurfaceView sv) {
|
public Preview(Activity act, SurfaceView sv, PreviewListener cb) {
|
||||||
super(act);
|
super(act);
|
||||||
|
|
||||||
activity = act;
|
activity = act;
|
||||||
|
callback = cb;
|
||||||
surfaceView = sv;
|
surfaceView = sv;
|
||||||
surfaceHolder = surfaceView.getHolder();
|
surfaceHolder = surfaceView.getHolder();
|
||||||
surfaceHolder.addCallback(this);
|
surfaceHolder.addCallback(this);
|
||||||
@ -95,6 +96,8 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
}
|
}
|
||||||
setupPreview();
|
setupPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback.setFlashAvailable(Utils.hasFlash(camera));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoMode)
|
if (isVideoMode)
|
||||||
@ -321,10 +324,6 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean enableFlash() {
|
public boolean enableFlash() {
|
||||||
if (!Utils.hasFlash(camera)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isFlashEnabled = true;
|
isFlashEnabled = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -397,4 +396,8 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
|
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface PreviewListener {
|
||||||
|
void setFlashAvailable(boolean available);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user