A jogging timer for Android wear.
Revision | 40230bf8683bf1081d276800e325df501ab95427 (tree) |
---|---|
Zeit | 2018-04-18 00:15:57 |
Autor | MRSa <mrsa@myad...> |
Commiter | MRSa |
CreateModelDataDialogのDialogFragment化(Ambient時に操作できない不具合を改修)
@@ -256,8 +256,8 @@ public class RecordDetailSetup implements ITimeEntryDatabaseCallback, IDetailEd | ||
256 | 256 | @Override |
257 | 257 | public void run() |
258 | 258 | { |
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"); | |
261 | 261 | } |
262 | 262 | }); |
263 | 263 | } |
@@ -218,8 +218,8 @@ public class ListActivity extends WearableActivity implements IDetailLauncher, R | ||
218 | 218 | { |
219 | 219 | case R.id.menu_create_model: |
220 | 220 | // モデルデータの作成 |
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"); | |
223 | 223 | break; |
224 | 224 | |
225 | 225 |
@@ -1,8 +1,12 @@ | ||
1 | 1 | package net.osdn.gokigen.joggingtimer.utilities; |
2 | 2 | |
3 | +import android.app.Activity; | |
3 | 4 | import android.app.AlertDialog; |
5 | +import android.app.Dialog; | |
6 | +import android.app.DialogFragment; | |
4 | 7 | import android.content.DialogInterface; |
5 | -import android.support.wearable.activity.WearableActivity; | |
8 | +import android.os.Bundle; | |
9 | +import android.support.annotation.NonNull; | |
6 | 10 | import android.util.Log; |
7 | 11 | import android.view.ContextThemeWrapper; |
8 | 12 | import android.view.LayoutInflater; |
@@ -18,24 +22,58 @@ import net.osdn.gokigen.joggingtimer.R; | ||
18 | 22 | * |
19 | 23 | * |
20 | 24 | */ |
21 | -public class CreateModelDataDialog | |
25 | +public class CreateModelDataDialog extends DialogFragment | |
22 | 26 | { |
23 | 27 | private final String TAG = toString(); |
24 | - private final WearableActivity activity; | |
25 | 28 | |
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) | |
27 | 41 | { |
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); | |
29 | 52 | } |
30 | 53 | |
31 | 54 | /** |
32 | 55 | * |
33 | - * @param callback 結果をコールバック | |
56 | + * | |
34 | 57 | */ |
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) | |
36 | 73 | { |
37 | 74 | Log.v(TAG, "show " + "def. : " + defaultValue); |
38 | 75 | |
76 | + Activity activity = getActivity(); | |
39 | 77 | // 確認ダイアログの生成 |
40 | 78 | final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme)); |
41 | 79 |
@@ -117,16 +155,39 @@ public class CreateModelDataDialog | ||
117 | 155 | new DialogInterface.OnClickListener() { |
118 | 156 | public void onClick(DialogInterface dialog, int which) |
119 | 157 | { |
120 | - callback.dataCreateCancelled(); | |
158 | + try | |
159 | + { | |
160 | + callback.dataCreateCancelled(); | |
161 | + } | |
162 | + catch (Exception e) | |
163 | + { | |
164 | + e.printStackTrace(); | |
165 | + } | |
121 | 166 | dialog.cancel(); |
122 | 167 | } |
123 | 168 | }); |
124 | 169 | |
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 | + } | |
127 | 184 | } |
128 | 185 | |
129 | - // コールバックインタフェース | |
186 | + | |
187 | + /** | |
188 | + * コールバックインタフェース | |
189 | + * | |
190 | + */ | |
130 | 191 | public interface Callback |
131 | 192 | { |
132 | 193 | void dataCreated(boolean isLap, int lap, long previousValue, long newValue); // OKを選択したとき |