1 package net.osdn.gokigen.joggingtimer.utilities;
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.app.Dialog;
6 import androidx.fragment.app.DialogFragment;
8 import android.graphics.Color;
9 import android.os.Bundle;
10 import android.util.Log;
11 import android.view.LayoutInflater;
12 import android.view.View;
13 import android.widget.NumberPicker;
14 import android.widget.TextView;
17 import androidx.annotation.NonNull;
19 import net.osdn.gokigen.joggingtimer.R;
26 public class CreateModelDataDialog extends DialogFragment
28 private final String TAG = toString();
30 private boolean isLap = true;
31 private String title = "";
32 private int lapCount = 0;
33 private Callback callback = null;
34 private long defaultValue = 0;
35 Dialog myDialog = null;
41 public static CreateModelDataDialog newInstance(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
43 CreateModelDataDialog instance = new CreateModelDataDialog();
44 instance.prepare(isLap, title, lapCount, callback, defaultValue);
46 // パラメータはBundleにまとめておく
47 Bundle arguments = new Bundle();
48 arguments.putString("title", title);
49 //arguments.putString("message", message);
50 instance.setArguments(arguments);
59 private void prepare(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
63 this.lapCount = lapCount;
64 this.callback = callback;
65 this.defaultValue = defaultValue;
73 public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
75 Log.v(TAG, "show " + "def. : " + defaultValue);
77 Activity activity = getActivity();
79 //final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
80 final AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity, R.style.wear2_dialog_theme);
82 // Get the layout inflater
83 LayoutInflater inflater = activity.getLayoutInflater();
84 final View alertView = inflater.inflate(R.layout.time_model_picker, null, false);
85 alertDialog.setView(alertView);
87 final TextView titleText = alertView.findViewById(R.id.information_picker);
88 final TextView lapStartText = alertView.findViewById(R.id.lap_start);
89 final TextView lapEndText = alertView.findViewById(R.id.lap_end);
90 final NumberPicker lap = alertView.findViewById(R.id.number_picker_lap_count);
91 final NumberPicker hour = alertView.findViewById(R.id.number_picker_hours);
92 final NumberPicker minute = alertView.findViewById(R.id.number_picker_minutes);
93 final NumberPicker second = alertView.findViewById(R.id.number_picker_seconds);
99 titleText.setText(title);
103 lap.setVisibility(View.VISIBLE);
104 lapStartText.setVisibility(View.VISIBLE);
105 lapEndText.setVisibility(View.VISIBLE);
111 lap.setValue(lapCount);
112 lap.setVisibility(View.GONE);
113 lapStartText.setVisibility(View.GONE);
114 lapEndText.setVisibility(View.GONE);
118 hour.setMaxValue(72);
119 minute.setMinValue(0);
120 minute.setMaxValue(59);
121 second.setMinValue(0);
122 second.setMaxValue(59);
123 second.setValue((int) (defaultValue / 1000) % 60);
124 minute.setValue((int) ((defaultValue / (1000 * 60)) % 60));
125 hour.setValue((int) ((defaultValue / (1000 * 60 * 60)) % 24));
132 alertDialog.setCancelable(true);
135 alertDialog.setPositiveButton(activity.getString(R.string.dialog_positive_execute),
139 Log.v(TAG, "ENTRY [" + lap.getValue() + "] " + hour.getValue() + ":" + minute.getValue() + ":" + second.getValue());
140 int lapC = (isLap) ? lap.getValue() : lapCount;
141 long newMillis = ((long) hour.getValue() * 60 * 60 * 1000) + ((long) minute.getValue() * 60 * 1000) + (second.getValue() * 1000L);
142 callback.dataCreated(isLap, lapC, defaultValue, newMillis);
147 callback.dataCreateCancelled();
152 // ボタンを設定する (キャンセルボタン)
153 alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
157 callback.dataCreateCancelled();
166 alertView.setBackgroundColor(Color.BLACK);
167 myDialog = alertDialog.create();
173 public void onPause()
176 Log.v(TAG, "AlertDialog::onPause()");
177 if (myDialog != null)
188 public interface Callback
190 void dataCreated(boolean isLap, int lap, long previousValue, long newValue); // OKを選択したとき
191 void dataCreateCancelled(); // キャンセルしたとき