package net.osdn.gokigen.joggingtimer.utilities;
+import android.app.Activity;
import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.support.wearable.activity.WearableActivity;
+import android.app.Dialog;
+import androidx.fragment.app.DialogFragment;
+
+import android.graphics.Color;
+import android.os.Bundle;
import android.util.Log;
-import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.TextView;
+import androidx.annotation.NonNull;
+
import net.osdn.gokigen.joggingtimer.R;
*
*
*/
-public class CreateModelDataDialog
+public class CreateModelDataDialog extends DialogFragment
{
private final String TAG = toString();
- private final WearableActivity activity;
- public CreateModelDataDialog(WearableActivity activity)
+ private boolean isLap = true;
+ private String title = "";
+ private int lapCount = 0;
+ private Callback callback = null;
+ private long defaultValue = 0;
+ Dialog myDialog = null;
+
+ /**
+ *
+ *
+ */
+ public static CreateModelDataDialog newInstance(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
+ {
+ CreateModelDataDialog instance = new CreateModelDataDialog();
+ instance.prepare(isLap, title, lapCount, callback, defaultValue);
+
+ // パラメータはBundleにまとめておく
+ Bundle arguments = new Bundle();
+ arguments.putString("title", title);
+ //arguments.putString("message", message);
+ instance.setArguments(arguments);
+
+ return (instance);
+ }
+
+ /**
+ *
+ *
+ */
+ private void prepare(boolean isLap, String title, int lapCount, Callback callback, long defaultValue)
{
- this.activity = activity;
+ this.isLap = isLap;
+ this.title = title;
+ this.lapCount = lapCount;
+ this.callback = callback;
+ this.defaultValue = defaultValue;
}
/**
*
- * @param callback 結果をコールバック
+ *
*/
- public void show(final boolean isLap, String title, final int lapCount, final Callback callback, final long defaultValue)
+ @Override
+ public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
{
Log.v(TAG, "show " + "def. : " + defaultValue);
+ Activity activity = getActivity();
// 確認ダイアログの生成
- final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
+ //final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.wear2_dialog_theme));
+ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity, R.style.wear2_dialog_theme);
// Get the layout inflater
LayoutInflater inflater = activity.getLayoutInflater();
// ボタンを設定する(実行ボタン)
alertDialog.setPositiveButton(activity.getString(R.string.dialog_positive_execute),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which)
+ (dialog, which) -> {
+ try
+ {
+ Log.v(TAG, "ENTRY [" + lap.getValue() + "] " + hour.getValue() + ":" + minute.getValue() + ":" + second.getValue());
+ int lapC = (isLap) ? lap.getValue() : lapCount;
+ long newMillis = ((long) hour.getValue() * 60 * 60 * 1000) + ((long) minute.getValue() * 60 * 1000) + (second.getValue() * 1000L);
+ callback.dataCreated(isLap, lapC, defaultValue, newMillis);
+ }
+ catch (Exception e)
{
- try
- {
- Log.v(TAG, "ENTRY [" + lap.getValue() + "] " + hour.getValue() + ":" + minute.getValue() + ":" + second.getValue());
- int lapC = (isLap) ? lap.getValue() : lapCount;
- long newMillis = (hour.getValue() * 60 * 60 * 1000) + (minute.getValue() * 60 * 1000) + (second.getValue() * 1000);
- callback.dataCreated(isLap, lapC, defaultValue, newMillis);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- callback.dataCreateCancelled();
- }
- dialog.dismiss();
+ e.printStackTrace();
+ callback.dataCreateCancelled();
}
+ dialog.dismiss();
});
// ボタンを設定する (キャンセルボタン)
alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which)
+ (dialog, which) -> {
+ try
{
callback.dataCreateCancelled();
- dialog.cancel();
}
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ dialog.cancel();
});
- // 確認ダイアログを表示する
- alertDialog.show();
+ alertView.setBackgroundColor(Color.BLACK);
+ myDialog = alertDialog.create();
+ return (myDialog);
+ }
+
+
+ @Override
+ public void onPause()
+ {
+ super.onPause();
+ Log.v(TAG, "AlertDialog::onPause()");
+ if (myDialog != null)
+ {
+ myDialog.cancel();
+ }
}
- // コールバックインタフェース
+
+ /**
+ * コールバックインタフェース
+ *
+ */
public interface Callback
{
void dataCreated(boolean isLap, int lap, long previousValue, long newValue); // OKを選択したとき