This Flashlight Torch is very simple based on computer's 0 1. Where 0 = Off and 1 = On !
Its works even when your screen is off or you turn off your screen to save power. It is having Bright LED algorithm which ensures you the Bright Flash Light. Being eco friendly, It uses black background to save energy.
State of the art flash icon, opens in fraction of second and keep lights on until you turn it off.
NOTE : If you want to run app in background just open Flashlight torch - Bright LED, which turn on automatically, Press home button and Flashlight Torch will be minimised.
If you encounter any issue while turning off.Then simply open the app Press Back button on your phone. Light will be off.
Here is the code How it works :
------------->>>>>>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSwitch = (ImageButton) findViewById(R.id.btnSwitch);
// get the camera
getCamera();
toggleButtonImage();
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn)
{
turnOffFlash();
} else
turnOnFlash();
}
}
});
}
// Get the camera
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Failed to Open", e.getMessage());
}
}
}
// Turning On flash
private void turnOnFlash() {
if (!isFlashOn) {
if (camera == null || params == null) {
return;
}
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
// changing button/switch image
toggleButtonImage();
}
}
// Turning Off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
// changing button/switch image
toggleButtonImage();
}
private void toggleButtonImage(){
if(isFlashOn){
btnSwitch.setImageResource(R.drawable.btn_switch_on);
}else{
btnSwitch.setImageResource(R.drawable.btn_switch_off);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onRestart() {
super.onRestart();
}
@Override
protected void onResume() {
super.onResume();
if(hasFlash)
turnOnFlash();
}
@Override
protected void onStart() {
super.onStart();
getCamera();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
if (camera != null) {
camera.release();
camera = null;
}
Log.d("Camera","Back Pressed");
}
@Override
protected void onStop() {
super.onStop();
}
}
********************************************************
This is the codes Flashligh Torch - Bright LED is using !
If you need your app custom designed for you. Just Drop me mail with Subject :
"Modify Flashlight App for me"
Give your two pics for light_on and light_off Images!
Thanks !