Java Code Examples for androidx.appcompat.app.AppCompatDelegate#MODE_NIGHT_YES

The following examples show how to use androidx.appcompat.app.AppCompatDelegate#MODE_NIGHT_YES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThemeManager.java    From zephyr with MIT License 6 votes vote down vote up
private void setDefaultNightMode(@Theme int theme) {
    int nightMode;
    switch (theme) {
        case Theme.SYSTEM_DEFAULT:
            nightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
            break;
        case Theme.LIGHT:
            nightMode = AppCompatDelegate.MODE_NIGHT_NO;
            break;
        case Theme.DARK:
            nightMode = AppCompatDelegate.MODE_NIGHT_YES;
            break;
        default:
            setDefaultNightMode(getDefaultTheme());
            return;
    }

    AppCompatDelegate.setDefaultNightMode(nightMode);
}
 
Example 2
Source File: DesignActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
	switch (AppCompatDelegate.getDefaultNightMode()) {
		case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:
			menu.findItem(R.id.menu_night_mode_system).setChecked(true);
			break;
		case AppCompatDelegate.MODE_NIGHT_AUTO:
			menu.findItem(R.id.menu_night_mode_auto).setChecked(true);
			break;
		case AppCompatDelegate.MODE_NIGHT_YES:
			menu.findItem(R.id.menu_night_mode_night).setChecked(true);
			break;
		case AppCompatDelegate.MODE_NIGHT_NO:
			menu.findItem(R.id.menu_night_mode_day).setChecked(true);
			break;
	}
	return true;
}
 
Example 3
Source File: LinphonePreferences.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
public boolean isDarkModeEnabled() {
    if (getConfig() == null) return false;
    if (!mContext.getResources().getBoolean(R.bool.allow_dark_mode)) return false;

    boolean useNightModeDefault =
            AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES;
    if (mContext != null) {
        int nightMode =
                mContext.getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK;
        if (nightMode == Configuration.UI_MODE_NIGHT_YES) {
            useNightModeDefault = true;
        }
    }

    return getConfig().getBool("app", "dark_mode", useNightModeDefault);
}
 
Example 4
Source File: ThemeHelper.java    From android with MIT License 5 votes vote down vote up
private static int ofKey(Context context, String newTheme) {
    if (context.getString(R.string.theme_dark).equals(newTheme)) {
        return AppCompatDelegate.MODE_NIGHT_YES;
    }
    if (context.getString(R.string.theme_light).equals(newTheme)) {
        return AppCompatDelegate.MODE_NIGHT_NO;
    }
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
        return AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
    }
    return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}
 
Example 5
Source File: MainActivity.java    From cythara with GNU General Public License v3.0 5 votes vote down vote up
private void enableTheme() {
    final SharedPreferences preferences = getSharedPreferences(PREFS_FILE,
            MODE_PRIVATE);
    isDarkModeEnabled = preferences.getBoolean(USE_DARK_MODE, true);

    int mode = AppCompatDelegate.MODE_NIGHT_NO;
    if (isDarkModeEnabled) {
        mode = AppCompatDelegate.MODE_NIGHT_YES;
    }

    AppCompatDelegate.setDefaultNightMode(mode);
}
 
Example 6
Source File: SettingsRepository.java    From zapp with MIT License 5 votes vote down vote up
public int prefValueToUiMode(String prefSetting) {
	switch (prefSetting) {
		case "light":
			// light
			return AppCompatDelegate.MODE_NIGHT_NO;
		case "dark":
			// dark
			return AppCompatDelegate.MODE_NIGHT_YES;
		default:
			// default
			return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ?
				AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM :
				AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
	}
}
 
Example 7
Source File: MainActivity.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
private void setDarkMode(boolean dayTime) {
    if (SettingsOptionManager.getInstance(this).getDarkMode() == DarkMode.AUTO) {
        int mode = dayTime ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES;
        getDelegate().setLocalNightMode(mode);
        AppCompatDelegate.setDefaultNightMode(mode);
    }
}
 
Example 8
Source File: PresetThemeStore.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@NightMode
public int getNightMode() {
    switch (mPreferenceStore.getBaseColor()) {
        case AUTO:
            return AppCompatDelegate.MODE_NIGHT_AUTO;
        case DARK:
            return AppCompatDelegate.MODE_NIGHT_YES;
        case LIGHT:
        default:
            return AppCompatDelegate.MODE_NIGHT_NO;
    }
}
 
Example 9
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private void checkNightMode(Location location) {
    if (mNextNightCheck > mLastLocationMilliseconds)
        return;

    mSunriseSunset.setLocation(location.getLatitude(), location.getLongitude());
    final boolean isNightTime = !mSunriseSunset.isDaytime((location.getTime() * 1d / 3600000) % 24);

    if (isNightTime ^ mNightMode) {
        int nightMode = isNightTime ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
        getDelegate().setLocalNightMode(nightMode);
    }

    mNextNightCheck = mLastLocationMilliseconds + NIGHT_CHECK_PERIOD;
}
 
Example 10
Source File: AuthUiActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@OnClick({R.id.default_theme, R.id.purple_theme, R.id.green_theme, R.id.dark_theme})
public void toggleDarkTheme() {
    int mode = mDarkTheme.isChecked() ?
            AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
    AppCompatDelegate.setDefaultNightMode(mode);
    getDelegate().setLocalNightMode(mode);
}
 
Example 11
Source File: MBaseActivity.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public int getNightMode() {
    return isNightTheme() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
}
 
Example 12
Source File: SpHelper.java    From AppOpsX with MIT License 4 votes vote down vote up
public static int getThemeMode(Context context) {
  if (getSharedPreferences(context).getBoolean("pref_app_daynight_mode", false)) {
    return AppCompatDelegate.MODE_NIGHT_YES;
  }
  return AppCompatDelegate.MODE_NIGHT_NO;
}
 
Example 13
Source File: BaseActivity.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
public void switchTheme() {
        if (App.followSystemDarkMode(this)) {
            return;
        }

        //直接夜间 设置退出
        int theme = App.getCustomTheme(this);
        int cur = AppCompatDelegate.getDefaultNightMode();
        int to = cur;
        boolean autoChange = false;

        //夜间主题
        if (theme == ThemeActivity.THEME_NIGHT) {
            to = AppCompatDelegate.MODE_NIGHT_YES;
        } else {//白天主题
            if (App.isAutoDarkMode(this)) {
                autoChange = true;
                int[] time = App.getDarkModeTime(this);
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if ((hour >= time[0] || hour < time[1])) {
                    //自动切换
                    to = AppCompatDelegate.MODE_NIGHT_YES;
                } else {
                    to = AppCompatDelegate.MODE_NIGHT_NO;
                }
            } else {
                to = AppCompatDelegate.MODE_NIGHT_NO;
            }
        }

        if (to == AppCompatDelegate.MODE_NIGHT_YES) {
            //夜间模式主题
            setTheme(R.style.AppTheme);
        } else {
            setTheme(theme);
        }

        //黑白发生了变化
        if (to != cur) {
//            if (autoChnage) {
//                showToast("自动" + (to == AppCompatDelegate.MODE_NIGHT_YES ?
//                        "切换到夜间模式" : "关闭夜间模式"));
//            }
            AppCompatDelegate.setDefaultNightMode(to);
        }
    }