Browse Source

-Add alert type in model
-Add dynamic text when status not passed
-Fixing variable name
-Add plugin git version from ajoberstar for easy tag git
-Update soundpool and audio attributes for >= LOLLIPOP

ilhamitubagoes 4 years ago
parent
commit
c4a72ea96b

+ 4 - 2
app/build.gradle

@@ -1,5 +1,7 @@
1
 apply plugin: 'com.android.application'
1
 apply plugin: 'com.android.application'
2
 
2
 
3
+apply from: '../config/git-version.gradle'
4
+
3
 android {
5
 android {
4
     compileSdkVersion 29
6
     compileSdkVersion 29
5
     buildToolsVersion "29.0.2"
7
     buildToolsVersion "29.0.2"
@@ -7,8 +9,8 @@ android {
7
         applicationId "com.fusi24.rfid"
9
         applicationId "com.fusi24.rfid"
8
         minSdkVersion 21
10
         minSdkVersion 21
9
         targetSdkVersion 29
11
         targetSdkVersion 29
10
-        versionCode 1
11
-        versionName "1.0"
12
+        versionCode gitVersionCode
13
+        versionName gitVersionName
12
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13
     }
15
     }
14
     buildTypes {
16
     buildTypes {

+ 11 - 0
app/src/main/java/com/fusi24/rfid/MainActivity.java

@@ -140,6 +140,17 @@ public class MainActivity extends BaseActivity {
140
         });
140
         });
141
 
141
 
