33a7cd1a77208bb40eee3cd9e693d21bcf3ee13d.svn-base 18 KB

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