Java Code Examples for android.support.v7.app.AppCompatDelegate.getDefaultNightMode()

The following are Jave code examples for showing how to use getDefaultNightMode() of the android.support.v7.app.AppCompatDelegate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AURdroid   File: MainActivity.java   Source Code and License Vote up 6 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    /*
      app share and rate group
      hide on AurPackageDetailsFragment
     */
    MenuItem menuItem = menu.findItem(R.id.menu_main_app_group);
    Fragment fragmentByTag = fragmentManager.findFragmentByTag(AUR_PACKAGE_DETAILS_FRAGMENT_TAG);
    menuItem.setVisible(fragmentByTag == null);
    // night mode
    switch (AppCompatDelegate.getDefaultNightMode()) {
        case AppCompatDelegate.MODE_NIGHT_AUTO:
            menu.findItem(R.id.menu_main_action_night_mode_auto).setChecked(true);
            break;
        case AppCompatDelegate.MODE_NIGHT_YES:
            menu.findItem(R.id.menu_main_action_night_mode_night).setChecked(true);
            break;
        case AppCompatDelegate.MODE_NIGHT_NO:
            menu.findItem(R.id.menu_main_action_night_mode_day).setChecked(true);
            break;
    }
    return true;
}
 
Example 2
Project: PNightMode   File: MainAppCompatActivity.java   Source Code and License Vote up 5 votes
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.btn_second_activity:
            Intent intent = new Intent();
            intent.setClass(this, SecondAppCompatActivity.class);
            startActivity(intent);
            break;
        case R.id.btn_toggle_night_mode:
            int mode = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES
                    ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES;
            toggleGlobalNightMode(mode);
            break;
    }
}
 
Example 3
Project: AURdroid   File: MainActivity.java   Source Code and License Vote up 5 votes
private void storeApplyNightMode(int nightMode) {
    if (nightMode != AppCompatDelegate.getDefaultNightMode()) {
        sharedPreferences.edit()
                .putInt(getResources().getString(R.string.key_night_mode), nightMode)
                .apply();
        AppCompatDelegate.setDefaultNightMode(nightMode);
        recreate();
    }
}
 
Example 4
Project: PNightMode   File: MainAppCompatActivity.java   Source Code and License Vote up 4 votes
@Override
protected void onResume() {
    super.onResume();
    int mode = AppCompatDelegate.getDefaultNightMode();
    Log.d(TAG, "onResume mode:" + mode);
}