Use type inference where possible.
Normalize use of Annotations like VisibleForTesting, Nullable and so on. Also, fix a small issue where we were not doubling the marging on cells when calculating columns for grid view. Change-Id: Ia02f683c2682fa8d0963d13f253a359911d27965
This commit is contained in:
@@ -22,7 +22,6 @@ import static com.android.documentsui.DirectoryFragment.ANIM_SIDE;
|
||||
import static com.android.documentsui.DirectoryFragment.ANIM_UP;
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
@@ -38,6 +37,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Root;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -60,8 +60,6 @@ import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.DurableUtils;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -371,7 +369,7 @@ abstract class BaseActivity extends Activity {
|
||||
public String currentSearch;
|
||||
|
||||
/** Instance state for every shown directory */
|
||||
public HashMap<String, SparseArray<Parcelable>> dirState = Maps.newHashMap();
|
||||
public HashMap<String, SparseArray<Parcelable>> dirState = new HashMap<>();
|
||||
|
||||
/** Currently copying file */
|
||||
public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -36,7 +36,6 @@ import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
@@ -24,14 +24,13 @@ import static com.android.documentsui.BaseActivity.State.MODE_GRID;
|
||||
import static com.android.documentsui.BaseActivity.State.MODE_LIST;
|
||||
import static com.android.documentsui.BaseActivity.State.MODE_UNKNOWN;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_UNKNOWN;
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorString;
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import static com.android.internal.util.Preconditions.checkState;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Fragment;
|
||||
@@ -98,7 +97,7 @@ import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -235,8 +234,7 @@ public class DirectoryFragment extends Fragment {
|
||||
public void onLayoutChange(
|
||||
View v, int left, int top, int right, int bottom, int oldLeft,
|
||||
int oldTop, int oldRight, int oldBottom) {
|
||||
int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
|
||||
mColumnCount = pickColumnCount(thumbSize);
|
||||
mColumnCount = calculateColumnCount();
|
||||
if (mGridLayout != null) {
|
||||
mGridLayout.setSpanCount(mColumnCount);
|
||||
}
|
||||
@@ -573,13 +571,15 @@ public class DirectoryFragment extends Fragment {
|
||||
mThumbSize = new Point(thumbSize, thumbSize);
|
||||
}
|
||||
|
||||
private int pickColumnCount(final int thumbSize) {
|
||||
int itemPadding =
|
||||
getResources().getDimensionPixelSize(R.dimen.grid_item_margin);
|
||||
private int calculateColumnCount() {
|
||||
int cellWidth = getResources().getDimensionPixelSize(R.dimen.grid_width);
|
||||
int cellMargin = 2 * getResources().getDimensionPixelSize(R.dimen.grid_item_margin);
|
||||
int viewPadding = mRecView.getPaddingLeft() + mRecView.getPaddingRight();
|
||||
|
||||
checkState(mRecView.getWidth() > 0);
|
||||
int columnCount = Math.max(1,
|
||||
(mRecView.getWidth() - viewPadding) / (thumbSize + itemPadding));
|
||||
(mRecView.getWidth() - viewPadding) / (cellWidth + cellMargin));
|
||||
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ public class DirectoryFragment extends Fragment {
|
||||
Intent intent;
|
||||
|
||||
// Filter out directories - those can't be shared.
|
||||
List<DocumentInfo> docsForSend = Lists.newArrayList();
|
||||
List<DocumentInfo> docsForSend = new ArrayList<>();
|
||||
for (DocumentInfo doc: docs) {
|
||||
if (!Document.MIME_TYPE_DIR.equals(doc.mimeType)) {
|
||||
docsForSend.add(doc);
|
||||
@@ -774,8 +774,8 @@ public class DirectoryFragment extends Fragment {
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
|
||||
final ArrayList<String> mimeTypes = Lists.newArrayList();
|
||||
final ArrayList<Uri> uris = Lists.newArrayList();
|
||||
final ArrayList<String> mimeTypes = new ArrayList<>();
|
||||
final ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (DocumentInfo doc : docsForSend) {
|
||||
mimeTypes.add(doc.mimeType);
|
||||
uris.add(doc.derivedUri);
|
||||
@@ -956,7 +956,7 @@ public class DirectoryFragment extends Fragment {
|
||||
private final Context mContext;
|
||||
private final LayoutInflater mInflater;
|
||||
// TODO: Bring back support for footers.
|
||||
private final List<Footer> mFooters = Lists.newArrayList();
|
||||
private final List<Footer> mFooters = new ArrayList<>();
|
||||
|
||||
private Cursor mCursor;
|
||||
private int mCursorCount;
|
||||
@@ -1330,7 +1330,7 @@ public class DirectoryFragment extends Fragment {
|
||||
return MimePredicate.mimeMatches(state.acceptMimes, docMimeType);
|
||||
}
|
||||
|
||||
private @NonNull List<DocumentInfo> getSelectedDocuments() {
|
||||
private List<DocumentInfo> getSelectedDocuments() {
|
||||
Selection sel = mSelectionManager.getSelection(new Selection());
|
||||
return getItemsAsDocuments(sel);
|
||||
}
|
||||
@@ -1570,6 +1570,7 @@ public class DirectoryFragment extends Fragment {
|
||||
final Cursor cursor = mAdapter.getItem(position);
|
||||
checkNotNull(cursor, "Cursor cannot be null.");
|
||||
final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
|
||||
|
||||
return Lists.newArrayList(doc);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.BaseActivity.State.MODE_UNKNOWN;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_DISPLAY_NAME;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_LAST_MODIFIED;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_SIZE;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_UNKNOWN;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
|
||||
|
||||
import android.content.AsyncTaskLoader;
|
||||
@@ -31,8 +31,6 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.OperationCanceledException;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.DocumentsContract;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ContentProviderClient;
|
||||
@@ -26,15 +24,15 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -78,7 +76,7 @@ final class DocumentClipper {
|
||||
* Returns a list of Documents as decoded from Clipboard primary clipdata.
|
||||
* This should be run from inside an AsyncTask.
|
||||
*/
|
||||
public @NonNull List<DocumentInfo> getClippedDocuments() {
|
||||
public List<DocumentInfo> getClippedDocuments() {
|
||||
return getDocumentsFromClipData(mClipboard.getPrimaryClip());
|
||||
}
|
||||
|
||||
@@ -86,9 +84,9 @@ final class DocumentClipper {
|
||||
* Returns a list of Documents as decoded in clipData.
|
||||
* This should be run from inside an AsyncTask.
|
||||
*/
|
||||
public @NonNull List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
|
||||
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
|
||||
Preconditions.checkNotNull(clipData);
|
||||
final List<DocumentInfo> srcDocs = Lists.newArrayList();
|
||||
final List<DocumentInfo> srcDocs = new ArrayList<>();
|
||||
|
||||
int count = clipData.getItemCount();
|
||||
if (count == 0) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorString;
|
||||
|
||||
|
||||
@@ -23,13 +23,11 @@ import android.graphics.drawable.Drawable;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import com.google.android.collect.Maps;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IconUtils {
|
||||
|
||||
private static HashMap<String, Integer> sMimeIcons = Maps.newHashMap();
|
||||
private static HashMap<String, Integer> sMimeIcons = new HashMap<>();
|
||||
|
||||
private static void add(String mimeType, int resId) {
|
||||
if (sMimeIcons.put(mimeType, resId) != null) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import android.view.GestureDetector.OnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,8 +20,6 @@ import android.os.AsyncTask;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.google.android.collect.Lists;
|
||||
import com.google.android.collect.Maps;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,7 +30,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
public class ProviderExecutor extends Thread implements Executor {
|
||||
|
||||
@GuardedBy("sExecutors")
|
||||
private static HashMap<String, ProviderExecutor> sExecutors = Maps.newHashMap();
|
||||
private static HashMap<String, ProviderExecutor> sExecutors = new HashMap<>();
|
||||
|
||||
public static ProviderExecutor forAuthority(String authority) {
|
||||
synchronized (sExecutors) {
|
||||
@@ -53,7 +51,7 @@ public class ProviderExecutor extends Thread implements Executor {
|
||||
|
||||
private final LinkedBlockingQueue<Runnable> mQueue = new LinkedBlockingQueue<Runnable>();
|
||||
|
||||
private final ArrayList<WeakReference<Preemptable>> mPreemptable = Lists.newArrayList();
|
||||
private final ArrayList<WeakReference<Preemptable>> mPreemptable = new ArrayList<>();
|
||||
|
||||
private void preempt() {
|
||||
synchronized (mPreemptable) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.model.DocumentInfo.getCursorString;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipDescription;
|
||||
import android.content.ComponentName;
|
||||
@@ -28,6 +27,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.documentsui.BaseActivity.DocumentContext;
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.BaseActivity.State.SORT_ORDER_LAST_MODIFIED;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.AsyncTaskLoader;
|
||||
@@ -36,14 +36,14 @@ import android.util.Log;
|
||||
|
||||
import com.android.documentsui.BaseActivity.State;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.google.android.collect.Maps;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.google.common.util.concurrent.AbstractFuture;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -53,7 +53,7 @@ import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
|
||||
private static final boolean LOGD = true;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
// TODO: clean up cursor ownership so background thread doesn't traverse
|
||||
// previously returned cursors for filtering/sorting; this currently races
|
||||
@@ -81,7 +81,7 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
|
||||
private final RootsCache mRoots;
|
||||
private final State mState;
|
||||
|
||||
private final HashMap<RootInfo, RecentTask> mTasks = Maps.newHashMap();
|
||||
private final HashMap<RootInfo, RecentTask> mTasks = new HashMap<>();
|
||||
|
||||
private final int mSortOrder = State.SORT_ORDER_LAST_MODIFIED;
|
||||
|
||||
@@ -196,7 +196,7 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
|
||||
|
||||
// Collect all finished tasks
|
||||
boolean allDone = true;
|
||||
List<Cursor> cursors = Lists.newArrayList();
|
||||
List<Cursor> cursors = new ArrayList<>();
|
||||
for (RecentTask task : mTasks.values()) {
|
||||
if (task.isDone()) {
|
||||
try {
|
||||
@@ -221,7 +221,7 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
|
||||
}
|
||||
}
|
||||
|
||||
if (LOGD) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
@@ -50,7 +50,6 @@ import com.android.documentsui.RecentsProvider.RecentColumns;
|
||||
import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.DurableUtils;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
@@ -157,7 +156,7 @@ public class RecentsCreateFragment extends Fragment {
|
||||
@Override
|
||||
public List<DocumentStack> loadInBackground(Uri uri, CancellationSignal signal) {
|
||||
final Collection<RootInfo> matchingRoots = mRoots.getMatchingRootsBlocking(mState);
|
||||
final ArrayList<DocumentStack> result = Lists.newArrayList();
|
||||
final ArrayList<DocumentStack> result = new ArrayList<>();
|
||||
|
||||
final ContentResolver resolver = getContext().getContentResolver();
|
||||
final Cursor cursor = resolver.query(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
|
||||
import android.content.ContentProviderClient;
|
||||
import android.content.ContentResolver;
|
||||
@@ -39,14 +39,14 @@ import android.util.Log;
|
||||
import com.android.documentsui.BaseActivity.State;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.google.android.collect.Lists;
|
||||
import com.google.android.collect.Sets;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -74,10 +74,10 @@ public class RootsCache {
|
||||
@GuardedBy("mLock")
|
||||
private Multimap<String, RootInfo> mRoots = ArrayListMultimap.create();
|
||||
@GuardedBy("mLock")
|
||||
private HashSet<String> mStoppedAuthorities = Sets.newHashSet();
|
||||
private HashSet<String> mStoppedAuthorities = new HashSet<>();
|
||||
|
||||
@GuardedBy("mObservedAuthorities")
|
||||
private final HashSet<String> mObservedAuthorities = Sets.newHashSet();
|
||||
private final HashSet<String> mObservedAuthorities = new HashSet<>();
|
||||
|
||||
public RootsCache(Context context) {
|
||||
mContext = context;
|
||||
@@ -159,7 +159,7 @@ public class RootsCache {
|
||||
private final String mFilterPackage;
|
||||
|
||||
private final Multimap<String, RootInfo> mTaskRoots = ArrayListMultimap.create();
|
||||
private final HashSet<String> mTaskStoppedAuthorities = Sets.newHashSet();
|
||||
private final HashSet<String> mTaskStoppedAuthorities = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Update all roots.
|
||||
@@ -251,7 +251,7 @@ public class RootsCache {
|
||||
}
|
||||
}
|
||||
|
||||
final List<RootInfo> roots = Lists.newArrayList();
|
||||
final List<RootInfo> roots = new ArrayList<>();
|
||||
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
|
||||
|
||||
ContentProviderClient client = null;
|
||||
@@ -350,7 +350,7 @@ public class RootsCache {
|
||||
|
||||
@VisibleForTesting
|
||||
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
|
||||
final List<RootInfo> matching = Lists.newArrayList();
|
||||
final List<RootInfo> matching = new ArrayList<>();
|
||||
for (RootInfo root : roots) {
|
||||
final boolean supportsCreate = (root.flags & Root.FLAG_SUPPORTS_CREATE) != 0;
|
||||
final boolean supportsIsChild = (root.flags & Root.FLAG_SUPPORTS_IS_CHILD) != 0;
|
||||
|
||||
@@ -44,8 +44,8 @@ import android.widget.TextView;
|
||||
import com.android.documentsui.BaseActivity.State;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -293,8 +293,8 @@ public class RootsFragment extends Fragment {
|
||||
RootItem audio = null;
|
||||
RootItem downloads = null;
|
||||
|
||||
final List<RootInfo> clouds = Lists.newArrayList();
|
||||
final List<RootInfo> locals = Lists.newArrayList();
|
||||
final List<RootInfo> clouds = new ArrayList<>();
|
||||
final List<RootInfo> locals = new ArrayList<>();
|
||||
|
||||
for (RootInfo root : roots) {
|
||||
if (root.isRecents()) {
|
||||
@@ -338,7 +338,7 @@ public class RootsFragment extends Fragment {
|
||||
final List<ResolveInfo> infos = pm.queryIntentActivities(
|
||||
includeApps, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
|
||||
final List<AppItem> apps = Lists.newArrayList();
|
||||
final List<AppItem> apps = new ArrayList<>();
|
||||
|
||||
// Omit ourselves from the list
|
||||
for (ResolveInfo info : infos) {
|
||||
|
||||
@@ -22,8 +22,6 @@ import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -31,7 +29,7 @@ import java.util.ArrayList;
|
||||
* provide a header, and correctly handling item types across child adapters.
|
||||
*/
|
||||
public class SectionedListAdapter extends BaseAdapter {
|
||||
private ArrayList<SectionAdapter> mSections = Lists.newArrayList();
|
||||
private ArrayList<SectionAdapter> mSections = new ArrayList<>();
|
||||
|
||||
public interface SectionAdapter extends ListAdapter {
|
||||
public View getHeaderView(View convertView, ViewGroup parent);
|
||||
|
||||
24
packages/DocumentsUI/src/com/android/documentsui/Shared.java
Normal file
24
packages/DocumentsUI/src/com/android/documentsui/Shared.java
Normal 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.
|
||||
*/
|
||||
|
||||
package com.android.documentsui;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final class Shared {
|
||||
public static final String TAG = "Documents";
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import static com.android.documentsui.DirectoryFragment.ANIM_DOWN;
|
||||
import static com.android.documentsui.DirectoryFragment.ANIM_NONE;
|
||||
import static com.android.documentsui.DirectoryFragment.ANIM_UP;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@@ -33,6 +32,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Root;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
|
||||
@@ -27,16 +27,16 @@ import android.os.OperationCanceledException;
|
||||
* changes while started, manages {@link CancellationSignal}, and caches
|
||||
* returned results.
|
||||
*/
|
||||
public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
public abstract class UriDerivativeLoader<Param, Res> extends AsyncTaskLoader<Res> {
|
||||
final ForceLoadContentObserver mObserver;
|
||||
|
||||
private final P mParam;
|
||||
private final Param mParam;
|
||||
|
||||
private R mResult;
|
||||
private Res mResult;
|
||||
private CancellationSignal mCancellationSignal;
|
||||
|
||||
@Override
|
||||
public final R loadInBackground() {
|
||||
public final Res loadInBackground() {
|
||||
synchronized (this) {
|
||||
if (isLoadInBackgroundCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
@@ -52,7 +52,7 @@ public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract R loadInBackground(P param, CancellationSignal signal);
|
||||
public abstract Res loadInBackground(Param param, CancellationSignal signal);
|
||||
|
||||
@Override
|
||||
public void cancelLoadInBackground() {
|
||||
@@ -66,12 +66,12 @@ public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliverResult(R result) {
|
||||
public void deliverResult(Res result) {
|
||||
if (isReset()) {
|
||||
closeQuietly(result);
|
||||
return;
|
||||
}
|
||||
R oldResult = mResult;
|
||||
Res oldResult = mResult;
|
||||
mResult = result;
|
||||
|
||||
if (isStarted()) {
|
||||
@@ -83,7 +83,7 @@ public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
}
|
||||
}
|
||||
|
||||
public UriDerivativeLoader(Context context, P param) {
|
||||
public UriDerivativeLoader(Context context, Param param) {
|
||||
super(context);
|
||||
mObserver = new ForceLoadContentObserver();
|
||||
mParam = param;
|
||||
@@ -105,7 +105,7 @@ public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled(R result) {
|
||||
public void onCanceled(Res result) {
|
||||
closeQuietly(result);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class UriDerivativeLoader<P, R> extends AsyncTaskLoader<R> {
|
||||
getContext().getContentResolver().unregisterContentObserver(mObserver);
|
||||
}
|
||||
|
||||
private void closeQuietly(R result) {
|
||||
private void closeQuietly(Res result) {
|
||||
if (result instanceof AutoCloseable) {
|
||||
try {
|
||||
((AutoCloseable) result).close();
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.provider.DocumentsContract.Root;
|
||||
import android.provider.DocumentsProvider;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.documentsui.model;
|
||||
|
||||
import static com.android.documentsui.DocumentsActivity.TAG;
|
||||
import static com.android.documentsui.Shared.TAG;
|
||||
|
||||
import android.os.BadParcelableException;
|
||||
import android.os.Parcel;
|
||||
|
||||
@@ -21,7 +21,8 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.android.documentsui.BaseActivity.State;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ import android.provider.DocumentsProvider;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.collect.Maps;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -101,7 +99,7 @@ public class StubProvider extends DocumentsProvider {
|
||||
});
|
||||
}
|
||||
// Create new roots.
|
||||
mRoots = Maps.newHashMap();
|
||||
mRoots = new HashMap<>();
|
||||
for (String rootId : rootIds) {
|
||||
final RootInfo rootInfo = new RootInfo(rootId, getSize(rootId));
|
||||
mRoots.put(rootId, rootInfo);
|
||||
|
||||
Reference in New Issue
Block a user