NaTo1000's picture
download
raw
2.61 kB
package com.termux.shared.theme;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import com.termux.shared.logger.Logger;
/** 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);
/** The current app wide night mode used by various libraries. Defaults to {@link #SYSTEM}. */
private static NightMode APP_NIGHT_MODE;
private static final String LOG_TAG = "NightMode";
private final String name;
private final @AppCompatDelegate.NightMode int mode;
NightMode(final String name, int mode) {
this.name = name;
this.mode = mode;
}
public String getName() {
return name;
}
public int getMode() {
return mode;
}
/** Get {@link NightMode} for {@code name} if found, otherwise {@code null}. */
@Nullable
public static NightMode modeOf(String name) {
for (NightMode v : NightMode.values()) {
if (v.name.equals(name)) {
return v;
}
}
return null;
}
/** Get {@link NightMode} for {@code name} if found, otherwise {@code def}. */
@NonNull
public static NightMode modeOf(@Nullable String name, @NonNull NightMode def) {
NightMode nightMode = modeOf(name);
return nightMode != null ? nightMode : def;
}
/** Set {@link #APP_NIGHT_MODE}. */
public static void setAppNightMode(@Nullable String name) {
if (name == null || name.isEmpty()) {
APP_NIGHT_MODE = SYSTEM;
} else {
NightMode nightMode = NightMode.modeOf(name);
if (nightMode == null) {
Logger.logError(LOG_TAG, "Invalid APP_NIGHT_MODE \"" + name + "\"");
return;
}
APP_NIGHT_MODE = nightMode;
}
Logger.logVerbose(LOG_TAG, "Set APP_NIGHT_MODE to \"" + APP_NIGHT_MODE.getName() + "\"");
}
/** Get {@link #APP_NIGHT_MODE}. */
@NonNull
public static NightMode getAppNightMode() {
if (APP_NIGHT_MODE == null)
APP_NIGHT_MODE = SYSTEM;
return APP_NIGHT_MODE;
}
}

Xet Storage Details

Size:
2.61 kB
·
Xet hash:
e5247cb641ec56ff43ae42c67037ab4bf89853ba2a01e9929fd8df3d811059a6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.