• R/O
  • HTTP
  • SSH
  • HTTPS

A01d: Commit

OPC(Olympus Air)用望遠鏡アプリ。


Commit MetaInfo

Révisionc78a60d4827ea53fec97373ec4d4cdcbabbc8a49 (tree)
l'heure2018-06-18 00:35:07
AuteurMRSa <mrsa@myad...>
CommiterMRSa

Message de Log

SONY APIの呼び出しのための処理を追加する準備。

Change Summary

Modification

--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/ISonyInterfaceProvider.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/ISonyInterfaceProvider.java
@@ -8,6 +8,7 @@ import net.osdn.gokigen.a01d.camera.ILiveViewControl;
88 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
99 import net.osdn.gokigen.a01d.camera.sony.wrapper.IDisplayInjector;
1010 import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyApiService;
11+import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraApi;
1112 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
1213
1314 import java.util.List;
@@ -23,4 +24,5 @@ public interface ISonyInterfaceProvider
2324 ICaptureControl getCaptureControl();
2425 IDisplayInjector getDisplayInjector();
2526 List<String> getApiCommands();
27+ ISonyCameraApi getCameraApi();
2628 }
--- /dev/null
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SendRequestDialog.java
@@ -0,0 +1,185 @@
1+package net.osdn.gokigen.a01d.camera.sony.cameraproperty;
2+
3+import android.app.Activity;
4+import android.app.AlertDialog;
5+import android.app.Dialog;
6+import android.support.v4.app.DialogFragment;
7+import android.content.DialogInterface;
8+import android.os.Bundle;
9+import android.support.annotation.NonNull;
10+import android.support.annotation.Nullable;
11+import android.util.Log;
12+import android.view.LayoutInflater;
13+import android.view.View;
14+import android.widget.AdapterView;
15+import android.widget.ArrayAdapter;
16+import android.widget.EditText;
17+import android.widget.Spinner;
18+import android.widget.TextView;
19+
20+import net.osdn.gokigen.a01d.R;
21+import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraApi;
22+
23+
24+/**
25+ *
26+ *
27+ */
28+public class SendRequestDialog extends DialogFragment
29+{
30+ private final String TAG = toString();
31+ private ISonyCameraApi cameraApi;
32+ private String method = "";
33+ private int selectedPosition = 0;
34+ private SendRequestDialog.Callback callback = null;
35+ Dialog myDialog = null;
36+
37+ /**
38+ *
39+ *
40+ */
41+ public static SendRequestDialog newInstance(@NonNull ISonyCameraApi cameraApi, @NonNull String method, @Nullable SendRequestDialog.Callback callback)
42+ {
43+ SendRequestDialog instance = new SendRequestDialog();
44+ instance.prepare(cameraApi, method, callback);
45+
46+ // パラメータはBundleにまとめておく
47+ Bundle arguments = new Bundle();
48+ arguments.putString("method", method);
49+ //arguments.putString("message", message);
50+ instance.setArguments(arguments);
51+
52+ return (instance);
53+ }
54+
55+ /**
56+ *
57+ *
58+ */
59+ private void prepare(@NonNull ISonyCameraApi cameraApi,@NonNull String method, @Nullable SendRequestDialog.Callback callback)
60+ {
61+ this.cameraApi = cameraApi;
62+ this.method = method;
63+ this.callback = callback;
64+ }
65+
66+ /**
67+ *
68+ *
69+ */
70+ @Override
71+ public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
72+ {
73+ final Activity activity = getActivity();
74+
75+ // 確認ダイアログの生成
76+ //final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
77+ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
78+
79+ // Get the layout inflater
80+ LayoutInflater inflater = activity.getLayoutInflater();
81+ final View alertView = inflater.inflate(R.layout.request_edit_layout, null, false);
82+ alertDialog.setView(alertView);
83+
84+ alertDialog.setIcon(R.drawable.ic_linked_camera_black_24dp);
85+ alertDialog.setTitle("API : " + method);
86+ final Spinner spinner = alertView.findViewById(R.id.spinner_selection_service);
87+ final TextView methodName = alertView.findViewById(R.id.method_name);
88+ final EditText parameter = alertView.findViewById(R.id.edit_parameter);
89+ final EditText version = alertView.findViewById(R.id.edit_version);
90+ try
91+ {
92+ methodName.setText("");
93+ version.setText(activity.getString(R.string.dialog_version_hint));
94+ ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item);
95+ adapter.addAll(cameraApi.getSonyApiServiceList());
96+ spinner.setAdapter(adapter);
97+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
98+ {
99+ @Override
100+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
101+ {
102+ Log.v(TAG, "onItemSelected : " + position + " (" + id + ")");
103+ selectedPosition = position;
104+ }
105+
106+ @Override
107+ public void onNothingSelected(AdapterView<?> parent)
108+ {
109+ Log.v(TAG, "onNothingSelected");
110+ }
111+ });
112+ }
113+ catch (Exception e)
114+ {
115+ e.printStackTrace();
116+ }
117+ alertDialog.setCancelable(true);
118+
119+ // ボタンを設定する(実行ボタン)
120+ alertDialog.setPositiveButton(activity.getString(R.string.dialog_positive_execute),
121+ new DialogInterface.OnClickListener() {
122+ public void onClick(DialogInterface dialog, int which)
123+ {
124+ try
125+ {
126+ Activity activity = getActivity();
127+ if (activity != null)
128+ {
129+ if (callback != null)
130+ {
131+ callback.sendRequest((String) spinner.getAdapter().getItem(selectedPosition), method, parameter.getText().toString(), version.getText().toString());
132+ }
133+ }
134+ }
135+ catch (Exception e)
136+ {
137+ e.printStackTrace();
138+ if (callback != null)
139+ {
140+ callback.cancelled();
141+ }
142+ }
143+ dialog.dismiss();
144+ }
145+ });
146+
147+ // ボタンを設定する (キャンセルボタン)
148+ alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
149+ new DialogInterface.OnClickListener() {
150+ public void onClick(DialogInterface dialog, int which) {
151+ if (callback != null)
152+ {
153+ callback.cancelled();
154+ }
155+ dialog.cancel();
156+ }
157+ });
158+
159+ // 確認ダイアログを応答する
160+ myDialog = alertDialog.create();
161+ return (myDialog);
162+ }
163+
164+
165+ @Override
166+ public void onPause()
167+ {
168+ super.onPause();
169+ Log.v(TAG, "AlertDialog::onPause()");
170+ if (myDialog != null)
171+ {
172+ myDialog.cancel();
173+ }
174+ }
175+
176+ /**
177+ * コールバックインタフェース
178+ *
179+ */
180+ public interface Callback
181+ {
182+ void sendRequest(String service, String apiName, String parameter, String version); // OKを選択したとき
183+ void cancelled(); // キャンセルしたとき
184+ }
185+}
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SonyCameraApiListFragment.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SonyCameraApiListFragment.java
@@ -1,10 +1,12 @@
11 package net.osdn.gokigen.a01d.camera.sony.cameraproperty;
22
3+import android.app.Activity;
34 import android.content.Intent;
45 import android.os.Bundle;
56 import android.support.annotation.NonNull;
67 import android.support.annotation.Nullable;
78 import android.support.v4.app.FragmentActivity;
9+import android.support.v4.app.FragmentManager;
810 import android.support.v4.app.ListFragment;
911 import android.support.v7.app.ActionBar;
1012 import android.support.v7.app.AppCompatActivity;
@@ -24,10 +26,11 @@ import net.osdn.gokigen.a01d.R;
2426 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
2527
2628 import java.util.ArrayList;
29+import java.util.Arrays;
2730 import java.util.List;
2831
2932
30-public class SonyCameraApiListFragment extends ListFragment
33+public class SonyCameraApiListFragment extends ListFragment implements SendRequestDialog.Callback
3134 {
3235 private final String TAG = toString();
3336 private ArrayAdapter<String> adapter;
@@ -251,12 +254,65 @@ public class SonyCameraApiListFragment extends ListFragment
251254 try
252255 {
253256 ListAdapter listAdapter = l.getAdapter();
254- String apiName = (String) listAdapter.getItem(position);
257+ final String apiName = (String) listAdapter.getItem(position);
258+ final SendRequestDialog.Callback apiCallback = this;
255259 Log.v(TAG, "onListItemClick() [" + position + "] " + apiName);
260+ Activity activity = getActivity();
261+ if (activity != null)
262+ {
263+ activity.runOnUiThread(new Runnable()
264+ {
265+ @Override
266+ public void run()
267+ {
268+ SendRequestDialog dialog = SendRequestDialog.newInstance(interfaceProvider.getSonyInterface().getCameraApi(), apiName, apiCallback);
269+ FragmentManager manager = getFragmentManager();
270+ String tag = "dialog";
271+ if (manager != null)
272+ {
273+ dialog.show(manager, tag);
274+ }
275+ }
276+ });
277+ }
256278 }
257279 catch (Exception e)
258280 {
259281 e.printStackTrace();
260282 }
261283 }
284+
285+ /**
286+ * API のコマンドを発行する。
287+ *
288+ * ※ 注意:パラメータはカンマ区切りで複数個を入力してもらう予定
289+ *
290+ */
291+ @Override
292+ public void sendRequest(String service, String apiName, String parameter, String version)
293+ {
294+ String[] parameterItems = parameter.split(",");
295+
296+ StringBuilder logBuilder = new StringBuilder();
297+ logBuilder.append("sendRequest(");
298+ logBuilder.append(service);
299+ logBuilder.append(", ");
300+ logBuilder.append(apiName);
301+ logBuilder.append(", [ ");
302+ for (int index = 0; index < parameterItems.length; index++)
303+ {
304+ logBuilder.append(parameterItems[index]);
305+ logBuilder.append(" ");
306+ }
307+ logBuilder.append("], ");
308+ logBuilder.append(version);
309+ logBuilder.append(");");
310+ Log.v(TAG, logBuilder.toString());
311+ }
312+
313+ @Override
314+ public void cancelled()
315+ {
316+ Log.v(TAG, "cancelled()");
317+ }
262318 }
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/ISonyCameraApi.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/ISonyCameraApi.java
@@ -5,6 +5,8 @@ import android.support.annotation.NonNull;
55 import org.json.JSONArray;
66 import org.json.JSONObject;
77
8+import java.util.List;
9+
810 public interface ISonyCameraApi
911 {
1012 JSONObject getAvailableApiList();
@@ -53,4 +55,7 @@ public interface ISonyCameraApi
5355
5456 JSONObject startStreaming();
5557 JSONObject stopStreaming();
58+
59+ List<String> getSonyApiServiceList();
60+ JSONObject callGenericSonyApiMethod(@NonNull String service, @NonNull String method, @NonNull JSONArray params, @NonNull String version);
5661 }
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/SonyCameraApi.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/SonyCameraApi.java
@@ -7,6 +7,8 @@ import net.osdn.gokigen.a01d.camera.sony.wrapper.utils.SimpleHttpClient;
77
88 import org.json.JSONArray;
99 import org.json.JSONObject;
10+
11+import java.util.ArrayList;
1012 import java.util.List;
1113
1214 class SonyCameraApi implements ISonyCameraApi
@@ -479,6 +481,32 @@ class SonyCameraApi implements ISonyCameraApi
479481
480482 }
481483
484+ @Override
485+ public List<String> getSonyApiServiceList()
486+ {
487+ try
488+ {
489+ List<String> serviceList = new ArrayList<>();
490+ List<ISonyApiService> services = sonyCamera.getApiServices();
491+ for (ISonyApiService apiService : services)
492+ {
493+ serviceList.add(apiService.getName());
494+ }
495+ return (serviceList);
496+ }
497+ catch (Exception e)
498+ {
499+ e.printStackTrace();
500+ }
501+ return (null);
502+ }
503+
504+ @Override
505+ public JSONObject callGenericSonyApiMethod(@NonNull String service, @NonNull String method, @NonNull JSONArray params, @NonNull String version)
506+ {
507+ return (communicateJSON(service, method, params, version, -1));
508+ }
509+
482510 public static boolean isErrorReply(JSONObject replyJson)
483511 {
484512 return ((replyJson != null && replyJson.has("error")));
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/SonyCameraWrapper.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/SonyCameraWrapper.java
@@ -168,6 +168,12 @@ public class SonyCameraWrapper implements ISonyCameraHolder, ISonyInterfaceProvi
168168 }
169169
170170 @Override
171+ public ISonyCameraApi getCameraApi()
172+ {
173+ return (sonyCameraApi);
174+ }
175+
176+ @Override
171177 public void injectDisplay(@NonNull IAutoFocusFrameDisplay frameDisplayer, @NonNull IIndicatorControl indicator, @NonNull IFocusingModeNotify focusingModeNotify)
172178 {
173179 Log.v(TAG, "injectDisplay()");
--- /dev/null
+++ b/app/src/main/res/layout-land/request_edit_layout.xml
@@ -0,0 +1,55 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+ android:layout_width="match_parent"
4+ android:layout_height="match_parent">
5+
6+ <ScrollView
7+ android:layout_width="match_parent"
8+ android:layout_height="wrap_content">
9+
10+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
11+ android:id="@+id/info_edit_data"
12+ android:orientation="vertical"
13+ android:layout_width="fill_parent"
14+ android:layout_height="wrap_content"
15+ android:padding="6dp"
16+ >
17+
18+ <Spinner
19+ android:id="@+id/spinner_selection_service"
20+ android:layout_width="fill_parent"
21+ android:layout_height="wrap_content"
22+ android:text="@string/blank"
23+ android:visibility="visible" />
24+
25+ <TextView
26+ android:layout_width="fill_parent"
27+ android:layout_height="wrap_content"
28+ android:id="@+id/method_name"
29+ android:tag="title"
30+ android:maxWidth="130dp"
31+ android:minWidth="130dp"
32+ android:layout_gravity="start">
33+ </TextView>
34+
35+ <EditText android:id="@+id/edit_parameter"
36+ android:layout_width="fill_parent"
37+ android:layout_height="wrap_content"
38+ android:autoLink="all"
39+ android:linksClickable="true"
40+ android:inputType="text"
41+ android:hint="@string/dialog_parameter_hint"
42+ />
43+
44+ <EditText android:id="@+id/edit_version"
45+ android:layout_width="fill_parent"
46+ android:layout_height="wrap_content"
47+ android:autoLink="all"
48+ android:linksClickable="true"
49+ android:inputType="text"
50+ android:hint="@string/dialog_version_hint"
51+ />
52+ </LinearLayout>
53+ </ScrollView>
54+
55+</LinearLayout>
--- /dev/null
+++ b/app/src/main/res/layout/request_edit_layout.xml
@@ -0,0 +1,55 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+ android:layout_width="match_parent"
4+ android:layout_height="match_parent">
5+
6+ <ScrollView
7+ android:layout_width="match_parent"
8+ android:layout_height="wrap_content">
9+
10+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
11+ android:id="@+id/info_edit_data"
12+ android:orientation="vertical"
13+ android:layout_width="fill_parent"
14+ android:layout_height="wrap_content"
15+ android:padding="6dp"
16+ >
17+
18+ <Spinner
19+ android:id="@+id/spinner_selection_service"
20+ android:layout_width="fill_parent"
21+ android:layout_height="wrap_content"
22+ android:text="@string/blank"
23+ android:visibility="visible" />
24+
25+ <TextView
26+ android:layout_width="fill_parent"
27+ android:layout_height="wrap_content"
28+ android:id="@+id/method_name"
29+ android:tag="title"
30+ android:maxWidth="130dp"
31+ android:minWidth="130dp"
32+ android:layout_gravity="start">
33+ </TextView>
34+
35+ <EditText android:id="@+id/edit_parameter"
36+ android:layout_width="fill_parent"
37+ android:layout_height="wrap_content"
38+ android:autoLink="all"
39+ android:linksClickable="true"
40+ android:inputType="text"
41+ android:hint="@string/dialog_parameter_hint"
42+ />
43+
44+ <EditText android:id="@+id/edit_version"
45+ android:layout_width="fill_parent"
46+ android:layout_height="wrap_content"
47+ android:autoLink="all"
48+ android:linksClickable="true"
49+ android:inputType="text"
50+ android:hint="@string/dialog_version_hint"
51+ />
52+ </LinearLayout>
53+ </ScrollView>
54+
55+</LinearLayout>
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -109,6 +109,9 @@
109109 <string name="pref_sony_api_list">カメラAPI一覧</string>
110110 <string name="pref_summary_sony_api_list">カメラのAPI一覧を表示します。</string>
111111
112+ <string name="dialog_parameter_hint">(parameter)</string>
113+ <string name="dialog_version_hint">1.0</string>
114+
112115 <string name="only_opc_feature">OPCカメラでのみ有効です。</string>
113116 <string name="camera_detected">発見 : </string>
114117 <string name="camera_search_request">カメラ検索</string>
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -114,6 +114,9 @@
114114 <string name="pref_sony_api_list">Sony Camera Api List</string>
115115 <string name="pref_summary_sony_api_list">Show available camera apis.</string>
116116
117+ <string name="dialog_parameter_hint">(parameter)</string>
118+ <string name="dialog_version_hint">1.0</string>
119+
117120 <string name="only_opc_feature">This feature is only available for a OPC Camera.</string>
118121 <string name="camera_detected">Detected : </string>
119122 <string name="camera_search_request">Search Camera</string>
Afficher sur ancien navigateur de dépôt.