Java Code Examples for android.support.v7.app.AppCompatDelegate#MODE_NIGHT_YES

The following examples show how to use android.support.v7.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: Canvas.java    From Google-AAD-CheatSheet with MIT License 6 votes vote down vote up
@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.night_mode) {
            // Get the night mode state of the app.
            int nightMode = AppCompatDelegate.getDefaultNightMode();
            //Set the theme mode for the restarted activity
            if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) {
                AppCompatDelegate.setDefaultNightMode
                        (AppCompatDelegate.MODE_NIGHT_NO);
            } else {
                AppCompatDelegate.setDefaultNightMode
                        (AppCompatDelegate.MODE_NIGHT_YES);
            }
// Recreate the activity for the theme change to take effect.
            recreate();

        }
        return super.onOptionsItemSelected(item);
    }
 
Example 2
Source File: DayNightModeMapper.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
@AppCompatDelegate.NightMode
public int toDayNightMode(@NonNull final Theme theme) {
    switch (theme) {
        case NIGHT:
            return AppCompatDelegate.MODE_NIGHT_YES;

        case DAY:
            return AppCompatDelegate.MODE_NIGHT_NO;

        case DAYNIGHT:
            return AppCompatDelegate.MODE_NIGHT_AUTO;

        default:
            throw new IllegalArgumentException("Unexpected theme: " + theme);
    }
}
 
Example 3
Source File: FlavorRecyclerAdapter.java    From Scoops with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("WrongConstant")
@Override
public void onClick(View v) {
    int i = v.getId();
    int mode = 0;
    if (i == R.id.opt_auto) {
        mode = AppCompatDelegate.MODE_NIGHT_AUTO;
    } else if (i == R.id.opt_system) {
        mode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
    } else if (i == R.id.opt_off) {
        mode = AppCompatDelegate.MODE_NIGHT_NO;
    } else if (i == R.id.opt_on) {
        mode = AppCompatDelegate.MODE_NIGHT_YES;
    }

    AppCompatDelegate.setDefaultNightMode(mode);
    Scoop.getInstance().chooseDayNightMode(mode);
    bindOptions(mode);
}
 
Example 4
Source File: SettingFragment.java    From Ency with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == provincialFlowPreference) {
            sharePrefManager.setProvincialTrafficPatterns((Boolean) newValue);
        } else if (preference == nightModePreference) {
            sharePrefManager.setNightMode((Boolean) newValue);
            int currentMode = (Boolean) newValue ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
            AppCompatDelegate.setDefaultNightMode(currentMode);
            // recreate()会产生闪屏
//            if (getActivity() instanceof SettingActivity) {
//                getActivity().recreate();
//            }
            // 调用startActivity启动,并为其添加了一个透明渐变的启动动画,最后调用finish结束掉旧的页面。
            getActivity().startActivity(new Intent(getActivity(), SettingActivity.class));
            getActivity().overridePendingTransition(R.anim.alpha_start, R.anim.alpha_out);
            getActivity().finish();
        }
        return true;
    }
 
Example 5
Source File: ThemeUtils.java    From sleep-cycle-alarm with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: SettingsPageAdapter.java    From MaoWanAndoidClient with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(SettingsViewItemHolder helper, SettingData item) {
    helper.setText(R.id.tv_setting_item_title,item.getmName());
    if(item.ismIsSwitch()){
       helper.setVisible(R.id.setting_switch,true);
       //禁止switch 点击 保持 与 item点击 同步
       helper.getView(R.id.setting_switch).setClickable(false);
       if(AppCompatDelegate.MODE_NIGHT_YES == mode){
           //当前模式为夜间模式
           helper.setChecked(R.id.setting_switch,true);
       }else {
           helper.setChecked(R.id.setting_switch,false);
       }
    }else {
        helper.setVisible(R.id.iv_chevron_right,true);
    }
    if(Constants.SETTINGS_VERSION_TYPE.equals(item.getType())){
        helper.setVisible(R.id.tv_version_Name,true);
        helper.setText(R.id.tv_version_Name,ToolsUtils.getVersion(mContext));
    }
}
 
Example 7
Source File: MainActivity.java    From cheesesquare with Apache License 2.0 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 8
Source File: EmbeddedNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void alternateNightMode(int currentNightMode) {
  int newNightMode;
  if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
    newNightMode = AppCompatDelegate.MODE_NIGHT_NO;
  } else {
    newNightMode = AppCompatDelegate.MODE_NIGHT_YES;
  }
  saveNightModeToPreferences(newNightMode);
  recreate();
}
 
