| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- package eVVM.apk.ui.home;
- import android.animation.Animator;
- import android.animation.AnimatorSet;
- import android.animation.ObjectAnimator;
- import android.app.Dialog;
- import android.content.Intent;
- import android.content.res.Resources;
- import android.nfc.NdefMessage;
- import android.nfc.NdefRecord;
- import android.nfc.NfcAdapter;
- import android.os.Handler;
- import android.os.Message;
- import android.os.Parcelable;
- import android.util.DisplayMetrics;
- import android.util.Log;
- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.CycleInterpolator;
- import android.view.animation.DecelerateInterpolator;
- import android.view.animation.LinearInterpolator;
- import android.view.animation.RotateAnimation;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.RelativeLayout;
- import com.hjq.bar.OnTitleBarListener;
- import com.hjq.bar.TitleBar;
- import com.hjq.base.BaseDialog;
- import com.hjq.base.BaseDialogFragment;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import butterknife.BindView;
- import eVVM.apk.R;
- import eVVM.apk.helper.ActivityStackManager;
- import eVVM.apk.helper.DoubleClickHelper;
- import eVVM.apk.helper.SPUtils;
- import eVVM.apk.helper.SoundPoolHelper;
- import eVVM.apk.ui.bean.VnDetailBean;
- import eVVM.apk.ui.home.uploadChip.UploadChipContract;
- import eVVM.apk.ui.login.LoginActivity;
- import eVVM.apk.widget.EvvmMsgDiago;
- /**
- * 厂家操作员登录页面
- */
- public class FactoryOperatorActivity extends BaseNfcActivity implements UploadChipContract.View {
- private String textRecord;
- @BindView(R.id.reading_title)
- TitleBar readingTitle;
- @BindView(R.id.reading__line)
- ImageView imgreadline;
- @BindView(R.id.fly_phonerl)
- RelativeLayout flyphonerl;
- private Animation animation;
- private AlphaAnimation alp;
- private AnimatorSet animatorSetsuofang;
- private AnimatorSet animatorSetsuofang2;
- private BaseDialog loadDiago;
- private ProgressBar readpb;
- private List<String> logOutList = new ArrayList<>();
- @Override
- protected int getLayoutId() {
- return R.layout.activity_factory_operator;
- }
- @Override
- protected int getTitleId() {
- return R.id.reading_title;
- }
- @Override
- protected void initView() {
- getAnimationSao(); //进行雷达扫描动画
- soundPoolHelper = new SoundPoolHelper(5, SoundPoolHelper.TYPE_MUSIC)
- .setRingtoneType(SoundPoolHelper.RING_TYPE_MUSIC)
- .loadDefault(FactoryOperatorActivity.this)
- .load(FactoryOperatorActivity.this, "factory_operator_success", R.raw.factory_operator_success)
- .load(FactoryOperatorActivity.this, "factory_operator_error", R.raw.factory_operator_error)
- .load(FactoryOperatorActivity.this, "nuliduquzhong", R.raw.nuliduquzhong)
- .load(FactoryOperatorActivity.this, "shujukumeiyouxinpianid", R.raw.shujukumeiyouxinpianid)
- .load(FactoryOperatorActivity.this, "xinpianidyicunzai", R.raw.xinpianidyicunzai);
- readingTitle.setOnTitleBarListener(new OnTitleBarListener() {
- @Override
- public void onLeftClick(View v) {
- }
- @Override
- public void onTitleClick(View v) {
- }
- @Override
- public void onRightClick(View v) {
- getExit();
- //toast("tuichu");
- }
- });
- /*int flyPhoneType = (int) SPUtils.get("FlyPhoneType", 0);
- if (flyPhoneType == 0) {
- getFlyPhone();
- SPUtils.put("FlyPhoneType", 1);
- } else {
- flyphonerl.setVisibility(View.GONE);
- }*/
- }
- private void getFlyPhone() {
- Resources resources = this.getResources();
- DisplayMetrics dm = resources.getDisplayMetrics();
- int height3 = dm.heightPixels;
- //组合动画
- animatorSetsuofang = new AnimatorSet();
- // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
- ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", height3, flyphonerl.getY());
- animatorSetsuofang.setDuration(1200);
- animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
- animatorSetsuofang.play(scaleY);
- animatorSetsuofang.start();
- animatorSetsuofang.addListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
- @Override
- public void onAnimationEnd(Animator animation) {
- postDelayed(new Runnable() {
- @Override
- public void run() {
- //flyphonerl.setVisibility(View.GONE);
- animatorSetsuofang.cancel();
- getFlyGoBack();
- }
- }, 5000);
- }
- @Override
- public void onAnimationCancel(Animator animation) {
- }
- @Override
- public void onAnimationRepeat(Animator animation) {
- }
- });
- }
- private void getFlyGoBack() {
- Resources resources = this.getResources();
- DisplayMetrics dm = resources.getDisplayMetrics();
- int height3 = dm.heightPixels;
- //组合动画
- animatorSetsuofang2 = new AnimatorSet();
- // ObjectAnimator scaleX = ObjectAnimator.ofFloat(scohhh, "translationX", 1.5f, 1f);
- ObjectAnimator scaleY = ObjectAnimator.ofFloat(flyphonerl, "translationY", 0, height3);
- animatorSetsuofang2.setDuration(1500);
- animatorSetsuofang2.setInterpolator(new DecelerateInterpolator());
- animatorSetsuofang2.play(scaleY);
- animatorSetsuofang2.start();
- animatorSetsuofang2.addListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
- @Override
- public void onAnimationEnd(Animator animation) {
- flyphonerl.setVisibility(View.GONE);
- animatorSetsuofang2.cancel();
- }
- @Override
- public void onAnimationCancel(Animator animation) {
- }
- @Override
- public void onAnimationRepeat(Animator animation) {
- }
- });
- }
- private void getExit() {
- new EvvmMsgDiago.Builder(this)
- .setTitle("您确定要退出吗?")
- .setConfirm("确定")
- .setCancel("取消") // 设置 null 表示不显示取消按钮
- //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
- .setListener(new EvvmMsgDiago.OnListener() {
- @Override
- public void onConfirm(Dialog dialog) {
- //退出的操作
- startActivity(LoginActivity.class);
- SPUtils.logout();
- // 进行内存优化,销毁掉所有的界面
- ActivityStackManager.getInstance().finishAllActivities(LoginActivity.class);
- }
- @Override
- public void onCancel(Dialog dialog) {
- //toast("取消了");
- }
- })
- .show();
- }
- private void getAnimationSao() {
- animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- animation.setFillAfter(true);
- animation.setDuration(2000); //两秒转一圈
- animation.setInterpolator(new LinearInterpolator());
- animation.setRepeatCount(Animation.INFINITE); //循环执行
- imgreadline.startAnimation(animation);
- 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,
- R.id.reading_antenna7, R.id.reading_antenna8, R.id.reading_antenna9};
- int nfcWireIndex = 2;
- try {
- nfcWireIndex = Integer.parseInt(String.valueOf(SPUtils.get("PHONE_MODEL", "2")));
- } catch (Exception e) {
- e.printStackTrace();
- }
- alp = new AlphaAnimation(1, 0.2f);
- alp.setStartOffset(500);
- alp.setDuration(1000);
- alp.setFillAfter(false);
- alp.setInterpolator(new CycleInterpolator(2));
- alp.setRepeatCount(Animation.INFINITE);
- findViewById(antenna[nfcWireIndex - 1]).setAnimation(alp);
- alp.start();
- }
- @Override
- protected void initData() {
- mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
- // gpsLocationManager = GPSLocationManager.getInstances(FactoryOperatorActivity.this);
- }
- //记录ProgressBar的完成进度
- private int status = 0; //进度条进度
- private int hasDate = 0;//每次快进多少
- //创建一个负责更新进度的Handler
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- //表明消息是由该程序发送的
- if (msg.what == 0x111) {
- readpb.setProgress(status);
- if (status == 100) {
- loadDiago.dismiss();
- }
- }
- }
- };
- @Override
- public void onNewIntent(Intent intent) {
- readNfcTag(intent);
- Log.e("***", textRecord);
- if (textRecord != null) {
- hasDate = 0;
- status = 0;
- soundPoolHelper.play("nuliduquzhong", false);
- loadDiago = new BaseDialogFragment.Builder(FactoryOperatorActivity.this)
- .setContentView(R.layout.progressreader)
- .setAnimStyle(BaseDialog.AnimStyle.SCALE)
- //.setText(id, "我是预设置的文本")
- .addOnShowListener(new BaseDialog.OnShowListener() {
- @Override
- public void onShow(BaseDialog dialog) {
- //toast("Dialog 显示了");
- }
- })
- .addOnCancelListener(new BaseDialog.OnCancelListener() {
- @Override
- public void onCancel(BaseDialog dialog) {
- //toast("Dialog 取消了");
- }
- })
- .addOnDismissListener(new BaseDialog.OnDismissListener() {
- @Override
- public void onDismiss(BaseDialog dialog) {
- //进度条走完 进行加载
- if (textRecord.length() > 94) {
- if (SPUtils.contains("LOCATION")) {
- Log.e("LOCATION", SPUtils.get("LOCATION", "").toString());
- String location[] = SPUtils.get("LOCATION", "").toString().split(",");
- if (location.length > 1) {
- Double latitude = Double.parseDouble(location[0]);
- Double longitude = Double.parseDouble(location[1]);
- String chipNumber = textRecord.substring(6, chipNumberEndIndex);
- getPresenter().forFactoryOperator(chipNumber, textRecord, longitude, latitude);
- } else {
- toast("位置信息错误");
- }
- } else {
- toast("位置信息获取失败");
- }
- } else {
- toast("读取失败,请重试");
- }
- }
- })
- .show();
- readpb = loadDiago.findViewById(R.id.read_progress);
- //启动线程来执行任务
- new Thread() {
- @Override
- public void run() {
- super.run();
- while (status < 100) {
- //获取耗时操作的完成百分比
- status = doWork();
- //发送消息
- mHandler.sendEmptyMessage(0x111);
- }
- }
- }.start();
- }
- }
- //进行进度条加载
- private int doWork() {
- //为元素赋值
- hasDate += 10;
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return hasDate;
- }
- private SoundPoolHelper soundPoolHelper;
- @Override
- public void uploadChipError(String msg) {
- if (msg.equals("芯片不存在")) {
- soundPoolHelper.play("shujukumeiyouxinpianid", false);
- }else if (msg.equals("芯片记录已保存") || msg.equals("芯片已使用")) {
- soundPoolHelper.play("xinpianidyicunzai", false);
- }else{
- soundPoolHelper.play("factory_operator_error", false);
- }
- toast(msg);
- }
- @Override
- public void uploadChipSuccess(VnDetailBean data) {
- soundPoolHelper.play("factory_operator_success", false);
- toast("读取成功");
- Log.e("FactoryOperatorActivity", data.getCode() + "");
- }
- /**
- * 读取NFC标签文本数据
- */
- private void readNfcTag(Intent intent) {
- if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
- Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
- NfcAdapter.EXTRA_NDEF_MESSAGES);
- NdefMessage msgs[] = null;
- int contentSize = 0;
- if (rawMsgs != null) {
- msgs = new NdefMessage[rawMsgs.length];
- for (int i = 0; i < rawMsgs.length; i++) {
- msgs[i] = (NdefMessage) rawMsgs[i];
- contentSize += msgs[i].toByteArray().length;
- }
- }
- try {
- if (msgs != null) {
- NdefRecord record = msgs[0].getRecords()[0];
- textRecord = parseTextRecord(record);
- // mTagText += textRecord + "\n\ntext\n" + contentSize + " bytes";
- }
- } catch (Exception e) {
- }
- }
- }
- /**
- * 解析NDEF文本数据
- */
- public static String parseTextRecord(NdefRecord ndefRecord) {
- /**
- * 判断数据是否为NDEF格式
- */
- //判断TNF
- if (ndefRecord.getTnf() != NdefRecord.TNF_WELL_KNOWN) {
- return null;
- }
- //判断可变的长度的类型
- if (!Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
- return null;
- }
- try {
- byte[] bArray = ndefRecord.getPayload();
- StringBuffer sb = new StringBuffer(bArray.length);
- String sTemp;
- for (int i = 0; i < bArray.length; i++) {
- sTemp = Integer.toHexString(0xFF & bArray[i]);
- if (sTemp.length() < 2)
- sb.append(0);
- sb.append(sTemp.toUpperCase());
- }
- return sb.toString();
- } catch (Exception e) {
- throw new IllegalArgumentException();
- }
- }
- @Override
- protected void onStart() {
- super.onStart();
- }
- @Override
- protected void onStop() {
- super.onStop();
- //终止定位
- // gpsLocationManager.stop();
- }
- @Override
- protected void onDestroy() {
- animation.cancel();
- alp.cancel();
- mHandler.removeCallbacksAndMessages(true);
- super.onDestroy();
- }
- @Override
- public void onBackPressed() {
- if (DoubleClickHelper.isOnDoubleClick()) {
- //移动到上一个任务栈,避免侧滑引起的不良反应
- moveTaskToBack(false);
- postDelayed(new Runnable() {
- @Override
- public void run() {
- // 进行内存优化,销毁掉所有的界面
- ActivityStackManager.getInstance().finishAllActivities();
- // 销毁进程
- System.exit(0);
- }
- }, 300);
- } else {
- toast(getResources().getString(R.string.home_exit_hint));
- }
- }
- @Override
- public boolean isSupportSwipeBack() {
- // 不使用侧滑功能
- return false;
- }
- }
|