summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-06-23 03:47:13 +0200
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-07-05 22:55:11 -0700
commitef1d17890d68e853a0267280dc824eb9ad216732 (patch)
treef86a2e7d40a77d1aed775057b4892f6e34a862aa
parent3f06cd551a5e46e48eb0637f666e80ffaf0fb342 (diff)
downloadpackages_apps_settings-ef1d17890d68e853a0267280dc824eb9ad216732.zip
packages_apps_settings-ef1d17890d68e853a0267280dc824eb9ad216732.tar.gz
packages_apps_settings-ef1d17890d68e853a0267280dc824eb9ad216732.tar.bz2
Storage Settings: Allow user to trigger a volume rescan
This change allows to trigger a rescan of a volume with the next restrictions: - Internal volumes if they are emulates - Primary volumes - Non-Removable volumes Requires http://review.cyanogenmod.org/#/c/44585/ Change-Id: I42aebc9fc0d3530cf0a3efb4d2139b688707d43d JIRA: CYAN-1391 Issue: https://jira.cyanogenmod.org/browse/CYAN-1391 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--res/layout/preference_memoryusage.xml23
-rw-r--r--res/values/cm_strings.xml2
-rw-r--r--src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java62
-rw-r--r--src/com/android/settings/deviceinfo/UsageBarPreference.java64
4 files changed, 146 insertions, 5 deletions
diff --git a/res/layout/preference_memoryusage.xml b/res/layout/preference_memoryusage.xml
index ddc619d..edabcee 100644
--- a/res/layout/preference_memoryusage.xml
+++ b/res/layout/preference_memoryusage.xml
@@ -20,8 +20,27 @@
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
- android:paddingEnd="?android:attr/scrollbarSize"
- android:paddingStart="@*android:dimen/preference_widget_width">
+ android:paddingEnd="?android:attr/scrollbarSize">
+
+ <ImageView android:id="@+id/memory_usage_rescan_media"
+ android:layout_width="48dip"
+ android:layout_height="48dip"
+ android:padding="6dp"
+ android:layout_gravity="center"
+ android:clickable="true"
+ android:focusable="false"
+ android:focusableInTouchMode="false"
+ android:src="@drawable/ic_menu_refresh_holo_dark"
+ android:background="@*android:drawable/list_selector_holo_dark"
+ android:contentDescription="@string/storage_rescan_media"/>
+
+ <ProgressBar android:id="@+id/memory_usage_rescan_media_waiting"
+ android:layout_width="48dip"
+ android:layout_height="48dip"
+ android:padding="6dp"
+ android:layout_gravity="center"
+ android:visibility="gone"
+ android:indeterminateOnly="true"/>
<com.android.settings.deviceinfo.PercentageBarChart
android:id="@+id/percentage_bar_chart"
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 3b335db..182849a 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -689,6 +689,8 @@
<!-- USB Mass Storage -->
<string name="usb_mass_storage_title">Mass storage</string>
<string name="usb_mass_storage_summary">Enable USB mass storage</string>
+ <string name="storage_rescan_media">Rescan media for the storage volume</string>
+ <string name="storage_rescan_media_complete">Scan completed</string>
<!-- Android debugging over WiFi -->
<string name="adb_over_network">ADB over network</string>
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
index 61188ec..be7c530 100644
--- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
+++ b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
@@ -16,6 +16,8 @@
package com.android.settings.deviceinfo;
+import android.app.Activity;
+import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
import android.app.DownloadManager;
@@ -25,27 +27,39 @@ import android.content.pm.IPackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.hardware.usb.UsbManager;
+import android.media.MediaScannerConnection;
+import android.media.MediaScannerConnection.OnScanCompletedListener;
+import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.UserManager;
+import android.os.Environment.UserEnvironment;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.text.format.Formatter;
+import android.util.Log;
+import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.deviceinfo.StorageMeasurement.MeasurementDetails;
import com.android.settings.deviceinfo.StorageMeasurement.MeasurementReceiver;
+import com.android.settings.deviceinfo.UsageBarPreference.OnRequestMediaRescanListener;
import com.google.android.collect.Lists;
+import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-public class StorageVolumePreferenceCategory extends PreferenceCategory {
+public class StorageVolumePreferenceCategory extends PreferenceCategory
+ implements OnRequestMediaRescanListener, OnScanCompletedListener {
+
+ public static final String TAG = "StorageVolumePreferenceCategory";
+
public static final String KEY_CACHE = "cache";
private static final int ORDER_USAGE_BAR = -2;
@@ -54,6 +68,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
/** Physical volume being measured, or {@code null} for internal. */
private final StorageVolume mVolume;
private final StorageMeasurement mMeasure;
+ private final boolean mIsInternal;
+ private final boolean mIsPrimary;
private final Resources mResources;
private final StorageManager mStorageManager;
@@ -120,6 +136,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
super(context);
mVolume = volume;
+ mIsInternal = mVolume == null;
+ mIsPrimary = mVolume != null ? mVolume.isPrimary() : false;
mMeasure = StorageMeasurement.getInstance(context, volume);
mResources = context.getResources();
@@ -147,8 +165,17 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
final List<UserInfo> otherUsers = getUsersExcluding(currentUser);
final boolean showUsers = mVolume == null && otherUsers.size() > 0;
+ boolean allowMediaScan = false;
+ if ((mIsInternal && Environment.isExternalStorageEmulated()) || mIsPrimary) {
+ allowMediaScan = true;
+ } else if (mVolume != null && !mVolume.isRemovable()) {
+ allowMediaScan = true;
+ }
+
mUsageBarPreference = new UsageBarPreference(context);
mUsageBarPreference.setOrder(ORDER_USAGE_BAR);
+ mUsageBarPreference.setOnRequestMediaRescanListener(this);
+ mUsageBarPreference.setAllowMediaScan(allowMediaScan);
addPreference(mUsageBarPreference);
mItemTotal = buildItem(R.string.memory_size, 0);
@@ -481,4 +508,37 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
}
return users;
}
+
+ @Override
+ public void onRequestMediaRescan() {
+ final int currentUser = ActivityManager.getCurrentUser();
+ final UserEnvironment currentEnv = new UserEnvironment(currentUser);
+
+ File path = null;
+ if ((mIsInternal && Environment.isExternalStorageEmulated()) || mIsPrimary) {
+ path = currentEnv.getExternalStorageDirectory();
+ } else {
+ path = mVolume.getPathFile();
+ }
+
+ Log.d(TAG, "Request scan of " + path.getAbsolutePath());
+ MediaScannerConnection.scanFile(
+ getContext(), new String[]{path.getAbsolutePath()}, null, this);
+ }
+
+ @Override
+ public void onScanCompleted(String path, final Uri uri) {
+ if (uri != null) {
+ measure();
+ }
+ ((Activity)getContext()).runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mUsageBarPreference.notifyScanCompleted();
+ if (uri != null) {
+ Toast.makeText(getContext(), R.string.storage_rescan_media_complete, Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ }
}
diff --git a/src/com/android/settings/deviceinfo/UsageBarPreference.java b/src/com/android/settings/deviceinfo/UsageBarPreference.java
index 2f3fd03..b0fd226 100644
--- a/src/com/android/settings/deviceinfo/UsageBarPreference.java
+++ b/src/com/android/settings/deviceinfo/UsageBarPreference.java
@@ -20,9 +20,13 @@ import com.android.settings.R;
import com.google.common.collect.Lists;
import android.content.Context;
+import android.os.Handler;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
import java.util.ArrayList;
import java.util.Collection;
@@ -33,23 +37,42 @@ import java.util.List;
* Creates a percentage bar chart inside a preference.
*/
public class UsageBarPreference extends Preference {
+
+ public interface OnRequestMediaRescanListener {
+ void onRequestMediaRescan();
+ }
+
+ private ImageView mRescanMedia = null;
+ private ProgressBar mRescanMediaWaiting = null;
private PercentageBarChart mChart = null;
+ private boolean mAllowMediaScan;
+
+ private OnRequestMediaRescanListener mOnRequestMediaRescanListener;
+
private final List<PercentageBarChart.Entry> mEntries = Lists.newArrayList();
+ private Handler mHandler;
+
public UsageBarPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- setLayoutResource(R.layout.preference_memoryusage);
+ init();
}
public UsageBarPreference(Context context) {
super(context);
- setLayoutResource(R.layout.preference_memoryusage);
+ init();
}
public UsageBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
+ init();
+ }
+
+ private void init() {
setLayoutResource(R.layout.preference_memoryusage);
+ mHandler = new Handler();
+ mAllowMediaScan = false;
}
public void addEntry(int order, float percentage, int color) {
@@ -57,12 +80,49 @@ public class UsageBarPreference extends Preference {
Collections.sort(mEntries);
}
+ protected void setOnRequestMediaRescanListener(OnRequestMediaRescanListener listener) {
+ mOnRequestMediaRescanListener = listener;
+ }
+
+ protected void setAllowMediaScan(boolean allow) {
+ mAllowMediaScan = allow;
+ notifyScanCompleted();
+ }
+
+ protected void notifyScanCompleted() {
+ if (mRescanMedia != null) {
+ mRescanMedia.setVisibility(mAllowMediaScan ? View.VISIBLE : View.INVISIBLE);
+ mRescanMediaWaiting.setVisibility(View.GONE);
+ }
+ }
+
@Override
protected void onBindView(View view) {
super.onBindView(view);
mChart = (PercentageBarChart) view.findViewById(R.id.percentage_bar_chart);
mChart.setEntries(mEntries);
+
+ mRescanMediaWaiting = (ProgressBar) view.findViewById(R.id.memory_usage_rescan_media_waiting);
+
+ mRescanMedia = (ImageView) view.findViewById(R.id.memory_usage_rescan_media);
+ mRescanMedia.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mOnRequestMediaRescanListener != null) {
+ mRescanMedia.setVisibility(View.GONE);
+ mRescanMediaWaiting.setVisibility(View.VISIBLE);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mOnRequestMediaRescanListener.onRequestMediaRescan();
+ }
+ });
+ }
+ }
+ });
+
+ notifyScanCompleted();
}
public void commit() {