Loading packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +23 −12 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.documentsui; import static com.android.documentsui.Shared.DEBUG; import static com.android.documentsui.Shared.TAG; import static com.android.internal.util.Preconditions.checkState; import android.content.ContentProviderClient; import android.content.ContentResolver; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.documentsui.model.RootInfo; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; Loading Loading @@ -86,8 +88,6 @@ public class RootsCache { // Create a new anonymous "Recents" RootInfo. It's a faker. mRecentsRoot = new RootInfo() {{ // Special root for recents authority = null; rootId = null; derivedIcon = R.drawable.ic_root_recent; derivedType = RootInfo.TYPE_RECENTS; flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_IS_CHILD; Loading Loading @@ -116,6 +116,16 @@ public class RootsCache { * Gather roots from all known storage providers. */ public void updateAsync() { // Verifying an assumption about the recents root being immutable. if (DEBUG) { checkState(mRecentsRoot.authority == null); checkState(mRecentsRoot.rootId == null); checkState(mRecentsRoot.derivedIcon == R.drawable.ic_root_recent); checkState(mRecentsRoot.derivedType == RootInfo.TYPE_RECENTS); checkState(mRecentsRoot.flags == (Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_IS_CHILD)); checkState(mRecentsRoot.title == mContext.getString(R.string.root_recent)); checkState(mRecentsRoot.availableBytes == -1); } new UpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } Loading Loading @@ -412,9 +422,10 @@ public class RootsCache { if (!state.showAdvanced && root.isAdvanced()) continue; // Exclude non-local devices when local only if (state.localOnly && !root.isLocalOnly()) continue; // Exclude downloads roots that don't support directory creation // TODO: Add flag to check the root supports directory creation or not. if (state.directoryCopy && !root.supportsChildren()) continue; // Exclude downloads roots as it doesn't support directory creation (actually // we just don't show them). // TODO: Add flag to check the root supports directory creation. if (state.directoryCopy && !root.isDownloads()) continue; // Only show empty roots when creating, or in browse mode. if (root.isEmpty() && (state.action == State.ACTION_OPEN Loading packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java +1 −12 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.android.documentsui.model.DocumentInfo; import com.android.documentsui.model.RootInfo; import java.util.ArrayList; Loading Loading @@ -403,17 +402,7 @@ public class RootsFragment extends Fragment { public static class RootComparator implements Comparator<RootItem> { @Override public int compare(RootItem lhs, RootItem rhs) { // Sort by root type, then title, then summary. int score = lhs.root.derivedType - rhs.root.derivedType; if (score != 0) { return score; } score = DocumentInfo.compareToIgnoreCaseNullable(lhs.root.title, rhs.root.title); if (score != 0) { return score; } return DocumentInfo.compareToIgnoreCaseNullable(lhs.root.summary, rhs.root.summary); return lhs.root.compareTo(rhs.root); } } } packages/DocumentsUI/src/com/android/documentsui/Shared.java +38 −0 Original line number Diff line number Diff line Loading @@ -17,14 +17,17 @@ package com.android.documentsui; import android.content.Context; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.Time; import java.text.Collator; import java.util.ArrayList; import java.util.List; /** @hide */ public final class Shared { /** Intent action name to pick a copy destination. */ public static final String ACTION_PICK_COPY_DESTINATION = "com.android.documentsui.PICK_COPY_DESTINATION"; Loading @@ -39,6 +42,19 @@ public final class Shared { public static final String TAG = "Documents"; public static final String EXTRA_STACK = "com.android.documentsui.STACK"; /** * String prefix used to indicate the document is a directory. */ public static final char DIR_PREFIX = '\001'; private static final Collator sCollator; static { sCollator = Collator.getInstance(); sCollator.setStrength(Collator.SECONDARY); } /** * Generates a formatted quantity string. */ Loading Loading @@ -76,4 +92,26 @@ public final class Shared { ? (ArrayList<T>) list : new ArrayList<T>(list); } /** * Compare two strings against each other using system default collator in a * case-insensitive mode. Clusters strings prefixed with {@link DIR_PREFIX} * before other items. */ public static int compareToIgnoreCaseNullable(String lhs, String rhs) { final boolean leftEmpty = TextUtils.isEmpty(lhs); final boolean rightEmpty = TextUtils.isEmpty(rhs); if (leftEmpty && rightEmpty) return 0; if (leftEmpty) return -1; if (rightEmpty) return 1; final boolean leftDir = (lhs.charAt(0) == DIR_PREFIX); final boolean rightDir = (rhs.charAt(0) == DIR_PREFIX); if (leftDir && !rightDir) return -1; if (rightDir && !leftDir) return 1; return sCollator.compare(lhs, rhs); } } packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −2 Original line number Diff line number Diff line Loading @@ -1071,8 +1071,8 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi return false; } // Can't copy folders to roots that don't support children. if (!root.supportsChildren()) { // Can't copy folders to downloads, because we don't show folders there. if (!root.isDownloads()) { for (DocumentInfo docs : files) { if (docs.isDirectory()) { return false; Loading packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java +3 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.util.Log; import com.android.documentsui.DirectoryResult; import com.android.documentsui.RootCursorWrapper; import com.android.documentsui.Shared; import com.android.documentsui.dirlist.MultiSelectManager.Selection; import com.android.documentsui.model.DocumentInfo; Loading Loading @@ -170,7 +171,7 @@ public class Model { final String displayName = getCursorString( mCursor, Document.COLUMN_DISPLAY_NAME); if (Document.MIME_TYPE_DIR.equals(mimeType)) { stringValues[pos] = DocumentInfo.DIR_PREFIX + displayName; stringValues[pos] = Shared.DIR_PREFIX + displayName; } else { stringValues[pos] = displayName; } Loading Loading @@ -227,7 +228,7 @@ public class Model { final String lhs = pivotValue; final String rhs = sortKey[mid]; final int compare = DocumentInfo.compareToIgnoreCaseNullable(lhs, rhs); final int compare = Shared.compareToIgnoreCaseNullable(lhs, rhs); if (compare < 0) { right = mid; Loading Loading
packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +23 −12 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.documentsui; import static com.android.documentsui.Shared.DEBUG; import static com.android.documentsui.Shared.TAG; import static com.android.internal.util.Preconditions.checkState; import android.content.ContentProviderClient; import android.content.ContentResolver; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.documentsui.model.RootInfo; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; Loading Loading @@ -86,8 +88,6 @@ public class RootsCache { // Create a new anonymous "Recents" RootInfo. It's a faker. mRecentsRoot = new RootInfo() {{ // Special root for recents authority = null; rootId = null; derivedIcon = R.drawable.ic_root_recent; derivedType = RootInfo.TYPE_RECENTS; flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_IS_CHILD; Loading Loading @@ -116,6 +116,16 @@ public class RootsCache { * Gather roots from all known storage providers. */ public void updateAsync() { // Verifying an assumption about the recents root being immutable. if (DEBUG) { checkState(mRecentsRoot.authority == null); checkState(mRecentsRoot.rootId == null); checkState(mRecentsRoot.derivedIcon == R.drawable.ic_root_recent); checkState(mRecentsRoot.derivedType == RootInfo.TYPE_RECENTS); checkState(mRecentsRoot.flags == (Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_IS_CHILD)); checkState(mRecentsRoot.title == mContext.getString(R.string.root_recent)); checkState(mRecentsRoot.availableBytes == -1); } new UpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } Loading Loading @@ -412,9 +422,10 @@ public class RootsCache { if (!state.showAdvanced && root.isAdvanced()) continue; // Exclude non-local devices when local only if (state.localOnly && !root.isLocalOnly()) continue; // Exclude downloads roots that don't support directory creation // TODO: Add flag to check the root supports directory creation or not. if (state.directoryCopy && !root.supportsChildren()) continue; // Exclude downloads roots as it doesn't support directory creation (actually // we just don't show them). // TODO: Add flag to check the root supports directory creation. if (state.directoryCopy && !root.isDownloads()) continue; // Only show empty roots when creating, or in browse mode. if (root.isEmpty() && (state.action == State.ACTION_OPEN Loading
packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java +1 −12 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.android.documentsui.model.DocumentInfo; import com.android.documentsui.model.RootInfo; import java.util.ArrayList; Loading Loading @@ -403,17 +402,7 @@ public class RootsFragment extends Fragment { public static class RootComparator implements Comparator<RootItem> { @Override public int compare(RootItem lhs, RootItem rhs) { // Sort by root type, then title, then summary. int score = lhs.root.derivedType - rhs.root.derivedType; if (score != 0) { return score; } score = DocumentInfo.compareToIgnoreCaseNullable(lhs.root.title, rhs.root.title); if (score != 0) { return score; } return DocumentInfo.compareToIgnoreCaseNullable(lhs.root.summary, rhs.root.summary); return lhs.root.compareTo(rhs.root); } } }
packages/DocumentsUI/src/com/android/documentsui/Shared.java +38 −0 Original line number Diff line number Diff line Loading @@ -17,14 +17,17 @@ package com.android.documentsui; import android.content.Context; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.Time; import java.text.Collator; import java.util.ArrayList; import java.util.List; /** @hide */ public final class Shared { /** Intent action name to pick a copy destination. */ public static final String ACTION_PICK_COPY_DESTINATION = "com.android.documentsui.PICK_COPY_DESTINATION"; Loading @@ -39,6 +42,19 @@ public final class Shared { public static final String TAG = "Documents"; public static final String EXTRA_STACK = "com.android.documentsui.STACK"; /** * String prefix used to indicate the document is a directory. */ public static final char DIR_PREFIX = '\001'; private static final Collator sCollator; static { sCollator = Collator.getInstance(); sCollator.setStrength(Collator.SECONDARY); } /** * Generates a formatted quantity string. */ Loading Loading @@ -76,4 +92,26 @@ public final class Shared { ? (ArrayList<T>) list : new ArrayList<T>(list); } /** * Compare two strings against each other using system default collator in a * case-insensitive mode. Clusters strings prefixed with {@link DIR_PREFIX} * before other items. */ public static int compareToIgnoreCaseNullable(String lhs, String rhs) { final boolean leftEmpty = TextUtils.isEmpty(lhs); final boolean rightEmpty = TextUtils.isEmpty(rhs); if (leftEmpty && rightEmpty) return 0; if (leftEmpty) return -1; if (rightEmpty) return 1; final boolean leftDir = (lhs.charAt(0) == DIR_PREFIX); final boolean rightDir = (rhs.charAt(0) == DIR_PREFIX); if (leftDir && !rightDir) return -1; if (rightDir && !leftDir) return 1; return sCollator.compare(lhs, rhs); } }
packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −2 Original line number Diff line number Diff line Loading @@ -1071,8 +1071,8 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi return false; } // Can't copy folders to roots that don't support children. if (!root.supportsChildren()) { // Can't copy folders to downloads, because we don't show folders there. if (!root.isDownloads()) { for (DocumentInfo docs : files) { if (docs.isDirectory()) { return false; Loading
packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java +3 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.util.Log; import com.android.documentsui.DirectoryResult; import com.android.documentsui.RootCursorWrapper; import com.android.documentsui.Shared; import com.android.documentsui.dirlist.MultiSelectManager.Selection; import com.android.documentsui.model.DocumentInfo; Loading Loading @@ -170,7 +171,7 @@ public class Model { final String displayName = getCursorString( mCursor, Document.COLUMN_DISPLAY_NAME); if (Document.MIME_TYPE_DIR.equals(mimeType)) { stringValues[pos] = DocumentInfo.DIR_PREFIX + displayName; stringValues[pos] = Shared.DIR_PREFIX + displayName; } else { stringValues[pos] = displayName; } Loading Loading @@ -227,7 +228,7 @@ public class Model { final String lhs = pivotValue; final String rhs = sortKey[mid]; final int compare = DocumentInfo.compareToIgnoreCaseNullable(lhs, rhs); final int compare = Shared.compareToIgnoreCaseNullable(lhs, rhs); if (compare < 0) { right = mid; Loading