diff --git a/app/src/main/java/org/y20k/trackbook/MainActivity.java b/app/src/main/java/org/y20k/trackbook/MainActivity.java index 9c9bee1..b587cb5 100755 --- a/app/src/main/java/org/y20k/trackbook/MainActivity.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivity.java @@ -534,11 +534,16 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys { mainActivityMapFragment.handleShowMyLocation(); } }); + + // secret night mode switch mFloatingActionButtonLocation.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - longPressFeedback(R.string.toast_message_long_press_night_mode_switch); - NightModeHelper.switchToOpposite(MainActivity.this); + NightModeHelper.switchMode(MainActivity.this); + // vibrate 50 milliseconds + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + vibrator.vibrate(50); + // recreate activity recreate(); return true; } diff --git a/app/src/main/java/org/y20k/trackbook/Trackbook.java b/app/src/main/java/org/y20k/trackbook/Trackbook.java index 395022c..3be8999 100755 --- a/app/src/main/java/org/y20k/trackbook/Trackbook.java +++ b/app/src/main/java/org/y20k/trackbook/Trackbook.java @@ -17,13 +17,10 @@ package org.y20k.trackbook; import android.app.Application; -import android.os.Build; import org.y20k.trackbook.helpers.LogHelper; import org.y20k.trackbook.helpers.NightModeHelper; -import androidx.appcompat.app.AppCompatDelegate; - /** * Trackbook.class @@ -39,13 +36,16 @@ public class Trackbook extends Application { super.onCreate(); // set Day / Night theme state - if (Build.VERSION.SDK_INT >= 28) { - // Android P might introduce a system wide theme option - in that case: follow system (28 = Build.VERSION_CODES.P) - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); - } else { - // try t0 get last state the user chose - NightModeHelper.restoreSavedState(this); - } + NightModeHelper.restoreSavedState(this); + +// todo remove +// if (Build.VERSION.SDK_INT >= 28) { +// // Android P might introduce a system wide theme option - in that case: follow system (28 = Build.VERSION_CODES.P) +// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); +// } else { +// // try to get last state the user chose +// NightModeHelper.restoreSavedState(this); +// } } diff --git a/app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java index c7655dd..f6c0ef2 100755 --- a/app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java @@ -23,6 +23,9 @@ import android.content.res.Configuration; import android.os.Build; import android.preference.PreferenceManager; import android.view.View; +import android.widget.Toast; + +import org.y20k.trackbook.R; import androidx.appcompat.app.AppCompatDelegate; @@ -36,23 +39,24 @@ public final class NightModeHelper implements TrackbookKeys { private static final String LOG_TAG = NightModeHelper.class.getSimpleName(); - /* Switches to opposite theme */ - public static void switchToOpposite(Activity activity) { - switch (getCurrentNightModeState(activity)) { - case Configuration.UI_MODE_NIGHT_NO: - // night mode is currently not active - turn on night mode + /* Switches between modes: day, night, undefined */ + public static void switchMode(Activity activity) { + // SWITCH: undefined -> night / night -> day / day - undefined + switch (AppCompatDelegate.getDefaultNightMode()) { + case AppCompatDelegate.MODE_NIGHT_NO: + // currently: day mode -> switch to: follow system displayDefaultStatusBar(activity); // necessary hack :-/ - activateNightMode(activity); + activateFollowSystemMode(activity, true); break; - case Configuration.UI_MODE_NIGHT_YES: - // night mode is currently active - turn off night mode + case AppCompatDelegate.MODE_NIGHT_YES: + // currently: night mode -> switch to: day mode displayLightStatusBar(activity); // necessary hack :-/ - deactivateNightMode(activity); + activateDayMode(activity, true); break; - case Configuration.UI_MODE_NIGHT_UNDEFINED: - // don't know what mode is active - turn off night mode + default: + // currently: follow system / undefined -> switch to: day mode displayLightStatusBar(activity); // necessary hack :-/ - deactivateNightMode(activity); + activateNightMode(activity, true); break; } } @@ -61,20 +65,20 @@ public final class NightModeHelper implements TrackbookKeys { /* Sets night mode / dark theme */ public static void restoreSavedState(Context context) { int savedNightModeState = loadNightModeState(context); - int currentNightModeState = getCurrentNightModeState(context); - if (savedNightModeState != -1 && savedNightModeState != currentNightModeState) { + int currentNightModeState = AppCompatDelegate.getDefaultNightMode(); + if (savedNightModeState != currentNightModeState) { switch (savedNightModeState) { - case Configuration.UI_MODE_NIGHT_NO: - // turn off night mode - deactivateNightMode(context); + case AppCompatDelegate.MODE_NIGHT_NO: + // turn on day mode + activateDayMode(context, false); break; - case Configuration.UI_MODE_NIGHT_YES: + case AppCompatDelegate.MODE_NIGHT_YES: // turn on night mode - activateNightMode(context); + activateNightMode(context, false); break; - case Configuration.UI_MODE_NIGHT_UNDEFINED: - // turn off night mode - deactivateNightMode(context); + default: + // turn on mode "follow system" + activateFollowSystemMode(context, false); break; } } @@ -88,21 +92,46 @@ public final class NightModeHelper implements TrackbookKeys { /* Activates Night Mode */ - private static void activateNightMode(Context context) { - saveNightModeState(context, Configuration.UI_MODE_NIGHT_YES); + private static void activateNightMode(Context context, Boolean notifyUser) { + saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_YES); // switch to Night Mode AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + + // notify user + if (notifyUser) { + Toast.makeText(context, context.getText(R.string.toast_message_theme_night), Toast.LENGTH_SHORT).show(); + } } - /* Deactivates Night Mode */ - private static void deactivateNightMode(Context context) { + /* Activates Day Mode */ + private static void activateDayMode(Context context, Boolean notifyUser) { // save the new state - saveNightModeState(context, Configuration.UI_MODE_NIGHT_NO); + saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_NO); // switch to Day Mode AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + + // notify user + if (notifyUser) { + Toast.makeText(context, context.getText(R.string.toast_message_theme_day), Toast.LENGTH_LONG).show(); + } + } + + + /* Activate Mode "Follow System" */ + private static void activateFollowSystemMode(Context context, Boolean notifyUser) { + // save the new state + saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + + // switch to Undefined Mode / Follow System + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + + // notify user + if (notifyUser) { + Toast.makeText(context, context.getText(R.string.toast_message_theme_follow_system), Toast.LENGTH_LONG).show(); + } } @@ -135,7 +164,7 @@ public final class NightModeHelper implements TrackbookKeys { /* Load state of Night Mode */ private static int loadNightModeState(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_NIGHT_MODE_STATE, -1); + return PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_NIGHT_MODE_STATE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index dcd4e93..c1434ce 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -63,8 +63,10 @@ GPX-Export erfolgreich: GPX-Export fehlgeschlagen: Hinweis: Die Genauogkeit der Höhenmeter-Werte ist geräteabhängig. Gemessen werden die Steigungen und Gefälle der Gesamtstrecke. - Schalter für Nachtmodus (Längeres Drücken erkannt) Bitte zunächst einen Dateimanager oder GPX-Betrachter installieren. + Nachtmodus aktiviert (Längeres Drücken erkannt) + Tagmodus aktiviert (Längeres Drücken erkannt) + Modus Systemeinstellung Beachten aktiviert (Längeres Drücken erkannt) Quelle diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 56748f1..addf46b 100755 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -63,8 +63,10 @@ GPX export successful: GPX export failed: Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured. - Night mode switch (long press detected) Please install a file manager or a GPX track viewer first. + Switching to Night mode (long press detected) + Switching to Day mode (long press detected) + Switching to Follow System Setting mode (long press detected) Source diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 06d6001..338efa4 100755 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -63,8 +63,10 @@ L\'esportazione GPX è riuscita: L\'esportazione GPX non è riuscita: Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured. - Night mode switch (long press detected) Please install a file manager or a GPX track viewer first. + Switching to Night mode (long press detected) + Switching to Day mode (long press detected) + Switching to Follow System Setting mode (long press detected) Fonte diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml index 610523d..8ab72bc 100755 --- a/app/src/main/res/values-nb-rNO/strings.xml +++ b/app/src/main/res/values-nb-rNO/strings.xml @@ -63,8 +63,10 @@ GPX-eksportering vellykket: GPX-eksportering mislyktes: Hint: Høydedataens nøyaktighet avhenger av enheten din. Opp og ned-stigningen for hele ruten måles. - Nattmodusveksling (langt trykk oppdaget) Please install a file manager or a GPX track viewer first. + Switching to Night mode (long press detected) + Switching to Day mode (long press detected) + Switching to Follow System Setting mode (long press detected) Kilde diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index f31d114..2ee53a1 100755 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -63,8 +63,10 @@ GPX export successful: GPX export failed: Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured. - Night mode switch (long press detected) Please install a file manager or a GPX track viewer first. + Switching to Night mode (long press detected) + Switching to Day mode (long press detected) + Switching to Follow System Setting mode (long press detected) Bron diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc59df0..0bd2fc2 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,8 +63,10 @@ GPX export successful: GPX export failed: Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured. - Night mode switch (long press detected) Please install a file manager or a GPX track viewer first. + Switching to Night mode (long press detected) + Switching to Day mode (long press detected) + Switching to Follow System Setting mode (long press detected) Source