Java Code Examples for android.content.res.Configuration#UI_MODE_NIGHT_UNDEFINED

The following examples show how to use android.content.res.Configuration#UI_MODE_NIGHT_UNDEFINED . 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: RNCAppearanceModule.java    From react-native-appearance with MIT License 6 votes vote down vote up
protected String getColorScheme(Configuration config) {
    String colorScheme = "no-preference";

    // Only Android 10+ support dark mode
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
        int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
            case Configuration.UI_MODE_NIGHT_UNDEFINED:
                colorScheme = "light";
                break;
            case Configuration.UI_MODE_NIGHT_YES:
                colorScheme = "dark";
                break;

        }
    }

    return colorScheme;
}
 
Example 2
Source File: MainActivity.java    From SkinSprite with MIT License 6 votes vote down vote up
@Override
public void onClick(View view) {
    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO: {
            setDayNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            // Night mode is not active, we're in day time
            break;
        }
        case Configuration.UI_MODE_NIGHT_YES:{
            setDayNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            // Night mode is active, we're at night!
            break;
        }
        case Configuration.UI_MODE_NIGHT_UNDEFINED: {
            // We don't know what mode we're in, assume notnight
        }
    }
}
 
Example 3
Source File: ThemeableActivity.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    int nightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (nightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            if (LinphonePreferences.instance().isDarkModeEnabled()) {
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            }
        case Configuration.UI_MODE_NIGHT_YES:
            if (!LinphonePreferences.instance().isDarkModeEnabled()) {
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            }
    }
}
 
Example 4
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public static boolean isNightModeOn(@NonNull Context context, boolean fallback) {
    int mode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (mode) {
        case Configuration.UI_MODE_NIGHT_YES:
            return true;
        case Configuration.UI_MODE_NIGHT_NO:
            return false;
        default:
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            return fallback;
    }
}
 
Example 5
Source File: ThemeManager.java    From zephyr with MIT License 5 votes vote down vote up
@Theme
@Override
public int getCurrentTheme() {
    int currentNightMode = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
            return Theme.LIGHT;
        case Configuration.UI_MODE_NIGHT_YES:
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
        default:
            return Theme.DARK;
    }
}
 
Example 6
Source File: ThemeHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private static boolean nightMode(Context context) {
    int nightModeFlags = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (nightModeFlags) {
        case Configuration.UI_MODE_NIGHT_YES:
            return true;
        case Configuration.UI_MODE_NIGHT_NO:
            return false;
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            return false;
        default:
            return false;
    }
}
 
Example 7
Source File: ApplicationPreferences.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static String applicationTheme(Context context, boolean useNightMode) {
    synchronized (PPApplication.applicationPreferencesMutex) {
        if (applicationTheme == null)
            applicationTheme(context);
        String _applicationTheme = applicationTheme;
        if (_applicationTheme.equals("light") ||
                _applicationTheme.equals("material") ||
                _applicationTheme.equals("color") ||
                _applicationTheme.equals("dlight")) {
            String defaultValue = "white";
            if (Build.VERSION.SDK_INT >= 28)
                defaultValue = "night_mode";
            _applicationTheme = defaultValue;
            SharedPreferences.Editor editor = ApplicationPreferences.getSharedPreferences(context).edit();
            editor.putString(ApplicationPreferences.PREF_APPLICATION_THEME, _applicationTheme);
            editor.apply();
            applicationTheme = _applicationTheme;
        }
        if (_applicationTheme.equals("night_mode") && useNightMode) {
            int nightModeFlags =
                    context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
            switch (nightModeFlags) {
                case Configuration.UI_MODE_NIGHT_YES:
                    _applicationTheme = "dark";
                    break;
                case Configuration.UI_MODE_NIGHT_NO:
                case Configuration.UI_MODE_NIGHT_UNDEFINED:
                    _applicationTheme = "white";
                    break;
            }
        }
        return _applicationTheme;
    }
}
 
Example 8
Source File: FragmentTracklist.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_tracklist, container, false);

    TVTracklistEmpty    = view.findViewById(R.id.id_textView_TracklistEmpty);
    recyclerView        = view.findViewById(R.id.my_recycler_view);

    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.getItemAnimator().setChangeDuration(0);
    adapter = new TrackAdapter(data);

    switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
        case Configuration.UI_MODE_NIGHT_NO:
            // Night mode is not active, we're in day time
            adapter.isLightTheme = true;
            break;
        case Configuration.UI_MODE_NIGHT_YES:
            // Night mode is active, we're at night!
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            // We don't know what mode we're in, assume notnight
            adapter.isLightTheme = false;
            break;
    }

    recyclerView.setAdapter(adapter);

    return view;
}
 
Example 9
Source File: FragmentSingleIllust.java    From Pixiv-Shaft with MIT License 4 votes vote down vote up
private void loadImage() {
    int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            Glide.with(mContext)
                    .load(GlideUtil.getSquare(illust))
                    .apply(bitmapTransform(new BlurTransformation(25, 3)))
                    .transition(withCrossFade())
                    .into(baseBind.bgImage);
            break;
        case Configuration.UI_MODE_NIGHT_YES:
            baseBind.bgImage.setImageResource(R.color.black);
            break;
    }


    mDetailAdapter = new IllustDetailAdapter(illust, mActivity);
    mDetailAdapter.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(View v, int position, int viewType) {
            if (viewType == 0) {
                Intent intent = new Intent(mContext, ImageDetailActivity.class);
                intent.putExtra("illust", illust);
                intent.putExtra("dataType", "二级详情");
                intent.putExtra("index", position);
                if (Shaft.sSettings.isFirstImageSize()) {
                    mActivity.startActivity(intent);
                } else {
                    if (mDetailAdapter.getHasLoad().get(position)) {
                        Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity,
                                v, "big_image_" + position).toBundle();
                        startActivity(intent, bundle);
                    } else {
                        mActivity.startActivity(intent);
                    }
                }
            } else if (viewType == 1) {

            }
        }
    });
    baseBind.recyclerView.setAdapter(mDetailAdapter);
}