Updated on 2026-08-14
This commit is contained in:
parent
be707f0f4f
commit
40393e71b5
6 changed files with 205 additions and 127 deletions
|
|
@ -11,13 +11,18 @@ import android.nfc.tech.IsoDep
|
|||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.view.animation.Transformation
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.Toast
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.tangemcard.android.nfc.DeviceNFCAntennaLocation
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.tangemcard.android.reader.NfcReader
|
||||
import com.tangem.tangemcard.data.asBundle
|
||||
|
|
@ -26,6 +31,7 @@ import com.tangem.tangemcard.tasks.CreateNewWalletTask
|
|||
import com.tangem.tangemcard.util.Util
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_create_new_wallet.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
|
||||
class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
|
|
@ -40,6 +46,8 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private lateinit var antenna: DeviceNFCAntennaLocation
|
||||
|
||||
private var createNewWalletTask: CreateNewWalletTask? = null
|
||||
private var lastReadSuccess = true
|
||||
|
||||
|
|
@ -58,6 +66,51 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
progressBar = findViewById(R.id.progressBar)
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
|
||||
// get NFC Antenna
|
||||
antenna = DeviceNFCAntennaLocation()
|
||||
antenna.getAntennaLocation()
|
||||
|
||||
// set card orientation
|
||||
when (antenna.orientation) {
|
||||
DeviceNFCAntennaLocation.CARD_ORIENTATION_HORIZONTAL -> {
|
||||
ivHandCardHorizontal.visibility = View.VISIBLE
|
||||
ivHandCardVertical.visibility = View.GONE
|
||||
}
|
||||
|
||||
DeviceNFCAntennaLocation.CARD_ORIENTATION_VERTICAL -> {
|
||||
ivHandCardVertical.visibility = View.VISIBLE
|
||||
ivHandCardHorizontal.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
// set card z position
|
||||
when (antenna.z) {
|
||||
DeviceNFCAntennaLocation.CARD_ON_BACK -> llHand.elevation = 0.0f
|
||||
DeviceNFCAntennaLocation.CARD_ON_FRONT -> llHand.elevation = 30.0f
|
||||
}
|
||||
|
||||
animate()
|
||||
}
|
||||
|
||||
private fun animate() {
|
||||
val lp = llHand.layoutParams as RelativeLayout.LayoutParams
|
||||
val lp2 = llNfc.layoutParams as RelativeLayout.LayoutParams
|
||||
val dp = resources.displayMetrics.density
|
||||
val lm = dp * (69 + antenna.x * 75)
|
||||
lp.topMargin = (dp * (-100 + antenna.y * 250)).toInt()
|
||||
lp2.topMargin = (dp * (-125 + antenna.y * 250)).toInt()
|
||||
llNfc.layoutParams = lp2
|
||||
|
||||
val a = object : Animation() {
|
||||
override fun applyTransformation(interpolatedTime: Float, t: Transformation) {
|
||||
lp.leftMargin = (lm * interpolatedTime).toInt()
|
||||
llHand.layoutParams = lp
|
||||
}
|
||||
}
|
||||
a.duration = 2000
|
||||
a.interpolator = DecelerateInterpolator()
|
||||
llHand.startAnimation(a)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
|
|
@ -70,11 +123,11 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
// Log.v(TAG, "UID: " + sUID);
|
||||
|
||||
if (sUID == ctx.card!!.uid) {
|
||||
if (lastReadSuccess) {
|
||||
if (lastReadSuccess)
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 5000
|
||||
} else {
|
||||
else
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
|
||||
createNewWalletTask = CreateNewWalletTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this)
|
||||
createNewWalletTask!!.start()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import com.tangem.util.PhoneUtility
|
|||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
|
@ -65,7 +66,7 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
private var zipFile: File? = null
|
||||
private var antenna: DeviceNFCAntennaLocation? = null
|
||||
private lateinit var antenna: DeviceNFCAntennaLocation
|
||||
private var unsuccessReadCount = 0
|
||||
private var lastTag: Tag? = null
|
||||
private var readCardInfoTask: ReadCardInfoTask? = null
|
||||
|
|
@ -98,11 +99,12 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
|
||||
rippleBackgroundNfc.startRippleAnimation()
|
||||
|
||||
// get NFC Antenna
|
||||
antenna = DeviceNFCAntennaLocation()
|
||||
antenna!!.getAntennaLocation()
|
||||
antenna.getAntennaLocation()
|
||||
|
||||
// set card orientation
|
||||
when (antenna!!.orientation) {
|
||||
when (antenna.orientation) {
|
||||
DeviceNFCAntennaLocation.CARD_ORIENTATION_HORIZONTAL -> {
|
||||
ivHandCardHorizontal.visibility = View.VISIBLE
|
||||
ivHandCardVertical.visibility = View.GONE
|
||||
|
|
@ -115,19 +117,19 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
}
|
||||
|
||||
// set card z position
|
||||
when (antenna!!.z) {
|
||||
when (antenna.z) {
|
||||
DeviceNFCAntennaLocation.CARD_ON_BACK -> llHand.elevation = 0.0f
|
||||
DeviceNFCAntennaLocation.CARD_ON_FRONT -> llHand.elevation = 30.0f
|
||||
}
|
||||
|
||||
animate()
|
||||
|
||||
// set phone name
|
||||
if (antenna!!.fullName != "")
|
||||
if (antenna.fullName != "")
|
||||
tvNFCHint.text = String.format(getString(R.string.scan_banknote), antenna!!.fullName)
|
||||
else
|
||||
tvNFCHint.text = String.format(getString(R.string.scan_banknote), getString(R.string.phone))
|
||||
|
||||
animate()
|
||||
|
||||
// NFC
|
||||
val intent = intent
|
||||
if (intent != null && (NfcAdapter.ACTION_TECH_DISCOVERED == intent.action || NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action)) {
|
||||
|
|
@ -388,9 +390,9 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
val lp = llHand.layoutParams as RelativeLayout.LayoutParams
|
||||
val lp2 = llNfc.layoutParams as RelativeLayout.LayoutParams
|
||||
val dp = resources.displayMetrics.density
|
||||
val lm = dp * (69 + antenna!!.x * 75)
|
||||
lp.topMargin = (dp * (-100 + antenna!!.y * 250)).toInt()
|
||||
lp2.topMargin = (dp * (-125 + antenna!!.y * 250)).toInt()
|
||||
val lm = dp * (69 + antenna.x * 75)
|
||||
lp.topMargin = (dp * (-100 + antenna.y * 250)).toInt()
|
||||
lp2.topMargin = (dp * (-125 + antenna.y * 250)).toInt()
|
||||
llNfc.layoutParams = lp2
|
||||
|
||||
val a = object : Animation() {
|
||||
|
|
|
|||
|
|
@ -104,14 +104,15 @@ public class WaitSecurityDelayDialog extends DialogFragment {
|
|||
// return instance;
|
||||
// }
|
||||
|
||||
private final static int MinRemainingDelayToShowDialog=1000;
|
||||
private final static int DelayBeforeShowDialog=5000;
|
||||
private final static int MinRemainingDelayToShowDialog = 1000;
|
||||
private final static int DelayBeforeShowDialog = 5000;
|
||||
|
||||
public static void onReadBeforeRequest(final AppCompatActivity activity, final int timeout) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timerToShowDelayDialog != null || timeout < DelayBeforeShowDialog+MinRemainingDelayToShowDialog) return;
|
||||
if (timerToShowDelayDialog != null || timeout < DelayBeforeShowDialog + MinRemainingDelayToShowDialog)
|
||||
return;
|
||||
timerToShowDelayDialog = new Timer();
|
||||
timerToShowDelayDialog.schedule(new TimerTask() {
|
||||
@Override
|
||||
|
|
@ -149,13 +150,14 @@ public class WaitSecurityDelayDialog extends DialogFragment {
|
|||
|
||||
if (msec == 0) {
|
||||
if (instance != null) {
|
||||
//TODO remove onNext java.lang.IllegalStateException: Fragment WaitSecurityDelayDialog{ba2c429 (2368a785-523e-4c3d-b46a-402d2c4f102b)} not associated with a fragment manager.
|
||||
instance.dismiss();
|
||||
instance = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (instance == null) {
|
||||
if( msec>MinRemainingDelayToShowDialog ) {
|
||||
if (msec > MinRemainingDelayToShowDialog) {
|
||||
instance = new WaitSecurityDelayDialog();
|
||||
// 1000ms - card delay notification interval
|
||||
instance.setup(msec + 1000, 1000);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue