diff --git a/android/src/main/java/nordpol/ui/NfcDeviceDesign.java b/android/src/main/java/nordpol/ui/NfcDeviceDesign.java new file mode 100644 index 0000000..03a9fe8 --- /dev/null +++ b/android/src/main/java/nordpol/ui/NfcDeviceDesign.java @@ -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]; + } +} diff --git a/android/src/main/java/nordpol/ui/NfcGuideView.java b/android/src/main/java/nordpol/ui/NfcGuideView.java index 1f83a91..2f0bd74 100644 --- a/android/src/main/java/nordpol/ui/NfcGuideView.java +++ b/android/src/main/java/nordpol/ui/NfcGuideView.java @@ -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; @@ -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); @@ -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); + } + } }