android.content.res.Configuration#UI_MODE_NIGHT_NO源码实例Demo

下面列出了android.content.res.Configuration#UI_MODE_NIGHT_NO 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
源代码2 项目: linphone-android   文件: ThemeableActivity.java
@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);
            }
    }
}
 
源代码3 项目: AsteroidOSSync   文件: MainActivity.java
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    getDelegate().onConfigurationChanged(newConfig);
    int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            break;
        case Configuration.UI_MODE_NIGHT_YES:
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            break;
    }

    finish();
    overridePendingTransition(0, 0);
    startActivity(getIntent());
}
 
源代码4 项目: Taskbar   文件: U.java
private static String getCurrentTheme(Context context) {
    String defaultTheme = context.getString(R.string.tb_pref_theme_default);

    SharedPreferences pref = getSharedPreferences(context);
    String themePref = pref.getString(PREF_THEME, defaultTheme);

    if(themePref.equals("system")) {
        Configuration configuration = context.getResources().getConfiguration();
        int currentNightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch(currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
                // Night mode is not active, we're using the light theme
                return "light";
            case Configuration.UI_MODE_NIGHT_YES:
                // Night mode is active, we're using dark theme
                return "dark";
        }
    } else
        return themePref;

    return defaultTheme;
}
 
源代码5 项目: SkinSprite   文件: MainActivity.java
@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
        }
    }
}
 
源代码6 项目: Markdown   文件: MainActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() != 0x1
            && item.getItemId() != 0x2) {
        setText(item.getItemId());
        return true;
    } else if (item.getItemId() == 0x1) {
        getResources().getConfiguration().uiMode |= Configuration.UI_MODE_NIGHT_YES;
        getResources().getConfiguration().uiMode &= ~Configuration.UI_MODE_NIGHT_NO;
        getResources().updateConfiguration(getResources().getConfiguration(), getResources().getDisplayMetrics());
        recreate();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}
 
源代码7 项目: CommonUtils   文件: CommonUtils.java
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;
    }
}
 
源代码8 项目: call_manage   文件: ThemeUtils.java
/**
 * Check if night mode is on by system
 * @param context
 * @return is on / not
 */
public static boolean isNightModeOn(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
            // Night mode is not active, we're using the light theme
            return false;
        case Configuration.UI_MODE_NIGHT_YES:
            // Night mode is active, we're using dark theme
            return true;
        default:
            return false;
    }
}
 
源代码9 项目: timecat   文件: 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);
    }
    return resource;
}
 
源代码10 项目: MaoWanAndoidClient   文件: SettingsFragment.java
private void ChangeThemeMode() {
    int mode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    if(mode == Configuration.UI_MODE_NIGHT_YES) {
        RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_NO));
    } else if(mode == Configuration.UI_MODE_NIGHT_NO) {
        RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_YES));
    }else {
        //否则保持亮色主题
        RxBus.getDefault().post(new ThemeModeEvent(AppCompatDelegate.MODE_NIGHT_NO));
    }
}
 
源代码11 项目: Aegis   文件: AuthActivity.java
@Override
protected void setPreferredTheme(Theme theme) {
    if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
        // set the theme based on the system theme
        int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
                theme = Theme.LIGHT;
                break;
            case Configuration.UI_MODE_NIGHT_YES:
                theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
                break;
        }
    }

    switch (theme) {
        case LIGHT:
            setTheme(R.style.AppTheme_Light_NoActionBar);
            break;
        case DARK:
            setTheme(R.style.AppTheme_Dark_NoActionBar);
            break;
        case AMOLED:
            setTheme(R.style.AppTheme_TrueBlack_NoActionBar);
            break;
    }
}
 
源代码12 项目: Aegis   文件: AegisActivity.java
protected void setPreferredTheme(Theme theme) {
    if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
        // set the theme based on the system theme
        int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
                theme = Theme.LIGHT;
                break;
            case Configuration.UI_MODE_NIGHT_YES:
                theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
                break;
        }
    }

    _currentTheme = theme;

    switch (theme) {
        case LIGHT:
            setTheme(R.style.AppTheme);
            break;
        case DARK:
            setTheme(R.style.AppTheme_Dark);
            break;
        case AMOLED:
            setTheme(R.style.AppTheme_TrueBlack);
            break;
    }
}
 
