OSDN Git Service

フラッシュモードとセルフタイマーの設定を変更できるようにする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewFragment.java
index 97bf434..f8aa972 100644 (file)
@@ -1,21 +1,24 @@
 package net.osdn.gokigen.gr2control.liveview;
 
-import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Vibrator;
-import android.support.annotation.NonNull;
-import android.support.v4.app.Fragment;
-import android.support.v4.content.ContextCompat;
-import android.support.v4.content.res.ResourcesCompat;
-import android.support.v4.graphics.drawable.DrawableCompat;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.preference.PreferenceManager;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
+import androidx.core.graphics.drawable.DrawableCompat;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.PreferenceManager;
+
 import android.util.Log;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -28,6 +31,7 @@ import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
 import net.osdn.gokigen.gr2control.camera.ICameraRunMode;
+import net.osdn.gokigen.gr2control.camera.ICameraRunModeCallback;
 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
@@ -35,6 +39,8 @@ import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
+import net.osdn.gokigen.gr2control.camera.olympus.myolycameraprops.LoadSaveCameraProperties;
+import net.osdn.gokigen.gr2control.camera.olympus.myolycameraprops.LoadSaveMyCameraPropertyDialog;
 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
 import net.osdn.gokigen.gr2control.scene.IChangeScene;
@@ -45,7 +51,7 @@ import static android.content.Context.VIBRATOR_SERVICE;
  *  撮影用ライブビュー画面
  *
  */
