1 package net.osdn.gokigen.a01d.camera.fujix.cameraproperty;
3 import android.app.Activity;
4 import android.app.Dialog;
5 import android.content.DialogInterface;
6 import android.os.Bundle;
7 import android.util.Log;
8 import android.view.LayoutInflater;
9 import android.view.View;
10 import android.widget.AdapterView;
11 import android.widget.ArrayAdapter;
12 import android.widget.Button;
13 import android.widget.EditText;
14 import android.widget.Spinner;
15 import android.widget.TextView;
17 import androidx.annotation.NonNull;
18 import androidx.appcompat.app.AlertDialog;
19 import androidx.collection.SparseArrayCompat;
20 import androidx.fragment.app.DialogFragment;
22 import net.osdn.gokigen.a01d.R;
23 import net.osdn.gokigen.a01d.camera.fujix.IFujiXInterfaceProvider;
24 import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.IFujiXCameraCommands;
25 import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.IFujiXCommandPublisher;
26 import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.CommandGeneric;
27 import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.SetPropertyValue;
28 import net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraModeChangeToLiveView;
29 import net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraModeChangeToPlayback;
30 import net.osdn.gokigen.a01d.camera.fujix.wrapper.status.IFujiXCameraProperties;
32 public class FujiXCameraCommandSendDialog extends DialogFragment
34 private final String TAG = toString();
35 private Dialog myDialog = null;
36 private IFujiXCommandPublisher commandPublisher = null;
37 private FujiXCameraCommandResponse responseReceiver = null;
38 private SparseArrayCompat<String> commandNameIndexArray;
40 private int selectedCommandIdPosition = 0;
41 private int selectedMessageTypePosition = 0;
42 private int selectedBodyLengthPosition = 0;
44 public static FujiXCameraCommandSendDialog newInstance(@NonNull IFujiXInterfaceProvider interfaceProvider)
46 FujiXCameraCommandSendDialog instance = new FujiXCameraCommandSendDialog();
47 instance.prepare(interfaceProvider);
49 // パラメータはBundleにまとめておく
50 Bundle arguments = new Bundle();
51 //arguments.putString("method", method);
52 //arguments.putString("message", message);
53 instance.setArguments(arguments);
58 private void prepare(@NonNull IFujiXInterfaceProvider interfaceProvider)
60 this.commandPublisher = interfaceProvider.getCommandPublisher();
61 this.commandNameIndexArray = new SparseArrayCompat<>();
65 public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
67 final Activity activity = getActivity();
68 final AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
70 // Get the layout inflater
71 LayoutInflater inflater = activity.getLayoutInflater();
72 final View alertView = inflater.inflate(R.layout.fujix_request_command_layout, null, false);
73 alertDialog.setView(alertView);
75 alertDialog.setIcon(R.drawable.ic_linked_camera_black_24dp);
76 alertDialog.setTitle(getString(R.string.dialog_fujix_command_title_command));
79 final TextView commandResponse = alertView.findViewById(R.id.command_response_value);
80 final EditText edit_command_id = alertView.findViewById(R.id.edit_command_id);
81 final EditText edit_message_body1 = alertView.findViewById(R.id.edit_message_body1);
82 final EditText edit_message_body2 = alertView.findViewById(R.id.edit_message_body2);
83 final Spinner selection_command_id = alertView.findViewById(R.id.spinner_selection_command_id);
84 final Spinner selection_message_type = alertView.findViewById(R.id.spinner_selection_message_type);
85 final Spinner selection_message_body_length = alertView.findViewById(R.id.spinner_selection_message_body_length);
86 final Button sendButton = alertView.findViewById(R.id.send_message_button);
87 final Button liveViewButton = alertView.findViewById(R.id.change_to_liveview);
88 final Button playbackButton = alertView.findViewById(R.id.change_to_playback);
90 responseReceiver = new FujiXCameraCommandResponse(activity, commandResponse);
92 initializeCommandSelection(activity, selection_command_id, edit_command_id);
93 initializeMessageTypeSelection(activity, selection_message_type);
94 initializeBodyLengthSelection(activity, selection_message_body_length);
96 sendButton.setOnClickListener(new View.OnClickListener()
99 public void onClick(View v)
103 //Log.v(TAG, "SEND COMMAND");
104 if (responseReceiver != null)
106 responseReceiver.clear();
107 int id = parseInt(edit_command_id);
108 int value1 = parseInt(edit_message_body1);
109 int value2 = parseInt(edit_message_body2);
110 if (selectedMessageTypePosition == 0)
113 if (selectedBodyLengthPosition == 0)
115 commandPublisher.enqueueCommand(new CommandGeneric(responseReceiver, id));
117 else if (selectedBodyLengthPosition == 3)
119 commandPublisher.enqueueCommand(new CommandGeneric(responseReceiver, id, 8, value1, value2));
121 else if (selectedBodyLengthPosition == 2)
123 commandPublisher.enqueueCommand(new CommandGeneric(responseReceiver, id, 4, value1));
127 commandPublisher.enqueueCommand(new CommandGeneric(responseReceiver, id, 2, value1));
133 if (selectedBodyLengthPosition == 0)
135 commandPublisher.enqueueCommand(new SetPropertyValue(responseReceiver, id));
137 else if (selectedBodyLengthPosition == 3)
139 commandPublisher.enqueueCommand(new SetPropertyValue(responseReceiver, id, 8, value1, value2));
141 else if (selectedBodyLengthPosition == 2)
143 commandPublisher.enqueueCommand(new SetPropertyValue(responseReceiver, id, 4, value1));
147 commandPublisher.enqueueCommand(new SetPropertyValue(responseReceiver, id, 2, value1));
158 if ((responseReceiver != null)&&(commandPublisher != null))
160 liveViewButton.setOnClickListener(new FujiXCameraModeChangeToLiveView(commandPublisher, responseReceiver));
161 playbackButton.setOnClickListener(new FujiXCameraModeChangeToPlayback(commandPublisher, responseReceiver));
168 alertDialog.setCancelable(true);
171 alertDialog.setPositiveButton(activity.getString(R.string.dialog_positive_execute),
172 new DialogInterface.OnClickListener() {
173 public void onClick(DialogInterface dialog, int which)
179 // ボタンを設定する (キャンセルボタン)
180 alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
181 new DialogInterface.OnClickListener() {
182 public void onClick(DialogInterface dialog, int which) {
188 myDialog = alertDialog.create();
193 public void onPause()
196 Log.v(TAG, "AlertDialog::onPause()");
197 if (myDialog != null)
203 private int parseInt(EditText area)
207 String value = (area.getText().toString()).toLowerCase();
208 int index = value.indexOf("x");
211 value = value.substring(index + 1);
213 if (value.length() < 1)
218 //int convertValue = (int)Long.parseLong(value, 16);
219 //Log.v(TAG, String.format(Locale.US, "PARSED VALUE : 0x%08x (%d)", convertValue, convertValue));
220 //return (convertValue);
221 return ((int)Long.parseLong(value, 16));
226 Log.v(TAG, "[" + area.getText().toString() + "]");
232 private ArrayAdapter<String> prepareCommandAdapter(@NonNull final Activity activity)
235 ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item);
236 commandNameIndexArray.clear();
239 adapter.add("(Direct Input)");
240 commandNameIndexArray.append(position++, "");
242 adapter.add(IFujiXCameraCommands.SHUTTER_STR + " (" + IFujiXCameraCommands.SHUTTER_STR_ID + ")");
243 commandNameIndexArray.append(position++, IFujiXCameraCommands.SHUTTER_STR_ID);
245 adapter.add(IFujiXCameraCommands.FOCUS_POINT_STR + " (" + IFujiXCameraCommands.FOCUS_POINT_STR_ID + ")");
246 commandNameIndexArray.append(position++, IFujiXCameraCommands.FOCUS_POINT_STR_ID);
248 adapter.add(IFujiXCameraCommands.FOCUS_UNLOCK_STR + " (" + IFujiXCameraCommands.FOCUS_UNLOCK_STR_ID + ")");
249 commandNameIndexArray.append(position++, IFujiXCameraCommands.FOCUS_UNLOCK_STR_ID);
251 adapter.add(IFujiXCameraCommands.SHUTTER_SPEED_STR + " (" + IFujiXCameraCommands.SHUTTER_SPEED_STR_ID + ")");
252 commandNameIndexArray.append(position++, IFujiXCameraCommands.SHUTTER_SPEED_STR_ID);
254 adapter.add(IFujiXCameraCommands.APERTURE_STR + " (" + IFujiXCameraCommands.APERTURE_STR_ID + ")");
255 commandNameIndexArray.append(position++, IFujiXCameraCommands.APERTURE_STR_ID);
257 adapter.add(IFujiXCameraCommands.EXPREV_STR + " (" + IFujiXCameraCommands.EXPREV_STR_ID + ")");
258 commandNameIndexArray.append(position++, IFujiXCameraCommands.EXPREV_STR_ID);
260 adapter.add(IFujiXCameraProperties.WHITE_BALANCE_STR + " (" + IFujiXCameraProperties.WHITE_BALANCE_STR_ID + ")");
261 commandNameIndexArray.append(position++, IFujiXCameraProperties.WHITE_BALANCE_STR_ID);
263 adapter.add(IFujiXCameraProperties.EXPOSURE_COMPENSATION_STR + " (" + IFujiXCameraProperties.EXPOSURE_COMPENSATION_STR_ID + ")");
264 commandNameIndexArray.append(position++, IFujiXCameraProperties.EXPOSURE_COMPENSATION_STR_ID);
266 adapter.add(IFujiXCameraProperties.APERTURE_STR + " (" + IFujiXCameraProperties.APERTURE_STR_ID + ")");
267 commandNameIndexArray.append(position++, IFujiXCameraProperties.APERTURE_STR_ID);
269 adapter.add(IFujiXCameraProperties.SHUTTER_SPEED_STR + " (" + IFujiXCameraProperties.SHUTTER_SPEED_STR_ID + ")");
270 commandNameIndexArray.append(position++, IFujiXCameraProperties.SHUTTER_SPEED_STR_ID);
272 adapter.add(IFujiXCameraProperties.SELF_TIMER_STR + " (" + IFujiXCameraProperties.SELF_TIMER_STR_ID + ")");
273 commandNameIndexArray.append(position++, IFujiXCameraProperties.SELF_TIMER_STR_ID);
275 adapter.add(IFujiXCameraProperties.FILM_SIMULATION_STR + " (" + IFujiXCameraProperties.FILM_SIMULATION_STR_ID + ")");
276 commandNameIndexArray.append(position++, IFujiXCameraProperties.FILM_SIMULATION_STR_ID);
278 adapter.add(IFujiXCameraProperties.ISO_STR + " (" + IFujiXCameraProperties.ISO_STR_ID + ")");
279 commandNameIndexArray.append(position++, IFujiXCameraProperties.ISO_STR_ID);
281 adapter.add(IFujiXCameraProperties.MOVIE_ISO_STR + " (" + IFujiXCameraProperties.MOVIE_ISO_STR_ID + ")");
282 commandNameIndexArray.append(position++, IFujiXCameraProperties.MOVIE_ISO_STR_ID);
284 adapter.add(IFujiXCameraProperties.IMAGE_FORMAT_STR + " (" + IFujiXCameraProperties.IMAGE_FORMAT_STR_ID + ")");
285 commandNameIndexArray.append(position++, IFujiXCameraProperties.IMAGE_FORMAT_STR_ID);
287 adapter.add(IFujiXCameraProperties.IMAGE_ASPECT_STR + " (" + IFujiXCameraProperties.IMAGE_ASPECT_STR_ID + ")");
288 commandNameIndexArray.append(position++, IFujiXCameraProperties.IMAGE_ASPECT_STR_ID);
290 adapter.add(IFujiXCameraProperties.FLASH_STR + " (" + IFujiXCameraProperties.FLASH_STR_ID + ")");
291 commandNameIndexArray.append(position++, IFujiXCameraProperties.FLASH_STR_ID);
293 adapter.add(IFujiXCameraProperties.F_SS_CONTROL_STR + " (" + IFujiXCameraProperties.F_SS_CONTROL_STR_ID + ")");
294 commandNameIndexArray.append(position++, IFujiXCameraProperties.F_SS_CONTROL_STR_ID);
296 adapter.add(IFujiXCameraProperties.RECMODE_ENABLE_STR + " (" + IFujiXCameraProperties.RECMODE_ENABLE_STR_ID + ")");
297 commandNameIndexArray.append(position++, IFujiXCameraProperties.RECMODE_ENABLE_STR_ID);
299 adapter.add(IFujiXCameraProperties.BATTERY_LEVEL_STR + " (" + IFujiXCameraProperties.BATTERY_LEVEL_STR_ID + ")");
300 commandNameIndexArray.append(position++, IFujiXCameraProperties.BATTERY_LEVEL_STR_ID);
302 adapter.add(IFujiXCameraProperties.BATTERY_LEVEL_2_STR + " (" + IFujiXCameraProperties.BATTERY_LEVEL_2_STR_ID + ")");
303 commandNameIndexArray.append(position++, IFujiXCameraProperties.BATTERY_LEVEL_2_STR_ID);
305 adapter.add(IFujiXCameraProperties.FOCUS_MODE_STR + " (" + IFujiXCameraProperties.FOCUS_MODE_STR_ID + ")");
306 commandNameIndexArray.append(position++, IFujiXCameraProperties.FOCUS_MODE_STR_ID);
308 adapter.add(IFujiXCameraProperties.SHOOTING_MODE_STR + " (" + IFujiXCameraProperties.SHOOTING_MODE_STR_ID + ")");
309 commandNameIndexArray.append(position++, IFujiXCameraProperties.SHOOTING_MODE_STR_ID);
311 adapter.add(IFujiXCameraProperties.FOCUS_POINT_STR + " (" + IFujiXCameraProperties.FOCUS_POINT_STR_ID + ")");
312 commandNameIndexArray.append(position++, IFujiXCameraProperties.FOCUS_POINT_STR_ID);
314 adapter.add(IFujiXCameraProperties.FOCUS_LOCK_STR + " (" + IFujiXCameraProperties.FOCUS_LOCK_STR_ID + ")");
315 commandNameIndexArray.append(position++, IFujiXCameraProperties.FOCUS_LOCK_STR_ID);
317 adapter.add(IFujiXCameraProperties.SDCARD_REMAIN_SIZE_STR + " (" + IFujiXCameraProperties.SDCARD_REMAIN_SIZE_STR_ID + ")");
318 commandNameIndexArray.append(position++, IFujiXCameraProperties.SDCARD_REMAIN_SIZE_STR_ID);
320 adapter.add(IFujiXCameraProperties.MOVIE_REMAINING_TIME_STR + " (" + IFujiXCameraProperties.MOVIE_REMAINING_TIME_STR_ID + ")");
321 commandNameIndexArray.append(position++, IFujiXCameraProperties.MOVIE_REMAINING_TIME_STR_ID);
323 adapter.add(IFujiXCameraProperties.DEVICE_ERROR_STR + " (" + IFujiXCameraProperties.DEVICE_ERROR_STR_ID + ")");
324 commandNameIndexArray.append(position++, IFujiXCameraProperties.DEVICE_ERROR_STR_ID);
326 adapter.add(IFujiXCameraProperties.IMAGE_FILE_COUNT_STR + " (" + IFujiXCameraProperties.IMAGE_FILE_COUNT_STR_ID + ")");
327 commandNameIndexArray.append(position++, IFujiXCameraProperties.IMAGE_FILE_COUNT_STR_ID);
329 adapter.add(IFujiXCameraCommands.CAMERA_CAPABILITIES_STR + " (" + IFujiXCameraCommands.CAMERA_CAPABILITIES_STR_ID + ")");
330 commandNameIndexArray.append(position++, IFujiXCameraCommands.CAMERA_CAPABILITIES_STR_ID);
332 adapter.add(IFujiXCameraCommands.SINGLE_REQUEST_STR + " (" + IFujiXCameraCommands.SINGLE_REQUEST_STR_ID + ")");
333 commandNameIndexArray.append(position++, IFujiXCameraCommands.SINGLE_REQUEST_STR_ID);
335 adapter.add(IFujiXCameraCommands.STOP_STR + " (" + IFujiXCameraCommands.STOP_STR_ID + ")");
336 commandNameIndexArray.append(position++, IFujiXCameraCommands.STOP_STR_ID);
338 adapter.add(IFujiXCameraCommands.IMAGE_INFO_STR + " (" + IFujiXCameraCommands.IMAGE_INFO_STR_ID + ")");
339 commandNameIndexArray.append(position++, IFujiXCameraCommands.IMAGE_INFO_STR_ID);
341 adapter.add(IFujiXCameraCommands.THUMBNAIL_INDEX_STR + " (" + IFujiXCameraCommands.THUMBNAIL_INDEX_STR_ID + ")");
342 commandNameIndexArray.append(position++, IFujiXCameraCommands.THUMBNAIL_INDEX_STR_ID);
344 adapter.add(IFujiXCameraCommands.FULL_IMAGE_STR + " (" + IFujiXCameraCommands.FULL_IMAGE_STR_ID + ")");
345 commandNameIndexArray.append(position++, IFujiXCameraCommands.FULL_IMAGE_STR_ID);
347 adapter.add(IFujiXCameraCommands.LAST_IMAGE_CAMERA_STR + " (" + IFujiXCameraCommands.LAST_IMAGE_CAMERA_STR_ID + ")");
348 commandNameIndexArray.append(position, IFujiXCameraCommands.LAST_IMAGE_CAMERA_STR_ID);
353 private void initializeCommandSelection(@NonNull final Activity activity, final Spinner spinner, final EditText commandIdArea)
357 commandIdArea.setText("");
358 ArrayAdapter<String> adapter = prepareCommandAdapter(activity);
359 spinner.setAdapter(adapter);
360 spinner.setSelection(selectedCommandIdPosition);
361 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
364 public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
366 Log.v(TAG, "onItemSelected : " + position + " (" + id + ")");
369 selectedCommandIdPosition = position;
370 commandIdArea.setText(commandNameIndexArray.get(position, ""));
379 public void onNothingSelected(AdapterView<?> parent)
381 Log.v(TAG, "onNothingSelected");
391 private void initializeMessageTypeSelection(final Activity activity, final Spinner spinner)
395 ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item);
396 adapter.add("Command(Single)");
397 adapter.add("Property(Multi)");
399 spinner.setAdapter(adapter);
400 spinner.setSelection(selectedMessageTypePosition);
401 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
404 public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
406 Log.v(TAG, "onItemSelected : " + position + " (" + id + ")");
407 selectedMessageTypePosition = position;
411 public void onNothingSelected(AdapterView<?> parent)
413 Log.v(TAG, "onNothingSelected");
423 private void initializeBodyLengthSelection(final Activity activity, final Spinner spinner)
427 ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item);
433 spinner.setAdapter(adapter);
434 spinner.setSelection(selectedBodyLengthPosition);
435 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
438 public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
440 Log.v(TAG, "onItemSelected : " + position + " (" + id + ")");
441 selectedBodyLengthPosition = position;
445 public void onNothingSelected(AdapterView<?> parent)
447 Log.v(TAG, "onNothingSelected");