1 package net.osdn.gokigen.joggingtimer.utilities;
3 import android.app.AlertDialog;
4 import android.content.DialogInterface;
5 import android.support.wearable.activity.WearableActivity;
6 import android.util.Log;
7 import android.view.ContextThemeWrapper;
8 import android.view.LayoutInflater;
9 import android.view.View;
10 import android.widget.NumberPicker;
11 import android.widget.TextView;
14 import net.osdn.gokigen.joggingtimer.R;
21 public class CreateModelDataDialog
23 private final String TAG = toString();
24 private final WearableActivity activity;
26 public CreateModelDataDialog(WearableActivity activity)
28 this.activity = activity;
33 * @param callback 結果をコールバック
35 public void show(final boolean isLap, String title, final int lapCount, final Callback callback, final long defaultValue)
37 Log.v(TAG, "show " + "def. : " + defaultValue);
40 final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
42 // Get the layout inflater
43 LayoutInflater inflater = activity.getLayoutInflater();
44 final View alertView = inflater.inflate(R.layout.time_model_picker, null, false);
45 alertDialog.setView(alertView);
47 final TextView titleText = alertView.findViewById(R.id.information_picker);
48 final TextView lapStartText = alertView.findViewById(R.id.lap_start);
49 final TextView lapEndText = alertView.findViewById(R.id.lap_end);
50 final NumberPicker lap = alertView.findViewById(R.id.number_picker_lap_count);
51 final NumberPicker hour = alertView.findViewById(R.id.number_picker_hours);
52 final NumberPicker minute = alertView.findViewById(R.id.number_picker_minutes);
53 final NumberPicker second = alertView.findViewById(R.id.number_picker_seconds);
59 titleText.setText(title);
63 lap.setVisibility(View.VISIBLE);
64 lapStartText.setVisibility(View.VISIBLE);
65 lapEndText.setVisibility(View.VISIBLE);
71 lap.setValue(lapCount);
72 lap.setVisibility(View.GONE);
73 lapStartText.setVisibility(View.GONE);
74 lapEndText.setVisibility(View.GONE);
79 minute.setMinValue(0);
80 minute.setMaxValue(59);
81 second.setMinValue(0);
82 second.setMaxValue(59);
83 second.setValue((int) (defaultValue / 1000) % 60);
84 minute.setValue((int) ((defaultValue / (1000 * 60)) % 60));
85 hour.setValue((int) ((defaultValue / (1000 * 60 * 60)) % 24));
92 alertDialog.setCancelable(true);
95 alertDialog.setPositiveButton(activity.getString(R.string.dialog_positive_execute),
96 new DialogInterface.OnClickListener() {
97 public void onClick(DialogInterface dialog, int which)
101 Log.v(TAG, "ENTRY [" + lap.getValue() + "] " + hour.getValue() + ":" + minute.getValue() + ":" + second.getValue());
102 int lapC = (isLap) ? lap.getValue() : lapCount;
103 long newMillis = (hour.getValue() * 60 * 60 * 1000) + (minute.getValue() * 60 * 1000) + (second.getValue() * 1000);
104 callback.dataCreated(isLap, lapC, defaultValue, newMillis);
109 callback.dataCreateCancelled();
115 // ボタンを設定する (キャンセルボタン)
116 alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
117 new DialogInterface.OnClickListener() {
118 public void onClick(DialogInterface dialog, int which)
120 callback.dataCreateCancelled();
130 public interface Callback
132 void dataCreated(boolean isLap, int lap, long previousValue, long newValue); // OKを選択したとき
133 void dataCreateCancelled(); // キャンセルしたとき