android.support.v7.app.AppCompatDelegate Java Examples
The following examples show how to use
android.support.v7.app.AppCompatDelegate.
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: MainActivity.java From HeroVideo-master with Apache License 2.0 | 6 votes |
/** * 日夜间模式切换 */ private void switchNightMode() { boolean isNight = PreferenceUtil.getBoolean(ConstantUtil.SWITCH_MODE_KEY, false); if (isNight) { // 日间模式 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, false); } else { // 夜间模式 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, true); } LogUtil.d(TAG," isNight = " +isNight); recreate(); }
Example #2
Source File: MainActivity.java From MaterialHome with Apache License 2.0 | 6 votes |
private void initNavView() { boolean night = SPUtils.getPrefBoolean(Constant.THEME_MODEL, false); if (night) { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); } MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme); mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true); mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch); mThemeSwitch.setChecked(night); mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SPUtils.setPrefBoolean(Constant.THEME_MODEL, isChecked); mThemeSwitch.setChecked(isChecked); if (isChecked) { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); } } }); }
Example #3
Source File: ContactAdapter.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
public ContactAdapter(Context context) { this.context = context; AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); // Get colors from theme TypedValue typedValueHighlight = new TypedValue(); context.getTheme().resolveAttribute(R.attr.backgroundElement, typedValueHighlight, true); colorHighlight = typedValueHighlight.data; TypedValue typedValuePrimary = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValuePrimary, true); colorPrimary = typedValuePrimary.data; // Init color primary inverse TypedValue typedValueSecondary = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimaryInverse, typedValueSecondary, true); colorPrimaryInverse = typedValueSecondary.data; // Init circle background circleBackground = ContextCompat.getDrawable(context, R.drawable.background_circle); circleBackground.setColorFilter(colorPrimaryInverse, PorterDuff.Mode.SRC_ATOP); }
Example #4
Source File: MainActivity.java From Yuan-WanAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFragments = new BaseFragment[5]; mVersionDialog = new VersionUpdateDialog(); boolean isNightChange = getIntent().getBooleanExtra(Constant.KEY_NIGHT_CHANGE, false); if (savedInstanceState == null) { mFragments[0] = new HomeFragment(); mFragments[1] = new SystemFragment(); mFragments[2] = new WxFragment(); mFragments[3] = new ProjectFragment(); mFragments[4] = new PersonFragment(); loadMultipleFragment(R.id.frameContain, 0, mFragments); if (isNightChange) mBottomBnv.setSelectedItemId(R.id.personItem); AppCompatDelegate.setDefaultNightMode(mPresenter.getNightStyleState() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); } else { //屏幕翻转后回到当前页面,夜间模式开启后重新登录app mFragments[0] = findFragmentByTag(HomeFragment.class.getName()); mFragments[1] = findFragmentByTag(SystemFragment.class.getName()); mFragments[2] = findFragmentByTag(WxFragment.class.getName()); mFragments[3] = findFragmentByTag(ProjectFragment.class.getName()); mFragments[4] = findFragmentByTag(PersonFragment.class.getName()); mBottomBnv.setSelectedItemId(getSelectedItemId(mPresenter.getNavCurrentItem())); } }
Example #5
Source File: MainActivity.java From styT with Apache License 2.0 | 6 votes |
@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 #6
Source File: MainActivity.java From ZhihuDaily with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_notification: goToLogin(); break; case R.id.action_night: if ((boolean) SharedPreferencesUtils.get(App.getContext(), "night_mode", false)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); SharedPreferencesUtils.put(App.getContext(), "night_mode", false); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); SharedPreferencesUtils.put(App.getContext(), "night_mode", true); } recreate(); break; case R.id.action_setting: startActivity(new Intent(this, SettingActivity.class)); break; } return super.onOptionsItemSelected(item); }
Example #7
Source File: SqrlApplication.java From secure-quick-reliable-login with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); configureShortcuts(getApplicationContext()); setApplicationShortcuts(getApplicationContext()); try { long currentId = getCurrentId(getApplicationContext()); if (currentId > 0) { SQRLStorage.getInstance(getApplicationContext()).read(IdentityDBHelper.getInstance(getApplicationContext()).getIdentityData(currentId)); } EntropyHarvester.getInstance(); } catch (Exception e) { Log.e(TAG, "Failed to get initiate EntropyHarvester or SQRLStorage."); } }
Example #8
Source File: WordSetActivity.java From friendspell with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_word_set); ButterKnife.bind(this); ((FriendSpellApplication) getApplication()).component().inject(this); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); try { init(); } catch (IOException e) { Timber.e(Log.getStackTraceString(e)); } }
Example #9
Source File: NanoApplication.java From nano-wallet-android with BSD 2-Clause "Simplified" License | 6 votes |
public void onCreate() { super.onCreate(); // initialize Realm database Realm.init(this); if (BuildConfig.DEBUG) { Timber.plant(new Timber.DebugTree()); } // create new instance of the application component (DI) mApplicationComponent = DaggerApplicationComponent .builder() .applicationModule(new ApplicationModule(this)) .build(); // initialize vault Vault.initializeVault(this); generateEncryptionKey(); // initialize fingerprint Reprint.initialize(this); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }
Example #10
Source File: ThemeUtils.java From sleep-cycle-alarm with GNU General Public License v3.0 | 6 votes |
public static int getCurrentTheme(String themeId) { int currentTheme; switch(themeId) { case "1": currentTheme = AppCompatDelegate.MODE_NIGHT_NO; break; case "2": currentTheme = AppCompatDelegate.MODE_NIGHT_AUTO; break; case "3": currentTheme = AppCompatDelegate.MODE_NIGHT_YES; break; default: Log.e(ThemeUtils.class.getName(), "Default case in setAppTheme switch"); currentTheme = AppCompatDelegate.MODE_NIGHT_NO; break; } return currentTheme; }
Example #11
Source File: MainActivity.java From cheesesquare with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_night_mode_system: setNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); break; case R.id.menu_night_mode_day: setNightMode(AppCompatDelegate.MODE_NIGHT_NO); break; case R.id.menu_night_mode_night: setNightMode(AppCompatDelegate.MODE_NIGHT_YES); break; case R.id.menu_night_mode_auto: setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); break; } return super.onOptionsItemSelected(item); }
Example #12
Source File: SettingsActivity.java From GPSLogger with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { AppCompatDelegate.setDefaultNightMode(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefColorTheme", "2"))); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); toolbar = findViewById(R.id.id_toolbar2); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(R.string.menu_settings); FragmentSettings wvf = new FragmentSettings(); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.id_preferences, wvf); ft.commit(); }
Example #13
Source File: MainActivity.java From AnotherRSS with The Unlicense | 6 votes |
@Override protected void onResume() { Log.d(AnotherRSS.TAG, "onResume"); AnotherRSS.withGui = true; new DbExpunge().execute(); boolean night = mPreferences.getBoolean("nightmode_use", false); if (night) { int startH = mPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START); int stopH = mPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP); if (AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) { umm.setNightMode(UiModeManager.MODE_NIGHT_YES); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } if (!AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_NO) { umm.setNightMode(UiModeManager.MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } } else { if (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES) { umm.setNightMode(UiModeManager.MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } } super.onResume(); }
Example #14
Source File: BaseActivity.java From ZZShow with Apache License 2.0 | 5 votes |
/** * 设置主题样式,必须在setContentView 之前调用 */ private void setNightOrDayMode(){ if(SharedPreferencesUtil.isNightMode()){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); initNightView(); mNightView.setBackgroundResource(R.color.night_mask); }else{ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } }
Example #15
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else{ menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example #16
Source File: BaseActivity.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
@Override public void useNightMode(boolean isNight) { if (isNight) { AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.MODE_NIGHT_NO); } recreate(); }
Example #17
Source File: BaseActivity.java From BookReader with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false) != mNowMode) { if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } recreate(); } }
Example #18
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode){ int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example #19
Source File: SettingsFragment.java From MaoWanAndoidClient with Apache License 2.0 | 5 votes |
private void ChangeThemeMode() { int mode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; if(mode == Configuration.UI_MODE_NIGHT_YES) { RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_NO)); } else if(mode == Configuration.UI_MODE_NIGHT_NO) { RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_YES)); }else { //否则保持亮色主题 RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_NO)); } }
Example #20
Source File: AddProductFragment.java From mobikul-standalone-pos with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); if (getArguments() != null) { product = (Product) getArguments().getSerializable(ARG_PARAM1); isEdit = getArguments().getBoolean(ARG_PARAM2); } }
Example #21
Source File: App.java From QuickLyric with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); super.onCreate(); refWatcher = LeakCanary.install(this); registerActivityLifecycleCallbacks(this); }
Example #22
Source File: MainActivity.java From hyperion-android-grabber with MIT License | 5 votes |
private void initActivity() { // assume the recorder is not running until we are notified otherwise mRecorderRunning = false; setContentView(R.layout.activity_main); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); ImageView iv = findViewById(R.id.power_toggle); iv.setOnClickListener(this); iv.setOnFocusChangeListener(this); iv.setFocusable(true); iv.requestFocus(); ImageButton ib = findViewById(R.id.settingsButton); ib.setOnClickListener(this); ib.setOnFocusChangeListener(this); ib.setFocusable(true); setImageViews(mRecorderRunning, false); LocalBroadcastManager.getInstance(this).registerReceiver( mMessageReceiver, new IntentFilter(BROADCAST_FILTER)); // request an update on the running status checkForInstance(); }
Example #23
Source File: SettingsFragment.java From QuickNote with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String key = preference.getKey(); if (key.equals(KEY_THEME)) { if (value.equals(QuickNote.getString(R.string.theme_value_default))) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else if (value.equals(QuickNote.getString(R.string.theme_value_night))) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } getActivity().recreate(); } else if (key.equals(KEY_LANG)) { if (value.equals(QuickNote.getString(R.string.lang_value_chinese))) { CommonUtil.changeLocalLanguage(QuickNote.getAppContext(), Locale.SIMPLIFIED_CHINESE); } else if (value.equals(QuickNote.getString(R.string.lang_value_english))) { CommonUtil.changeLocalLanguage(QuickNote.getAppContext(), Locale.US); } getActivity().recreate(); } else if (key.equals(KEY_AUTO_UPDATE)) { if (value.equals(false)) { // 提示用户如需更新可到关于界面进行手动更新 CommonUtil.showSnackBarOnUiThread(getView(), R.string.prompt_close_auto_update); } } else if (key.equals(KEY_GESTURE_PWD)) { if (value.equals(true)) { if (TextUtils.isEmpty(QuickNote.getSavedPattern())) { // 如果是初次启用 Intent intent = new Intent(getActivity(), LockActivity.class); startActivity(intent); } } } return true; }
Example #24
Source File: UiUtils.java From STUer-client with MIT License | 5 votes |
public static boolean isNightMode(AppCompatActivity activity) { int uiMode = activity.getResources().getConfiguration().uiMode; int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK; if (SPUtils.getBoolean(MainActivity.CURRENT_NIGHT_MODE) && dayNightUiMode != Configuration.UI_MODE_NIGHT_YES) { activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); activity.recreate(); return true; } return false; }
Example #25
Source File: SettingsActivity.java From Meshenger with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setTitle(getResources().getString(R.string.menu_settings)); prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); nick = prefs.getString("username", "undefined"); findViewById(R.id.changeNickLayout).setOnClickListener((v) -> changeNick()); CheckBox ignoreCB = findViewById(R.id.checkBoxIgnoreUnsaved); ignoreCB.setChecked(prefs.getBoolean("ignoreUnsaved", false)); ignoreCB.setOnCheckedChangeListener((compoundButton, b) -> { prefs.edit().putBoolean("ignoreUnsaved", b).apply(); syncSettings("ignoreUnsaved", b); }); CheckBox nightMode = findViewById(R.id.checkBoxNightMode); nightMode.setChecked(AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES); nightMode.setOnCheckedChangeListener((compoundButton, b) -> { AppCompatDelegate.setDefaultNightMode(compoundButton.isChecked() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); // TODO sync settings //syncSettings("ignoreUnsaved", b); }); }
Example #26
Source File: MainActivity.java From android-ponewheel with MIT License | 5 votes |
private void setupDarkModes(Bundle savedInstanceState) { if (App.INSTANCE.getSharedPreferences().isDayNightMode()) { if (savedInstanceState == null) { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); recreate(); } } if (App.INSTANCE.getSharedPreferences().isDarkNightMode()) { if (savedInstanceState == null) { getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); recreate(); } } }
Example #27
Source File: XmppActivity.java From Conversations with GNU General Public License v3.0 | 5 votes |
@Override public boolean onMenuOpened(int id, Menu menu) { if (id == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR && menu != null) { MenuDoubleTabUtil.recordMenuOpen(); } return super.onMenuOpened(id, menu); }
Example #28
Source File: MyApplication.java From AndroidDemo with MIT License | 5 votes |
protected void initNightMode() { boolean isNight = MyMusicUtil.getNightMode(context); if (isNight) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } }
Example #29
Source File: MyMusicUtil.java From MeetMusic with Apache License 2.0 | 5 votes |
public static void setNightMode(Context context, boolean mode) { if (mode) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } SharedPreferences sharedPreferences = context.getSharedPreferences(Constant.THEME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("night", mode).commit(); }
Example #30
Source File: ActivityUtils.java From Forage with Mozilla Public License 2.0 | 5 votes |
/** * Sets the support action bar back button. The activity still has to manage the back button * event correctly! * * @param delegate AppCompatDelegate for the AppCompatActivity you want to modify. */ public static void setSupportActionBarBack(@NonNull AppCompatDelegate delegate) { ActionBar bar = delegate.getSupportActionBar(); if (bar != null) { delegate.getSupportActionBar().setDisplayShowHomeEnabled(true); delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }