|
@@ -1,27 +1,36 @@
|
1
|
1
|
package com.fusi24.entryPermitScanner.ui.setting;
|
2
|
2
|
|
|
3
|
+import android.content.Intent;
|
3
|
4
|
import android.os.Bundle;
|
4
|
5
|
import android.view.MenuItem;
|
5
|
6
|
import android.view.View;
|
6
|
7
|
import android.widget.AdapterView;
|
7
|
8
|
import android.widget.ArrayAdapter;
|
8
|
9
|
import android.widget.TextView;
|
|
10
|
+import android.widget.Toast;
|
9
|
11
|
|
10
|
12
|
import androidx.appcompat.widget.Toolbar;
|
11
|
13
|
|
12
|
14
|
import com.fusi24.entryPermitScanner.R;
|
13
|
15
|
import com.fusi24.entryPermitScanner.base.BaseActivity;
|
|
16
|
+import com.fusi24.entryPermitScanner.data.entity.DataDirectURL;
|
14
|
17
|
import com.fusi24.entryPermitScanner.data.entity.DataSerialPort;
|
15
|
18
|
import com.fusi24.entryPermitScanner.databinding.ActivitySettingBinding;
|
|
19
|
+import com.fusi24.entryPermitScanner.ui.home.HomeActivity;
|
|
20
|
+import com.fusi24.entryPermitScanner.ui.login.LoginActivity;
|
16
|
21
|
|
17
|
22
|
import java.util.ArrayList;
|
18
|
23
|
import java.util.List;
|
19
|
24
|
|
20
|
25
|
public class SettingActivity extends BaseActivity {
|
21
|
26
|
|
|
27
|
+ public static final String IS_FROM_LOGIN = "is_from_login"; // <== To define from Login Page or Home Page
|
22
|
28
|
private DataSerialPort dataSerialPort;
|
|
29
|
+ private DataDirectURL dataDirectURL;
|
23
|
30
|
private List<DataSerialPort> serialPortList;
|
|
31
|
+ private List<DataDirectURL> directURLList;
|
24
|
32
|
private ActivitySettingBinding binding;
|
|
33
|
+ private boolean isFromLogin = false;
|
25
|
34
|
|
26
|
35
|
@Override
|
27
|
36
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -29,6 +38,7 @@ public class SettingActivity extends BaseActivity {
|
29
|
38
|
binding = ActivitySettingBinding.inflate(getLayoutInflater());
|
30
|
39
|
View view = binding.getRoot();
|
31
|
40
|
setContentView(view);
|
|
41
|
+ System.out.println("DEVELOPER Setting onCreate");
|
32
|
42
|
|
33
|
43
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
34
|
44
|
TextView toolbarTitle = findViewById(R.id.toolbar_text);
|
|
@@ -43,10 +53,17 @@ public class SettingActivity extends BaseActivity {
|
43
|
53
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
44
|
54
|
}
|
45
|
55
|
|
|
56
|
+ if (getIntent().getExtras() != null){
|
|
57
|
+ isFromLogin = getIntent().getExtras().getBoolean(IS_FROM_LOGIN);
|
|
58
|
+ }
|
|
59
|
+
|
46
|
60
|
dataSerialPort = new DataSerialPort();
|
|
61
|
+ dataDirectURL = new DataDirectURL();
|
47
|
62
|
serialPortList = new ArrayList<>();
|
|
63
|
+ directURLList = new ArrayList<>();
|
48
|
64
|
|
49
|
65
|
getDataSerialPort();
|
|
66
|
+ getDataDirectURL();
|
50
|
67
|
initEvent();
|
51
|
68
|
}
|
52
|
69
|
|
|
@@ -56,6 +73,12 @@ public class SettingActivity extends BaseActivity {
|
56
|
73
|
setDataSerialPort();
|
57
|
74
|
}
|
58
|
75
|
|
|
76
|
+ private void getDataDirectURL() {
|
|
77
|
+ directURLList.add(new DataDirectURL(1, "Development"));
|
|
78
|
+ directURLList.add(new DataDirectURL(2, "Production"));
|
|
79
|
+ setDataDirectURL();
|
|
80
|
+ }
|
|
81
|
+
|
59
|
82
|
|
60
|
83
|
private void setDataSerialPort(){
|
61
|
84
|
ArrayAdapter<DataSerialPort> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, serialPortList);
|
|
@@ -67,6 +90,16 @@ public class SettingActivity extends BaseActivity {
|
67
|
90
|
}
|
68
|
91
|
}
|
69
|
92
|
|
|
93
|
+ private void setDataDirectURL(){
|
|
94
|
+ ArrayAdapter<DataDirectURL> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, directURLList);
|
|
95
|
+ binding.spinnerDirectUrl.setAdapter(adapter);
|
|
96
|
+ if (getSessionManager().isDevelopment()){
|
|
97
|
+ binding.spinnerDirectUrl.setSelection(0);
|
|
98
|
+ } else {
|
|
99
|
+ binding.spinnerDirectUrl.setSelection(1);
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+
|
70
|
103
|
private void initEvent(){
|
71
|
104
|
|
72
|
105
|
binding.spinnerSerialPort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
@@ -81,12 +114,45 @@ public class SettingActivity extends BaseActivity {
|
81
|
114
|
}
|
82
|
115
|
});
|
83
|
116
|
|
|
117
|
+ binding.spinnerDirectUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
118
|
+ @Override
|
|
119
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
120
|
+ dataDirectURL = (DataDirectURL) parent.getItemAtPosition(position);
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ @Override
|
|
124
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
125
|
+ dataDirectURL = (DataDirectURL) parent.getSelectedItem();
|
|
126
|
+ }
|
|
127
|
+ });
|
|
128
|
+
|
84
|
129
|
binding.btnScan.setOnClickListener(v -> {
|
|
130
|
+
|
|
131
|
+ Toast.makeText(this, dataSerialPort.getName() + " " + dataDirectURL.getName(), Toast.LENGTH_LONG).show();
|
|
132
|
+
|
|
133
|
+ // ID 1 ==> Serial Port 2
|
85
|
134
|
if (dataSerialPort.getId() == 1){
|
86
|
135
|
getSessionManager().setIsSerialport2(true);
|
87
|
136
|
} else {
|
88
|
137
|
getSessionManager().setIsSerialport2(false);
|
89
|
138
|
}
|
|
139
|
+
|
|
140
|
+ // ID 1 ==> Development
|
|
141
|
+ if (dataDirectURL.getId() == 1){
|
|
142
|
+ getSessionManager().setIsDevelopment(true);
|
|
143
|
+ } else {
|
|
144
|
+ getSessionManager().setIsDevelopment(false);
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ Intent intent;
|
|
148
|
+ if (isFromLogin){
|
|
149
|
+ intent = new Intent(this, LoginActivity.class);
|
|
150
|
+ } else {
|
|
151
|
+ intent = new Intent(this, HomeActivity.class);
|
|
152
|
+ }
|
|
153
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
154
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
155
|
+ startActivity(intent);
|
90
|
156
|
finish();
|
91
|
157
|
});
|
92
|
158
|
}
|
|
@@ -108,6 +174,7 @@ public class SettingActivity extends BaseActivity {
|
108
|
174
|
@Override
|
109
|
175
|
protected void onDestroy() {
|
110
|
176
|
super.onDestroy();
|
|
177
|
+ System.out.println("DEVELOPER Setting onDestroy");
|
111
|
178
|
binding = null;
|
112
|
179
|
}
|
113
|
180
|
}
|