c3728f0ac05a1178b0e8546cc2b215359844e3aa.svn-base 9.4 KB

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