Quellcode durchsuchen

-Add config dynamic for serial port

ilhamitubagoes vor 4 Jahren
Ursprung
Commit
9c19dfaa5c

+ 6 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,6 @@
1
+<component name="InspectionProjectProfileManager">
2
+  <profile version="1.0">
3
+    <option name="myName" value="Project Default" />
4
+    <inspection_tool class="UNCHECKED_WARNING" enabled="false" level="WARNING" enabled_by_default="false" />
5
+  </profile>
6
+</component>

+ 5 - 0
app/src/main/AndroidManifest.xml

@@ -34,6 +34,11 @@
34 34
             android:theme="@style/Theme.AppCompat.Light.NoActionBar">
35 35
         </activity>
36 36
         <activity
37
+            android:name=".ui.setting.SettingActivity"
38
+            android:screenOrientation="portrait"
39
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
40
+        </activity>
41
+        <activity
37 42
             android:name=".ui.ScanActivity"
38 43
             android:screenOrientation="portrait"
39 44
             android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

+ 6 - 6
app/src/main/java/com/fusi24/entryPermitScanner/config/Constant.java

@@ -19,13 +19,13 @@ public final class Constant {
19 19
 
20 20
     /*===================================================================================================*/
21 21
 
22
-    // API < 3.0 BUAT TEST DEVICE di FUSI
23
-    /*public final static String PATH = "/dev/ttyS2";
24
-    public final static String PATHNAME = "/proc/gpiocontrol/set_id";*/
22
+    // SERIAL PORT ttyS2 BUAT TEST DEVICE di FUSI
23
+    public final static String PATH_SP2 = "/dev/ttyS2";
24
+    public final static String PATHNAME_SP2 = "/proc/gpiocontrol/set_id";
25 25
 
26
-    // API 3.0 BUAT TEST DEVICE di BERAU COAL
27
-    public final static String PATH = "/dev/ttyS3"; // Untuk versi 3.0
28
-    public final static String PATHNAME = "/proc/gpiocontrol/set_sam"; // untuk versi 3.0
26
+    // SERIAL PORT ttyS3 BUAT TEST DEVICE di BERAU COAL
27
+    public final static String PATH_SP3 = "/dev/ttyS3"; // Untuk versi 3.0
28
+    public final static String PATHNAME_SP3 = "/proc/gpiocontrol/set_sam"; // untuk versi 3.0
29 29
 
30 30
     /*===================================================================================================*/
31 31
 

+ 11 - 0
app/src/main/java/com/fusi24/entryPermitScanner/data/SessionManager.java

@@ -13,6 +13,7 @@ public class SessionManager {
13 13
     private static final String USER_TELEPHONE          = "user_telephone";
14 14
     private static final String USER_RFID_NUMBER        = "user_rfid_number";
15 15
     private static final String GATE                    = "gate";
16
+    private static final String IS_SERIALPORT_2         = "serial_port_2";
16 17
 
17 18
     private final SharedPreferences preferences;
18 19
 
@@ -110,6 +111,16 @@ public class SessionManager {
110 111
         editor.apply();
111 112
     }
112 113
 
114
+    public Boolean isSerialPort2() {
115
+        return preferences.getBoolean(IS_SERIALPORT_2, false);
116
+    }
117
+
118
+    public void setIsSerialport2(Boolean isSerialport2) {
119
+        SharedPreferences.Editor editor = preferences.edit();
120
+        editor.putBoolean(IS_SERIALPORT_2, isSerialport2);
121
+        editor.apply();
122
+    }
123
+
113 124
     public void clearData() {
114 125
         SharedPreferences.Editor editor = preferences.edit();
115 126
         editor.remove(IS_LOGIN);

+ 38 - 0
app/src/main/java/com/fusi24/entryPermitScanner/data/entity/DataSerialPort.java

@@ -0,0 +1,38 @@
1
+package com.fusi24.entryPermitScanner.data.entity;
2
+
3
+import org.jetbrains.annotations.NotNull;
4
+
5
+public class DataSerialPort {
6
+
7
+    private Integer id;
8
+    private String name;
9
+
10
+    public DataSerialPort() {}
11
+
12
+    public DataSerialPort(Integer id, String name) {
13
+        this.id = id;
14
+        this.name = name;
15
+    }
16
+
17
+    public Integer getId() {
18
+        return id;
19
+    }
20
+
21
+    public void setId(Integer id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public String getName() {
26
+        return name;
27
+    }
28
+
29
+    public void setName(String name) {
30
+        this.name = name;
31
+    }
32
+
33
+    @NotNull
34
+    @Override
35
+    public String toString() {
36
+        return name;
37
+    }
38
+}

+ 6 - 0
app/src/main/java/com/fusi24/entryPermitScanner/ui/home/HomeActivity.java

@@ -37,6 +37,7 @@ import com.fusi24.entryPermitScanner.data.entity.DataEntryPermit;
37 37
 import com.fusi24.entryPermitScanner.data.entity.DataSite;
38 38
 import com.fusi24.entryPermitScanner.databinding.ActivityHomeBinding;
39 39
 import com.fusi24.entryPermitScanner.ui.ScanActivity;
40
+import com.fusi24.entryPermitScanner.ui.setting.SettingActivity;
40 41
 
41 42
 import java.util.ArrayList;
42 43
 import java.util.List;
@@ -99,6 +100,11 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
99 100
     @Override
100 101
     public boolean onOptionsItemSelected(@NonNull MenuItem item) {
101 102
 
103
+        if (item.getItemId() == R.id.action_setting) {
104
+            startActivity(new Intent(this, SettingActivity.class));
105
+            return true;
106
+        }
107
+
102 108
         if (item.getItemId() == R.id.action_logout) {
103 109
             getSessionManager().clearData();
104 110
             startActivity(new Intent(this, SplashScreenActivity.class));

+ 20 - 2
app/src/main/java/com/fusi24/entryPermitScanner/ui/login/LoginActivity.java

@@ -3,12 +3,14 @@ package com.fusi24.entryPermitScanner.ui.login;
3 3
 import android.app.Activity;
4 4
 import android.content.Intent;
5 5
 import android.os.Bundle;
6
+import android.view.View;
6 7
 import android.widget.Toast;
7 8
 
8
-import com.fusi24.entryPermitScanner.R;
9 9
 import com.fusi24.entryPermitScanner.data.SessionManager;
10 10
 import com.fusi24.entryPermitScanner.data.entity.DataAuth;
11 11
 import com.fusi24.entryPermitScanner.data.entity.DataUser;
12
+import com.fusi24.entryPermitScanner.databinding.ActivityLoginBinding;
13
+import com.fusi24.entryPermitScanner.ui.setting.SettingActivity;
12 14
 import com.fusi24.entryPermitScanner.util.Helper;
13 15
 import com.fusi24.entryPermitScanner.util.LFScanProcessing;
14 16
 
@@ -18,20 +20,36 @@ public class LoginActivity extends LFScanProcessing implements LoginView {
18 20
 
19 21
     private SessionManager session;
20 22
     private LoginPresenter presenter;
23
+    private ActivityLoginBinding binding;
21 24
 
22 25
     @Override
23 26
     protected void onCreate(Bundle savedInstanceState) {
24 27
         super.onCreate(savedInstanceState);
25
-        setContentView(R.layout.activity_login);
28
+        binding = ActivityLoginBinding.inflate(getLayoutInflater());
29
+        View view = binding.getRoot();
30
+        setContentView(view);
26 31
 
27 32
         presenter = new LoginPresenter(getManager(), getAndroidScheduler(), getProcessScheduler());
28 33
         presenter.attachView(this);
29 34
         session = new SessionManager(Helper.getDefaultPreferences(this));
30 35
 
36
+        initEvent();
31 37
         initSound();
38
+    }
39
+
40
+    @Override
41
+    protected void onResume() {
42
+        super.onResume();
32 43
         onStart();
33 44
     }
34 45
 
46
+    private void initEvent() {
47
+        binding.ivIconScan.setOnClickListener(v -> {
48
+            Intent intent = new Intent(this, SettingActivity.class);
49
+            startActivity(intent);
50
+        });
51
+    }
52
+
35 53
     void startInstance(String numberRfidTemp){
36 54
         DataAuth dataAuth = new DataAuth();
37 55
         dataAuth.setRfidCode(Helper.formatRfidNumber(numberRfidTemp));

+ 113 - 0
app/src/main/java/com/fusi24/entryPermitScanner/ui/setting/SettingActivity.java

@@ -0,0 +1,113 @@
1
+package com.fusi24.entryPermitScanner.ui.setting;
2
+
3
+import android.os.Bundle;
4
+import android.view.MenuItem;
5
+import android.view.View;
6
+import android.widget.AdapterView;
7
+import android.widget.ArrayAdapter;
8
+import android.widget.TextView;
9
+
10
+import androidx.appcompat.widget.Toolbar;
11
+
12
+import com.fusi24.entryPermitScanner.R;
13
+import com.fusi24.entryPermitScanner.base.BaseActivity;
14
+import com.fusi24.entryPermitScanner.data.entity.DataSerialPort;
15
+import com.fusi24.entryPermitScanner.databinding.ActivitySettingBinding;
16
+
17
+import java.util.ArrayList;
18
+import java.util.List;
19
+
20
+public class SettingActivity extends BaseActivity {
21
+
22
+    private DataSerialPort dataSerialPort;
23
+    private List<DataSerialPort> serialPortList;
24
+    private ActivitySettingBinding binding;
25
+
26
+    @Override
27
+    protected void onCreate(Bundle savedInstanceState) {
28
+        super.onCreate(savedInstanceState);
29
+        binding = ActivitySettingBinding.inflate(getLayoutInflater());
30
+        View view = binding.getRoot();
31
+        setContentView(view);
32
+
33
+        Toolbar toolbar = findViewById(R.id.toolbar);
34
+        TextView toolbarTitle = findViewById(R.id.toolbar_text);
35
+
36
+        if (toolbarTitle != null && toolbar != null) {
37
+            toolbarTitle.setText(getString(R.string.label_setting));
38
+            setSupportActionBar(toolbar);
39
+        }
40
+
41
+        if (getSupportActionBar() != null) {
42
+            getSupportActionBar().setDisplayShowTitleEnabled(false);
43
+            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
44
+        }
45
+
46
+        dataSerialPort = new DataSerialPort();
47
+        serialPortList = new ArrayList<>();
48
+
49
+        getDataSerialPort();
50
+        initEvent();
51
+    }
52
+
53
+    private void getDataSerialPort() {
54
+        serialPortList.add(new DataSerialPort(1, "Serial Port 2"));
55
+        serialPortList.add(new DataSerialPort(2, "Serial Port 3"));
56
+        setDataSerialPort();
57
+    }
58
+
59
+
60
+    private void setDataSerialPort(){
61
+        ArrayAdapter<DataSerialPort> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, serialPortList);
62
+        binding.spinnerSerialPort.setAdapter(adapter);
63
+        if (getSessionManager().isSerialPort2()){
64
+            binding.spinnerSerialPort.setSelection(0);
65
+        } else {
66
+            binding.spinnerSerialPort.setSelection(1);
67
+        }
68
+    }
69
+
70
+    private void initEvent(){
71
+
72
+        binding.spinnerSerialPort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
73
+            @Override
74
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
75
+                dataSerialPort = (DataSerialPort) parent.getItemAtPosition(position);
76
+            }
77
+
78
+            @Override
79
+            public void onNothingSelected(AdapterView<?> parent) {
80
+                dataSerialPort = (DataSerialPort) parent.getSelectedItem();
81
+            }
82
+        });
83
+
84
+        binding.btnScan.setOnClickListener(v -> {
85
+            if (dataSerialPort.getId() == 1){
86
+                getSessionManager().setIsSerialport2(true);
87
+            } else {
88
+                getSessionManager().setIsSerialport2(false);
89
+            }
90
+            finish();
91
+        });
92
+    }
93
+
94
+    @Override
95
+    public boolean onOptionsItemSelected(MenuItem item) {
96
+        if (item.getItemId()==android.R.id.home){
97
+            finish();
98
+        }
99
+        return super.onOptionsItemSelected(item);
100
+    }
101
+
102
+    @Override
103
+    public void onBackPressed() {
104
+        super.onBackPressed();
105
+        finish();
106
+    }
107
+
108
+    @Override
109
+    protected void onDestroy() {
110
+        super.onDestroy();
111
+        binding = null;
112
+    }
113
+}

+ 12 - 2
app/src/main/java/com/fusi24/entryPermitScanner/util/LFScanProcessing.java

@@ -38,7 +38,12 @@ public abstract class LFScanProcessing extends LFSerialPortActivity {
38 38
         super.onStart();
39 39
 
40 40
         // Start Reception
41
-        PowerUtil.power("1");
41
+        if (getSessionManager().isSerialPort2()){
42
+            PowerUtil.power("1", true);
43
+        } else {
44
+            // Serial Port 3
45
+            PowerUtil.power("1", false);
46
+        }
42 47
         this.open();
43 48
     }
44 49
 
@@ -48,6 +53,11 @@ public abstract class LFScanProcessing extends LFSerialPortActivity {
48 53
 
49 54
         // Stop Reception
50 55
         this.close();
51
-        PowerUtil.power("0");
56
+        if (getSessionManager().isSerialPort2()){
57
+            PowerUtil.power("0", true);
58
+        } else {
59
+            // Serial Port 3
60
+            PowerUtil.power("0", false);
61
+        }
52 62
     }
53 63
 }

+ 7 - 2
app/src/main/java/com/fusi24/entryPermitScanner/util/LFSerialPortActivity.java

@@ -33,7 +33,8 @@ import android_serialport_api.SerialPortTool;
33 33
 
34 34
 public abstract class LFSerialPortActivity extends BaseActivity {
35 35
 
36
-  public static final String PATH = Constant.PATH;
36
+  public static final String PATH_SP2 = Constant.PATH_SP2;
37
+  public static final String PATH_SP3 = Constant.PATH_SP3;
37 38
   public static final int BAUTRATE = Constant.BAUTRATE;
38 39
 
39 40
   protected SerialPortTool serialPortTool;
@@ -95,7 +96,11 @@ public abstract class LFSerialPortActivity extends BaseActivity {
95 96
 
96 97
     try {
97 98
 
98
-      mSerialPort = serialPortTool.getSerialPort(PATH, BAUTRATE);
99
+      if (getSessionManager().isSerialPort2()){
100
+        mSerialPort = serialPortTool.getSerialPort(PATH_SP2, BAUTRATE);
101
+      } else {
102
+        mSerialPort = serialPortTool.getSerialPort(PATH_SP3, BAUTRATE);
103
+      }
99 104
       mOutputStream = mSerialPort.getOutputStream();
100 105
       mInputStream = mSerialPort.getInputStream();
101 106
 

+ 7 - 2
app/src/main/java/com/fusi24/entryPermitScanner/util/PowerUtil.java

@@ -6,9 +6,14 @@ import java.io.File;
6 6
 import java.io.FileWriter;
7 7
 
8 8
 public class PowerUtil {
9
-  public static void power(String id) {
9
+  public static void power(String id, Boolean isSerialPort2) {
10 10
     try {
11
-      FileWriter localFileWriterOn = new FileWriter(new File(Constant.PATHNAME));
11
+      FileWriter localFileWriterOn;
12
+      if (isSerialPort2){
13
+        localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP2));
14
+      } else {
15
+        localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP3));
16
+      }
12 17
       localFileWriterOn.write(id);
13 18
       localFileWriterOn.close();
14 19
     } catch (Exception e) {

+ 2 - 2
app/src/main/res/drawable/ic_scan_card.xml

@@ -1,6 +1,6 @@
1 1
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
-    android:width="512dp"
3
-    android:height="512dp"
2
+    android:width="200dp"
3
+    android:height="200dp"
4 4
     android:viewportWidth="300"
5 5
     android:viewportHeight="300">
6 6
   <path

+ 1 - 2
app/src/main/res/layout/activity_login.xml

@@ -3,8 +3,7 @@
3 3
     xmlns:tools="http://schemas.android.com/tools"
4 4
     android:layout_width="match_parent"
5 5
     android:layout_height="match_parent"
6
-    tools:context=".ui.ScanActivity"
7
-    tools:viewBindingIgnore="true">
6
+    tools:context=".ui.ScanActivity">
8 7
 
9 8
     <TextView
10 9
         android:id="@+id/tv_login_note"

+ 57 - 0
app/src/main/res/layout/activity_setting.xml

@@ -0,0 +1,57 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout
3
+    xmlns:android="http://schemas.android.com/apk/res/android"
4
+    xmlns:tools="http://schemas.android.com/tools"
5
+    android:layout_width="match_parent"
6
+    android:layout_height="match_parent"
7
+    android:orientation="vertical"
8
+    tools:context=".ui.setting.SettingActivity">
9
+
10
+    <include layout="@layout/default_toolbar" />
11
+
12
+    <RelativeLayout
13
+        android:layout_width="match_parent"
14
+        android:layout_height="match_parent">
15
+
16
+        <TextView
17
+            android:id="@+id/tv_title_label"
18
+            android:layout_width="match_parent"
19
+            android:layout_height="wrap_content"
20
+            android:layout_alignParentStart="true"
21
+            android:layout_alignParentEnd="true"
22
+            android:layout_marginTop="16dp"
23
+            android:layout_marginStart="16dp"
24
+            android:layout_marginEnd="16dp"
25
+            android:gravity="start"
26
+            style="@style/MyTextLabel"
27
+            android:text="@string/label_serial_port"/>
28
+
29
+        <androidx.appcompat.widget.AppCompatSpinner
30
+            android:id="@+id/spinner_serial_port"
31
+            android:layout_width="match_parent"
32
+            android:layout_height="wrap_content"
33
+            android:layout_below="@+id/tv_title_label"
34
+            android:layout_alignParentStart="true"
35
+            android:layout_alignParentEnd="true"
36
+            android:layout_marginStart="16dp"
37
+            android:layout_marginTop="8dp"
38
+            android:layout_marginEnd="16dp"
39
+            android:layout_marginBottom="0dp"
40
+            style="@style/spinner_style" />
41
+
42
+        <Button
43
+            android:id="@+id/btn_scan"
44
+            style="@style/ButtonCommon"
45
+            android:layout_width="match_parent"
46
+            android:layout_height="wrap_content"
47
+            android:layout_below="@+id/spinner_serial_port"
48
+            android:layout_alignParentStart="true"
49
+            android:layout_alignParentEnd="true"
50
+            android:layout_marginStart="16dp"
51
+            android:layout_marginTop="32dp"
52
+            android:layout_marginEnd="16dp"
53
+            android:text="@string/label_save" />
54
+
55
+    </RelativeLayout>
56
+
57
+</LinearLayout>

+ 5 - 0
app/src/main/res/menu/menu_home.xml

@@ -16,6 +16,11 @@
16 16
                 app:showAsAction="withText"/>
17 17
 
18 18
             <item
19
+                android:id="@+id/action_setting"
20
+                android:title="@string/label_setting"
21
+                app:showAsAction="withText"/>
22
+
23
+            <item
19 24
                 android:id="@+id/action_logout"
20 25
                 android:title="@string/label_logout"
21 26
                 app:showAsAction="withText"/>

+ 11 - 8
app/src/main/res/values/strings.xml

@@ -11,11 +11,22 @@
11 11
     <string name="label_more_options">More Options</string>
12 12
     <string name="label_app_version">App version</string>
13 13
     <string name="label_logout">Keluar</string>
14
+    <string name="label_setting">Pengaturan Device</string>
15
+    <string name="label_serial_port">Serial Port</string>
16
+    <string name="label_save">Simpan</string>
14 17
     <string name="label_home">Home</string>
15 18
     <string name="label_scan_other">Scan Other</string>
16 19
     <string name="label_status_passed">PASSED</string>
17 20
     <string name="label_status_not_passed">NOT PASSED</string>
18 21
     <string name="label_status_not_valid">NOT VALID</string>
22
+    <string name="label_number_rfid">Nomor RFID Gun</string>
23
+    <string name="label_number_rfid_card">Nomor RFID Card</string>
24
+    <string name="label_employee_name">Nama Karyawan</string>
25
+    <string name="label_gate">Gate</string>
26
+    <string name="label_site">Site</string>
27
+    <string name="label_entry_ermit">Izin Masuk</string>
28
+    <string name="label_scan_status">Status Scan</string>
29
+    <string name="label_strip">-</string>
19 30
 
20 31
     //Content Description
21 32
     <string name="cd_image">IMAGE</string>
@@ -26,13 +37,5 @@
26 37
     <string name="error_unknown">The serial port can not be opened for an unknown reason.</string>
27 38
     <string name="error_scan_id">Mohon maaf sistem sedang sibuk</string>
28 39
     <string name="error_only_security">Oops……… \n anda gagal login</string>
29
-    <string name="label_number_rfid">Nomor RFID Gun</string>
30
-    <string name="label_number_rfid_card">Nomor RFID Card</string>
31
-    <string name="label_employee_name">Nama Karyawan</string>
32
-    <string name="label_gate">Gate</string>
33
-    <string name="label_site">Site</string>
34
-    <string name="label_entry_ermit">Izin Masuk</string>
35
-    <string name="label_scan_status">Status Scan</string>
36
-    <string name="label_strip">-</string>
37 40
 
38 41
 </resources>