第一次提交

This commit is contained in:
jjLv 2025-07-25 16:57:58 +08:00
parent 61b1c94af1
commit 367e1923cf
4 changed files with 915 additions and 0 deletions

View File

@ -0,0 +1,113 @@
/*
* Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.bonus.canteen.activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import com.bonus.canteen.core.BaseActivity;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;
import org.easydarwin.easypusher.R;
import org.easydarwin.easypusher.databinding.ActivityHomePageBinding;
public class HomeActivity extends BaseActivity<ActivityHomePageBinding> {
private static final String PAGE_TYPE = "pageType";
private MaterialDialog dialog;
@Override
protected ActivityHomePageBinding viewBindingInflate(LayoutInflater inflater) {
return ActivityHomePageBinding.inflate(inflater);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreen();
initView();
}
private void setFullScreen() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
}
private void initView(){
binding.openEnterLinear.setOnClickListener(view -> {
showTipDialog("正在进入入库页面,请稍候...");
new Handler().postDelayed(()->{
Intent intent = new Intent(HomeActivity.this, MainActivity.class);
intent.putExtra(PAGE_TYPE, "enter");
startActivity(intent);
finish();
closeDialog();
},300);
});
binding.openOutLinear.setOnClickListener(view ->{
showTipDialog("正在进入出库页面,请稍候...");
new Handler().postDelayed(()->{
Intent intent = new Intent(HomeActivity.this, MainActivity.class);
intent.putExtra(PAGE_TYPE, "out");
startActivity(intent);
finish();
closeDialog();
},300);
});
binding.openSelectLinear.setOnClickListener(view -> {
showTipDialog("正在进入查询页面,请稍候...");
new Handler().postDelayed(()->{
Intent intent = new Intent(HomeActivity.this, MainActivity.class);
intent.putExtra(PAGE_TYPE, "select");
startActivity(intent);
finish();
closeDialog();
},300);
});
}
private void closeDialog() {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
dialog = null;
}
}
/**
* 带圆形Loading的Dialog
*/
public void showTipDialog(String text) {
dialog = new MaterialDialog.Builder(this)
.iconRes(R.drawable.icon_tip)
.limitIconToDefaultSize()
.title("提示")
.content(text)
.progress(true, 0)
.progressIndeterminateStyle(false)
.cancelable(false)
.show();
}
@Override
protected void onDestroy() {
super.onDestroy();
closeDialog();
}
}

View File

