1 package net.osdn.gokigen.gr2control;
3 import android.Manifest;
4 import android.content.SharedPreferences;
5 import android.content.pm.PackageManager;
7 import androidx.annotation.NonNull;
8 import androidx.appcompat.app.ActionBar;
9 import androidx.appcompat.app.AppCompatActivity;
10 import androidx.core.app.ActivityCompat;
11 import androidx.core.content.ContextCompat;
12 import androidx.fragment.app.FragmentTransaction;
13 import androidx.preference.PreferenceManager;
15 import android.os.Bundle;
16 import android.util.Log;
17 import android.view.KeyEvent;
18 import android.view.WindowManager;
20 import net.osdn.gokigen.gr2control.camera.CameraInterfaceProvider;
21 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
22 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
23 import net.osdn.gokigen.gr2control.liveview.LiveViewFragment;
24 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
25 import net.osdn.gokigen.gr2control.scene.CameraSceneUpdater;
31 public class Gr2ControlMain extends AppCompatActivity
33 private final String TAG = toString();
34 private IInterfaceProvider interfaceProvider = null;
35 private CameraSceneUpdater scenceUpdater = null;
36 private LiveViewFragment liveViewFragment = null;
39 protected void onCreate(Bundle savedInstanceState)
41 super.onCreate(savedInstanceState);
44 setContentView(R.layout.activity_gr2_control_main);
47 ActionBar bar = getSupportActionBar();
58 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
61 final int REQUEST_NEED_PERMISSIONS = 1010;
62 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
63 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
64 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
65 (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) ||
66 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
67 ActivityCompat.requestPermissions(this,
69 Manifest.permission.WRITE_EXTERNAL_STORAGE,
70 Manifest.permission.ACCESS_NETWORK_STATE,
71 Manifest.permission.ACCESS_WIFI_STATE,
72 Manifest.permission.VIBRATE,
73 Manifest.permission.INTERNET,
75 REQUEST_NEED_PERMISSIONS);
87 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
89 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
97 protected void onPause()
102 ICameraConnection connection = interfaceProvider.getCameraConnection();
103 if (connection != null)
105 connection.stopWatchWifiStatus(this);
115 * クラスの初期化 (instantiate)
118 private void initializeClass()
122 scenceUpdater = CameraSceneUpdater.newInstance(this);
123 interfaceProvider = CameraInterfaceProvider.newInstance(this, scenceUpdater);
125 if (liveViewFragment == null)
127 liveViewFragment = LiveViewFragment.newInstance(scenceUpdater, interfaceProvider);
128 scenceUpdater.registerInterface(liveViewFragment, interfaceProvider);
130 liveViewFragment.setRetainInstance(true);
131 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
132 transaction.replace(R.id.fragment1, liveViewFragment);
133 transaction.commitAllowingStateLoss();
142 * 初期化終了時の処理 (カメラへの自動接続)
144 private void onReadyClass()
149 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
150 boolean isAutoConnectCamera = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
151 Log.v(TAG, "isAutoConnectCamera() : " + isAutoConnectCamera);
154 if (isAutoConnectCamera)
157 scenceUpdater.changeCameraConnection();
167 public boolean onKeyDown(int keyCode, KeyEvent event)
169 Log.v(TAG, "onKeyDown()" + " " + keyCode);
172 if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
173 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
175 if (liveViewFragment != null)
177 return (liveViewFragment.handleKeyDown(keyCode, event));
185 return (super.onKeyDown(keyCode, event));