package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper.connection;
-import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentActivity;
/**
public class RicohGr2Connection implements ICameraConnection
{
private final String TAG = toString();
- private final Activity context;
+ private final FragmentActivity context;
private final ICameraStatusReceiver statusReceiver;
private final BroadcastReceiver connectionReceiver;
+ private final IUseGR2CommandNotify gr2CommandNotify;
//private final ConnectivityManager connectivityManager;
private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
//private final Handler networkConnectionTimeoutHandler;
*
*
*/
- public RicohGr2Connection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver)
+ public RicohGr2Connection(@NonNull final FragmentActivity context, @NonNull final ICameraStatusReceiver statusReceiver, @NonNull IUseGR2CommandNotify gr2CommandNotify)
{
- Log.v(TAG, "RicohGr2Connection()");
+ Log.v(TAG, " RicohGr2Connection()");
this.context = context;
this.statusReceiver = statusReceiver;
+ this.gr2CommandNotify = gr2CommandNotify;
connectionReceiver = new BroadcastReceiver()
{
@Override
WifiInfo info = wifiManager.getConnectionInfo();
if (wifiManager.isWifiEnabled() && info != null)
{
- if (info.getNetworkId() != -1)
+ if (info.getNetworkId() == -1)
{
Log.v(TAG, "Network ID is -1, there is no currently connected network.");
}
+ else
+ {
+ Log.v(TAG, "Network ID is " + info.getNetworkId());
+ }
// 自動接続が指示されていた場合は、カメラとの接続処理を行う
connectToCamera();
- } else {
+ }
+ else
+ {
if (info == null)
{
Log.v(TAG, "NETWORK INFO IS NULL.");
- } else {
+ }
+ else
+ {
Log.v(TAG, "isWifiEnabled : " + wifiManager.isWifiEnabled() + " NetworkId : " + info.getNetworkId());
}
}
public void alertConnectingFailed(String message)
{
Log.v(TAG, "alertConnectingFailed() : " + message);
- final AlertDialog.Builder builder = new AlertDialog.Builder(context)
- .setTitle(context.getString(R.string.dialog_title_connect_failed))
- .setMessage(message)
- .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- connect();
- }
- })
- .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- try
- {
- // Wifi 設定画面を表示する
- context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
- }
- catch (android.content.ActivityNotFoundException ex)
- {
- // Activity が存在しなかった...設定画面が起動できなかった
- Log.v(TAG, "android.content.ActivityNotFoundException...");
-
- // この場合は、再試行と等価な動きとする
+ if (context != null)
+ {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context)
+ .setTitle(context.getString(R.string.dialog_title_connect_failed))
+ .setMessage(message)
+ .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
connect();
}
- catch (Exception e)
- {
- e.printStackTrace();
+ })
+ .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ try {
+ // Wifi 設定画面を表示する
+ context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+ } catch (android.content.ActivityNotFoundException ex) {
+ // Activity が存在しなかった...設定画面が起動できなかった
+ Log.v(TAG, "android.content.ActivityNotFoundException...");
+
+ // この場合は、再試行と等価な動きとする
+ connect();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- }
- });
- context.runOnUiThread(new Runnable()
- {
- @Override
- public void run()
- {
- builder.show();
- }
- });
+ });
+ context.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ builder.show();
+ }
+ });
+ }
}
@Override
connectionStatus = CameraConnectionStatus.CONNECTING;
try
{
- cameraExecutor.execute(new RicohGr2CameraConnectSequence(context, statusReceiver, this));
+ cameraExecutor.execute(new RicohGr2CameraConnectSequence(context, statusReceiver, this, gr2CommandNotify));
}
catch (Exception e)
{