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

Commit bbd06e85 authored by tibbi's avatar tibbi
Browse files

replace vibration with haptic feedback at the pin tab

parent 4d9d9ff4
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
package com.simplemobiletools.commons.extensions

import android.view.HapticFeedbackConstants
import android.view.View
import android.view.ViewTreeObserver

@@ -9,11 +10,17 @@ fun View.beVisibleIf(beVisible: Boolean) = if (beVisible) beVisible() else beGon

fun View.beGoneIf(beGone: Boolean) = beVisibleIf(!beGone)

fun View.beInvisible() { visibility = View.INVISIBLE }
fun View.beInvisible() {
    visibility = View.INVISIBLE
}

fun View.beVisible() { visibility = View.VISIBLE }
fun View.beVisible() {
    visibility = View.VISIBLE
}

fun View.beGone() { visibility = View.GONE }
fun View.beGone() {
    visibility = View.GONE
}

fun View.onGlobalLayout(callback: () -> Unit) {
    viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
@@ -29,3 +36,5 @@ fun View.isVisible() = visibility == View.VISIBLE
fun View.isInvisible() = visibility == View.INVISIBLE

fun View.isGone() = visibility == View.GONE

fun View.performHapticFeedback() = performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
+4 −6
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@ package com.simplemobiletools.commons.views

import android.content.Context
import android.graphics.PorterDuff
import android.os.Vibrator
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.performHapticFeedback
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.PROTECTION_PIN
@@ -52,12 +52,8 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
        if (pin.length < 10) {
            pin += number
            updatePinCode()

            val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
            if (vibrator.hasVibrator()) {
                vibrator.vibrate(100)
            }
        }
        performHapticFeedback()
    }

    private fun clear() {
@@ -65,6 +61,7 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
            pin = pin.substring(0, pin.length - 1)
            updatePinCode()
        }
        performHapticFeedback()
    }

    private fun confirmPIN() {
@@ -85,6 +82,7 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
                pin_lock_title.setText(R.string.enter_pin)
            }
        }
        performHapticFeedback()
    }

    private fun resetPin() {