adjusted the secret night mode switch behavior
This commit is contained in:
parent
705d38651e
commit
2750533e5c
9 changed files with 92 additions and 46 deletions
|
@ -534,11 +534,16 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
||||||
mainActivityMapFragment.handleShowMyLocation();
|
mainActivityMapFragment.handleShowMyLocation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// secret night mode switch
|
||||||
mFloatingActionButtonLocation.setOnLongClickListener(new View.OnLongClickListener() {
|
mFloatingActionButtonLocation.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
longPressFeedback(R.string.toast_message_long_press_night_mode_switch);
|
NightModeHelper.switchMode(MainActivity.this);
|
||||||
NightModeHelper.switchToOpposite(MainActivity.this);
|
// vibrate 50 milliseconds
|
||||||
|
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
vibrator.vibrate(50);
|
||||||
|
// recreate activity
|
||||||
recreate();
|
recreate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,10 @@
|
||||||
package org.y20k.trackbook;
|
package org.y20k.trackbook;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import org.y20k.trackbook.helpers.LogHelper;
|
import org.y20k.trackbook.helpers.LogHelper;
|
||||||
import org.y20k.trackbook.helpers.NightModeHelper;
|
import org.y20k.trackbook.helpers.NightModeHelper;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trackbook.class
|
* Trackbook.class
|
||||||
|
@ -39,13 +36,16 @@ public class Trackbook extends Application {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
// set Day / Night theme state
|
// set Day / Night theme state
|
||||||
if (Build.VERSION.SDK_INT >= 28) {
|
NightModeHelper.restoreSavedState(this);
|
||||||
// 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);
|
// todo remove
|
||||||
} else {
|
// if (Build.VERSION.SDK_INT >= 28) {
|
||||||
// try t0 get last state the user chose
|
// // Android P might introduce a system wide theme option - in that case: follow system (28 = Build.VERSION_CODES.P)
|
||||||
NightModeHelper.restoreSavedState(this);
|
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||||
}
|
// } else {
|
||||||
|
// // try to get last state the user chose
|
||||||
|
// NightModeHelper.restoreSavedState(this);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.y20k.trackbook.R;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
|
||||||
|
@ -36,23 +39,24 @@ public final class NightModeHelper implements TrackbookKeys {
|
||||||
private static final String LOG_TAG = NightModeHelper.class.getSimpleName();
|
private static final String LOG_TAG = NightModeHelper.class.getSimpleName();
|
||||||
|
|
||||||
|
|
||||||
/* Switches to opposite theme */
|
/* Switches between modes: day, night, undefined */
|
||||||
public static void switchToOpposite(Activity activity) {
|
public static void switchMode(Activity activity) {
|
||||||
switch (getCurrentNightModeState(activity)) {
|
// SWITCH: undefined -> night / night -> day / day - undefined
|
||||||
case Configuration.UI_MODE_NIGHT_NO:
|
switch (AppCompatDelegate.getDefaultNightMode()) {
|
||||||
// night mode is currently not active - turn on night mode
|
case AppCompatDelegate.MODE_NIGHT_NO:
|
||||||
|
// currently: day mode -> switch to: follow system
|
||||||
displayDefaultStatusBar(activity); // necessary hack :-/
|
displayDefaultStatusBar(activity); // necessary hack :-/
|
||||||
activateNightMode(activity);
|
activateFollowSystemMode(activity, true);
|
||||||
break;
|
break;
|
||||||
case Configuration.UI_MODE_NIGHT_YES:
|
case AppCompatDelegate.MODE_NIGHT_YES:
|
||||||
// night mode is currently active - turn off night mode
|
// currently: night mode -> switch to: day mode
|
||||||
displayLightStatusBar(activity); // necessary hack :-/
|
displayLightStatusBar(activity); // necessary hack :-/
|
||||||
deactivateNightMode(activity);
|
activateDayMode(activity, true);
|
||||||
break;
|
break;
|
||||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
default:
|
||||||
// don't know what mode is active - turn off night mode
|
// currently: follow system / undefined -> switch to: day mode
|
||||||
displayLightStatusBar(activity); // necessary hack :-/
|
displayLightStatusBar(activity); // necessary hack :-/
|
||||||
deactivateNightMode(activity);
|
activateNightMode(activity, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,20 +65,20 @@ public final class NightModeHelper implements TrackbookKeys {
|
||||||
/* Sets night mode / dark theme */
|
/* Sets night mode / dark theme */
|
||||||
public static void restoreSavedState(Context context) {
|
public static void restoreSavedState(Context context) {
|
||||||
int savedNightModeState = loadNightModeState(context);
|
int savedNightModeState = loadNightModeState(context);
|
||||||
int currentNightModeState = getCurrentNightModeState(context);
|
int currentNightModeState = AppCompatDelegate.getDefaultNightMode();
|
||||||
if (savedNightModeState != -1 && savedNightModeState != currentNightModeState) {
|
if (savedNightModeState != currentNightModeState) {
|
||||||
switch (savedNightModeState) {
|
switch (savedNightModeState) {
|
||||||
case Configuration.UI_MODE_NIGHT_NO:
|
case AppCompatDelegate.MODE_NIGHT_NO:
|
||||||
// turn off night mode
|
// turn on day mode
|
||||||
deactivateNightMode(context);
|
activateDayMode(context, false);
|
||||||
break;
|
break;
|
||||||
case Configuration.UI_MODE_NIGHT_YES:
|
case AppCompatDelegate.MODE_NIGHT_YES:
|
||||||
// turn on night mode
|
// turn on night mode
|
||||||
activateNightMode(context);
|
activateNightMode(context, false);
|
||||||
break;
|
break;
|
||||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
default:
|
||||||
// turn off night mode
|
// turn on mode "follow system"
|
||||||
deactivateNightMode(context);
|
activateFollowSystemMode(context, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,21 +92,46 @@ public final class NightModeHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Activates Night Mode */
|
/* Activates Night Mode */
|
||||||
private static void activateNightMode(Context context) {
|
private static void activateNightMode(Context context, Boolean notifyUser) {
|
||||||
saveNightModeState(context, Configuration.UI_MODE_NIGHT_YES);
|
saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_YES);
|
||||||
|
|
||||||
// switch to Night Mode
|
// switch to Night Mode
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
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 */
|
/* Activates Day Mode */
|
||||||
private static void deactivateNightMode(Context context) {
|
private static void activateDayMode(Context context, Boolean notifyUser) {
|
||||||
// save the new state
|
// save the new state
|
||||||
saveNightModeState(context, Configuration.UI_MODE_NIGHT_NO);
|
saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_NO);
|
||||||
|
|
||||||
// switch to Day Mode
|
// switch to Day Mode
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
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 */
|
/* Load state of Night Mode */
|
||||||
private static int loadNightModeState(Context context) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">GPX-Export erfolgreich:</string>
|
<string name="toast_message_export_success">GPX-Export erfolgreich:</string>
|
||||||
<string name="toast_message_export_fail">GPX-Export fehlgeschlagen:</string>
|
<string name="toast_message_export_fail">GPX-Export fehlgeschlagen:</string>
|
||||||
<string name="toast_message_elevation_info">Hinweis: Die Genauogkeit der Höhenmeter-Werte ist geräteabhängig. Gemessen werden die Steigungen und Gefälle der Gesamtstrecke.</string>
|
<string name="toast_message_elevation_info">Hinweis: Die Genauogkeit der Höhenmeter-Werte ist geräteabhängig. Gemessen werden die Steigungen und Gefälle der Gesamtstrecke.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Schalter für Nachtmodus (Längeres Drücken erkannt)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Bitte zunächst einen Dateimanager oder GPX-Betrachter installieren.</string>
|
<string name="toast_message_install_file_helper">Bitte zunächst einen Dateimanager oder GPX-Betrachter installieren.</string>
|
||||||
|
<string name="toast_message_theme_night">Nachtmodus aktiviert (Längeres Drücken erkannt)</string>
|
||||||
|
<string name="toast_message_theme_day">Tagmodus aktiviert (Längeres Drücken erkannt)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Modus Systemeinstellung Beachten aktiviert (Längeres Drücken erkannt)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Quelle</string>
|
<string name="marker_description_source">Quelle</string>
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">GPX export successful:</string>
|
<string name="toast_message_export_success">GPX export successful:</string>
|
||||||
<string name="toast_message_export_fail">GPX export failed:</string>
|
<string name="toast_message_export_fail">GPX export failed:</string>
|
||||||
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Night mode switch (long press detected)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
||||||
|
<string name="toast_message_theme_night">Switching to Night mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_day">Switching to Day mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Switching to Follow System Setting mode (long press detected)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Source</string>
|
<string name="marker_description_source">Source</string>
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">L\'esportazione GPX è riuscita:</string>
|
<string name="toast_message_export_success">L\'esportazione GPX è riuscita:</string>
|
||||||
<string name="toast_message_export_fail">L\'esportazione GPX non è riuscita:</string>
|
<string name="toast_message_export_fail">L\'esportazione GPX non è riuscita:</string>
|
||||||
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Night mode switch (long press detected)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
||||||
|
<string name="toast_message_theme_night">Switching to Night mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_day">Switching to Day mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Switching to Follow System Setting mode (long press detected)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Fonte</string>
|
<string name="marker_description_source">Fonte</string>
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">GPX-eksportering vellykket:</string>
|
<string name="toast_message_export_success">GPX-eksportering vellykket:</string>
|
||||||
<string name="toast_message_export_fail">GPX-eksportering mislyktes:</string>
|
<string name="toast_message_export_fail">GPX-eksportering mislyktes:</string>
|
||||||
<string name="toast_message_elevation_info">Hint: Høydedataens nøyaktighet avhenger av enheten din. Opp og ned-stigningen for hele ruten måles.</string>
|
<string name="toast_message_elevation_info">Hint: Høydedataens nøyaktighet avhenger av enheten din. Opp og ned-stigningen for hele ruten måles.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Nattmodusveksling (langt trykk oppdaget)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
||||||
|
<string name="toast_message_theme_night">Switching to Night mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_day">Switching to Day mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Switching to Follow System Setting mode (long press detected)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Kilde</string>
|
<string name="marker_description_source">Kilde</string>
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">GPX export successful:</string>
|
<string name="toast_message_export_success">GPX export successful:</string>
|
||||||
<string name="toast_message_export_fail">GPX export failed:</string>
|
<string name="toast_message_export_fail">GPX export failed:</string>
|
||||||
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Night mode switch (long press detected)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
||||||
|
<string name="toast_message_theme_night">Switching to Night mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_day">Switching to Day mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Switching to Follow System Setting mode (long press detected)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Bron</string>
|
<string name="marker_description_source">Bron</string>
|
||||||
|
|
|
@ -63,8 +63,10 @@
|
||||||
<string name="toast_message_export_success">GPX export successful:</string>
|
<string name="toast_message_export_success">GPX export successful:</string>
|
||||||
<string name="toast_message_export_fail">GPX export failed:</string>
|
<string name="toast_message_export_fail">GPX export failed:</string>
|
||||||
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
<string name="toast_message_elevation_info">Hint: The accuracy of elevation data depends on your device. The uphill and downhill elevation of the whole route is measured.</string>
|
||||||
<string name="toast_message_long_press_night_mode_switch">Night mode switch (long press detected)</string>
|
|
||||||
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
<string name="toast_message_install_file_helper">Please install a file manager or a GPX track viewer first.</string>
|
||||||
|
<string name="toast_message_theme_night">Switching to Night mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_day">Switching to Day mode (long press detected)</string>
|
||||||
|
<string name="toast_message_theme_follow_system">Switching to Follow System Setting mode (long press detected)</string>
|
||||||
|
|
||||||
<!-- map markers -->
|
<!-- map markers -->
|
||||||
<string name="marker_description_source">Source</string>
|
<string name="marker_description_source">Source</string>
|
||||||
|
|
Loading…
Reference in a new issue