17d6f8a23ec4f331cf58c26576d5774daee1f58f.svn-base 18 KB

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