From 17f7e5891cbe86fc6cacae045a4edd3e41f8d5ee Mon Sep 17 00:00:00 2001 From: Steve McKay Date: Mon, 4 Apr 2016 15:26:48 -0700 Subject: Massage code to better support Files overlay. Also, allow "productivity_mode" config to be enabled via intent extra as a developement aide. Bug: 28006206 Change-Id: I7be8d96a0e924f9ce8023347e051d28d69a0eec9 --- AndroidManifest.xml | 18 ++++---- res/mipmap-hdpi/ic_launcher_download.png | Bin 4473 -> 0 bytes res/mipmap-hdpi/ic_launcher_downloads.png | Bin 0 -> 4473 bytes res/mipmap-mdpi/ic_launcher_download.png | Bin 2818 -> 0 bytes res/mipmap-mdpi/ic_launcher_downloads.png | Bin 0 -> 2818 bytes res/mipmap-xhdpi/ic_launcher_download.png | Bin 6351 -> 0 bytes res/mipmap-xhdpi/ic_launcher_downloads.png | Bin 0 -> 6351 bytes res/mipmap-xxhdpi/ic_launcher_download.png | Bin 10361 -> 0 bytes res/mipmap-xxhdpi/ic_launcher_downloads.png | Bin 0 -> 10361 bytes res/mipmap-xxxhdpi/ic_launcher_download.png | Bin 14962 -> 0 bytes res/mipmap-xxxhdpi/ic_launcher_downloads.png | Bin 0 -> 14962 bytes res/values/config.xml | 14 +++--- res/values/strings.xml | 3 -- src/com/android/documentsui/BaseActivity.java | 18 +++----- src/com/android/documentsui/DocumentsActivity.java | 4 +- src/com/android/documentsui/FilesActivity.java | 5 ++- src/com/android/documentsui/LauncherActivity.java | 19 +++++++- src/com/android/documentsui/RootsFragment.java | 5 ++- src/com/android/documentsui/Shared.java | 49 +++++++++++++++++---- .../android/documentsui/FilesActivityUiTest.java | 9 ++-- 20 files changed, 95 insertions(+), 49 deletions(-) delete mode 100644 res/mipmap-hdpi/ic_launcher_download.png create mode 100644 res/mipmap-hdpi/ic_launcher_downloads.png delete mode 100644 res/mipmap-mdpi/ic_launcher_download.png create mode 100644 res/mipmap-mdpi/ic_launcher_downloads.png delete mode 100644 res/mipmap-xhdpi/ic_launcher_download.png create mode 100644 res/mipmap-xhdpi/ic_launcher_downloads.png delete mode 100644 res/mipmap-xxhdpi/ic_launcher_download.png create mode 100644 res/mipmap-xxhdpi/ic_launcher_downloads.png delete mode 100644 res/mipmap-xxxhdpi/ic_launcher_download.png create mode 100644 res/mipmap-xxxhdpi/ic_launcher_downloads.png diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 14609b21d..69912ab12 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -43,9 +43,9 @@ + android:label="@string/downloads_label" + android:icon="@mipmap/ic_launcher_downloads" + android:theme="@android:style/Theme.NoDisplay"> @@ -54,21 +54,21 @@ + android:icon="@mipmap/ic_launcher_downloads" + android:documentLaunchMode="intoExisting" + android:theme="@style/DocumentsTheme"> - + + - + - diff --git a/res/mipmap-hdpi/ic_launcher_download.png b/res/mipmap-hdpi/ic_launcher_download.png deleted file mode 100644 index f958bbd3c..000000000 Binary files a/res/mipmap-hdpi/ic_launcher_download.png and /dev/null differ diff --git a/res/mipmap-hdpi/ic_launcher_downloads.png b/res/mipmap-hdpi/ic_launcher_downloads.png new file mode 100644 index 000000000..f958bbd3c Binary files /dev/null and b/res/mipmap-hdpi/ic_launcher_downloads.png differ diff --git a/res/mipmap-mdpi/ic_launcher_download.png b/res/mipmap-mdpi/ic_launcher_download.png deleted file mode 100644 index f2e937663..000000000 Binary files a/res/mipmap-mdpi/ic_launcher_download.png and /dev/null differ diff --git a/res/mipmap-mdpi/ic_launcher_downloads.png b/res/mipmap-mdpi/ic_launcher_downloads.png new file mode 100644 index 000000000..f2e937663 Binary files /dev/null and b/res/mipmap-mdpi/ic_launcher_downloads.png differ diff --git a/res/mipmap-xhdpi/ic_launcher_download.png b/res/mipmap-xhdpi/ic_launcher_download.png deleted file mode 100644 index 4dc533638..000000000 Binary files a/res/mipmap-xhdpi/ic_launcher_download.png and /dev/null differ diff --git a/res/mipmap-xhdpi/ic_launcher_downloads.png b/res/mipmap-xhdpi/ic_launcher_downloads.png new file mode 100644 index 000000000..4dc533638 Binary files /dev/null and b/res/mipmap-xhdpi/ic_launcher_downloads.png differ diff --git a/res/mipmap-xxhdpi/ic_launcher_download.png b/res/mipmap-xxhdpi/ic_launcher_download.png deleted file mode 100644 index 871629096..000000000 Binary files a/res/mipmap-xxhdpi/ic_launcher_download.png and /dev/null differ diff --git a/res/mipmap-xxhdpi/ic_launcher_downloads.png b/res/mipmap-xxhdpi/ic_launcher_downloads.png new file mode 100644 index 000000000..871629096 Binary files /dev/null and b/res/mipmap-xxhdpi/ic_launcher_downloads.png differ diff --git a/res/mipmap-xxxhdpi/ic_launcher_download.png b/res/mipmap-xxxhdpi/ic_launcher_download.png deleted file mode 100644 index f5be21991..000000000 Binary files a/res/mipmap-xxxhdpi/ic_launcher_download.png and /dev/null differ diff --git a/res/mipmap-xxxhdpi/ic_launcher_downloads.png b/res/mipmap-xxxhdpi/ic_launcher_downloads.png new file mode 100644 index 000000000..f5be21991 Binary files /dev/null and b/res/mipmap-xxxhdpi/ic_launcher_downloads.png differ diff --git a/res/values/config.xml b/res/values/config.xml index 6590bbeda..f0cab0872 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -20,13 +20,15 @@ + + true - - true - - false + + + false + true + diff --git a/res/values/strings.xml b/res/values/strings.xml index fb557caf8..3754d59a9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -18,9 +18,6 @@ Documents - - Files - Downloads diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 87136ef35..938805854 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -19,10 +19,9 @@ package com.android.documentsui; import static com.android.documentsui.Shared.DEBUG; import static com.android.documentsui.Shared.EXTRA_BENCHMARK; import static com.android.documentsui.State.ACTION_CREATE; +import static com.android.documentsui.State.ACTION_GET_CONTENT; import static com.android.documentsui.State.ACTION_OPEN; import static com.android.documentsui.State.ACTION_OPEN_TREE; -import static com.android.documentsui.State.ACTION_GET_CONTENT; -import static com.android.documentsui.State.ACTION_PICK_COPY_DESTINATION; import static com.android.documentsui.State.MODE_GRID; import android.app.Activity; @@ -37,14 +36,12 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; -import android.os.MessageQueue; import android.os.MessageQueue.IdleHandler; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Root; import android.support.annotation.CallSuper; import android.support.annotation.LayoutRes; import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; @@ -228,8 +225,7 @@ public abstract class BaseActivity extends Activity includeState(state); // Advanced roots are shown by deafult without menu option if forced by config or intent. - state.showAdvanced = getResources().getBoolean(R.bool.advanced_roots_shown) - || intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); + state.showAdvanced = Shared.shouldShowDeviceRoot(this, intent); // Menu option is shown for whitelisted intents if advanced roots are not shown by default. state.showAdvancedOption = !state.showAdvanced && (state.action == ACTION_OPEN || @@ -478,11 +474,11 @@ public abstract class BaseActivity extends Activity * Method can be overridden if the change of the behavior of the the child activity is needed. */ public Uri getDefaultRoot() { - return Shared.isHomeRootHidden(this) - ? DocumentsContract.buildRootUri("com.android.providers.downloads.documents", - "downloads") - : DocumentsContract.buildHomeUri(); - } + return Shared.shouldShowDocumentsRoot(this, getIntent()) + ? DocumentsContract.buildHomeUri() + : DocumentsContract.buildRootUri( + "com.android.providers.downloads.documents", "downloads"); + } void setDisplayAdvancedDevices(boolean display) { mState.showAdvanced = display; diff --git a/src/com/android/documentsui/DocumentsActivity.java b/src/com/android/documentsui/DocumentsActivity.java index 5788420a0..40b54d34e 100644 --- a/src/com/android/documentsui/DocumentsActivity.java +++ b/src/com/android/documentsui/DocumentsActivity.java @@ -203,8 +203,8 @@ public class DocumentsActivity extends BaseActivity { mState.action == ACTION_PICK_COPY_DESTINATION) { title = getResources().getString(R.string.title_save); } else { - // If all else fails, just call it "Downloads". - title = getResources().getString(R.string.downloads_label); + // If all else fails, just call it "Documents". + title = getResources().getString(R.string.app_label); } } diff --git a/src/com/android/documentsui/FilesActivity.java b/src/com/android/documentsui/FilesActivity.java index d4439d8b4..30680acff 100644 --- a/src/com/android/documentsui/FilesActivity.java +++ b/src/com/android/documentsui/FilesActivity.java @@ -180,7 +180,10 @@ public class FilesActivity extends BaseActivity { @Override public String getDrawerTitle() { - return getResources().getString(R.string.downloads_label); + Intent intent = getIntent(); + return (intent != null && intent.hasExtra(Intent.EXTRA_TITLE)) + ? intent.getStringExtra(Intent.EXTRA_TITLE) + : getTitle().toString(); } @Override diff --git a/src/com/android/documentsui/LauncherActivity.java b/src/com/android/documentsui/LauncherActivity.java index 7930c28fc..5cb6ca347 100644 --- a/src/com/android/documentsui/LauncherActivity.java +++ b/src/com/android/documentsui/LauncherActivity.java @@ -87,9 +87,24 @@ public class LauncherActivity extends Activity { startActivity(intent); } - static final Intent createLaunchIntent(Context context) { - Intent intent = new Intent(context, FilesActivity.class); + static final Intent createLaunchIntent(Activity activity) { + Intent intent = new Intent(activity, FilesActivity.class); intent.setData(buildLaunchUri()); + + // Relay any config overrides bits present in the original intent. + Intent original = activity.getIntent(); + if (original != null) { + if (original.hasExtra(Shared.EXTRA_PRODUCTIVITY_MODE)) { + intent.putExtra( + Shared.EXTRA_PRODUCTIVITY_MODE, + original.getBooleanExtra(Shared.EXTRA_PRODUCTIVITY_MODE, false)); + } + if (original.hasExtra(Intent.EXTRA_TITLE)) { + intent.putExtra( + Intent.EXTRA_TITLE, + original.getStringExtra(Intent.EXTRA_TITLE)); + } + } return intent; } diff --git a/src/com/android/documentsui/RootsFragment.java b/src/com/android/documentsui/RootsFragment.java index 5f665c0e4..8bbcc306a 100644 --- a/src/com/android/documentsui/RootsFragment.java +++ b/src/com/android/documentsui/RootsFragment.java @@ -17,8 +17,8 @@ package com.android.documentsui; import static com.android.documentsui.Shared.DEBUG; -import static com.android.documentsui.State.ACTION_OPEN_TREE; +import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; @@ -319,7 +319,8 @@ public class RootsFragment extends Fragment { for (final RootInfo root : roots) { final RootItem item = new RootItem(root); - if (root.isHome() && Shared.isHomeRootHidden(context)) { + if (root.isHome() && + !Shared.shouldShowDocumentsRoot(context, ((Activity) context).getIntent())) { continue; } else if (root.isLibrary()) { if (DEBUG) Log.d(TAG, "Adding " + root + " as library."); diff --git a/src/com/android/documentsui/Shared.java b/src/com/android/documentsui/Shared.java index 2c60d4a32..1ba836a7f 100644 --- a/src/com/android/documentsui/Shared.java +++ b/src/com/android/documentsui/Shared.java @@ -16,19 +16,16 @@ package com.android.documentsui; +import android.app.AlertDialog; import android.content.Context; +import android.content.Intent; import android.content.res.Configuration; +import android.provider.DocumentsContract; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.Time; import android.view.WindowManager; -import com.android.documentsui.State.ActionType; - -import static com.android.documentsui.State.ACTION_OPEN_TREE; - -import android.app.AlertDialog; - import java.text.Collator; import java.util.ArrayList; import java.util.List; @@ -44,11 +41,22 @@ public final class Shared { public static final String ACTION_PICK_COPY_DESTINATION = "com.android.documentsui.PICK_COPY_DESTINATION"; + /** + * Extra flag allowing app to be opened in productivity mode (less downloadsy). + * Useful developers and the likes. When set to true overrides the default + * config value of productivity_device. + */ + public static final String EXTRA_PRODUCTIVITY_MODE = "com.android.documentsui.PRODUCTIVITY"; + /** * Extra boolean flag for {@link ACTION_PICK_COPY_DESTINATION}, which * specifies if the destination directory needs to create new directory or not. */ public static final String EXTRA_DIRECTORY_COPY = "com.android.documentsui.DIRECTORY_COPY"; + + /** + * Extra flag used to store the current stack so user opens in right spot. + */ public static final String EXTRA_STACK = "com.android.documentsui.STACK"; /** @@ -175,10 +183,33 @@ public final class Shared { } /* - * Indicates if the home directory should be hidden in the roots list. + * Returns true if app is running in "productivity mode". */ - public static boolean isHomeRootHidden(Context context) { - return context.getResources().getBoolean(R.bool.home_root_hidden); + public static boolean productivityMode(Context context) { + return context.getResources().getBoolean(R.bool.productivity_device); } + /* + * Returns true if app is running in "productivity mode". + */ + private static boolean isProductivityMode(Context context, Intent intent) { + return intent.getBooleanExtra( + Shared.EXTRA_PRODUCTIVITY_MODE, + context.getResources().getBoolean(R.bool.productivity_device)); + } + + /* + * Returns true if "Documents" root should be shown. + */ + public static boolean shouldShowDocumentsRoot(Context context, Intent intent) { + return isProductivityMode(context, intent); + } + + /* + * Returns true if device root should be shown. + */ + public static boolean shouldShowDeviceRoot(Context context, Intent intent) { + return isProductivityMode(context, intent) + || intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); + } } diff --git a/tests/src/com/android/documentsui/FilesActivityUiTest.java b/tests/src/com/android/documentsui/FilesActivityUiTest.java index f2949196f..69f0e677e 100644 --- a/tests/src/com/android/documentsui/FilesActivityUiTest.java +++ b/tests/src/com/android/documentsui/FilesActivityUiTest.java @@ -22,8 +22,10 @@ import static com.android.documentsui.StubProvider.ROOT_1_ID; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.RemoteException; +import android.provider.DocumentsContract; import android.support.test.uiautomator.Configurator; import android.support.test.uiautomator.UiObject; import android.test.suitebuilder.annotation.LargeTest; @@ -69,11 +71,10 @@ public class FilesActivityUiTest extends ActivityTest { ROOT_1_ID); // Separate logic for "Documents" root, which presence depends on the config setting - boolean homeRootHidden = context.getResources().getBoolean(R.bool.home_root_hidden); - if (homeRootHidden) { - bots.roots.assertRootsAbsent("Documents"); - } else { + if (Shared.shouldShowDocumentsRoot(context, new Intent(DocumentsContract.ACTION_BROWSE))) { bots.roots.assertRootsPresent("Documents"); + } else { + bots.roots.assertRootsAbsent("Documents"); } } -- cgit v1.2.3-59-g8ed1b