• R/O
  • HTTP
  • SSH
  • HTTPS

A01d: Commit

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


Commit MetaInfo

Révisione01988bfcaf9418d9fea0cbb23228857764db42c (tree)
l'heure2018-06-19 00:41:51
AuteurMRSa <mrsa@myad...>
CommiterMRSa

Message de Log

コマンドを投げるところを作成した。

Change Summary

Modification

--- a/app/src/main/java/net/osdn/gokigen/a01d/ConfirmationDialog.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/ConfirmationDialog.java
@@ -1,14 +1,24 @@
1+
12 package net.osdn.gokigen.a01d;
23
34 import android.content.Context;
45 import android.content.DialogInterface;
6+import android.support.v4.app.DialogFragment;
57 import android.support.v7.app.AlertDialog;
68
7-public class ConfirmationDialog
9+public class ConfirmationDialog extends DialogFragment
810 {
9- private final Context context;
11+ private Context context = null;
12+
13+ public static ConfirmationDialog newInstance(Context context)
14+ {
15+ ConfirmationDialog instance = new ConfirmationDialog();
16+ instance.prepare(context);
1017
11- public ConfirmationDialog(Context context)
18+ return (instance);
19+ }
20+
21+ private void prepare(Context context)
1222 {
1323 this.context = context;
1424 }
@@ -59,6 +69,28 @@ public class ConfirmationDialog
5969 alertDialog.show();
6070 }
6171
72+ public void show(int iconResId, String title, String message)
73+ {
74+ // 表示イアログの生成
75+ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
76+ alertDialog.setTitle(title);
77+ alertDialog.setIcon(iconResId);
78+ alertDialog.setMessage(message);
79+ alertDialog.setCancelable(true);
80+
81+ // ボタンを設定する(実行ボタン)
82+ alertDialog.setPositiveButton(context.getString(R.string.dialog_positive_execute),
83+ new DialogInterface.OnClickListener() {
84+ public void onClick(DialogInterface dialog, int which)
85+ {
86+ dialog.dismiss();
87+ }
88+ });
89+
90+ // 確認ダイアログを表示する
91+ alertDialog.show();
92+ }
93+
6294 // コールバックインタフェース
6395 public interface Callback
6496 {
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/cameraproperty/CameraPropertyOperator.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/cameraproperty/CameraPropertyOperator.java
@@ -42,7 +42,7 @@ public class CameraPropertyOperator implements View.OnClickListener
4242 {
4343 try
4444 {
45- final ConfirmationDialog dialog = new ConfirmationDialog(context);
45+ final ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
4646 dialog.show(R.string.dialog_title_confirmation,
4747 R.string.dialog_message_restore_camera_property,
4848 new ConfirmationDialog.Callback() {
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/operation/CameraPowerOff.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/operation/CameraPowerOff.java
@@ -57,7 +57,7 @@ public class CameraPowerOff implements Preference.OnPreferenceClickListener, Con
5757 {
5858
5959 // 確認ダイアログの生成と表示
60- ConfirmationDialog dialog = new ConfirmationDialog(context);
60+ ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
6161 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, this);
6262 return (true);
6363 }
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SendRequestDialog.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SendRequestDialog.java
@@ -87,13 +87,27 @@ public class SendRequestDialog extends DialogFragment
8787 final TextView methodName = alertView.findViewById(R.id.method_name);
8888 final EditText parameter = alertView.findViewById(R.id.edit_parameter);
8989 final EditText version = alertView.findViewById(R.id.edit_version);
90- try
91- {
90+ try {
9291 methodName.setText("");
9392 version.setText(activity.getString(R.string.dialog_version_hint));
9493 ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item);
9594 adapter.addAll(cameraApi.getSonyApiServiceList());
95+
96+ int defaultSelection;
97+ for (defaultSelection = (adapter.getCount() - 1); defaultSelection >= 0; defaultSelection--)
98+ {
99+ String item = adapter.getItem(defaultSelection);
100+ if ((item != null) && (item.equals("camera")))
101+ {
102+ break;
103+ }
104+ }
105+ if ((defaultSelection < 0) || (defaultSelection >= adapter.getCount()))
106+ {
107+ defaultSelection = 0;
108+ }
96109 spinner.setAdapter(adapter);
110+ spinner.setSelection(defaultSelection);
97111 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
98112 {
99113 @Override
--- 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,6 +1,7 @@
11 package net.osdn.gokigen.a01d.camera.sony.cameraproperty;
22
33 import android.app.Activity;
4+import android.content.Context;
45 import android.content.Intent;
56 import android.os.Bundle;
67 import android.support.annotation.NonNull;
@@ -9,6 +10,7 @@ import android.support.v4.app.FragmentActivity;
910 import android.support.v4.app.FragmentManager;
1011 import android.support.v4.app.ListFragment;
1112 import android.support.v7.app.ActionBar;
13+import android.support.v7.app.AlertDialog;
1214 import android.support.v7.app.AppCompatActivity;
1315 import android.util.Log;
1416 import android.view.LayoutInflater;
@@ -22,9 +24,13 @@ import android.widget.ListAdapter;
2224 import android.widget.ListView;
2325 import android.widget.Toast;
2426
27+import net.osdn.gokigen.a01d.ConfirmationDialog;
2528 import net.osdn.gokigen.a01d.R;
2629 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
2730
31+import org.json.JSONArray;
32+import org.json.JSONObject;
33+
2834 import java.util.ArrayList;
2935 import java.util.Arrays;
3036 import java.util.List;
@@ -289,9 +295,9 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
289295 *
290296 */
291297 @Override
292- public void sendRequest(String service, String apiName, String parameter, String version)
298+ public void sendRequest(final String service, final String apiName, final String parameter, final String version)
293299 {
294- String[] parameterItems = parameter.split(",");
300+ final String[] parameterItems = parameter.split(",");
295301
296302 StringBuilder logBuilder = new StringBuilder();
297303 logBuilder.append("sendRequest(");
@@ -308,6 +314,39 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
308314 logBuilder.append(version);
309315 logBuilder.append(");");
310316 Log.v(TAG, logBuilder.toString());
317+
318+ try
319+ {
320+ Thread thread = new Thread(new Runnable()
321+ {
322+ @Override
323+ public void run()
324+ {
325+ try
326+ {
327+ // メッセージを送信する
328+ JSONArray params = new JSONArray();
329+ if (parameter.length() != 0)
330+ {
331+ for (int index = 0; index < parameterItems.length; index++)
332+ {
333+ params.put(parameterItems[index]);
334+ }
335+ }
336+ receivedReply(interfaceProvider.getSonyInterface().getCameraApi().callGenericSonyApiMethod(service, apiName, params, version));
337+ }
338+ catch (Exception e)
339+ {
340+ e.printStackTrace();
341+ }
342+ }
343+ });
344+ thread.start();
345+ }
346+ catch (Exception e)
347+ {
348+ e.printStackTrace();
349+ }
311350 }
312351
313352 @Override
@@ -315,4 +354,40 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
315354 {
316355 Log.v(TAG, "cancelled()");
317356 }
357+
358+
359+ private void receivedReply(final JSONObject reply)
360+ {
361+ try
362+ {
363+ final Activity activity = getActivity();
364+ if (activity != null)
365+ {
366+ activity.runOnUiThread(new Runnable()
367+ {
368+ @Override
369+ public void run()
370+ {
371+ try
372+ {
373+ ConfirmationDialog dialog = ConfirmationDialog.newInstance(getActivity());
374+ dialog.show(android.R.drawable.ic_dialog_info, getString(R.string.dialog_title_reply), reply.getString("result"));
375+ }
376+ catch (Exception e)
377+ {
378+ ConfirmationDialog dialog = ConfirmationDialog.newInstance(getActivity());
379+ dialog.show(android.R.drawable.ic_dialog_alert, getString(R.string.dialog_title_reply), "RECEIVE ERROR");
380+ e.printStackTrace();
381+ }
382+ }
383+ });
384+ }
385+ }
386+ catch (Exception e)
387+ {
388+ e.printStackTrace();
389+ }
390+
391+ }
392+
318393 }
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/operation/CameraPowerOffSony.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/operation/CameraPowerOffSony.java
@@ -57,7 +57,7 @@ import net.osdn.gokigen.a01d.preference.olympus.IPreferencePropertyAccessor;
5757 {
5858
5959 // 確認ダイアログの生成と表示
60- ConfirmationDialog dialog = new ConfirmationDialog(context);
60+ ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
6161 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_exit_application, this);
6262 return (true);
6363 }
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -111,6 +111,7 @@
111111
112112 <string name="dialog_parameter_hint">(parameter)</string>
113113 <string name="dialog_version_hint">1.0</string>
114+ <string name="dialog_title_reply">応答</string>
114115
115116 <string name="only_opc_feature">OPCカメラでのみ有効です。</string>
116117 <string name="camera_detected">発見 : </string>
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -116,6 +116,7 @@
116116
117117 <string name="dialog_parameter_hint">(parameter)</string>
118118 <string name="dialog_version_hint">1.0</string>
119+ <string name="dialog_title_reply">Reply</string>
119120
120121 <string name="only_opc_feature">This feature is only available for a OPC Camera.</string>
121122 <string name="camera_detected">Detected : </string>
Afficher sur ancien navigateur de dépôt.