d250a7a334126f883b5a7f66bc27995253c3d9cf.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. package eVVM.apk.ui.home;
  2. import android.animation.Animator;
  3. import android.animation.AnimatorSet;
  4. import android.animation.ObjectAnimator;
  5. import android.app.Dialog;
  6. import android.content.Intent;
  7. import android.content.res.Resources;
  8. import android.nfc.NdefMessage;
  9. import android.nfc.NdefRecord;
  10. import android.nfc.NfcAdapter;
  11. import android.os.Handler;
  12. import android.os.Message;
  13. import android.os.Parcelable;
  14. import android.util.DisplayMetrics;
  15. import android.util.Log;
  16. import android.view.View;
  17. import android.view.animation.AlphaAnimation;
  18. import android.view.animation.Animation;
  19. import android.view.animation.CycleInterpolator;
  20. import android.view.animation.DecelerateInterpolator;
  21. import android.view.animation.LinearInterpolator;
  22. import android.view.animation.RotateAnimation;
  23. import android.widget.ImageView;
  24. import android.widget.ProgressBar;
  25. import android.widget.RelativeLayout;
  26. import com.hjq.bar.OnTitleBarListener;
  27. import com.hjq.bar.TitleBar;
  28. import com.hjq.base.BaseDialog;
  29. import com.hjq.base.BaseDialogFragment;
  30. import java.util.ArrayList;
  31. import java.util.Arrays;
  32. import java.util.List;
  33. import butterknife.BindView;
  34. import eVVM.apk.R;
  35. import eVVM.apk.helper.ActivityStackManager;
  36. import eVVM.apk.helper.DoubleClickHelper;
  37. import eVVM.apk.helper.SPUtils;
  38. import eVVM.apk.helper.SoundPoolHelper;
  39. import eVVM.apk.ui.bean.VnDetailBean;
  40. import eVVM.apk.ui.home.uploadChip.UploadChipContract;
  41. import eVVM.apk.ui.login.LoginActivity;
  42. import eVVM.apk.widget.EvvmMsgDiago;
  43. /**
  44. * 厂家操作员登录页面
  45. */
  46. public class FactoryOperatorActivity extends BaseNfcActivity implements UploadChipContract.View {
  47. private String textRecord;
  48. @BindView(R.id.reading_title)
  49. TitleBar readingTitle;
  50. @BindView(R.id.reading__line)
  51. ImageView imgreadline;
  52. @BindView(R.id.fly_phonerl)
  53. RelativeLayout flyphonerl;
  54. private Animation animation;
  55. private AlphaAnimation alp;
  56. private AnimatorSet animatorSetsuofang;
  57. private AnimatorSet animatorSetsuofang2;
  58. private BaseDialog loadDiago;
  59. private ProgressBar readpb;
  60. private List<String> logOutList = new ArrayList<>();
  61. @Override
  62. protected int getLayoutId() {
  63. return R.layout.activity_factory_operator;
  64. }
  65. @Override
  66. protected int getTitleId() {
  67. return R.id.reading_title;
  68. }
  69. @Override
  70. protected void initView() {
  71. getAnimationSao(); //进行雷达扫描动画
  72. soundPoolHelper = new SoundPoolHelper(5, SoundPoolHelper.TYPE_MUSIC)
  73. .setRingtoneType(SoundPoolHelper.RING_TYPE_MUSIC)
  74. .loadDefault(FactoryOperatorActivity.this)
  75. .load(FactoryOperatorActivity.this, "factory_operator_success", R.raw.factory_operator_success)
  76. .load(FactoryOperatorActivity.this, "factory_operator_error", R.raw.factory_operator_error)
  77. .load(FactoryOperatorActivity.this, "nuliduquzhong", R.raw.nuliduquzhong)
  78. .load(FactoryOperatorActivity.this, "shujukumeiyouxinpianid", R.raw.shujukumeiyouxinpianid)
  79. .load(FactoryOperatorActivity.this, "xinpianidyicunzai", R.raw.xinpianidyicunzai);
  80. readingTitle.setOnTitleBarListener(new OnTitleBarListener() {
  81. @Override
  82. public void onLeftClick(View v) {
  83. }
  84. @Override
  85. public void onTitleClick(View v) {
  86. }
  87. @Override
  88. public void onRightClick(View v) {
  89. getExit();
  90. //toast("tuichu");
  91. }
  92. });
  93. /*int flyPhoneType = (int) SPUtils.get("FlyPhoneType", 0);
  94. if (flyPhoneType == 0) {
  95. getFlyPhone();
  96. SPUtils.put("FlyPhoneType", 1);
  97. } else {
  98. flyphonerl.setVisibility(View.GONE);
  99. }*/
  100. }
  101. private void getFlyPhone() {
  102. Resources resources = this.getResources();
  103. DisplayMetrics dm = resources.getDisplayMetrics();
  104. int height3 = dm.heightPixels;
  105. //组合动画
  106. animatorSetsuofang = new AnimatorSet();
  107. // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
  108. ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", height3, flyphonerl.getY());
  109. animatorSetsuofang.setDuration(1200);
  110. animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
  111. animatorSetsuofang.play(scaleY);
  112. animatorSetsuofang.start();
  113. animatorSetsuofang.addListener(new Animator.AnimatorListener() {
  114. @Override
  115. public void onAnimationStart(Animator animation) {
  116. }
  117. @Override
  118. public void onAnimationEnd(Animator animation) {
  119. postDelayed(new Runnable() {
  120. @Override
  121. public void run() {
  122. //flyphonerl.setVisibility(View.GONE);
  123. animatorSetsuofang.cancel();
  124. getFlyGoBack();
  125. }
  126. }, 5000);
  127. }
  128. @Override
  129. public void onAnimationCancel(Animator animation) {
  130. }
  131. @Override
  132. public void onAnimationRepeat(Animator animation) {
  133. }
  134. });
  135. }
  136. private void getFlyGoBack() {
  137. Resources resources = this.getResources();
  138. DisplayMetrics dm = resources.getDisplayMetrics();
  139. int height3 = dm.heightPixels;
  140. //组合动画
  141. animatorSetsuofang2 = new AnimatorSet();
  142. // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
  143. ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", 0, height3);
  144. animatorSetsuofang2.setDuration(1500);
  145. animatorSetsuofang2.setInterpolator(new DecelerateInterpolator());
  146. animatorSetsuofang2.play(scaleY);
  147. animatorSetsuofang2.start();
  148. animatorSetsuofang2.addListener(new Animator.AnimatorListener() {
  149. @Override
  150. public void onAnimationStart(Animator animation) {
  151. }
  152. @Override
  153. public void onAnimationEnd(Animator animation) {
  154. flyphonerl.setVisibility(View.GONE);
  155. animatorSetsuofang2.cancel();
  156. }
  157. @Override
  158. public void onAnimationCancel(Animator animation) {
  159. }
  160. @Override
  161. public void onAnimationRepeat(Animator animation) {
  162. }
  163. });
  164. }
  165. private void getExit() {
  166. new EvvmMsgDiago.Builder(this)
  167. .setTitle("您确定要退出吗?")
  168. .setConfirm("确定")
  169. .setCancel("取消") // 设置 null 表示不显示取消按钮
  170. //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
  171. .setListener(new EvvmMsgDiago.OnListener() {
  172. @Override
  173. public void onConfirm(Dialog dialog) {
  174. //退出的操作
  175. startActivity(LoginActivity.class);
  176. SPUtils.logout();
  177. // 进行内存优化,销毁掉所有的界面
  178. ActivityStackManager.getInstance().finishAllActivities(LoginActivity.class);
  179. }
  180. @Override
  181. public void onCancel(Dialog dialog) {
  182. //toast("取消了");
  183. }
  184. })
  185. .show();
  186. }
  187. private void getAnimationSao() {
  188. animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  189. animation.setFillAfter(true);
  190. animation.setDuration(2000); //两秒转一圈
  191. animation.setInterpolator(new LinearInterpolator());
  192. animation.setRepeatCount(Animation.INFINITE); //循环执行
  193. imgreadline.startAnimation(animation);
  194. int[] antenna = new int[]{R.id.reading_antenna1, R.id.reading_antenna2, R.id.reading_antenna3, R.id.reading_antenna4, R.id.reading_antenna5, R.id.reading_antenna6,
  195. R.id.reading_antenna7, R.id.reading_antenna8, R.id.reading_antenna9};
  196. int nfcWireIndex = 2;
  197. try {
  198. nfcWireIndex = Integer.parseInt(String.valueOf(SPUtils.get("PHONE_MODEL", "2")));
  199. } catch (Exception e) {
  200. e.printStackTrace();
  201. }
  202. alp = new AlphaAnimation(1, 0.2f);
  203. alp.setStartOffset(500);
  204. alp.setDuration(1000);
  205. alp.setFillAfter(false);
  206. alp.setInterpolator(new CycleInterpolator(2));
  207. alp.setRepeatCount(Animation.INFINITE);
  208. findViewById(antenna[nfcWireIndex - 1]).setAnimation(alp);
  209. alp.start();
  210. }
  211. @Override
  212. protected void initData() {
  213. mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
  214. // gpsLocationManager = GPSLocationManager.getInstances(FactoryOperatorActivity.this);
  215. }
  216. //记录ProgressBar的完成进度
  217. private int status = 0; //进度条进度
  218. private int hasDate = 0;//每次快进多少
  219. //创建一个负责更新进度的Handler
  220. private Handler mHandler = new Handler() {
  221. @Override
  222. public void handleMessage(Message msg) {
  223. //表明消息是由该程序发送的
  224. if (msg.what == 0x111) {
  225. readpb.setProgress(status);
  226. if (status == 100) {
  227. loadDiago.dismiss();
  228. }
  229. }
  230. }
  231. };
  232. private boolean issao; //设置一个flag 判断是否正在读取
  233. @Override
  234. public void onNewIntent(Intent intent) {
  235. readNfcTag(intent);
  236. Log.e("***", textRecord);
  237. if (issao) {
  238. return;
  239. } else {
  240. issao = true; //开始读取
  241. if (textRecord != null) {
  242. hasDate = 0;
  243. status = 0;
  244. soundPoolHelper.play("nuliduquzhong", false);
  245. loadDiago = new BaseDialogFragment.Builder(FactoryOperatorActivity.this)
  246. .setContentView(R.layout.progressreader)
  247. .setAnimStyle(BaseDialog.AnimStyle.SCALE)
  248. //.setText(id, "我是预设置的文本")
  249. .addOnShowListener(new BaseDialog.OnShowListener() {
  250. @Override
  251. public void onShow(BaseDialog dialog) {
  252. //toast("Dialog 显示了");
  253. }
  254. })
  255. .addOnCancelListener(new BaseDialog.OnCancelListener() {
  256. @Override
  257. public void onCancel(BaseDialog dialog) {
  258. //toast("Dialog 取消了");
  259. }
  260. })
  261. .addOnDismissListener(new BaseDialog.OnDismissListener() {
  262. @Override
  263. public void onDismiss(BaseDialog dialog) {
  264. //进度条走完 进行加载
  265. if (textRecord.length() > 94) {
  266. if (SPUtils.contains("LOCATION")) {
  267. Log.e("LOCATION", SPUtils.get("LOCATION", "").toString());
  268. String location[] = SPUtils.get("LOCATION", "").toString().split(",");
  269. if (location.length > 1) {
  270. Double latitude = Double.parseDouble(location[0]);
  271. Double longitude = Double.parseDouble(location[1]);
  272. String chipNumber = textRecord.substring(6, chipNumberEndIndex);
  273. getPresenter().forFactoryOperator(chipNumber, textRecord, longitude, latitude);
  274. } else {
  275. toast("位置信息错误");
  276. }
  277. } else {
  278. toast("位置信息获取失败");
  279. }
  280. } else {
  281. toast("读取失败,请重试");
  282. }
  283. issao = false; //一次读取结束
  284. }
  285. })
  286. .show();
  287. readpb = loadDiago.findViewById(R.id.read_progress);
  288. //启动线程来执行任务
  289. new Thread() {
  290. @Override
  291. public void run() {
  292. super.run();
  293. while (status < 100) {
  294. //获取耗时操作的完成百分比
  295. status = doWork();
  296. //发送消息
  297. mHandler.sendEmptyMessage(0x111);
  298. }
  299. }
  300. }.start();
  301. }
  302. }
  303. }
  304. //进行进度条加载
  305. private int doWork() {
  306. //为元素赋值
  307. hasDate += 10;
  308. try {
  309. Thread.sleep(200);
  310. } catch (InterruptedException e) {
  311. e.printStackTrace();
  312. }
  313. return hasDate;
  314. }
  315. private SoundPoolHelper soundPoolHelper;
  316. @Override
  317. public void uploadChipError(String msg) {
  318. if (msg.equals("芯片不存在")) {
  319. soundPoolHelper.play("shujukumeiyouxinpianid", false);
  320. } else if (msg.equals("芯片记录已保存") || msg.equals("芯片已使用")) {
  321. soundPoolHelper.play("xinpianidyicunzai", false);
  322. } else {
  323. soundPoolHelper.play("factory_operator_error", false);
  324. }
  325. toast(msg);
  326. }
  327. @Override
  328. public void uploadChipSuccess(VnDetailBean data) {
  329. soundPoolHelper.play("factory_operator_success", false);
  330. toast("读取成功");
  331. Log.e("FactoryOperatorActivity", data.getCode() + "");
  332. }
  333. /**
  334. * 读取NFC标签文本数据
  335. */
  336. private void readNfcTag(Intent intent) {
  337. if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
  338. Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
  339. NfcAdapter.EXTRA_NDEF_MESSAGES);
  340. NdefMessage msgs[] = null;
  341. int contentSize = 0;
  342. if (rawMsgs != null) {
  343. msgs = new NdefMessage[rawMsgs.length];
  344. for (int i = 0; i < rawMsgs.length; i++) {
  345. msgs[i] = (NdefMessage) rawMsgs[i];
  346. contentSize += msgs[i].toByteArray().length;
  347. }
  348. }
  349. try {
  350. if (msgs != null) {
  351. NdefRecord record = msgs[0].getRecords()[0];
  352. textRecord = parseTextRecord(record);
  353. // mTagText += textRecord + "\n\ntext\n" + contentSize + " bytes";
  354. }
  355. } catch (Exception e) {
  356. }
  357. }
  358. }
  359. /**
  360. * 解析NDEF文本数据
  361. */
  362. public static String parseTextRecord(NdefRecord ndefRecord) {
  363. /**
  364. * 判断数据是否为NDEF格式
  365. */
  366. //判断TNF
  367. if (ndefRecord.getTnf() != NdefRecord.TNF_WELL_KNOWN) {
  368. return null;
  369. }
  370. //判断可变的长度的类型
  371. if (!Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
  372. return null;
  373. }
  374. try {
  375. byte[] bArray = ndefRecord.getPayload();
  376. StringBuffer sb = new StringBuffer(bArray.length);
  377. String sTemp;
  378. for (int i = 0; i < bArray.length; i++) {
  379. sTemp = Integer.toHexString(0xFF & bArray[i]);
  380. if (sTemp.length() < 2)
  381. sb.append(0);
  382. sb.append(sTemp.toUpperCase());
  383. }
  384. return sb.toString();
  385. } catch (Exception e) {
  386. throw new IllegalArgumentException();
  387. }
  388. }
  389. @Override
  390. protected void onStart() {
  391. super.onStart();
  392. }
  393. @Override
  394. protected void onStop() {
  395. super.onStop();
  396. //终止定位
  397. // gpsLocationManager.stop();
  398. }
  399. @Override
  400. protected void onDestroy() {
  401. animation.cancel();
  402. alp.cancel();
  403. mHandler.removeCallbacksAndMessages(true);
  404. super.onDestroy();
  405. }
  406. @Override
  407. public void onBackPressed() {
  408. if (DoubleClickHelper.isOnDoubleClick()) {
  409. //移动到上一个任务栈,避免侧滑引起的不良反应
  410. moveTaskToBack(false);
  411. postDelayed(new Runnable() {
  412. @Override
  413. public void run() {
  414. // 进行内存优化,销毁掉所有的界面
  415. ActivityStackManager.getInstance().finishAllActivities();
  416. // 销毁进程
  417. System.exit(0);
  418. }
  419. }, 300);
  420. } else {
  421. toast(getResources().getString(R.string.home_exit_hint));
  422. }
  423. }
  424. @Override
  425. public boolean isSupportSwipeBack() {
  426. // 不使用侧滑功能
  427. return false;
  428. }
  429. }