源代码13 项目: zephyr   文件: ThemeManager.java
@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;
    }
}
 
源代码14 项目: MagicaSakura   文件: 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);
    }
    return resource;
}
 
源代码15 项目: GankGirl   文件: MainActivity.java
@Override
protected void onResume() {
    super.onResume();
    int uiMode = getResources().getConfiguration().uiMode;
    int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK;
    if (dayNightUiMode == Configuration.UI_MODE_NIGHT_NO) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    } else if (dayNightUiMode == Configuration.UI_MODE_NIGHT_YES) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
    }
}
 
源代码16 项目: Pix-Art-Messenger   文件: ThemeHelper.java
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;
    }
}
 
源代码17 项目: GPSLogger   文件: FragmentTracklist.java
@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;
}
 
源代码18 项目: OneText_For_Android   文件: BaseActivity.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sharedPreferences = getSharedPreferences("setting", MODE_PRIVATE);
    editor = sharedPreferences.edit();
    //Q导航栏沉浸
    rootview = findViewById(android.R.id.content);

    /*ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView(), new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            v.setPadding(0,0,0,insets.getSystemWindowInsetBottom());
            return insets;
        }
    });*/
    //状态栏icon黑色
    int mode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    if (mode == Configuration.UI_MODE_NIGHT_NO) {
        this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
    }
    rootview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    ViewCompat.setOnApplyWindowInsetsListener(rootview, new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            rootview.setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(), 0);
            return insets;
        }
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        //rootView.setFitsSystemWindows(true);
        //rootView.setPadding(0,0,0,getNavigationBarHeight());
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    //rootView.setFitsSystemWindows(true);
    /*if ((Build.VERSION.SDK_INT<Build.VERSION_CODES.Q)|(getNavigationBarHeight()>dp2px(16))) {
        //rootView.setPadding(0,0,0,getNavigationBarHeight());
        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
            //rootView.setFitsSystemWindows(true);
            rootView.setPadding(0,0,0,getNavigationBarHeight());
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }else {
            //rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            //rootView.setFitsSystemWindows(true);
        }
    }else {
        rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }*/
    //设置为miui主题
    //setMiuiTheme(BaseActivity.this,0,mode);
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    //全局自定义字体
    ViewPump.init(ViewPump.builder()
            .addInterceptor(new CalligraphyInterceptor(
                    new CalligraphyConfig.Builder()
                            .setDefaultFontPath(sharedPreferences.getString("font_path", null))
                            .setFontAttrId(R.attr.fontPath)
                            .build()))
            .build());
}
 
源代码19 项目: Pixiv-Shaft   文件: FragmentSingleIllust.java
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);
}
 
源代码20 项目: mage-android   文件: ProfileActivity.java
@Override
public void onMapReady(GoogleMap map) {
	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
	map.setMapType(preferences.getInt(getString(R.string.baseLayerKey), getResources().getInteger(R.integer.baseLayerDefaultValue)));

	int dayNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
	if (dayNightMode == Configuration.UI_MODE_NIGHT_NO) {
		map.setMapStyle(null);
	} else {
		map.setMapStyle(MapStyleOptions.loadRawResourceStyle(getApplicationContext(), R.raw.map_theme_night));
	}


	if (latLng != null && icon != null) {
		map.addMarker(new MarkerOptions()
			.position(latLng)
			.icon(icon));

		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null) {
			float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());

			int color = LocationBitmapFactory.locationColor(getApplicationContext(), location);
			map.addCircle(new CircleOptions()
				.center(latLng)
				.radius(accuracy)
				.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
				.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
				.strokeWidth(2.0f));

			double latitudePadding = (accuracy / 111325);
			LatLngBounds bounds = new LatLngBounds(
					new LatLng(latLng.latitude - latitudePadding, latLng.longitude),
					new LatLng(latLng.latitude + latitudePadding, latLng.longitude));

			int minDimension = Math.min(mapView.getWidth(), mapView.getHeight());
			int padding = (int) Math.floor(minDimension / 5f);
			map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
		} else {
			map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
		}
	}
}