| | |
| | | package safeluck.drive.evaluation.fragment; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Color; |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.os.Bundle; |
| | | import android.text.SpannableString; |
| | | import android.text.Spanned; |
| | | import android.text.style.AbsoluteSizeSpan; |
| | | import android.text.style.ForegroundColorSpan; |
| | | import android.util.Log; |
| | | import android.util.TypedValue; |
| | | import android.view.Gravity; |
| | |
| | | |
| | | import com.anyun.exam.lib.AYSdk; |
| | | import com.anyun.basecommonlib.MyLog; |
| | | import com.google.gson.Gson; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.Constant; |
| | | import safeluck.drive.evaluation.DB.gps.GPSInfo; |
| | | import safeluck.drive.evaluation.DB.gps.GpsInfoViewModel; |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfig; |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel; |
| | | import safeluck.drive.evaluation.MainActivity; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.adapter.BaseDataInfoAdapter; |
| | | import safeluck.drive.evaluation.adapter.GpsInfoAdapter; |
| | | import safeluck.drive.evaluation.bean.BaseDataUIBean; |
| | | import safeluck.drive.evaluation.bean.ExamPlatformData; |
| | | import safeluck.drive.evaluation.bean.RTKInfoBean; |
| | | import safeluck.drive.evaluation.cEventCenter.CEventCenter; |
| | | import safeluck.drive.evaluation.cEventCenter.ICEventListener; |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | |
| | | /** |
| | |
| | | private static final String TAG = "GpsInfoFragment"; |
| | | |
| | | private ListView lv; |
| | | private GpsInfoAdapter gpsInfoAdapter; |
| | | private List<String> gpsinfos = new ArrayList<>(); |
| | | |
| | | private BaseDataInfoAdapter gpsInfoAdapter; |
| | | private Gson gson = new Gson(); |
| | | private SpannableString spannableString; |
| | | private List<BaseDataUIBean> datas = new ArrayList<>(); |
| | | |
| | | public static SupportFragment newInstance() { |
| | | return new GpsInfoFragment(); |
| | |
| | | |
| | | View view = inflater.inflate(R.layout.layout_gps_info, container, false); |
| | | initView(view); |
| | | GpsInfoViewModel gpsInfoViewModel = ViewModelProviders.of(this).get(GpsInfoViewModel.class); |
| | | gpsInfoViewModel.getGpsInfo().observe(this, new Observer<GPSInfo>() { |
| | | @Override |
| | | public void onChanged(GPSInfo gpsInfo) { |
| | | if (gpsInfo != null) { |
| | | MyLog.i(TAG, "gpsinfo=" + gpsInfo == null ? "null" : gpsInfo.toString()); |
| | | gpsinfos.clear(); |
| | | Field[] fields = gpsInfo.getClass().getDeclaredFields(); |
| | | for (int i = 0; i < fields.length; i++) { |
| | | //设置是否允许访问,不是修改原来的访问权限修饰词。 |
| | | fields[i].setAccessible(true); |
| | | try { |
| | | if (fields[i].getName().equalsIgnoreCase("id")) { |
| | | continue; |
| | | } |
| | | gpsinfos.add(fields[i].getName() + ":" + fields[i].get(gpsInfo)); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | gpsInfoAdapter.addAll(gpsinfos); |
| | | }else{ |
| | | MyLog.i(TAG,"未检测到GPS数据库信息"); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | return view; |
| | | } |
| | | |
| | | private void initView(View view) { |
| | | Log.i(TAG,"currTopFragment="+getTopFragment().getClass().getSimpleName()); |
| | | if (HomeFragment.class.getSimpleName().equals(getTopFragment().getClass().getSimpleName())){ |
| | | ((MainActivity)_mActivity).viewtitle.setVisibility(View.GONE); |
| | | ((MainActivity)_mActivity).btn_return.setVisibility(View.GONE); |
| | | }else{ |
| | | ((MainActivity)_mActivity).viewtitle.setVisibility(View.VISIBLE); |
| | | ((MainActivity)_mActivity).btn_return.setVisibility(View.VISIBLE); |
| | | Log.i(TAG,"currTopFragment visible="+getTopFragment().getClass().getSimpleName()); |
| | | } |
| | | lv = view.findViewById(R.id.lv_gpsinfo); |
| | | gpsInfoAdapter = new GpsInfoAdapter(_mActivity); |
| | | gpsInfoAdapter = new BaseDataInfoAdapter(_mActivity); |
| | | lv.setAdapter(gpsInfoAdapter); |
| | | |
| | | lv.setDivider(new ColorDrawable(Color.parseColor("#2A344B"))); |
| | | lv.setDividerHeight(1); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onAttach(@NonNull Context context) { |
| | | super.onAttach(context); |
| | | CEventCenter.onBindEvent(true,icEventListener1, Constant.BIND_RTK_INFO_MAP); |
| | | } |
| | | private String lastRtkinfoStr = ""; |
| | | private ICEventListener icEventListener1 = new ICEventListener() { |
| | | @Override |
| | | public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { |
| | | if (msgCode == Constant.RTK_INFO){ |
| | | String str = (String)obj; |
| | | |
| | | if (!str.equalsIgnoreCase(lastRtkinfoStr)){ |
| | | RTKInfoBean rtkInfoBean = gson.fromJson(str, RTKInfoBean.class); |
| | | |
| | | if (rtkInfoBean != null){ |
| | | Field[] fields = rtkInfoBean.getClass().getDeclaredFields(); |
| | | |
| | | datas.clear(); |
| | | for (int i = 0; i < fields.length; i++) { |
| | | fields[i].setAccessible(true); |
| | | try { |
| | | String fieldName= fields[i].getName(); |
| | | datas.add(new BaseDataUIBean(str2SpannableString(fieldName),R.mipmap.conn_status,str2FouregourdSpannableString(fields[i].get(rtkInfoBean)+""),"",1,null)); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | lv.post(()->{ |
| | | gpsInfoAdapter.addAll(datas); |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | public void onDetach() { |
| | | super.onDetach(); |
| | | CEventCenter.onBindEvent(false,icEventListener1,Constant.BIND_RTK_INFO_MAP); |
| | | } |
| | | |
| | | private SpannableString str2SpannableString(String str) { |
| | | spannableString = new SpannableString(str); |
| | | spannableString.setSpan(new AbsoluteSizeSpan(22),0,str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#A8AAA7")),0,str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return spannableString; |
| | | } |
| | | private SpannableString str2FouregourdSpannableString(String s) { |
| | | spannableString = new SpannableString(s); |
| | | spannableString.setSpan(new AbsoluteSizeSpan(28),0,s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFFFF")),0,s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return spannableString; |
| | | } |
| | | } |