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

Commit 4a4fc466 authored by Adnan's avatar Adnan Committed by Nolen Johnson
Browse files

Keyguard: Add option to scramble pin layout when unlocking (2/2).

Adapted to Lineage SDK and squashed with the following changes:

  From: Adnan Begovic <adnan@cyngn.com>
  Date: Wed, 05 Aug 2015 10:40:41 -0700

      Keyguard: Don't disable visibility when scrambling pin.

        Otherwise the first numbers text is flipped to invisible
        even though it shouldn't be.

      Change-Id: Ia2b80d594e7f11af7a60a85bdb4ea9909d0ac20b

  From: Adnan Begovic <adnan@cyngn.com>
  Date: Wed, 05 Aug 2015 16:21:27 -0700

      Keyguard: Fix scramblepin logic.

      Change-Id: I71e6d26e853fa7bfaeea4b3256902881ac7f74fc

  From: LuK1337 <priv.luk@gmail.com>
  Date: Sat Apr 24 18:14:46 2021 +0200

      Keyguard: Fix mapping mismatch between KeyEvent and NumPadKey

      Change-Id: Ida28a4f037c2f3fa843ac136779e026020d711db

Original Change-Id: Ibe8611eb0b8a5bd9275bc96682d2cbafaa37d8f5
Change-Id: I6716b1c76b69d51bd1457ce07de2274541fca1e8

Change-Id: Iad58845071e000c2483186587dd1f6355195576b
parent 26557a3b
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils;
import com.android.systemui.R;

import lineageos.providers.LineageSettings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
@@ -46,6 +51,9 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
    private ViewGroup mRow3;
    private int mDisappearYTranslation;
    private View[][] mViews;
    private boolean mScramblePin;

    private static List<Integer> sNumbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);

    public KeyguardPINView(Context context) {
        this(context, null);
@@ -140,6 +148,30 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
                new View[]{
                        null, mEcaView, null
                }};

        mScramblePin = LineageSettings.System.getInt(getContext().getContentResolver(),
                LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1;
        if (mScramblePin) {
            Collections.shuffle(sNumbers);
            // get all children who are NumPadKey's
            List<NumPadKey> views = new ArrayList<NumPadKey>();
            for (int i = 0; i < mContainer.getChildCount(); i++) {
                if (mContainer.getChildAt(i) instanceof LinearLayout) {
                    LinearLayout nestedLayout = ((LinearLayout) mContainer.getChildAt(i));
                    for (int j = 0; j < nestedLayout.getChildCount(); j++){
                        View view = nestedLayout.getChildAt(j);
                        if (view.getClass() == NumPadKey.class) {
                            views.add((NumPadKey) view);
                        }
                    }
                }
            }
            // reset the digits in the views
            for (int i = 0; i < sNumbers.size(); i++) {
                NumPadKey view = views.get(i);
                view.setDigit(sNumbers.get(i));
            }
        }
    }

    @Override
@@ -194,6 +226,14 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
        setClipChildren(enable);
    }

    @Override
    protected int getNumberIndex(int number) {
        if (mScramblePin) {
            return (sNumbers.indexOf(number) + 1) % sNumbers.size();
        }
        return super.getNumberIndex(number);
    }

    @Override
    public boolean hasOverlappingRendering() {
        return false;
+5 −1
Original line number Diff line number Diff line
@@ -120,9 +120,13 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
        }
    }

    protected int getNumberIndex(int number) {
        return number;
    }

    private void performNumberClick(int number) {
        if (number >= 0 && number <= 9) {
            mButtons[number].performClick();
            mButtons[getNumberIndex(number)].performClick();
        }
    }

+24 −11
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.Utils;
import com.android.systemui.R;

import lineageos.providers.LineageSettings;

public class NumPadKey extends ViewGroup {
    // list of "ABC", etc per digit, starting with '0'
    static String sKlondike[];
@@ -114,30 +116,41 @@ public class NumPadKey extends ViewGroup {
        mDigitText.setText(Integer.toString(mDigit));
        mKlondikeText = (TextView) findViewById(R.id.klondike_text);

        updateText();
        setContentDescription(mDigitText.getText().toString());

        Drawable background = getBackground();
        if (background instanceof RippleDrawable) {
            mAnimator = new NumPadAnimator(context, (RippleDrawable) background,
                    R.style.NumPadKey);
        } else {
            mAnimator = null;
        }
    }

    public void setDigit(int digit) {
        mDigit = digit;
        updateText();
    }

    private void updateText() {
       boolean scramblePin = (LineageSettings.System.getInt(getContext().getContentResolver(),
                LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1);
        if (mDigit >= 0) {
            mDigitText.setText(Integer.toString(mDigit));
            if (sKlondike == null) {
                sKlondike = getResources().getStringArray(R.array.lockscreen_num_pad_klondike);
            }
            if (sKlondike != null && sKlondike.length > mDigit) {
                String klondike = sKlondike[mDigit];
                final int len = klondike.length();
                if (len > 0) {
                if (len > 0 || scramblePin) {
                    mKlondikeText.setText(klondike);
                } else if (mKlondikeText.getVisibility() != View.GONE) {
                    mKlondikeText.setVisibility(View.INVISIBLE);
                }
            }
        }

        setContentDescription(mDigitText.getText().toString());

        Drawable background = getBackground();
        if (background instanceof RippleDrawable) {
            mAnimator = new NumPadAnimator(context, (RippleDrawable) background,
                    R.style.NumPadKey);
        } else {
            mAnimator = null;
        }
    }

    @Override