1 package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper;
3 import android.support.annotation.NonNull;
4 import android.util.Log;
6 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
7 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
8 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
9 import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
11 import java.util.ArrayList;
12 import java.util.List;
18 public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatus
20 private final String TAG = toString();
21 private final String statusCheckUrl = "http://192.168.0.1/v1/props";
22 private final String statusSetUrl = "http://192.168.0.1/v1/params/camera";
23 private final String grCommandUrl = "http://192.168.0.1/_gr";
24 private final int sleepMs;
26 private int timeoutMs = 5000;
27 private boolean whileFetching = false;
28 private RicohGr2StatusHolder statusHolder;
34 RicohGr2StatusChecker(int sleepMs)
36 this.sleepMs = sleepMs;
44 public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
46 Log.v(TAG, "startStatusWatch()");
49 this.statusHolder = new RicohGr2StatusHolder(notifier);
50 Thread thread = new Thread(new Runnable()
57 start(statusCheckUrl);
78 public void stoptStatusWatch()
80 Log.v(TAG, "stoptStatusWatch()");
81 whileFetching = false;
88 private void start(@NonNull final String watchUrl)
92 Log.v(TAG, "start() already starting.");
99 Thread thread = new Thread(new Runnable()
104 Log.d(TAG, "Start status watch.");
105 while (whileFetching)
109 statusHolder.updateStatus(SimpleHttpClient.httpGet(watchUrl, timeoutMs));
110 Thread.sleep(sleepMs);
117 Log.v(TAG, "STATUS WATCH STOPPED.");
129 public @NonNull List<String> getStatusList(@NonNull final String key)
133 if (statusHolder == null)
135 return (new ArrayList<>());
137 String listKey = key + "List";
138 return (statusHolder.getAvailableItemList(listKey));
144 return (new ArrayList<>());
148 public String getStatus(@NonNull String key)
152 if (statusHolder == null)
156 return (statusHolder.getItemStatus(key));
166 public void setStatus(@NonNull final String key, @NonNull final String value)
168 Thread thread = new Thread(new Runnable() {
173 String postData = key + "=" + value;
174 String response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
175 Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
177 // GR専用コマンドで、画面表示をリフレッシュ
178 response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
179 Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");