Merge "Switch DocumentsUI over from Toasts to Snackbars."
diff --git a/packages/DocumentsUI/res/layout/drawer_layout.xml b/packages/DocumentsUI/res/layout/drawer_layout.xml
index dec4e92..0dac0d5 100644
--- a/packages/DocumentsUI/res/layout/drawer_layout.xml
+++ b/packages/DocumentsUI/res/layout/drawer_layout.xml
@@ -14,62 +14,71 @@
limitations under the License.
-->
-<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/drawer_layout"
+<!-- CoordinatorLayout is necessary for various components (e.g. Snackbars, and
+ floating action buttons) to operate correctly. -->
+<android.support.design.widget.CoordinatorLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:id="@+id/coordinator_layout">
- <LinearLayout
+ <android.support.v4.widget.DrawerLayout
+ android:id="@+id/drawer_layout"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
+ android:layout_height="match_parent">
- <com.android.documentsui.DocumentsToolBar
- android:id="@+id/toolbar"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="?android:attr/actionBarSize"
- android:background="?android:attr/colorPrimary"
- android:elevation="8dp"
- android:theme="?actionBarTheme"
- android:popupTheme="?actionBarPopupTheme">
+ android:layout_height="match_parent"
+ android:orientation="vertical">
- <Spinner
- android:id="@+id/stack"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="4dp"
- android:overlapAnchor="true" />
+ <com.android.documentsui.DocumentsToolBar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="?android:attr/colorPrimary"
+ android:elevation="8dp"
+ android:theme="?actionBarTheme"
+ android:popupTheme="?actionBarPopupTheme">
- </com.android.documentsui.DocumentsToolBar>
+ <Spinner
+ android:id="@+id/stack"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:overlapAnchor="true" />
- <include layout="@layout/directory_cluster"/>
+ </com.android.documentsui.DocumentsToolBar>
- </LinearLayout>
+ <include layout="@layout/directory_cluster"/>
- <LinearLayout
- android:id="@+id/drawer_roots"
- android:layout_width="256dp"
- android:layout_height="match_parent"
- android:layout_gravity="start"
- android:orientation="vertical"
- android:elevation="16dp"
- android:background="@*android:color/white">
+ </LinearLayout>
- <Toolbar
- android:id="@+id/roots_toolbar"
- android:layout_width="match_parent"
- android:layout_height="?android:attr/actionBarSize"
- android:background="?android:attr/colorPrimary"
- android:elevation="8dp"
- android:theme="?actionBarTheme"
- android:popupTheme="?actionBarPopupTheme" />
+ <LinearLayout
+ android:id="@+id/drawer_roots"
+ android:layout_width="256dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"
+ android:orientation="vertical"
+ android:elevation="16dp"
+ android:background="@*android:color/white">
- <FrameLayout
- android:id="@+id/container_roots"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1" />
+ <Toolbar
+ android:id="@+id/roots_toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="?android:attr/colorPrimary"
+ android:elevation="8dp"
+ android:theme="?actionBarTheme"
+ android:popupTheme="?actionBarPopupTheme" />
- </LinearLayout>
+ <FrameLayout
+ android:id="@+id/container_roots"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1" />
-</android.support.v4.widget.DrawerLayout>
+ </LinearLayout>
+
+ </android.support.v4.widget.DrawerLayout>
+</android.support.design.widget.CoordinatorLayout>
diff --git a/packages/DocumentsUI/res/layout/fixed_layout.xml b/packages/DocumentsUI/res/layout/fixed_layout.xml
index eba9af4..403c667 100644
--- a/packages/DocumentsUI/res/layout/fixed_layout.xml
+++ b/packages/DocumentsUI/res/layout/fixed_layout.xml
@@ -14,49 +14,59 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<!-- CoordinatorLayout is necessary for various components (e.g. Snackbars, and
+ floating action buttons) to operate correctly. -->
+<android.support.design.widget.CoordinatorLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical">
+ android:id="@+id/coordinator_layout">
- <com.android.documentsui.DocumentsToolBar
- android:id="@+id/toolbar"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="?android:attr/actionBarSize"
- android:background="?android:attr/colorPrimary"
- android:elevation="8dp"
- android:theme="?actionBarTheme"
- android:popupTheme="?actionBarPopupTheme">
+ android:layout_height="match_parent"
+ android:orientation="vertical">
- <Spinner
- android:id="@+id/stack"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="4dp"
- android:overlapAnchor="true" />
-
- </com.android.documentsui.DocumentsToolBar>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:orientation="horizontal"
- android:baselineAligned="false"
- android:divider="?android:attr/dividerVertical"
- android:showDividers="middle">
-
- <FrameLayout
- android:id="@+id/container_roots"
- android:layout_width="256dp"
- android:layout_height="match_parent" />
-
- <include layout="@layout/directory_cluster"
- android:layout_width="0dp"
- android:layout_weight="1"
+ <com.android.documentsui.DocumentsToolBar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="?android:attr/colorPrimary"
android:elevation="8dp"
- android:background="@color/material_grey_50" />
+ android:theme="?actionBarTheme"
+ android:popupTheme="?actionBarPopupTheme">
+
+ <Spinner
+ android:id="@+id/stack"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:overlapAnchor="true" />
+
+ </com.android.documentsui.DocumentsToolBar>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:orientation="horizontal"
+ android:baselineAligned="false"
+ android:divider="?android:attr/dividerVertical"
+ android:showDividers="middle">
+
+ <FrameLayout
+ android:id="@+id/container_roots"
+ android:layout_width="256dp"
+ android:layout_height="match_parent" />
+
+ <include layout="@layout/directory_cluster"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:elevation="8dp"
+ android:background="@color/material_grey_50" />
+
+ </LinearLayout>
</LinearLayout>
-</LinearLayout>
+</android.support.design.widget.CoordinatorLayout>
diff --git a/packages/DocumentsUI/res/layout/single_pane_layout.xml b/packages/DocumentsUI/res/layout/single_pane_layout.xml
index 20c3232..c5a5745 100644
--- a/packages/DocumentsUI/res/layout/single_pane_layout.xml
+++ b/packages/DocumentsUI/res/layout/single_pane_layout.xml
@@ -14,29 +14,39 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<!-- CoordinatorLayout is necessary for various components (e.g. Snackbars, and
+ floating action buttons) to operate correctly. -->
+<android.support.design.widget.CoordinatorLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical">
+ android:id="@+id/coordinator_layout">
- <com.android.documentsui.DocumentsToolBar
- android:id="@+id/toolbar"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="?android:attr/actionBarSize"
- android:background="?android:attr/colorPrimary"
- android:elevation="8dp"
- android:theme="?actionBarTheme"
- android:popupTheme="?actionBarPopupTheme">
+ android:layout_height="match_parent"
+ android:orientation="vertical">
- <Spinner
- android:id="@+id/stack"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="4dp"
- android:overlapAnchor="true" />
+ <com.android.documentsui.DocumentsToolBar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="?android:attr/colorPrimary"
+ android:elevation="8dp"
+ android:theme="?actionBarTheme"
+ android:popupTheme="?actionBarPopupTheme">
- </com.android.documentsui.DocumentsToolBar>
+ <Spinner
+ android:id="@+id/stack"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:overlapAnchor="true" />
- <include layout="@layout/directory_cluster"/>
+ </com.android.documentsui.DocumentsToolBar>
-</LinearLayout>
+ <include layout="@layout/directory_cluster"/>
+
+ </LinearLayout>
+
+</android.support.design.widget.CoordinatorLayout>
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
index f1492dc..815fbfe 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
@@ -20,6 +20,7 @@
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
+import android.app.Activity;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
@@ -37,6 +38,7 @@
import android.os.SystemClock;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
+import android.support.design.widget.Snackbar;
import android.text.format.DateUtils;
import android.util.Log;
import android.widget.Toast;
@@ -107,10 +109,10 @@
* @param srcDocs A list of src files to copy.
* @param dstStack The copy destination stack.
*/
- public static void start(Context context, List<DocumentInfo> srcDocs, DocumentStack dstStack,
+ public static void start(Activity activity, List<DocumentInfo> srcDocs, DocumentStack dstStack,
int mode) {
- final Resources res = context.getResources();
- final Intent copyIntent = new Intent(context, CopyService.class);
+ final Resources res = activity.getResources();
+ final Intent copyIntent = new Intent(activity, CopyService.class);
copyIntent.putParcelableArrayListExtra(
EXTRA_SRC_LIST, new ArrayList<DocumentInfo>(srcDocs));
copyIntent.putExtra(EXTRA_STACK, (Parcelable) dstStack);
@@ -118,10 +120,10 @@
int toastMessage = (mode == TRANSFER_MODE_COPY) ? R.plurals.copy_begin
: R.plurals.move_begin;
- Toast.makeText(context,
+ Shared.makeSnackbar(activity,
res.getQuantityString(toastMessage, srcDocs.size(), srcDocs.size()),
- Toast.LENGTH_SHORT).show();
- context.startService(copyIntent);
+ Snackbar.LENGTH_SHORT).show();
+ activity.startService(copyIntent);
}
@Override
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
index e408e6e..9f44516 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
@@ -32,6 +32,7 @@
import android.os.Bundle;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
+import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -39,7 +40,6 @@
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
-import android.widget.Toast;
import com.android.documentsui.model.DocumentInfo;
@@ -147,7 +147,7 @@
// Navigate into newly created child
mActivity.onDirectoryCreated(result);
} else {
- Toast.makeText(mActivity, R.string.create_error, Toast.LENGTH_SHORT).show();
+ Shared.makeSnackbar(mActivity, R.string.create_error, Snackbar.LENGTH_SHORT).show();
}
mActivity.setPending(false);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
index 5eacf21..2893cd2 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
@@ -91,7 +91,6 @@
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.TextView;
-import android.widget.Toast;
import com.android.documentsui.BaseActivity.DocumentContext;
import com.android.documentsui.MultiSelectManager.Selection;
@@ -805,8 +804,8 @@
mModel.markForDeletion(selected);
- Activity activity = getActivity();
- Snackbar.make(this.getView(), message, Snackbar.LENGTH_LONG)
+ final Activity activity = getActivity();
+ Shared.makeSnackbar(activity, message, Snackbar.LENGTH_LONG)
.setAction(
R.string.undo,
new android.view.View.OnClickListener() {
@@ -824,8 +823,8 @@
new Runnable() {
@Override
public void run() {
- Snackbar.make(
- DirectoryFragment.this.getView(),
+ Shared.makeSnackbar(
+ activity,
R.string.toast_failed_delete,
Snackbar.LENGTH_LONG)
.show();
@@ -1245,9 +1244,11 @@
private void copyDocuments(final List<DocumentInfo> docs, final DocumentInfo destination) {
if (!canCopy(docs, destination)) {
- Toast.makeText(
+ Shared.makeSnackbar(
getActivity(),
- R.string.clipboard_files_cannot_paste, Toast.LENGTH_SHORT).show();
+ R.string.clipboard_files_cannot_paste,
+ Snackbar.LENGTH_SHORT)
+ .show();
return;
}
@@ -1297,10 +1298,10 @@
void onDocumentsReady(List<DocumentInfo> docs) {
mClipper.clipDocuments(docs);
Activity activity = getActivity();
- Toast.makeText(activity,
+ Shared.makeSnackbar(activity,
activity.getResources().getQuantityString(
R.plurals.clipboard_files_clipped, docs.size(), docs.size()),
- Toast.LENGTH_SHORT).show();
+ Snackbar.LENGTH_SHORT).show();
}
}.execute(items);
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
index 4658fe3..f6ded4b 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
@@ -41,6 +41,7 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.DocumentsContract;
+import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -48,7 +49,6 @@
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.Spinner;
-import android.widget.Toast;
import android.widget.Toolbar;
import com.android.documentsui.RecentsProvider.RecentColumns;
@@ -611,8 +611,8 @@
if (result != null) {
onTaskFinished(result);
} else {
- Toast.makeText(DocumentsActivity.this, R.string.save_error, Toast.LENGTH_SHORT)
- .show();
+ Shared.makeSnackbar(
+ DocumentsActivity.this, R.string.save_error, Snackbar.LENGTH_SHORT).show();
}
setPending(false);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
index e8d1088..df803fb 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
@@ -31,6 +31,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
@@ -38,7 +39,6 @@
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.Spinner;
-import android.widget.Toast;
import android.widget.Toolbar;
import com.android.documentsui.RecentsProvider.ResumeColumns;
@@ -322,7 +322,7 @@
try {
startActivity(intent);
} catch (ActivityNotFoundException ex2) {
- Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
+ Shared.makeSnackbar(this, R.string.toast_no_application, Snackbar.LENGTH_SHORT).show();
}
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/ManageRootActivity.java b/packages/DocumentsUI/src/com/android/documentsui/ManageRootActivity.java
index 4754899..ed7333d 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/ManageRootActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/ManageRootActivity.java
@@ -31,12 +31,12 @@
import android.net.Uri;
import android.os.Bundle;
import android.provider.DocumentsContract;
+import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.Spinner;
-import android.widget.Toast;
import android.widget.Toolbar;
import com.android.documentsui.RecentsProvider.ResumeColumns;
@@ -184,7 +184,8 @@
try {
startActivity(view);
} catch (ActivityNotFoundException ex2) {
- Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
+ Shared.makeSnackbar(this, R.string.toast_no_application, Snackbar.LENGTH_SHORT)
+ .show();
}
}
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/Shared.java b/packages/DocumentsUI/src/com/android/documentsui/Shared.java
index 9c884d4..29bcd24 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/Shared.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/Shared.java
@@ -16,7 +16,12 @@
package com.android.documentsui;
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.app.Activity;
import android.content.Context;
+import android.support.design.widget.Snackbar;
+import android.view.View;
/**
* @hide
@@ -31,4 +36,14 @@
public static final String getQuantityString(Context context, int resourceId, int quantity) {
return context.getResources().getQuantityString(resourceId, quantity, quantity);
}
+
+ public static final Snackbar makeSnackbar(Activity activity, int messageId, int duration) {
+ return makeSnackbar(activity, activity.getResources().getText(messageId), duration);
+ }
+
+ public static final Snackbar makeSnackbar(Activity activity, CharSequence message, int duration)
+ {
+ final View view = checkNotNull(activity.findViewById(R.id.coordinator_layout));
+ return Snackbar.make(view, message, duration);
+ }
}