本文整理汇总了Java中android.app.UiModeManager类的典型用法代码示例。如果您正苦于以下问题:Java UiModeManager类的具体用法?Java UiModeManager怎么用?Java UiModeManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UiModeManager类属于android.app包,在下文中一共展示了UiModeManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSharedPreferenceChanged
import android.app.UiModeManager; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals("nightmode_use")) {
boolean night = sharedPreferences.getBoolean("nightmode_use", false);
int startH = sharedPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
int stopH = sharedPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
if (night && AnotherRSS.inTimeSpan(startH, stopH)) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
getActivity().recreate();
}
}
}
示例2: getDeviceType
import android.app.UiModeManager; //导入依赖的package包/类
/**
* Returns true when running Android TV
*
* @param c Context to detect UI Mode.
* @return true when device is running in tv mode, false otherwise.
*/
public static String getDeviceType(Context c) {
UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
int modeType = uiModeManager.getCurrentModeType();
switch (modeType){
case Configuration.UI_MODE_TYPE_TELEVISION:
return "TELEVISION";
case Configuration.UI_MODE_TYPE_WATCH:
return "WATCH";
case Configuration.UI_MODE_TYPE_NORMAL:
String type = isTablet(c) ? "TABLET" : "PHONE";
return type;
case Configuration.UI_MODE_TYPE_UNDEFINED:
return "UNKOWN";
default:
return "";
}
}
示例3: mapNightModeToYesNo
import android.app.UiModeManager; //导入依赖的package包/类
private int mapNightModeToYesNo(int mode) {
switch (mode) {
case -1:
switch (((UiModeManager) this.mContext.getSystemService("uimode")).getNightMode()) {
case 0:
return 0;
case 2:
return 2;
default:
return 1;
}
case 0:
if (getTwilightManager().isNight()) {
return 2;
}
return 1;
case 2:
return 2;
default:
return 1;
}
}
示例4: setupNightModeSwitch
import android.app.UiModeManager; //导入依赖的package包/类
private void setupNightModeSwitch() {
// 设置夜间模式
uiManager = (UiModeManager) getActivity().getSystemService(Context.UI_MODE_SERVICE);
nightModeSwitch = (SwitchPreference) getPreferenceManager().findPreference("night_mode_switch");
nightModeSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean nextNightMode = !PreferenceHelper.isNightModeEnabled();
if (nextNightMode) {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
} else {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
}
return true;
}
});
}
示例5: mapNightModeToYesNo
import android.app.UiModeManager; //导入依赖的package包/类
@BinaryNightMode
private int mapNightModeToYesNo(@NightMode final int mode) {
switch (mode) {
case MODE_NIGHT_AUTO:
return getTwilightManager().isNight() ? MODE_NIGHT_YES : MODE_NIGHT_NO;
case MODE_NIGHT_FOLLOW_SYSTEM:
final UiModeManager uiModeManager = (UiModeManager)
mContext.getSystemService(Context.UI_MODE_SERVICE);
switch (uiModeManager.getNightMode()) {
case UiModeManager.MODE_NIGHT_YES:
return MODE_NIGHT_YES;
case UiModeManager.MODE_NIGHT_AUTO:
return MODE_NIGHT_AUTO;
case UiModeManager.MODE_NIGHT_NO:
default:
return MODE_NIGHT_NO;
}
case MODE_NIGHT_YES:
return MODE_NIGHT_YES;
case MODE_NIGHT_NO:
default:
return MODE_NIGHT_NO;
}
}
示例6: onSharedPreferenceChanged
import android.app.UiModeManager; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals("nightmode_use")) {
boolean night = sharedPreferences.getBoolean("nightmode_use", false);
int startH = sharedPreferences.getInt("nightmode_use_start", ViboraApp.Config.DEFAULT_NIGHT_START);
int stopH = sharedPreferences.getInt("nightmode_use_stop", ViboraApp.Config.DEFAULT_NIGHT_STOP);
if (night && ViboraApp.inTimeSpan(startH, stopH)) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
getActivity().recreate();
}
}
}
示例7: onCreate
import android.app.UiModeManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "onCreate");
Intent newIntent;
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
LogHelper.d(TAG, "Running on a TV Device");
newIntent = new Intent(this, TvPlaybackActivity.class);
} else {
LogHelper.d(TAG, "Running on a non-TV Device");
newIntent = new Intent(this, MusicPlayerActivity.class);
}
startActivity(newIntent);
finish();
}
示例8: SoundWaveWallpaperEngine
import android.app.UiModeManager; //导入依赖的package包/类
public SoundWaveWallpaperEngine() {
// Enable automatic NightMode switch
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
Paint wavePaint = new Paint();
wavePaint.setColor(waveColor);
wavePaint.setAlpha(150);
// Define all three waves
wave1 = new Wave(wavePaint, 50, 15, timePerValue);
wave2 = new Wave(wavePaint, 35, 20, timePerValue);
wave3 = new Wave(wavePaint, 25, 25, timePerValue);
handler.post(drawRunner);
}
示例9: onCreate
import android.app.UiModeManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
Intent newIntent;
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device");
// TODO: add launch Android TV "Now Playing" activity
// newIntent = new Intent(this, TvNowPlayingActivity.class);
throw new UnsupportedOperationException("Android TV is not yet supported");
} else {
Log.d(TAG, "Running on a non-TV Device");
newIntent = new Intent(this, MusicPlayerActivity.class);
}
startActivity(newIntent);
finish();
}
示例10: notifyNewRootView
import android.app.UiModeManager; //导入依赖的package包/类
public static void notifyNewRootView(Activity activity)
{
View rootView = activity.findViewById(android.R.id.content);
UiModeManager modeMgr = (UiModeManager) activity.getSystemService(Context.UI_MODE_SERVICE);
if (modeMgr.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION)
{
// Increase view padding on TVs
float scale = activity.getResources().getDisplayMetrics().density;
int verticalPaddingPixels = (int) (TV_VERTICAL_PADDING_DP*scale + 0.5f);
int horizontalPaddingPixels = (int) (TV_HORIZONTAL_PADDING_DP*scale + 0.5f);
rootView.setPadding(horizontalPaddingPixels, verticalPaddingPixels,
horizontalPaddingPixels, verticalPaddingPixels);
}
}
示例11: onResume
import android.app.UiModeManager; //导入依赖的package包/类
@Override
protected void onResume() {
Log.d(AnotherRSS.TAG, "onResume");
AnotherRSS.withGui = true;
new DbExpunge().execute();
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean night = mPreferences.getBoolean("nightmode_use", false);
if (night) {
int startH = mPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
int stopH = mPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
if (AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
if (!AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_NO) {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
} else {
if (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
super.onResume();
}
示例12: onCreate
import android.app.UiModeManager; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// 创建Activity时设置夜间模式
uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
if (PreferenceHelper.isNightModeEnabled()) {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
}
super.onCreate(savedInstanceState);
}
示例13: isRunningOnOUYA
import android.app.UiModeManager; //导入依赖的package包/类
public boolean isRunningOnOUYA() {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo("tv.ouya", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) || Globals.OuyaEmulation;
}
示例14: isAndroidTV
import android.app.UiModeManager; //导入依赖的package包/类
public boolean isAndroidTV() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
} else {
return false;
}
}
示例15: onCreate
import android.app.UiModeManager; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
uiManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
}