Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Card ID #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public void onNewIntent(Intent intent) {
Log.i(TAG,"Discovered tag with intent: " + intent);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);


try {
ValueData val = Readers.getInstance().readTag(tag);
Log.w(TAG,"Setting read data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ValueFragment extends Fragment {
private ValueData valueData;
private TextView tvCurrentValue;
private TextView tvLastValue;
private TextView tvCardId;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,9 +34,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

tvCurrentValue = ((TextView) v.findViewById(R.id.current));
tvLastValue = (TextView) v.findViewById(R.id.last);
tvCardId = (TextView) v.findViewById(R.id.card_id);

ViewCompat.setTransitionName(tvCurrentValue, "current");
ViewCompat.setTransitionName(tvLastValue, "last");
ViewCompat.setTransitionName(tvCardId, "last");

if (savedInstanceState!=null) {
valueData = (ValueData) savedInstanceState.getSerializable(VALUE);
Expand All @@ -60,10 +63,19 @@ private void updateView() {
if (valueData==null) {
tvCurrentValue.setText(getString(R.string.place_on_card));
tvLastValue.setVisibility(View.GONE);
tvCardId.setVisibility(View.GONE);
} else {

String current = moneyStr(valueData.value);
tvCurrentValue.setText(current);

if(valueData.cardId == null) {
tvCardId.setVisibility(View.GONE);
} else {
tvCardId.setText(getString(R.string.card_id) + " " + fromByteArray(valueData.cardId));
tvCardId.setVisibility(View.VISIBLE);
}

if (valueData.lastTransaction != null) {
String last = moneyStr(valueData.lastTransaction);
tvLastValue.setText(getString(R.string.last_withdrawal) + " " + last);
Expand All @@ -74,6 +86,14 @@ private void updateView() {
}
}

static long fromByteArray(byte[] bytes) {
long value = 0;
for (int i = 0; i < bytes.length; i++) {
value += ((long) bytes[i] & 0xffL) << (8 * i);
}
return value;
}

@Override
public void onSaveInstanceState(Bundle bundle) {
bundle.putSerializable(VALUE, valueData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ValueData readTag(Tag tag) throws DesfireException {
tech.connect();

ValueData val = Readers.getInstance().readCard(desfireTag);
val.cardId = tag.getId();
ValueHolder.data=val;
return val;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@
* Stores Data read from a card
*/
public class ValueData implements Serializable {
/**
* Card ID
*/
public byte[] cardId;

/**
* Current value on card, in tenths of Euro cents.
*/
public int value;

/**
* Last transaction, in tenths of Euro cents. null if not supported by card.
*/
public Integer lastTransaction;

public ValueData(byte[] cardId, int value, Integer lastTransaction) {
this.cardId = cardId;
this.value = value;
this.lastTransaction = lastTransaction;
}
public ValueData(int value, Integer lastTransaction) {
this.value = value;
this.lastTransaction = lastTransaction;
Expand Down
10 changes: 10 additions & 0 deletions MensaGuthaben/src/main/res/layout/fragment_value.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@
tools:text="@string/last_withdrawal"
tools:visibility="visible"/>

<TextView
android:id="@+id/card_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:textSize="22sp"
android:visibility="gone"
tools:text="@string/card_id"
tools:visibility="visible"/>

</LinearLayout>
1 change: 1 addition & 0 deletions MensaGuthaben/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="turn_nfc_on">Bitte NFC einschalten</string>
<string name="goto_settings">Zu Einstellungen wechseln</string>
<string name="last_withdrawal">Letzte Abbuchung:</string>
<string name="card_id">Karten-ID:</string>
<string name="card_not_supported">Karte nicht unterstützt</string>
<string name="communication_fail">Kommunikation mit Karte fehlgeschlagen</string>

Expand Down
1 change: 1 addition & 0 deletions MensaGuthaben/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="turn_nfc_on">Please turn on NFC</string>
<string name="goto_settings">go to settings</string>
<string name="last_withdrawal">Last withdrawal:</string>
<string name="card_id">Card ID:</string>
<string name="card_not_supported">Card not supported</string>
<string name="communication_fail">Communication with Card failed</string>
<string name="website">If you test the app on cards from a different university, I\'d love to hear about the results. Write me <a href="mailto:[email protected]">a Mail</a> or <a href="https://github.com/jakobwenzel/MensaGuthaben/issues">via Github</a>!</string>
Expand Down