Implemented NFC Card Reader Code from https://git.sterul.com/student-projects/dhbw...
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / nfcreader / MifareDESFire / ValueFileSettings.java
diff --git a/app/src/main/java/de/dhbwloe/campusapp/nfcreader/MifareDESFire/ValueFileSettings.java b/app/src/main/java/de/dhbwloe/campusapp/nfcreader/MifareDESFire/ValueFileSettings.java
new file mode 100644 (file)
index 0000000..fb3bc18
--- /dev/null
@@ -0,0 +1,74 @@
+package de.dhbwloe.campusapp.nfcreader.MifareDESFire;
+
+import android.util.Log;
+
+import de.dhbwloe.campusapp.nfcreader.Hex;
+
+/**
+ * Created by stefan on 22.01.16.
+ */
+public class ValueFileSettings extends FileSettings {
+    private int lowerLimit;
+    private int upperLimit;
+    private int limitedCreditValue;
+    private boolean limitedCreditEnabled;
+
+    public ValueFileSettings(String fileType, String communicationSettings, String accessRights, int lowerLimit, int upperLimit, int limitedCreditValue, boolean limitedCreditEnabled) {
+        super(fileType, communicationSettings, accessRights);
+        this.lowerLimit = lowerLimit;
+        this.upperLimit = upperLimit;
+        this.limitedCreditValue = limitedCreditValue;
+        this.limitedCreditEnabled = limitedCreditEnabled;
+    }
+
+    public static ValueFileSettings createByRawData(Byte[] rawData) {
+        String fileType = Hex.hexToString(Hex.subByteArray(0, 1, rawData));
+        String communicationSettings = Hex.hexToString(Hex.subByteArray(1, 2, rawData));
+        String accessRights = Hex.hexToString(Hex.reverseByteOrder(Hex.subByteArray(2,4, rawData)));
+        int lowerLimit = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(4, 8, rawData)));
+        int upperLimit = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(8,12, rawData)));
+        int limitedCreditValue = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(12,16, rawData)));
+        //TODO: Fix this
+        boolean limitedCreditEnabled = true;
+
+        return new ValueFileSettings(fileType, communicationSettings, accessRights, lowerLimit, upperLimit, limitedCreditValue, limitedCreditEnabled);
+    }
+
+
+    /**
+     *  Returns the lower limit of the value
+     * @return Lower limit
+     */
+    public int getLowerLimit() {
+        return lowerLimit;
+    }
+
+
+    /**
+     *  Returns the upper limit of the value
+     * @return Upper limit
+     */
+    public int getUpperLimit() {
+        return upperLimit;
+    }
+
+
+    /**
+     *  Returns the limited credit value
+     * @return Limited credit value
+     */
+    public int getLimitedCreditValue() {
+        return limitedCreditValue;
+    }
+
+
+    /**
+     * Returns if the limited credit feature is enabled on this value file
+     * DO NOT USE AT THE MOMENT!
+     * @return Is limited credit enabled?
+     */
+    public boolean getLimitedCreditEnabled() {
+        Log.e("ValueFileSettings", "Method not implemented, result is not valid");
+        return limitedCreditEnabled;
+    }
+}