Ricoh Theta x Nurosky Shutter
Révision | 3a0c26fa091098fdfbf838fc1015b386e533e6a5 (tree) |
---|---|
l'heure | 2021-02-23 22:21:05 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
不要なパーミッションの整理など。
@@ -5,12 +5,9 @@ | ||
5 | 5 | <uses-feature android:name="com.theta360.receptor.v" android:required="true"/> |
6 | 6 | <uses-feature android:name="com.theta360.receptor.z1" android:required="true"/> |
7 | 7 | |
8 | - <uses-permission android:name="android.permission.BLUETOOTH" /> | |
9 | 8 | <uses-permission android:name="android.permission.INTERNET" /> |
10 | - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
11 | 9 | <uses-permission android:name="android.permission.BLUETOOTH" /> |
12 | 10 | <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> |
13 | - <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
14 | 11 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
15 | 12 | |
16 | 13 | <application |
@@ -1,9 +1,13 @@ | ||
1 | 1 | package jp.osdn.gokigen.thetathoughtshutter |
2 | 2 | |
3 | +import android.Manifest | |
3 | 4 | import android.bluetooth.BluetoothDevice |
5 | +import android.content.pm.PackageManager | |
4 | 6 | import android.os.Bundle |
5 | 7 | import android.util.Log |
6 | 8 | import android.view.KeyEvent |
9 | +import androidx.core.app.ActivityCompat | |
10 | +import androidx.core.content.ContextCompat | |
7 | 11 | import com.theta360.pluginlibrary.activity.PluginActivity |
8 | 12 | import com.theta360.pluginlibrary.callback.KeyCallback |
9 | 13 | import com.theta360.pluginlibrary.receiver.KeyReceiver |
@@ -21,7 +25,6 @@ import jp.osdn.gokigen.thetathoughtshutter.theta.ThetaSetupBluetoothSPP | ||
21 | 25 | import jp.osdn.gokigen.thetathoughtshutter.theta.operation.IOperationCallback |
22 | 26 | import jp.osdn.gokigen.thetathoughtshutter.theta.status.ThetaCameraStatusWatcher |
23 | 27 | import java.util.* |
24 | -import kotlin.collections.HashMap | |
25 | 28 | |
26 | 29 | class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingReceiver |
27 | 30 | { |
@@ -34,15 +37,54 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
34 | 37 | companion object |
35 | 38 | { |
36 | 39 | private val TAG = MainActivity::class.java.simpleName |
40 | + private const val REQUEST_CODE_PERMISSIONS = 10 | |
41 | + private val REQUIRED_PERMISSIONS = arrayOf( | |
42 | + Manifest.permission.INTERNET, | |
43 | + Manifest.permission.BLUETOOTH, | |
44 | + Manifest.permission.BLUETOOTH_ADMIN, | |
45 | + Manifest.permission.ACCESS_COARSE_LOCATION, | |
46 | + ) | |
37 | 47 | } |
38 | 48 | |
49 | + private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all { | |
50 | + ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED | |
51 | + } | |
52 | + | |
53 | + | |
39 | 54 | override fun onCreate(savedInstanceState: Bundle?) |
40 | 55 | { |
41 | 56 | super.onCreate(savedInstanceState) |
42 | 57 | setContentView(layout.activity_main) |
43 | - | |
44 | 58 | setAutoClose(true) |
59 | + updateStatus(applicationStatus.status) | |
60 | + | |
61 | + if (allPermissionsGranted()) | |
62 | + { | |
63 | + initializeKeyOperation() | |
64 | + } | |
65 | + else | |
66 | + { | |
67 | + ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS) | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) | |
72 | + { | |
73 | + if (requestCode == REQUEST_CODE_PERMISSIONS) | |
74 | + { | |
75 | + if (allPermissionsGranted()) | |
76 | + { | |
77 | + initializeKeyOperation() | |
78 | + } | |
79 | + else | |
80 | + { | |
81 | + finish() | |
82 | + } | |
83 | + } | |
84 | + } | |
45 | 85 | |
86 | + private fun initializeKeyOperation() | |
87 | + { | |
46 | 88 | setKeyCallback(object : KeyCallback { |
47 | 89 | override fun onKeyDown(keyCode: Int, event: KeyEvent?) { |
48 | 90 |
@@ -83,6 +125,7 @@ class MainActivity : PluginActivity(), IBluetoothScanResult, IDetectSensingRecei | ||
83 | 125 | updateStatus(applicationStatus.status) |
84 | 126 | } |
85 | 127 | |
128 | + | |
86 | 129 | // Bluetooth SPPで EEGに接続する |
87 | 130 | private fun connectToEEG() |
88 | 131 | { |