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:
@@ -6460,6 +6460,12 @@
|
|||||||
<!-- Title of storage preference to control where app is stored -->
|
<!-- Title of storage preference to control where app is stored -->
|
||||||
<string name="storage_used">Storage used</string>
|
<string name="storage_used">Storage used</string>
|
||||||
|
|
||||||
|
<!-- Title of button to change storage [CHAR LIMIT=25] -->
|
||||||
|
<string name="change">Change</string>
|
||||||
|
|
||||||
|
<!-- Title of dialog to change storage [CHAR LIMIT=25] -->
|
||||||
|
<string name="change_storage">Change storage</string>
|
||||||
|
|
||||||
<!-- Label for notification settings for an specific app [CHAR LIMIT=40] -->
|
<!-- Label for notification settings for an specific app [CHAR LIMIT=40] -->
|
||||||
<string name="notifications_label">Notifications</string>
|
<string name="notifications_label">Notifications</string>
|
||||||
<!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
|
<!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
|
||||||
|
@@ -17,11 +17,19 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/application_info_label">
|
android:title="@string/application_info_label">
|
||||||
|
|
||||||
<com.android.settings.DropDownPreference
|
<com.android.settings.applications.SpacePreference
|
||||||
android:key="app_location_setting"
|
android:layout_height="8dp" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="storage_used"
|
||||||
android:title="@string/storage_used"
|
android:title="@string/storage_used"
|
||||||
android:summary="@string/storage_type_internal"
|
android:summary="@string/storage_type_internal"
|
||||||
android:selectable="true" />
|
android:selectable="false"
|
||||||
|
android:layout="@layout/horizontal_preference" />
|
||||||
|
|
||||||
|
<com.android.settings.applications.LayoutPreference
|
||||||
|
android:key="change_storage_button"
|
||||||
|
android:layout="@layout/single_button_panel" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="storage_category"
|
android:key="storage_category"
|
||||||
|
@@ -38,7 +38,6 @@ import android.view.View.OnClickListener;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.settings.DropDownPreference;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.deviceinfo.StorageWizardMoveConfirm;
|
import com.android.settings.deviceinfo.StorageWizardMoveConfirm;
|
||||||
@@ -51,7 +50,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AppStorageSettings extends AppInfoWithHeader
|
public class AppStorageSettings extends AppInfoWithHeader
|
||||||
implements OnClickListener, Callbacks, DropDownPreference.Callback {
|
implements OnClickListener, Callbacks, DialogInterface.OnClickListener {
|
||||||
private static final String TAG = AppStorageSettings.class.getSimpleName();
|
private static final String TAG = AppStorageSettings.class.getSimpleName();
|
||||||
|
|
||||||
//internal constants used in Handler
|
//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_CLEAR_DATA = DLG_BASE + 1;
|
||||||
private static final int DLG_CANNOT_CLEAR_DATA = DLG_BASE + 2;
|
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_STORAGE_CATEGORY = "storage_category";
|
||||||
|
|
||||||
private static final String KEY_TOTAL_SIZE = "total_size";
|
private static final String KEY_TOTAL_SIZE = "total_size";
|
||||||
@@ -94,7 +94,8 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
private Button mClearDataButton;
|
private Button mClearDataButton;
|
||||||
private Button mClearCacheButton;
|
private Button mClearCacheButton;
|
||||||
|
|
||||||
private DropDownPreference mMoveDropDown;
|
private Preference mStorageUsed;
|
||||||
|
private Button mChangeStorageButton;
|
||||||
|
|
||||||
private boolean mCanClearData = true;
|
private boolean mCanClearData = true;
|
||||||
private boolean mHaveSizes = false;
|
private boolean mHaveSizes = false;
|
||||||
@@ -113,6 +114,9 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
private CharSequence mInvalidSizeStr;
|
private CharSequence mInvalidSizeStr;
|
||||||
private CharSequence mComputingStr;
|
private CharSequence mComputingStr;
|
||||||
|
|
||||||
|
private VolumeInfo[] mCandidates;
|
||||||
|
private AlertDialog.Builder mDialogBuilder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -146,8 +150,11 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_DATA))
|
mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_DATA))
|
||||||
.findViewById(R.id.button);
|
.findViewById(R.id.button);
|
||||||
|
|
||||||
mMoveDropDown = (DropDownPreference) findPreference(KEY_MOVE_PREFERENCE);
|
mStorageUsed = findPreference(KEY_STORAGE_USED);
|
||||||
mMoveDropDown.setCallback(this);
|
mChangeStorageButton = (Button) ((LayoutPreference) findPreference(KEY_CHANGE_STORAGE))
|
||||||
|
.findViewById(R.id.button);
|
||||||
|
mChangeStorageButton.setText(R.string.change);
|
||||||
|
mChangeStorageButton.setOnClickListener(this);
|
||||||
|
|
||||||
// Cache section
|
// Cache section
|
||||||
mCacheSize = findPreference(KEY_CACHE_SIZE);
|
mCacheSize = findPreference(KEY_CACHE_SIZE);
|
||||||
@@ -164,7 +171,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
mClearCacheObserver = new ClearCacheObserver();
|
mClearCacheObserver = new ClearCacheObserver();
|
||||||
}
|
}
|
||||||
mPm.deleteApplicationCacheFiles(mPackageName, mClearCacheObserver);
|
mPm.deleteApplicationCacheFiles(mPackageName, mClearCacheObserver);
|
||||||
} else if(v == mClearDataButton) {
|
} else if (v == mClearDataButton) {
|
||||||
if (mAppEntry.info.manageSpaceActivityName != null) {
|
if (mAppEntry.info.manageSpaceActivityName != null) {
|
||||||
if (!Utils.isMonkeyRunning()) {
|
if (!Utils.isMonkeyRunning()) {
|
||||||
Intent intent = new Intent(Intent.ACTION_DEFAULT);
|
Intent intent = new Intent(Intent.ACTION_DEFAULT);
|
||||||
@@ -175,15 +182,17 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
} else {
|
} else {
|
||||||
showDialogInner(DLG_CLEAR_DATA, 0);
|
showDialogInner(DLG_CLEAR_DATA, 0);
|
||||||
}
|
}
|
||||||
|
} else if (v == mChangeStorageButton) {
|
||||||
|
mDialogBuilder.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemSelected(int pos, Object value) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
|
|
||||||
// If not current volume, kick off move wizard
|
// If not current volume, kick off move wizard
|
||||||
final VolumeInfo targetVol = (VolumeInfo) value;
|
final VolumeInfo targetVol = mCandidates[which];
|
||||||
final VolumeInfo currentVol = context.getPackageManager().getPackageCurrentVolume(
|
final VolumeInfo currentVol = context.getPackageManager().getPackageCurrentVolume(
|
||||||
mAppEntry.info);
|
mAppEntry.info);
|
||||||
if (!Objects.equals(targetVol, currentVol)) {
|
if (!Objects.equals(targetVol, currentVol)) {
|
||||||
@@ -192,8 +201,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
|
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
dialog.dismiss();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSizeStr(long size) {
|
private String getSizeStr(long size) {
|
||||||
@@ -273,18 +281,20 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
@Override
|
@Override
|
||||||
protected boolean refreshUi() {
|
protected boolean refreshUi() {
|
||||||
retrieveAppEntry();
|
retrieveAppEntry();
|
||||||
refreshButtons();
|
|
||||||
refreshSizeInfo();
|
refreshSizeInfo();
|
||||||
|
|
||||||
final VolumeInfo currentVol = getActivity().getPackageManager()
|
final VolumeInfo currentVol = getActivity().getPackageManager()
|
||||||
.getPackageCurrentVolume(mAppEntry.info);
|
.getPackageCurrentVolume(mAppEntry.info);
|
||||||
mMoveDropDown.setSelectedValue(currentVol);
|
final StorageManager storage = getContext().getSystemService(StorageManager.class);
|
||||||
|
mStorageUsed.setSummary(storage.getBestVolumeDescription(currentVol));
|
||||||
|
|
||||||
|
refreshButtons();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshButtons() {
|
private void refreshButtons() {
|
||||||
initMoveDropDown();
|
initMoveDialog();
|
||||||
initDataButtons();
|
initDataButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +324,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMoveDropDown() {
|
private void initMoveDialog() {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
final StorageManager storage = context.getSystemService(StorageManager.class);
|
final StorageManager storage = context.getSystemService(StorageManager.class);
|
||||||
|
|
||||||
@@ -323,14 +333,23 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
if (candidates.size() > 1) {
|
if (candidates.size() > 1) {
|
||||||
Collections.sort(candidates, VolumeInfo.getDescriptionComparator());
|
Collections.sort(candidates, VolumeInfo.getDescriptionComparator());
|
||||||
|
|
||||||
mMoveDropDown.clearItems();
|
CharSequence[] labels = new CharSequence[candidates.size()];
|
||||||
for (VolumeInfo vol : candidates) {
|
int current = -1;
|
||||||
final String volDescrip = storage.getBestVolumeDescription(vol);
|
for (int i = 0; i < candidates.size(); i++) {
|
||||||
mMoveDropDown.addItem(volDescrip, vol);
|
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 {
|
} else {
|
||||||
removePreference(KEY_MOVE_PREFERENCE);
|
removePreference(KEY_STORAGE_USED);
|
||||||
|
removePreference(KEY_CHANGE_STORAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user