• R/O
  • HTTP
  • SSH
  • HTTPS

JoggingTimer: Commit

A jogging timer for Android wear.


Commit MetaInfo

Revision40230bf8683bf1081d276800e325df501ab95427 (tree)
Time2018-04-18 00:15:57
AuthorMRSa <mrsa@myad...>
CommiterMRSa

Log Message

CreateModelDataDialogのDialogFragment化(Ambient時に操作できない不具合を改修)

Change Summary

Incremental Difference

--- a/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.java
+++ b/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.java
@@ -256,8 +256,8 @@ public class RecordDetailSetup implements ITimeEntryDatabaseCallback, IDetailEd
256256 @Override
257257 public void run()
258258 {
259- CreateModelDataDialog dialog2 = new CreateModelDataDialog(activity);
260- dialog2.show(false, activity.getString(R.string.information_modify_time), count, new CreateModelData(database, editCallback, null, indexId, dataId), defaultMillis);
259+ CreateModelDataDialog dialog2 = CreateModelDataDialog.newInstance(false, activity.getString(R.string.information_modify_time), count, new CreateModelData(database, editCallback, null, indexId, dataId), defaultMillis);
260+ dialog2.show(activity.getFragmentManager(), "dialog2");
261261 }
262262 });
263263 }
--- a/wear/src/main/java/net/osdn/gokigen/joggingtimer/recordlist/ListActivity.java
+++ b/wear/src/main/java/net/osdn/gokigen/joggingtimer/recordlist/ListActivity.java
@@ -218,8 +218,8 @@ public class ListActivity extends WearableActivity implements IDetailLauncher, R
218218 {
219219 case R.id.menu_create_model:
220220 // モデルデータの作成
221- CreateModelDataDialog dialog2 = new CreateModelDataDialog(this);
222- dialog2.show(true, getString(R.string.information_time_picker), 0, setupper.getCreateModelDataCallback(ITimeEntryDatabase.DONT_USE_ID, ITimeEntryDatabase.DONT_USE_ID), 0);
221+ CreateModelDataDialog dialog2 = CreateModelDataDialog.newInstance(true, getString(R.string.information_time_picker), 0, setupper.getCreateModelDataCallback(ITimeEntryDatabase.DONT_USE_ID, ITimeEntryDatabase.DONT_USE_ID), 0);
222+ dialog2.show(getFragmentManager(), "dialog2");
223223 break;
224224
225225
--- a/wear/src/main/java/net/osdn/gokigen/joggingtimer/utilities/CreateModelDataDialog.java
+++ b/wear/src/main/java/net/osdn/gokigen/joggingtimer/utilities/CreateModelDataDialog.java
@@ -1,8 +1,12 @@
11 package net.osdn.gokigen.joggingtimer.utilities;
22
3+import android.app.Activity;
34 import android.app.AlertDialog;
5+import android.app.Dialog;
6+import android.app.DialogFragment;
47 import android.content.DialogInterface;
5-import android.support.wearable.activity.WearableActivity;
8+import android.os.Bundle;
9+import android.support.annotation.NonNull;
610 import android.util.Log;
711 import android.view.ContextThemeWrapper;
812 import android.view.LayoutInflater;
@@ -18,24 +22,58 @@ import net.osdn.gokigen.joggingtimer.R;
1822 *
1923 *
2024 */
21-public class CreateModelDataDialog
25+public class CreateModelDataDialog extends DialogFragment
2226 {
2327 private final String TAG = toString();
24- private final WearableActivity activity;
2528
26- public CreateModelDataDialog(WearableActivity activity)
29+ private boolean isLap = true;
30+ private String title = "";
31+ private int lapCount = 0;
32+ private Callback callback = null;
33+ private long defaultValue = 0;
34+ Dialog myDialog = null;
35+
36+ /**
37+ *
38+ *
39+ */
40+ public static CreateModelDataDialog newInstance(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
2741 {
28- this.activity = activity;
42+ CreateModelDataDialog instance = new CreateModelDataDialog();
43+ instance.prepare(isLap, title, lapCount, callback, defaultValue);
44+
45+ // パラメータはBundleにまとめておく
46+ Bundle arguments = new Bundle();
47+ arguments.putString("title", title);
48+ //arguments.putString("message", message);
49+ instance.setArguments(arguments);
50+
51+ return (instance);
2952 }
3053
3154 /**
3255 *
33- * @param callback 結果をコールバック
56+ *
3457 */
35- public void show(final boolean isLap, String title, final int lapCount, final Callback callback, final long defaultValue)
58+ private void prepare(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
59+ {
60+ this.isLap = isLap;
61+ this.title = title;
62+ this.lapCount = lapCount;
63+ this.callback = callback;
64+ this.defaultValue = defaultValue;
65+ }
66+
67+ /**
68+ *
69+ *
70+ */
71+ @Override
72+ public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
3673 {
3774 Log.v(TAG, "show " + "def. : " + defaultValue);
3875
76+ Activity activity = getActivity();
3977 // 確認ダイアログの生成
4078 final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
4179
@@ -117,16 +155,39 @@ public class CreateModelDataDialog
117155 new DialogInterface.OnClickListener() {
118156 public void onClick(DialogInterface dialog, int which)
119157 {
120- callback.dataCreateCancelled();
158+ try
159+ {
160+ callback.dataCreateCancelled();
161+ }
162+ catch (Exception e)
163+ {
164+ e.printStackTrace();
165+ }
121166 dialog.cancel();
122167 }
123168 });
124169
125- // 確認ダイアログを表示する
126- alertDialog.show();
170+ myDialog = alertDialog.create();
171+ return (myDialog);
172+ }
173+
174+
175+ @Override
176+ public void onPause()
177+ {
178+ super.onPause();
179+ Log.v(TAG, "AlertDialog::onPause()");
180+ if (myDialog != null)
181+ {
182+ myDialog.cancel();
183+ }
127184 }
128185
129- // コールバックインタフェース
186+
187+ /**
188+ * コールバックインタフェース
189+ *
190+ */
130191 public interface Callback
131192 {
132193 void dataCreated(boolean isLap, int lap, long previousValue, long newValue); // OKを選択したとき
Show on old repository browser