Example usage for android.content.res Configuration UI_MODE_NIGHT_MASK

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

Introduction

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

Prototype

int UI_MODE_NIGHT_MASK

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

Click Source Link

Document

Constant for #uiMode : bits that encode the night mode.

Usage

From source file:com.shalzz.attendance.controllers.DayController.java

public DayController(Context context, DayFragment view) {
    mContext = context;/*from w  w w.j  av  a2s .c om*/
    mView = view;
    mAdapter = new DayListAdapter();
    String unit_id;
    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    if (currentNightMode == Configuration.UI_MODE_NIGHT_YES)
        unit_id = mContext.getString(R.string.native_black_timetable_ad);
    else
        unit_id = mContext.getString(R.string.native_white_timetable_ad);

    adapterWrapper = new AdmobExpressRecyclerAdapterWrapper(mContext, unit_id,
            new AdSize(AdSize.FULL_WIDTH, 80));

    adapterWrapper.setAdapter(mAdapter);

    adapterWrapper.setLimitOfAds(1);
    adapterWrapper.setFirstAdIndex(3);
    mView.mRecyclerView.setAdapter(adapterWrapper);
}

From source file:com.shalzz.attendance.controllers.AttendanceController.java

@Inject
public AttendanceController(Context context, AttendanceListFragment view, DataAPI api) {
    mContext = context;//from w  ww  . jav a 2s  .  com
    mResources = context.getResources();
    mView = view;
    db = new DatabaseHandler(mContext);
    this.api = api;

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
    int expandLimit = Integer
            .parseInt(sharedPref.getString(mContext.getString(R.string.pref_key_sub_limit), "3"));

    mAdapter = new ExpandableListAdapter(mContext, mView);
    mAdapter.setLimit(expandLimit);
    LayoutInflater inflater = mView.getActivity().getLayoutInflater();
    mFooter = inflater.inflate(R.layout.list_footer, mView.mRecyclerView, false);
    mFooter.setVisibility(View.INVISIBLE);
    mAdapter.addFooter(mFooter);

    String unit_id;
    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    if (currentNightMode == Configuration.UI_MODE_NIGHT_YES)
        unit_id = mContext.getString(R.string.native_black_attendance_ad);
    else
        unit_id = mContext.getString(R.string.native_white_attendance_ad);

    adapterWrapper = new AdmobExpressRecyclerAdapterWrapper(mContext, unit_id,
            new AdSize(AdSize.FULL_WIDTH, 100));

    adapterWrapper.setAdapter(mAdapter);

    adapterWrapper.setLimitOfAds(1);
    adapterWrapper.setNoOfDataBetweenAds(5);
    adapterWrapper.setFirstAdIndex(5);

    mView.mRecyclerView.setAdapter(adapterWrapper);
}

From source file:com.example.ray.firstapp.bottombar.MiscUtils.java

/**
 * Determine if the current UI Mode is Night Mode.
 *
 * @param context Context to get the configuration.
 * @return true if the night mode is enabled, otherwise false.
 */// ww  w . ja  v a2s.  c o m
protected static boolean isNightMode(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}

From source file:com.pagenews.zhihudaily.homepage.MainActivity.java

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    drawer.closeDrawer(GravityCompat.START);

    int id = item.getItemId();
    if (id == R.id.nav_home) {
        showMainFragment();//from   ww w  .  j  a  va  2  s  .c  om
    } else if (id == R.id.nav_bookmarks) {
        showBookmarksFragment();
    } else if (id == R.id.nav_change_theme) {

        // change the day/night mode after the drawer closed
        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SharedPreferences sp = getSharedPreferences("user_settings", MODE_PRIVATE);
                if ((getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
                    sp.edit().putInt("theme", 0).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                } else {
                    sp.edit().putInt("theme", 1).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                }
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                recreate();
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

    } else if (id == R.id.nav_settings) {
        startActivity(new Intent(this, SettingsPreferenceActivity.class));
    } else if (id == R.id.nav_about) {
        startActivity(new Intent(this, AboutPreferenceActivity.class));
    }

    return true;
}

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  w  w  . java2s .  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:io.github.marktony.espresso.mvp.packages.MainActivity.java

/**
 * Handle different items of the navigation drawer
 * @param item The selected item.// w  w w.j  av  a 2  s  .  c  o m
 * @return Selected or not.
 */
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.nav_home) {

        showPackagesFragment();

    } else if (id == R.id.nav_companies) {

        showCompaniesFragment();

    } else if (id == R.id.nav_switch_theme) {

        drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                if ((getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
                    sp.edit().putBoolean(SettingsUtil.KEY_NIGHT_MODE, false).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                } else {
                    sp.edit().putBoolean(SettingsUtil.KEY_NIGHT_MODE, true).apply();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                }
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                recreate();
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

    } else if (id == R.id.nav_settings) {

        Intent intent = new Intent(MainActivity.this, PrefsActivity.class);
        intent.putExtra(PrefsActivity.EXTRA_FLAG, PrefsActivity.FLAG_SETTINGS);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

    } else if (id == R.id.nav_about) {

        Intent intent = new Intent(MainActivity.this, PrefsActivity.class);
        intent.putExtra(PrefsActivity.EXTRA_FLAG, PrefsActivity.FLAG_ABOUT);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

    }

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

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);
    }/*  ww  w . j a va2 s  .  c o m*/
    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 ww w . j  a v  a  2 s  . c o m
    }

    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:// ww w  .java 2s.co  m
        return true;
    }
}