1 package net.osdn.gokigen.gr2control.liveview;
3 import android.content.DialogInterface;
4 import android.os.Vibrator;
5 import android.util.Log;
6 import android.view.View;
7 import android.widget.ImageView;
9 import androidx.annotation.NonNull;
10 import androidx.annotation.Nullable;
11 import androidx.appcompat.app.AlertDialog;
12 import androidx.core.content.ContextCompat;
13 import androidx.fragment.app.FragmentActivity;
15 import net.osdn.gokigen.gr2control.R;
16 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
17 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
18 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandCallback;
19 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandPublisher;
20 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.CommandGeneric;
21 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.FinishRecordingMovie;
22 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.IFujiXCameraCommands;
23 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.StartRecordingMovie;
24 import net.osdn.gokigen.gr2control.camera.utils.SimpleLogDumper;
26 import java.util.List;
28 public class LiveViewFujiXKeyPanelClickListener implements View.OnClickListener, View.OnLongClickListener, IFujiXCommandCallback
30 private final String TAG = toString();
31 private final FragmentActivity activity;
32 private static final boolean isDumpLog = false;
33 private final IInterfaceProvider interfaceProvider;
34 private final Vibrator vibrator;
35 private boolean isRecordingVideoMovie = false;
36 private boolean commandIssued = false;
37 private int startMovieSequenceNumber = 0;
39 LiveViewFujiXKeyPanelClickListener(@NonNull FragmentActivity activity, @NonNull IInterfaceProvider interfaceProvider, @Nullable Vibrator vibrator)
41 this.activity = activity;
42 this.interfaceProvider = interfaceProvider;
43 this.vibrator = vibrator;
47 public void onClick(View v)
49 boolean isVibrate = true;
55 case R.id.button_fuji_x_sv_minus:
56 updateValue(IFujiXCameraCommands.SHUTTER_SPEED, 0);
58 case R.id.button_fuji_x_sv_plus:
59 updateValue(IFujiXCameraCommands.SHUTTER_SPEED, 1);
61 case R.id.button_fuji_x_tv_minus:
62 updateValue(IFujiXCameraCommands.APERTURE, 0);
64 case R.id.button_fuji_x_tv_plus:
65 updateValue(IFujiXCameraCommands.APERTURE, 1);
67 case R.id.button_fuji_x_xv_minus:
68 updateValue(IFujiXCameraCommands.EXPREV, 0);
70 case R.id.button_fuji_x_xv_plus:
71 updateValue(IFujiXCameraCommands.EXPREV, 1);
73 case R.id.button_fuji_x_flash:
74 updateSelection(ICameraStatus.FLASH_XV);
77 case R.id.button_fuji_x_timer:
78 updateSelection(ICameraStatus.SELF_TIMER);
81 case R.id.button_fuji_x_video_on_off:
97 public boolean onLongClick(View v)
99 boolean isVibrate = false;
106 case R.id.button_fuji_x_sv_minus:
108 case R.id.button_fuji_x_sv_plus:
110 case R.id.button_fuji_x_tv_minus:
112 case R.id.button_fuji_x_tv_plus:
114 case R.id.button_fuji_x_xv_minus:
116 case R.id.button_fuji_x_xv_plus:
118 case R.id.button_fuji_x_flash:
120 case R.id.button_fuji_x_timer:
138 private void updateValue(int id, int value)
142 IFujiXCommandPublisher publisher = interfaceProvider.getFujiXInterfaceProvider().getCommandPublisher();
143 publisher.enqueueCommand(new CommandGeneric(this, id, 4, value));
155 private void updateSelection(@NonNull final String key)
159 Log.v(TAG, "updateSelection() : " + key);
160 final ICameraStatus statusList = interfaceProvider.getCameraStatusListHolder();
161 if (statusList == null)
163 // ステータスリストの保持クラスが取れなかった...
164 Log.w(TAG, "ICameraStatus is NULL...");
167 final String current = statusList.getStatus(key);
168 final List<String> itemList = statusList.getStatusList(key);
169 if (itemList.size() <= 0)
171 // アイテム(選択肢)が登録されていなければ、何もしない
175 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
178 String[] items = new String[itemList.size()];
180 for (String item : itemList)
182 Log.v(TAG, " (" + index + ") " + item);
186 int position = itemList.indexOf(current);
187 Log.v(TAG, " updateSelection() : " + key + " " + itemList.size() + " " + position);
188 builder.setSingleChoiceItems(items, position, new DialogInterface.OnClickListener() {
190 public void onClick(DialogInterface dialogInterface, int i)
192 String choice = itemList.get(i);
193 Log.v(TAG, key + " ITEM CHOICED : " + choice + "(CURRENT : " + current + ")");
195 statusList.setStatus(key, choice);
196 dialogInterface.dismiss();
211 private void startFinishMovie()
217 // すでにコマンド発行中。コマンドの発行は抑止する
218 Log.v(TAG, " COMMAND IS ALREADY ISSUED...");
221 commandIssued = true;
223 IFujiXCommandPublisher publisher = interfaceProvider.getFujiXInterfaceProvider().getCommandPublisher();
224 if (isRecordingVideoMovie)
227 publisher.enqueueCommand(new FinishRecordingMovie(new IFujiXCommandCallback() {
229 public void receivedMessage(int id, byte[] rx_body)
231 commandIssued = false;
232 isRecordingVideoMovie = false;
233 updateMovieRecordingIcon();
234 SimpleLogDumper.dump_bytes(" STOP MOVIE REPLY (" + startMovieSequenceNumber + ") ", rx_body);
235 startMovieSequenceNumber = 0;
239 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
245 public boolean isReceiveMulti()
249 }, startMovieSequenceNumber));
254 publisher.enqueueCommand(new StartRecordingMovie(new IFujiXCommandCallback() {
256 public void receivedMessage(int id, byte[] rx_body)
258 commandIssued = false;
259 if ((rx_body[7] == (byte) 0x20)&&(rx_body[6] == (byte) 0x01))
261 // 応答コード OKの場合... SequenceNumberを記憶する
262 startMovieSequenceNumber = ((((int) rx_body[11]) & 0xff) << 24) + ((((int) rx_body[10]) & 0xff) << 16) + ((((int) rx_body[9]) & 0xff) << 8) + (((int) rx_body[8]) & 0xff);
263 isRecordingVideoMovie = true;
265 updateMovieRecordingIcon();
266 SimpleLogDumper.dump_bytes(" START MOVIE REPLY (" + startMovieSequenceNumber + ") ", rx_body);
270 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
276 public boolean isReceiveMulti()
286 commandIssued = false;
290 private void updateMovieRecordingIcon()
294 activity.runOnUiThread(new Runnable() {
297 ImageView imageView = activity.findViewById(R.id.button_fuji_x_video_on_off);
298 if (isRecordingVideoMovie)
300 //imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_videocam_off_black_24dp));
301 imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_stop_black_24dp));
305 imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_videocam_black__24dp));
307 imageView.invalidate();
325 private void vibrate(boolean isVibrate)
327 if ((vibrator != null)&&(isVibrate))
329 vibrator.vibrate(30);
334 public void receivedMessage(int id, byte[] rx_body)
338 SimpleLogDumper.dump_bytes("" + id, rx_body);
343 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
345 Log.v(TAG, " onReceiveProgress() : " + currentBytes + "/" + totalBytes);
349 public boolean isReceiveMulti()