summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/HolographicLinearLayout.java
diff options
context:
space:
mode:
authorCristina Stancu <crstn@google.com>2013-08-16 11:15:40 +0100
committerCristina Stancu <crstn@google.com>2013-08-16 12:06:59 +0100
commitd791998dd8643048ae40adaad2311fed0543bbb1 (patch)
tree54f65ffa38c97eb9710e705e70c655872ff362ef /src/com/android/launcher3/HolographicLinearLayout.java
parente3381e11b0dbee7e956f72c0d1b92904ab171acf (diff)
downloadandroid_packages_apps_Trebuchet-d791998dd8643048ae40adaad2311fed0543bbb1.tar.gz
android_packages_apps_Trebuchet-d791998dd8643048ae40adaad2311fed0543bbb1.tar.bz2
android_packages_apps_Trebuchet-d791998dd8643048ae40adaad2311fed0543bbb1.zip
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
Diffstat (limited to 'src/com/android/launcher3/HolographicLinearLayout.java')
-rw-r--r--src/com/android/launcher3/HolographicLinearLayout.java57
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;
+ }
}