private static void activateFollowSystemMode(Context context, Boolean notifyUser) { // save the new state saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); // switch to Undefined Mode / Follow System AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); // notify user if (notifyUser) { Toast.makeText(context, context.getText(R.string.toastmessage_theme_follow_system), Toast.LENGTH_LONG).show(); } }
private static void activateNightMode(Context context, Boolean notifyUser) { saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_YES); // switch to Night Mode AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); // notify user if (notifyUser) { Toast.makeText(context, context.getText(R.string.toastmessage_theme_night), Toast.LENGTH_LONG).show(); } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { LangHelper.updateLanguage(this); super.onCreate(savedInstanceState); AppCompatDelegate.setDefaultNightMode(SpHelper.getThemeMode(this)); }
private static void activateDayMode(Context context, Boolean notifyUser) { // save the new state saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_NO); // switch to Day Mode AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); // notify user if (notifyUser) { Toast.makeText(context, context.getText(R.string.toastmessage_theme_day), Toast.LENGTH_LONG).show(); } }
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.menu_night_mode) { menuItem.setChecked(!menuItem.isChecked()); if (menuItem.isChecked()) { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); } getDelegate().applyDayNight(); } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set Night Mode SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); // Set theme setTheme(getResources().getIdentifier( sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), "style", getPackageName()) ); }
@Override public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) { if ("dark_theme".equals(key)) { final boolean darkMode = sharedPreferences.getBoolean(key, false); AppCompatDelegate.setDefaultNightMode( sharedPreferences.getBoolean(key, false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); invalidateDrawableCache(getResources(), darkMode); recreate(); } } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { // Don't initialize analytics with debug build if (!BuildConfig.DEBUG) { Fabric.with(this, new Crashlytics()); } AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); Utils.DARK_THEME = Themes.isDarkTheme(this); Themes.Theme theme = Themes.getTheme(this, Utils.DARK_THEME); if (Utils.DARK_THEME) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } setTheme(theme.getStyle()); super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && setStatusBarColor()) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(statusBarColor()); } }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preferences preference = Preferences.getPreference(key); if(preference != null) { switch (preference.getChangeAction()) { case NOTHING: break; case RECREATE: recreateActivity = true; FaviconLoader.clearCache(); AppCompatDelegate.setDefaultNightMode(Preferences.getNightMode(sharedPreferences)); Intent intent = getIntent(); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRA_RECREATE_ACTIVITY, recreateActivity); startActivity(intent); finish(); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); break; case UPDATE: PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(Preferences.SYS_NEEDS_UPDATE_AFTER_SYNC.getKey(), true).apply(); break; } } }
@Override public void onCreate() { super.onCreate(); asyncWorker = new AsyncWorker(AsyncTask.SERIAL_EXECUTOR, new Handler(Looper.getMainLooper())); rootShell = new RootShell(getApplicationContext()); toolsInstaller = new ToolsInstaller(getApplicationContext()); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); AppCompatDelegate.setDefaultNightMode( sharedPreferences.getBoolean("dark_theme", false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); tunnelManager = new TunnelManager(new FileConfigStore(getApplicationContext())); tunnelManager.onCreate(); asyncWorker.supplyAsync(Application::getBackend).thenAccept(futureBackend::complete); } }
public void applyThemeToActivity(Activity activity) { if (currentCustomThemePatcher == null && currentCustomTheme != null) { ThemeResourceFileBuilder.CustomTheme theme = ThemeResourceFileBuilder .createTheme(context, currentCustomTheme); currentTheme = theme; File themeFile = ThemeResourceFileBuilder.createThemeZipFile(context, theme.getResTable()); currentCustomThemePatcher = new Theme(context, themeFile.getAbsolutePath()); } if (currentCustomThemePatcher != null) { currentCustomThemePatcher.applyToActivity(activity); } ThemeResInfo currentBaseTheme = currentTheme; if (currentCustomTheme != null) currentBaseTheme = currentCustomTheme.baseThemeInfo; if (currentBaseTheme instanceof BaseTheme) { if (((BaseTheme) currentBaseTheme).isDark) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); else AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } if (mNeedsApplyIrcColors) IRCColorUtils.loadColors(activity.getTheme(), currentTheme.getIRCColorsResId()); }
AppCompatDelegate.setDefaultNightMode(Preferences.getNightMode(preferences));