@ -0,0 +1,365 @@
package com.bonus.canteen.activity;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.bonus.canteen.constants.AppConstants;
import com.bonus.canteen.core.BaseActivity;
import com.bonus.canteen.db.AppDatabase;
import com.bonus.canteen.db.entity.base.DeviceInfo;
import com.bonus.canteen.db.entity.base.LoginInfo;
import com.bonus.canteen.db.entity.base.ParamSettingInfo;
import com.bonus.canteen.utils.AppUtil;
import com.bonus.canteen.utils.OkHttpService;
import com.bonus.canteen.utils.SM4EncryptUtils;
import com.bonus.canteen.utils.StringHelper;
import com.bonus.canteen.utils.ThreadPoolManager;
import com.bonus.canteen.utils.UrlConfig;
import com.bonus.canteen.utils.WorkConfig;
import com.xuexiang.xui.XUI;
import com.xuexiang.xui.utils.XToastUtils;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;
import org.easydarwin.easypusher.R;
import org.easydarwin.easypusher.databinding.ActivityLoginBinding;
import java.util.ArrayList;
import java.util.List;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
public class LoginActivity extends BaseActivity<ActivityLoginBinding> {
private static final String TAG = "LoginActivity";
public final OkHttpService service = new OkHttpService();
private Boolean isChecked = false;
private MaterialDialog dialog;
private static final String NO_LOGIN_ROLE = "当前账号无登录权限,请联系管理员";
@Override
protected ActivityLoginBinding viewBindingInflate(LayoutInflater inflater) {
return ActivityLoginBinding.inflate(inflater);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
XUI.initTheme(this);
super.onCreate(savedInstanceState);
setupImmersiveMode();
initView();
}
private void setupImmersiveMode() {
View decorView = getWindow().getDecorView();
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
decorView.setSystemUiVisibility(flags);
}
public void initView() {
initListener();
}
public void initListener() {
findViewById(R.id.btn_login).setOnClickListener(v -> {
String userName = binding.etUsername.getText().toString();
String password = binding.etPassword.getText().toString();
boolean tf = checkParameters(userName, password);
if (!tf) {
return;
}
login(userName, password);
});
binding.tvForgetPassword.setOnClickListener(view -> XToastUtils.warning("请在后台管理端重置密码!"));
// 查看密码
binding.checkPassword.setOnClickListener(view -> {
if (isChecked) {
isChecked = false;
binding.checkPassword.setImageResource(R.drawable.ic_eye_close);
binding.etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
isChecked = true;
binding.checkPassword.setImageResource(R.drawable.ic_eye_open);
binding.etPassword.setInputType(InputType.TYPE_CLASS_TEXT);
}
});
}
private void login(String userName, String password) {
showTipDialog("正在登录,请稍候...");
ThreadPoolManager.getExecutor().execute(() -> {
try {
String url = WorkConfig.getPrefixesUrl() + UrlConfig.LOGIN_URL;
org.json.JSONObject json = new org.json.JSONObject();
json.put("username", SM4EncryptUtils.sm4Encrypt(userName));
json.put("password", SM4EncryptUtils.sm4Encrypt(password));
json.put("verificationCode", "");
json.put("code", "");
json.put("phoneUuid", "");
json.put("uuid", "");
json.put("loginType", "KITCHEN_PHONE_PASSWORD");
String jsonString = json.toString();
Log.i("getPersonMessage jsonString", jsonString);
// 定义 JSON MediaType
MediaType mediaType = MediaType.parse(AppConstants.MEDIA_TYPE);
// 创建 RequestBody
RequestBody body = RequestBody.create(mediaType, jsonString);
String result = service.httpLoginPost(url, body, this);
Log.e(TAG, "登录结果: " + result);
if (result != null && !result.isEmpty()) {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getIntValue("code") == 500) {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
runOnUiThread(() -> XToastUtils.error(jsonObject.getString("msg")));
return;
}
runOnUiThread(() -> XToastUtils.success("登录成功"));
String data = jsonObject.getString("data");
JSONObject dataJson = JSONObject.parseObject(data);
if (judgeIsExistRole(dataJson)) return;
AppDatabase.getDatabase(this).loginInfoDao().deleteAll();
LoginInfo loginInfo = new LoginInfo();
loginInfo.setUserName(dataJson.getString("staffName"));
loginInfo.setUserPwd(password);
loginInfo.setUserId(dataJson.getString("staffId")); // 假设用户ID为1实际应用中应从服务器获取
loginInfo.setPhone(dataJson.getString("mobile")); // 假设手机号为1234567890实际应用中应从服务器获取
loginInfo.setToken(dataJson.getString("access_token")); // 假设令牌为sample_token实际应用中应从服务器获取
AppDatabase.getDatabase(this).loginInfoDao().insert(loginInfo);
List<String> res = new ArrayList<>();
initParameterInfo(res);
initDeviceInfo(res);
Log.e(TAG, "初始化结果: " + res);
if (res.size() != 2) {
runOnUiThread(() -> {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
XToastUtils.error("初始化失败,请联系管理员");
});
} else {
runOnUiThread(() -> {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
XToastUtils.error("数据初始化成功");
});
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
finish();
}
} else {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
runOnUiThread(() -> XToastUtils.error("登录失败,请检查用户名和密码"));
}
} catch (Exception e) {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
Log.e("LoginActivity", "Login error: ", e);
runOnUiThread(() -> XToastUtils.error("登录失败,请检查网络连接或服务器状态"));
}
});
}
private boolean judgeIsExistRole(JSONObject jsonObject) {
if (!jsonObject.containsKey("deviceTypes")) {
runOnUiThread(() -> {
dialog.dismiss();
dialog = null;
XToastUtils.error(NO_LOGIN_ROLE);
});
return true;
}
List<String> deviceTypeList = jsonObject.getList("deviceTypes", String.class);
// 处理设备类型
if (deviceTypeList == null || deviceTypeList.isEmpty()) {
runOnUiThread(() -> {
dialog.dismiss();
dialog = null;
XToastUtils.error(NO_LOGIN_ROLE);
});
return true;
} else {
//判断deviceTypeArray是否包含21
boolean hasKitchenPhone = false;
for (String deviceType : deviceTypeList) {
if ("51".equals(deviceType.trim())) {
hasKitchenPhone = true;
break;
}
}
if (!hasKitchenPhone) {
runOnUiThread(() -> {
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
XToastUtils.error(NO_LOGIN_ROLE);
});
return true;
}
}
return false;
}
private void initDeviceInfo(List<String> list) {
@SuppressLint("DefaultLocale") String url = String.format("%s/kitchen_device_info/list?deviceType=%s&pageNum=%d&pageSize=%d&keyWord=%s",
WorkConfig.getBaseUrl(), "51", 1, 10, AppUtil.getSn(this));
String result = service.httpGet(url, this);
if (StringHelper.isEmptyAndNull(result)) {
runOnUiThread(() -> XToastUtils.error("设备信息初始化失败,请检查网络连接或服务器状态"));
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getIntValue("code") == 200) {
String data = jsonObject.getString("rows");
Log.e(TAG, "设备信息: " + data);
if (data != null && !data.isEmpty() && !data.equals("[]")) {
data = data.substring(1, data.length() - 1); // 去掉首尾的中括号
DeviceInfo deviceInfo = JSONObject.parseObject(data, DeviceInfo.class);
if (deviceInfo != null) {
Log.e("LoginActivity", "设备信息: " + deviceInfo.toString());
AppDatabase.getDatabase(this).deviceInfoDao().deleteAll();
AppDatabase.getDatabase(this).deviceInfoDao().insert(deviceInfo);
list.add("设备信息初始化成功");
}
}else{
runOnUiThread(() -> XToastUtils.error("当前设备暂未注册,请联系管理员进行设备注册"));
}
} else {
runOnUiThread(() -> XToastUtils.error(jsonObject.getString("msg")));
}
}
}
private void initParameterInfo(List<String> list) {
String jsonString = new JSONObject().toString();
Log.i("getMealTime jsonString", jsonString);
// 定义 JSON MediaType
MediaType mediaType = MediaType.parse(AppConstants.MEDIA_TYPE);
// 创建 RequestBody
RequestBody body = RequestBody.create(mediaType, jsonString);
String url = WorkConfig.getBaseUrl() + UrlConfig.PARAM_SETTING_INFO;
Request request = new Request.Builder().url(url)
.post(body).build();
try {
String result = service.httpPost(url, body, this, request);
Log.e(TAG, "参数信息: " + result);
if (StringHelper.isEmptyAndNull(result)) {
runOnUiThread(() -> XToastUtils.error("参数信息初始化失败,请检查网络连接或服务器状态"));
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getIntValue("code") == 200) {
String data = jsonObject.getString("data");
if (data != null && !data.isEmpty()) {
ParamSettingInfo paramSettingInfo = JSONObject.parseObject(data, ParamSettingInfo.class);
if (paramSettingInfo != null) {
Log.e("LoginActivity", "参数信息: " + paramSettingInfo.toString());
ParamSettingInfo localParamSettingInfo = AppDatabase.getDatabase(this).parameterInfoDao().getOneInfo();
if (localParamSettingInfo == null) {
AppDatabase.getDatabase(this).parameterInfoDao().insert(paramSettingInfo);
} else if (!localParamSettingInfo.getVersion().equals(paramSettingInfo.getVersion())) {
AppDatabase.getDatabase(this).parameterInfoDao().deleteAll();
AppDatabase.getDatabase(this).parameterInfoDao().insert(paramSettingInfo);
}
list.add("参数信息初始化成功");
}
}
} else {
runOnUiThread(() -> XToastUtils.error(jsonObject.getString("msg")));
}
}
} catch (Exception e) {
Log.e(TAG, "initParameterInfo error: ", e);
runOnUiThread(() -> {
dialog.dismiss();
dialog = null;
XToastUtils.error("参数信息初始化失败,请检查网络连接或服务器状态");
});
}
}
private boolean checkParameters(String userName, String password) {
if (userName.isEmpty()) {
XToastUtils.warning("用户名不能为空");
return false;
}
if (password.isEmpty()) {
XToastUtils.warning("登录密码不能为空");
return false;
}
return true;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v instanceof EditText) {
int[] location = new int[2];
v.getLocationOnScreen(location);
float x = ev.getRawX() + v.getLeft() - location[0];
float y = ev.getRawY() + v.getTop() - location[1];
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
hideKeyboard(v);
}
}
}
return super.dispatchTouchEvent(ev);
}
private void hideKeyboard(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
/**
* 带圆形Loading的Dialog
*/
public void showTipDialog(String text) {
dialog = new MaterialDialog.Builder(this)
.iconRes(R.drawable.icon_tip)
.limitIconToDefaultSize()
.title("提示")
.content(text)
.progress(true, 0)
.progressIndeterminateStyle(false)
.cancelable(false)
.show();
}
}

