Skip to content

Commit b56076a

Browse files
Bart SearsAndroid (Google) Code Review
authored andcommitted
Merge "Fix WebTextView rings" into ics-mr1
2 parents 3744d1f + 8463c88 commit b56076a

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

core/java/android/webkit/WebTextView.java

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import android.content.Context;
2020
import android.graphics.Canvas;
2121
import android.graphics.Color;
22+
import android.graphics.ColorFilter;
2223
import android.graphics.Paint;
2324
import android.graphics.Paint.Style;
25+
import android.graphics.PixelFormat;
2426
import android.graphics.Rect;
2527
import android.graphics.drawable.ColorDrawable;
28+
import android.graphics.drawable.Drawable;
2629
import android.os.Bundle;
2730
import android.os.Handler;
2831
import android.os.Message;
@@ -51,7 +54,6 @@
5154
import android.view.inputmethod.EditorInfo;
5255
import android.view.inputmethod.InputConnection;
5356
import android.view.inputmethod.InputMethodManager;
54-
import android.widget.AbsoluteLayout;
5557
import android.widget.AbsoluteLayout.LayoutParams;
5658
import android.widget.AdapterView;
5759
import android.widget.ArrayAdapter;
@@ -74,7 +76,6 @@
7476

7577
static final String LOGTAG = "webtextview";
7678

77-
private Paint mRingPaint;
7879
private int mRingInset;
7980

8081
private WebView mWebView;
@@ -207,13 +208,51 @@ public void handleMessage(Message msg) {
207208
}
208209
}
209210
};
210-
float ringWidth = 4f * context.getResources().getDisplayMetrics().density;
211211
mReceiver = new MyResultReceiver(mHandler);
212-
mRingPaint = new Paint();
213-
mRingPaint.setColor(0x6633b5e5);
214-
mRingPaint.setStrokeWidth(ringWidth);
215-
mRingPaint.setStyle(Style.FILL);
212+
float ringWidth = 2f * context.getResources().getDisplayMetrics().density;
216213
mRingInset = (int) ringWidth;
214+
setBackgroundDrawable(new BackgroundDrawable(mRingInset));
215+
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
216+
getPaddingBottom());
217+
}
218+
219+
private static class BackgroundDrawable extends Drawable {
220+
221+
private Paint mPaint = new Paint();
222+
private int mBorderWidth;
223+
private Rect mInsetRect = new Rect();
224+
225+
public BackgroundDrawable(int width) {
226+
mPaint = new Paint();
227+
mPaint.setStrokeWidth(width);
228+
mBorderWidth = width;
229+
}
230+
231+
@Override
232+
public void draw(Canvas canvas) {
233+
mPaint.setColor(0x6633b5e5);
234+
canvas.drawRect(getBounds(), mPaint);
235+
mInsetRect.left = getBounds().left + mBorderWidth;
236+
mInsetRect.top = getBounds().top + mBorderWidth;
237+
mInsetRect.right = getBounds().right - mBorderWidth;
238+
mInsetRect.bottom = getBounds().bottom - mBorderWidth;
239+
mPaint.setColor(Color.WHITE);
240+
canvas.drawRect(mInsetRect, mPaint);
241+
}
242+
243+
@Override
244+
public void setAlpha(int alpha) {
245+
}
246+
247+
@Override
248+
public void setColorFilter(ColorFilter cf) {
249+
}
250+
251+
@Override
252+
public int getOpacity() {
253+
return PixelFormat.TRANSLUCENT;
254+
}
255+
217256
}
218257

219258
public void setAutoFillable(int queryId) {
@@ -223,35 +262,9 @@ public void setAutoFillable(int queryId) {
223262
}
224263

225264
@Override
226-
protected void onDraw(Canvas canvas) {
227-
super.onDraw(canvas);
228-
if (isFocused()) {
229-
final int ib = getHeight() - mRingInset;
230-
canvas.drawRect(0, 0, getWidth(), mRingInset, mRingPaint);
231-
canvas.drawRect(0, ib, getWidth(), getHeight(), mRingPaint);
232-
canvas.drawRect(0, mRingInset, mRingInset, ib, mRingPaint);
233-
canvas.drawRect(getWidth() - mRingInset, mRingInset, getWidth(), ib, mRingPaint);
234-
}
235-
}
236-
237-
private void growOrShrink(boolean grow) {
238-
AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) getLayoutParams();
239-
if (grow) {
240-
lp.x -= mRingInset;
241-
lp.y -= mRingInset;
242-
lp.width += 2 * mRingInset;
243-
lp.height += 2 * mRingInset;
244-
setPadding(getPaddingLeft() + mRingInset, getPaddingTop() + mRingInset,
245-
getPaddingRight() + mRingInset, getPaddingBottom() + mRingInset);
246-
} else {
247-
lp.x += mRingInset;
248-
lp.y += mRingInset;
249-
lp.width -= 2 * mRingInset;
250-
lp.height -= 2 * mRingInset;
251-
setPadding(getPaddingLeft() - mRingInset, getPaddingTop() - mRingInset,
252-
getPaddingRight() - mRingInset, getPaddingBottom() - mRingInset);
253-
}
254-
setLayoutParams(lp);
265+
public void setPadding(int left, int top, int right, int bottom) {
266+
super.setPadding(left + mRingInset, top + mRingInset,
267+
right + mRingInset, bottom + mRingInset);
255268
}
256269

257270
@Override
@@ -555,7 +568,6 @@ protected void onFocusChanged(boolean focused, int direction,
555568
} else if (!mInsideRemove) {
556569
mWebView.setActive(false);
557570
}
558-
growOrShrink(focused);
559571
mFromFocusChange = false;
560572
}
561573

@@ -966,6 +978,10 @@ private void setMaxLength(int maxLength) {
966978
*/
967979
/* package */ void setRect(int x, int y, int width, int height) {
968980
LayoutParams lp = (LayoutParams) getLayoutParams();
981+
x -= mRingInset;
982+
y -= mRingInset;
983+
width += 2 * mRingInset;
984+
height += 2 * mRingInset;
969985
boolean needsUpdate = false;
970986
if (null == lp) {
971987
lp = new LayoutParams(width, height, x, y);

0 commit comments

Comments
 (0)