Merge "Show proper icons for SD and USB attached storage." into nyc-dev am: eef85e0c02

am: f3322fccfa

* commit 'f3322fccfa21ce251055b1051788a5b411c28f26':
  Show proper icons for SD and USB attached storage.
This commit is contained in:
Steve McKay
2016-03-03 20:38:07 +00:00
committed by android-build-merger
5 changed files with 103 additions and 24 deletions

View File

@@ -568,6 +568,22 @@ public final class DocumentsContract {
* @hide
*/
public static final int FLAG_HAS_SETTINGS = 1 << 17;
/**
* Flag indicating that this root is on removable SD card storage.
*
* @see #COLUMN_FLAGS
* @hide
*/
public static final int FLAG_REMOVABLE_SD = 1 << 18;
/**
* Flag indicating that this root is on removable USB storage.
*
* @see #COLUMN_FLAGS
* @hide
*/
public static final int FLAG_REMOVABLE_USB = 1 << 19;
}
/**

View File

@@ -14,8 +14,8 @@ Copyright (C) 2015 The Android Open Source Project
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path

View File

@@ -0,0 +1,24 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M15 7v4h1v2h-3V5h2l-3,-4,-3 4h2v8H8v-2.07c.7,-.37 1.2,-1.08 1.2,-1.93 0,-1.21,-.99,-2.2,-2.2,-2.2,-1.21 0,-2.2.99,-2.2 2.2 0 .85.5 1.56 1.2 1.93V13c0 1.11.89 2 2 2h3v3.05c-.71.37,-1.2 1.1,-1.2 1.95 0 1.22.99 2.2 2.2 2.2 1.21 0 2.2,-.98 2.2,-2.2 0,-.85,-.49,-1.58,-1.2,-1.95V15h3c1.11 0 2,-.89 2,-2v-2h1V7h-4z"/>
</vector>

View File

@@ -16,6 +16,7 @@
package com.android.documentsui.model;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.Shared.compareToIgnoreCaseNullable;
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
@@ -31,6 +32,7 @@ import android.os.Parcelable;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Root;
import android.text.TextUtils;
import android.util.Log;
import com.android.documentsui.IconUtils;
import com.android.documentsui.R;
@@ -47,6 +49,8 @@ import java.util.Objects;
* Representation of a {@link Root}.
*/
public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
private static final String TAG = "RootInfo";
private static final int VERSION_INIT = 1;
private static final int VERSION_DROP_TYPE = 2;
@@ -59,6 +63,8 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
TYPE_DOWNLOADS,
TYPE_LOCAL,
TYPE_MTP,
TYPE_SD,
TYPE_USB,
TYPE_OTHER
})
@Retention(RetentionPolicy.SOURCE)
@@ -70,7 +76,9 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
public static final int TYPE_DOWNLOADS = 5;
public static final int TYPE_LOCAL = 6;
public static final int TYPE_MTP = 7;
public static final int TYPE_OTHER = 8;
public static final int TYPE_SD = 8;
public static final int TYPE_USB = 9;
public static final int TYPE_OTHER = 10;
public String authority;
public String rootId;
@@ -185,33 +193,40 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
private void deriveFields() {
derivedMimeTypes = (mimeTypes != null) ? mimeTypes.split("\n") : null;
// TODO: remove these special case icons
if (isHome()) {
derivedType = TYPE_LOCAL;
derivedIcon = R.drawable.ic_root_documents;
derivedType = TYPE_LOCAL;
} else if (isExternalStorage()) {
derivedIcon = R.drawable.ic_root_smartphone;
derivedType = TYPE_LOCAL;
// TODO: Apply SD card icon to SD devices.
} else if (isDownloads()) {
derivedIcon = R.drawable.ic_root_download;
derivedType = TYPE_DOWNLOADS;
} else if (isImages()) {
derivedIcon = R.drawable.ic_doc_image;
derivedType = TYPE_IMAGES;
} else if (isVideos()) {
derivedIcon = R.drawable.ic_doc_video;
derivedType = TYPE_VIDEO;
} else if (isAudio()) {
derivedIcon = R.drawable.ic_doc_audio;
derivedType = TYPE_AUDIO;
} else if (isRecents()) {
derivedType = TYPE_RECENTS;
} else if (isMtp()) {
derivedType = TYPE_MTP;
derivedIcon = R.drawable.ic_usb_storage;
} else if (isUsb()) {
derivedType = TYPE_USB;
derivedIcon = R.drawable.ic_usb_storage;
} else if (isSd()) {
derivedType = TYPE_SD;
derivedIcon = R.drawable.ic_sd_storage;
} else if (isExternalStorage()) {
derivedType = TYPE_LOCAL;
derivedIcon = R.drawable.ic_root_smartphone;
} else if (isDownloads()) {
derivedType = TYPE_DOWNLOADS;
derivedIcon = R.drawable.ic_root_download;
} else if (isImages()) {
derivedType = TYPE_IMAGES;
derivedIcon = R.drawable.ic_doc_image;
} else if (isVideos()) {
derivedType = TYPE_VIDEO;
derivedIcon = R.drawable.ic_doc_video;
} else if (isAudio()) {
derivedType = TYPE_AUDIO;
derivedIcon = R.drawable.ic_doc_audio;
} else if (isRecents()) {
derivedType = TYPE_RECENTS;
} else {
derivedType = TYPE_OTHER;
}
if (DEBUG) Log.d(TAG, "Finished deriving fields: " + this);
}
public Uri getUri() {
@@ -291,6 +306,14 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
return (flags & Root.FLAG_EMPTY) != 0;
}
public boolean isSd() {
return (flags & Root.FLAG_REMOVABLE_SD) != 0;
}
public boolean isUsb() {
return (flags & Root.FLAG_REMOVABLE_USB) != 0;
}
public Drawable loadIcon(Context context) {
if (derivedIcon != 0) {
return context.getDrawable(derivedIcon);
@@ -358,7 +381,14 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
@Override
public String toString() {
return "Root{authority=" + authority + ", rootId=" + rootId + ", title=" + title + "}";
return "Root{"
+ "authority=" + authority
+ ", rootId=" + rootId
+ ", title=" + title
+ ", isUsb=" + isUsb()
+ ", isSd=" + isSd()
+ ", isMtp=" + isMtp()
+ "}";
}
public String getDirectoryString() {

View File

@@ -34,6 +34,7 @@ import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor.OnCloseListener;
import android.os.UserHandle;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.provider.DocumentsContract;
@@ -184,6 +185,14 @@ public class ExternalStorageProvider extends DocumentsProvider {
root.flags = Root.FLAG_LOCAL_ONLY
| Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
final DiskInfo disk = volume.getDisk();
if (DEBUG) Log.d(TAG, "Disk for root " + rootId + " is " + disk);
if (disk != null && disk.isSd()) {
root.flags |= Root.FLAG_REMOVABLE_SD;
} else if (disk != null && disk.isUsb()) {
root.flags |= Root.FLAG_REMOVABLE_USB;
}
if (volume.isPrimary()) {
// save off the primary volume for subsequent "Home" dir initialization.
primaryVolume = volume;