View File

@ -0,0 +1,342 @@
/*
* Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.bonus.canteen.activity;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bonus.canteen.core.BaseActivity;
import com.bonus.canteen.db.AppDatabase;
import com.bonus.canteen.db.entity.base.LoginInfo;
import com.bonus.canteen.fragment.EnterAndOutRecordsFragment;
import com.bonus.canteen.fragment.EnterWarehouseFragment;
import com.bonus.canteen.fragment.OutWarehouseFragment;
import com.bonus.canteen.fragment.commonFragment.DocumentSelectionFragment;
import com.bonus.canteen.fragment.commonFragment.ProductSelectionFragment;
import com.bonus.canteen.receiver.ShutdownReceiver;
import com.bonus.canteen.utils.AppUtil;
import com.bonus.canteen.utils.GlideUtil;
import com.bonus.canteen.utils.SimplePopupWindow;
import com.bonus.canteen.utils.ThreadPoolManager;
import com.weight.serialport.SerialPort;
import com.xuexiang.xui.widget.dialog.DialogLoader;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;
import com.xuexiang.xutil.common.ClickUtils;
import org.checkerframework.checker.units.qual.C;
import org.easydarwin.easypusher.R;
import org.easydarwin.easypusher.databinding.ActivityMainBinding;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class MainActivity extends BaseActivity<ActivityMainBinding> implements ClickUtils.OnClick2ExitListener {
private static final String COLOR_SELECT = "#409eff";
private static final String COLOR_NO_SELECT = "#8a8a8a";
private static final String TAG = "MainActivity";
private MaterialDialog dialog;
@Override
protected ActivityMainBinding viewBindingInflate(LayoutInflater inflater) {
return ActivityMainBinding.inflate(inflater);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreen();
initView();
Bundle extras = getIntent().getExtras();
if (extras != null) {
String pageType = extras.getString("pageType");
if (pageType != null) {
switch (pageType) {
case "enter":
binding.linearEnter.performClick();
break;
case "out":
binding.linearOut.performClick();
break;
case "select":
binding.linearSelect.performClick();
break;
default:
binding.linearHome.performClick();
break;
}
} else {
binding.linearHome.performClick();
}
}
initTab();
}
private void setFullScreen() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
}
protected void initView() {
ThreadPoolManager.getExecutor().execute(()->{
LoginInfo loginInfo = AppDatabase.getDatabase(this).loginInfoDao().getLoginInfoOne();
binding.tvUserName.setText(loginInfo.getUserName());
});
binding.linearHome.setOnClickListener(view -> {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Fragment()).commit();
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
finish();
});
binding.linearEnter.setOnClickListener(view -> {
binding.linearEnter.setVisibility(View.GONE);
binding.linearEnterSidebar.setVisibility(View.VISIBLE);
binding.imgInGood.setImageResource(R.drawable.ic_store_select);
binding.tvInGood.setTextColor(Color.parseColor(COLOR_SELECT));
binding.linearOutSidebar.setVisibility(View.GONE);
binding.linearSelectSidebar.setVisibility(View.GONE);
binding.linearOut.setVisibility(View.VISIBLE);
binding.linearSelect.setVisibility(View.VISIBLE);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Fragment()).commit();
Bundle bundle = new Bundle();
bundle.putString("type", "enter");
switchPage(ProductSelectionFragment.class, bundle);
});
binding.linearOut.setOnClickListener(view -> {
binding.linearOut.setVisibility(View.GONE);
binding.linearEnterSidebar.setVisibility(View.GONE);
binding.linearOutSidebar.setVisibility(View.VISIBLE);
binding.imgOutGood.setImageResource(R.drawable.ic_outbound_select);
binding.tvOutGood.setTextColor(Color.parseColor(COLOR_SELECT));
binding.linearSelectSidebar.setVisibility(View.GONE);
binding.linearEnter.setVisibility(View.VISIBLE);
binding.linearSelect.setVisibility(View.VISIBLE);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Fragment()).commit();
Bundle bundle = new Bundle();
bundle.putString("type", "out");
switchPage(ProductSelectionFragment.class, bundle);
});
binding.linearSelect.setOnClickListener(view -> {
binding.linearSelect.setVisibility(View.GONE);
binding.linearEnterSidebar.setVisibility(View.GONE);
binding.linearOutSidebar.setVisibility(View.GONE);
binding.linearSelectSidebar.setVisibility(View.VISIBLE);
binding.linearOut.setVisibility(View.VISIBLE);
binding.linearEnter.setVisibility(View.VISIBLE);
binding.imgSelectGood.setImageResource(R.drawable.ic_select_good_select);
binding.tvSelectGood.setTextColor(Color.parseColor(COLOR_SELECT));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Fragment()).commit();
Bundle bundle = new Bundle();
bundle.putString("type", "select");
switchPage(ProductSelectionFragment.class, bundle);
});
binding.linearUser.setOnClickListener(view -> {
DialogLoader.getInstance().showConfirmDialog(
this,
"是否退出登录?",
getString(R.string.lab_yes),
(dialog, which) -> {
//跳转到登陆界面
startActivity(new Intent(this, LoginActivity.class));
finish();
},
getString(R.string.lab_no),
(dialog, which) -> dialog.dismiss());
});
}
private void initTab() {
View.OnClickListener tabClickListener = view -> {
int id = view.getId();
// 显示加载中阴影层
binding.loadingOverlay.setVisibility(View.VISIBLE);
// 显示加载中阴影层
binding.loadingText.setVisibility(View.VISIBLE);
changView();
// 清除上一个fragment
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Fragment()).commit();
if (id == R.id.linear_in_good) {
binding.tvInGood.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgInGood.setImageResource(R.drawable.ic_store_select);
Bundle bundle = new Bundle();
bundle.putString("type", "enter");
switchPage(ProductSelectionFragment.class, bundle);
}else if(id == R.id.linear_in_document){
binding.tvInDocument.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgInDocument.setImageResource(R.drawable.ic_document_select);
Bundle bundle = new Bundle();
bundle.putString("type", "enterInDocument");
switchPage(DocumentSelectionFragment.class,bundle);
}else if (id == R.id.linear_out_good) {
binding.tvOutGood.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgOutGood.setImageResource(R.drawable.ic_outbound_select);
Bundle bundle = new Bundle();
bundle.putString("type", "out");
switchPage(ProductSelectionFragment.class, bundle);
} else if(id == R.id.linear_out_document){
binding.tvOutDocument.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgOutDocument.setImageResource(R.drawable.ic_document_select);
Bundle bundle = new Bundle();
bundle.putString("type", "outInDocument");
switchPage(DocumentSelectionFragment.class,bundle);
}else if (id == R.id.linear_record) {
binding.tvRecord.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgRecord.setImageResource(R.drawable.ic_in_and_out_records_select);
switchPage(EnterAndOutRecordsFragment.class);
}else if (id == R.id.linear_select_good) {
binding.tvSelectGood.setTextColor(Color.parseColor(COLOR_SELECT));
binding.imgSelectGood.setImageResource(R.drawable.ic_select_good_select);
Bundle bundle = new Bundle();
bundle.putString("type", "select");
switchPage(ProductSelectionFragment.class, bundle);
}
// 延迟关闭加载中阴影层确保切换完成
binding.loadingOverlay.postDelayed(() -> {
binding.loadingOverlay.setVisibility(View.GONE);
binding.loadingText.setVisibility(View.GONE);
}, 300);
};
binding.linearInGood.setOnClickListener(tabClickListener);
binding.linearInDocument.setOnClickListener(tabClickListener);
binding.linearOutGood.setOnClickListener(tabClickListener);
binding.linearOutDocument.setOnClickListener(tabClickListener);
binding.linearRecord.setOnClickListener(tabClickListener);
binding.linearSelectGood.setOnClickListener(tabClickListener);
}
private void changView(){
binding.imgInGood.setImageResource(R.drawable.ic_store_no_select);
binding.tvInGood.setTextColor(Color.parseColor(COLOR_NO_SELECT));
binding.imgInDocument.setImageResource(R.drawable.ic_document);
binding.tvInDocument.setTextColor(Color.parseColor(COLOR_NO_SELECT));
binding.imgOutGood.setImageResource(R.drawable.ic_outbound_no_select);
binding.tvOutGood.setTextColor(Color.parseColor(COLOR_NO_SELECT));
binding.imgOutDocument.setImageResource(R.drawable.ic_document);
binding.tvOutDocument.setTextColor(Color.parseColor(COLOR_NO_SELECT));
binding.imgRecord.setImageResource(R.drawable.ic_in_and_out_records_no_select);
binding.tvRecord.setTextColor(Color.parseColor(COLOR_NO_SELECT));
binding.imgSelectGood.setImageResource(R.drawable.ic_select_good);
binding.tvSelectGood.setTextColor(Color.parseColor(COLOR_NO_SELECT));
}
@Override
public void onRetry() {
}
@Override
public void onExit() {
}
/**
* 只需要在最父级的activity中重写dispatchTouchEvent方法
* Activity 中使用 dispatchTouchEvent 方案无需在子布局重复注册触摸监听
*
* @param ev 触摸事件
* @return 返回值
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v instanceof EditText) {
int[] location = new int[2];
v.getLocationOnScreen(location);
float x = ev.getRawX() + v.getLeft() - location[0];
float y = ev.getRawY() + v.getTop() - location[1];
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
hideKeyboard(v);
}
}
}
return super.dispatchTouchEvent(ev);
}
private void hideKeyboard(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
ThreadPoolManager.shutdown();
}
public void updateView(int i) {
Log.d(TAG, "updateView: " + i);
changView();
switch (i) {
case 1:
binding.linearEnter.performClick();
break;
case 2:
binding.linearOut.performClick();
break;
case 3:
binding.linearEnter.performClick();
binding.linearInDocument.performClick();
break;
case 4:
binding.linearOut.performClick();
binding.linearOutDocument.performClick();
break;
default:
binding.linearHome.performClick();
break;
}
}
public void showTipDialog(String text) {
dialog = new MaterialDialog.Builder(this)
.iconRes(R.drawable.icon_tip)
.limitIconToDefaultSize()
.title("提示")
.content(text)
.progress(true, 0)
.progressIndeterminateStyle(false)
.cancelable(false)
.show();
}
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.bonus.canteen.activity;
import android.view.KeyEvent;
import com.bonus.canteen.db.AppDatabase;
import com.bonus.canteen.upgrade.UpdateDown;
import com.bonus.canteen.utils.TokenUtils;
import com.bonus.canteen.utils.WorkConfig;
import com.xuexiang.xui.utils.KeyboardUtils;
import com.xuexiang.xui.widget.activity.BaseSplashActivity;
import com.xuexiang.xutil.app.ActivityUtils;
import org.easydarwin.easypusher.R;
import me.jessyan.autosize.internal.CancelAdapt;
/**
* 启动页无需适配屏幕大小
*
* @author xuexiang
* @since 2019-06-30 17:32
*/
public class SplashActivity extends BaseSplashActivity implements CancelAdapt {
UpdateDown down = new UpdateDown(SplashActivity.this);
@Override
protected long getSplashDurationMillis() {
return 500;
}
/**
* activity启动后的初始化
*/
@Override
protected void onCreateActivity() {
initSplashView(R.drawable.xui_config_bg_splash);
startSplash(false);
}
/**
* 启动页结束后的动作
*/
@Override
protected void onSplashFinished() {
loginOrGoMainPage();
}
private void loginOrGoMainPage() {
// if (NetworkUtils.isNetworkConnected(this)) {
// new Thread(() -> {
// ParamSettingInfo paramSettingInfo = AppDatabase.getDatabase(this).parameterInfoDao().getOneInfo();
// String url = WorkConfig.getBaseUrl();
// if (paramSettingInfo != null){
// url = paramSettingInfo.getIpAddress() + "/smart-canteen";
// }
// boolean isLatestVersion = down.checkUpdate(url);
// runOnUiThread(() -> {
// if (!isLatestVersion) {
// navigateToNextPage();
// }
// });
// }).start();
// } else {
navigateToNextPage();
// }
}
private void navigateToNextPage() {
ActivityUtils.startActivity(LoginActivity.class);
finish();
}
/**
* 菜单返回键响应
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return KeyboardUtils.onDisableBackKeyDown(keyCode) && super.onKeyDown(keyCode, event);
}
}