[Magnifier - 6] Simplify API and configuration
* removed "scale" from the show(...) API
* made the zoom scale a dimension => the widget is
fully self-configured
* fixed the magnifier not always scaling the content
to the full pop-up window size
Bug: 63531115
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: manual test that shows the magnifier working
Change-Id: Ibf5c571970c8f6bd3cdbc6d46fbe57d08291783c
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 384f4f8..68ee197 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -165,7 +165,6 @@
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 @@
+ 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 6d54d7b..f9e98ea 100644
--- a/core/java/com/android/internal/widget/Magnifier.java
+++ b/core/java/com/android/internal/widget/Magnifier.java
@@ -63,7 +63,7 @@
// 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 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 @@
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 @@
* 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 @@
yPosInView = 0;
}
- if (mScale != scale) {
- resizeBitmap(scale);
- }
- mScale = scale;
configureCoordinates(xPosInView, yPosInView);
if (mTimer == null) {
@@ -164,6 +151,7 @@
/**
* @return the height of the magnifier window.
*/
+ @NonNull
public int getHeight() {
return mWindowHeight;
}
@@ -171,15 +159,17 @@
/**
* @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 d6cd8b4..f3344c7 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 08e2233..dc75ba6 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 1627a0e..896de53 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" />