-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed|Deprecated: Deprecate
use-black-ui
termux property and repl…
…ace 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.
- Loading branch information
1 parent
28ecb64
commit d96883c
Showing
6 changed files
with
174 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
termux-shared/src/main/java/com/termux/shared/models/theme/NightMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.termux.shared.models.theme; | ||
|
||
import androidx.appcompat.app.AppCompatDelegate; | ||
|
||
/** The modes used by to decide night mode for themes. */ | ||
public enum NightMode { | ||
|
||
/** Night theme should be enabled. */ | ||
TRUE("true", AppCompatDelegate.MODE_NIGHT_YES), | ||
|
||
/** Dark theme should be enabled. */ | ||
FALSE("false", AppCompatDelegate.MODE_NIGHT_NO), | ||
|
||
/** | ||
* Use night or dark theme depending on system night mode. | ||
* https://developer.android.com/guide/topics/resources/providing-resources#NightQualifier | ||
*/ | ||
SYSTEM("system", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); | ||
|
||
private final String name; | ||
private final int mode; | ||
|
||
NightMode(final String name, int mode) { | ||
this.name = name; | ||
this.mode = mode; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getMode() { | ||
return mode; | ||
} | ||
|
||
public static Integer modeOf(String name) { | ||
if (TRUE.name.equals(name)) | ||
return TRUE.mode; | ||
else if (FALSE.name.equals(name)) | ||
return FALSE.mode; | ||
else if (SYSTEM.name.equals(name)) { | ||
return SYSTEM.mode; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |