- alarmSwitch = (Switch) findViewById(R.id.alarmSwitch);
-
- alarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
-
- String strAlarm = "alarm";
- IoTString iotAlarm = new IoTString(strAlarm);
- String strStatusOn = "1";
- IoTString iotStatusOn = new IoTString(strStatusOn);
- String strStatusOff = "0";
- IoTString iotStatusOff = new IoTString(strStatusOff);
-
- try {
- if (bChecked) {
-
- try {
- t1.update();
- t1.startTransaction();
- t1.addKV(iotAlarm, iotStatusOn);
- t1.commitTransaction();
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- Log.e("ALI::::", sw.toString());
- }
-
- } else {
-
- try {
- t1.update();
- t1.startTransaction();
- t1.addKV(iotAlarm, iotStatusOff);
- t1.commitTransaction();
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- Log.e("ALI::::", sw.toString());
- }
+ alarmButton = (Button) findViewById(R.id.alarmButton);
+ alarmButton.setOnClickListener(this);
+
+ handler.post(runnable);
+ }
+
+ public void onClick(View v) {
+
+ if (v == alarmButton) {
+ String strAlarm = "alarm";
+ IoTString iotAlarm = new IoTString(strAlarm);
+ String strStatusOn = "1";
+ IoTString iotStatusOn = new IoTString(strStatusOn);
+ String strStatusOff = "0";
+ IoTString iotStatusOff = new IoTString(strStatusOff);
+
+ Log.d("RAHMADI:::::", "Button pressed!");
+
+ try {
+ mutex.acquire();
+ if (!alarmOn) {
+
+ try {
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(iotAlarm, iotStatusOn);
+ t1.commitTransaction();
+ alarmOn = true;
+ alarmButton.setText("ON");
+ } catch (Exception e) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+ Log.e("ALI::::", sw.toString());