Modify qsb bar elements to handle hotword state.
They currently handle a pressed mode (showing a blue overlay), we'd like
them to also handle a hotword state that would modify their appearance
when hotword is available and active.
Meant to work with: ag/344334
Change-Id: I07e261ce64307fdad8a4c16fc02eb009ca826ece
diff --git a/src/com/android/launcher3/HolographicLinearLayout.java b/src/com/android/launcher3/HolographicLinearLayout.java
index 73d4c3a..cdf4381 100644
--- a/src/com/android/launcher3/HolographicLinearLayout.java
+++ b/src/com/android/launcher3/HolographicLinearLayout.java
@@ -22,17 +22,22 @@
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 @@
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 @@
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 @@
}
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;
+ }
}