OSDN Git Service

767c22580de336afc40b3dc28495b2109f6c4d8d
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / ricohgr2 / operation / RicohGr2CameraButtonControl.java
1 package net.osdn.gokigen.gr2control.camera.ricohgr2.operation;
2
3 import android.support.annotation.NonNull;
4 import android.util.Log;
5
6 import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
7 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
8
9 /**
10  *
11  *
12  */
13 public class RicohGr2CameraButtonControl implements ICameraButtonControl
14 {
15     private final String TAG = toString();
16     private final String buttonControlUrl = "http://192.168.0.1/_gr";
17     private final String greenButtonUrl = "http://192.168.0.1/v1/params/camera";
18     private int timeoutMs = 6000;
19
20     /**
21      *
22      *
23      */
24     @Override
25     public boolean pushedButton(String code, boolean isLongPress)
26     {
27         return (pushButton(code, isLongPress));
28     }
29
30     /**
31      *
32      *
33      */
34     private boolean pushButton(@NonNull final String keyName, final boolean isLongPress)
35     {
36         Log.v(TAG, "pushButton()");
37         if (keyName.equals(ICameraButtonControl.SPECIAL_GREEN_BUTTON))
38         {
39             // Greenボタンの処理を入れる
40             return (processGreenButton(isLongPress));
41         }
42         try
43         {
44             Thread thread = new Thread(new Runnable()
45             {
46                 /**
47                  *
48                  *
49                  */
50                 @Override
51                 public void run()
52                 {
53                     try
54                     {
55                         String cmd = "cmd=" + keyName;
56                         if (isLongPress)
57                         {
58                             // ボタン長押しの場合...
59                             cmd = cmd + " 1";
60                         }
61                         String result = SimpleHttpClient.httpPost(buttonControlUrl, cmd, timeoutMs);
62                         if ((result == null)||(result.length() < 1)) {
63                             Log.v(TAG, "pushButton() reply is null. " + cmd);
64                         } else {
65                             Log.v(TAG, "pushButton() " + cmd + " result: " + result);
66                         }
67                     }
68                     catch (Exception e)
69                     {
70                         e.printStackTrace();
71                     }
72                 }
73             });
74             thread.start();
75         }
76         catch (Exception e)
77         {
78             e.printStackTrace();
79         }
80         return (true);
81     }
82
83     private boolean processGreenButton(boolean isLongPress)
84     {
85         Log.v(TAG, "processGreenButton()");
86         try
87         {
88             Thread thread = new Thread(new Runnable()
89             {
90                 /**
91                  *
92                  *
93                  */
94                 @Override
95                 public void run()
96                 {
97                     try
98                     {
99                         String cmd = "";
100                         String result = SimpleHttpClient.httpPut(greenButtonUrl, cmd, timeoutMs);
101                         if ((result == null)||(result.length() < 1)) {
102                             Log.v(TAG, "processGreenButton() reply is null.");
103                         } else {
104                             Log.v(TAG, "processGreenButton() result: " + result);
105                         }
106                     }
107                     catch (Exception e)
108                     {
109                         e.printStackTrace();
110                     }
111                 }
112             });
113             thread.start();
114         }
115         catch (Exception e)
116         {
117             e.printStackTrace();
118         }
119         return (true);
120     }
121 }