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

Commit d6644dcf authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

[Magnifier - 10] Make it public

* moves the Magnifier from com.android.internal.widget to
  android.widget
* removes useless public getters; useless for now because we have
  no magnifier configuration but the hardcoded one

Bug: 67839742
Bug: 63531115
Test: bit CtsWidgetTestCases:android.widget.cts.MagnifierTest
Change-Id: Ie6f474c4c781038650007a15937d61c650ee5fdd
parent e3a80101
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -51219,6 +51219,12 @@ package android.widget {
    field public android.view.View view;
    field public android.view.View view;
  }
  }
  public final class Magnifier {
    ctor public Magnifier(android.view.View);
    method public void dismiss();
    method public void show(float, float);
  }
  public class MediaController extends android.widget.FrameLayout {
  public class MediaController extends android.widget.FrameLayout {
    ctor public MediaController(android.content.Context, android.util.AttributeSet);
    ctor public MediaController(android.content.Context, android.util.AttributeSet);
    ctor public MediaController(android.content.Context, boolean);
    ctor public MediaController(android.content.Context, boolean);
+0 −1
Original line number Original line Diff line number Diff line
@@ -119,7 +119,6 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
import com.android.internal.widget.EditableInputConnection;
import com.android.internal.widget.EditableInputConnection;
import com.android.internal.widget.Magnifier;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
+27 −42
Original line number Original line Diff line number Diff line
@@ -11,10 +11,10 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */
 */


package com.android.internal.widget;
package android.widget;


import android.annotation.FloatRange;
import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -32,15 +32,13 @@ import android.view.PixelCopy;
import android.view.Surface;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.SurfaceView;
import android.view.View;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;


import com.android.internal.R;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;


/**
/**
 * Android magnifier widget. Can be used by any view which is attached to window.
 * Android magnifier widget. Can be used by any view which is attached to a window.
 */
 */
@UiThread
public final class Magnifier {
public final class Magnifier {
    // Use this to specify that a previous configuration value does not exist.
    // Use this to specify that a previous configuration value does not exist.
    private static final int NONEXISTENT_PREVIOUS_CONFIG_VALUE = -1;
    private static final int NONEXISTENT_PREVIOUS_CONFIG_VALUE = -1;
@@ -75,16 +73,20 @@ public final class Magnifier {
     *
     *
     * @param view the view for which this magnifier is attached
     * @param view the view for which this magnifier is attached
     */
     */
    @UiThread
    public Magnifier(@NonNull View view) {
    public Magnifier(@NonNull View view) {
        mView = Preconditions.checkNotNull(view);
        mView = Preconditions.checkNotNull(view);
        final Context context = mView.getContext();
        final Context context = mView.getContext();
        final float elevation = context.getResources().getDimension(R.dimen.magnifier_elevation);
        final float elevation = context.getResources().getDimension(
        final View content = LayoutInflater.from(context).inflate(R.layout.magnifier, null);
                com.android.internal.R.dimen.magnifier_elevation);
        content.findViewById(R.id.magnifier_inner).setClipToOutline(true);
        final View content = LayoutInflater.from(context).inflate(
        mWindowWidth = context.getResources().getDimensionPixelSize(R.dimen.magnifier_width);
                com.android.internal.R.layout.magnifier, null);
        mWindowHeight = context.getResources().getDimensionPixelSize(R.dimen.magnifier_height);
        content.findViewById(com.android.internal.R.id.magnifier_inner).setClipToOutline(true);
        mZoomScale = context.getResources().getFloat(R.dimen.magnifier_zoom_scale);
        mWindowWidth = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.magnifier_width);
        mWindowHeight = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.magnifier_height);
        mZoomScale = context.getResources().getFloat(
                com.android.internal.R.dimen.magnifier_zoom_scale);


        mWindow = new PopupWindow(context);
        mWindow = new PopupWindow(context);
        mWindow.setContentView(content);
        mWindow.setContentView(content);
@@ -104,13 +106,16 @@ public final class Magnifier {
     * Shows the magnifier on the screen.
     * Shows the magnifier on the screen.
     *
     *
     * @param xPosInView horizontal coordinate of the center point of the magnifier source relative
     * @param xPosInView horizontal coordinate of the center point of the magnifier source relative
     *        to the view. The lower end is clamped to 0
     *        to the view. The lower end is clamped to 0 and the higher end is clamped to the view
     *        width.
     * @param yPosInView vertical coordinate of the center point of the magnifier source
     * @param yPosInView vertical coordinate of the center point of the magnifier source
     *        relative to the view. The lower end is clamped to 0
     *        relative to the view. The lower end is clamped to 0 and the higher end is clamped to
     *        the view height.
     */
     */
    public void show(@FloatRange(from=0) float xPosInView, @FloatRange(from=0) float yPosInView) {
    public void show(@FloatRange(from = 0) float xPosInView,
        xPosInView = Math.max(0, xPosInView);
            @FloatRange(from = 0) float yPosInView) {
        yPosInView = Math.max(0, yPosInView);
        xPosInView = Math.max(0, Math.min(xPosInView, mView.getWidth()));
        yPosInView = Math.max(0, Math.min(yPosInView, mView.getHeight()));


        configureCoordinates(xPosInView, yPosInView);
        configureCoordinates(xPosInView, yPosInView);


@@ -136,7 +141,7 @@ public final class Magnifier {
    }
    }


    /**
    /**
     * Dismisses the magnifier from the screen.
     * Dismisses the magnifier from the screen. Calling this on a dismissed magnifier is a no-op.
     */
     */
    public void dismiss() {
    public void dismiss() {
        mWindow.dismiss();
        mWindow.dismiss();
@@ -155,27 +160,6 @@ public final class Magnifier {
        }
        }
    }
    }


    /**
     * @return the height of the magnifier window.
     */
    public int getHeight() {
        return mWindowHeight;
    }

    /**
     * @return the width of the magnifier window.
     */
    public int getWidth() {
        return mWindowWidth;
    }

    /**
     * @return the zoom scale of the magnifier.
     */
    public float getZoomScale() {
        return mZoomScale;
    }

    private void configureCoordinates(float xPosInView, float yPosInView) {
    private void configureCoordinates(float xPosInView, float yPosInView) {
        final float posX;
        final float posX;
        final float posY;
        final float posY;
@@ -195,7 +179,7 @@ public final class Magnifier {
        mCenterZoomCoords.y = Math.round(posY);
        mCenterZoomCoords.y = Math.round(posY);


        final int verticalMagnifierOffset = mView.getContext().getResources().getDimensionPixelSize(
        final int verticalMagnifierOffset = mView.getContext().getResources().getDimensionPixelSize(
                R.dimen.magnifier_offset);
                com.android.internal.R.dimen.magnifier_offset);
        mWindowCoords.x = mCenterZoomCoords.x - mWindowWidth / 2;
        mWindowCoords.x = mCenterZoomCoords.x - mWindowWidth / 2;
        mWindowCoords.y = mCenterZoomCoords.y - mWindowHeight / 2 - verticalMagnifierOffset;
        mWindowCoords.y = mCenterZoomCoords.y - mWindowHeight / 2 - verticalMagnifierOffset;
    }
    }
@@ -231,6 +215,7 @@ public final class Magnifier {
    }
    }


    private ImageView getImageView() {
    private ImageView getImageView() {
        return mWindow.getContentView().findViewById(R.id.magnifier_image);
        return mWindow.getContentView().findViewById(
                com.android.internal.R.id.magnifier_image);
    }
    }
}
}