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

Commit 4f231e89 authored by Adnan's avatar Adnan Committed by Michael Bestas
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

Original Change-Id: Ibe8611eb0b8a5bd9275bc96682d2cbafaa37d8f5
Change-Id: I6716b1c76b69d51bd1457ce07de2274541fca1e8
parent d1516928
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -21,11 +21,19 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

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;

/**
 * Displays a PIN pad for unlocking.
 */
@@ -44,6 +52,8 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
    private View[][] mViews;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;

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

    public KeyguardPINView(Context context) {
        this(context, null);
    }
@@ -119,6 +129,31 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
                mCallback.onCancelClicked();
            });
        }

        boolean scramblePin = (LineageSettings.System.getInt(getContext().getContentResolver(),
                LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1);
        if (scramblePin) {
            Collections.shuffle(sNumbers);
            // get all children who are NumPadKey's
            LinearLayout container = (LinearLayout) findViewById(R.id.container);
            List<NumPadKey> views = new ArrayList<NumPadKey>();
            for (int i = 0; i < container.getChildCount(); i++) {
                if (container.getChildAt(i) instanceof LinearLayout) {
                    LinearLayout nestedLayout = ((LinearLayout) container.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
+17 −8
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import android.widget.TextView;
import com.android.internal.widget.LockPatternUtils;
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[];
@@ -102,27 +104,34 @@ public class NumPadKey extends ViewGroup {
        mDigitText.setText(Integer.toString(mDigit));
        mKlondikeText = (TextView) findViewById(R.id.klondike_text);

        updateText();
        setBackground(mContext.getDrawable(R.drawable.ripple_drawable));
        setContentDescription(mDigitText.getText().toString());
    }

    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 {
                    mKlondikeText.setVisibility(View.INVISIBLE);
                }
            }
        }

        a = context.obtainStyledAttributes(attrs, android.R.styleable.View);
        if (!a.hasValueOrEmpty(android.R.styleable.View_background)) {
            setBackground(mContext.getDrawable(R.drawable.ripple_drawable_pin));
        }
        a.recycle();
        setContentDescription(mDigitText.getText().toString());
    }

    @Override