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

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

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

Change-Id: Ic627953c5df854c442671a98b5da539b994da18b
parent 1aa106b0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -42,4 +42,9 @@
    <string name="lock_pattern_size_5" translatable="false">5 \u00d7 5</string>
    <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>
</resources>
+9 −2
Original line number Diff line number Diff line
@@ -27,6 +27,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"
@@ -38,7 +46,6 @@
        android:title="@string/lockpattern_settings_enhanced_pin_privacy_title"
        android:summary="@string/lockpattern_settings_enhanced_pin_privacy_summary" />
 

    <!-- available in pin/pattern/password -->
    <com.android.settings.security.screenlock.ProtectedTimeoutListPreference
        android:key="lock_after_timeout"
+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);
    }
}
+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 PatternErrorVisiblePreferenceController
        extends AbstractPatternSwitchPreferenceController {
    private static final String PREF_KEY = "visible_error_pattern";

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

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

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