Removing custom state definition from FastBitmapDrawable
> For Fast scrolling, using state list animator defined in xml > For Pressed state, using onState change method in a drawable Change-Id: Ia608690f593938cf0f77e00afcc2a3076e48d8f4
This commit is contained in:
1 parent
f28629a47b
commit
2a76e3fbc6
7 files changed
+135
-235
No files matched your search
@@ -53,8 +53,7 @@ import java.text.NumberFormat;
|
||||
* because we want to make the bubble taller than the text and TextView's clip is
|
||||
* too aggressive.
|
||||
*/
|
||||
public class BubbleTextView extends TextView
|
||||
implements BaseRecyclerViewFastScrollBar.FastScrollFocusableView, ItemInfoUpdateReceiver {
|
||||
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
|
||||
|
||||
// Dimensions in DP
|
||||
private static final float AMBIENT_SHADOW_RADIUS = 2.5f;
|
||||
@@ -67,6 +66,8 @@ public class BubbleTextView extends TextView
|
||||
private static final int DISPLAY_ALL_APPS = 1;
|
||||
private static final int DISPLAY_FOLDER = 2;
|
||||
|
||||
private static final int[] STATE_PRESSED = new int[] {android.R.attr.state_pressed};
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private Drawable mIcon;
|
||||
private final boolean mCenterVertically;
|
||||
@@ -232,14 +233,21 @@ public class BubbleTextView extends TextView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPressed(boolean pressed) {
|
||||
super.setPressed(pressed);
|
||||
|
||||
public void refreshDrawableState() {
|
||||
if (!mIgnorePressedStateChange) {
|
||||
updateIconState();
|
||||
super.refreshDrawableState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] onCreateDrawableState(int extraSpace) {
|
||||
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||
if (mStayPressed) {
|
||||
mergeDrawableStates(drawableState, STATE_PRESSED);
|
||||
}
|
||||
return drawableState;
|
||||
}
|
||||
|
||||
/** Returns the icon for this view. */
|
||||
public Drawable getIcon() {
|
||||
return mIcon;
|
||||
@@ -250,17 +258,6 @@ public class BubbleTextView extends TextView
|
||||
return mLayoutHorizontal;
|
||||
}
|
||||
|
||||
private void updateIconState() {
|
||||
if (mIcon instanceof FastBitmapDrawable) {
|
||||
FastBitmapDrawable d = (FastBitmapDrawable) mIcon;
|
||||
if (isPressed() || mStayPressed) {
|
||||
d.animateState(FastBitmapDrawable.State.PRESSED);
|
||||
} else {
|
||||
d.animateState(FastBitmapDrawable.State.NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnLongClickListener(OnLongClickListener l) {
|
||||
super.setOnLongClickListener(l);
|
||||
@@ -334,7 +331,7 @@ public class BubbleTextView extends TextView
|
||||
this, mPressedBackground);
|
||||
}
|
||||
|
||||
updateIconState();
|
||||
refreshDrawableState();
|
||||
}
|
||||
|
||||
void clearPressedBackground() {
|
||||
@@ -364,7 +361,7 @@ public class BubbleTextView extends TextView
|
||||
|
||||
mPressedBackground = null;
|
||||
mIgnorePressedStateChange = false;
|
||||
updateIconState();
|
||||
refreshDrawableState();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -544,10 +541,6 @@ public class BubbleTextView extends TextView
|
||||
@Override
|
||||
public void reapplyItemInfo(ItemInfoWithIcon info) {
|
||||
if (getTag() == info) {
|
||||
FastBitmapDrawable.State prevState = FastBitmapDrawable.State.NORMAL;
|
||||
if (mIcon instanceof FastBitmapDrawable) {
|
||||
prevState = ((FastBitmapDrawable) mIcon).getCurrentState();
|
||||
}
|
||||
mIconLoadRequest = null;
|
||||
mDisableRelayout = true;
|
||||
|
||||
@@ -566,12 +559,6 @@ public class BubbleTextView extends TextView
|
||||
applyFromPackageItemInfo((PackageItemInfo) info);
|
||||
}
|
||||
|
||||
// If we are reapplying over an old icon, then we should update the new icon to the same
|
||||
// state as the old icon
|
||||
if (mIcon instanceof FastBitmapDrawable) {
|
||||
((FastBitmapDrawable) mIcon).setState(prevState);
|
||||
}
|
||||
|
||||
mDisableRelayout = false;
|
||||
}
|
||||
}
|
||||
@@ -593,34 +580,6 @@ public class BubbleTextView extends TextView
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFastScrollFocusState(final FastBitmapDrawable.State focusState, boolean animated) {
|
||||
// We can only set the fast scroll focus state on a FastBitmapDrawable
|
||||
if (!(mIcon instanceof FastBitmapDrawable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
FastBitmapDrawable d = (FastBitmapDrawable) mIcon;
|
||||
if (animated) {
|
||||
FastBitmapDrawable.State prevState = d.getCurrentState();
|
||||
if (d.animateState(focusState)) {
|
||||
// If the state was updated, then update the view accordingly
|
||||
animate().scaleX(focusState.viewScale)
|
||||
.scaleY(focusState.viewScale)
|
||||
.setStartDelay(getStartDelayForStateChange(prevState, focusState))
|
||||
.setDuration(d.getDurationForStateChange(prevState, focusState))
|
||||
.start();
|
||||
}
|
||||
} else {
|
||||
if (d.setState(focusState)) {
|
||||
// If the state was updated, then update the view accordingly
|
||||
animate().cancel();
|
||||
setScaleX(focusState.viewScale);
|
||||
setScaleY(focusState.viewScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the view can show custom shortcuts.
|
||||
*/
|
||||
@@ -629,21 +588,6 @@ public class BubbleTextView extends TextView
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the start delay when animating between certain {@link FastBitmapDrawable} states.
|
||||
*/
|
||||
private static int getStartDelayForStateChange(final FastBitmapDrawable.State fromState,
|
||||
final FastBitmapDrawable.State toState) {
|
||||
switch (toState) {
|
||||
case NORMAL:
|
||||
switch (fromState) {
|
||||
case FAST_SCROLL_HIGHLIGHTED:
|
||||
return FastBitmapDrawable.FAST_SCROLL_INACTIVE_DURATION / 4;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to be implemented by the grand parent to allow click shadow effect.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user