Merge "DocsUI: Update the drag shadow to meet UI spec." into nyc-dev
This commit is contained in:
28
packages/DocumentsUI/res/drawable/drag_shadow_background.xml
Normal file
28
packages/DocumentsUI/res/drawable/drag_shadow_background.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="@color/item_doc_background" />
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="#ff9f9f9f" />
|
||||||
|
<corners
|
||||||
|
android:bottomRightRadius="3dp"
|
||||||
|
android:bottomLeftRadius="3dp"
|
||||||
|
android:topLeftRadius="3dp"
|
||||||
|
android:topRightRadius="3dp"/>
|
||||||
|
</shape>
|
||||||
44
packages/DocumentsUI/res/layout/drag_shadow_layout.xml
Normal file
44
packages/DocumentsUI/res/layout/drag_shadow_layout.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical|left"
|
||||||
|
android:background="@drawable/drag_shadow_background">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@android:id/icon"
|
||||||
|
android:layout_width="@dimen/root_icon_size"
|
||||||
|
android:layout_height="@dimen/root_icon_size"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:duplicateParentState="true"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textColor="@color/item_title"
|
||||||
|
android:paddingStart="8dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -38,4 +38,8 @@
|
|||||||
<dimen name="drag_shadow_size">120dp</dimen>
|
<dimen name="drag_shadow_size">120dp</dimen>
|
||||||
<dimen name="grid_item_elevation">2dp</dimen>
|
<dimen name="grid_item_elevation">2dp</dimen>
|
||||||
<dimen name="max_drawer_width">280dp</dimen>
|
<dimen name="max_drawer_width">280dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="drag_shadow_width">160dp</dimen>
|
||||||
|
<dimen name="drag_shadow_height">48dp</dimen>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -223,6 +223,12 @@
|
|||||||
<item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> selected</item>
|
<item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> selected</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<!-- Label text showing user how many items are being dragged. Can be one or more elements. -->
|
||||||
|
<plurals name="elements_dragged">
|
||||||
|
<item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> item</item>
|
||||||
|
<item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> items</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- Dialog text shown to users when asking if they want to delete a file (a confirmation) -->
|
<!-- Dialog text shown to users when asking if they want to delete a file (a confirmation) -->
|
||||||
<string name="delete_filename_confirmation_message">Delete \"<xliff:g id="name" example="cat.jpg">%1$s</xliff:g>\"?</string>
|
<string name="delete_filename_confirmation_message">Delete \"<xliff:g id="name" example="cat.jpg">%1$s</xliff:g>\"?</string>
|
||||||
<!-- Dialog text shown to users when asking if they want to delete a folder (a confirmation) -->
|
<!-- Dialog text shown to users when asking if they want to delete a folder (a confirmation) -->
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import android.content.Loader;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@@ -72,8 +73,8 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Toolbar;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toolbar;
|
||||||
|
|
||||||
import com.android.documentsui.BaseActivity;
|
import com.android.documentsui.BaseActivity;
|
||||||
import com.android.documentsui.DirectoryLoader;
|
import com.android.documentsui.DirectoryLoader;
|
||||||
@@ -1229,41 +1230,68 @@ public class DirectoryFragment extends Fragment
|
|||||||
DocumentInfo.fromDirectoryCursor(cursor));
|
DocumentInfo.fromDirectoryCursor(cursor));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getDragShadowIcon(List<DocumentInfo> docs) {
|
private static class DragShadowBuilder extends View.DragShadowBuilder {
|
||||||
if (docs.size() == 1) {
|
|
||||||
final DocumentInfo doc = docs.get(0);
|
private final Context mContext;
|
||||||
return mIconHelper.getDocumentIcon(getActivity(), doc.authority, doc.documentId,
|
private final IconHelper mIconHelper;
|
||||||
doc.mimeType, doc.icon);
|
private final LayoutInflater mInflater;
|
||||||
|
private final View mShadowView;
|
||||||
|
private final TextView mTitle;
|
||||||
|
private final ImageView mIcon;
|
||||||
|
private final int mWidth;
|
||||||
|
private final int mHeight;
|
||||||
|
|
||||||
|
public DragShadowBuilder(Context context, IconHelper iconHelper, List<DocumentInfo> docs) {
|
||||||
|
mContext = context;
|
||||||
|
mIconHelper = iconHelper;
|
||||||
|
mInflater = LayoutInflater.from(context);
|
||||||
|
|
||||||
|
mWidth = mContext.getResources().getDimensionPixelSize(R.dimen.drag_shadow_width);
|
||||||
|
mHeight= mContext.getResources().getDimensionPixelSize(R.dimen.drag_shadow_height);
|
||||||
|
|
||||||
|
mShadowView = mInflater.inflate(R.layout.drag_shadow_layout, null);
|
||||||
|
mTitle = (TextView) mShadowView.findViewById(android.R.id.title);
|
||||||
|
mIcon = (ImageView) mShadowView.findViewById(android.R.id.icon);
|
||||||
|
|
||||||
|
mTitle.setText(getTitle(docs));
|
||||||
|
mIcon.setImageDrawable(getIcon(docs));
|
||||||
}
|
}
|
||||||
return getActivity().getDrawable(R.drawable.ic_doc_generic);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DrawableShadowBuilder extends View.DragShadowBuilder {
|
private Drawable getIcon(List<DocumentInfo> docs) {
|
||||||
|
if (docs.size() == 1) {
|
||||||
|
final DocumentInfo doc = docs.get(0);
|
||||||
|
return mIconHelper.getDocumentIcon(mContext, doc.authority, doc.documentId,
|
||||||
|
doc.mimeType, doc.icon);
|
||||||
|
}
|
||||||
|
return mContext.getDrawable(R.drawable.ic_doc_generic);
|
||||||
|
}
|
||||||
|
|
||||||
private final Drawable mShadow;
|
private String getTitle(List<DocumentInfo> docs) {
|
||||||
|
if (docs.size() == 1) {
|
||||||
private final int mShadowDimension;
|
final DocumentInfo doc = docs.get(0);
|
||||||
|
return doc.displayName;
|
||||||
public DrawableShadowBuilder(Drawable shadow) {
|
}
|
||||||
mShadow = shadow;
|
return Shared.getQuantityString(mContext, R.plurals.elements_dragged, docs.size());
|
||||||
mShadowDimension = getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.drag_shadow_size);
|
|
||||||
mShadow.setBounds(0, 0, mShadowDimension, mShadowDimension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProvideShadowMetrics(
|
public void onProvideShadowMetrics(
|
||||||
Point shadowSize, Point shadowTouchPoint) {
|
Point shadowSize, Point shadowTouchPoint) {
|
||||||
shadowSize.set(mShadowDimension, mShadowDimension);
|
shadowSize.set(mWidth, mHeight);
|
||||||
shadowTouchPoint.set(mShadowDimension / 2, mShadowDimension / 2);
|
shadowTouchPoint.set(mWidth, mHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawShadow(Canvas canvas) {
|
public void onDrawShadow(Canvas canvas) {
|
||||||
mShadow.draw(canvas);
|
Rect r = canvas.getClipBounds();
|
||||||
|
// Calling measure is necessary in order for all child views to get correctly laid out.
|
||||||
|
mShadowView.measure(
|
||||||
|
View.MeasureSpec.makeMeasureSpec(r.right- r.left, View.MeasureSpec.EXACTLY),
|
||||||
|
View.MeasureSpec.makeMeasureSpec(r.top- r.bottom, View.MeasureSpec.EXACTLY));
|
||||||
|
mShadowView.layout(r.left, r.top, r.right, r.bottom);
|
||||||
|
mShadowView.draw(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract task providing support for loading documents *off*
|
* Abstract task providing support for loading documents *off*
|
||||||
* the main thread. And if it isn't obvious, creating a list
|
* the main thread. And if it isn't obvious, creating a list
|
||||||
@@ -1414,7 +1442,7 @@ public class DirectoryFragment extends Fragment
|
|||||||
}
|
}
|
||||||
v.startDragAndDrop(
|
v.startDragAndDrop(
|
||||||
mClipper.getClipDataForDocuments(docs),
|
mClipper.getClipDataForDocuments(docs),
|
||||||
new DrawableShadowBuilder(getDragShadowIcon(docs)),
|
new DragShadowBuilder(getActivity(), mIconHelper, docs),
|
||||||
getDisplayState().stack.peek(),
|
getDisplayState().stack.peek(),
|
||||||
View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ |
|
View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ |
|
||||||
View.DRAG_FLAG_GLOBAL_URI_WRITE
|
View.DRAG_FLAG_GLOBAL_URI_WRITE
|
||||||
|
|||||||
Reference in New Issue
Block a user