@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(); } } }
/** * 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 ""; } }
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; } }
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; } }); }
@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; } }
@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(); } } }
@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(); }
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); }
@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(); }
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); } }
@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(); }
@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); }
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; }
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; } }
@Override public void onCreate() { super.onCreate(); UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE); uiManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO); }
/** * Returns true when running Android Auto or a car dock. * * A preferable way of detecting if your app is running in the context of an Android Auto * compatible car is by registering a BroadcastReceiver for the action * {@link CarHelper#ACTION_MEDIA_STATUS}. * * @param c Context to detect UI Mode. * @return true when device is running in car mode, false otherwise. */ public static boolean isCarUiMode(Context c) { UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) { LOG.d("Running in Car mode"); return true; } else { LOG.d("Running on a non-Car mode"); return false; } }
@Override protected void onResume() { Log.d(ViboraApp.TAG, "onResume"); ViboraApp.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", ViboraApp.Config.DEFAULT_NIGHT_START); int stopH = mPreferences.getInt("nightmode_use_stop", ViboraApp.Config.DEFAULT_NIGHT_STOP); if (ViboraApp.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) { umm.setNightMode(UiModeManager.MODE_NIGHT_YES); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } if (!ViboraApp.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(); }
private static boolean shouldServiceRun() { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return false; final boolean result = (DexCollectionType.hasXbridgeWixel() || DexCollectionType.hasBtWixel()) && ((!Home.get_forced_wear() && (((UiModeManager) xdrip.getAppContext().getSystemService(UI_MODE_SERVICE)).getCurrentModeType() != Configuration.UI_MODE_TYPE_WATCH)) || PersistentStore.getBoolean(CollectionServiceStarter.pref_run_wear_collector)); if (d) Log.d(TAG, "shouldServiceRun() returning: " + result); return result; }
public static SubjectFactory<UiModeManagerSubject, UiModeManager> type() { return new SubjectFactory<UiModeManagerSubject, UiModeManager>() { @Override public UiModeManagerSubject getSubject(FailureStrategy fs, UiModeManager that) { return new UiModeManagerSubject(fs, that); } }; }
@Override protected void onCreate(Bundle bundle) { UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); PackageManager pm = getPackageManager(); if(!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) { touchscreen = false; } setUncaughtExceptionHandler(); applyTheme(); applyFullscreen(); super.onCreate(bundle); startService(new Intent(this, DownloadService.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) { lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0); } if(preferencesListener == null) { Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener); } if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{ permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }
@Override public void switchNightMode(boolean isNight) { UiModeManager mUiModeManager = (UiModeManager) MyApplication.getContext().getSystemService(Context.UI_MODE_SERVICE); mUiModeManager.setNightMode(isNight == true ? UiModeManager.MODE_NIGHT_YES : UiModeManager.MODE_NIGHT_NO); SPutils.put(MyApplication.getContext(),"NigthMode",isNight); getView().showNightModeSwitchState(isNight); }
/** * Determines if the current device is a TV. * * @param context The context to use for determining the device information * @return True if the current device is a TV */ public boolean isDeviceTV(Context context) { //Since Android TV is only API 21+ that is the only time we will compare configurations if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UiModeManager uiManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE); return uiManager != null && uiManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; } return false; }
public static boolean isAndroidTv() { try { if (sIsAndroidTv == null) { FinskyApp localFinskyApp = FinskyApp.get(); boolean bool2 = localFinskyApp.getPackageManager().hasSystemFeature("android.software.leanback"); boolean bool3 = false; if (bool2) { UiModeManager localUiModeManager = (UiModeManager)localFinskyApp.getSystemService("uimode"); bool3 = false; if (localUiModeManager != null) { int i = localUiModeManager.getCurrentModeType(); bool3 = false; if (i == 4) { bool3 = true; } } } sIsAndroidTv = Boolean.valueOf(bool3); } boolean bool1 = sIsAndroidTv.booleanValue(); return bool1; } finally {} }
/** * 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 boolean isTvUiMode(Context c) { UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { LogHelper.d(TAG, "Running in TV mode"); return true; } else { LogHelper.d(TAG, "Running on a non-TV mode"); return false; } }
public static boolean isContextTelevision(Context context) { if (context == null) { return false; } UiModeManager modeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE); return modeManager != null && modeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; }
public static int getUIMode(Context context) { if (Build.VERSION.SDK_INT >= 8) { UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE); return uiModeManager.getCurrentModeType(); } else { return 0; } }
public AutoDemoNotificationManager(Context context) { mContext = context; mNotificationManagerCompat = NotificationManagerCompat.from(mContext); mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotifications = new ArrayList<Notification>(); mSummarizedMessages = new ArrayList<String>(); mUiModeManager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE); }
/** * Returns true when running Android Auto or a car dock. * * @param c Context to detect UI Mode. * @return true when device is running in car mode, false otherwise. */ public static boolean isCarUiMode(Context c) { UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) { LogHelper.d(TAG, "Running in Car mode"); return true; } else { LogHelper.d(TAG, "Running on a non-Car mode"); return false; } }
/** * Default Constructor. */ public CapabilitiesDelegate() { super(); Context context = (Context) AppRegistryBridge.getInstance().getPlatformContext().getContext(); UiModeManager uiModeManager = (UiModeManager) context.getSystemService(context.UI_MODE_SERVICE); tv = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; pm = context.getPackageManager(); }