diff options
Diffstat (limited to 'core/java')
| -rwxr-xr-x | core/java/android/content/res/Resources.java | 11 | ||||
| -rw-r--r-- | core/java/android/text/Html.java | 4 | ||||
| -rw-r--r-- | core/java/android/text/Layout.java | 29 | ||||
| -rw-r--r-- | core/java/android/text/TextDirectionHeuristics.java | 74 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 19 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 7 | ||||
| -rw-r--r-- | core/java/android/widget/AdapterView.java | 6 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 103 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java | 15 |
9 files changed, 145 insertions, 123 deletions
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 24f8319..d7f901a 100755 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -73,6 +73,7 @@ public class Resources { private static final boolean DEBUG_LOAD = false; private static final boolean DEBUG_CONFIG = false; private static final boolean TRACE_FOR_PRELOAD = false; + private static final boolean TRACE_FOR_MISS_PRELOAD = false; private static final int ID_OTHER = 0x01000004; @@ -1899,6 +1900,16 @@ public class Resources { String file = value.string.toString(); + if (TRACE_FOR_MISS_PRELOAD) { + // Log only framework resources + if ((id >>> 24) == 0x1) { + final String name = getResourceName(id); + if (name != null) android.util.Log.d(TAG, "Loading framework drawable #" + + Integer.toHexString(id) + ": " + name + + " at " + file); + } + } + if (DEBUG_LOAD) Log.v(TAG, "Loading drawable for cookie " + value.assetCookie + ": " + file); diff --git a/core/java/android/text/Html.java b/core/java/android/text/Html.java index 85a3bbb..ca7263c 100644 --- a/core/java/android/text/Html.java +++ b/core/java/android/text/Html.java @@ -499,11 +499,11 @@ class HtmlToSpannedConverter implements ContentHandler { handleP(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("div")) { handleP(mSpannableStringBuilder); - } else if (tag.equalsIgnoreCase("em")) { + } else if (tag.equalsIgnoreCase("strong")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); } else if (tag.equalsIgnoreCase("b")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); - } else if (tag.equalsIgnoreCase("strong")) { + } else if (tag.equalsIgnoreCase("em")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("cite")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index 768071f..bdfe940 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -673,6 +673,35 @@ public abstract class Layout { return false; } + /** + * Returns true if the character at offset is right to left (RTL). + * @param offset the offset + * @return true if the character is RTL, false if it is LTR + */ + public boolean isRtlCharAt(int offset) { + int line = getLineForOffset(offset); + Directions dirs = getLineDirections(line); + if (dirs == DIRS_ALL_LEFT_TO_RIGHT) { + return false; + } + if (dirs == DIRS_ALL_RIGHT_TO_LEFT) { + return true; + } + int[] runs = dirs.mDirections; + int lineStart = getLineStart(line); + for (int i = 0; i < runs.length; i += 2) { + int start = lineStart + (runs[i] & RUN_LENGTH_MASK); + // No need to test the end as an offset after the last run should return the value + // corresponding of the last run + if (offset >= start) { + int level = (runs[i+1] >>> RUN_LEVEL_SHIFT) & RUN_LEVEL_MASK; + return ((level & 1) != 0); + } + } + // Should happen only if the offset is "out of bounds" + return false; + } + private boolean primaryIsTrailingPrevious(int offset) { int line = getLineForOffset(offset); int lineStart = getLineStart(line); diff --git a/core/java/android/text/TextDirectionHeuristics.java b/core/java/android/text/TextDirectionHeuristics.java index 18b4040..e5c1e5b 100644 --- a/core/java/android/text/TextDirectionHeuristics.java +++ b/core/java/android/text/TextDirectionHeuristics.java @@ -62,24 +62,6 @@ public class TextDirectionHeuristics { new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false); /** - * Examines only the strong directional non-format characters, and if either - * left to right or right to left characters are 60% or more of this total, - * determines that the direction follows the majority of characters. Falls - * back to left to right if neither direction meets this threshold. - */ - public static final TextDirectionHeuristic CHARCOUNT_LTR = - new TextDirectionHeuristicInternal(CharCount.INSTANCE_DEFAULT, false); - - /** - * Examines only the strong directional non-format characters, and if either - * left to right or right to left characters are 60% or more of this total, - * determines that the direction follows the majority of characters. Falls - * back to right to left if neither direction meets this threshold. - */ - public static final TextDirectionHeuristic CHARCOUNT_RTL = - new TextDirectionHeuristicInternal(CharCount.INSTANCE_DEFAULT, true); - - /** * Force the paragraph direction to the Locale direction. Falls back to left to right. */ public static final TextDirectionHeuristic LOCALE = TextDirectionHeuristicLocale.INSTANCE; @@ -255,62 +237,6 @@ public class TextDirectionHeuristics { } /** - * Algorithm that uses the relative proportion of strong directional - * characters (excluding LRE, LRO, RLE, RLO) to determine the direction - * of the paragraph, if the proportion exceeds a given threshold. - * - * @hide - */ - public static class CharCount implements TextDirectionAlgorithm { - private final float mThreshold; - - @Override - public TriState checkRtl(char[] text, int start, int count) { - int countLtr = 0; - int countRtl = 0; - for(int i = start, e = start + count; i < e; ++i) { - switch (isRtlText(Character.getDirectionality(text[i]))) { - case TRUE: - ++countLtr; - break; - case FALSE: - ++countRtl; - break; - default: - break; - } - } - int limit = (int)((countLtr + countRtl) * mThreshold); - if (limit > 0) { - if (countLtr > limit) { - return TriState.FALSE; - } - if (countRtl > limit) { - return TriState.TRUE; - } - } - return TriState.UNKNOWN; - } - - private CharCount(float threshold) { - mThreshold = threshold; - } - - public static CharCount withThreshold(float threshold) { - if (threshold < 0 || threshold > 1) { - throw new IllegalArgumentException(); - } - if (threshold == DEFAULT_THRESHOLD) { - return INSTANCE_DEFAULT; - } - return new CharCount(threshold); - } - - public static final float DEFAULT_THRESHOLD = 0.6f; - public static final CharCount INSTANCE_DEFAULT = new CharCount(DEFAULT_THRESHOLD); - } - - /** * Algorithm that uses the Locale direction to force the direction of a paragraph. */ public static class TextDirectionHeuristicLocale extends TextDirectionHeuristicImpl { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index fa1d249..ba23218 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -2568,26 +2568,18 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit public static final int TEXT_DIRECTION_ANY_RTL = 2; /** - * Text direction is the same as the one held by a 60% majority of the characters. If there is - * no majority then the paragraph direction is the resolved layout direction of the View. - * - * @hide - */ - public static final int TEXT_DIRECTION_CHAR_COUNT = 3; - - /** * Text direction is forced to LTR. * * @hide */ - public static final int TEXT_DIRECTION_LTR = 4; + public static final int TEXT_DIRECTION_LTR = 3; /** * Text direction is forced to RTL. * * @hide */ - public static final int TEXT_DIRECTION_RTL = 5; + public static final int TEXT_DIRECTION_RTL = 4; /** * Default text direction is inherited @@ -2603,7 +2595,6 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), - @ViewDebug.IntToString(from = TEXT_DIRECTION_CHAR_COUNT, to = "CHAR_COUNT"), @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") }) @@ -2621,7 +2612,6 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), - @ViewDebug.IntToString(from = TEXT_DIRECTION_CHAR_COUNT, to = "CHAR_COUNT"), @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") }) @@ -10320,7 +10310,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit throw new OutOfMemoryError(); } - bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); + Resources resources = getResources(); + if (resources != null) { + bitmap.setDensity(resources.getDisplayMetrics().densityDpi); + } Canvas canvas; if (attachInfo != null) { diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 64fbae6..5bb0ef2 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -6546,6 +6546,13 @@ public class WebView extends AbsoluteLayout } private void stopTouch() { + if (mScroller.isFinished() && !mSelectingText + && (mTouchMode == TOUCH_DRAG_MODE || mTouchMode == TOUCH_DRAG_LAYER_MODE)) { + WebViewCore.resumePriority(); + WebViewCore.resumeUpdatePicture(mWebViewCore); + nativeSetIsScrolling(false); + } + // we also use mVelocityTracker == null to tell us that we are // not "moving around", so we can take the slower/prettier // mode in the drawing code diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java index 4ba604d..b945038 100644 --- a/core/java/android/widget/AdapterView.java +++ b/core/java/android/widget/AdapterView.java @@ -926,8 +926,10 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup { } event.setItemCount(getCount()); event.setCurrentItemIndex(getSelectedItemPosition()); - event.setFromIndex(mFirstPosition); - event.setToIndex(mFirstPosition + getChildCount()); + if (getChildCount() > 0) { + event.setFromIndex(getFirstVisiblePosition()); + event.setToIndex(getLastVisiblePosition()); + } } @Override diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index abf1281..3f68ce3 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -10333,6 +10333,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private abstract class HandleView extends View implements TextViewPositionListener { protected Drawable mDrawable; + protected Drawable mDrawableLtr; + protected Drawable mDrawableRtl; private final PopupWindow mContainer; // Position with respect to the parent TextView private int mPositionX, mPositionY; @@ -10355,7 +10357,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // Used to delay the appearance of the action popup window private Runnable mActionPopupShower; - public HandleView() { + public HandleView(Drawable drawableLtr, Drawable drawableRtl) { super(TextView.this.mContext); mContainer = new PopupWindow(TextView.this.mContext, null, com.android.internal.R.attr.textSelectHandleWindowStyle); @@ -10364,14 +10366,24 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL); mContainer.setContentView(this); - initDrawable(); + mDrawableLtr = drawableLtr; + mDrawableRtl = drawableRtl; + + updateDrawable(); final int handleHeight = mDrawable.getIntrinsicHeight(); mTouchOffsetY = -0.3f * handleHeight; mIdealVerticalOffset = 0.7f * handleHeight; } - protected abstract void initDrawable(); + protected void updateDrawable() { + final int offset = getCurrentCursorOffset(); + final boolean isRtlCharAtOffset = mLayout.isRtlCharAt(offset); + mDrawable = isRtlCharAtOffset ? mDrawableRtl : mDrawableLtr; + mHotspotX = getHotspotX(mDrawable, isRtlCharAtOffset); + } + + protected abstract int getHotspotX(Drawable drawable, boolean isRtlRun); // Touch-up filter: number of previous positions remembered private static final int HISTORY_SIZE = 5; @@ -10487,7 +10499,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public abstract int getCurrentCursorOffset(); - public abstract void updateSelection(int offset); + protected void updateSelection(int offset) { + updateDrawable(); + } public abstract void updatePosition(float x, float y); @@ -10629,6 +10643,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private float mDownPositionX, mDownPositionY; private Runnable mHider; + public InsertionHandleView(Drawable drawable) { + super(drawable, drawable); + } + @Override public void show() { super.show(); @@ -10665,13 +10683,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } @Override - protected void initDrawable() { - if (mSelectHandleCenter == null) { - mSelectHandleCenter = mContext.getResources().getDrawable( - mTextSelectHandleRes); - } - mDrawable = mSelectHandleCenter; - mHotspotX = mDrawable.getIntrinsicWidth() / 2; + protected int getHotspotX(Drawable drawable, boolean isRtlRun) { + return drawable.getIntrinsicWidth() / 2; } @Override @@ -10741,14 +10754,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private class SelectionStartHandleView extends HandleView { + + public SelectionStartHandleView(Drawable drawableLtr, Drawable drawableRtl) { + super(drawableLtr, drawableRtl); + } + @Override - protected void initDrawable() { - if (mSelectHandleLeft == null) { - mSelectHandleLeft = mContext.getResources().getDrawable( - mTextSelectHandleLeftRes); + protected int getHotspotX(Drawable drawable, boolean isRtlRun) { + if (isRtlRun) { + return drawable.getIntrinsicWidth() / 4; + } else { + return (drawable.getIntrinsicWidth() * 3) / 4; } - mDrawable = mSelectHandleLeft; - mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4; } @Override @@ -10758,6 +10775,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public void updateSelection(int offset) { + super.updateSelection(offset); Selection.setSelection((Spannable) mText, offset, getSelectionEnd()); } @@ -10778,14 +10796,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private class SelectionEndHandleView extends HandleView { + + public SelectionEndHandleView(Drawable drawableLtr, Drawable drawableRtl) { + super(drawableLtr, drawableRtl); + } + @Override - protected void initDrawable() { - if (mSelectHandleRight == null) { - mSelectHandleRight = mContext.getResources().getDrawable( - mTextSelectHandleRightRes); + protected int getHotspotX(Drawable drawable, boolean isRtlRun) { + if (isRtlRun) { + return (drawable.getIntrinsicWidth() * 3) / 4; + } else { + return drawable.getIntrinsicWidth() / 4; } - mDrawable = mSelectHandleRight; - mHotspotX = mDrawable.getIntrinsicWidth() / 4; } @Override @@ -10795,6 +10817,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public void updateSelection(int offset) { + super.updateSelection(offset); Selection.setSelection((Spannable) mText, getSelectionStart(), offset); } @@ -10864,8 +10887,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private InsertionHandleView getHandle() { + if (mSelectHandleCenter == null) { + mSelectHandleCenter = mContext.getResources().getDrawable( + mTextSelectHandleRes); + } if (mHandle == null) { - mHandle = new InsertionHandleView(); + mHandle = new InsertionHandleView(mSelectHandleCenter); } return mHandle; } @@ -10899,10 +10926,30 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (isInBatchEditMode()) { return; } + initDrawables(); + initHandles(); + hideInsertionPointCursorController(); + } + private void initDrawables() { + if (mSelectHandleLeft == null) { + mSelectHandleLeft = mContext.getResources().getDrawable( + mTextSelectHandleLeftRes); + } + if (mSelectHandleRight == null) { + mSelectHandleRight = mContext.getResources().getDrawable( + mTextSelectHandleRightRes); + } + } + + private void initHandles() { // Lazy object creation has to be done before updatePosition() is called. - if (mStartHandle == null) mStartHandle = new SelectionStartHandleView(); - if (mEndHandle == null) mEndHandle = new SelectionEndHandleView(); + if (mStartHandle == null) { + mStartHandle = new SelectionStartHandleView(mSelectHandleLeft, mSelectHandleRight); + } + if (mEndHandle == null) { + mEndHandle = new SelectionEndHandleView(mSelectHandleRight, mSelectHandleLeft); + } mStartHandle.show(); mEndHandle.show(); @@ -11244,10 +11291,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case TEXT_DIRECTION_ANY_RTL: mTextDir = TextDirectionHeuristics.ANYRTL_LTR; break; - case TEXT_DIRECTION_CHAR_COUNT: - mTextDir = (defaultIsRtl ? TextDirectionHeuristics.CHARCOUNT_RTL: - TextDirectionHeuristics.CHARCOUNT_LTR); - break; case TEXT_DIRECTION_LTR: mTextDir = TextDirectionHeuristics.LTR; break; diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java index cd1f8ba..173279e 100644 --- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java +++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java @@ -79,6 +79,7 @@ public class MultiWaveView extends View { private static final int HIDE_ANIMATION_DURATION = RETURN_TO_HOME_DELAY; private static final int SHOW_ANIMATION_DURATION = 0; private static final int SHOW_ANIMATION_DELAY = 0; + private static final float TAP_RADIUS_SCALE_ACCESSIBILITY_ENABLED = 1.3f; private TimeInterpolator mChevronAnimationInterpolator = Ease.Quad.easeOut; private ArrayList<TargetDrawable> mTargetDrawables = new ArrayList<TargetDrawable>(); @@ -663,7 +664,7 @@ public class MultiWaveView extends View { final float y = event.getY(); final float dx = x - mWaveCenterX; final float dy = y - mWaveCenterY; - if (dist2(dx,dy) <= square(mTapRadius)) { + if (dist2(dx,dy) <= getScaledTapRadiusSquared()) { if (DEBUG) Log.v(TAG, "** Handle HIT"); switchToState(STATE_FIRST_TOUCH, x, y); moveHandleTo(x, y, false); @@ -684,7 +685,7 @@ public class MultiWaveView extends View { case MotionEvent.ACTION_HOVER_MOVE: final float dx = event.getX() - mWaveCenterX; final float dy = event.getY() - mWaveCenterY; - if (dist2(dx,dy) <= square(mTapRadius)) { + if (dist2(dx,dy) <= getScaledTapRadiusSquared()) { if (!mWaveHovered) { mWaveHovered = true; final long timeSinceLastHoverExitMillis = @@ -894,6 +895,16 @@ public class MultiWaveView extends View { return dx*dx + dy*dy; } + private float getScaledTapRadiusSquared() { + final float scaledTapRadius; + if (AccessibilityManager.getInstance(mContext).isEnabled()) { + scaledTapRadius = TAP_RADIUS_SCALE_ACCESSIBILITY_ENABLED * mTapRadius; + } else { + scaledTapRadius = mTapRadius; + } + return square(scaledTapRadius); + } + private void announceTargets() { StringBuilder utterance = new StringBuilder(); final int targetCount = mTargetDrawables.size(); |
