@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver resolver = getActivity().getContentResolver();

    addPreferencesFromResource(R.xml.display_settings);

    mDisplayRotationPreference = (PreferenceScreen) findPreference(KEY_DISPLAY_ROTATION);

    mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
    if (mScreenSaverPreference != null
        && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) {
      getPreferenceScreen().removePreference(mScreenSaverPreference);
    }

    mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT);
    final long currentTimeout =
        Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
    mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
    mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
    disableUnusableTimeouts(mScreenTimeoutPreference);
    updateTimeoutPreferenceDescription(currentTimeout);
    updateDisplayRotationPreferenceDescription();

    mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE);
    mFontSizePref.setOnPreferenceChangeListener(this);
    mFontSizePref.setOnPreferenceClickListener(this);

    mDisplayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE);
    mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
    mWifiDisplayPreference = (Preference) findPreference(KEY_WIFI_DISPLAY);
    if (mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE) {
      getPreferenceScreen().removePreference(mWifiDisplayPreference);
      mWifiDisplayPreference = null;
    }

    mVolumeWake = (CheckBoxPreference) findPreference(KEY_VOLUME_WAKE);
    if (mVolumeWake != null) {
      if (!getResources().getBoolean(R.bool.config_show_volumeRockerWake)) {
        getPreferenceScreen().removePreference(mVolumeWake);
        getPreferenceScreen()
            .removePreference((PreferenceCategory) findPreference(KEY_WAKEUP_CATEGORY));
      } else {
        mVolumeWake.setChecked(
            Settings.System.getInt(resolver, Settings.System.VOLUME_WAKE_SCREEN, 0) == 1);
      }
    }
  }
  @Override
  public void onResume() {
    super.onResume();
    updateDisplayRotationPreferenceDescription();

    RotationPolicy.registerRotationPolicyListener(getActivity(), mRotationPolicyListener);

    // Display rotation observer
    getContentResolver()
        .registerContentObserver(
            Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
            true,
            mAccelerometerRotationObserver);

    if (mWifiDisplayPreference != null) {
      getActivity()
          .registerReceiver(
              mReceiver, new IntentFilter(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED));
      mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
    }

    updateState();
  }
Example #3
0
 public static boolean deviceSupportsWifiDisplay(Context ctx) {
   DisplayManager dm = (DisplayManager) ctx.getSystemService(Context.DISPLAY_SERVICE);
   return (dm.getWifiDisplayStatus().getFeatureState()
       != WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE);
 }