Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67d50f0b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Magnifier - 6] Simplify API and configuration"

parents 58488631 d27c36b8
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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() {
+15 −25
Original line number Diff line number Diff line
@@ -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) {
+4 −3
Original line number Diff line number Diff line
@@ -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"
+1 −0
Original line number Diff line number Diff line
@@ -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 -->
+1 −0
Original line number Diff line number Diff line
@@ -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" />