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

Commit c9c684dc authored by Roy Chou's avatar Roy Chou Committed by Automerger Merge Worker
Browse files

chore(#MagSettingsPanel): make seekbar index reflect the controlling magnifier scale am: 96261a53

parents 1701022a 96261a53
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -107,6 +107,10 @@ public class MagnificationSettingsController implements ComponentCallbacks {
        return mWindowMagnificationSettings.isSettingPanelShowing();
    }

    void setMagnificationScale(float scale) {
        mWindowMagnificationSettings.setMagnificationScale(scale);
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        final int configDiff = newConfig.diff(mConfiguration);
+4 −0
Original line number Diff line number Diff line
@@ -310,6 +310,10 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
            return;
        }
        scales.put(displayId, scale);

        final MagnificationSettingsController magnificationSettingsController =
                mMagnificationSettingsSupplier.get(displayId);
        magnificationSettingsController.setMagnificationScale(scale);
    }

    @VisibleForTesting
+7 −6
Original line number Diff line number Diff line
@@ -1491,13 +1491,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
                // Simulate tapping the drag view so it opens the Settings.
                handleSingleTap(mDragView);
            } else if (action == R.id.accessibility_action_zoom_in) {
                final float scale = mScale + A11Y_CHANGE_SCALE_DIFFERENCE;
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                performScale(mScale + A11Y_CHANGE_SCALE_DIFFERENCE);
            } else if (action == R.id.accessibility_action_zoom_out) {
                final float scale = mScale - A11Y_CHANGE_SCALE_DIFFERENCE;
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                performScale(mScale - A11Y_CHANGE_SCALE_DIFFERENCE);
            } else if (action == R.id.accessibility_action_move_up) {
                move(0, -mSourceBounds.height());
            } else if (action == R.id.accessibility_action_move_down) {
@@ -1512,5 +1508,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
            mWindowMagnifierCallback.onAccessibilityActionPerformed(mDisplayId);
            return true;
        }

        private void performScale(float scale) {
            scale = A11Y_ACTION_SCALE_RANGE.clamp(scale);
            mWindowMagnifierCallback.onPerformScaleAction(mDisplayId, scale);
        }
    }
}
 No newline at end of file
+21 −37
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;

import com.android.internal.accessibility.common.MagnificationConstants;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
import com.android.systemui.R;
@@ -89,14 +88,12 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
    private final MagnificationGestureDetector mGestureDetector;
    private boolean mSingleTapDetected = false;

    @VisibleForTesting
    SeekBarWithIconButtonsView mZoomSeekbar;
    private SeekBarWithIconButtonsView mZoomSeekbar;
    private LinearLayout mAllowDiagonalScrollingView;
    private TextView mAllowDiagonalScrollingTitle;
    private Switch mAllowDiagonalScrollingSwitch;
    private LinearLayout mPanelView;
    private LinearLayout mSettingView;
    private LinearLayout mButtonView;
    private ImageButton mSmallButton;
    private ImageButton mMediumButton;
    private ImageButton mLargeButton;
@@ -110,10 +107,11 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
     * magnitude = 10 means, for every 1 scale increase, 10 progress increase in seekbar.
     */
    private int mSeekBarMagnitude;
    private float mScale = SCALE_MIN_VALUE;

    private WindowMagnificationSettingsCallback mCallback;

    private ContentObserver mMagnificationCapabilityObserver;
    private ContentObserver mMagnificationScaleObserver;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
