OSDN Git Service

キー操作時のバイブレーション対応。
authorMRSa <mrsa@myad.jp>
Sun, 12 Aug 2018 15:24:38 +0000 (00:24 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 12 Aug 2018 15:24:38 +0000 (00:24 +0900)
app/src/main/AndroidManifest.xml
app/src/main/java/net/osdn/gokigen/gr2control/Gr2ControlMain.java
app/src/main/java/net/osdn/gokigen/gr2control/liveview/LiveViewFragment.java
app/src/main/java/net/osdn/gokigen/gr2control/liveview/LiveViewKeyPanelClickListener.java

index 7e3de3f..eb98496 100644 (file)
@@ -6,6 +6,7 @@
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.VIBRATE" />
 
     <application
         android:allowBackup="true"
index b91691b..edc0a5d 100644 (file)
@@ -58,12 +58,14 @@ public class Gr2ControlMain extends AppCompatActivity
         if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
+                (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
             ActivityCompat.requestPermissions(this,
                     new String[]{
                             Manifest.permission.WRITE_EXTERNAL_STORAGE,
                             Manifest.permission.ACCESS_NETWORK_STATE,
                             Manifest.permission.ACCESS_WIFI_STATE,
+                            Manifest.permission.VIBRATE,
                             Manifest.permission.INTERNET,
                     },
                     REQUEST_NEED_PERMISSIONS);
index 5cfe78a..8c06327 100644 (file)
@@ -4,6 +4,7 @@ import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.os.Vibrator;
 import android.support.annotation.NonNull;
 import android.support.v4.app.Fragment;
 import android.support.v4.content.res.ResourcesCompat;
@@ -33,6 +34,8 @@ import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
 import net.osdn.gokigen.gr2control.scene.IChangeScene;
 
+import static android.content.Context.VIBRATOR_SERVICE;
+
 /**
  *  撮影用ライブビュー画面
  *
@@ -142,9 +145,11 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             {
                 Log.v(TAG, "interfaceInjector is NULL...");
             }
-            if (onClickTouchListener == null)
+            Activity activity = this.getActivity();
+            Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
+            if ((onClickTouchListener == null)&&(activity != null))
             {
-                onClickTouchListener = new LiveViewClickTouchListener(this.getActivity(), imageView, this, changeScene, interfaceProvider, this);
+                onClickTouchListener = new LiveViewClickTouchListener(activity, imageView, this, changeScene, interfaceProvider, this);
             }
             imageView.setOnClickListener(onClickTouchListener);
             imageView.setOnTouchListener(onClickTouchListener);
@@ -161,7 +166,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
 
             if (onPanelClickListener == null)
             {
-                onPanelClickListener = new LiveViewControlPanelClickListener(this.getActivity(), interfaceProvider);
+                onPanelClickListener = new LiveViewControlPanelClickListener(activity, interfaceProvider);
             }
             setPanelClickListener(view, R.id.takemodeTextView);
             setPanelClickListener(view, R.id.shutterSpeedTextView);
@@ -173,7 +178,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
 
             if (onKeyPanelClickListener == null)
             {
-                onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider);
+                onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider, vibrator);
             }
             setKeyPanelClickListener(view, R.id.button_front_left);
             setKeyPanelClickListener(view, R.id.button_front_right);
index 59e4933..dacae11 100644 (file)
@@ -1,6 +1,8 @@
 package net.osdn.gokigen.gr2control.liveview;
 
+import android.os.Vibrator;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.util.Log;
 import android.view.View;
 
@@ -16,10 +18,12 @@ class LiveViewKeyPanelClickListener  implements View.OnClickListener
 {
     private final String TAG = toString();
     private final IInterfaceProvider interfaceProvider;
+    private final Vibrator vibrator;
 
-    LiveViewKeyPanelClickListener(@NonNull IInterfaceProvider interfaceProvider)
+    LiveViewKeyPanelClickListener(@NonNull IInterfaceProvider interfaceProvider, @Nullable Vibrator vibrator)
     {
         this.interfaceProvider = interfaceProvider;
+        this.vibrator = vibrator;
     }
 
     @Override
@@ -113,6 +117,10 @@ class LiveViewKeyPanelClickListener  implements View.OnClickListener
                 if (buttonControl != null)
                 {
                     buttonControl.pushedButton(keyId);
+                    if (vibrator != null)
+                    {
+                        vibrator.vibrate(30);
+                    }
                 }
             }
         }