OSDN Git Service

フラッシュモードとセルフタイマーの設定を変更できるようにする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewFragment.java
index 4264d45..f8aa972 100644 (file)
@@ -1,6 +1,5 @@
 package net.osdn.gokigen.gr2control.liveview;
 
-import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.graphics.Color;
@@ -15,9 +14,11 @@ 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;
@@ -30,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;
@@ -49,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();
 
@@ -64,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;
@@ -116,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()");
@@ -154,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))
             {
@@ -180,6 +183,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             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)
             {
@@ -220,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)
             {
@@ -291,6 +308,23 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         }
     }
 
+    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)
+        {
+            e.printStackTrace();
+        }
+    }
+
     /**
      *
      */
@@ -359,7 +393,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            Activity activity = getActivity();
+            FragmentActivity activity = getActivity();
             if (activity != null)
             {
                 if (showGrid == null) {
@@ -493,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();
@@ -520,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();
     }
 
     /**
@@ -580,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)
         {
@@ -663,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
@@ -721,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;
@@ -734,7 +786,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -765,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;
@@ -796,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;
@@ -826,7 +878,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -857,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;
@@ -916,7 +968,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     {
         try
         {
-            final Activity activity = getActivity();
+            final FragmentActivity activity = getActivity();
             if (activity == null)
             {
                 return;
@@ -973,7 +1025,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
     @Override
     public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
     {
-        final Activity activity = getActivity();
+        final FragmentActivity activity = getActivity();
         try
         {
             if (activity != null)
@@ -1040,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);
@@ -1072,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);
@@ -1092,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));
+    }
 }