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

Unverified Commit b549341e authored by Michael Bestas's avatar Michael Bestas Committed by LuK1337
Browse files

Settings: Forward port pattern visibility settings (2/2)

Change-Id: Ic627953c5df854c442671a98b5da539b994da18b
parent f55b6d33
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -76,6 +76,11 @@
    <string name="lock_pattern_size_6" translatable="false">6 \u00d7 6</string>
    <string name="lock_settings_picker_pattern_size_message">Choose a pattern size</string>

    <!-- Whether a visible red line will be drawn after the user has drawn the unlock pattern incorrectly -->
    <string name="lockpattern_settings_enable_error_path_title">Show pattern error</string>
    <!-- Whether the dots will be drawn when using the lockscreen pattern -->
    <string name="lockpattern_settings_enable_dots_title">Show pattern dots</string>

    <!-- Max refresh rate -->
    <string name="max_refresh_rate_title">Peak refresh rate</string>

+8 −0
Original line number Diff line number Diff line
@@ -77,6 +77,14 @@
            android:key="visiblepattern"
            android:title="@string/lockpattern_settings_enable_visible_pattern_title" />

        <SwitchPreferenceCompat
            android:key="visible_error_pattern"
            android:title="@string/lockpattern_settings_enable_error_path_title" />

        <SwitchPreferenceCompat
            android:key="visibledots"
            android:title="@string/lockpattern_settings_enable_dots_title" />

        <!-- available in pin -->
        <SwitchPreferenceCompat
            android:key="auto_pin_confirm"
+6 −0
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ import com.android.settings.safetycenter.LockScreenSafetySource;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.security.screenlock.AutoPinConfirmPreferenceController;
import com.android.settings.security.screenlock.LockAfterTimeoutPreferenceController;
import com.android.settings.security.screenlock.PatternDotsVisiblePreferenceController;
import com.android.settings.security.screenlock.PatternErrorVisiblePreferenceController;
import com.android.settings.security.screenlock.PatternVisiblePreferenceController;
import com.android.settings.security.screenlock.PinPrivacyPreferenceController;
import com.android.settings.security.screenlock.PinScramblePreferenceController;
@@ -710,6 +712,10 @@ public class ChooseLockGeneric extends SettingsActivity {
        private void buildUnlockSettingsPreferenceControllers() {
            mUnlockSettingsControllers.add(new PatternVisiblePreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PatternErrorVisiblePreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PatternDotsVisiblePreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PinPrivacyPreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PinScramblePreferenceController(
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.security.screenlock;

import android.content.Context;

import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;

public abstract class AbstractPatternSwitchPreferenceController
        extends AbstractPreferenceController
        implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {

    private final String mKey;
    private final int mUserId;
    private final LockPatternUtils mLockPatternUtils;

    public AbstractPatternSwitchPreferenceController(Context context, String key,
            int userId, LockPatternUtils lockPatternUtils) {
        super(context);
        mKey = key;
        mUserId = userId;
        mLockPatternUtils = lockPatternUtils;
    }

    @Override
    public boolean isAvailable() {
        return isPatternLock();
    }

    @Override
    public String getPreferenceKey() {
        return mKey;
    }

    @Override
    public void updateState(Preference preference) {
        ((TwoStatePreference) preference).setChecked(isEnabled(mLockPatternUtils, mUserId));
    }

    private boolean isPatternLock() {
        return mLockPatternUtils.getCredentialTypeForUser(mUserId)
                == LockPatternUtils.CREDENTIAL_TYPE_PATTERN;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        setEnabled(mLockPatternUtils, mUserId, (Boolean) newValue);
        return true;
    }

    protected abstract boolean isEnabled(LockPatternUtils utils, int userId);
    protected abstract void setEnabled(LockPatternUtils utils, int userId, boolean enabled);
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.security.screenlock;

import android.content.Context;

import com.android.internal.widget.LockPatternUtils;

public class PatternDotsVisiblePreferenceController
        extends AbstractPatternSwitchPreferenceController {
    private static final String PREF_KEY = "visibledots";

    public PatternDotsVisiblePreferenceController(Context context, int userId,
            LockPatternUtils lockPatternUtils) {
        super(context, PREF_KEY, userId, lockPatternUtils);
    }

    @Override
    protected boolean isEnabled(LockPatternUtils utils, int userId) {
        return utils.isVisibleDotsEnabled(userId);
    }

    @Override
    protected void setEnabled(LockPatternUtils utils, int userId, boolean enabled) {
        utils.setVisibleDotsEnabled(enabled, userId);
    }
}
Loading