summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ben Lin <linben@google.com> 2016-11-01 12:14:38 -0700
committer Ben Lin <linben@google.com> 2016-11-09 13:22:47 -0800
commit166c5c6fc17461cb52f2b83eaec86cfc15b53004 (patch)
tree32fd0fd43c0d160a73f0092ff0cb72513bd9113f
parentc717533e1d28bfe653751e193ab77ecae994fda7 (diff)
Update DragShadow states to UX spec.
There was an attempt to use LevelListDrawable for the different levels of background of DocumentHolder, but that resulted in a weird state. Can revisit that on another attempt. Bug: 31182423 Change-Id: I74af77557790b1d30e316fa167ffed577eaf9032
-rw-r--r--res/drawable/drag_shadow_background.xml8
-rw-r--r--res/drawable/drop_badge_states.xml (renamed from res/color/item_doc_list_background_activated.xml)20
-rw-r--r--res/drawable/ic_drop_not_ok_badge.xml38
-rw-r--r--res/drawable/ic_drop_ok_badge.xml37
-rw-r--r--res/drawable/item_doc_list_background.xml20
-rw-r--r--res/layout/drag_shadow_layout.xml8
-rw-r--r--res/layout/drop_badge.xml (renamed from res/drawable/drag_shadow_background_no_drop.xml)20
-rw-r--r--res/values/attrs.xml4
-rw-r--r--res/values/colors.xml5
-rw-r--r--res/values/dimens.xml3
-rw-r--r--src/com/android/documentsui/DragShadowBuilder.java24
-rw-r--r--src/com/android/documentsui/DrawerController.java2
-rw-r--r--src/com/android/documentsui/DropBadgeView.java86
-rw-r--r--src/com/android/documentsui/HorizontalBreadcrumb.java2
-rw-r--r--src/com/android/documentsui/ItemDragListener.java11
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java37
-rw-r--r--src/com/android/documentsui/dirlist/DocumentHolder.java22
-rw-r--r--src/com/android/documentsui/sidebar/RootsFragment.java2
-rw-r--r--tests/unit/com/android/documentsui/ItemDragListenerTest.java2
-rw-r--r--tests/unit/com/android/documentsui/dirlist/DragScrollListenerTest.java2
20 files changed, 264 insertions, 89 deletions
diff --git a/res/drawable/drag_shadow_background.xml b/res/drawable/drag_shadow_background.xml
index d6ec373d5..5940bb375 100644
--- a/res/drawable/drag_shadow_background.xml
+++ b/res/drawable/drag_shadow_background.xml
@@ -21,8 +21,8 @@
android:width="1dp"
android:color="#ff9f9f9f" />
<corners
- android:bottomRightRadius="3dp"
- android:bottomLeftRadius="3dp"
- android:topLeftRadius="3dp"
- android:topRightRadius="3dp"/>
+ android:bottomRightRadius="2dp"
+ android:bottomLeftRadius="2dp"
+ android:topLeftRadius="2dp"
+ android:topRightRadius="2dp"/>
</shape>
diff --git a/res/color/item_doc_list_background_activated.xml b/res/drawable/drop_badge_states.xml
index 7d7a11086..f859b7ca1 100644
--- a/res/color/item_doc_list_background_activated.xml
+++ b/res/drawable/drop_badge_states.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 The Android Open Source Project
+<!-- 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.
@@ -14,11 +14,17 @@
limitations under the License.
-->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
<item
- android:state_activated="true"
- android:color="?android:attr/colorAccent"
- android:alpha="0.1" />
+ app:state_droppable="true"
+ app:state_drop_hovered="true"
+ android:drawable="@drawable/ic_drop_ok_badge" />
<item
- android:color="@android:color/transparent" />
-</selector>
+ app:state_droppable="false"
+ app:state_drop_hovered="true"
+ android:drawable="@drawable/ic_drop_not_ok_badge" />
+ <item
+ app:state_drop_hovered="false"
+ android:drawable="@android:color/transparent" />
+</selector> \ No newline at end of file
diff --git a/res/drawable/ic_drop_not_ok_badge.xml b/res/drawable/ic_drop_not_ok_badge.xml
new file mode 100644
index 000000000..45c8b6dd7
--- /dev/null
+++ b/res/drawable/ic_drop_not_ok_badge.xml
@@ -0,0 +1,38 @@
+<!--
+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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="15dp"
+ android:height="15dp"
+ android:viewportWidth="30.0"
+ android:viewportHeight="30.0">
+
+ <group
+ android:name="whiteBg">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M0,15a15,15 0 1,0 30,0a15,15 0 1,0 -30,0" />
+ </group>
+
+ <group
+ android:name="badge"
+ android:translateX="2"
+ android:translateY="2">
+ <path
+ android:fillColor="#FFC53929"
+ android:pathData="M3.8056487,3.8056487 C-1.26854957,8.87984696 -1.26854957,17.1162267 3.8056487,22.190425 C8.87984696,27.2646233 17.1162267,27.2646233 22.190425,22.190425 C27.2646233,17.1162267 27.2646233,8.87984696 22.190425,3.8056487 C17.1162267,-1.26854957 8.87984696,-1.26854957 3.8056487,3.8056487 L3.8056487,3.8056487 Z M16.5335708,17.9477843 L12.9980369,14.4122504 L9.46250295,17.9477843 L8.04828938,16.5335708 L11.5838233,12.9980369 L8.04828938,9.46250295 L9.46250295,8.04828938 L12.9980369,11.5838233 L16.5335708,8.04828938 L17.9477843,9.46250295 L14.4122504,12.9980369 L17.9477843,16.5335708 L16.5335708,17.9477843 L16.5335708,17.9477843 Z" />
+ </group>
+</vector>
diff --git a/res/drawable/ic_drop_ok_badge.xml b/res/drawable/ic_drop_ok_badge.xml
new file mode 100644
index 000000000..48e3e838a
--- /dev/null
+++ b/res/drawable/ic_drop_ok_badge.xml
@@ -0,0 +1,37 @@
+<!--
+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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="15dp"
+ android:height="15dp"
+ android:viewportWidth="30.0"
+ android:viewportHeight="30.0">
+
+ <group
+ android:name="whiteBg">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M0,15a15,15 0 1,0 30,0a15,15 0 1,0 -30,0" />
+ </group>
+
+ <group
+ android:name="badge"
+ android:translateX="2"
+ android:translateY="2">
+ <path
+ android:fillColor="#FF0B8043"
+ android:pathData="M13,0 C5.824,0 0,5.824 0,13 C0,20.176 5.824,26 13,26 C20.176,26 26,20.176 26,13 C26,5.824 20.176,0 13,0 L13,0 Z M19,14 L14,14 L14,19 L12,19 L12,14 L7,14 L7,12 L12,12 L12,7 L14,7 L14,12 L19,12 L19,14 Z" />
+ </group>
+</vector>
diff --git a/res/drawable/item_doc_list_background.xml b/res/drawable/item_doc_list_background.xml
deleted file mode 100644
index 13910bbe3..000000000
--- a/res/drawable/item_doc_list_background.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 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_list_background_activated" />
-</shape>
diff --git a/res/layout/drag_shadow_layout.xml b/res/layout/drag_shadow_layout.xml
index 26613efdd..e94c443ae 100644
--- a/res/layout/drag_shadow_layout.xml
+++ b/res/layout/drag_shadow_layout.xml
@@ -23,13 +23,7 @@
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"/>
+ <include layout="@layout/drop_badge"/>
<TextView
android:id="@android:id/title"
diff --git a/res/drawable/drag_shadow_background_no_drop.xml b/res/layout/drop_badge.xml
index b92c30a66..485f400f2 100644
--- a/res/drawable/drag_shadow_background_no_drop.xml
+++ b/res/layout/drop_badge.xml
@@ -14,15 +14,11 @@
limitations under the License.
-->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <solid android:color="@color/item_drag_shadow_background_no_drop" />
- <stroke
- android:width="1dp"
- android:color="#ff9f9f9f" />
- <corners
- android:bottomRightRadius="3dp"
- android:bottomLeftRadius="3dp"
- android:topLeftRadius="3dp"
- android:topRightRadius="3dp"/>
-</shape>
+<com.android.documentsui.DropBadgeView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ 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"/> \ No newline at end of file
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 46ca582e7..a5b128026 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -17,4 +17,8 @@
<declare-styleable name="HighlightedItemView">
<attr name="state_highlighted" format="boolean"/>
</declare-styleable>
+ <declare-styleable name="DroppableItemView">
+ <attr name="state_droppable" format="boolean"/>
+ <attr name="state_drop_hovered" format="boolean"/>
+ </declare-styleable>
</resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index cb4b04cdf..09ba86d00 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -38,8 +38,9 @@
<color name="item_doc_background_disabled">#fff4f4f4</color>
<color name="item_doc_background_selected">@*android:color/accent_device_default_50</color>
<color name="item_breadcrumb_background_hovered">#1affffff</color>
+ <color name="item_doc_droppable_background">#ffe8f0fb</color>
+ <color name="item_doc_not_droppable_background">#ffe0e0e0</color>
- <color name="item_drag_shadow_background">#fffafafa</color>
- <color name="item_drag_shadow_background_no_drop">#ffffb6c1</color>
+ <color name="item_drag_shadow_background">@*android:color/white</color>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index ecd598eed..2c4ff9977 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -51,4 +51,7 @@
<dimen name="dropdown_sort_widget_margin">20dp</dimen>
<dimen name="dropdown_sort_widget_icon_size">30dp</dimen>
+
+ <dimen name="drop_icon_height">15dp</dimen>
+ <dimen name="drop_icon_width">15dp</dimen>
</resources>
diff --git a/src/com/android/documentsui/DragShadowBuilder.java b/src/com/android/documentsui/DragShadowBuilder.java
index d6877ec00..24e037da9 100644
--- a/src/com/android/documentsui/DragShadowBuilder.java
+++ b/src/com/android/documentsui/DragShadowBuilder.java
@@ -23,7 +23,6 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageView;
import android.widget.TextView;
import com.android.documentsui.base.DocumentInfo;
@@ -39,11 +38,9 @@ public final class DragShadowBuilder extends View.DragShadowBuilder {
private final View mShadowView;
private final TextView mTitle;
- private final ImageView mIcon;
+ private final DropBadgeView mIcon;
private final int mWidth;
private final int mHeight;
- private final Drawable mDefaultBackground;
- private final Drawable mNoDropBackground;
public DragShadowBuilder(Context context) {
mWidth = context.getResources().getDimensionPixelSize(R.dimen.drag_shadow_width);
@@ -51,12 +48,11 @@ public final class DragShadowBuilder extends View.DragShadowBuilder {
mShadowView = LayoutInflater.from(context).inflate(R.layout.drag_shadow_layout, null);
mTitle = (TextView) mShadowView.findViewById(android.R.id.title);
- mIcon = (ImageView) mShadowView.findViewById(android.R.id.icon);
+ mIcon = (DropBadgeView) mShadowView.findViewById(android.R.id.icon);
- mDefaultBackground = context.getResources().getDrawable(R.drawable.drag_shadow_background,
- null);
- mNoDropBackground = context.getResources()
- .getDrawable(R.drawable.drag_shadow_background_no_drop, null);
+ mShadowView
+ .setBackground(context.getResources().getDrawable(R.drawable.drag_shadow_background,
+ null));
}
@Override
@@ -82,15 +78,17 @@ public final class DragShadowBuilder extends View.DragShadowBuilder {
}
public void updateIcon(Drawable icon) {
- mIcon.setImageDrawable(icon);
+ mIcon.updateIcon(icon);
}
public void resetBackground() {
- mShadowView.setBackground(mDefaultBackground);
+ mIcon.setDropHovered(false);
+ mIcon.setEnabled(false);
}
- public void setNoDropBackground() {
- mShadowView.setBackground(mNoDropBackground);
+ public void setAppearDroppable(boolean droppable) {
+ mIcon.setDropHovered(true);
+ mIcon.setDroppable(droppable);
}
/**
diff --git a/src/com/android/documentsui/DrawerController.java b/src/com/android/documentsui/DrawerController.java
index f8062a76b..12f00ee9d 100644
--- a/src/com/android/documentsui/DrawerController.java
+++ b/src/com/android/documentsui/DrawerController.java
@@ -156,7 +156,7 @@ public abstract class DrawerController implements DrawerListener {
}
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
}
@Override
diff --git a/src/com/android/documentsui/DropBadgeView.java b/src/com/android/documentsui/DropBadgeView.java
new file mode 100644
index 000000000..8ed67013d
--- /dev/null
+++ b/src/com/android/documentsui/DropBadgeView.java
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+package com.android.documentsui;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.widget.ImageView;
+
+/**
+ * Provides a way to encapsulate droppable badge toggling logic into a single class.
+ */
+public final class DropBadgeView extends ImageView {
+ private static final int[] STATE_DROPPABLE = {R.attr.state_droppable};
+ private static final int[] STATE_DROP_HOVERED = {R.attr.state_drop_hovered};
+
+ private boolean mDroppable = false;
+ private boolean mDropHovered = false;
+ private LayerDrawable mBackground;
+
+ public DropBadgeView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ final int badgeHeight = context.getResources()
+ .getDimensionPixelSize(R.dimen.drop_icon_height);
+ final int badgeWidth = context.getResources()
+ .getDimensionPixelSize(R.dimen.drop_icon_width);
+
+ Drawable okBadge = context.getResources().getDrawable(R.drawable.drop_badge_states, null);
+ Drawable defaultIcon = context.getResources()
+ .getDrawable(com.android.internal.R.drawable.ic_doc_generic, null);
+
+ Drawable[] list = {defaultIcon, okBadge};
+ mBackground = new LayerDrawable(list);
+
+ mBackground.setLayerGravity(1, Gravity.BOTTOM | Gravity.RIGHT);
+ mBackground.setLayerSize(1, badgeWidth, badgeHeight);
+
+ setBackground(mBackground);
+ }
+
+ @Override
+ public int[] onCreateDrawableState(int extraSpace) {
+ final int[] drawableState = super.onCreateDrawableState(extraSpace + 2);
+
+ if (mDroppable) {
+ mergeDrawableStates(drawableState, STATE_DROPPABLE);
+ }
+
+ if (mDropHovered) {
+ mergeDrawableStates(drawableState, STATE_DROP_HOVERED);
+ }
+
+ return drawableState;
+ }
+
+ public void setDroppable(boolean droppable) {
+ mDroppable = droppable;
+ refreshDrawableState();
+ }
+
+ public void setDropHovered(boolean hovered) {
+ mDropHovered = hovered;
+ refreshDrawableState();
+ }
+
+ public void updateIcon(Drawable icon) {
+ mBackground.setDrawable(0, icon);
+ }
+} \ No newline at end of file
diff --git a/src/com/android/documentsui/HorizontalBreadcrumb.java b/src/com/android/documentsui/HorizontalBreadcrumb.java
index 240a0d3fc..598deccce 100644
--- a/src/com/android/documentsui/HorizontalBreadcrumb.java
+++ b/src/com/android/documentsui/HorizontalBreadcrumb.java
@@ -118,7 +118,7 @@ public final class HorizontalBreadcrumb extends RecyclerView
}
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
RecyclerView.ViewHolder vh = getChildViewHolder(v);
if (vh instanceof BreadcrumbHolder) {
((BreadcrumbHolder) vh).setHighlighted(highlight);
diff --git a/src/com/android/documentsui/ItemDragListener.java b/src/com/android/documentsui/ItemDragListener.java
index 79f71d964..87c12748c 100644
--- a/src/com/android/documentsui/ItemDragListener.java
+++ b/src/com/android/documentsui/ItemDragListener.java
@@ -68,7 +68,7 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
return true;
case DragEvent.ACTION_DRAG_EXITED:
case DragEvent.ACTION_DRAG_ENDED:
- handleExitedEndedEvent(v);
+ handleExitedEndedEvent(v, event);
return true;
case DragEvent.ACTION_DROP:
return handleDropEvent(v, event);
@@ -80,10 +80,10 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
private void handleEnteredEvent(View v, DragEvent event) {
mDragHost.onDragEntered(v, event.getLocalState());
@Nullable TimerTask task = createOpenTask(v, event);
+ mDragHost.setDropTargetHighlight(v, event.getLocalState(), true);
if (task == null) {
return;
}
- mDragHost.setDropTargetHighlight(v, true);
v.setTag(R.id.drag_hovering_tag, task);
mHoverTimer.schedule(task, SPRING_TIMEOUT);
}
@@ -95,8 +95,8 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
}
}
- private void handleExitedEndedEvent(View v) {
- mDragHost.setDropTargetHighlight(v, false);
+ private void handleExitedEndedEvent(View v, DragEvent event) {
+ mDragHost.setDropTargetHighlight(v, event.getLocalState(), false);
TimerTask task = (TimerTask) v.getTag(R.id.drag_hovering_tag);
if (task != null) {
@@ -154,9 +154,10 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
/**
* Highlights/unhighlights the view to visually indicate this view is being hovered.
* @param v the view being hovered
+ * @param localState the Local state object given by DragEvent
* @param highlight true if highlight the view; false if unhighlight it
*/
- void setDropTargetHighlight(View v, boolean highlight);
+ void setDropTargetHighlight(View v, Object localState, boolean highlight);
/**
* Notifies hovering timeout has elapsed
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 12430eb23..1f0419e8c 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -896,6 +896,12 @@ public class DirectoryFragment extends Fragment
// For now, just always reset drag shadow when drag exits
mActivity.getShadowBuilder().resetBackground();
v.updateDragShadow(mActivity.getShadowBuilder());
+ if (v.getParent() == mRecView) {
+ DocumentHolder holder = getDocumentHolder(v);
+ if (holder != null) {
+ holder.resetDropHighlight();
+ }
+ }
}
void dragStopped(boolean result) {
@@ -913,16 +919,13 @@ public class DirectoryFragment extends Fragment
* {@inheritDoc}
*
* In DirectoryFragment, we close the roots drawer right away.
+ * We also want to update the Drag Shadow to indicate whether the
+ * item is droppable or not.
*/
@Override
public void onDragEntered(View v, Object localState) {
- mActivity.setRootsDrawerOpen(false);
-
- if (canCopyTo(localState, v)) {
- mActivity.getShadowBuilder().resetBackground();
- } else {
- mActivity.getShadowBuilder().setNoDropBackground();
- }
+ mActivity.setRootsDrawerOpen(false);
+ mActivity.getShadowBuilder().setAppearDroppable(canCopyTo(localState, v));
v.updateDragShadow(mActivity.getShadowBuilder());
}
@@ -1004,13 +1007,17 @@ public class DirectoryFragment extends Fragment
}
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
// Note: use exact comparison - this code is searching for views which are children of
// the RecyclerView instance in the UI.
if (v.getParent() == mRecView) {
- RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(v);
- if (vh instanceof DocumentHolder) {
- ((DocumentHolder) vh).setDroppableHighlight(highlight);
+ DocumentHolder holder = getDocumentHolder(v);
+ if (holder != null) {
+ if (!highlight) {
+ holder.resetDropHighlight();
+ } else {
+ holder.setDroppableHighlight(canCopyTo(localState, v));
+ }
}
}
}
@@ -1032,6 +1039,14 @@ public class DirectoryFragment extends Fragment
return null;
}
+ private @Nullable DocumentHolder getDocumentHolder(View v) {
+ RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(v);
+ if (vh instanceof DocumentHolder) {
+ return (DocumentHolder) vh;
+ }
+ return null;
+ }
+
// TODO: Move to activities when Model becomes activity level object.
private boolean canSelect(DocumentDetails doc) {
return canSetSelectionState(doc.getModelId(), true);
diff --git a/src/com/android/documentsui/dirlist/DocumentHolder.java b/src/com/android/documentsui/dirlist/DocumentHolder.java
index b5c1174f5..3015d4264 100644
--- a/src/com/android/documentsui/dirlist/DocumentHolder.java
+++ b/src/com/android/documentsui/dirlist/DocumentHolder.java
@@ -49,6 +49,8 @@ public abstract class DocumentHolder
protected final Context mContext;
protected final @ColorInt int mDefaultBgColor;
protected final @ColorInt int mSelectedBgColor;
+ protected final @ColorInt int mDroppableBgColor;
+ protected final @ColorInt int mNotDroppableBgColor;
protected @Nullable String mModelId;
@@ -72,6 +74,9 @@ public abstract class DocumentHolder
mDefaultBgColor = context.getColor(R.color.item_doc_background);
mSelectedBgColor = context.getColor(R.color.item_doc_background_selected);
+ mDroppableBgColor = context.getColor(R.color.item_doc_droppable_background);
+ mNotDroppableBgColor = context.getColor(R.color.item_doc_not_droppable_background);
+
mSelectionHotspot = itemView.findViewById(R.id.icon_check);
mDebugContainer = (FrameLayout) itemView.findViewById(R.id.debug_info);
@@ -118,13 +123,24 @@ public abstract class DocumentHolder
* Highlights the associated item view to indicate it's droppable.
* @param highlighted
*/
- public void setDroppableHighlight(boolean highlighted) {
- // If item is already selected, its droppable highlight should not be changed.
+ public void setDroppableHighlight(boolean droppable) {
+ // If item is already selected, its highlight should not be changed.
+ if (itemView.isActivated()) {
+ return;
+ }
+
+ itemView.setBackgroundColor(droppable ? mDroppableBgColor : mNotDroppableBgColor);
+ }
+
+ /**
+ * Reset the associated item view's droppable background highlight.
+ */
+ public void resetDropHighlight() {
if (itemView.isActivated()) {
return;
}
- itemView.setBackgroundColor(highlighted ? mSelectedBgColor : mDefaultBgColor);
+ itemView.setBackgroundColor(mDefaultBgColor);
}
public void setEnabled(boolean enabled) {
diff --git a/src/com/android/documentsui/sidebar/RootsFragment.java b/src/com/android/documentsui/sidebar/RootsFragment.java
index 242f5744b..e4cc57cf6 100644
--- a/src/com/android/documentsui/sidebar/RootsFragment.java
+++ b/src/com/android/documentsui/sidebar/RootsFragment.java
@@ -397,7 +397,7 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
}
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
// SpacerView doesn't have DragListener so this view is guaranteed to be a RootItemView.
RootItemView itemView = (RootItemView) v;
itemView.setHighlight(highlight);
diff --git a/tests/unit/com/android/documentsui/ItemDragListenerTest.java b/tests/unit/com/android/documentsui/ItemDragListenerTest.java
index 865d8b6c6..71799ac9d 100644
--- a/tests/unit/com/android/documentsui/ItemDragListenerTest.java
+++ b/tests/unit/com/android/documentsui/ItemDragListenerTest.java
@@ -202,7 +202,7 @@ public class ItemDragListenerTest {
private View mLastEnteredView;
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
mHighlightedView = highlight ? v : null;
}
diff --git a/tests/unit/com/android/documentsui/dirlist/DragScrollListenerTest.java b/tests/unit/com/android/documentsui/dirlist/DragScrollListenerTest.java
index fc5933a3e..3a0cc4c08 100644
--- a/tests/unit/com/android/documentsui/dirlist/DragScrollListenerTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/DragScrollListenerTest.java
@@ -188,7 +188,7 @@ public class DragScrollListenerTest {
private static class TestDragHost implements ItemDragListener.DragHost {
@Override
- public void setDropTargetHighlight(View v, boolean highlight) {
+ public void setDropTargetHighlight(View v, Object localState, boolean highlight) {
}
@Override