a1b2d7e91094ca9fea1404047b2a05e6f3fcd8a8.svn-base 16 KB

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