settings: Change unmount button to a mount/unmount toggle

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat
2010-01-06 21:41:47 -08:00
parent eea480c796
commit 35351faed3
3 changed files with 46 additions and 10 deletions

View File

@@ -1169,6 +1169,14 @@
<string name="sd_eject">Unmount SD card</string> <string name="sd_eject">Unmount SD card</string>
<!-- SD card & phone storage settings item title that will result in the phone unmounting the SD card. This will be done before the user phyiscally removes the SD card from the phone. Kind of like the "Safely remove" on some operating systems. --> <!-- SD card & phone storage settings item title that will result in the phone unmounting the SD card. This will be done before the user phyiscally removes the SD card from the phone. Kind of like the "Safely remove" on some operating systems. -->
<string name="sd_eject_summary">Unmount the SD card for safe removal</string> <string name="sd_eject_summary">Unmount the SD card for safe removal</string>
<!-- SD card & phone storage settings item summary that is displayed when no SD card is inserted -->
<string name="sd_insert_summary">Insert an SD card for mounting</string>
<!-- SD card & phone storage settings item title that will result in the phone mounting the SD card. -->
<string name="sd_mount">Mount SD card</string>
<!-- SD card & phone storage settings item title that will result in the phone mounting the SD card. -->
<string name="sd_mount_summary">Mount the SD card</string>
<!-- SD card & phone storage settings item title that will result in the phone formatting the SD card. --> <!-- SD card & phone storage settings item title that will result in the phone formatting the SD card. -->
<string name="sd_format">Format SD card</string> <string name="sd_format">Format SD card</string>
<!-- SD card & phone storage settings item title that will result in the phone unmounting the SD card. --> <!-- SD card & phone storage settings item title that will result in the phone unmounting the SD card. -->

View File

@@ -25,7 +25,7 @@
style="?android:attr/preferenceInformationStyle" style="?android:attr/preferenceInformationStyle"
android:title="@string/memory_available" android:title="@string/memory_available"
android:summary="00"/> android:summary="00"/>
<Preference android:key="memory_sd_unmount" <Preference android:key="memory_sd_mount_toggle"
android:title="@string/sd_eject" android:title="@string/sd_eject"
android:summary="@string/sd_eject_summary"/> android:summary="@string/sd_eject_summary"/>
<Preference android:key="memory_sd_format" <Preference android:key="memory_sd_format"

View File

@@ -47,14 +47,14 @@ public class Memory extends PreferenceActivity {
private static final String MEMORY_SD_AVAIL = "memory_sd_avail"; private static final String MEMORY_SD_AVAIL = "memory_sd_avail";
private static final String MEMORY_SD_UNMOUNT = "memory_sd_unmount"; private static final String MEMORY_SD_MOUNT_TOGGLE = "memory_sd_mount_toggle";
private static final String MEMORY_SD_FORMAT = "memory_sd_format"; private static final String MEMORY_SD_FORMAT = "memory_sd_format";
private Resources mRes; private Resources mRes;
private Preference mSdSize; private Preference mSdSize;
private Preference mSdAvail; private Preference mSdAvail;
private Preference mSdUnmount; private Preference mSdMountToggle;
private Preference mSdFormat; private Preference mSdFormat;
// Access using getMountService() // Access using getMountService()
@@ -69,7 +69,7 @@ public class Memory extends PreferenceActivity {
mRes = getResources(); mRes = getResources();
mSdSize = findPreference(MEMORY_SD_SIZE); mSdSize = findPreference(MEMORY_SD_SIZE);
mSdAvail = findPreference(MEMORY_SD_AVAIL); mSdAvail = findPreference(MEMORY_SD_AVAIL);
mSdUnmount = findPreference(MEMORY_SD_UNMOUNT); mSdMountToggle = findPreference(MEMORY_SD_MOUNT_TOGGLE);
mSdFormat = findPreference(MEMORY_SD_FORMAT); mSdFormat = findPreference(MEMORY_SD_FORMAT);
} }
@@ -112,8 +112,13 @@ public class Memory extends PreferenceActivity {
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mSdUnmount) { if (preference == mSdMountToggle) {
unmount(); String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
unmount();
} else {
mount();
}
return true; return true;
} else if (preference == mSdFormat) { } else if (preference == mSdFormat) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -146,6 +151,20 @@ public class Memory extends PreferenceActivity {
} }
} }
private void mount() {
IMountService mountService = getMountService();
try {
if (mountService != null) {
mountService.mountMedia(Environment.getExternalStorageDirectory().toString());
} else {
Log.e(TAG, "Mount service is null, can't mount");
}
} catch (RemoteException ex) {
// Failed for some reason, try to update UI to actual state
updateMemoryStatus();
}
}
private void updateMemoryStatus() { private void updateMemoryStatus() {
String status = Environment.getExternalStorageState(); String status = Environment.getExternalStorageState();
String readOnly = ""; String readOnly = "";
@@ -166,7 +185,11 @@ public class Memory extends PreferenceActivity {
mSdSize.setSummary(formatSize(totalBlocks * blockSize)); mSdSize.setSummary(formatSize(totalBlocks * blockSize));
mSdAvail.setSummary(formatSize(availableBlocks * blockSize) + readOnly); mSdAvail.setSummary(formatSize(availableBlocks * blockSize) + readOnly);
mSdUnmount.setEnabled(true);
mSdMountToggle.setEnabled(true);
mSdMountToggle.setTitle(mRes.getString(R.string.sd_eject));
mSdMountToggle.setSummary(mRes.getString(R.string.sd_eject_summary));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// this can occur if the SD card is removed, but we haven't received the // this can occur if the SD card is removed, but we haven't received the
// ACTION_MEDIA_REMOVED Intent yet. // ACTION_MEDIA_REMOVED Intent yet.
@@ -176,15 +199,20 @@ public class Memory extends PreferenceActivity {
} else { } else {
mSdSize.setSummary(mRes.getString(R.string.sd_unavailable)); mSdSize.setSummary(mRes.getString(R.string.sd_unavailable));
mSdAvail.setSummary(mRes.getString(R.string.sd_unavailable)); mSdAvail.setSummary(mRes.getString(R.string.sd_unavailable));
mSdUnmount.setEnabled(false);
if (status.equals(Environment.MEDIA_UNMOUNTED) || if (status.equals(Environment.MEDIA_UNMOUNTED) ||
status.equals(Environment.MEDIA_NOFS) || status.equals(Environment.MEDIA_NOFS) ||
status.equals(Environment.MEDIA_UNMOUNTABLE) ) { status.equals(Environment.MEDIA_UNMOUNTABLE) ) {
mSdFormat.setEnabled(true); mSdFormat.setEnabled(true);
mSdMountToggle.setEnabled(true);
mSdMountToggle.setTitle(mRes.getString(R.string.sd_mount));
mSdMountToggle.setSummary(mRes.getString(R.string.sd_mount_summary));
} else {
mSdMountToggle.setEnabled(false);
mSdMountToggle.setTitle(mRes.getString(R.string.sd_mount));
mSdMountToggle.setSummary(mRes.getString(R.string.sd_insert_summary));
} }
} }
File path = Environment.getDataDirectory(); File path = Environment.getDataDirectory();