mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-10 04:24:05 +08:00
Changed|Deprecated: Deprecate use-black-ui
termux property and replace it with night-mode
This will not break existing `use-black-ui` settings for users and it will automatically be converted to `night-mode` when properties are loaded from disk but a deprecation message will be logged. This `night-mode` key can be used to set the day/night theme variant for activities used by termux app and its plugin. The user can set a string value to `true` to force use dark variant of theme, `false` to force use light variant of theme or `system` to automatically set theme based on current system settings. The default value is still `system`. The app must be restarted for changes to take effect for existing activities, including main terminal `TermuxActivity`. This is required since "theme != night mode". In future custom theme or color support may be provided that will have both dark and night modes for the same theme.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.termux.shared.theme;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.termux.shared.models.theme.NightMode;
|
||||
|
||||
public class ThemeUtils {
|
||||
|
||||
/**
|
||||
* Will return true if system has enabled night mode.
|
||||
* https://developer.android.com/guide/topics/resources/providing-resources#NightQualifier
|
||||
*/
|
||||
public static boolean isNightModeEnabled(Context context) {
|
||||
if (context == null) return false;
|
||||
return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
}
|
||||
|
||||
/** Will return true if mode is set to {@link NightMode#TRUE}, otherwise will return true if
|
||||
* mode is set to {@link NightMode#SYSTEM} and night mode is enabled by system. */
|
||||
public static boolean shouldEnableDarkTheme(Context context, String name) {
|
||||
if (NightMode.TRUE.getName().equals(name))
|
||||
return true;
|
||||
else if (NightMode.FALSE.getName().equals(name))
|
||||
return false;
|
||||
else if (NightMode.SYSTEM.getName().equals(name)) {
|
||||
return isNightModeEnabled(context);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user