diff options
| -rw-r--r-- | core/java/android/widget/Editor.java | 3 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/Magnifier.java | 40 | ||||
| -rw-r--r-- | core/res/res/layout/magnifier.xml | 7 | ||||
| -rw-r--r-- | core/res/res/values/dimens.xml | 1 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 |
5 files changed, 22 insertions, 30 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 384f4f8393cf..68ee19737fd0 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -165,7 +165,6 @@ public class Editor { private static final int MENU_ITEM_ORDER_PASTE_AS_PLAIN_TEXT = 11; private static final int MENU_ITEM_ORDER_PROCESS_TEXT_INTENT_ACTIONS_START = 100; - private static final float MAGNIFIER_ZOOM = 1.25f; @IntDef({MagnifierHandleTrigger.SELECTION_START, MagnifierHandleTrigger.SELECTION_END, MagnifierHandleTrigger.INSERTION}) @@ -4547,7 +4546,7 @@ public class Editor { + mTextView.getTotalPaddingTop() - mTextView.getScrollY(); suspendBlink(); - mMagnifier.show(xPosInView, yPosInView, MAGNIFIER_ZOOM); + mMagnifier.show(xPosInView, yPosInView); } protected final void dismissMagnifier() { diff --git a/core/java/com/android/internal/widget/Magnifier.java b/core/java/com/android/internal/widget/Magnifier.java index 6d54d7b8f1e2..f9e98eac9cfe 100644 --- a/core/java/com/android/internal/widget/Magnifier.java +++ b/core/java/com/android/internal/widget/Magnifier.java @@ -63,7 +63,7 @@ public final class Magnifier { // the copy is finished. private final Handler mPixelCopyHandler = Handler.getMain(); // Current magnification scale. - private float mScale; + private final float mZoomScale; // Timer used to schedule the copy task. private Timer mTimer; @@ -76,11 +76,12 @@ public final class Magnifier { public Magnifier(@NonNull View view) { mView = Preconditions.checkNotNull(view); final Context context = mView.getContext(); + final float elevation = context.getResources().getDimension(R.dimen.magnifier_elevation); final View content = LayoutInflater.from(context).inflate(R.layout.magnifier, null); content.findViewById(R.id.magnifier_inner).setClipToOutline(true); mWindowWidth = context.getResources().getDimensionPixelSize(R.dimen.magnifier_width); mWindowHeight = context.getResources().getDimensionPixelSize(R.dimen.magnifier_height); - final float elevation = context.getResources().getDimension(R.dimen.magnifier_elevation); + mZoomScale = context.getResources().getFloat(R.dimen.magnifier_zoom_scale); mWindow = new PopupWindow(context); mWindow.setContentView(content); @@ -90,7 +91,9 @@ public final class Magnifier { mWindow.setTouchable(false); mWindow.setBackgroundDrawable(null); - mBitmap = Bitmap.createBitmap(mWindowWidth, mWindowHeight, Bitmap.Config.ARGB_8888); + final int bitmapWidth = (int) (mWindowWidth / mZoomScale); + final int bitmapHeight = (int) (mWindowHeight / mZoomScale); + mBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); getImageView().setImageBitmap(mBitmap); } @@ -101,20 +104,8 @@ public final class Magnifier { * to the view. The lower end is clamped to 0 * @param yPosInView vertical coordinate of the center point of the magnifier source * relative to the view. The lower end is clamped to 0 - * @param scale the scale at which the magnifier zooms on the source content. The - * lower end is clamped to 1 and the higher end to 4 */ - public void show(@FloatRange(from=0) float xPosInView, - @FloatRange(from=0) float yPosInView, - @FloatRange(from=1, to=4) float scale) { - if (scale > 4) { - scale = 4; - } - - if (scale < 1) { - scale = 1; - } - + public void show(@FloatRange(from=0) float xPosInView, @FloatRange(from=0) float yPosInView) { if (xPosInView < 0) { xPosInView = 0; } @@ -123,10 +114,6 @@ public final class Magnifier { yPosInView = 0; } - if (mScale != scale) { - resizeBitmap(scale); - } - mScale = scale; configureCoordinates(xPosInView, yPosInView); if (mTimer == null) { @@ -164,6 +151,7 @@ public final class Magnifier { /** * @return the height of the magnifier window. */ + @NonNull public int getHeight() { return mWindowHeight; } @@ -171,15 +159,17 @@ public final class Magnifier { /** * @return the width of the magnifier window. */ + @NonNull public int getWidth() { return mWindowWidth; } - private void resizeBitmap(float scale) { - final int bitmapWidth = (int) (mWindowWidth / scale); - final int bitmapHeight = (int) (mWindowHeight / scale); - mBitmap.reconfigure(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); - getImageView().setImageBitmap(mBitmap); + /** + * @return the zoom scale of the magnifier. + */ + @NonNull + public float getZoomScale() { + return mZoomScale; } private void configureCoordinates(float xPosInView, float yPosInView) { diff --git a/core/res/res/layout/magnifier.xml b/core/res/res/layout/magnifier.xml index d6cd8b4e2737..f3344c7470a1 100644 --- a/core/res/res/layout/magnifier.xml +++ b/core/res/res/layout/magnifier.xml @@ -22,10 +22,11 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/magnifier_inner" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="@android:dimen/magnifier_width" + android:layout_height="@android:dimen/magnifier_height" + android:elevation="@android:dimen/magnifier_elevation" android:background="?android:attr/floatingToolbarPopupBackgroundDrawable" - android:elevation="@android:dimen/magnifier_elevation"> + android:scaleType="fitXY"> <ImageView android:id="@+id/magnifier_image" android:layout_width="match_parent" diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index 08e2233ebba7..dc75ba6077e7 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -525,6 +525,7 @@ <dimen name="magnifier_height">48dp</dimen> <dimen name="magnifier_elevation">2dp</dimen> <dimen name="magnifier_offset">42dp</dimen> + <item type="dimen" format="float" name="magnifier_zoom_scale">1.25</item> <dimen name="chooser_grid_padding">0dp</dimen> <!-- Spacing around the background change frome service to non-service --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 1627a0eca6dd..896de53cbc4e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2484,6 +2484,7 @@ <java-symbol type="dimen" name="magnifier_width" /> <java-symbol type="dimen" name="magnifier_height" /> <java-symbol type="dimen" name="magnifier_elevation" /> + <java-symbol type="dimen" name="magnifier_zoom_scale" /> <java-symbol type="dimen" name="magnifier_offset" /> <java-symbol type="string" name="date_picker_prev_month_button" /> |