c2cf0d05f1e78d6485a8a02ca8321cfcbf7d8785.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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.Parcelable;
  13. import android.os.Bundle;
  14. import android.util.DisplayMetrics;
  15. import android.util.Log;
  16. import android.view.View;
  17. import com.hjq.bar.OnTitleBarListener;
  18. import com.hjq.bar.TitleBar;
  19. import com.hjq.dialog.MessageDialog;
  20. import android.view.animation.AlphaAnimation;
  21. import android.view.animation.Animation;
  22. import android.view.animation.CycleInterpolator;
  23. import android.view.animation.DecelerateInterpolator;
  24. import android.view.animation.LinearInterpolator;
  25. import android.view.animation.RotateAnimation;
  26. import android.widget.ImageView;
  27. import android.widget.RelativeLayout;
  28. import java.util.Arrays;
  29. import butterknife.BindView;
  30. import eVVM.apk.R;
  31. import eVVM.apk.helper.SPUtils;
  32. import eVVM.apk.helper.SoundPoolHelper;
  33. import eVVM.apk.ui.bean.VnDetailBean;
  34. import eVVM.apk.ui.home.uploadChip.UploadChipContract;
  35. import eVVM.apk.helper.ActivityStackManager;
  36. import eVVM.apk.helper.DoubleClickHelper;
  37. import eVVM.apk.ui.login.LoginActivity;
  38. /**
  39. * 厂家操作员登录页面
  40. */
  41. public class FactoryOperatorActivity extends BaseNfcActivity implements UploadChipContract.View {
  42. private String textRecord;
  43. @BindView(R.id.reading_title)
  44. TitleBar readingTitle;
  45. @BindView(R.id.reading__line)
  46. ImageView imgreadline;
  47. @BindView(R.id.fly_phonerl)
  48. RelativeLayout flyphonerl;
  49. private Animation animation;
  50. private AlphaAnimation alp;
  51. private AnimatorSet animatorSetsuofang;
  52. private AnimatorSet animatorSetsuofang2;
  53. @Override
  54. protected int getLayoutId() {
  55. return R.layout.activity_factory_operator;
  56. }
  57. @Override
  58. protected int getTitleId() {
  59. return R.id.reading_title;
  60. }
  61. @Override
  62. protected void initView() {
  63. getAnimationSao(); //进行雷达扫描动画
  64. soundPoolHelper = new SoundPoolHelper(4, SoundPoolHelper.TYPE_MUSIC)
  65. .setRingtoneType(SoundPoolHelper.RING_TYPE_MUSIC)
  66. .loadDefault(FactoryOperatorActivity.this)
  67. .load(FactoryOperatorActivity.this, "factory_operator_success", R.raw.factory_operator_success)
  68. .load(FactoryOperatorActivity.this, "factory_operator_error", R.raw.factory_operator_error);
  69. readingTitle.setOnTitleBarListener(new OnTitleBarListener() {
  70. @Override
  71. public void onLeftClick(View v) {
  72. }
  73. @Override
  74. public void onTitleClick(View v) {
  75. }
  76. @Override
  77. public void onRightClick(View v) {
  78. getExit();
  79. //toast("tuichu");
  80. }
  81. });
  82. getFlyPhone();
  83. }
  84. private void getFlyPhone() {
  85. Resources resources = this.getResources();
  86. DisplayMetrics dm = resources.getDisplayMetrics();
  87. int height3 = dm.heightPixels;
  88. //组合动画
  89. animatorSetsuofang = new AnimatorSet();
  90. // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
  91. ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", height3, flyphonerl.getY());
  92. animatorSetsuofang.setDuration(3500);
  93. animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
  94. animatorSetsuofang.play(scaleY);
  95. animatorSetsuofang.start();
  96. animatorSetsuofang.addListener(new Animator.AnimatorListener() {
  97. @Override
  98. public void onAnimationStart(Animator animation) {
  99. }
  100. @Override
  101. public void onAnimationEnd(Animator animation) {
  102. postDelayed(new Runnable() {
  103. @Override
  104. public void run() {
  105. //flyphonerl.setVisibility(View.GONE);
  106. animatorSetsuofang.cancel();
  107. getFlyGoBack();
  108. }
  109. }, 3500);
  110. }
  111. @Override
  112. public void onAnimationCancel(Animator animation) {
  113. }
  114. @Override
  115. public void onAnimationRepeat(Animator animation) {
  116. }
  117. });
  118. }
  119. private void getFlyGoBack() {
  120. Resources resources = this.getResources();
  121. DisplayMetrics dm = resources.getDisplayMetrics();
  122. int height3 = dm.heightPixels;
  123. //组合动画
  124. animatorSetsuofang2 = new AnimatorSet();
  125. // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
  126. ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", 0, height3);
  127. animatorSetsuofang2.setDuration(3000);
  128. animatorSetsuofang2.setInterpolator(new DecelerateInterpolator());
  129. animatorSetsuofang2.play(scaleY);
  130. animatorSetsuofang2.start();
  131. animatorSetsuofang2.addListener(new Animator.AnimatorListener() {
  132. @Override
  133. public void onAnimationStart(Animator animation) {
  134. }
  135. @Override
  136. public void onAnimationEnd(Animator animation) {
  137. flyphonerl.setVisibility(View.GONE);
  138. animatorSetsuofang2.cancel();
  139. }
  140. @Override
  141. public void onAnimationCancel(Animator animation) {
  142. }
  143. @Override
  144. public void onAnimationRepeat(Animator animation) {
  145. }
  146. });
  147. }
  148. private void getExit() {
  149. new MessageDialog.Builder(this)
  150. .setTitle("") // 标题可以不用填写
  151. .setMessage("您确定要退出吗")
  152. .setConfirm("确定")
  153. .setCancel("取消") // 设置 null 表示不显示取消按钮
  154. //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
  155. .setListener(new MessageDialog.OnListener() {
  156. @Override
  157. public void onConfirm(Dialog dialog) {
  158. //退出的操作
  159. startActivity(LoginActivity.class);
  160. SPUtils.logout();
  161. // 进行内存优化,销毁掉所有的界面
  162. ActivityStackManager.getInstance().finishAllActivities(LoginActivity.class);
  163. }
  164. @Override
  165. public void onCancel(Dialog dialog) {
  166. //toast("取消了");
  167. }
  168. })
  169. .show();
  170. }
  171. private void getAnimationSao() {
  172. animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  173. animation.setFillAfter(true);
  174. animation.setDuration(2000); //两秒转一圈
  175. animation.setInterpolator(new LinearInterpolator());
  176. animation.setRepeatCount(Animation.INFINITE); //循环执行
  177. imgreadline.startAnimation(animation);
  178. 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,
  179. R.id.reading_antenna7, R.id.reading_antenna8, R.id.reading_antenna9};
  180. int nfcWireIndex = 2;
  181. try {
  182. nfcWireIndex = Integer.parseInt(String.valueOf(SPUtils.get("PHONE_MODEL", "2")));
  183. } catch (Exception e) {
  184. e.printStackTrace();
  185. }
  186. alp = new AlphaAnimation(1, 0.2f);
  187. alp.setStartOffset(500);
  188. alp.setDuration(1000);
  189. alp.setFillAfter(false);
  190. alp.setInterpolator(new CycleInterpolator(2));
  191. alp.setRepeatCount(Animation.INFINITE);
  192. findViewById(antenna[nfcWireIndex - 1]).setAnimation(alp);
  193. alp.start();
  194. }
  195. @Override
  196. protected void initData() {
  197. mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
  198. // gpsLocationManager = GPSLocationManager.getInstances(FactoryOperatorActivity.this);
  199. }
  200. @Override
  201. public void onNewIntent(Intent intent) {
  202. readNfcTag(intent);
  203. Log.e("***", textRecord);
  204. if (textRecord.length() > 94) {
  205. if (SPUtils.contains("LOCATION")) {
  206. Log.e("LOCATION", SPUtils.get("LOCATION", "").toString());
  207. String location[] = SPUtils.get("LOCATION", "").toString().split(",");
  208. if (location.length > 1) {
  209. Double latitude = Double.parseDouble(location[0]);
  210. Double longitude = Double.parseDouble(location[1]);
  211. String chipNumber = textRecord.substring(6, chipNumberEndIndex);
  212. getPresenter().forFactoryOperator(chipNumber, textRecord, longitude, latitude);
  213. } else {
  214. toast("位置信息错误");
  215. }
  216. } else {
  217. toast("位置信息获取失败");
  218. }
  219. } else {
  220. toast("读取失败,请重试");
  221. }
  222. }
  223. private SoundPoolHelper soundPoolHelper;
  224. @Override
  225. public void uploadChipError(String msg) {
  226. if (msg.equals("芯片不存在")) {
  227. soundPoolHelper.play("factory_operator_error", false);
  228. }
  229. toast(msg);
  230. }
  231. @Override
  232. public void uploadChipSuccess(VnDetailBean data) {
  233. soundPoolHelper.play("factory_operator_success", false);
  234. toast("读取成功");
  235. Log.e("FactoryOperatorActivity", data.getCode() + "");
  236. }
  237. /**
  238. * 读取NFC标签文本数据
  239. */
  240. private void readNfcTag(Intent intent) {
  241. if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
  242. Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
  243. NfcAdapter.EXTRA_NDEF_MESSAGES);
  244. NdefMessage msgs[] = null;
  245. int contentSize = 0;
  246. if (rawMsgs != null) {
  247. msgs = new NdefMessage[rawMsgs.length];
  248. for (int i = 0; i < rawMsgs.length; i++) {
  249. msgs[i] = (NdefMessage) rawMsgs[i];
  250. contentSize += msgs[i].toByteArray().length;
  251. }
  252. }
  253. try {
  254. if (msgs != null) {
  255. NdefRecord record = msgs[0].getRecords()[0];
  256. textRecord = parseTextRecord(record);
  257. // mTagText += textRecord + "\n\ntext\n" + contentSize + " bytes";
  258. }
  259. } catch (Exception e) {
  260. }
  261. }
  262. }
  263. /**
  264. * 解析NDEF文本数据
  265. */
  266. public static String parseTextRecord(NdefRecord ndefRecord) {
  267. /**
  268. * 判断数据是否为NDEF格式
  269. */
  270. //判断TNF
  271. if (ndefRecord.getTnf() != NdefRecord.TNF_WELL_KNOWN) {
  272. return null;
  273. }
  274. //判断可变的长度的类型
  275. if (!Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
  276. return null;
  277. }
  278. try {
  279. byte[] bArray = ndefRecord.getPayload();
  280. StringBuffer sb = new StringBuffer(bArray.length);
  281. String sTemp;
  282. for (int i = 0; i < bArray.length; i++) {
  283. sTemp = Integer.toHexString(0xFF & bArray[i]);
  284. if (sTemp.length() < 2)
  285. sb.append(0);
  286. sb.append(sTemp.toUpperCase());
  287. }
  288. return sb.toString();
  289. } catch (Exception e) {
  290. throw new IllegalArgumentException();
  291. }
  292. }
  293. @Override
  294. protected void onStart() {
  295. super.onStart();
  296. }
  297. @Override
  298. protected void onStop() {
  299. super.onStop();
  300. //终止定位
  301. // gpsLocationManager.stop();
  302. }
  303. @Override
  304. protected void onDestroy() {
  305. animation.cancel();
  306. alp.cancel();
  307. super.onDestroy();
  308. }
  309. @Override
  310. public void onBackPressed() {
  311. if (DoubleClickHelper.isOnDoubleClick()) {
  312. //移动到上一个任务栈,避免侧滑引起的不良反应
  313. moveTaskToBack(false);
  314. postDelayed(new Runnable() {
  315. @Override
  316. public void run() {
  317. // 进行内存优化,销毁掉所有的界面
  318. ActivityStackManager.getInstance().finishAllActivities();
  319. // 销毁进程
  320. System.exit(0);
  321. }
  322. }, 300);
  323. } else {
  324. toast(getResources().getString(R.string.home_exit_hint));
  325. }
  326. }
  327. @Override
  328. public boolean isSupportSwipeBack() {
  329. // 不使用侧滑功能
  330. return false;
  331. }
  332. }