读取app 准备

master
wangh 6 months ago
parent 0f83bf9a17
commit 38edb74d4c

@ -30,11 +30,10 @@
<activity <activity
android:name=".AppLoginActivity" android:name=".AppLoginActivity"
android:exported="true"> android:exported="true">
<intent-filter>
<!-- <intent-filter> --> <action android:name="android.intent.action.MAIN" />
<!-- <action android:name="android.intent.action.MAIN" /> --> <category android:name="android.intent.category.LAUNCHER" />
<!-- <category android:name="android.intent.category.LAUNCHER" /> --> </intent-filter>
<!-- </intent-filter> -->
</activity> </activity>
<activity <activity
android:name=".ReadActivity" android:name=".ReadActivity"
@ -43,10 +42,10 @@
android:name=".WriteUserActivity" android:name=".WriteUserActivity"
android:exported="true"> android:exported="true">
<!-- <intent-filter> --> <!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" /> --> <!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" /> --> <!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter> --> <!-- </intent-filter>-->
</activity> </activity>
<activity <activity
android:name=".ConfigurationTableActivity" android:name=".ConfigurationTableActivity"
@ -54,11 +53,11 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true">
<intent-filter> <!-- <intent-filter>-->
<action android:name="android.intent.action.MAIN" /> <!-- <action android:name="android.intent.action.MAIN" />-->
<category android:name="android.intent.category.LAUNCHER" /> <!-- <category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter> <!-- </intent-filter>-->
</activity> </activity>
</application> </application>

@ -50,10 +50,11 @@ public class AppLoginActivity extends AppCompatActivity {
SharedPreferencesUtils.putstring("language", s); SharedPreferencesUtils.putstring("language", s);
getLocaleStringXML(s); getLocaleStringXML(s);
resources.updateConfiguration(config, resources.getDisplayMetrics()); resources.updateConfiguration(config, resources.getDisplayMetrics());
//
var intent = new Intent(this, ReadActivity.class); var intent = new Intent(this, ReadActivity.class);
Log.e("TAG", "appLoginClick:" + value); Log.e("TAG", "appLoginClick:" + value);
intent.putExtra("work",value); intent.putExtra("work",value);
SharedPreferencesUtils.putstring("languageIndex", index + "");
intent.putExtra("appType",true);
startActivity(intent); startActivity(intent);
finish(); finish();
} }

@ -39,6 +39,7 @@ public class MainActivity extends BaseActivity {
private Resources resources; private Resources resources;
private Configuration config; private Configuration config;
private int index; private int index;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -62,17 +63,16 @@ public class MainActivity extends BaseActivity {
} }
private void getLocaleStringXML(String languageString) {
private void getLocaleStringXML(String languageString){ if (languageString.equals("中文")) {
if (languageString.equals("中文")){
config.locale = Locale.CHINA; config.locale = Locale.CHINA;
index=0; index = 0;
}else if (languageString.equals("English")){ } else if (languageString.equals("English")) {
config.locale = Locale.ENGLISH; config.locale = Locale.ENGLISH;
index=1; index = 1;
}else { } else {
config.locale =new Locale("vi","VN"); config.locale = new Locale("vi", "VN");
index=2; index = 2;
} }
} }
@ -90,7 +90,7 @@ public class MainActivity extends BaseActivity {
map.put("UserID", name); map.put("UserID", name);
map.put("UserPass", pass); map.put("UserPass", pass);
map.put("token", "123456"); map.put("token", "123456");
map.put("Language", index+""); map.put("Language", index + "");
if (pass == null || name == null || pass.isEmpty() || name.isEmpty()) return; if (pass == null || name == null || pass.isEmpty() || name.isEmpty()) return;
OkGo.<MyResult>post(url + "/login") OkGo.<MyResult>post(url + "/login")
.upRequestBody(RequestBody.create(JSON, gson.toJson(map))) .upRequestBody(RequestBody.create(JSON, gson.toJson(map)))
@ -109,13 +109,13 @@ public class MainActivity extends BaseActivity {
SharedPreferencesUtils.putstring("pass", pass); SharedPreferencesUtils.putstring("pass", pass);
} }
SharedPreferencesUtils.putstring("language", selectLanguage); SharedPreferencesUtils.putstring("language", selectLanguage);
SharedPreferencesUtils.putstring("languageIndex", index+""); SharedPreferencesUtils.putstring("languageIndex", index + "");
resources.updateConfiguration(config, resources.getDisplayMetrics()); resources.updateConfiguration(config, resources.getDisplayMetrics());
List<ConfigurationTable> list = LitePal.findAll(ConfigurationTable.class); List<ConfigurationTable> list = LitePal.findAll(ConfigurationTable.class);
Intent intent; Intent intent;
if (list==null||list.isEmpty()){ if (list == null || list.isEmpty()) {
intent = new Intent(MainActivity.this, ConfigurationTableActivity.class); intent = new Intent(MainActivity.this, ConfigurationTableActivity.class);
}else { } else {
intent = new Intent(MainActivity.this, WriteUserActivity.class); intent = new Intent(MainActivity.this, WriteUserActivity.class);
} }
startActivity(intent); startActivity(intent);

