diff options
Diffstat (limited to 'src/com/android/launcher3/HolographicLinearLayout.java')
-rw-r--r-- | src/com/android/launcher3/HolographicLinearLayout.java | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/com/android/launcher3/HolographicLinearLayout.java b/src/com/android/launcher3/HolographicLinearLayout.java index 73d4c3a01..cdf43812a 100644 --- a/src/com/android/launcher3/HolographicLinearLayout.java +++ b/src/com/android/launcher3/HolographicLinearLayout.java @@ -22,17 +22,22 @@ import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnFocusChangeListener; +import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.LinearLayout; -import com.android.launcher3.R; - public class HolographicLinearLayout extends LinearLayout { - private final HolographicViewHelper mHolographicHelper; private ImageView mImageView; private int mImageViewId; + private boolean mHotwordOn; + private boolean mIsPressed; + private boolean mIsFocused; + public HolographicLinearLayout(Context context) { this(context, null); } @@ -47,10 +52,33 @@ public class HolographicLinearLayout extends LinearLayout { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HolographicLinearLayout, defStyle, 0); mImageViewId = a.getResourceId(R.styleable.HolographicLinearLayout_sourceImageViewId, -1); + mHotwordOn = a.getBoolean(R.styleable.HolographicLinearLayout_stateHotwordOn, false); a.recycle(); + setWillNotDraw(false); mHolographicHelper = new HolographicViewHelper(context); + + setOnTouchListener(new OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (isPressed() != mIsPressed) { + mIsPressed = isPressed(); + refreshDrawableState(); + } + return false; + } + }); + + setOnFocusChangeListener(new OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (isFocused() != mIsFocused) { + mIsFocused = isFocused(); + refreshDrawableState(); + } + } + }); } @Override @@ -58,10 +86,12 @@ public class HolographicLinearLayout extends LinearLayout { super.drawableStateChanged(); if (mImageView != null) { + mHolographicHelper.generatePressedFocusedStates(mImageView); Drawable d = mImageView.getDrawable(); if (d instanceof StateListDrawable) { StateListDrawable sld = (StateListDrawable) d; sld.setState(getDrawableState()); + sld.invalidateSelf(); } } } @@ -82,4 +112,25 @@ public class HolographicLinearLayout extends LinearLayout { } mHolographicHelper.generatePressedFocusedStates(mImageView); } + + private boolean isHotwordOn() { + return mHotwordOn; + } + + public void setHotwordState(boolean on) { + if (on == mHotwordOn) { + return; + } + mHotwordOn = on; + refreshDrawableState(); + } + + @Override + public int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); + if (isHotwordOn()) { + mergeDrawableStates(drawableState, new int[] {R.attr.stateHotwordOn}); + } + return drawableState; + } } |