142
         btnScan.setOnClickListener(v -> {
142
         btnScan.setOnClickListener(v -> {
143
+
144
+            if (spinnerSite.getSelectedItem() == null){
145
+                Toast.makeText(this, "Data Site Belum Terpilih", Toast.LENGTH_SHORT).show();
146
+                return;
147
+            }
148
+
149
+            if (spinnerPermit.getSelectedItem() == null){
150
+                Toast.makeText(this, "Data Permit Belum Terpilih", Toast.LENGTH_SHORT).show();
151
+                return;
152
+            }
153
+
143
             Intent intent = new Intent(this, ScanActivity.class);
154
             Intent intent = new Intent(this, ScanActivity.class);
144
             intent.putExtra(ScanActivity.ID_SITE, String.valueOf(dataSite.getId()));
155
             intent.putExtra(ScanActivity.ID_SITE, String.valueOf(dataSite.getId()));
145
             intent.putExtra(ScanActivity.ID_PERMIT, String.valueOf(dataEntryPermit.getId()));
156
             intent.putExtra(ScanActivity.ID_PERMIT, String.valueOf(dataEntryPermit.getId()));

+ 9 - 0
app/src/main/java/com/fusi24/rfid/data/entity/DataResultRfid.java

@@ -6,6 +6,7 @@ public class DataResultRfid {
6
 
6
 
7
     private DataEmployee employee;
7
     private DataEmployee employee;
8
     private Boolean passed;
8
     private Boolean passed;
9
+    private String alertType;
9
     private String message;
10
     private String message;
10
     private List<DataProblems> problems;
11
     private List<DataProblems> problems;
11
 
12
 
@@ -25,6 +26,14 @@ public class DataResultRfid {
25
         this.passed = passed;
26
         this.passed = passed;
26
     }
27
     }
27
 
28
 
29
+    public String getAlertType() {
30
+        return alertType;
31
+    }
32
+
33
+    public void setAlertType(String alertType) {
34
+        this.alertType = alertType;
35
+    }
36
+
28
     public String getMessage() {
37
     public String getMessage() {
29
         return message;
38
         return message;
30
     }
39
     }

+ 7 - 8
app/src/main/java/com/fusi24/rfid/ui/ScanActivity.java

@@ -48,18 +48,18 @@ public class ScanActivity extends LFScanProcessing {
48
             onStop();
48
             onStop();
49
     }
49
     }
50
 
50
 
51
-    void startInstance(String reception){
51
+    void startInstance(String rfidCardNumber){
52
         Intent intent = new Intent(this, ScanResultActivity.class);
52
         Intent intent = new Intent(this, ScanResultActivity.class);
53
         intent.putExtra(ScanResultActivity.ID_SITE, idSite);
53
         intent.putExtra(ScanResultActivity.ID_SITE, idSite);
54
         intent.putExtra(ScanResultActivity.ID_PERMIT, idPermit);
54
         intent.putExtra(ScanResultActivity.ID_PERMIT, idPermit);
55
-        intent.putExtra(ScanResultActivity.RFID_CARD_NUMBER, reception);
55
+        intent.putExtra(ScanResultActivity.RFID_CARD_NUMBER, rfidCardNumber);
56
         startActivityForResult(intent, 1);
56
         startActivityForResult(intent, 1);
57
     }
57
     }
58
 
58
 
59
     @Override
59
     @Override
60
     protected void onDataReceived(byte[] buffer, int size) {
60
     protected void onDataReceived(byte[] buffer, int size) {
61
         runOnUiThread(() -> {
61
         runOnUiThread(() -> {
62
-            if (stringReception != null) {
62
+            if (rfidCardNumber != null) {
63
                 if (size > 0) {
63
                 if (size > 0) {
64
                     if (size >= 5) {
64
                     if (size >= 5) {
65
                         byte[] tempBuf = new byte[size - 4];
65
                         byte[] tempBuf = new byte[size - 4];
@@ -67,14 +67,13 @@ public class ScanActivity extends LFScanProcessing {
67
                         String temStr = new String(tempBuf);
67
                         String temStr = new String(tempBuf);
68
                         int temInt = Integer.parseInt(temStr, 16);
68
                         int temInt = Integer.parseInt(temStr, 16);
69
                         soundpool.play(soundid, 1, 1, 0, 0, 1);
69
                         soundpool.play(soundid, 1, 1, 0, 0, 1);
70
-                        stringReception = Integer.toString(temInt);
70
+                        rfidCardNumber = Integer.toString(temInt);
71
 
71
 
72
-                        //Toast.makeText(ScanHomepage.this, "Hasil dari RFID LF: " + stringReception, Toast.LENGTH_LONG).show();
73
-                        Timber.i("Hasil dari RFID LF: %s", stringReception);
74
-                        startInstance(stringReception);
72
+                        Timber.i("Hasil dari RFID LF: %s", rfidCardNumber);
73
+                        startInstance(rfidCardNumber);
75
                     } else {
74
                     } else {
76
                         // receipt data 4 digit to start
75
                         // receipt data 4 digit to start
77
-                        stringReception = new String(buffer, 0, size);
76
+                        rfidCardNumber = new String(buffer, 0, size);
78
                     }
77
                     }
79
                 }
78
                 }
80
             }
79
             }

+ 9 - 2
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultActivity.java

@@ -140,8 +140,15 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
140
             tvProfileStatus.setText(R.string.label_status_passed);
140
             tvProfileStatus.setText(R.string.label_status_passed);
141
             llProfileStatus.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
141
             llProfileStatus.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
142
         } else {
142
         } else {
143
-            tvProfileStatus.setText(R.string.label_status_not_passed);
144
-            llProfileStatus.setBackgroundColor(getResources().getColor(R.color.colorRedDark));
143
+            if (dataResultRfid.getAlertType().equalsIgnoreCase("ERROR")){
144
+                tvProfileStatus.setText(R.string.label_status_not_passed);
145
+                llProfileStatus.setBackgroundColor(getResources().getColor(R.color.colorRedDark));
146
+            }
147
+
148
+            if (dataResultRfid.getAlertType().equalsIgnoreCase("WARNING")){
149
+                tvProfileStatus.setText(R.string.label_status_not_valid);
150
+                llProfileStatus.setBackgroundColor(getResources().getColor(R.color.colorRedDark));
151
+            }
145
         }
152
         }
146
 
153
 
147
         problemsList = dataResultRfid.getProblems();
154
         problemsList = dataResultRfid.getProblems();

+ 19 - 2
app/src/main/java/com/fusi24/rfid/util/LFScanProcessing.java

@@ -1,7 +1,9 @@
1
 package com.fusi24.rfid.util;
1
 package com.fusi24.rfid.util;
2
 
2
 
3
+import android.media.AudioAttributes;
3
 import android.media.AudioManager;
4
 import android.media.AudioManager;
4
 import android.media.SoundPool;
5
 import android.media.SoundPool;
6
+import android.os.Build;
5
 
7
 
6
 import com.fusi24.rfid.R;
8
 import com.fusi24.rfid.R;
7
 
9
 
@@ -9,11 +11,26 @@ public abstract class LFScanProcessing extends LFSerialPortActivity {
9
 
11
 
10
     protected int soundid;
12
     protected int soundid;
11
     protected SoundPool soundpool = null;
13
     protected SoundPool soundpool = null;
14
+    protected AudioAttributes attributes = null;
12
 
15
 
13
-    public String stringReception = "";
16
+    public String rfidCardNumber = "";
14
 
17
 
15
     protected void initSound(){
18
     protected void initSound(){
16
-        soundpool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 100);
19
+
20
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
21
+            attributes = new AudioAttributes.Builder()
22
+                    .setAllowedCapturePolicy(AudioAttributes.ALLOW_CAPTURE_BY_NONE)
23
+                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
24
+                    .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
25
+                    .build();
26
+
27
+            soundpool = new SoundPool.Builder()
28
+                    .setMaxStreams(1)
29
+                    .setAudioAttributes(attributes)
30
+                    .build();
31
+        } else {
32
+            soundpool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 100);
33
+        }
17
         soundid = soundpool.load(this, R.raw.rfid_beep, 1);
34
         soundid = soundpool.load(this, R.raw.rfid_beep, 1);
18
     }
35
     }
19
 
36
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -16,5 +16,6 @@
16
     <string name="label_scan_other">Scan Other</string>
16
     <string name="label_scan_other">Scan Other</string>
17
     <string name="label_status_passed">PASSED</string>
17
     <string name="label_status_passed">PASSED</string>
18
     <string name="label_status_not_passed">NOT PASSED</string>
18
     <string name="label_status_not_passed">NOT PASSED</string>
19
+    <string name="label_status_not_valid">NOT VALID</string>
19
 
20
 
20
 </resources>
21
 </resources>

+ 7 - 2
build.gradle

@@ -7,7 +7,7 @@ buildscript {
7
         
7
         
8
     }
8
     }
9
     dependencies {
9
     dependencies {
10
-        classpath 'com.android.tools.build:gradle:3.5.2'
10
+        classpath 'com.android.tools.build:gradle:3.5.3'
11
         
11
         
12
         // NOTE: Do not place your application dependencies here; they belong
12
         // NOTE: Do not place your application dependencies here; they belong
13
         // in the individual module build.gradle files
13
         // in the individual module build.gradle files
@@ -18,7 +18,12 @@ allprojects {
18
     repositories {
18
     repositories {
19
         google()
19
         google()
20
         jcenter()
20
         jcenter()
21
-        
21
+        maven {
22
+            url 'https://maven.google.com/'
23
+        }
24
+        maven {
25
+            url 'https://jitpack.io'
26
+        }
22
     }
27
     }
23
 }
28
 }
24
 
29
 

+ 15 - 0
config/git-version.gradle

@@ -0,0 +1,15 @@
1
+buildscript {
2
+    repositories {
3
+        jcenter()
4
+    }
5
+    dependencies {
6
+        classpath 'org.ajoberstar:grgit:1.5.0'
7
+    }
8
+}
9
+
10
+ext {
11
+    git = org.ajoberstar.grgit.Grgit.open(currentDir: projectDir)
12
+    gitVersionName = git.describe()
13
+    gitVersionCode = git.tag.list().size() + 1
14
+    gitVersionCodeTime = git.head().time
15
+}