Skip to content

Commit

Permalink
AND-9515 Disable system menu for PinCode fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Mama1emon committed Dec 19, 2024
1 parent 3ce1984 commit bf79e20
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 39 deletions.
7 changes: 4 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.tangem.sdk.ui.common

import android.os.Build
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.google.android.material.textfield.TextInputEditText
import com.tangem.sdk.R

internal fun TextInputEditText.disableContextMenu() {
setOnCreateContextMenuListener { _, _, _ -> }

customInsertionActionModeCallback = EmptyActionModeCallback
customSelectionActionModeCallback = EmptyActionModeCallback

setTextIsSelectable(false)

isLongClickable = false
setOnLongClickListener { false }

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setTextSelectHandle(R.drawable.empty_text_selector)
setTextSelectHandleLeft(R.drawable.empty_text_selector)
setTextSelectHandleRight(R.drawable.empty_text_selector)
}
}

internal fun TextInputEditText.disableAutofill() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(null)
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO
}
}

private object EmptyActionModeCallback : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean = false
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean = false
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean = false
override fun onDestroyActionMode(mode: ActionMode?) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.tangem.sdk.SessionViewDelegateState
import com.tangem.sdk.extensions.hideSoftKeyboard
import com.tangem.sdk.extensions.showSoftKeyboard
import com.tangem.sdk.postUI
import com.tangem.sdk.ui.common.disableAutofill
import com.tangem.sdk.ui.common.disableContextMenu

/**
* Created by Anton Zhilenkov on 05/08/2020.
Expand All @@ -32,7 +34,6 @@ class PinCodeModificationWidget(
private val tvScreenTitle: TextView = mainView.findViewById(R.id.tvScreenTitle)

private val tilPinCode: TextInputLayout = mainView.findViewById(R.id.tilPinCode)
private val tilNewPinCode: TextInputLayout = mainView.findViewById(R.id.tilNewPinCode)
private val tilPinCodeConfirm: TextInputLayout = mainView.findViewById(R.id.tilPinCodeConfirm)

private val etPinCode: TextInputEditText = mainView.findViewById(R.id.etPinCode)
Expand All @@ -51,6 +52,12 @@ class PinCodeModificationWidget(
init {
setStateByMode()
setupInnerLogic()

etPinCode.disableContextMenu()
etPinCodeConfirm.disableContextMenu()

etPinCode.disableAutofill()
etPinCodeConfirm.disableAutofill()
}

override fun setState(params: SessionViewDelegateState) {
Expand All @@ -73,15 +80,13 @@ class PinCodeModificationWidget(
Mode.SET -> {
tvScreenTitle.text = getFormattedString(R.string.pin_set_code_format, nameOfPin)
tilPinCode.hint = nameOfPin
tilNewPinCode.visibility = View.GONE
tilPinCodeConfirm.hint = getFormattedString(R.string.pin_set_code_confirm_format, nameOfPin)
btnSave.text = getString(R.string.common_continue)
}
Mode.RESET -> {
tvScreenTitle.text = getFormattedString(R.string.pin_change_new_code_format, nameOfPin)
tilPinCode.hint = nameOfPin
etPinCode.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
tilNewPinCode.visibility = View.GONE
tilPinCodeConfirm.hint = getFormattedString(R.string.pin_set_code_confirm_format, nameOfPin)
etPinCodeConfirm.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
btnSave.text = getString(R.string.common_continue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import com.tangem.sdk.extensions.localizedDescription
import com.tangem.sdk.extensions.show
import com.tangem.sdk.extensions.showSoftKeyboard
import com.tangem.sdk.postUI
import com.tangem.sdk.ui.common.disableAutofill
import com.tangem.sdk.ui.common.disableContextMenu

/**
* Created by Anton Zhilenkov on 09/08/2020.
Expand All @@ -29,23 +31,24 @@ class PinCodeRequestWidget(mainView: View) : BaseSessionDelegateStateWidget(main
private val etPinCode = mainView.findViewById<TextInputEditText>(R.id.etPinCode)
private val btnContinue = mainView.findViewById<Button>(R.id.btnContinue)
private val btnForgotCode = mainView.findViewById<Button>(R.id.btnForgotCode)
private val expandingView = mainView.findViewById<View>(R.id.expandingView)

init {
etPinCode.isSingleLine = true
etPinCode.imeOptions = EditorInfo.IME_ACTION_DONE
etPinCode.setOnEditorActionListener { v, actionId, event ->
etPinCode.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
btnContinue.performClick()
return@setOnEditorActionListener true
true
} else {
false
}
return@setOnEditorActionListener false
}
val hiddenPassword = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
etPinCode.inputType = hiddenPassword
}

fun canExpand(): Boolean = expandingView != null
etPinCode.disableContextMenu()
etPinCode.disableAutofill()
}

override fun setState(params: SessionViewDelegateState) {
when (params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<size
android:width="0dp"
android:height="0dp" />
</shape>
19 changes: 0 additions & 19 deletions tangem-sdk-android/src/main/res/layout/pin_code_change_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilNewPinCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:boxBackgroundColor="@android:color/transparent"
tools:hint="@string/pin_change_new_code_format">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etNewPinCode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:inputType="textPassword"
android:paddingStart="0dp"
android:paddingEnd="0dp" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPinCodeConfirm"
android:layout_width="match_parent"
Expand Down
13 changes: 6 additions & 7 deletions tangem-sdk-android/src/main/res/layout/reset_codes_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"

>
android:focusableInTouchMode="true">

<View
android:id="@+id/expandingView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

</View>

<LinearLayout
Expand All @@ -30,7 +27,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold" />
android:textStyle="bold"
tools:text="Reset pin1" />

<FrameLayout
android:id="@+id/leapfrog_views_container"
Expand Down Expand Up @@ -99,7 +97,7 @@
android:textColor="@color/sdk_message_header"
android:textSize="20sp"
android:textStyle="bold"
tools:text="Connect card and phone" />
tools:text="Tap the card or ring you want to restore" />

<TextView
android:id="@+id/tvMessageSubtitle"
Expand All @@ -109,7 +107,8 @@
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:textColor="@color/sdk_message_body"
android:textSize="15sp" />
android:textSize="15sp"
tools:text="First, prepare the card or ring for restore process"/>
</LinearLayout>


Expand Down

0 comments on commit bf79e20

Please sign in to comment.