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

Commit f988bdfb authored by Adam Cohen's avatar Adam Cohen
Browse files

Fixing up glowpad scaling issues (issue 7494378)

Change-Id: I55c0f7a3774d42d4f5893b12bc0c08690268e351
parent 4eb36cfd
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ public class GlowPadView extends View {
    private int mMaxTargetHeight;
    private int mMaxTargetWidth;
    private float mRingScaleFactor = 1f;
    private boolean mAllowScaling;

    private float mOuterRadius = 0.0f;
    private float mSnapMargin = 0.0f;
@@ -222,6 +223,7 @@ public class GlowPadView extends View {
                mVibrationDuration);
        mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount,
                mFeedbackCount);
        mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
        TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
        mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0);
        mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
@@ -793,8 +795,12 @@ public class GlowPadView extends View {
    }

    private void updateGlowPosition(float x, float y) {
        mPointCloud.glowManager.setX(x);
        mPointCloud.glowManager.setY(y);
        float dx = x - mOuterRing.getX();
        float dy = y - mOuterRing.getY();
        dx *= 1f / mRingScaleFactor;
        dy *= 1f / mRingScaleFactor;
        mPointCloud.glowManager.setX(mOuterRing.getX() + dx);
        mPointCloud.glowManager.setY(mOuterRing.getY() + dy);
    }

    private void handleDown(MotionEvent event) {
@@ -863,7 +869,7 @@ public class GlowPadView extends View {

            if (mDragging) {
                // For multiple targets, snap to the one that matches
                final float snapRadius = mOuterRadius - mSnapMargin;
                final float snapRadius = mRingScaleFactor * mOuterRadius - mSnapMargin;
                final float snapDistance2 = snapRadius * snapRadius;
                // Find first target in range
                for (int i = 0; i < ntargets; i++) {
@@ -1034,6 +1040,10 @@ public class GlowPadView extends View {
     */
    private float computeScaleFactor(int desiredWidth, int desiredHeight,
            int actualWidth, int actualHeight) {

        // Return unity if scaling is not allowed.
        if (!mAllowScaling) return 1f;

        final int layoutDirection = getLayoutDirection();
        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);

+2 −1
Original line number Diff line number Diff line
@@ -42,4 +42,5 @@
    prvandroid:feedbackCount="1"
    prvandroid:vibrationDuration="20"
    prvandroid:glowRadius="@*android:dimen/glowpadview_glow_radius"
    prvandroid:pointDrawable="@*android:drawable/ic_lockscreen_glowdot" />
    prvandroid:pointDrawable="@*android:drawable/ic_lockscreen_glowdot"
    prvandroid:allowScaling="true" />
+5 −0
Original line number Diff line number Diff line
@@ -5484,6 +5484,11 @@
        <attr name="magneticTargets" format="boolean" />

        <attr name="gravity" />

        <!-- Determine whether the glow pad is allowed to scale to fit the bounds indicated
            by its parent. If this is set to false, no scaling will occur. If this is set to true
            scaling will occur to fit for any axis in which gravity is set to center. -->
        <attr name="allowScaling" format="boolean" />
    </declare-styleable>

    <!-- =============================== -->