From 7037b0fce55ed51a5edff44d816e1d049db6d6b8 Mon Sep 17 00:00:00 2001 From: Fung Date: Wed, 14 Jun 2017 19:18:45 +0800 Subject: [PATCH] LaunchActivity: Change alarm icon by state Signed-off-by: Fung --- .../papdt/blackblub/ui/LaunchActivity.java | 26 ++++++++++++++++--- .../papdt/blackblub/ui/SchedulerDialog.java | 7 +++++ .../res/drawable/ic_alarm_off_black_24dp.xml | 9 +++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/ic_alarm_off_black_24dp.xml diff --git a/app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java b/app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java index 2264389..3945d98 100644 --- a/app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java +++ b/app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java @@ -35,6 +35,7 @@ public class LaunchActivity extends Activity implements PopupMenu.OnMenuItemClic private DiscreteSeekBar mSeekbar; private static MaterialAnimatedSwitch mSwitch; private TextView mModeText; + private ImageButton mSchedulerBtn; private PopupMenu popupMenu; private AlertDialog mAlertDialog, mModeDialog; @@ -240,7 +241,13 @@ public void onClick(View view) { }); menuBtn.setOnTouchListener(popupMenu.getDragToOpenListener()); - findViewById(R.id.btn_scheduler).setOnClickListener(new View.OnClickListener() { + mSchedulerBtn = findViewById(R.id.btn_scheduler); + if (mNightScreenSettings.getBoolean(NightScreenSettings.KEY_AUTO_MODE, false)) { + mSchedulerBtn.setImageResource(R.drawable.ic_alarm_black_24dp); + } else { + mSchedulerBtn.setImageResource(R.drawable.ic_alarm_off_black_24dp); + } + mSchedulerBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -252,7 +259,7 @@ public void onClick(View view) { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - new SchedulerDialog(LaunchActivity.this).show(); + showSchedulerDialog(); } }) .setNeutralButton(R.string.dialog_button_go_to_set, new DialogInterface.OnClickListener() { @@ -270,8 +277,8 @@ public void onClick(DialogInterface dialogInterface, int i) { .show(); return; } + showSchedulerDialog(); } - new SchedulerDialog(LaunchActivity.this).show(); } }); @@ -284,6 +291,19 @@ public void onClick(View view) { }); } + private void showSchedulerDialog() { + new SchedulerDialog(this, new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialogInterface) { + if (mNightScreenSettings.getBoolean(NightScreenSettings.KEY_AUTO_MODE, false)) { + mSchedulerBtn.setImageResource(R.drawable.ic_alarm_black_24dp); + } else { + mSchedulerBtn.setImageResource(R.drawable.ic_alarm_off_black_24dp); + } + } + }).show(); + } + @Override public void onPause() { super.onPause(); diff --git a/app/src/main/java/info/papdt/blackblub/ui/SchedulerDialog.java b/app/src/main/java/info/papdt/blackblub/ui/SchedulerDialog.java index 7628c51..407f393 100644 --- a/app/src/main/java/info/papdt/blackblub/ui/SchedulerDialog.java +++ b/app/src/main/java/info/papdt/blackblub/ui/SchedulerDialog.java @@ -37,6 +37,13 @@ public SchedulerDialog(Context context) { init(); } + public SchedulerDialog(Context context, OnDismissListener onDismissListener) { + super(context); + if (context instanceof Activity) setOwnerActivity((Activity) context); + if (onDismissListener != null) setOnDismissListener(onDismissListener); + init(); + } + public SchedulerDialog(Context context, int themeResId) { super(context, themeResId); if (context instanceof Activity) setOwnerActivity((Activity) context); diff --git a/app/src/main/res/drawable/ic_alarm_off_black_24dp.xml b/app/src/main/res/drawable/ic_alarm_off_black_24dp.xml new file mode 100644 index 0000000..785e67b --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_off_black_24dp.xml @@ -0,0 +1,9 @@ + + +