Merge "Massage code to better support Files overlay." into nyc-dev

This commit is contained in:
Steve McKay
2016-04-06 18:44:58 +00:00
committed by Android (Google) Code Review
15 changed files with 96 additions and 50 deletions

View File

@@ -43,9 +43,9 @@
<activity
android:name=".LauncherActivity"
android:theme="@android:style/Theme.NoDisplay"
android:icon="@mipmap/ic_launcher_download"
android:label="@string/downloads_label">
android:label="@string/downloads_label"
android:icon="@mipmap/ic_launcher_downloads"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -54,22 +54,22 @@
<activity
android:name=".FilesActivity"
android:theme="@style/DocumentsTheme"
android:icon="@mipmap/ic_launcher_download"
android:label="@string/downloads_label"
android:documentLaunchMode="intoExisting">
android:icon="@mipmap/ic_launcher_downloads"
android:documentLaunchMode="intoExisting"
android:theme="@style/DocumentsTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW_DOWNLOADS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.action.BROWSE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.document/root" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW_DOWNLOADS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -20,13 +20,15 @@
<!-- Intentionally unset. Vendors should set this in an overlay. -->
<string name="trusted_quick_viewer_package" translatable="false"></string>
<!-- overridden for RTL langs -->
<bool name="list_divider_inset_left">true</bool>
<!-- Indicates if the home directory should be hidden in the roots list, that is presented
in the drawer/left side panel ) -->
<bool name="home_root_hidden">true</bool>
<!-- Indicates if the advanced roots like internal storage should be shown in the roots list.
When enabled there is no menu option to toggle internal storage visibility. -->
<bool name="advanced_roots_shown">false</bool>
<!-- Flags setup as productivity oriented in which case Downloads app will be presented
as Files app. Including showing of the Documents and "advanced" roots. -->
<bool name="productivity_device">false</bool>
<!-- Indicates if search view is taking the whole toolbar space -->
<bool name="full_bar_search_view">true</bool>
</resources>

View File

@@ -18,9 +18,6 @@
<!-- Title of the documents application [CHAR LIMIT=32] -->
<string name="app_label">Documents</string>
<!-- Title of the standalone files activity. [CHAR LIMIT=32] -->
<string name="files_label">Files</string>
<!-- Title of the standalone downloads activity. [CHAR LIMIT=32] -->
<string name="downloads_label">Downloads</string>

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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.");

View File

@@ -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);
}
}

View File

@@ -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<FilesActivity> {
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");
}
}