Example usage for android.content.res Configuration UI_MODE_NIGHT_NO

List of usage examples for android.content.res Configuration UI_MODE_NIGHT_NO

Introduction

In this page you can find the example usage for android.content.res Configuration UI_MODE_NIGHT_NO.

Prototype

int UI_MODE_NIGHT_NO

To view the source code for android.content.res Configuration UI_MODE_NIGHT_NO.

Click Source Link

Document

Constant for #uiMode : a #UI_MODE_NIGHT_MASK value that corresponds to the notnight resource qualifier.

Usage

From source file:com.white.bihudaily.module.dailys.DailyActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Open the navigation drawer when the home icon is selected from the toolbar.
        mDrawerLayout.openDrawer(GravityCompat.START);
        return true;
    case R.id.action_setting:
        ActivityUtils.toSettingActivity(this);
        break;/*from   w ww .  ja  v a  2 s.  c o  m*/
    case R.id.action_night:
        int uiMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (uiMode) {
        case Configuration.UI_MODE_NIGHT_NO://??
            SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, true);
            getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            break;
        case Configuration.UI_MODE_NIGHT_YES://??
            SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, false);
            getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            break;
        }
        getSupportFragmentManager().getFragments().clear();
        recreate();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static Resources updateNightMode(Resources resource, boolean on) {
    DisplayMetrics dm = resource.getDisplayMetrics();
    Configuration config = resource.getConfiguration();
    final int uiModeNightMaskOrigin = config.uiMode &= ~Configuration.UI_MODE_TYPE_MASK;
    final int uiModeNightMaskNew = on ? Configuration.UI_MODE_NIGHT_YES : Configuration.UI_MODE_NIGHT_NO;
    if (uiModeNightMaskOrigin != uiModeNightMaskNew) {
        config.uiMode &= ~Configuration.UI_MODE_NIGHT_MASK;
        config.uiMode |= uiModeNightMaskNew;
        resource.updateConfiguration(config, dm);
    }/*from   w ww .j a v  a2  s.  c om*/
    return resource;
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static boolean isInNightMode(@NonNull Resources argResources) {

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES)
        return true;

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO)
        return false;

    int currentNightMode = argResources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_UNDEFINED:
        // We don't know what mode we're in, assume notnight
        return false;
    case Configuration.UI_MODE_NIGHT_NO:
        // Night mode is not active, we're in day time
        return false;
    case Configuration.UI_MODE_NIGHT_YES: {
        // Night mode is active, we're at night!
        //color = (int) (color * 0.2);
        //color = darken(color, 1f);
        return true;
    }//from  w  w w . ja va 2  s . com
    }

    return false;
}

From source file:de.sindzinski.wetter.util.Utility.java

public static boolean getUiModeNight(Context mContext) {

    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_NO:
        Log.i(TAG, "Night mode is not active, we're in day time");
        return false;
    case Configuration.UI_MODE_NIGHT_YES:
        Log.i(TAG, "Night mode is active, we're at night!");
        return true;
    case Configuration.UI_MODE_NIGHT_UNDEFINED:
        Log.i(TAG, "We don't know what mode we're in, assume notnight");
        return true;
    default:/*w  w w. ja  v  a 2  s.co  m*/
        return true;
    }
}