SDKを最新に更新。
リモートスイッチでシャッターを切れるように変更。
@@ -8,6 +8,7 @@ | ||
8 | 8 | import android.provider.Settings; |
9 | 9 | import android.os.Bundle; |
10 | 10 | import android.util.Log; |
11 | +import android.view.KeyEvent; | |
11 | 12 | import android.view.WindowManager; |
12 | 13 | |
13 | 14 | import androidx.appcompat.app.ActionBar; |
@@ -33,6 +34,7 @@ | ||
33 | 34 | private final String TAG = this.toString(); |
34 | 35 | private static final int REQUEST_NEED_PERMISSIONS = 1010; |
35 | 36 | private CameraConnectCoordinator coordinator = null; |
37 | + private LiveViewFragment liveViewFragment = null; | |
36 | 38 | |
37 | 39 | /** |
38 | 40 | * |
@@ -287,10 +289,13 @@ | ||
287 | 289 | */ |
288 | 290 | private void changeViewToLiveViewFragment(OLYCamera myCamera) |
289 | 291 | { |
290 | - LiveViewFragment fragment = new LiveViewFragment(); | |
291 | - fragment.setCamera(myCamera); | |
292 | + if (liveViewFragment == null) | |
293 | + { | |
294 | + liveViewFragment = new LiveViewFragment(); | |
295 | + } | |
296 | + liveViewFragment.setCamera(myCamera); | |
292 | 297 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
293 | - transaction.replace(R.id.fragment1, fragment); | |
298 | + transaction.replace(R.id.fragment1, liveViewFragment); | |
294 | 299 | transaction.commitAllowingStateLoss(); |
295 | 300 | } |
296 | 301 |
@@ -327,4 +332,25 @@ | ||
327 | 332 | return (ret); |
328 | 333 | } |
329 | 334 | |
335 | + @Override | |
336 | + public boolean onKeyDown(int keyCode, KeyEvent event) | |
337 | + { | |
338 | + Log.v(TAG, "onKeyDown()" + " " + keyCode); | |
339 | + try | |
340 | + { | |
341 | + if ((event.getAction() == KeyEvent.ACTION_DOWN)&& | |
342 | + ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA))) | |
343 | + { | |
344 | + if (liveViewFragment != null) | |
345 | + { | |
346 | + return (liveViewFragment.handleKeyDown(keyCode, event)); | |
347 | + } | |
348 | + } | |
349 | + } | |
350 | + catch (Exception e) | |
351 | + { | |
352 | + e.printStackTrace(); | |
353 | + } | |
354 | + return (super.onKeyDown(keyCode, event)); | |
355 | + } | |
330 | 356 | } |
@@ -2,9 +2,12 @@ | ||
2 | 2 | |
3 | 3 | import android.graphics.PointF; |
4 | 4 | import android.util.Log; |
5 | +import android.view.KeyEvent; | |
5 | 6 | import android.view.MotionEvent; |
6 | 7 | import android.view.View; |
7 | 8 | |
9 | +import androidx.annotation.NonNull; | |
10 | + | |
8 | 11 | import jp.osdn.gokigen.aira01a.R; |
9 | 12 | import jp.osdn.gokigen.aira01a.takepicture.CameraController; |
10 | 13 | import jp.osdn.gokigen.aira01a.takepicture.TakePictureControl; |
@@ -218,6 +221,30 @@ | ||
218 | 221 | } |
219 | 222 | } |
220 | 223 | |
224 | + /** | |
225 | + * ボタンを押したときの対応 | |
226 | + * | |
227 | + */ | |
228 | + public boolean onKey(View view, int keyCode, @NonNull KeyEvent keyEvent) | |
229 | + { | |
230 | + Log.v(TAG, "onKey() : " + keyCode); | |
231 | + try | |
232 | + { | |
233 | + if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN)&& | |
234 | + ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA))) | |
235 | + { | |
236 | + takePictureControl.startTakePicture(this); | |
237 | + return (true); | |
238 | + } | |
239 | + } | |
240 | + catch (Exception e) | |
241 | + { | |
242 | + e.printStackTrace(); | |
243 | + } | |
244 | + return (false); | |
245 | + } | |
246 | + | |
247 | + | |
221 | 248 | // ------------------------------------------------------------------------- |
222 | 249 | // Camera actions |
223 | 250 | // ------------------------------------------------------------------------- |
@@ -10,6 +10,7 @@ | ||
10 | 10 | import android.graphics.PointF; |
11 | 11 | import android.os.Bundle; |
12 | 12 | import android.util.Log; |
13 | +import android.view.KeyEvent; | |
13 | 14 | import android.view.LayoutInflater; |
14 | 15 | import android.view.MotionEvent; |
15 | 16 | import android.view.View; |
@@ -1305,4 +1306,14 @@ | ||
1305 | 1306 | } |
1306 | 1307 | } |
1307 | 1308 | |
1309 | + | |
1310 | + public boolean handleKeyDown(int keyCode, KeyEvent event) | |
1311 | + { | |
1312 | + if (viewOnTouchClickListener == null) | |
1313 | + { | |
1314 | + return (false); | |
1315 | + } | |
1316 | + return (viewOnTouchClickListener.onKey(null, keyCode, event)); | |
1317 | + } | |
1318 | + | |
1308 | 1319 | } |