-public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify, LiveViewKeyPanelClickListener.KeyPanelFeedback
+public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify, LiveViewKeyPanelClickListener.KeyPanelFeedback, ICameraRunModeCallback
 {
     private final String TAG = this.toString();
 
@@ -60,6 +66,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     private LiveViewClickTouchListener onClickTouchListener = null;
     private LiveViewControlPanelClickListener onPanelClickListener = null;
     private LiveViewKeyPanelClickListener onKeyPanelClickListener = null;
+    private LiveViewFujiXKeyPanelClickListener fujiXOnKeyPanelClickListener = null;
 
     private TextView statusArea = null;
     private TextView focalLengthArea = null;
@@ -112,7 +119,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
      *
      */
     @Override
-    public void onAttach(Context context)
+    public void onAttach(@NonNull Context context)
     {
         super.onAttach(context);
         Log.v(TAG, "onAttach()");
@@ -150,7 +157,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             {
                 Log.v(TAG, "interfaceInjector is NULL...");
             }
-            Activity activity = this.getActivity();
+            FragmentActivity activity = this.getActivity();
             Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
             if ((onClickTouchListener == null)&&(activity != null))
             {
@@ -159,6 +166,10 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             imageView.setOnClickListener(onClickTouchListener);
             imageView.setOnTouchListener(onClickTouchListener);
 
+            // キーイベントを拾うことにする
+            view.setOnKeyListener(onClickTouchListener);
+            view.setFocusableInTouchMode(true);
+
             setOnClickListener(view, R.id.hideControlPanelTextView);
             setOnClickListener(view, R.id.showControlPanelTextView);
             setOnClickListener(view, R.id.showKeyPanelImageView);
@@ -171,6 +182,8 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             setOnClickListener(view, R.id.show_hide_grid_button);
             setOnClickListener(view, R.id.zoom_in_button);
             setOnClickListener(view, R.id.zoom_out_button);
+            setOnClickListener(view, R.id.specialButtonImageView);
+            setOnClickListener(view, R.id.fuji_x_hideKeyPanelTextView);
 
             if (onPanelClickListener == null)
             {
@@ -211,6 +224,19 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             setKeyPanelClickListener(view, R.id.button_lcd_onoff);
             setKeyPanelClickListener(view, R.id.button_highlight);
 
+            if (fujiXOnKeyPanelClickListener == null)
+            {
+                fujiXOnKeyPanelClickListener = new LiveViewFujiXKeyPanelClickListener(getActivity(), interfaceProvider, vibrator);
+            }
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_sv_minus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_sv_plus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_tv_minus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_tv_plus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_xv_minus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_xv_plus);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_flash);
+            setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_timer);
+
             connectStatus = view.findViewById(R.id.connect_disconnect_button);
             if (connectStatus != null)
             {
@@ -273,6 +299,24 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             if (button != null)
             {
                 button.setOnClickListener(onKeyPanelClickListener);
+                button.setOnLongClickListener(onKeyPanelClickListener);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void setFujiXKeyPanelClickListener(View view, int id)
+    {
+        try
+        {
+            View button = view.findViewById(id);
+            if (button != null)
+            {
+                button.setOnClickListener(fujiXOnKeyPanelClickListener);
+                button.setOnLongClickListener(fujiXOnKeyPanelClickListener);
             }
         }
         catch (Exception e)
@@ -349,7 +393,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            Activity activity = getActivity();
+            FragmentActivity activity = getActivity();
             if (activity != null)
             {
                 if (showGrid == null) {
@@ -483,10 +527,16 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
         {
             // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。)
-            changeRunModeExecutor.changeRunMode(true);
+            changeRunModeExecutor.changeRunMode(true, this);
+            Log.v(TAG, "onResume() End");
+            return;
         }
+        prepareToStart();
+        Log.v(TAG, "onResume() End");
+    }
 
-        // propertyを取得
+    private void prepareToStart()
+    {
         try
         {
             Context context = getContext();
@@ -510,7 +560,18 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         {
             e.printStackTrace();
         }
-        Log.v(TAG, "onResume() End");
+    }
+
+    @Override
+    public void onCompleted(boolean isRecording)
+    {
+        prepareToStart();
+    }
+
+    @Override
+    public void onErrorOccurred(boolean isRecording)
+    {
+        prepareToStart();
     }
 
     /**
@@ -570,6 +631,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     @Override
     public void startLiveView()
     {
+        Log.v(TAG, " LiveViewFragment::startLiveView() ");
         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
         if (liveViewControl == null)
         {
@@ -633,16 +695,8 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         try
         {
             Log.v(TAG, "showFavoriteSettingDialog()");
-/*
-            LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
-            dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
-            dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
-            FragmentManager manager = getFragmentManager();
-            if (manager != null)
-            {
-                dialog.show(manager, "my_dialog");
-            }
-*/
+            LoadSaveMyCameraPropertyDialog dialog = LoadSaveMyCameraPropertyDialog.newInstance(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterfaceProvider()));
+            dialog.show(getChildFragmentManager(), "favorite_dialog");
         }
         catch (Exception e)
         {
@@ -661,7 +715,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             @Override
             public void run() {
                 // isVisibleがtrueなら、ズームレンズボタンを有効にする
-                Activity activity = getActivity();
+                FragmentActivity activity = getActivity();
                 if (activity != null)
                 {
                     try
@@ -709,7 +763,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         if (statusWatcher != null)
         {
-            statusWatcher.stoptStatusWatch();
+            statusWatcher.stopStatusWatch();
         }
     }
 
@@ -719,7 +773,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
      */
     private void runOnUiThread(Runnable action)
     {
-        Activity activity = getActivity();
+        FragmentActivity activity = getActivity();
         if (activity == null)
         {
             return;
@@ -732,7 +786,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -763,7 +817,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         try
         {
             final String shutterSpeed = tv.replace(".", "/");
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -794,7 +848,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         try
         {
             final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -824,7 +878,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -855,7 +909,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         try
         {
             Log.v(TAG, "updatedMeteringMode() : " + meteringMode);
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if ((activity == null)||(meteringMode == null))
             {
                 return;
@@ -910,11 +964,11 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
      *
      */
     @Override
-    public void updateRemainBattery(int percentage)
+    public void updateRemainBattery(final int percentage)
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -937,7 +991,6 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
                 iconId = R.drawable.ic_battery_full_black_24dp;
             }
             final int id = iconId;
-            final boolean isAlert = (percentage < 20);
             activity.runOnUiThread(new Runnable()
             {
                 @Override
@@ -949,9 +1002,12 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
                         Drawable target = ResourcesCompat.getDrawable(getResources(), id, null);
                         if (target != null)
                         {
-                            if (isAlert)
+                            if (percentage <= 20)
                             {
                                 DrawableCompat.setTint(target, Color.RED);
+                            } else if (percentage <= 40)
+                            {
+                                DrawableCompat.setTint(target, Color.YELLOW);
                             }
                             view.setImageDrawable(target);
                             view.invalidate();
@@ -969,7 +1025,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     @Override
     public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
     {
-        Activity activity = getActivity();
+        final FragmentActivity activity = getActivity();
         try
         {
             if (activity != null)
@@ -977,31 +1033,32 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
                 activity.runOnUiThread(new Runnable() {
                     @Override
                     public void run() {
-                        ImageView view = getActivity().findViewById(R.id.focusUnlockImageView);
-                        if (focused)
+                        try
                         {
-                            Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
-                            if (icon != null)
-                            {
-                                DrawableCompat.setTint(icon, Color.GREEN);
-                                view.setImageDrawable(icon);
+                            ImageView view = activity.findViewById(R.id.focusUnlockImageView);
+                            if (focused) {
+                                Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
+                                if (icon != null) {
+                                    DrawableCompat.setTint(icon, Color.GREEN);
+                                    view.setImageDrawable(icon);
+                                }
+                            } else {
+                                Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_focus_free_black_24dp, null);
+                                if (icon != null) {
+                                    int color = Color.BLACK;
+                                    if (focusLocked) {
+                                        color = Color.RED;
+                                    }
+                                    DrawableCompat.setTint(icon, color);
+                                    view.setImageDrawable(icon);
+                                }
                             }
+                            view.invalidate();
                         }
-                        else
+                        catch (Exception e)
                         {
-                            Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_focus_free_black_24dp, null);
-                            if (icon != null)
-                            {
-                                int color = Color.BLACK;
-                                if (focusLocked)
-                                {
-                                    color = Color.RED;
-                                }
-                                DrawableCompat.setTint(icon, color);
-                                view.setImageDrawable(icon);
-                            }
+                            e.printStackTrace();
                         }
-                        view.invalidate();
                     }
                 });
             }
@@ -1035,7 +1092,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            Activity activity = getActivity();
+            FragmentActivity activity = getActivity();
             if (activity != null)
             {
                 ImageView imageView = activity.findViewById(R.id.button_toggle_aeaf);
@@ -1067,7 +1124,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            Activity activity = getActivity();
+            FragmentActivity activity = getActivity();
             if (activity != null)
             {
                 TextView textView = activity.findViewById(R.id.lever_ael_caf);
@@ -1087,4 +1144,9 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             e.printStackTrace();
         }
     }
+
+    public boolean handleKeyDown(int keyCode, KeyEvent event)
+    {
+        return (onClickTouchListener.onKey(null, keyCode, event));
+    }
 }