Updated on 2026-08-14
This commit is contained in:
parent
83aaebb422
commit
a7e2964c53
10 changed files with 117 additions and 242 deletions
|
|
@ -1,8 +1,21 @@
|
|||
package com.tangem.tangemcard.android.nfc
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.view.animation.Transformation
|
||||
import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
|
||||
class DeviceNFCAntennaLocation(private var context: Context,
|
||||
private var ivHandCardHorizontal: ImageView,
|
||||
private var ivHandCardVertical: ImageView,
|
||||
private var llHand: LinearLayoutCompat,
|
||||
private var llNfc: LinearLayoutCompat) {
|
||||
|
||||
class DeviceNFCAntennaLocation {
|
||||
companion object {
|
||||
const val CARD_ON_BACK = 0
|
||||
const val CARD_ON_FRONT = 1
|
||||
|
|
@ -16,7 +29,33 @@ class DeviceNFCAntennaLocation {
|
|||
var y: Float = 0.toFloat()
|
||||
var z: Int = 0
|
||||
|
||||
fun getAntennaLocation() {
|
||||
fun init() {
|
||||
getAntennaLocation()
|
||||
setCardOrientation()
|
||||
animate()
|
||||
}
|
||||
|
||||
fun animate() {
|
||||
val lp = llHand.layoutParams as RelativeLayout.LayoutParams
|
||||
val lp2 = llNfc.layoutParams as RelativeLayout.LayoutParams
|
||||
val dp = context.resources.displayMetrics.density
|
||||
val lm = dp * (69 + x * 75)
|
||||
lp.topMargin = (dp * (-100 + y * 250)).toInt()
|
||||
lp2.topMargin = (dp * (-125 + 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)
|
||||
}
|
||||
|
||||
private fun getAntennaLocation() {
|
||||
val codename = Build.DEVICE
|
||||
|
||||
// default values
|
||||
|
|
@ -37,4 +76,24 @@ class DeviceNFCAntennaLocation {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setCardOrientation() {
|
||||
when (orientation) {
|
||||
CARD_ORIENTATION_HORIZONTAL -> {
|
||||
ivHandCardHorizontal.visibility = View.VISIBLE
|
||||
ivHandCardVertical.visibility = View.GONE
|
||||
}
|
||||
|
||||
CARD_ORIENTATION_VERTICAL -> {
|
||||
ivHandCardVertical.visibility = View.VISIBLE
|
||||
ivHandCardHorizontal.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
// set card z position
|
||||
when (z) {
|
||||
DeviceNFCAntennaLocation.CARD_ON_BACK -> llHand.elevation = 0.0f
|
||||
DeviceNFCAntennaLocation.CARD_ON_FRONT -> llHand.elevation = 30.0f
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue