Merge "DocsUI: Don't animate selection changes on all bind events." into nyc-dev
This commit is contained in:
@@ -77,10 +77,18 @@ public abstract class DocumentHolder
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -42,12 +42,17 @@ final class GridDirectoryHolder extends DocumentHolder {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,12 +69,16 @@ final class GridDocumentHolder extends DocumentHolder {
|
||||
}
|
||||
|
||||
@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 @@ final class GridDocumentHolder extends DocumentHolder {
|
||||
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) {
|
||||
|
||||
@@ -65,22 +65,31 @@ final class ListDocumentHolder extends DocumentHolder {
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.util.SparseArray;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.documentsui.State;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -103,7 +102,7 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
|
||||
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 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
|
||||
assert(!selected);
|
||||
}
|
||||
holder.setEnabled(enabled);
|
||||
holder.setSelected(mEnv.isSelected(modelId));
|
||||
holder.setSelected(mEnv.isSelected(modelId), false);
|
||||
|
||||
mEnv.onBindDocumentHolder(holder, cursor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user