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:
agnostic-apollo
2021-10-22 00:58:16 +05:00
parent 28ecb64992
commit d96883c4d6
6 changed files with 174 additions and 34 deletions

View File

@@ -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;
}
}
}