@ -50,7 +50,14 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
binding.setType(workmode == 1); binding.setType(workmode == 1);
// 名称 // 名称
stringArray = getResources().getStringArray(R.array.project_list); stringArray = getResources().getStringArray(R.array.project_list);
var appType = getIntent().getBooleanExtra("appType", false);
if (appType) {
// tl-gx4
} else {
rfidModel = new C5106Device(this); rfidModel = new C5106Device(this);
}
} }
@ -61,6 +68,7 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
public void readEPCInfo(View view) { public void readEPCInfo(View view) {
rfidModel.sanEpc(6); rfidModel.sanEpc(6);
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@Override @Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) { public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
@ -71,7 +79,7 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("EpcCode", info); map.put("EpcCode", info);
map.put("token", "123456"); map.put("token", "123456");
map.put("Language", SharedPreferencesUtils.getstring("languageIndex","0")); map.put("Language", SharedPreferencesUtils.getstring("languageIndex", "0"));
OkGo.<MyResult>post(url + "/readEPCCode") OkGo.<MyResult>post(url + "/readEPCCode")
.upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) { .upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@Override @Override
@ -79,7 +87,8 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
super.onSuccess(response); super.onSuccess(response);
var body = response.body(); var body = response.body();
if (body.getResultFlag().equals("1")) { if (body.getResultFlag().equals("1")) {
list.addAll(gson.fromJson(body.getJson(),new TypeToken<List<ReadTyreNoResult>>(){}.getType())); list.addAll(gson.fromJson(body.getJson(), new TypeToken<List<ReadTyreNoResult>>() {
}.getType()));
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} else { } else {
Toast.makeText(ReadActivity.this, body.getJson(), Toast.LENGTH_SHORT).show(); Toast.makeText(ReadActivity.this, body.getJson(), Toast.LENGTH_SHORT).show();
@ -89,7 +98,7 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
} }
}); });
}else { } else {
binding.readText.setText(null); binding.readText.setText(null);
} }
} }
@ -107,10 +116,12 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
list.add(new ReadTyreNoResult(i, stringArray[i], infos[i])); list.add(new ReadTyreNoResult(i, stringArray[i], infos[i]));
} }
}else { } else {
binding.readText.setText(null); binding.readText.setText(null);
} }
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
//
} }

