RobotInfoActivity.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package com.qy.agv.activity;
  2. import static com.qy.agv.util.Constant.CACHE_BIND_CONTROL;
  3. import static com.qy.agv.util.Constant.CACHE_LOGIN_KEY;
  4. import android.annotation.SuppressLint;
  5. import android.app.AlertDialog;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.os.Bundle;
  10. import android.os.Handler;
  11. import android.os.StrictMode;
  12. import android.provider.Settings;
  13. import android.view.View;
  14. import com.qy.agv.activity.model.EventMessage;
  15. import com.qy.agv.comm.BaseActivity;
  16. import com.qy.agv.comm.CacheService;
  17. import com.qy.agv.databinding.QyRobotInfoBinding;
  18. import com.qy.agv.update.UpdateManager;
  19. import com.qy.agv.update.UpdateXmlService;
  20. import com.qy.agv.util.Constant;
  21. import com.qy.agv.util.ProjectUtils;
  22. import com.qy.agv.util.StringUtils;
  23. import com.qy.agv.util.ToastUtils;
  24. import com.qy.agv.util.VersionUtils;
  25. import org.apache.log4j.Logger;
  26. import org.greenrobot.eventbus.EventBus;
  27. import org.xutils.x;
  28. import java.io.InputStream;
  29. import java.net.HttpURLConnection;
  30. import java.net.SocketTimeoutException;
  31. import java.net.URL;
  32. import java.util.HashMap;
  33. public class RobotInfoActivity extends BaseActivity {
  34. public static Logger mylog =Logger.getLogger(RobotInfoActivity.class);
  35. private Context context;
  36. private QyRobotInfoBinding binding;
  37. private HashMap<String,String> mHashMap;
  38. @Override
  39. public void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. binding = QyRobotInfoBinding.inflate(getLayoutInflater());
  42. setContentView(binding.getRoot());
  43. x.view().inject(this);
  44. context = this;
  45. initCommonTop2();
  46. init();
  47. }
  48. @SuppressLint("ClickableViewAccessibility")
  49. public void init(){
  50. if(Constant.user!=null) {
  51. binding.tvLoginName.setText(Constant.user.getReal_name());
  52. }else{
  53. binding.tvLoginName.setText("未登录");
  54. }
  55. binding.tvWorkStation.setText("操作员");
  56. binding.tvVersion.setText(VersionUtils.getVerName(context));
  57. binding.tvDeviceSeq.setText(getMac());
  58. binding.versionUpdate.setOnClickListener(view->{
  59. updateApp();
  60. });
  61. binding.exit.setOnClickListener(view->{
  62. logout();
  63. });
  64. }
  65. private void updateApp(){
  66. try {
  67. boolean haveInstallPermission = context.getPackageManager().canRequestPackageInstalls();
  68. Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
  69. if (!haveInstallPermission) {
  70. context.startActivity(intent);
  71. }
  72. }catch (NoSuchMethodError e){
  73. e.printStackTrace();
  74. }
  75. if(isUpdate()) {
  76. ProjectUtils.init();
  77. UpdateManager updateManager = new UpdateManager(context, mHashMap);
  78. updateManager.showDownloadDialog();
  79. }else {
  80. ToastUtils.showToast(this, "已经是最新版本了");
  81. }
  82. }
  83. public boolean isUpdate(){
  84. try {
  85. int versionCode = VersionUtils.getVerCode(this);
  86. UpdateXmlService service = new UpdateXmlService();
  87. String path = ProjectUtils.getProjectURL() + "/version.xml";
  88. URL url = new URL(path);
  89. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  90. conn.setReadTimeout(5 * 1000);
  91. conn.setConnectTimeout(10000);
  92. conn.setRequestMethod("GET");
  93. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  94. .permitAll().build();
  95. StrictMode.setThreadPolicy(policy);
  96. InputStream inStream = conn.getInputStream();
  97. mHashMap = service.parseXml(inStream);
  98. String current_version = mHashMap.get("version");
  99. if (StringUtils.isEmpty(current_version)) {
  100. return false;
  101. }
  102. if (null != mHashMap) {
  103. int serviceCode = Integer.parseInt(current_version);
  104. return serviceCode > versionCode;
  105. }
  106. } catch (SocketTimeoutException ex){
  107. ToastUtils.showToast(this, "连接超过");
  108. } catch (Exception e) {
  109. e.printStackTrace();
  110. }
  111. return false;
  112. }
  113. private void logout(){
  114. AlertDialog alert = new AlertDialog.Builder(RobotInfoActivity.this)
  115. .setTitle("提示")
  116. .setMessage("确定退出系统吗?")
  117. .setPositiveButton("确定",
  118. new DialogInterface.OnClickListener() {// 设置确定按钮
  119. @Override
  120. // 处理确定按钮点击事件
  121. public void onClick(DialogInterface dialog, int which) {
  122. Constant.user = null;
  123. CacheService.getInstance(context).clear(CACHE_BIND_CONTROL);
  124. CacheService.getInstance(context).clear(CACHE_LOGIN_KEY);
  125. Constant.ACCESS_TOKEN = null;
  126. Constant.REFRESH_TOKEN = null;
  127. try {
  128. EventMessage message = new EventMessage(1, "退出");
  129. EventBus.getDefault().post(message);
  130. }catch (Exception ex){
  131. ex.printStackTrace();
  132. }
  133. dialog.cancel();// 对话框关闭。
  134. new Handler().postDelayed(()->{finish();}, 300);
  135. }
  136. })
  137. .setNegativeButton("取消", null)
  138. .setCancelable(true).create();
  139. alert.show();
  140. }
  141. @Override
  142. public void receiverTask(String barcode) {
  143. }
  144. @Override
  145. protected String getCommonTopTitle() {
  146. return "设备信息";
  147. }
  148. @Override
  149. protected int getCommonTopICO() {
  150. return 0;
  151. }
  152. @Override
  153. protected void onDestroy() {
  154. super.onDestroy();
  155. }
  156. }