Java 类android.app.UiModeManager 实例源码

项目:AnotherRSS    文件:MyPreferenceFragment.java   
@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();
        }
    }
}
项目:easyfilemanager    文件:Utils.java   
/**
 * 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 "";
    }
}
项目:FireFiles    文件:Utils.java   
/**
 * 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 "";
    }
}
项目:boohee_v5.6    文件:AppCompatDelegateImplV14.java   
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;
    }
}
项目:simple-share-android    文件:Utils.java   
/**
 * 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 "";
    }
}
项目:BigNews    文件:SettingsActivity.java   
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;
        }
    });
}
项目:permissionsModule    文件:AppCompatDelegateImplV14.java   
@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;
    }
}
项目:ViboraFeed    文件:MyPreferenceFragment.java   
@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();
        }
    }
}
项目:MrinalMusicPlayer    文件:NowPlayingActivity.java   
@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();
}
项目:soundscape-livewallpaper    文件:MainWallpaperService.java   
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);
        }
项目:MyGaana-Universal    文件:NowPlayingActivity.java   
@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();
}
项目:android-UniversalMusicPlayer    文件:NowPlayingActivity.java   
@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();
}
项目:torrenttunes-android    文件:NowPlayingActivity.java   
@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();
}
项目:UniversalMusicPlayer    文件:NowPlayingActivity.java   
@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();
}
项目:MusicFromChina    文件:NowPlayingActivity.java   
@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();
}
项目:UniversalAndroidMusicPlayer    文件:NowPlayingActivity.java   
@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();
}
项目:moonlight-android    文件:UiHelper.java   
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);
    }
}
项目:AnotherRSS    文件:MainActivity.java   
@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();
}
项目:BigNews    文件:BaseActivity.java   
@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);
}
项目:NeoTerm    文件:MainActivity.java   
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;
}
项目:flappy    文件:TlappyActivity.java   
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;
    }
}
项目:zonebeacon    文件:ZoneBeaconApplication.java   
@Override
public void onCreate() {
    super.onCreate();

    UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    uiManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
}
项目:nuclei-android    文件:CarHelper.java   
/**
 * 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;
    }
}
项目:ViboraFeed    文件:MainActivity.java   
@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();
}
项目:xDrip    文件:DexCollectionService.java   
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;
}
项目:xDrip    文件:DexCollectionService.java   
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;
}
项目:xDrip-plus    文件:DexCollectionService.java   
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;
}
项目:xDrip-plus    文件:DexCollectionService.java   
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;
}
项目:truth-android    文件:UiModeManagerSubject.java   
public static SubjectFactory<UiModeManagerSubject, UiModeManager> type() {
  return new SubjectFactory<UiModeManagerSubject, UiModeManager>() {
    @Override
    public UiModeManagerSubject getSubject(FailureStrategy fs, UiModeManager that) {
      return new UiModeManagerSubject(fs, that);
    }
  };
}
项目:Audinaut    文件:SubsonicActivity.java   
@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);
    }
}
项目:lovelife    文件:UserCenterPresenter.java   
@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);
}
项目:luxunPro    文件:DeviceUtil.java   
/**
 * 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;
}
项目:FMTech    文件:UiUtils.java   
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 {}
}
项目:android-UniversalMusicPlayer    文件:TvHelper.java   
/**
 * 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;
    }
}
项目:talkback    文件:TelevisionNavigationController.java   
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;
}
项目:ExoMedia    文件:DeviceUtil.java   
/**
 * 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;
}
项目:learnforandroidfragAS    文件:lib.java   
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;
    }
}
项目:android-auto-messaging-demo    文件:AutoDemoNotificationManager.java   
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);

    }
项目:UniversalAndroidMusicPlayer    文件:CarHelper.java   
/**
 * 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;
    }
}
项目:adaptive-arp-android    文件:CapabilitiesDelegate.java   
/**
 * 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();
}