Merge "Adding background protection to icons and apps button."
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
|
||||
<item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/focused_application_background" />
|
||||
<item android:state_window_focused="false" android:state_focused="true" android:drawable="@android:color/transparent" />
|
||||
<item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
</selector>
|
||||
|
||||
@@ -15,4 +15,4 @@
|
||||
-->
|
||||
|
||||
<com.android.launcher2.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/WorkspaceIcon.Landscape" />
|
||||
style="@style/WorkspaceIcon.Landscape" />
|
||||
|
||||
@@ -125,7 +125,13 @@
|
||||
android:layout_toLeftOf="@id/configure_button"
|
||||
android:layout_marginLeft="@dimen/toolbar_button_spacing"
|
||||
android:layout_marginRight="@dimen/toolbar_button_spacing"
|
||||
android:textSize="18dp"
|
||||
android:textColor="#CCFFFFFF"
|
||||
android:textSize="18sp"
|
||||
|
||||
android:shadowColor="#A0000000"
|
||||
android:shadowDx="0.0"
|
||||
android:shadowDy="0.0"
|
||||
android:shadowRadius="2.0"
|
||||
|
||||
android:onClick="onClickAllAppsButton"
|
||||
android:focusable="true"
|
||||
|
||||
@@ -125,8 +125,14 @@
|
||||
android:layout_toLeftOf="@id/configure_button"
|
||||
android:layout_marginLeft="@dimen/toolbar_button_spacing"
|
||||
android:layout_marginRight="@dimen/toolbar_button_spacing"
|
||||
android:textColor="#CCFFFFFF"
|
||||
android:textSize="18dp"
|
||||
|
||||
android:shadowColor="#A0000000"
|
||||
android:shadowDx="0.0"
|
||||
android:shadowDy="0.0"
|
||||
android:shadowRadius="2.0"
|
||||
|
||||
android:onClick="onClickAllAppsButton"
|
||||
android:focusable="true"
|
||||
android:clickable="true" />
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
<!-- Duration in milliseconds toolbar fade in and fade out animations.
|
||||
NOTE: Fade in and fade out time should together be less the transition
|
||||
animations between all apps, customize, & the workspace. -->
|
||||
<integer name="config_toolbarButtonFadeInTime">350</integer>
|
||||
<integer name="config_toolbarButtonFadeOutTime">350</integer>
|
||||
<integer name="config_toolbarButtonFadeInTime">100</integer>
|
||||
<integer name="config_toolbarButtonFadeOutTime">100</integer>
|
||||
|
||||
<!-- When dragging items on the workspace, how much bigger (in pixels) the dragged view
|
||||
should be, as compared to the original view. If 0, it will not be scaled at all.
|
||||
|
||||
@@ -31,12 +31,13 @@
|
||||
</style>
|
||||
|
||||
<style name="WorkspaceIcon.Portrait">
|
||||
<item name="android:drawablePadding">0dip</item>
|
||||
<item name="android:drawablePadding">2dip</item>
|
||||
<item name="android:paddingTop">0dip</item>
|
||||
<item name="android:includeFontPadding">false</item>
|
||||
</style>
|
||||
|
||||
<style name="WorkspaceIcon.Landscape">
|
||||
<item name="android:drawablePadding">0dip</item>
|
||||
<item name="android:drawablePadding">2dip</item>
|
||||
<item name="android:paddingTop">0dip</item>
|
||||
<item name="android:includeFontPadding">false</item>
|
||||
</style>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<resources>
|
||||
<color name="window_background">#FF191919</color>
|
||||
<color name="grid_dark_background">#EB191919</color>
|
||||
<color name="bubble_dark_background">#B2191919</color>
|
||||
<color name="bubble_dark_background">#20000000</color>
|
||||
<color name="delete_color_filter">#A5FF0000</color>
|
||||
|
||||
<color name="appwidget_error_color">#FCCC</color>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<item name="android:textSize">13dip</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:ellipsize">marquee</item>
|
||||
<item name="android:shadowColor">#FF000000</item>
|
||||
<item name="android:shadowColor">#B0000000</item>
|
||||
<item name="android:shadowRadius">2.0</item>
|
||||
<item name="android:textColor">#FFF</item>
|
||||
<item name="android:gravity">center_horizontal</item>
|
||||
|
||||
@@ -16,15 +16,17 @@
|
||||
|
||||
package com.android.launcher2;
|
||||
|
||||
import android.widget.TextView;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Layout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View.MeasureSpec;
|
||||
|
||||
import com.android.launcher.R;
|
||||
|
||||
@@ -34,12 +36,15 @@ import com.android.launcher.R;
|
||||
* too aggressive.
|
||||
*/
|
||||
public class BubbleTextView extends CacheableTextView {
|
||||
static final float CORNER_RADIUS = 8.0f;
|
||||
static final float PADDING_H = 5.0f;
|
||||
static final float PADDING_V = 1.0f;
|
||||
static final float CORNER_RADIUS = 4.0f;
|
||||
static final float PADDING_H = 8.0f;
|
||||
static final float PADDING_V = 3.0f;
|
||||
|
||||
private int mAppCellWidth;
|
||||
|
||||
private final RectF mRect = new RectF();
|
||||
private Paint mPaint;
|
||||
private float mBubbleColorAlpha;
|
||||
private int mPrevAlpha = -1;
|
||||
|
||||
private boolean mBackgroundSizeChanged;
|
||||
@@ -64,20 +69,31 @@ public class BubbleTextView extends CacheableTextView {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setFocusable(true);
|
||||
mBackground = getBackground();
|
||||
setFocusable(true);
|
||||
setBackgroundDrawable(null);
|
||||
|
||||
final Resources res = getContext().getResources();
|
||||
int bubbleColor = res.getColor(R.color.bubble_dark_background);
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background));
|
||||
mPaint.setColor(bubbleColor);
|
||||
mBubbleColorAlpha = Color.alpha(bubbleColor) / 255.0f;
|
||||
mAppCellWidth = (int) res.getDimension(R.dimen.app_icon_size);
|
||||
|
||||
final float scale = getContext().getResources().getDisplayMetrics().density;
|
||||
final float scale = res.getDisplayMetrics().density;
|
||||
mCornerRadius = CORNER_RADIUS * scale;
|
||||
mPaddingH = PADDING_H * scale;
|
||||
//noinspection PointlessArithmeticExpression
|
||||
mPaddingV = PADDING_V * scale;
|
||||
}
|
||||
|
||||
protected int getVerticalPadding() {
|
||||
return (int) PADDING_V;
|
||||
}
|
||||
protected int getHorizontalPadding() {
|
||||
return (int) PADDING_H;
|
||||
}
|
||||
|
||||
public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
|
||||
Bitmap b = info.getIcon(iconCache);
|
||||
|
||||
@@ -133,39 +149,53 @@ public class BubbleTextView extends CacheableTextView {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the hotdog bubble
|
||||
final Layout layout = getLayout();
|
||||
final RectF rect = mRect;
|
||||
final int left = getCompoundPaddingLeft();
|
||||
final int top = getExtendedPaddingTop();
|
||||
final int offset = getExtendedPaddingTop();
|
||||
final int paddingLeft = getPaddingLeft();
|
||||
final int paddingRight = getPaddingRight();
|
||||
final float left = layout.getLineLeft(0) + paddingLeft;
|
||||
final float right = Math.min(layout.getLineRight(0) + paddingRight,
|
||||
left + getWidth() - paddingLeft - paddingRight);
|
||||
mRect.set(left - mPaddingH, offset + (int) layout.getLineTop(0) - mPaddingV,
|
||||
right + mPaddingH, offset + (int) layout.getLineBottom(0) + mPaddingV);
|
||||
|
||||
rect.set(left + layout.getLineLeft(0) - mPaddingH,
|
||||
top + layout.getLineTop(0) - mPaddingV,
|
||||
Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft),
|
||||
top + layout.getLineBottom(0) + mPaddingV);
|
||||
// TEMPORARILY DISABLE DRAWING ROUND RECT -- re-enable this when we tweak CacheableTextView
|
||||
// to support padding so we can capture the "rounded" edges
|
||||
//canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, mPaint);
|
||||
canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mPaint);
|
||||
|
||||
super.draw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
if (w > 0 && h > 0) {
|
||||
// Temporary Workaround: We need to set padding to compress the text so that we can draw
|
||||
// a hotdog around it. Currently, the background images prevent us from applying the
|
||||
// padding in XML, so we are doing this programmatically
|
||||
int d = w - mAppCellWidth;
|
||||
int pL = d - (d / 2);
|
||||
int pR = d - pL;
|
||||
setPadding(pL, getPaddingTop(), pR, getPaddingBottom());
|
||||
}
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mBackground.setCallback(this);
|
||||
if (mBackground != null) mBackground.setCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mBackground.setCallback(null);
|
||||
if (mBackground != null) mBackground.setCallback(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSetAlpha(int alpha) {
|
||||
if (mPrevAlpha != alpha) {
|
||||
mPrevAlpha = alpha;
|
||||
mPaint.setAlpha(alpha);
|
||||
mPaint.setAlpha((int) (alpha * mBubbleColorAlpha));
|
||||
super.onSetAlpha(alpha);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.widget.TextView;
|
||||
public class CacheableTextView extends TextView {
|
||||
private Bitmap mCache;
|
||||
private final Paint mCachePaint = new Paint();
|
||||
private final Canvas mCacheCanvas = new Canvas();
|
||||
|
||||
private int mPrevAlpha = -1;
|
||||
private boolean mIsBuildingCache;
|
||||
@@ -57,6 +58,13 @@ public class CacheableTextView extends TextView {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
protected int getVerticalPadding() {
|
||||
return 0;
|
||||
}
|
||||
protected int getHorizontalPadding() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void buildAndEnableCache() {
|
||||
if (getLayout() == null) {
|
||||
mWaitingToGenerateCache = true;
|
||||
@@ -64,32 +72,34 @@ public class CacheableTextView extends TextView {
|
||||
}
|
||||
|
||||
final Layout layout = getLayout();
|
||||
|
||||
final int left = getCompoundPaddingLeft();
|
||||
final int top = getExtendedPaddingTop();
|
||||
mTextCacheLeft = layout.getLineLeft(0);
|
||||
mTextCacheTop = top + layout.getLineTop(0) - mPaddingV;
|
||||
final float prevAlpha = getAlpha();
|
||||
|
||||
int vPadding = getVerticalPadding();
|
||||
int hPadding = getHorizontalPadding();
|
||||
|
||||
mTextCacheLeft = layout.getLineLeft(0) - hPadding;
|
||||
mTextCacheTop = top + layout.getLineTop(0) - mPaddingV - vPadding;
|
||||
|
||||
mRectLeft = mScrollX + getLeft();
|
||||
mRectTop = 0;
|
||||
mTextCacheScrollX = mScrollX;
|
||||
|
||||
final float textCacheRight =
|
||||
Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft);
|
||||
final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV;
|
||||
Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft) + hPadding;
|
||||
final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV + vPadding;
|
||||
|
||||
mCache = Bitmap.createBitmap((int) (textCacheRight - mTextCacheLeft),
|
||||
(int) (textCacheBottom - mTextCacheTop), Config.ARGB_8888);
|
||||
Canvas c = new Canvas(mCache);
|
||||
c.translate(-mTextCacheLeft, -mTextCacheTop);
|
||||
mCacheCanvas.setBitmap(mCache);
|
||||
mCacheCanvas.translate(-mTextCacheLeft, -mTextCacheTop);
|
||||
|
||||
mIsBuildingCache = true;
|
||||
float alpha = getAlpha();
|
||||
setAlpha(1.0f);
|
||||
draw(c);
|
||||
setAlpha(alpha);
|
||||
draw(mCacheCanvas);
|
||||
setAlpha(prevAlpha);
|
||||
mIsBuildingCache = false;
|
||||
mCachePaint.setFilterBitmap(true);
|
||||
|
||||
// A hack-- we set the text to be one space (we don't make it empty just to avoid any
|
||||
// potential issues with text measurement, like line height, etc.) so that the text view
|
||||
@@ -119,4 +129,4 @@ public class CacheableTextView extends TextView {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1281,9 +1281,14 @@ public class Workspace extends SmoothPagedView
|
||||
v.getDrawingRect(clipRect);
|
||||
|
||||
// For a TextView, adjust the clip rect so that we don't include the text label
|
||||
if (v instanceof TextView) {
|
||||
if (v instanceof BubbleTextView) {
|
||||
final BubbleTextView tv = (BubbleTextView) v;
|
||||
clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V +
|
||||
tv.getLayout().getLineTop(0);
|
||||
} else if (v instanceof TextView) {
|
||||
final TextView tv = (TextView) v;
|
||||
clipRect.bottom = clipRect.top + tv.getCompoundPaddingTop() - 1;
|
||||
clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding() +
|
||||
tv.getLayout().getLineTop(0);
|
||||
}
|
||||
|
||||
// Draw the View into the bitmap.
|
||||
|
||||
Reference in New Issue
Block a user