diff options
author | Mike Lockwood <lockwood@android.com> | 2011-07-18 10:59:10 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-07-18 15:58:46 -0700 |
commit | 6d11dc5c8c98d0a93e23d48774e863df17da01ca (patch) | |
tree | 8999e6b34d924604707261c1db32e163c6dcc29f | |
parent | ae2f9979ca1b376fb9af908cffae84ddfb80b095 (diff) | |
download | packages_apps_settings-6d11dc5c8c98d0a93e23d48774e863df17da01ca.zip packages_apps_settings-6d11dc5c8c98d0a93e23d48774e863df17da01ca.tar.gz packages_apps_settings-6d11dc5c8c98d0a93e23d48774e863df17da01ca.tar.bz2 |
USB: Toggle installer CD menu title when installer CD is enabled/disabled
Bug: 5032789
Change-Id: I0710133b2318147c7556e9f970f4443511ee1729
Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/settings/deviceinfo/UsbSettings.java | 53 |
2 files changed, 43 insertions, 14 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index f573181..e10d8f7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1769,7 +1769,9 @@ <!-- Storage setting. Label for PTP setting [CHAR LIMIT=30]--> <string name="usb_label_ptp">Connect as a camera (PTP)</string> <!-- Storage setting. Label for installer CD [CHAR LIMIT=30]--> - <string name="usb_label_installer_cd">Install file transfer tools</string> + <string name="usb_label_installer_cd">Install Android File Transfer application for Mac</string> + <!-- Storage setting. Label for installer CD [CHAR LIMIT=30]--> + <string name="usb_label_installer_cd_done">Done installing Android File Transfer application for Mac</string> <!-- Phone info screen, section titles: --> <string name="battery_status_title">Battery status</string> diff --git a/src/com/android/settings/deviceinfo/UsbSettings.java b/src/com/android/settings/deviceinfo/UsbSettings.java index 5da13af..ca6a0cc 100644 --- a/src/com/android/settings/deviceinfo/UsbSettings.java +++ b/src/com/android/settings/deviceinfo/UsbSettings.java @@ -16,9 +16,12 @@ package com.android.settings.deviceinfo; +import android.content.BroadcastReceiver; import android.content.ContentQueryMap; import android.content.ContentResolver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.hardware.usb.UsbManager; import android.os.Bundle; import android.os.storage.StorageManager; @@ -53,6 +56,13 @@ public class UsbSettings extends SettingsPreferenceFragment { private String mInstallerImagePath; private CheckBoxPreference mMtp; private CheckBoxPreference mPtp; + private MenuItem mInstallerCd; + + private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() { + public void onReceive(Context content, Intent intent) { + updateToggles(); + } + }; private PreferenceScreen createPreferenceHierarchy() { PreferenceScreen root = getPreferenceScreen(); @@ -80,13 +90,22 @@ public class UsbSettings extends SettingsPreferenceFragment { } @Override + public void onPause() { + super.onPause(); + getActivity().unregisterReceiver(mStateReceiver); + } + + @Override public void onResume() { super.onResume(); // Make sure we reload the preference hierarchy since some of these settings // depend on others... createPreferenceHierarchy(); - updateToggles(); + + // ACTION_USB_STATE is sticky so this will call updateToggles + getActivity().registerReceiver(mStateReceiver, + new IntentFilter(UsbManager.ACTION_USB_STATE)); } private void updateToggles() { @@ -100,6 +119,13 @@ public class UsbSettings extends SettingsPreferenceFragment { mMtp.setChecked(false); mPtp.setChecked(false); } + if (mInstallerCd != null) { + if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MASS_STORAGE)) { + mInstallerCd.setTitle( R.string.usb_label_installer_cd_done); + } else { + mInstallerCd.setTitle( R.string.usb_label_installer_cd); + } + } } @Override @@ -115,34 +141,35 @@ public class UsbSettings extends SettingsPreferenceFragment { return true; } } - if (preference == mMtp) { mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true); - mPtp.setChecked(false); } else if (preference == mPtp) { mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true); - mMtp.setChecked(false); } - + updateToggles(); return true; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - menu.add(Menu.NONE, MENU_ID_INSTALLER_CD, 0, R.string.usb_label_installer_cd) - //.setIcon(com.android.internal.R.drawable.stat_sys_data_usb) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + mInstallerCd = menu.add(Menu.NONE, MENU_ID_INSTALLER_CD, 0, + R.string.usb_label_installer_cd); + mInstallerCd.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_ID_INSTALLER_CD: - // installer CD is never default - mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MASS_STORAGE, false); - mUsbManager.setMassStorageBackingFile(mInstallerImagePath); - mMtp.setChecked(false); - mPtp.setChecked(false); + if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MASS_STORAGE)) { + // Disable installer CD, return to default function. + mUsbManager.setCurrentFunction(null, false); + } else { + // Enable installer CD. Don't set as default function. + mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MASS_STORAGE, false); + mUsbManager.setMassStorageBackingFile(mInstallerImagePath); + } + updateToggles(); return true; } return super.onOptionsItemSelected(item); |