Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from fidesmo/allow-programatic-setting-of-nfc-…
Browse files Browse the repository at this point in the history
…device-design

Allow programmatic setting of NFC device design
  • Loading branch information
Franzaine authored Mar 20, 2017
2 parents 46c1ac4 + 3de1a59 commit c90ce81
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
19 changes: 19 additions & 0 deletions android/src/main/java/nordpol/ui/NfcDeviceDesign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nordpol.android;

public enum NfcDeviceDesign {
// Needs to be an exact match to attrs.xml nfc_device
CARD_RUBY(0),
CARD_BLACK(1),
USB_BLACK(2),
USB_BLACK_FIDESMO(3);

private int ordinal;

NfcDeviceDesign(int ordinal){
this.ordinal = ordinal;
}

static NfcDeviceDesign getNfcDeviceDesign(int ordinal) {
return NfcDeviceDesign.values()[ordinal];
}
}
40 changes: 26 additions & 14 deletions android/src/main/java/nordpol/ui/NfcGuideView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import nordpol.android.NfcDeviceDesign;
import static nordpol.android.NfcDeviceDesign.getNfcDeviceDesign;

import nordpol.android.R;

Expand Down Expand Up @@ -108,20 +110,7 @@ public NfcGuideView(Context context, AttributeSet attrs) {
mNfcGuideHand = (ImageView) mRootView.findViewById(R.id.nfc_guide_view_hand);
nfcGuideViewTransactionItemIcon = (ImageView) mRootView.findViewById(R.id.nfc_guide_view_transaction_item_icon);

switch(nfcDeviceDesign) {
case 0:
mNfcGuideHand.setImageDrawable(getResDrawable(R.drawable.nfc_guide_view_hand_holding_card_ruby));
break;
case 1:
mNfcGuideHand.setImageDrawable(getResDrawable(R.drawable.nfc_guide_view_hand_holding_card_black));
break;
case 2:
mNfcGuideHand.setImageDrawable(getResDrawable(R.drawable.nfc_guide_view_hand_holding_usb_black));
break;
case 3:
mNfcGuideHand.setImageDrawable(getResDrawable(R.drawable.nfc_guide_view_hand_holding_usb_black_fidesmo));
break;
}
setNfcDeviceDesign(getNfcDeviceDesign(nfcDeviceDesign));

if (transactionItemIcon != null) {
nfcGuideViewTransactionItemIcon.setImageDrawable(transactionItemIcon);
Expand Down Expand Up @@ -374,4 +363,27 @@ private int getPixelsFromDp(float dp) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}

/**
* Sets the NfcDeviceDesign that is shown
*
* @param nfcDeviceDesign
*/
public void setNfcDeviceDesign(NfcDeviceDesign nfcDeviceDesign) {
mNfcGuideHand.setImageDrawable(getDeviceDrawable(nfcDeviceDesign));
}

private Drawable getDeviceDrawable(NfcDeviceDesign nfcDeviceDesign) {
switch(nfcDeviceDesign) {
case CARD_BLACK:
return getResDrawable(R.drawable.nfc_guide_view_hand_holding_card_black);
case USB_BLACK:
return getResDrawable(R.drawable.nfc_guide_view_hand_holding_usb_black);
case USB_BLACK_FIDESMO:
return getResDrawable(R.drawable.nfc_guide_view_hand_holding_usb_black_fidesmo);
case CARD_RUBY:
default:
return getResDrawable(R.drawable.nfc_guide_view_hand_holding_card_ruby);
}
}
}

0 comments on commit c90ce81

Please sign in to comment.