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

The following examples show how to use androidx.appcompat.app.AppCompatDelegate#MODE_NIGHT_NO . 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: 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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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);
        }
    }
 
Example 12
Source File: Preferences.java    From materialistic with Apache License 2.0 4 votes vote down vote up
public static int getAutoDayNightMode(Context context) {
    return getTheme(context, false) instanceof ThemePreference.DayNightSpec &&
            get(context, R.string.pref_daynight_auto, false) ?
            AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM : AppCompatDelegate.MODE_NIGHT_NO;
}
 
Example 13
Source File: MapTrek.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    mSelf = this;

    try {
        versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        logger.error("Failed to get version", e);
    }

    File cacheDir = getExternalCacheDir();
    File exportDir = new File(cacheDir, "export");
    if (!exportDir.exists())
        //noinspection ResultOfMethodCallIgnored
        exportDir.mkdir();
    mExceptionLog = new File(exportDir, EXCEPTION_PATH);
    mExceptionHandler = new DefaultExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(mExceptionHandler);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    Configuration.initialize(PreferenceManager.getDefaultSharedPreferences(this));
    initializeSettings();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    density = metrics.density;
    ydpi = metrics.ydpi;

    TextStyle.MAX_TEXT_WIDTH = (int) (density * 220);

    if (Build.VERSION.SDK_INT > 25)
        createNotificationChannel();

    File[] dirs = getExternalFilesDirs(null);
    for (File dir : dirs) {
        if (mSDCardDirectory == null && dir != null) {
            try {
                if (Environment.isExternalStorageRemovable(dir) &&
                        Environment.getExternalStorageState(dir).equals(Environment.MEDIA_MOUNTED)) {
                    mSDCardDirectory = dir;
                    break;
                }
            } catch (IllegalArgumentException ignore) {
                // directory is inaccessible
            }
        }
    }
    // find removable external storage
    logger.error("Has SD card: {}", mSDCardDirectory);

    mapObjects.clear();

    int nightMode = BuildConfig.FULL_VERSION ? Configuration.getNightModeState() : AppCompatDelegate.MODE_NIGHT_NO;
    AppCompatDelegate.setDefaultNightMode(nightMode);
}