Updated on 2026-08-14

This commit is contained in:
Tangem 2019-01-26 18:41:56 +03:00
parent be707f0f4f
commit 40393e71b5
6 changed files with 205 additions and 127 deletions

View file

@ -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 {

View file

@ -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() {

View file

@ -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);

View file

@ -1,15 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tangem.presentation.activity.CreateNewWalletActivity">
<include
layout="@layout/layout_touch_card"
android:layout_width="400dp"
android:layout_height="250dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.75">
<TextView
android:layout_width="match_parent"
@ -23,8 +39,8 @@
android:id="@+id/tvCardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:fontFamily="@font/maax"
android:textAlignment="center"
android:textColor="@color/black"
@ -41,6 +57,8 @@
</LinearLayout>
<include layout="@layout/layout_progress_horizontal" />
<include
android:id="@+id/progressBar"
layout="@layout/layout_progress_horizontal" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -17,115 +17,11 @@
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="30dp"
app:srcCompat="@drawable/tangem_logo_full_new" />
<RelativeLayout
android:layout_width="400dp"
android:layout_height="250dp"
android:gravity="center_vertical|center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="100dp"
android:elevation="2dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imSmartphone"
android:layout_width="75dp"
android:layout_height="150dp"
app:srcCompat="@drawable/smartphone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/llNfc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="100dp"
android:elevation="1dp"
android:gravity="center"
android:orientation="vertical">
<com.skyfishjy.library.RippleBackground
android:id="@+id/rippleBackgroundNfc"
android:layout_width="150dp"
android:layout_height="150dp"
app:rb_color="@color/fab"
app:rb_duration="3000"
app:rb_radius="16dp"
app:rb_rippleAmount="4"
app:rb_scale="4"
app:rb_strokeWidth="8dp"
app:rb_type="strokeRipple">
</com.skyfishjy.library.RippleBackground>
</LinearLayout>
<LinearLayout
android:id="@+id/llHand"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"
android:elevation="0dp"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="@+id/ivHandCardHorizontal"
android:layout_width="190dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/hand_card_horizontal"/>
<ImageView
android:id="@+id/ivHandCardVertical"
android:layout_width="190dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/hand_card_vertical"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/rlProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:elevation="10dp"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.75"
android:background="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:alpha="1"
android:text="@string/reading"
android:textColor="@color/colorPrimary"
android:textSize="10sp"
android:textStyle="bold" />
<ProgressBar
android:layout_width="@dimen/size_progress_bar_big"
android:layout_height="@dimen/size_progress_bar_big"
android:layout_centerInParent="true"
android:alpha="1"
android:elevation="1dp" />
</RelativeLayout>
</RelativeLayout>
<include layout="@layout/layout_touch_card" />
<TextView
android:id="@+id/tvNFCHint"

View file

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="400dp"
android:layout_height="250dp"
android:gravity="center_vertical|center_horizontal"
tools:ignore="contentDescription"
tools:showIn="@layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="100dp"
android:elevation="2dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imSmartphone"
android:layout_width="75dp"
android:layout_height="150dp"
app:srcCompat="@drawable/smartphone" />
</LinearLayout>
<LinearLayout
android:id="@+id/llNfc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="100dp"
android:elevation="1dp"
android:gravity="center"
android:orientation="vertical">
<com.skyfishjy.library.RippleBackground
android:id="@+id/rippleBackgroundNfc"
android:layout_width="150dp"
android:layout_height="150dp"
app:rb_color="@color/fab"
app:rb_duration="3000"
app:rb_radius="16dp"
app:rb_rippleAmount="4"
app:rb_scale="4"
app:rb_strokeWidth="8dp"
app:rb_type="strokeRipple" />
</LinearLayout>
<LinearLayout
android:id="@+id/llHand"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"
android:elevation="0dp"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="@+id/ivHandCardHorizontal"
android:layout_width="190dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/hand_card_horizontal" />
<ImageView
android:id="@+id/ivHandCardVertical"
android:layout_width="190dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/hand_card_vertical" />
</LinearLayout>
<RelativeLayout
android:id="@+id/rlProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:elevation="10dp"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.75"
android:background="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:alpha="1"
android:text="@string/reading"
android:textColor="@color/colorPrimary"
android:textSize="12sp"
android:textStyle="bold" />
<ProgressBar
android:layout_width="@dimen/size_progress_bar_big"
android:layout_height="@dimen/size_progress_bar_big"
android:layout_centerInParent="true"
android:alpha="1"
android:elevation="1dp" />
</RelativeLayout>
</RelativeLayout>