OSDN Git Service

318de818a139193fa4d5536dd009795c26dd818f
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewControlPanelClickListener.java
1 package net.osdn.gokigen.gr2control.liveview;
2
3 import android.app.Activity;
4 import android.content.DialogInterface;
5 import android.util.Log;
6 import android.view.View;
7
8 import net.osdn.gokigen.gr2control.R;
9 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
10 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
11
12 import java.util.List;
13
14 import androidx.annotation.NonNull;
15 import androidx.appcompat.app.AlertDialog;
16
17 /**
18  *
19  *
20  */
21 class LiveViewControlPanelClickListener  implements View.OnClickListener
22 {
23     private final String TAG = toString();
24     private final Activity activity;
25     private final IInterfaceProvider interfaceProvider;
26
27     LiveViewControlPanelClickListener(Activity context, IInterfaceProvider interfaceProvider)
28     {
29         this.activity = context;
30         this.interfaceProvider = interfaceProvider;
31     }
32
33     @Override
34     public void onClick(View view)
35     {
36         try
37         {
38             int id = view.getId();
39             ICameraStatus statusList = interfaceProvider.getCameraStatusListHolder();
40             if (statusList == null)
41             {
42                 // ステータスリストの保持クラスが取れなかった...
43                 Log.w(TAG, "ICameraStatus is NULL...");
44                 return;
45             }
46             switch (id)
47             {
48                 case R.id.takemodeTextView:
49                     selectTakeMode(statusList);
50                     break;
51
52                 case R.id.shutterSpeedTextView:
53                     selectShutterSpeed(statusList);
54                     break;
55
56                 case R.id.apertureValueTextView:
57                     selectAperture(statusList);
58                     break;
59
60                 case R.id.exposureCompensationTextView:
61                     selectExposureCompensation(statusList);
62                     break;
63
64                 case R.id.aeModeImageView:
65                     selectAeMode(statusList);
66                     break;
67
68                 case R.id.whiteBalanceTextView:
69                     selectWhiteBalance(statusList);
70                     break;
71
72                 case R.id.isoSensitivityTextView:
73                     selectIsoSensitivity(statusList);
74                     break;
75
76                 case R.id.setEffectImageView:
77                     selectEffect(statusList);
78                     break;
79
80                 default:
81                     Log.v(TAG, "onClick() : " + id);
82                     break;
83             }
84         }
85         catch (Exception e)
86         {
87             e.printStackTrace();
88         }
89     }
90
91     private void selectTakeMode(@NonNull ICameraStatus statusList)
92     {
93         Log.v(TAG,"selectTakeMode()");
94         try
95         {
96             choiceStatusList(statusList, ICameraStatus.TAKE_MODE);
97         }
98         catch (Exception e)
99         {
100             e.printStackTrace();
101         }
102     }
103
104     private void selectShutterSpeed(@NonNull ICameraStatus statusList)
105     {
106         Log.v(TAG,"selectShutterSpeed()");
107         try
108         {
109             choiceStatusList(statusList, ICameraStatus.SHUTTER_SPEED);
110         }
111         catch (Exception e)
112         {
113             e.printStackTrace();
114         }
115     }
116
117
118     private void selectAperture(@NonNull ICameraStatus statusList)
119     {
120         Log.v(TAG,"selectAperture()");
121         try
122         {
123             choiceStatusList(statusList, ICameraStatus.APERATURE);
124         }
125         catch (Exception e)
126         {
127             e.printStackTrace();
128         }
129     }
130
131
132     private void selectExposureCompensation(@NonNull ICameraStatus statusList)
133     {
134         Log.v(TAG,"selectExposureCompensation()");
135         try
136         {
137             choiceStatusList(statusList, ICameraStatus.EXPREV);
138         }
139         catch (Exception e)
140         {
141             e.printStackTrace();
142         }
143     }
144
145
146     private void selectAeMode(@NonNull ICameraStatus statusList)
147     {
148         Log.v(TAG,"selectAeMode()");
149         try
150         {
151             choiceStatusList(statusList, ICameraStatus.AE);
152         }
153         catch (Exception e)
154         {
155             e.printStackTrace();
156         }
157     }
158
159     private void selectWhiteBalance(@NonNull ICameraStatus statusList)
160     {
161         Log.v(TAG,"selectWhiteBalance()");
162         try
163         {
164             choiceStatusList(statusList, ICameraStatus.WHITE_BALANCE);
165         }
166         catch (Exception e)
167         {
168             e.printStackTrace();
169         }
170     }
171
172     private void selectIsoSensitivity(@NonNull ICameraStatus statusList)
173     {
174         Log.v(TAG,"selectIsoSensitivity()");
175         try
176         {
177             choiceStatusList(statusList, ICameraStatus.ISO_SENSITIVITY);
178         }
179         catch (Exception e)
180         {
181             e.printStackTrace();
182         }
183     }
184
185     private void selectEffect(@NonNull ICameraStatus statusList)
186     {
187         Log.v(TAG,"selectWhiteBalance()");
188         try
189         {
190             choiceStatusList(statusList, ICameraStatus.EFFECT);
191         }
192         catch (Exception e)
193         {
194             e.printStackTrace();
195         }
196     }
197
198     /**
199      *
200      *
201      */
202     private void choiceStatusList(@NonNull final ICameraStatus statusList, final String key)
203     {
204         try
205         {
206             final String current = statusList.getStatus(key);
207             final List<String> itemList = statusList.getStatusList(key);
208
209             if (itemList.size() <= 0)
210             {
211                 // アイテム(選択肢)が登録されていなければ、何もしない
212                 return;
213             }
214
215             // しかし、ここ、ちょーダサいんだけど...
216             String[] items = new String[itemList.size()];
217             for (int ii = 0; ii < items.length; ++ii)
218             {
219                 items[ii] = itemList.get(ii);
220                 // ついでにもうべたべたで...ここで表示用の文字列を置き換える
221                 //  (注: itemsだけ置き換え、itemList と current は 内部値のままとなっている
222                 if (key.equals(ICameraStatus.SHUTTER_SPEED))
223                 {
224                     items[ii] = items[ii].replace(".", "/");
225                 }
226                 else if (key.equals(ICameraStatus.APERATURE))
227                 {
228                     items[ii] = "F" + items[ii];
229                 }
230             }
231
232             AlertDialog.Builder builder = new AlertDialog.Builder(activity);
233             builder.setSingleChoiceItems(items, itemList.indexOf(current), new DialogInterface.OnClickListener() {
234                 @Override
235                 public void onClick(DialogInterface dialogInterface, int i)
236                 {
237                     String choice = itemList.get(i);
238                     Log.v(TAG, key + " ITEM CHOICED : " + choice + "(CURRENT : " + current + ")");
239
240                     statusList.setStatus(key, choice);
241                     dialogInterface.dismiss();
242                 }
243             });
244             builder.show();
245         }
246         catch (Exception e)
247         {
248             e.printStackTrace();
249         }
250     }
251 }