0c7d3663418fd2163e665fa2d671f442bfd9e076.svn-base 16 KB

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