Example 9
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 10
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 11
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 13
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 14
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 15
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 17
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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 18
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@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: SettingActivity.java    From apkextractor with GNU General Public License v3.0 4 votes vote down vote up
private void refreshSettingValues(){
    if(settings==null)return;
    //SharedPreferences.Editor editor=settings.edit();
    ((TextView)findViewById(R.id.settings_path_value)).setText(SPUtil.getDisplayingExportPath(this));
    ((TextView)findViewById(R.id.settings_share_mode_value)).setText(
            getResources().getString(
                    settings.getInt(Constants.PREFERENCE_SHAREMODE,Constants.PREFERENCE_SHAREMODE_DEFAULT)==Constants.SHARE_MODE_DIRECT?
                    R.string.share_mode_direct:R.string.share_mode_export));
    String night_mode_value="";
    switch (settings.getInt(Constants.PREFERENCE_NIGHT_MODE,Constants.PREFERENCE_NIGHT_MODE_DEFAULT)){
        default:break;
        case AppCompatDelegate.MODE_NIGHT_YES:night_mode_value=getResources().getString(R.string.night_mode_enabled);break;
        case AppCompatDelegate.MODE_NIGHT_NO:night_mode_value=getResources().getString(R.string.night_mode_disabled);break;
        case AppCompatDelegate.MODE_NIGHT_AUTO:night_mode_value=getResources().getString(R.string.night_mode_auto);break;
        case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:night_mode_value=getResources().getString(R.string.night_mode_follow_system);break;
    }
    ((TextView)findViewById(R.id.settings_night_mode_value)).setText(night_mode_value);
    String read_options="";
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT)){
        read_options+=getResources().getString(R.string.activity_detail_permissions);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.activity_detail_activities);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.activity_detail_services);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.activity_detail_receivers);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.activity_detail_providers);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_STATIC_LOADERS,Constants.PREFERENCE_LOAD_STATIC_LOADERS_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.activity_detail_static_loaders);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.dialog_loading_selection_signature);
    }
    if(settings.getBoolean(Constants.PREFERENCE_LOAD_FILE_HASH,Constants.PREFERENCE_LOAD_FILE_HASH_DEFAULT)){
        if(!read_options.equals(""))read_options+=",";
        read_options+=getResources().getString(R.string.dialog_loading_selection_file_hash);
    }
    if(read_options.trim().equals(""))read_options=getResources().getString(R.string.word_blank);
    ((TextView)findViewById(R.id.settings_loading_options_value)).setText(read_options);
    String language_value="";
    switch (SPUtil.getGlobalSharedPreferences(this).getInt(Constants.PREFERENCE_LANGUAGE,Constants.PREFERENCE_LANGUAGE_DEFAULT)){
        default:break;
        case Constants.LANGUAGE_FOLLOW_SYSTEM:language_value=getResources().getString(R.string.language_follow_system);break;
        case Constants.LANGUAGE_CHINESE:language_value=getResources().getString(R.string.language_chinese);break;
        case Constants.LANGUAGE_ENGLISH:language_value=getResources().getString(R.string.language_english);break;
    }
    ((TextView)findViewById(R.id.settings_language_value)).setText(language_value);
    ((TextView)findViewById(R.id.settings_port_number_value)).setText(String.valueOf(SPUtil.getPortNumber(this)));
    ((TextView)findViewById(R.id.settings_device_name_value)).setText(SPUtil.getDeviceName(this));
    ((TextView)findViewById(R.id.settings_extension_value)).setText(SPUtil.getCompressingExtensionName(this));
    final int value_package_scope=settings.getInt(Constants.PREFERENCE_PACKAGE_SCOPE,Constants.PREFERENCE_PACKAGE_SCOPE_DEFAULT);
    TextView tv_package_scope=findViewById(R.id.settings_package_scope_value);
    switch (value_package_scope){
        default:break;
        case Constants.PACKAGE_SCOPE_ALL:{
            tv_package_scope.setText(getResources().getString(R.string.package_scope_all));
        }
        break;
        case Constants.PACKAGE_SCOPE_EXPORTING_PATH:{
            tv_package_scope.setText(getResources().getString(R.string.package_scope_exporting_path));
        }
        break;
    }
    ((TextView)findViewById(R.id.settings_package_name_separator_value)).setText(settings.getString(Constants.PREFERENCE_COPYING_PACKAGE_NAME_SEPARATOR,Constants.PREFERENCE_COPYING_PACKAGE_NAME_SEPARATOR_DEFAULT));
}
 
Example 20
Source File: MeshengerActivity.java    From meshenger-android with GNU General Public License v3.0 4 votes vote down vote up
private boolean darkModeEnabled() {
    return (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES);
}