Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / MainActivity.java
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file MainActivity.java
22
23 package org.iotivity.service.ppm;
24
25 import java.util.EnumSet;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.iotivity.base.ModeType;
30 import org.iotivity.base.OcConnectivityType;
31 import org.iotivity.base.OcException;
32 import org.iotivity.base.OcPlatform;
33 import org.iotivity.base.OcRepresentation;
34 import org.iotivity.base.OcResource;
35 import org.iotivity.base.PlatformConfig;
36 import org.iotivity.base.QualityOfService;
37 import org.iotivity.base.ServiceType;
38
39 import android.app.Activity;
40 import android.content.Context;
41 import android.os.Bundle;
42 import android.os.Handler;
43 import android.util.Log;
44 import android.view.View;
45 import android.widget.Button;
46 import android.widget.TextView;
47 import android.widget.Toast;
48 import android.widget.ToggleButton;
49
50 public class MainActivity extends Activity implements
51         android.widget.NumberPicker.OnValueChangeListener {
52     class S_demo_device {
53         public String m_name;
54         public String m_power;
55         public int    m_bright;
56         public int    m_color;
57         public String m_uri;
58     }
59
60     static S_demo_device               belkinplug;
61     static S_demo_device               gearplug;
62     static S_demo_device               hueplug;
63     static OcResource                  belkinResource;
64     static OcResource                  gearResource;
65     static OcResource                  hueResource;
66     static TextView                    belkintv;
67     static TextView                    geartv;
68     static TextView                    huetv;
69     static ToggleButton                Hue;
70     static android.widget.NumberPicker hue_color;
71     static Activity                    mActivity;
72     final private static String LOG_TAG = "PPMSampleApp : MainActivity";
73
74     PluginManager                      m_pm;
75
76     Button                             belkinstart;
77     Button                             belkingetPlugins;
78     Button                             belkingetstate;
79     Button                             belkinstop;
80     Button                             belkinrescan;
81     Button                             Belkin;
82
83     Button                             gearstart;
84     Button                             geargetPlugins;
85     Button                             geargetstate;
86     Button                             gearstop;
87     Button                             gearrescan;
88     Button                             Gear;
89
90     Button                             huestart;
91     Button                             huegetPlugins;
92     Button                             huegetstate;
93     Button                             huestop;
94     Button                             huerescan;
95
96     Context                            ctx;
97
98     String                             name;
99     String                             key;
100     String                             state;
101     String                             id;
102     Plugin[]                           user_plugin;
103     Map<Integer, Integer>              onValueChangefinalVal    = new HashMap<Integer, Integer>();
104     Map<Integer, Boolean>              onValueChangeThreadStart = new HashMap<Integer, Boolean>();
105     String[]                           np_h                     = new String[11];
106     
107
108     @Override
109     protected void onCreate(Bundle savedInstanceState) {
110
111         super.onCreate(savedInstanceState);
112         ctx = getApplicationContext();
113         m_pm = new PluginManager(ctx);
114
115         setContentView(R.layout.activity_main);
116         mActivity = this;
117         onValueChangeThreadStart.put(R.id.np_hue_color, false);
118         belkinplug = new S_demo_device();
119         gearplug = new S_demo_device();
120         hueplug = new S_demo_device();
121
122         for (int i = 0; i < np_h.length; i++) {
123             np_h[i] = Integer.toString(i);
124         }
125
126         hue_color = (android.widget.NumberPicker) findViewById(R.id.np_hue_color);
127         hue_color.setMaxValue(10);
128         hue_color.setMinValue(0);
129         hue_color.setDisplayedValues(np_h);
130         hue_color.setFocusable(true);
131         hue_color.setFocusableInTouchMode(true);
132         hue_color
133                 .setDescendantFocusability(android.widget.NumberPicker.FOCUS_BLOCK_DESCENDANTS);
134         hue_color.setOnValueChangedListener(this);
135
136         PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC,
137                 ModeType.CLIENT_SERVER, "0.0.0.0", 0, QualityOfService.LOW);
138
139         OcPlatform.Configure(cfg);
140
141         try {
142             FoundResource foundResource = new FoundResource();
143             OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY,
144                     EnumSet.of(OcConnectivityType.CT_DEFAULT), foundResource);
145         } catch (Exception e) {
146             Log.e(LOG_TAG, "Exception : " + e);
147         }
148
149         Belkin = (Button) findViewById(R.id.btn_belkin);
150         Belkin.setOnClickListener(new Button.OnClickListener() {
151             public void onClick(View v) {
152                 Log.i(LOG_TAG, "Belkin button click listener");
153                 OcRepresentation rep = new OcRepresentation();
154                 try {
155                     if (belkinplug.m_power == null) {
156                         Log.i(LOG_TAG, "m_power is null");
157                         belkinplug.m_power = "on";
158                         rep.setValue("power", "on");
159                     }
160                     if (belkinplug.m_power.equals("on")) {
161                         Toast.makeText(getApplicationContext(), "Off",
162                                 Toast.LENGTH_SHORT).show();
163                         Log.i(LOG_TAG, "belkin wemo off");
164                         rep.setValue("power", "off");
165                     } else if (belkinplug.m_power.equals("off")) {
166                         Toast.makeText(getApplicationContext(), "On",
167                                 Toast.LENGTH_SHORT).show();
168                         Log.i(LOG_TAG, "belkin wemo on");
169                         rep.setValue("power", "on");
170                     } else {
171                         rep.setValue("power", "on");
172                     }
173                     rep.setValue("name", "belkin");
174                     rep.setValue("uri", "/a/wemo");
175                     rep.setValue("brightness", 0);
176                     rep.setValue("color", 0);
177                 } catch (OcException e) {
178                     Log.e(LOG_TAG, e.getMessage());
179                 }
180                 OnPutBelkinplug onPut = new OnPutBelkinplug();
181                 if (belkinResource != null) {
182                     try {
183                         belkinResource.put(rep, new HashMap<String, String>(),
184                                 onPut);
185                     } catch (OcException e) {
186                         e.printStackTrace();
187                     }
188                 } else {
189                     Toast.makeText(getApplicationContext(), "Belkinplug null",
190                             Toast.LENGTH_SHORT).show();
191                     Log.i(LOG_TAG, "Belkinplug null");
192                 }
193             }
194         });
195
196         belkinstart = (Button) findViewById(R.id.Button01);
197         belkinstart.setOnClickListener(new Button.OnClickListener() {
198             public void onClick(View v) {
199                 Log.i(LOG_TAG, "start button click listener");
200                 m_pm.startPlugins("ResourceType", "device.smartplug");
201
202                 Handler handler = new Handler();
203                 handler.postDelayed(new Runnable() {
204                     @Override
205                     public void run() {
206                         Log.i(LOG_TAG, "run called!!!");
207                         FoundResource foundResource = new FoundResource();
208                         try {
209                             OcPlatform
210                                     .findResource(
211                                             "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.smartplug",
212                                             EnumSet.of(OcConnectivityType.CT_DEFAULT), foundResource);
213                         } catch (OcException e) {
214                             e.printStackTrace();
215                         }
216                     }
217                 }, 3000);
218             }
219         });
220
221         belkinstop = (Button) findViewById(R.id.Button02);
222         belkinstop.setOnClickListener(new Button.OnClickListener() {
223             public void onClick(View v) {
224                 Log.i(LOG_TAG, "stop button click listener");
225                 m_pm.stopPlugins("ResourceType", "device.smartplug");
226                 belkinResource = null;
227                 try {
228                     java.lang.Thread.sleep(2000);
229                 } catch (InterruptedException e) {
230                     e.printStackTrace();
231                 }
232             }
233         });
234
235         belkingetPlugins = (Button) findViewById(R.id.Button03);
236         belkingetPlugins.setOnClickListener(new Button.OnClickListener() {
237             public void onClick(View v) {
238                 Log.i(LOG_TAG, "getPlugins button click listener");
239                 user_plugin = m_pm.getPlugins();
240                 // key = "name";
241                 state = "";
242                 id = "";
243
244                 for (int i = 0; i < user_plugin.length; i++) {
245                     System.out.println("value name " + user_plugin[i].getName());
246                     System.out.println("value id " + user_plugin[i].getID());
247                     // name = user_plugin[i].getID();
248                 }
249             }
250         });
251
252         belkingetPlugins = (Button) findViewById(R.id.Button04);
253         belkingetPlugins.setOnClickListener(new Button.OnClickListener() {
254             public void onClick(View v) {
255                 Log.i(LOG_TAG, "getState click listener");
256                 state = m_pm.getState("wemo");
257                 if (state == "")
258                     state = "null";
259                 System.out.println("state: " + state);
260                 try {
261                     Thread.sleep(2000);
262                 } catch (InterruptedException e) {
263                     e.printStackTrace();
264                 }
265             }
266         });
267
268         belkinrescan = (Button) findViewById(R.id.Button05);
269         belkinrescan.setOnClickListener(new Button.OnClickListener() {
270             public void onClick(View v) {
271                 Log.i(LOG_TAG, "Rescan Plugin click listener");
272                 m_pm.rescanPlugin();
273                 try {
274                     Thread.sleep(2000);
275                 } catch (InterruptedException e) {
276                     e.printStackTrace();
277                 }
278             }
279         });
280
281         Gear = (Button) findViewById(R.id.btn_gear);
282         Gear.setOnClickListener(new Button.OnClickListener() {
283             public void onClick(View v) {
284                 Log.i(LOG_TAG, "Gear button click listener");
285                 OcRepresentation rep = new OcRepresentation();
286                 
287                 try{   
288                     rep.setValue("power", "Happy New Year!");
289                     rep.setValue("name", "gear");
290                     rep.setValue("uri", "/a/galaxy/gear");
291                     rep.setValue("brightness", 0);
292                     rep.setValue("color", 0);
293                 } catch (OcException e) {
294                     Log.e(LOG_TAG, e.getMessage());
295                 }
296                 
297                 if (gearResource != null) {
298                     Toast.makeText(getApplicationContext(),
299                             "Send Noti. to Gear", Toast.LENGTH_SHORT).show();
300                     Log.i(LOG_TAG, "Send Noti. to Gear");
301                     try {
302                         OnPutGear onPut = new OnPutGear();
303                         gearResource.put(rep, new HashMap<String, String>(),
304                                 onPut);
305                     } catch (OcException e) {
306                         e.printStackTrace();
307                     }
308                 } else {
309                     Toast.makeText(getApplicationContext(), "Gear is null",
310                             Toast.LENGTH_SHORT).show();
311                     Log.i(LOG_TAG, "Gear is null");
312                 }
313             }
314         });
315
316         gearstart = (Button) findViewById(R.id.Button06);
317         gearstart.setOnClickListener(new Button.OnClickListener() {
318             public void onClick(View v) {
319                 Log.i(LOG_TAG, "start button click listener");
320                 m_pm.startPlugins("ResourceType", "device.notify");
321
322                 Handler handler = new Handler();
323                 handler.postDelayed(new Runnable() {
324                     @Override
325                     public void run() {
326                         Log.i(LOG_TAG, "run called!!!");
327                         FoundResource foundResource = new FoundResource();
328                         try {
329                             OcPlatform
330                             .findResource(
331                                     "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.notify",
332                                     EnumSet.of(OcConnectivityType.CT_DEFAULT), foundResource);
333                         } catch (OcException e) {
334                             e.printStackTrace();
335                         }
336                     }
337                 }, 3000);
338             }
339         });
340
341         gearstop = (Button) findViewById(R.id.Button07);
342         gearstop.setOnClickListener(new Button.OnClickListener() {
343             public void onClick(View v) {
344                 Log.i(LOG_TAG, "stop button click listener");
345                 m_pm.stopPlugins("ResourceType", "device.notify");
346                 gearResource = null;
347                 try {
348                     java.lang.Thread.sleep(2000);
349                 } catch (InterruptedException e) {
350                     e.printStackTrace();
351                 }
352             }
353         });
354
355         geargetPlugins = (Button) findViewById(R.id.Button08);
356         geargetPlugins.setOnClickListener(new Button.OnClickListener() {
357             public void onClick(View v) {
358                 Log.i(LOG_TAG, "getPlugins button click listener");
359                 user_plugin = m_pm.getPlugins();
360                 state = "";
361                 id = "";
362
363                 for (int i = 0; i < user_plugin.length; i++) {
364                     System.out.println("value name " + user_plugin[i].getName());
365                     System.out.println("value id " + user_plugin[i].getID());
366                     name = user_plugin[i].getID();
367                 }
368             }
369         });
370
371         geargetPlugins = (Button) findViewById(R.id.Button09);
372         geargetPlugins.setOnClickListener(new Button.OnClickListener() {
373             public void onClick(View v) {
374                 Log.i(LOG_TAG, "getState click listener");
375                 state = m_pm.getState("gearnoti");
376                 if (state == "")
377                     state = "null";
378                 System.out.println("state: " + state);
379                 try {
380                     Thread.sleep(2000);
381                 } catch (InterruptedException e) {
382                     e.printStackTrace();
383                 }
384             }
385         });
386
387         gearrescan = (Button) findViewById(R.id.Button10);
388         gearrescan.setOnClickListener(new Button.OnClickListener() {
389             public void onClick(View v) {
390                 Log.i(LOG_TAG, "Rescan Plugin click listener");
391                 m_pm.rescanPlugin();
392                 try {
393                     Thread.sleep(2000);
394                 } catch (InterruptedException e) {
395                     e.printStackTrace();
396                 }
397             }
398         });
399
400         Hue = (ToggleButton) findViewById(R.id.tbtn_hue_power);
401         Hue.setOnClickListener(new ToggleButton.OnClickListener() {
402             public void onClick(View v) {
403                 Log.i(LOG_TAG, "Hue button click listener");
404                 OcRepresentation rep = new OcRepresentation();
405                 ToggleButton t = (ToggleButton) v;
406                 if (t.isChecked()) {
407                     Toast.makeText(getApplicationContext(), "Hue ON",
408                             Toast.LENGTH_SHORT).show();
409                     Log.i(LOG_TAG, "Hue ON");
410                     if (hueplug.m_bright == 0) {
411                         Log.e(LOG_TAG, "hueplug m_bright is 0");
412                         hueplug.m_bright = 128;
413                     }
414                     try {
415                         rep.setValue("power", "on");
416                         rep.setValue("name", "hue");
417                         rep.setValue("uri", "/a/huebulb");
418                         rep.setValue("brightness", hueplug.m_bright);
419                         rep.setValue("color", hueplug.m_color);
420                     } catch (OcException e) {
421                         Log.e(LOG_TAG, e.getMessage());
422                     }
423
424                     OnPutHuebulb onPut = new OnPutHuebulb();
425                     if (hueResource != null) {
426                         try {
427                             hueResource.put(rep, new HashMap<String, String>(),
428                                     onPut);
429                         } catch (OcException e) {
430                             e.printStackTrace();
431                         }
432                     } else {
433                         Toast.makeText(getApplicationContext(),
434                                 "HueResource null", Toast.LENGTH_SHORT).show();
435                         Log.i(LOG_TAG, "HueResource null");
436                     }
437                 } else {
438                     Toast.makeText(getApplicationContext(), "Hue OFF",
439                             Toast.LENGTH_SHORT).show();
440                     Log.i(LOG_TAG, "Hue OFF");
441                     if (hueplug.m_bright == 0) {
442                         Log.e(LOG_TAG, "hueplug m_bright is 0");
443                         hueplug.m_bright = 128;
444                     }
445                     try {
446                         rep.setValue("power", "off");
447                         rep.setValue("name", "hue");
448                         rep.setValue("uri", "/a/huebulb");
449                         rep.setValue("brightness", hueplug.m_bright);
450                         rep.setValue("color", hueplug.m_color);
451                     } catch (OcException e) {
452                         Log.e(LOG_TAG, e.getMessage());
453                     }
454
455                     OnPutHuebulb onPut = new OnPutHuebulb();
456
457                     if (hueResource != null) {
458                         try {
459                             hueResource.put(rep, new HashMap<String, String>(),
460                                     onPut);
461                         } catch (OcException e) {
462                             e.printStackTrace();
463                             Log.e(LOG_TAG, e.getMessage());
464                         }
465                     } else {
466                         Toast.makeText(getApplicationContext(),
467                                 "HueResource null", Toast.LENGTH_SHORT).show();
468                         Log.i(LOG_TAG, "HueResource null");
469                     }
470                 }
471             }
472         });
473
474         huestart = (Button) findViewById(R.id.Button11);
475         huestart.setOnClickListener(new Button.OnClickListener() {
476             public void onClick(View v) {
477                 Log.i(LOG_TAG, "start button click listener");
478                 m_pm.startPlugins("ResourceType", "device.light");
479
480                 Handler handler = new Handler();
481                 handler.postDelayed(new Runnable() {
482                     @Override
483                     public void run() {
484                         Log.i(LOG_TAG, "run called!!!");
485                         FoundResource foundResource = new FoundResource();
486                         try {
487                             OcPlatform
488                             .findResource(
489                                     "", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "device.light",
490                                     EnumSet.of(OcConnectivityType.CT_DEFAULT), foundResource);
491                         } catch (OcException e) {
492                             e.printStackTrace();
493                         }
494                     }
495                 }, 3000);
496             }
497         });
498
499         huestop = (Button) findViewById(R.id.Button12);
500         huestop.setOnClickListener(new Button.OnClickListener() {
501             public void onClick(View v) {
502                 Log.i(LOG_TAG, "stop button click listener");
503                 m_pm.stopPlugins("ResourceType", "device.light");
504                 hueResource = null;
505                 try {
506                     java.lang.Thread.sleep(2000);
507                 } catch (InterruptedException e) {
508                     e.printStackTrace();
509                 }
510             }
511         });
512
513         huegetPlugins = (Button) findViewById(R.id.Button13);
514         huegetPlugins.setOnClickListener(new Button.OnClickListener() {
515             public void onClick(View v) {
516                 Log.i(LOG_TAG, "getPlugins button click listener");
517                 user_plugin = m_pm.getPlugins();
518                 key = "name";
519                 state = "";
520                 id = "";
521
522                 for (int i = 0; i < user_plugin.length; i++) {
523                     System.out.println("value name " + user_plugin[i].getName());
524                     System.out.println("value id " + user_plugin[i].getID());
525                     name = user_plugin[i].getID();
526                 }
527             }
528         });
529
530         huegetPlugins = (Button) findViewById(R.id.Button14);
531         huegetPlugins.setOnClickListener(new Button.OnClickListener() {
532             public void onClick(View v) {
533                 Log.i(LOG_TAG, "getState click listener");
534                 state = m_pm.getState("hue");
535                 if (state == "")
536                     state = "null";
537                 System.out.println("state: " + state);
538                 try {
539                     Thread.sleep(2000);
540                 } catch (InterruptedException e) {
541                     e.printStackTrace();
542                 }
543             }
544         });
545
546         huerescan = (Button) findViewById(R.id.Button15);
547         huerescan.setOnClickListener(new Button.OnClickListener() {
548             public void onClick(View v) {
549                 Log.i(LOG_TAG, "Rescan Plugin click listener");
550                 m_pm.rescanPlugin();
551                 try {
552                     Thread.sleep(2000);
553                 } catch (InterruptedException e) {
554                     e.printStackTrace();
555                 }
556             }
557         });
558     }
559
560     static public void updateConnectStatus(String device, boolean status) {
561         if (device.equals("belkinplug")) {
562             if (status) {
563                 Log.i(LOG_TAG, "belkingplug status green");
564                 Toast.makeText(mActivity.getApplicationContext(),
565                         "Belkin Connected", Toast.LENGTH_SHORT).show();
566                 Log.i(LOG_TAG, "Belkin Connected");
567             } else {
568                 Log.i(LOG_TAG, "belkingplug status gray");
569                 Toast.makeText(mActivity.getApplicationContext(),
570                         "Belkin Disonnected", Toast.LENGTH_SHORT).show();
571                 Log.i(LOG_TAG, "Belkin Disonnected");
572             }
573         } else if (device.equals("gear")) {
574             if (status) {
575                 Log.i(LOG_TAG, "gear status green");
576                 Toast.makeText(mActivity.getApplicationContext(),
577                         "Gear Connected", Toast.LENGTH_SHORT).show();
578                 Log.i(LOG_TAG, "Gear Connected");
579             } else {
580                 Log.i(LOG_TAG, "gear status gray");
581                 Toast.makeText(mActivity.getApplicationContext(),
582                         "Gear Disconnected", Toast.LENGTH_SHORT).show();
583                 Log.i(LOG_TAG, "Gear Disonnected");
584             }
585         } else if (device.equals("huebulb")) {
586             if (status) {
587                 Log.i(LOG_TAG, "huebulb status green");
588                 Toast.makeText(mActivity.getApplicationContext(),
589                         "Hue Connected", Toast.LENGTH_SHORT).show();
590                 Log.i(LOG_TAG, "Hue Connected");
591             } else {
592                 Log.i(LOG_TAG, "huebulb status gray");
593                 Toast.makeText(mActivity.getApplicationContext(),
594                         "Hue Disconnected", Toast.LENGTH_SHORT).show();
595                 Log.i(LOG_TAG, "Hue Disconnected");
596             }
597
598             if (hueplug.m_power.equals("on")) {
599                 Hue.setChecked(true);
600             } else {
601                 Hue.setChecked(false);
602             }
603         }
604     }
605
606     static public void updateBelkinStatus() {
607         updateConnectStatus("belkinplug", true);
608     }
609
610     static public void updateGearStatus() {
611         updateConnectStatus("gear", true);
612     }
613
614     static public void updateHuebulbStatus() {
615         updateConnectStatus("huebulb", true);
616     }
617
618     @Override
619     protected void onResume() {
620         Log.i(LOG_TAG, "onResume()");
621         super.onResume();
622     }
623
624     @Override
625     protected void onPause() {
626         Log.i(LOG_TAG, "onPause()");
627         super.onPause();
628         finish();
629     }
630
631     @Override
632     protected void onStop() {
633         Log.i(LOG_TAG, "onStop()");
634         super.onStop();
635     }
636
637     @Override
638     protected void onDestroy() {
639         Log.i(LOG_TAG, "onDestroy()");
640         System.exit(1);
641         super.onDestroy();
642     }
643
644     private class ValueChangeThread extends Thread {
645         int idx;
646
647         public ValueChangeThread(int idx) {
648             this.idx = idx;
649         }
650
651         public void run() {
652             onValueChangeThreadStart.put(idx, true);
653             try {
654                 sleep(1000, 0);
655             } catch (Exception e) {
656                 Log.i(LOG_TAG, "waitForFinal exception : " + e);
657             }
658             Log.i(LOG_TAG, "Final Value for NUMBERPICKER[" + idx + "] : "
659                     + onValueChangefinalVal.get(idx));
660
661             if (idx == R.id.np_hue_color) {
662                 hueplug.m_color = 6300 * onValueChangefinalVal.get(idx);
663                 Log.i(LOG_TAG, "m_color = " + hueplug.m_color);
664
665                 OcRepresentation rep = new OcRepresentation();
666                 if (hueplug.m_power == null) {
667                     hueplug.m_power = "on";
668                 }
669                 if (hueplug.m_bright == 0) {
670                     hueplug.m_bright = 128;
671                 }
672                 try{
673                     rep.setValue("power", hueplug.m_power);
674                     rep.setValue("name", "huebulb");
675                     rep.setValue("uri", "/a/huebulb");
676                     rep.setValue("brightness", hueplug.m_bright = 180);
677                     rep.setValue("color", hueplug.m_color);
678                 } catch (OcException e) {
679                     Log.e(LOG_TAG, e.getMessage());
680                 }
681
682                 OnPutHuebulb onPut = new OnPutHuebulb();
683                 if (hueResource != null) {
684                     Log.i(LOG_TAG, "huebulbResource is not null");
685                     try {
686                         hueResource.put(rep, new HashMap<String, String>(),
687                                 onPut);
688                     } catch (OcException e) {
689                         e.printStackTrace();
690                     }
691                 } else {
692                     Log.i(LOG_TAG, "huebulbResource is null");
693                 }
694             }
695             onValueChangeThreadStart.put(idx, false);
696         }
697     }
698
699     public void onValueChange(android.widget.NumberPicker picker, int oldVal,
700             int newVal) {
701         final int pickerIdx = picker.getId();
702
703         Thread waitForFinal = new ValueChangeThread(pickerIdx);
704         if (onValueChangeThreadStart.get(pickerIdx) == false)
705             waitForFinal.start();
706
707         onValueChangefinalVal.put(pickerIdx, newVal);
708     }
709 }