packages/apps/Settings
リビジョン | 8f1bd8a7526edf49196430be214acb54e66a63ee (tree) |
---|---|
日時 | 2011-06-07 07:48:08 |
作者 | Gilles Debunne <debunne@goog...> |
コミッター | Gilles Debunne |
Bug 4539424: confirmation dialog always shown
Change-Id: Id1e2a52a07255e2c98cbd0e8151a82d7a2612517
@@ -21,7 +21,6 @@ import android.app.Dialog; | ||
21 | 21 | import android.content.BroadcastReceiver; |
22 | 22 | import android.content.Context; |
23 | 23 | import android.content.DialogInterface; |
24 | -import android.content.DialogInterface.OnCancelListener; | |
25 | 24 | import android.content.Intent; |
26 | 25 | import android.content.IntentFilter; |
27 | 26 | import android.content.res.Resources; |
@@ -42,7 +41,7 @@ import android.widget.Toast; | ||
42 | 41 | import com.android.settings.R; |
43 | 42 | import com.android.settings.SettingsPreferenceFragment; |
44 | 43 | |
45 | -public class Memory extends SettingsPreferenceFragment implements OnCancelListener { | |
44 | +public class Memory extends SettingsPreferenceFragment { | |
46 | 45 | private static final String TAG = "MemorySettings"; |
47 | 46 | |
48 | 47 | private static final int DLG_CONFIRM_UNMOUNT = 1; |
@@ -50,9 +49,10 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen | ||
50 | 49 | |
51 | 50 | private Resources mResources; |
52 | 51 | |
53 | - // The mountToggle Preference that has been clicked. | |
54 | - // The click event will be discarded if this value is not null. Reset to null after (un)mount. | |
55 | - private Preference mClickedMountToggle; | |
52 | + // The mountToggle Preference that has last been clicked. | |
53 | + // Assumes no two successive unmount event on 2 different volumes are performed before the first | |
54 | + // one's preference is disabled | |
55 | + private Preference mLastClickedMountToggle; | |
56 | 56 | private String mClickedMountPoint; |
57 | 57 | |
58 | 58 | // Access using getMountService() |
@@ -157,9 +157,8 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen | ||
157 | 157 | return true; |
158 | 158 | } |
159 | 159 | |
160 | - boolean mountToggleClicked = svpc.mountToggleClicked(preference); | |
161 | - if (mountToggleClicked && mClickedMountToggle == null) { | |
162 | - mClickedMountToggle = preference; | |
160 | + if (svpc.mountToggleClicked(preference)) { | |
161 | + mLastClickedMountToggle = preference; | |
163 | 162 | final StorageVolume storageVolume = svpc.getStorageVolume(); |
164 | 163 | mClickedMountPoint = storageVolume.getPath(); |
165 | 164 | String state = mStorageManager.getVolumeState(storageVolume.getPath()); |
@@ -208,32 +207,19 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen | ||
208 | 207 | return null; |
209 | 208 | } |
210 | 209 | |
211 | - @Override | |
212 | - protected void showDialog(int id) { | |
213 | - super.showDialog(id); | |
214 | - | |
215 | - switch (id) { | |
216 | - case DLG_CONFIRM_UNMOUNT: | |
217 | - case DLG_ERROR_UNMOUNT: | |
218 | - setOnCancelListener(this); | |
219 | - break; | |
220 | - } | |
221 | - } | |
222 | - | |
223 | 210 | private void doUnmount() { |
224 | 211 | // Present a toast here |
225 | 212 | Toast.makeText(getActivity(), R.string.unmount_inform_text, Toast.LENGTH_SHORT).show(); |
226 | 213 | IMountService mountService = getMountService(); |
227 | 214 | try { |
228 | - mClickedMountToggle.setEnabled(false); | |
229 | - mClickedMountToggle.setTitle(mResources.getString(R.string.sd_ejecting_title)); | |
230 | - mClickedMountToggle.setSummary(mResources.getString(R.string.sd_ejecting_summary)); | |
215 | + mLastClickedMountToggle.setEnabled(false); | |
216 | + mLastClickedMountToggle.setTitle(mResources.getString(R.string.sd_ejecting_title)); | |
217 | + mLastClickedMountToggle.setSummary(mResources.getString(R.string.sd_ejecting_summary)); | |
231 | 218 | mountService.unmountVolume(mClickedMountPoint, true); |
232 | 219 | } catch (RemoteException e) { |
233 | 220 | // Informative dialog to user that unmount failed. |
234 | 221 | showDialogInner(DLG_ERROR_UNMOUNT); |
235 | 222 | } |
236 | - mClickedMountToggle = null; | |
237 | 223 | } |
238 | 224 | |
239 | 225 | private void showDialogInner(int id) { |
@@ -274,7 +260,6 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen | ||
274 | 260 | // Very unlikely. But present an error dialog anyway |
275 | 261 | Log.e(TAG, "Is MountService running?"); |
276 | 262 | showDialogInner(DLG_ERROR_UNMOUNT); |
277 | - mClickedMountToggle = null; | |
278 | 263 | } |
279 | 264 | } |
280 | 265 |
@@ -289,10 +274,5 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen | ||
289 | 274 | } catch (RemoteException ex) { |
290 | 275 | // Not much can be done |
291 | 276 | } |
292 | - mClickedMountToggle = null; | |
293 | - } | |
294 | - | |
295 | - public void onCancel(DialogInterface dialog) { | |
296 | - mClickedMountToggle = null; | |
297 | 277 | } |
298 | 278 | } |