mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-03-03 02:58:01 +01:00
turn the flashlight on at app start
This commit is contained in:
parent
758d8097c6
commit
cedd523eb1
@ -18,23 +18,32 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
setupCamera();
|
||||
|
||||
setupToggleButton();
|
||||
setupCamera();
|
||||
toggleFlashlight();
|
||||
}
|
||||
|
||||
private void setupToggleButton() {
|
||||
toggleBtn = (ImageView) findViewById(R.id.toggle_btn);
|
||||
toggleBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isFlashlightOn = !isFlashlightOn;
|
||||
|
||||
if (isFlashlightOn) {
|
||||
enableFlashlight();
|
||||
} else {
|
||||
disableFlashlight();
|
||||
}
|
||||
toggleFlashlight();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleFlashlight() {
|
||||
isFlashlightOn = !isFlashlightOn;
|
||||
|
||||
if (isFlashlightOn) {
|
||||
enableFlashlight();
|
||||
} else {
|
||||
disableFlashlight();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupCamera() {
|
||||
if (camera == null) {
|
||||
camera = Camera.open();
|
||||
|
Loading…
x
Reference in New Issue
Block a user