diff options
Diffstat (limited to 'src/com/android/settings/DisplaySettings.java')
-rw-r--r-- | src/com/android/settings/DisplaySettings.java | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 622d77e..e7e1ea6 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -20,10 +20,16 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; import android.app.ActivityManagerNative; import android.app.admin.DevicePolicyManager; +import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; +import android.hardware.display.DisplayManager; +import android.hardware.display.WifiDisplay; +import android.hardware.display.WifiDisplayStatus; import android.os.Bundle; import android.os.RemoteException; import android.preference.CheckBoxPreference; @@ -51,6 +57,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final String KEY_FONT_SIZE = "font_size"; private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; private static final String KEY_SCREEN_SAVER = "screensaver"; + private static final String KEY_WIFI_DISPLAY = "wifi_display"; + + private DisplayManager mDisplayManager; private CheckBoxPreference mAccelerometer; private ListPreference mFontSizePref; @@ -61,6 +70,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private ListPreference mScreenTimeoutPreference; private Preference mScreenSaverPreference; + private WifiDisplayStatus mWifiDisplayStatus; + private Preference mWifiDisplayPreference; + private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() { @Override @@ -116,6 +128,15 @@ public class DisplaySettings extends SettingsPreferenceFragment implements } } + 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; + } } private void updateTimeoutPreferenceDescription(long currentTimeout) { @@ -211,10 +232,16 @@ public class DisplaySettings extends SettingsPreferenceFragment implements public void onResume() { super.onResume(); - updateState(); - RotationPolicy.registerRotationPolicyListener(getActivity(), mRotationPolicyListener); + + if (mWifiDisplayPreference != null) { + getActivity().registerReceiver(mReceiver, new IntentFilter( + DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)); + mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus(); + } + + updateState(); } @Override @@ -223,12 +250,17 @@ public class DisplaySettings extends SettingsPreferenceFragment implements RotationPolicy.unregisterRotationPolicyListener(getActivity(), mRotationPolicyListener); + + if (mWifiDisplayPreference != null) { + getActivity().unregisterReceiver(mReceiver); + } } private void updateState() { updateAccelerometerRotationCheckbox(); readFontSizePreference(mFontSizePref); updateScreenSaverSummary(); + updateWifiDisplaySummary(); } private void updateScreenSaverSummary() { @@ -239,6 +271,23 @@ public class DisplaySettings extends SettingsPreferenceFragment implements mScreenSaverPreference.setSummary(""); } + private void updateWifiDisplaySummary() { + if (mWifiDisplayPreference != null) { + switch (mWifiDisplayStatus.getFeatureState()) { + case WifiDisplayStatus.FEATURE_STATE_OFF: + mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_off); + break; + case WifiDisplayStatus.FEATURE_STATE_ON: + mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_on); + break; + case WifiDisplayStatus.FEATURE_STATE_DISABLED: + default: + mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_disabled); + break; + } + } + } + private void updateAccelerometerRotationCheckbox() { if (getActivity() == null) return; @@ -285,4 +334,15 @@ public class DisplaySettings extends SettingsPreferenceFragment implements return true; } + + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)) { + mWifiDisplayStatus = (WifiDisplayStatus)intent.getParcelableExtra( + DisplayManager.EXTRA_WIFI_DISPLAY_STATUS); + updateWifiDisplaySummary(); + } + } + }; } |