66import android .os .Handler ;
77import android .text .Html ;
88import android .view .View ;
9- import android .view .ViewGroup ;
109import android .view .WindowManager ;
1110import android .widget .ArrayAdapter ;
1211import android .widget .ListView ;
3130import com .dspread .pos .utils .TRACE ;
3231import com .dspread .pos_android_app .BR ;
3332import com .dspread .pos_android_app .R ;
34- import com .dspread .pos_android_app .databinding .ActivityPaymentCommonBinding ;
35- import com .dspread .pos_android_app .databinding .ActivityPaymentD35D50Binding ;
36- import com .dspread .pos_android_app .databinding .ActivityPaymentD70Binding ;
33+ import com .dspread .pos_android_app .databinding .ActivityPaymentDefaultBinding ;
34+ import com .dspread .pos_android_app .databinding .ActivityPaymentFrontNfcBinding ;
35+ import com .dspread .pos_android_app .databinding .ActivityPaymentSmallScreenBinding ;
3736import com .dspread .xpos .QPOSService ;
3837
3938import java .text .SimpleDateFormat ;
4645import me .goldze .mvvmhabit .base .BaseActivity ;
4746import me .goldze .mvvmhabit .utils .ToastUtils ;
4847
49- public class PaymentActivity extends BaseActivity <ActivityPaymentCommonBinding , PaymentViewModel > implements PaymentServiceCallback {
48+ public class PaymentActivity extends BaseActivity <ActivityPaymentDefaultBinding , PaymentViewModel > implements PaymentServiceCallback {
5049
5150 private String amount ;
5251 private String deviceAddress ;
@@ -63,22 +62,20 @@ public class PaymentActivity extends BaseActivity<ActivityPaymentCommonBinding,
6362 private AtomicBoolean isStarting = new AtomicBoolean (false );
6463 private final int [] imageResources = {R .mipmap .ic_insert_new_d70 , R .mipmap .ic_tap_new_d70 , R .mipmap .ic_swipe_new_d70 };
6564 private final String [] textResources = {"<span style='color:red'>Insert</span><span style='color:black'>, tap or swipe</span>" , "<span style='color:black'>Insert, </span><span style='color:red'>tap</span> <span style='color:black'>or swipe</span>" , "<span style='color:black'>Insert, tap or </span><span style='color:red'>swipe</span>" };
66- private Object binding ;
67- private ActivityPaymentCommonBinding commonBinding ;
68- private ActivityPaymentD70Binding d70Binding ;
69- private ActivityPaymentD35D50Binding d35d50Binding ;
65+ private ActivityPaymentDefaultBinding defaultBinding ;
66+ private ActivityPaymentSmallScreenBinding smallScreenBinding ;
67+ private ActivityPaymentFrontNfcBinding frontNfcBinding ;
7068
7169 @ Override
7270 public int initContentView (Bundle savedInstanceState ) {
7371 getWindow ().addFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
74- if (DeviceUtils .isD70 (this )){
75- return R .layout .activity_payment_d70 ;
76- } else if (DeviceUtils .isD35D50 ()) {
77- return R .layout .activity_payment_d35_d50 ;
72+ if (DeviceUtils .getScreenSize (this ) <= 3.0 ){
73+ return R .layout .activity_payment_small_screen ; //todo 名字
74+ } else if (DeviceUtils .isFrontNFCDevices ()) {
75+ return R .layout .activity_payment_front_nfc ; //todo
7876 }else {
79- return R .layout .activity_payment_common ;
77+ return R .layout .activity_payment_default ;
8078 }
81- // return R.layout.activity_payment;
8279 }
8380
8481 @ Override
@@ -92,20 +89,17 @@ public int initVariableId() {
9289 */
9390 @ Override
9491 public void initData () {
95- if (DeviceUtils .isD70 (this )){
96- d70Binding = DataBindingUtil .setContentView (this , R .layout .activity_payment_d70 );
97- binding = d70Binding ;
98- d70Binding .setViewModel (viewModel );
99- initD70UI ();
100- } else if (DeviceUtils .isD35D50 ()) {
101- d35d50Binding = DataBindingUtil .setContentView (this , R .layout .activity_payment_d35_d50 );
102- binding = d35d50Binding ;
103- d35d50Binding .setViewModel (viewModel );
104- initD35D50UI ();
92+ if (DeviceUtils .getScreenSize (this ) <=3.0 ){
93+ smallScreenBinding = DataBindingUtil .setContentView (this , R .layout .activity_payment_small_screen );
94+ smallScreenBinding .setViewModel (viewModel );
95+ initSmallScreenUI ();
96+ } else if (DeviceUtils .isFrontNFCDevices ()) {
97+ frontNfcBinding = DataBindingUtil .setContentView (this , R .layout .activity_payment_front_nfc );
98+ frontNfcBinding .setViewModel (viewModel );
99+ initFrontNFCUI ();
105100 }else {
106- commonBinding = DataBindingUtil .setContentView (this , R .layout .activity_payment_common );
107- binding = commonBinding ;
108- commonBinding .setViewModel (viewModel );
101+ defaultBinding = DataBindingUtil .setContentView (this , R .layout .activity_payment_default );
102+ defaultBinding .setViewModel (viewModel );
109103 initCommonUI ();
110104 }
111105 viewModel .titleText .set ("Paymenting" );
@@ -135,34 +129,34 @@ public void initViewObservable() {
135129 }
136130
137131 private void initCommonUI () {
138- if (commonBinding != null ) {
139- commonBinding .pinpadEditText .setText ("" );
132+ if (defaultBinding != null ) {
133+ defaultBinding .pinpadEditText .setText ("" );
140134 setupCommonAnimation ();
141135 }
142136 }
143137
144- private void initD70UI () {
145- if (d70Binding != null ) {
138+ private void initSmallScreenUI () {
139+ if (smallScreenBinding != null ) {
146140 setupImageSwitcher ();
147141 }
148142 }
149143
150- private void initD35D50UI () {
151- if (d35d50Binding != null ) {
152- setupD35D50Animation ();
144+ private void initFrontNFCUI () {
145+ if (frontNfcBinding != null ) {
146+ setupFrontNFCAnimation ();
153147 }
154148 }
155149
156- private void setupD35D50Animation () {
157- if (d35d50Binding != null ) {
150+ private void setupFrontNFCAnimation () {
151+ if (frontNfcBinding != null ) {
158152 String deviceModel = DeviceUtils .getPhoneModel ();
159153 if ("D35" .equals (deviceModel )) {
160- if (d35d50Binding .ivCardGuide != null ) {
161- d35d50Binding .ivCardGuide .setImageResource (R .drawable .ic_payguide_d35 );
154+ if (frontNfcBinding .ivCardGuide != null ) {
155+ frontNfcBinding .ivCardGuide .setImageResource (R .drawable .ic_payguide_d35 );
162156 }
163157 } else if ("D50" .equals (deviceModel )) {
164- if (d35d50Binding .ivCardGuide != null ) {
165- d35d50Binding .ivCardGuide .setImageResource (R .mipmap .ic_payguide_d50 );
158+ if (frontNfcBinding .ivCardGuide != null ) {
159+ frontNfcBinding .ivCardGuide .setImageResource (R .mipmap .ic_payguide_d50 );
166160 }
167161 }
168162 }
@@ -174,47 +168,45 @@ private void setupImageSwitcher() {
174168 @ Override
175169 public void run () {
176170 currentIndex = (currentIndex + 1 ) % imageResources .length ;
177- updateD70Content ();
171+ updateSmallScreenContent ();
178172 handler .postDelayed (this , 2000 );
179173 }
180174 };
181175
182- updateD70Content ();
176+ updateSmallScreenContent ();
183177 handler .postDelayed (runnable , 2000 );
184178 }
185179
186- private void updateD70Content () {
187- if (d70Binding != null ) {
188- d70Binding . d70ImageView .setImageResource (imageResources [currentIndex ]);
189- d70Binding .txtWaitInsertTapCard .setText (Html .fromHtml (textResources [currentIndex ], Html .FROM_HTML_MODE_COMPACT ));
180+ private void updateSmallScreenContent () {
181+ if (smallScreenBinding != null ) {
182+ smallScreenBinding . guideImageView .setImageResource (imageResources [currentIndex ]);
183+ smallScreenBinding .txtWaitInsertTapCard .setText (Html .fromHtml (textResources [currentIndex ], Html .FROM_HTML_MODE_COMPACT ));
190184 }
191185 }
192186
193-
194-
195187 /**
196188 * Dynamically set Lottie animations according to the device model
197189 */
198190 private void setupCommonAnimation () {
199191 String deviceModel = DeviceUtils .getPhoneModel ();
200192 TRACE .d ("model:" + deviceModel );
201- if (commonBinding != null ) {
193+ if (defaultBinding != null ) {
202194 if ("D20" .equals (deviceModel )) {
203- commonBinding .animationView .setAnimation ("D20_checkCardImg.json" );
204- commonBinding .animationView .setImageAssetsFolder ("D20_images/" );
195+ defaultBinding .animationView .setAnimation ("D20_checkCardImg.json" );
196+ defaultBinding .animationView .setImageAssetsFolder ("D20_images/" );
205197 } else if ("D80" .equals (deviceModel )) {
206- commonBinding .animationView .setAnimation ("D80_checkCard.json" );
207- commonBinding .animationView .setImageAssetsFolder ("D80_images/" );
198+ defaultBinding .animationView .setAnimation ("D80_checkCard.json" );
199+ defaultBinding .animationView .setImageAssetsFolder ("D80_images/" );
208200 } else if ("D60" .equals (deviceModel )) {
209- commonBinding .animationView .setAnimation ("D60_checkCard.json" );
210- commonBinding .animationView .setImageAssetsFolder ("D60_images/" );
201+ defaultBinding .animationView .setAnimation ("D60_checkCard.json" );
202+ defaultBinding .animationView .setImageAssetsFolder ("D60_images/" );
211203 } else {//D30
212- commonBinding .animationView .setAnimation ("D30_checkCard.json" );
213- commonBinding .animationView .setImageAssetsFolder ("D30_images/" );
204+ defaultBinding .animationView .setAnimation ("D30_checkCard.json" );
205+ defaultBinding .animationView .setImageAssetsFolder ("D30_images/" );
214206 }
207+ defaultBinding .animationView .loop (true );
208+ defaultBinding .animationView .playAnimation ();
215209 }
216- commonBinding .animationView .loop (true );
217- commonBinding .animationView .playAnimation ();
218210 }
219211
220212 private void initConnectionCallback () {
@@ -239,12 +231,12 @@ public void onRequestQposDisconnected() {
239231 }
240232
241233 private android .widget .EditText getPinpadEditText () {
242- if (DeviceUtils .isD70 (this )){
243- return d70Binding != null ? d70Binding .pinpadEditText : null ;
244- } else if (DeviceUtils .isD35D50 ()) {
245- return d35d50Binding != null ? d35d50Binding .pinpadEditText : null ;
234+ if (DeviceUtils .getScreenSize (this ) <= 3.0 ){
235+ return smallScreenBinding != null ? smallScreenBinding .pinpadEditText : null ;
236+ } else if (DeviceUtils .isFrontNFCDevices ()) {
237+ return frontNfcBinding != null ? frontNfcBinding .pinpadEditText : null ;
246238 }else {
247- return commonBinding != null ? commonBinding .pinpadEditText : null ;
239+ return defaultBinding != null ? defaultBinding .pinpadEditText : null ;
248240 }
249241 }
250242
@@ -528,7 +520,6 @@ protected void onDestroy() {
528520 }
529521
530522 private void paymentStatus (String amount , String maskedPAN , String terminalTime , String errorMsg ) {
531- // binding.d70ImageView.setVisibility(View.GONE);
532523 if (isStarting .compareAndSet (false , true )) {
533524 try {
534525 Intent intent = new Intent (PaymentActivity .this , PaymentStatusActivity .class );
@@ -555,20 +546,20 @@ private void paymentStatus(String amount, String maskedPAN, String terminalTime,
555546 }
556547
557548 private com .airbnb .lottie .LottieAnimationView getAnimationView () {
558- if (DeviceUtils .isD35D50 ()){
559- return d35d50Binding != null ? d35d50Binding .animationView : null ;
549+ if (DeviceUtils .isFrontNFCDevices ()){
550+ return frontNfcBinding != null ? frontNfcBinding .animationView : null ;
560551 }else {
561- return commonBinding != null ? commonBinding .animationView : null ;
552+ return defaultBinding != null ? defaultBinding .animationView : null ;
562553 }
563554 }
564555
565556 private View getRootLayout () {
566- if (DeviceUtils .isD35D50 ()){
567- return d35d50Binding != null ? d35d50Binding .getRoot () : null ;
568- } else if (DeviceUtils .isD70 (this )) {
569- return d70Binding != null ? d70Binding .getRoot () : null ;
557+ if (DeviceUtils .isFrontNFCDevices ()){
558+ return frontNfcBinding != null ? frontNfcBinding .getRoot () : null ;
559+ } else if (DeviceUtils .getScreenSize (this ) <= 3.0 ) {
560+ return smallScreenBinding != null ? smallScreenBinding .getRoot () : null ;
570561 }else {
571- return commonBinding != null ? commonBinding .getRoot () : null ;
562+ return defaultBinding != null ? defaultBinding .getRoot () : null ;
572563 }
573564 }
574565
0 commit comments