Ricoh GR2 Control App for Android.
Revision | fbd3718f64525df954bc7b305afe14d002a04c7a (tree) |
---|---|
Zeit | 2020-05-05 21:48:17 |
Autor | MRSa <mrsa@myad...> |
Commiter | MRSa |
RICOHの接続処理を微修正。
@@ -1,6 +1,5 @@ | ||
1 | 1 | package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper.connection; |
2 | 2 | |
3 | -import android.app.Activity; | |
4 | 3 | import android.content.BroadcastReceiver; |
5 | 4 | import android.content.Context; |
6 | 5 | import android.content.DialogInterface; |
@@ -21,6 +20,7 @@ import java.util.concurrent.Executors; | ||
21 | 20 | |
22 | 21 | import androidx.annotation.NonNull; |
23 | 22 | import androidx.appcompat.app.AlertDialog; |
23 | +import androidx.fragment.app.FragmentActivity; | |
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -30,7 +30,7 @@ import androidx.appcompat.app.AlertDialog; | ||
30 | 30 | public class RicohGr2Connection implements ICameraConnection |
31 | 31 | { |
32 | 32 | private final String TAG = toString(); |
33 | - private final Activity context; | |
33 | + private final FragmentActivity context; | |
34 | 34 | private final ICameraStatusReceiver statusReceiver; |
35 | 35 | private final BroadcastReceiver connectionReceiver; |
36 | 36 | private final IUseGR2CommandNotify gr2CommandNotify; |
@@ -45,9 +45,9 @@ public class RicohGr2Connection implements ICameraConnection | ||
45 | 45 | * |
46 | 46 | * |
47 | 47 | */ |
48 | - public RicohGr2Connection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver, @NonNull IUseGR2CommandNotify gr2CommandNotify) | |
48 | + public RicohGr2Connection(@NonNull final FragmentActivity context, @NonNull final ICameraStatusReceiver statusReceiver, @NonNull IUseGR2CommandNotify gr2CommandNotify) | |
49 | 49 | { |
50 | - Log.v(TAG, "RicohGr2Connection()"); | |
50 | + Log.v(TAG, " RicohGr2Connection()"); | |
51 | 51 | this.context = context; |
52 | 52 | this.statusReceiver = statusReceiver; |
53 | 53 | this.gr2CommandNotify = gr2CommandNotify; |
@@ -183,47 +183,41 @@ public class RicohGr2Connection implements ICameraConnection | ||
183 | 183 | public void alertConnectingFailed(String message) |
184 | 184 | { |
185 | 185 | Log.v(TAG, "alertConnectingFailed() : " + message); |
186 | - final AlertDialog.Builder builder = new AlertDialog.Builder(context) | |
187 | - .setTitle(context.getString(R.string.dialog_title_connect_failed)) | |
188 | - .setMessage(message) | |
189 | - .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() { | |
190 | - @Override | |
191 | - public void onClick(DialogInterface dialog, int which) | |
192 | - { | |
193 | - connect(); | |
194 | - } | |
195 | - }) | |
196 | - .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() { | |
197 | - @Override | |
198 | - public void onClick(DialogInterface dialog, int which) | |
199 | - { | |
200 | - try | |
201 | - { | |
202 | - // Wifi 設定画面を表示する | |
203 | - context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); | |
204 | - } | |
205 | - catch (android.content.ActivityNotFoundException ex) | |
206 | - { | |
207 | - // Activity が存在しなかった...設定画面が起動できなかった | |
208 | - Log.v(TAG, "android.content.ActivityNotFoundException..."); | |
209 | - | |
210 | - // この場合は、再試行と等価な動きとする | |
186 | + if (context != null) | |
187 | + { | |
188 | + final AlertDialog.Builder builder = new AlertDialog.Builder(context) | |
189 | + .setTitle(context.getString(R.string.dialog_title_connect_failed)) | |
190 | + .setMessage(message) | |
191 | + .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() { | |
192 | + @Override | |
193 | + public void onClick(DialogInterface dialog, int which) { | |
211 | 194 | connect(); |
212 | 195 | } |
213 | - catch (Exception e) | |
214 | - { | |
215 | - e.printStackTrace(); | |
196 | + }) | |
197 | + .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() { | |
198 | + @Override | |
199 | + public void onClick(DialogInterface dialog, int which) { | |
200 | + try { | |
201 | + // Wifi 設定画面を表示する | |
202 | + context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); | |
203 | + } catch (android.content.ActivityNotFoundException ex) { | |
204 | + // Activity が存在しなかった...設定画面が起動できなかった | |
205 | + Log.v(TAG, "android.content.ActivityNotFoundException..."); | |
206 | + | |
207 | + // この場合は、再試行と等価な動きとする | |
208 | + connect(); | |
209 | + } catch (Exception e) { | |
210 | + e.printStackTrace(); | |
211 | + } | |
216 | 212 | } |
217 | - } | |
218 | - }); | |
219 | - context.runOnUiThread(new Runnable() | |
220 | - { | |
221 | - @Override | |
222 | - public void run() | |
223 | - { | |
224 | - builder.show(); | |
225 | - } | |
226 | - }); | |
213 | + }); | |
214 | + context.runOnUiThread(new Runnable() { | |
215 | + @Override | |
216 | + public void run() { | |
217 | + builder.show(); | |
218 | + } | |
219 | + }); | |
220 | + } | |
227 | 221 | } |
228 | 222 | |
229 | 223 | @Override |