@@ -163,31 +161,19 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
                });
            }
        };
        mMagnificationScaleObserver = new ContentObserver(
                mContext.getMainThreadHandler()) {
            @Override
            public void onChange(boolean selfChange) {
                setScaleSeekbar(getMagnificationScale());
            }
        };
    }

    private class ZoomSeekbarChangeListener implements
            SeekBarWithIconButtonsView.OnSeekBarWithIconButtonsChangeListener {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // Notify the service to update the magnifier scale only when the progress changed is
            // triggered by user interaction on seekbar
            if (fromUser) {
                float scale = (progress / (float) mSeekBarMagnitude) + SCALE_MIN_VALUE;
            // Update persisted scale only when scale >= PERSISTED_SCALE_MIN_VALUE const.
            // We assume if the scale is lower than the PERSISTED_SCALE_MIN_VALUE, there will be
            // no obvious magnification effect.
            if (scale >= MagnificationConstants.PERSISTED_SCALE_MIN_VALUE) {
                mSecureSettings.putFloatForUser(
                        Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
                        scale,
                        UserHandle.USER_CURRENT);
            }
                mCallback.onMagnifierScale(scale);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
@@ -322,7 +308,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest

        // Unregister observer before removing view
        mSecureSettings.unregisterContentObserver(mMagnificationCapabilityObserver);
        mSecureSettings.unregisterContentObserver(mMagnificationScaleObserver);
        mWindowManager.removeView(mSettingView);
        mIsVisible = false;
        if (resetPosition) {
@@ -374,7 +359,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
    private void showSettingPanel(boolean resetPosition) {
        if (!mIsVisible) {
            updateUIControlsIfNeeded();
            setScaleSeekbar(getMagnificationScale());
            setScaleSeekbar(mScale);
            if (resetPosition) {
                mDraggableWindowBounds.set(getDraggableWindowBounds());
                mParams.x = mDraggableWindowBounds.right;
@@ -387,10 +372,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
                    Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY,
                    mMagnificationCapabilityObserver,
                    UserHandle.USER_CURRENT);
            mSecureSettings.registerContentObserverForUser(
                    Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
                    mMagnificationScaleObserver,
                    UserHandle.USER_CURRENT);

            // Exclude magnification switch button from system gesture area.
            setSystemGestureExclusion();
@@ -430,11 +411,17 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
                UserHandle.USER_CURRENT);
    }

    private float getMagnificationScale() {
        return mSecureSettings.getFloatForUser(
                Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
                SCALE_MIN_VALUE,
                UserHandle.USER_CURRENT);
    /**
     * Only called from outside to notify the controlling magnifier scale changed
     *
     * @param scale The new controlling magnifier scale
     */
    public void setMagnificationScale(float scale) {
        mScale = scale;

        if (isSettingPanelShowing()) {
            setScaleSeekbar(scale);
        }
    }

    private void updateUIControlsIfNeeded() {
@@ -523,10 +510,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
        mZoomSeekbar.setMax((int) (mZoomSeekbar.getChangeMagnitude()
                * (SCALE_MAX_VALUE - SCALE_MIN_VALUE)));
        mSeekBarMagnitude = mZoomSeekbar.getChangeMagnitude();
        float scale = mSecureSettings.getFloatForUser(
                Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 0,
                UserHandle.USER_CURRENT);
        setScaleSeekbar(scale);
        setScaleSeekbar(mScale);
        mZoomSeekbar.setOnSeekBarWithIconButtonsChangeListener(new ZoomSeekbarChangeListener());

        mAllowDiagonalScrollingView =
+16 −0
Original line number Diff line number Diff line
@@ -170,6 +170,22 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
        mSeekBarListener.setOnSeekBarWithIconButtonsChangeListener(onSeekBarChangeListener);
    }

    /**
     * Only for testing. Get previous set mOnSeekBarChangeListener to the seekbar.
     */
    @VisibleForTesting
    public OnSeekBarWithIconButtonsChangeListener getOnSeekBarWithIconButtonsChangeListener() {
        return mSeekBarListener.mOnSeekBarChangeListener;
    }

    /**
     * Only for testing. Get {@link #mSeekbar} in the layout.
     */
    @VisibleForTesting
    public SeekBar getSeekbar() {
        return mSeekbar;
    }

    /**
     * Start and End icons might need to be updated when there is a change in seekbar progress.
     * Icon Start will need to be enabled when the seekbar progress is larger than 0.
Loading