I want to trigger an imagebutton according to the value that gets stored in a variable.
For eg: Let variable be amount. Then if amount<10 and amount>50 then the imagebutton should be triggered.
Here, through imagebutton I'm turning on and off the flashlight. So, if the
amount>10 and <30 then flashlight turns on
amount>30 and <50 then flashlight turns off
Secondly, I'm getting my value in string form from a function, which is to be converted into integer and stored in amount variable.
Java code:
Integer amount;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d("bluetooth_torch", "onCreate()");
setContentView(R.layout.activity_bluetooth_torch);
mTorchOnOffButton = (ImageButton)findViewById(R.id.button_on_off);
isTorchOn = false;
Boolean isFlashAvailable = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!isFlashAvailable) {
AlertDialog alert = new AlertDialog.Builder(bluetooth_torch_Activity.this)
.create();
alert.setTitle("Error !!");
alert.setMessage("Your device doesn't support flash light!");
alert.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// closing the application
finish();
System.exit(0);
}
});
alert.show();
return;
}
mCameraManager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
try {
mCameraId = mCameraManager.getCameraIdList()[0];
} catch (CameraAccessException e) {
e.printStackTrace();
}
amount = Integer.parseInt(DATA);
mTorchOnOffButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (isTorchOn) {
turnOffFlashLight();
isTorchOn = false;
} else {
turnOnFlashLight();
isTorchOn = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}