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

Commit 600bf6a9 authored by Danny Baumann's avatar Danny Baumann Committed by jt1134
Browse files

Provide haptic feedback on long pressing keys in lockscreen.

Change-Id: I01c759c0944939aded669ac474cea646e1f51408
parent a24d20ff
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -805,6 +805,15 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
        if (action != null) {
            String uri = Settings.System.getString(context.getContentResolver(), action);
            if (uri != null && runAction(context, uri) != ACTION_RESULT_NOTRUN) {
                long[] pattern = getLongPressVibePattern(context);
                if (pattern != null) {
                    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                    if (pattern.length == 1) {
                        v.vibrate(pattern[0]);
                    } else {
                        v.vibrate(pattern, -1);
                    }
                }
                return true;
            }
        }
@@ -839,6 +848,26 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
        }
    }

    private static long[] getLongPressVibePattern(Context context) {
        if (Settings.System.getInt(context.getContentResolver(),
                Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0) {
            return null;
        }

        int[] defaultPattern = context.getResources().getIntArray(
                com.android.internal.R.array.config_longPressVibePattern);
        if (defaultPattern == null) {
            return null;
        }

        long[] pattern = new long[defaultPattern.length];
        for (int i = 0; i < defaultPattern.length; i++) {
            pattern[i] = defaultPattern[i];
        }

        return pattern;
    }

    void updateConfiguration() {
        Configuration newConfig = getResources().getConfiguration();
        if (newConfig.orientation != mCreationOrientation) {