OSDN Git Service

フラッシュモードとセルフタイマーの設定を変更できるようにする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewFujiXKeyPanelClickListener.java
1 package net.osdn.gokigen.gr2control.liveview;
2
3 import android.content.DialogInterface;
4 import android.os.Vibrator;
5 import android.util.Log;
6 import android.view.View;
7
8 import androidx.annotation.NonNull;
9 import androidx.annotation.Nullable;
10 import androidx.appcompat.app.AlertDialog;
11 import androidx.fragment.app.FragmentActivity;
12
13 import net.osdn.gokigen.gr2control.R;
14 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
15 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
16 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandCallback;
17 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandPublisher;
18 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.CommandGeneric;
19 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.IFujiXCameraCommands;
20 import net.osdn.gokigen.gr2control.camera.utils.SimpleLogDumper;
21
22 import java.util.List;
23
24 public class LiveViewFujiXKeyPanelClickListener implements View.OnClickListener, View.OnLongClickListener, IFujiXCommandCallback
25 {
26     private final String TAG = toString();
27     private final FragmentActivity activity;
28     private static final boolean isDumpLog = false;
29     private final IInterfaceProvider interfaceProvider;
30     private final Vibrator vibrator;
31
32     LiveViewFujiXKeyPanelClickListener(@NonNull FragmentActivity activity, @NonNull IInterfaceProvider interfaceProvider, @Nullable Vibrator vibrator)
33     {
34         this.activity = activity;
35         this.interfaceProvider = interfaceProvider;
36         this.vibrator = vibrator;
37     }
38
39     @Override
40     public void onClick(View v)
41     {
42         boolean isVibrate = true;
43         try
44         {
45             int id = v.getId();
46             switch (id)
47             {
48                 case R.id.button_fuji_x_sv_minus:
49                     updateValue(IFujiXCameraCommands.SHUTTER_SPEED, 0);
50                     break;
51                 case R.id.button_fuji_x_sv_plus:
52                     updateValue(IFujiXCameraCommands.SHUTTER_SPEED, 1);
53                     break;
54                 case R.id.button_fuji_x_tv_minus:
55                     updateValue(IFujiXCameraCommands.APERTURE, 0);
56                     break;
57                 case R.id.button_fuji_x_tv_plus:
58                     updateValue(IFujiXCameraCommands.APERTURE, 1);
59                     break;
60                 case R.id.button_fuji_x_xv_minus:
61                     updateValue(IFujiXCameraCommands.EXPREV, 0);
62                     break;
63                 case R.id.button_fuji_x_flash:
64                     updateSelection(ICameraStatus.FLASH_XV);
65                     isVibrate = false;
66                     break;
67                 case R.id.button_fuji_x_timer:
68                     updateSelection(ICameraStatus.SELF_TIMER);
69                     isVibrate = false;
70                     break;
71
72                 default:
73                     isVibrate = false;
74                     break;
75             }
76             vibrate(isVibrate);
77         }
78         catch (Exception e)
79         {
80             e.printStackTrace();
81         }
82     }
83
84     @Override
85     public boolean onLongClick(View v)
86     {
87         boolean isVibrate = false;
88         boolean ret = false;
89         try
90         {
91             int id = v.getId();
92             switch (id)
93             {
94                 case R.id.button_fuji_x_sv_minus:
95                     break;
96                 case R.id.button_fuji_x_sv_plus:
97                     break;
98                 case R.id.button_fuji_x_tv_minus:
99                     break;
100                 case R.id.button_fuji_x_tv_plus:
101                     break;
102                 case R.id.button_fuji_x_xv_minus:
103                     break;
104                 case R.id.button_fuji_x_xv_plus:
105                     break;
106                 case R.id.button_fuji_x_flash:
107                     break;
108                 case R.id.button_fuji_x_timer:
109                     break;
110                 default:
111                     break;
112             }
113             vibrate(isVibrate);
114         }
115         catch (Exception e)
116         {
117             e.printStackTrace();
118         }
119         return (ret);
120     }
121
122     /**
123      *  値を更新する
124      *
125      */
126     private void updateValue(int id, int value)
127     {
128         try
129         {
130             IFujiXCommandPublisher publisher = interfaceProvider.getFujiXInterfaceProvider().getCommandPublisher();
131             publisher.enqueueCommand(new CommandGeneric(this, id, 4, value));
132         }
133         catch (Exception e)
134         {
135             e.printStackTrace();
136         }
137     }
138
139     /**
140      *  選択肢を更新する
141      *
142      */
143     private void updateSelection(@NonNull final String key)
144     {
145         try
146         {
147             Log.v(TAG, "updateSelection() : " + key);
148             final ICameraStatus statusList = interfaceProvider.getCameraStatusListHolder();
149             if (statusList == null)
150             {
151                 // ステータスリストの保持クラスが取れなかった...
152                 Log.w(TAG, "ICameraStatus is NULL...");
153                 return;
154             }
155             final String current = statusList.getStatus(key);
156             final List<String> itemList = statusList.getStatusList(key);
157             if (itemList.size() <= 0)
158             {
159                 // アイテム(選択肢)が登録されていなければ、何もしない
160                 return;
161             }
162
163             AlertDialog.Builder builder = new AlertDialog.Builder(activity);
164
165             // リストから配列に積み替え...
166             String[] items = new String[itemList.size()];
167             int index = 0;
168             for (String item : itemList)
169             {
170                 Log.v(TAG, " (" + index + ") " + item);
171                 items[index] = item;
172                 index++;
173             }
174             int position = itemList.indexOf(current);
175             Log.v(TAG, " updateSelection() : " + key + " " + itemList.size() + " " + position);
176             builder.setSingleChoiceItems(items, position, new DialogInterface.OnClickListener() {
177                 @Override
178                 public void onClick(DialogInterface dialogInterface, int i)
179                 {
180                     String choice = itemList.get(i);
181                     Log.v(TAG, key + " ITEM CHOICED : " + choice + "(CURRENT : " + current + ")");
182
183                     statusList.setStatus(key, choice);
184                     dialogInterface.dismiss();
185                 }
186             });
187             builder.show();
188         }
189         catch (Exception e)
190         {
191             e.printStackTrace();
192         }
193     }
194
195     /**
196      *   ぶるぶるさせる
197      *
198      */
199     private void vibrate(boolean isVibrate)
200     {
201         if ((vibrator != null)&&(isVibrate))
202         {
203             vibrator.vibrate(30);
204         }
205     }
206
207     @Override
208     public void receivedMessage(int id, byte[] rx_body)
209     {
210         if (isDumpLog)
211         {
212             SimpleLogDumper.dump_bytes("" + id, rx_body);
213         }
214     }
215
216     @Override
217     public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
218     {
219         Log.v(TAG, " onReceiveProgress() : " + currentBytes + "/" + totalBytes);
220     }
221
222     @Override
223     public boolean isReceiveMulti()
224     {
225         return (false);
226     }
227 }