@ -125,7 +125,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
writeUserState = true; writeUserState = true;
return; return;
} }
Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show(); tipDialog.shouDialog(false, body.getSaveMessage());
} }
}); });
@ -133,7 +133,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
if (writeUserState){ if (writeUserState){
Log.e("TAG", "写入"); Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr); var writeState = rfidModel.writeUser(validateDataLength(user), epcStr);
Toast.makeText(context, getString(writeState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show(); tipDialog.shouDialog(writeState,getString(writeState ? R.string.write_success : R.string.write_failed));
if (writeState) { if (writeState) {
list.clear(); list.clear();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();

@ -25,6 +25,7 @@ import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import com.example.jinyu_rfid.R; import com.example.jinyu_rfid.R;
import com.example.jinyu_rfid.dialog.TipDialog;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -48,6 +49,7 @@ public class BaseActivity extends AppCompatActivity {
private MyReceiver myReceiver; private MyReceiver myReceiver;
public MediaPlayer music; public MediaPlayer music;
public Context context; public Context context;
public TipDialog tipDialog;
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
public SimpleDateFormat format= new SimpleDateFormat( "yyyyMMdd_HHmmss"); public SimpleDateFormat format= new SimpleDateFormat( "yyyyMMdd_HHmmss");
@Override @Override
@ -57,10 +59,8 @@ public class BaseActivity extends AppCompatActivity {
gson = new Gson(); gson = new Gson();
this.context=this; this.context=this;
initDialog(); initDialog();
music = MediaPlayer.create(this, R.raw.msg); music = MediaPlayer.create(this, R.raw.msg);
} }
public class MyReceiver extends BroadcastReceiver { public class MyReceiver extends BroadcastReceiver {
@ -78,6 +78,7 @@ public class BaseActivity extends AppCompatActivity {
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("loading..."); dialog.setMessage("loading...");
tipDialog=new TipDialog(this);
} }
private void initSan() { private void initSan() {

@ -0,0 +1,35 @@
package com.example.jinyu_rfid.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import com.example.jinyu_rfid.R;
import com.example.jinyu_rfid.databinding.DialogLayoutBinding;
/**
* @author wanghao
* @date 2024/6/3 9:17
*/
public class TipDialog extends Dialog {
private DialogLayoutBinding binding;
public TipDialog(@NonNull Context context) {
super(context, R.style.dialog);
binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_layout, null, false);
setContentView(binding.getRoot());
binding.dialogButton.setOnClickListener(v -> dismiss());
}
public void shouDialog(boolean state,String text){
binding.setState(state);
binding.setTipText(text);
show();
}
}

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners android:radius="10dp"/>
<stroke android:color="#e1e1e1" android:width="1dp"/>
</shape>

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="state"
type="Boolean" />
<variable
name="tipText"
type="String" />
<import type="android.view.View"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:visibility="@{state?View.VISIBLE:View.GONE}"
android:src="@mipmap/icon_true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:visibility="@{state?View.GONE:View.VISIBLE}"
android:src="@mipmap/icon_false" />
<TextView
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="66dp"
android:text="@{tipText}" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1" />
<TextView
android:id="@+id/dialog_button"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="55dp"
android:text="@string/dialog_button_text"
android:textStyle="bold" />
</LinearLayout>
</layout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -34,4 +34,5 @@
<string name="net_model">network mode</string> <string name="net_model">network mode</string>
<string name="standalone_mode">"standalone mode "</string> <string name="standalone_mode">"standalone mode "</string>
<string name="scanning_area">scanning area</string> <string name="scanning_area">scanning area</string>
<string name="dialog_button_text">I see</string>
</resources> </resources>

@ -35,4 +35,5 @@
<string name="net_model">Chế độ mạng</string> <string name="net_model">Chế độ mạng</string>
<string name="standalone_mode">Chế độ đơn</string> <string name="standalone_mode">Chế độ đơn</string>
<string name="scanning_area">Khu vực quét</string> <string name="scanning_area">Khu vực quét</string>
<string name="dialog_button_text">Tôi biết rồi</string>
</resources> </resources>

@ -33,5 +33,6 @@
<string name="work_model_select">工作模式</string> <string name="work_model_select">工作模式</string>
<string name="net_model">网络模式</string> <string name="net_model">网络模式</string>
<string name="standalone_mode">单机模式</string> <string name="standalone_mode">单机模式</string>
<string name="scanning_area">扫描区域</string>> <string name="scanning_area">扫描区域</string>
<string name="dialog_button_text">我知道了</string>>
</resources> </resources>

@ -16,4 +16,18 @@
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
<item name="android:textSize">17sp</item> <item name="android:textSize">17sp</item>
</style> </style>
<style name="dialog">
<!--背景颜色及和透明程度-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--是否去除标题 -->
<item name="android:windowNoTitle">true</item>
<!--是否去除边框-->
<item name="android:windowFrame">@null</item>
<!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item>
<!--是否模糊-->
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowMinWidthMinor">95%</item><!--宽度铺满全屏-->
</style>
</resources> </resources>
Loading…
Cancel
Save