-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace com.andrognito.pinlockview (#78)
* Replace com.andrognito.pinlockview (jcenter only dependency) with custom implementation * Fix lint issue by using requireContext()
- Loading branch information
Showing
11 changed files
with
444 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/KeyboardButtonView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package eu.pretix.pretixscan.droid.ui | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.widget.ImageView | ||
import android.widget.RelativeLayout | ||
import android.widget.TextView | ||
import eu.pretix.pretixscan.droid.R | ||
|
||
|
||
// (c) 2015 OrangeGangsters | ||
// MIT License | ||
// https://github.com/omadahealth/LolliPin/blob/0c523dfb7e9ee5dfcf37ad047cbb970ccd8794fb/lib/src/main/java/com/github/omadahealth/lollipin/lib/views/KeyboardButtonView.java | ||
|
||
interface KeyboardButtonClickedListener { | ||
|
||
} | ||
|
||
class KeyboardButtonView @JvmOverloads constructor(private val mContext: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : RelativeLayout(mContext, attrs, defStyleAttr) { | ||
|
||
private var mKeyboardButtonClickedListener: KeyboardButtonClickedListener? = null | ||
private var mRippleView: View? = null | ||
|
||
init { | ||
initializeView(attrs, defStyleAttr) | ||
} | ||
|
||
private fun initializeView(attrs: AttributeSet?, defStyleAttr: Int) { | ||
if (attrs != null && !isInEditMode) { | ||
val attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.KeyboardButtonView, | ||
defStyleAttr, 0) | ||
val text = attributes.getString(R.styleable.KeyboardButtonView_lp_keyboard_button_text) | ||
val image = attributes.getDrawable(R.styleable.KeyboardButtonView_lp_keyboard_button_image) | ||
val rippleEnabled = attributes.getBoolean(R.styleable.KeyboardButtonView_lp_keyboard_button_ripple_enabled, true) | ||
|
||
attributes.recycle() | ||
|
||
val inflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
val view = inflater.inflate(R.layout.view_keyboard_button, this) as KeyboardButtonView | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
view.focusable = NOT_FOCUSABLE | ||
} | ||
|
||
if (text != null) { | ||
val textView = view.findViewById(R.id.keyboard_button_textview) as TextView | ||
textView?.setText(text) | ||
} | ||
if (image != null) { | ||
val imageView = view.findViewById(R.id.keyboard_button_imageview) as ImageView | ||
if (imageView != null) { | ||
imageView!!.setImageDrawable(image) | ||
imageView!!.setVisibility(View.VISIBLE) | ||
} | ||
} | ||
|
||
mRippleView = view.findViewById(R.id.pin_code_keyboard_button_ripple) as View | ||
//mRippleView!!.setRippleAnimationListener(this) | ||
if (mRippleView != null) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
mRippleView!!.focusable = NOT_FOCUSABLE | ||
} | ||
if (!rippleEnabled) { | ||
mRippleView!!.setVisibility(View.INVISIBLE) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun setOnRippleAnimationEndListener(keyboardButtonClickedListener: KeyboardButtonClickedListener) { | ||
mKeyboardButtonClickedListener = keyboardButtonClickedListener | ||
} | ||
|
||
fun onRippleAnimationEnd() { | ||
if (mKeyboardButtonClickedListener != null) { | ||
//mKeyboardButtonClickedListener!!.onRippleAnimationEnd() | ||
} | ||
} | ||
|
||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean { | ||
onTouchEvent(event) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/PinDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package eu.pretix.pretixscan.droid.ui | ||
|
||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.view.KeyEvent | ||
import android.view.View | ||
import androidx.core.os.bundleOf | ||
import androidx.databinding.ObservableField | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.fragment.app.setFragmentResult | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import eu.pretix.pretixscan.droid.databinding.DialogPinBinding | ||
import java.util.Collections | ||
|
||
|
||
class PINInputDataHolder() { | ||
val input = ObservableField("") | ||
val text = ObservableField("") | ||
} | ||
|
||
class PinDialog : DialogFragment() { | ||
companion object { | ||
const val TAG = "PinDialogFragment" | ||
const val RESULT_PIN = "pin" | ||
const val RESULT_DISMISS = "dismiss" | ||
} | ||
|
||
val data = PINInputDataHolder() | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
data.input.set("") | ||
|
||
val binding = DialogPinBinding.inflate(layoutInflater) | ||
binding.data = data | ||
|
||
binding.keyboardButtonView0.setOnClickListener { pushDigit("0") } | ||
binding.keyboardButtonView00.visibility = View.INVISIBLE | ||
binding.keyboardButtonView1.setOnClickListener { pushDigit("1") } | ||
binding.keyboardButtonView2.setOnClickListener { pushDigit("2") } | ||
binding.keyboardButtonView3.setOnClickListener { pushDigit("3") } | ||
binding.keyboardButtonView4.setOnClickListener { pushDigit("4") } | ||
binding.keyboardButtonView5.setOnClickListener { pushDigit("5") } | ||
binding.keyboardButtonView6.setOnClickListener { pushDigit("6") } | ||
binding.keyboardButtonView7.setOnClickListener { pushDigit("7") } | ||
binding.keyboardButtonView8.setOnClickListener { pushDigit("8") } | ||
binding.keyboardButtonView9.setOnClickListener { pushDigit("9") } | ||
binding.keyboardButtonViewBackspace.setOnClickListener { pushBackspace() } | ||
|
||
return MaterialAlertDialogBuilder(requireContext()) | ||
.setView(binding.root) | ||
.setOnKeyListener { _, keyCode, event -> | ||
if (event.action != KeyEvent.ACTION_DOWN) return@setOnKeyListener false | ||
|
||
if (event.displayLabel.toString().matches(Regex("^[0-9]$"))) { | ||
pushDigit(event.displayLabel.toString()) | ||
return@setOnKeyListener true | ||
} | ||
if (keyCode == KeyEvent.KEYCODE_DEL) { | ||
pushBackspace() | ||
return@setOnKeyListener true | ||
} | ||
if (keyCode == KeyEvent.KEYCODE_ESCAPE) { | ||
dismiss() | ||
return@setOnKeyListener true | ||
} | ||
|
||
return@setOnKeyListener false | ||
} | ||
.create() | ||
} | ||
|
||
protected fun pushBackspace() { | ||
val current = data.input.get()!! | ||
if (current.isNotBlank()) { | ||
data.input.set(current.substring(0, current.length - 1)) | ||
} | ||
data.text.set(Collections.nCopies(data.input.get()!!.length, "*").joinToString("")) | ||
} | ||
|
||
protected fun pushDigit(digit: String) { | ||
val current = data.input.get()!! | ||
data.input.set(current + digit) | ||
data.text.set(Collections.nCopies(data.input.get()!!.length, "*").joinToString("")) | ||
setFragmentResult(RESULT_PIN, bundleOf(RESULT_PIN to data.input.get()!!)) | ||
} | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
setFragmentResult(RESULT_DISMISS, bundleOf()) | ||
super.onDismiss(dialog) | ||
} | ||
|
||
fun show(manager: FragmentManager) { | ||
super.show(manager, TAG) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
pretixscan/app/src/main/res/drawable/ic_backspace_black_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0,12l5.41,8.11c0.36,0.53 0.9,0.89 1.59,0.89h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM19,15.59L17.59,17 14,13.41 10.41,17 9,15.59 12.59,12 9,8.41 10.41,7 14,10.59 17.59,7 19,8.41 15.41,12 19,15.59z"/> | ||
</vector> |
Oops, something went wrong.