Java Code Examples for androidx.appcompat.app.AppCompatDelegate#getDefaultNightMode()

The following examples show how to use androidx.appcompat.app.AppCompatDelegate#getDefaultNightMode() . 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: DesignActivity.java    From Android-Plugin-Framework with MIT License 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 2
Source File: LinphonePreferences.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
public boolean isDarkModeEnabled() {
    if (getConfig() == null) return false;
    if (!mContext.getResources().getBoolean(R.bool.allow_dark_mode)) return false;

    boolean useNightModeDefault =
            AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES;
    if (mContext != null) {
        int nightMode =
                mContext.getResources().getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK;
        if (nightMode == Configuration.UI_MODE_NIGHT_YES) {
            useNightModeDefault = true;
        }
    }

    return getConfig().getBool("app", "dark_mode", useNightModeDefault);
}
 
Example 3
Source File: ThemedActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeManager helper = ThemeManager.getInstance(this);
    helper.addThemeChangeListener(this);
    mDarkMode = AppCompatDelegate.getDefaultNightMode();
    super.onCreate(savedInstanceState);
}
 
Example 4
Source File: BaseActivity.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
public void switchTheme() {
        if (App.followSystemDarkMode(this)) {
            return;
        }

        //直接夜间 设置退出
        int theme = App.getCustomTheme(this);
        int cur = AppCompatDelegate.getDefaultNightMode();
        int to = cur;
        boolean autoChange = false;

        //夜间主题
        if (theme == ThemeActivity.THEME_NIGHT) {
            to = AppCompatDelegate.MODE_NIGHT_YES;
        } else {//白天主题
            if (App.isAutoDarkMode(this)) {
                autoChange = true;
                int[] time = App.getDarkModeTime(this);
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if ((hour >= time[0] || hour < time[1])) {
                    //自动切换
                    to = AppCompatDelegate.MODE_NIGHT_YES;
                } else {
                    to = AppCompatDelegate.MODE_NIGHT_NO;
                }
            } else {
                to = AppCompatDelegate.MODE_NIGHT_NO;
            }
        }

        if (to == AppCompatDelegate.MODE_NIGHT_YES) {
            //夜间模式主题
            setTheme(R.style.AppTheme);
        } else {
            setTheme(theme);
        }

        //黑白发生了变化
        if (to != cur) {
//            if (autoChnage) {
//                showToast("自动" + (to == AppCompatDelegate.MODE_NIGHT_YES ?
//                        "切换到夜间模式" : "关闭夜间模式"));
//            }
            AppCompatDelegate.setDefaultNightMode(to);
        }
    }
 
Example 5
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("WrongConstant")
@Override
public void onLocationChanged() {
    if (mLocationState == LocationState.SEARCHING) {
        mLocationState = mSavedLocationState;
        //TODO Change from center to location pivot (see zooming)
        mMap.getEventLayer().setFixOnCenter(true);
        updateLocationDrawable();
        mLocationOverlay.setEnabled(true);
        mMap.updateMap(true);
    }

    Location location = mLocationService.getLocation();
    double lat = location.getLatitude();
    double lon = location.getLongitude();
    float bearing = location.getBearing();
    if (bearing < mAveragedBearing - 180f)
        mAveragedBearing -= 360f;
    else if (mAveragedBearing < bearing - 180f)
        mAveragedBearing += 360f;
    mAveragedBearing = (float) movingAverage(bearing, mAveragedBearing);
    if (mAveragedBearing < 0f)
        mAveragedBearing += 360f;
    if (mAveragedBearing >= 360f)
        mAveragedBearing -= 360f;

    updateGauges();

    if (mLocationState == LocationState.NORTH || mLocationState == LocationState.TRACK) {
        long time = SystemClock.uptimeMillis();
        // Adjust map movement animation to location acquisition period to make movement smoother
        long locationDelay = time - mLastLocationMilliseconds;
        double duration = Math.min(1500, locationDelay); // 1.5 seconds maximum
        mMovementAnimationDuration = (int) movingAverage(duration, mMovementAnimationDuration);
        // Update map position
        mMap.getMapPosition(mMapPosition);

        boolean rotate = mLocationState == LocationState.TRACK && mTrackingDelay < time;
        double offset;
        if (rotate) {
            offset = mTrackingOffset / mTrackingOffsetFactor;
            if (mAutoTilt > 0f && !mAutoTiltSet && mAutoTiltShouldSet)
                mMapPosition.setTilt(mAutoTilt);
        } else {
            offset = mMovingOffset;
        }
        offset = offset / (mMapPosition.scale * Tile.SIZE);

        double rad = Math.toRadians(mAveragedBearing);
        double dx = offset * Math.sin(rad);
        double dy = offset * Math.cos(rad);

        if (!mPositionLocked) {
            mMapPosition.setX(MercatorProjection.longitudeToX(lon) + dx);
            mMapPosition.setY(MercatorProjection.latitudeToY(lat) - dy);
            mMapPosition.setBearing(-mAveragedBearing);
            //FIXME VTM
            mMap.animator().animateTo(mMovementAnimationDuration, mMapPosition, rotate);
        }
    }

    mLocationOverlay.setPosition(lat, lon, bearing);
    if (mNavigationLayer != null)
        mNavigationLayer.setPosition(lat, lon);
    mLastLocationMilliseconds = SystemClock.uptimeMillis();

    // TODO: Fix lint error
    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_AUTO)
        checkNightMode(location);

    for (WeakReference<LocationChangeListener> weakRef : mLocationChangeListeners) {
        LocationChangeListener locationChangeListener = weakRef.get();
        if (locationChangeListener != null) {
            locationChangeListener.onLocationChanged(location);
        }
    }
}