Change move storage from dropdown pref to dialog

Use a horizontal pref and a single button that triggers the dialog

Bug: 21922660
Change-Id: Ifb4de75ca9269d2e8163eec5602932260adec0d9
This commit is contained in:
Jason Monk
2015-07-15 13:04:59 -04:00
parent d7fb46de59
commit e8400c2fb7
3 changed files with 57 additions and 24 deletions

View File

@@ -38,7 +38,6 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.DropDownPreference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.deviceinfo.StorageWizardMoveConfirm;
@@ -51,7 +50,7 @@ import java.util.List;
import java.util.Objects;
public class AppStorageSettings extends AppInfoWithHeader
implements OnClickListener, Callbacks, DropDownPreference.Callback {
implements OnClickListener, Callbacks, DialogInterface.OnClickListener {
private static final String TAG = AppStorageSettings.class.getSimpleName();
//internal constants used in Handler
@@ -70,7 +69,8 @@ public class AppStorageSettings extends AppInfoWithHeader
private static final int DLG_CLEAR_DATA = DLG_BASE + 1;
private static final int DLG_CANNOT_CLEAR_DATA = DLG_BASE + 2;
private static final String KEY_MOVE_PREFERENCE = "app_location_setting";
private static final String KEY_STORAGE_USED = "storage_used";
private static final String KEY_CHANGE_STORAGE = "change_storage_button";
private static final String KEY_STORAGE_CATEGORY = "storage_category";
private static final String KEY_TOTAL_SIZE = "total_size";
@@ -94,7 +94,8 @@ public class AppStorageSettings extends AppInfoWithHeader
private Button mClearDataButton;
private Button mClearCacheButton;
private DropDownPreference mMoveDropDown;
private Preference mStorageUsed;
private Button mChangeStorageButton;
private boolean mCanClearData = true;
private boolean mHaveSizes = false;
@@ -113,6 +114,9 @@ public class AppStorageSettings extends AppInfoWithHeader
private CharSequence mInvalidSizeStr;
private CharSequence mComputingStr;
private VolumeInfo[] mCandidates;
private AlertDialog.Builder mDialogBuilder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -146,8 +150,11 @@ public class AppStorageSettings extends AppInfoWithHeader
mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_DATA))
.findViewById(R.id.button);
mMoveDropDown = (DropDownPreference) findPreference(KEY_MOVE_PREFERENCE);
mMoveDropDown.setCallback(this);
mStorageUsed = findPreference(KEY_STORAGE_USED);
mChangeStorageButton = (Button) ((LayoutPreference) findPreference(KEY_CHANGE_STORAGE))
.findViewById(R.id.button);
mChangeStorageButton.setText(R.string.change);
mChangeStorageButton.setOnClickListener(this);
// Cache section
mCacheSize = findPreference(KEY_CACHE_SIZE);
@@ -164,7 +171,7 @@ public class AppStorageSettings extends AppInfoWithHeader
mClearCacheObserver = new ClearCacheObserver();
}
mPm.deleteApplicationCacheFiles(mPackageName, mClearCacheObserver);
} else if(v == mClearDataButton) {
} else if (v == mClearDataButton) {
if (mAppEntry.info.manageSpaceActivityName != null) {
if (!Utils.isMonkeyRunning()) {
Intent intent = new Intent(Intent.ACTION_DEFAULT);
@@ -175,15 +182,17 @@ public class AppStorageSettings extends AppInfoWithHeader
} else {
showDialogInner(DLG_CLEAR_DATA, 0);
}
} else if (v == mChangeStorageButton) {
mDialogBuilder.show();
}
}
@Override
public boolean onItemSelected(int pos, Object value) {
public void onClick(DialogInterface dialog, int which) {
final Context context = getActivity();
// If not current volume, kick off move wizard
final VolumeInfo targetVol = (VolumeInfo) value;
final VolumeInfo targetVol = mCandidates[which];
final VolumeInfo currentVol = context.getPackageManager().getPackageCurrentVolume(
mAppEntry.info);
if (!Objects.equals(targetVol, currentVol)) {
@@ -192,8 +201,7 @@ public class AppStorageSettings extends AppInfoWithHeader
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
startActivity(intent);
}
return true;
dialog.dismiss();
}
private String getSizeStr(long size) {
@@ -273,18 +281,20 @@ public class AppStorageSettings extends AppInfoWithHeader
@Override
protected boolean refreshUi() {
retrieveAppEntry();
refreshButtons();
refreshSizeInfo();
final VolumeInfo currentVol = getActivity().getPackageManager()
.getPackageCurrentVolume(mAppEntry.info);
mMoveDropDown.setSelectedValue(currentVol);
final StorageManager storage = getContext().getSystemService(StorageManager.class);
mStorageUsed.setSummary(storage.getBestVolumeDescription(currentVol));
refreshButtons();
return true;
}
private void refreshButtons() {
initMoveDropDown();
initMoveDialog();
initDataButtons();
}
@@ -314,7 +324,7 @@ public class AppStorageSettings extends AppInfoWithHeader
}
}
private void initMoveDropDown() {
private void initMoveDialog() {
final Context context = getActivity();
final StorageManager storage = context.getSystemService(StorageManager.class);
@@ -323,14 +333,23 @@ public class AppStorageSettings extends AppInfoWithHeader
if (candidates.size() > 1) {
Collections.sort(candidates, VolumeInfo.getDescriptionComparator());
mMoveDropDown.clearItems();
for (VolumeInfo vol : candidates) {
final String volDescrip = storage.getBestVolumeDescription(vol);
mMoveDropDown.addItem(volDescrip, vol);
CharSequence[] labels = new CharSequence[candidates.size()];
int current = -1;
for (int i = 0; i < candidates.size(); i++) {
final String volDescrip = storage.getBestVolumeDescription(candidates.get(i));
if (Objects.equals(volDescrip, mStorageUsed.getSummary())) {
current = i;
}
labels[i] = volDescrip;
}
mMoveDropDown.setSelectable(!mAppControlRestricted);
mCandidates = candidates.toArray(new VolumeInfo[candidates.size()]);
mDialogBuilder = new AlertDialog.Builder(getContext())
.setTitle(R.string.change_storage)
.setSingleChoiceItems(labels, current, this)
.setNegativeButton(R.string.cancel, null);
} else {
removePreference(KEY_MOVE_PREFERENCE);
removePreference(KEY_STORAGE_USED);
removePreference(KEY_CHANGE_STORAGE);
}
}