summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/launcher2/BubbleTextView.java17
-rw-r--r--src/com/android/launcher2/CellLayout.java34
-rw-r--r--src/com/android/launcher2/LauncherAppWidgetHostView.java20
3 files changed, 61 insertions, 10 deletions
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 348fe34b9..4d1dbf88c 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -30,13 +30,14 @@ import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
+import android.view.View;
/**
* TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
* because we want to make the bubble taller than the text and TextView's clip is
* too aggressive.
*/
-public class BubbleTextView extends CacheableTextView {
+public class BubbleTextView extends CacheableTextView implements VisibilityChangedBroadcaster {
static final float CORNER_RADIUS = 4.0f;
static final float SHADOW_LARGE_RADIUS = 4.0f;
static final float SHADOW_SMALL_RADIUS = 1.75f;
@@ -64,6 +65,8 @@ public class BubbleTextView extends CacheableTextView {
private boolean mBackgroundSizeChanged;
private Drawable mBackground;
+ private VisibilityChangedListener mOnVisibilityChangedListener;
+
public BubbleTextView(Context context) {
super(context);
init();
@@ -240,6 +243,18 @@ public class BubbleTextView extends CacheableTextView {
return result;
}
+ public void setVisibilityChangedListener(VisibilityChangedListener listener) {
+ mOnVisibilityChangedListener = listener;
+ }
+
+ @Override
+ protected void onVisibilityChanged(View changedView, int visibility) {
+ if (mOnVisibilityChangedListener != null) {
+ mOnVisibilityChangedListener.receiveVisibilityChangedMessage(this);
+ }
+ super.onVisibilityChanged(changedView, visibility);
+ }
+
@Override
public void draw(Canvas canvas) {
if (mPressedOrFocusedBackground != null && (isPressed() || isFocused())) {
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 2ddebe77f..2359e322a 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -53,7 +53,7 @@ import android.view.animation.LayoutAnimationController;
import java.util.Arrays;
-public class CellLayout extends ViewGroup implements Dimmable {
+public class CellLayout extends ViewGroup implements Dimmable, VisibilityChangedListener {
static final String TAG = "CellLayout";
private int mCellWidth;
@@ -409,7 +409,11 @@ public class CellLayout extends ViewGroup implements Dimmable {
private void invalidateCache() {
mIsCacheDirty = true;
- invalidateIfNeeded();
+ invalidate();
+ }
+
+ public void receiveVisibilityChangedMessage(View v) {
+ invalidateCache();
}
public void updateCache() {
@@ -620,10 +624,11 @@ public class CellLayout extends ViewGroup implements Dimmable {
child.setId(childId);
- // We might be in the middle or end of shrinking/fading to a dimmed view
- // Make sure this view's alpha is set the same as all the rest of the views
- child.setAlpha(getAlpha());
addView(child, index, lp);
+ if (child instanceof VisibilityChangedBroadcaster) {
+ VisibilityChangedBroadcaster v = (VisibilityChangedBroadcaster) child;
+ v.setVisibilityChangedListener(this);
+ }
// invalidate the cache to have it reflect the new item
invalidateCache();
@@ -649,34 +654,40 @@ public class CellLayout extends ViewGroup implements Dimmable {
public void removeAllViews() {
super.removeAllViews();
clearOccupiedCells();
+ invalidateCache();
}
@Override
public void removeAllViewsInLayout() {
super.removeAllViewsInLayout();
clearOccupiedCells();
+ invalidateCache();
}
public void removeViewWithoutMarkingCells(View view) {
super.removeView(view);
+ invalidateCache();
}
@Override
public void removeView(View view) {
markCellsAsUnoccupiedForView(view);
super.removeView(view);
+ invalidateCache();
}
@Override
public void removeViewAt(int index) {
markCellsAsUnoccupiedForView(getChildAt(index));
super.removeViewAt(index);
+ invalidateCache();
}
@Override
public void removeViewInLayout(View view) {
markCellsAsUnoccupiedForView(view);
super.removeViewInLayout(view);
+ invalidateCache();
}
@Override
@@ -685,6 +696,7 @@ public class CellLayout extends ViewGroup implements Dimmable {
markCellsAsUnoccupiedForView(getChildAt(i));
}
super.removeViews(start, count);
+ invalidateCache();
}
@Override
@@ -693,6 +705,7 @@ public class CellLayout extends ViewGroup implements Dimmable {
markCellsAsUnoccupiedForView(getChildAt(i));
}
super.removeViewsInLayout(start, count);
+ invalidateCache();
}
@Override
@@ -1713,3 +1726,14 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
}
}
}
+
+// Custom interfaces used to listen to "visibility changed" events of *children* of Views. Avoided
+// using "onVisibilityChanged" in the names because there's a method of that name in framework
+// (which can only can be used to listen to ancestors' "visibility changed" events)
+interface VisibilityChangedBroadcaster {
+ public void setVisibilityChangedListener(VisibilityChangedListener listener);
+}
+
+interface VisibilityChangedListener {
+ public void receiveVisibilityChangedMessage(View v);
+}
diff --git a/src/com/android/launcher2/LauncherAppWidgetHostView.java b/src/com/android/launcher2/LauncherAppWidgetHostView.java
index c45140ef6..85a80f943 100644
--- a/src/com/android/launcher2/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher2/LauncherAppWidgetHostView.java
@@ -28,13 +28,13 @@ import com.android.launcher.R;
/**
* {@inheritDoc}
*/
-public class LauncherAppWidgetHostView extends AppWidgetHostView {
+public class LauncherAppWidgetHostView extends AppWidgetHostView
+ implements VisibilityChangedBroadcaster {
private boolean mHasPerformedLongPress;
-
private CheckForLongPress mPendingCheckForLongPress;
-
private LayoutInflater mInflater;
-
+ private VisibilityChangedListener mOnVisibilityChangedListener;
+
public LauncherAppWidgetHostView(Context context) {
super(context);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -110,4 +110,16 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView {
removeCallbacks(mPendingCheckForLongPress);
}
}
+
+ public void setVisibilityChangedListener(VisibilityChangedListener listener) {
+ mOnVisibilityChangedListener = listener;
+ }
+
+ @Override
+ protected void onVisibilityChanged(View changedView, int visibility) {
+ if (mOnVisibilityChangedListener != null) {
+ mOnVisibilityChangedListener.receiveVisibilityChangedMessage(this);
+ }
+ super.onVisibilityChanged(changedView, visibility);
+ }
}