Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35351fae authored by San Mehat's avatar San Mehat
Browse files

settings: Change unmount button to a mount/unmount toggle



Signed-off-by: default avatarSan Mehat <san@google.com>
parent eea480c7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1169,6 +1169,14 @@
    <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.   -->
    <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.   -->
    <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.   -->
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
            style="?android:attr/preferenceInformationStyle" 
            android:title="@string/memory_available"
            android:summary="00"/>
        <Preference android:key="memory_sd_unmount"
        <Preference android:key="memory_sd_mount_toggle"
            android:title="@string/sd_eject"
            android:summary="@string/sd_eject_summary"/>
        <Preference android:key="memory_sd_format"
+37 −9
Original line number Diff line number Diff line
@@ -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_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 Resources mRes;

    private Preference mSdSize;
    private Preference mSdAvail;
    private Preference mSdUnmount;
    private Preference mSdMountToggle;
    private Preference mSdFormat;
    
    // Access using getMountService()
@@ -69,7 +69,7 @@ public class Memory extends PreferenceActivity {
        mRes = getResources();
        mSdSize = findPreference(MEMORY_SD_SIZE);
        mSdAvail = findPreference(MEMORY_SD_AVAIL);
        mSdUnmount = findPreference(MEMORY_SD_UNMOUNT);
        mSdMountToggle = findPreference(MEMORY_SD_MOUNT_TOGGLE);
        mSdFormat = findPreference(MEMORY_SD_FORMAT);
    }
    
@@ -112,8 +112,13 @@ public class Memory extends PreferenceActivity {
    
    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        if (preference == mSdUnmount) {
        if (preference == mSdMountToggle) {
            String status = Environment.getExternalStorageState();
            if (status.equals(Environment.MEDIA_MOUNTED)) {
                unmount();
            } else {
                mount();
            }
            return true;
        } else if (preference == mSdFormat) {
            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() {
        String status = Environment.getExternalStorageState();
        String readOnly = "";
@@ -166,7 +185,11 @@ public class Memory extends PreferenceActivity {
                
                mSdSize.setSummary(formatSize(totalBlocks * blockSize));
                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) {
                // this can occur if the SD card is removed, but we haven't received the 
                // ACTION_MEDIA_REMOVED Intent yet.
@@ -176,15 +199,20 @@ public class Memory extends PreferenceActivity {
        } else {
            mSdSize.setSummary(mRes.getString(R.string.sd_unavailable));
            mSdAvail.setSummary(mRes.getString(R.string.sd_unavailable));
            mSdUnmount.setEnabled(false);


            if (status.equals(Environment.MEDIA_UNMOUNTED) ||
                status.equals(Environment.MEDIA_NOFS) ||
                status.equals(Environment.MEDIA_UNMOUNTABLE) ) {
                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();