Updated on 2026-08-14

This commit is contained in:
Tangem 2018-07-12 15:55:36 +03:00
parent c78902999e
commit 318afe1517
6 changed files with 46 additions and 13 deletions

View file

@ -4,15 +4,18 @@ import android.os.Build
import com.tangem.domain.NFCLocation
class DeviceNFCAntennaLocation {
val TAG: String = DeviceNFCAntennaLocation::class.java.simpleName
companion object {
const val CARD_ON_BACK = 0
const val CARD_ON_FRONT = 1
const val CARD_ORIENTATION_HORIZONTAL = 0
const val CARD_ORIENTATION_VERTICAL = 1
}
var orientation: Int = 0
var fullName: String = ""
var x: Float = 0.toFloat()
var y: Float = 0.toFloat()
var z: Float = 0.toFloat()
var onBackSide: Boolean = false
var strength: Float = 0.toFloat()
var z: Int = 0
fun getAntennaLocation() {
val codename = Build.DEVICE
@ -22,9 +25,7 @@ class DeviceNFCAntennaLocation {
this.fullName = ""
this.x = 0.5f
this.y = 0.35f
this.z = 0f
this.onBackSide = true
this.strength = 1.0f
this.z = 0
for (nfcLocation in NFCLocation.values()) {
if (codename == nfcLocation.codename) {
@ -32,7 +33,7 @@ class DeviceNFCAntennaLocation {
this.orientation = nfcLocation.orientation
this.x = nfcLocation.x / 100f
this.y = nfcLocation.y / 100f
this.z = nfcLocation.z / 100f
this.z = nfcLocation.z
}
}
}

View file

@ -17,6 +17,7 @@ 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.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -77,6 +78,8 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
TextView tvNFCHint = findViewById(R.id.tvNFCHint);
llTapPrompt = findViewById(R.id.llTapPrompt);
LinearLayout hand = findViewById(R.id.llHand);
ImageView ivHandCardHorizontal = findViewById(R.id.ivHandCardHorizontal);
ImageView ivHandCardVertical = findViewById(R.id.ivHandCardVertical);
LinearLayout nfc = findViewById(R.id.llNFC);
RippleBackground rippleBackground = findViewById(R.id.imNFC);
FloatingActionButton fab = findViewById(R.id.fab);
@ -90,11 +93,34 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
DeviceNFCAntennaLocation antenna = new DeviceNFCAntennaLocation();
antenna.getAntennaLocation();
// set card orientation
switch (antenna.getOrientation()) {
case DeviceNFCAntennaLocation.CARD_ORIENTATION_HORIZONTAL:
ivHandCardHorizontal.setVisibility(View.VISIBLE);
ivHandCardVertical.setVisibility(View.GONE);
break;
case DeviceNFCAntennaLocation.CARD_ORIENTATION_VERTICAL:
ivHandCardVertical.setVisibility(View.VISIBLE);
ivHandCardHorizontal.setVisibility(View.GONE);
break;
}
switch (antenna.getZ()) {
case DeviceNFCAntennaLocation.CARD_ON_BACK:
break;
case DeviceNFCAntennaLocation.CARD_ON_FRONT:
break;
}
// set phone name
if (!antenna.getFullName().equals(""))
tvNFCHint.setText("Scan a banknote with your\n" + antenna.getFullName() + "\n as shown above");
tvNFCHint.setText(String.format(getString(R.string.scan_banknote), antenna.getFullName()));
else
tvNFCHint.setText("Scan a banknote with your\n" + getString(R.string.phone) + "\n as shown above");
tvNFCHint.setText(String.format(getString(R.string.scan_banknote), getString(R.string.phone)));
// animate
final RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) hand.getLayoutParams();