display the flash icon only when its really available

This commit is contained in:
tibbi
2016-06-12 23:13:54 +02:00
parent faa72cf25c
commit dff62f66d9
2 changed files with 31 additions and 11 deletions

View File

@ -19,11 +19,13 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.simplemobiletools.camera.Preview.PreviewListener;
import butterknife.BindView;
import butterknife.ButterKnife;
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.toggle_camera) ImageView toggleCameraBtn;
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
@ -49,7 +51,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
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));
viewHolder.addView(preview);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
@ -77,9 +79,8 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
public void toggleFlash() {
if (isFlashEnabled) {
disableFlash();
} else if (preview.enableFlash()) {
isFlashEnabled = preview.enableFlash();
toggleFlashBtn.setImageResource(R.mipmap.flash_on);
} else {
enableFlash();
}
}
@ -89,6 +90,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
toggleFlashBtn.setImageResource(R.mipmap.flash_off);
}
private void enableFlash() {
preview.enableFlash();
isFlashEnabled = true;
toggleFlashBtn.setImageResource(R.mipmap.flash_on);
}
@OnClick(R.id.shutter)
public void shutterPressed() {
if (isPhoto) {
@ -215,4 +222,14 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
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();
}
}
}