Merge "DocsUI: Don't animate selection changes on all bind events." into nyc-dev
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java
index 5edda38..450341f 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentHolder.java
@@ -77,10 +77,18 @@
/**
* Makes the associated item view appear selected. Note that this merely affects the appearance
* of the view, it doesn't actually select the item.
+ * TODO: Use the DirectoryItemAnimator instead of manually controlling animation using a boolean
+ * flag.
*
* @param selected
+ * @param animate Whether or not to animate the change. Only selection changes initiated by the
+ * selection manager should be animated. See
+ * {@link ModelBackedDocumentsAdapter#onBindViewHolder(DocumentHolder, int, java.util.List)}
*/
- public void setSelected(boolean selected) {
+ public void setSelected(boolean selected, boolean animate) {
+ // Note: the animate param doesn't apply for this base implementation, because the
+ // DirectoryItemAnimator takes care of it. It's required by subclasses, which perform their
+ // own animation.
itemView.setActivated(selected);
itemView.setBackgroundColor(selected ? mSelectedBgColor : mDefaultBgColor);
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDirectoryHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
index 90b2341..ce5bcb1 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
@@ -42,12 +42,17 @@
}
@Override
- public void setSelected(boolean selected) {
- super.setSelected(selected);
+ public void setSelected(boolean selected, boolean animate) {
+ super.setSelected(selected, animate);
float checkAlpha = selected ? 1f : 0f;
- mIconCheck.animate().alpha(checkAlpha).start();
- mIconMime.animate().alpha(1f - checkAlpha).start();
+ if (animate) {
+ mIconCheck.animate().alpha(checkAlpha).start();
+ mIconMime.animate().alpha(1f - checkAlpha).start();
+ } else {
+ mIconCheck.setAlpha(checkAlpha);
+ mIconMime.setAlpha(1f - checkAlpha);
+ }
}
/**
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
index c8641a8..c4f6f11 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
@@ -69,12 +69,16 @@
}
@Override
- public void setSelected(boolean selected) {
+ public void setSelected(boolean selected, boolean animate) {
// We always want to make sure our check box disappears if we're not selected,
// even if the item is disabled. This is because this object can be reused
// and this method will be called to setup initial state.
float checkAlpha = selected ? 1f : 0f;
- mIconCheck.animate().alpha(checkAlpha).start();
+ if (animate) {
+ mIconCheck.animate().alpha(checkAlpha).start();
+ } else {
+ mIconCheck.setAlpha(checkAlpha);
+ }
// But it should be an error to be set to selected && be disabled.
if (!itemView.isEnabled()) {
@@ -82,9 +86,13 @@
return;
}
- super.setSelected(selected);
+ super.setSelected(selected, animate);
- mIconMimeSm.animate().alpha(1f - checkAlpha).start();
+ if (animate) {
+ mIconMimeSm.animate().alpha(1f - checkAlpha).start();
+ } else {
+ mIconMimeSm.setAlpha(1f - checkAlpha);
+ }
}
public void setEnabled(boolean enabled) {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java
index 3a1be11..ace53e0 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ListDocumentHolder.java
@@ -65,22 +65,31 @@
}
@Override
- public void setSelected(boolean selected) {
+ public void setSelected(boolean selected, boolean animate) {
// We always want to make sure our check box disappears if we're not selected,
// even if the item is disabled. But it should be an error (see assert below)
// to be set to selected && be disabled.
float checkAlpha = selected ? 1f : 0f;
- mIconCheck.animate().alpha(checkAlpha).start();
+ if (animate) {
+ mIconCheck.animate().alpha(checkAlpha).start();
+ } else {
+ mIconCheck.setAlpha(checkAlpha);
+ }
if (!itemView.isEnabled()) {
assert(!selected);
return;
}
- super.setSelected(selected);
+ super.setSelected(selected, animate);
- mIconMime.animate().alpha(1f - checkAlpha).start();
- mIconThumb.animate().alpha(1f - checkAlpha).start();
+ if (animate) {
+ mIconMime.animate().alpha(1f - checkAlpha).start();
+ mIconThumb.animate().alpha(1f - checkAlpha).start();
+ } else {
+ mIconMime.setAlpha(1f - checkAlpha);
+ mIconThumb.setAlpha(1f - checkAlpha);
+ }
}
@Override
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
index 149ecdd..ca3b2e2 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
@@ -29,7 +29,6 @@
import android.view.ViewGroup;
import com.android.documentsui.State;
-
import com.google.common.collect.Sets;
import java.util.ArrayList;
@@ -103,7 +102,7 @@
public void onBindViewHolder(DocumentHolder holder, int position, List<Object> payload) {
if (payload.contains(SELECTION_CHANGED_MARKER)) {
final boolean selected = mEnv.isSelected(mModelIds.get(position));
- holder.setSelected(selected);
+ holder.setSelected(selected, true);
} else {
onBindViewHolder(holder, position);
}
@@ -124,7 +123,7 @@
assert(!selected);
}
holder.setEnabled(enabled);
- holder.setSelected(mEnv.isSelected(modelId));
+ holder.setSelected(mEnv.isSelected(modelId), false);
mEnv.onBindDocumentHolder(holder, cursor);
}