app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -54,4 +54,5 @@ public static final String VEHICLE = "vehiclemodel.json"; public static final String BIND_RTKCONFIG_TOPIC = "rtkconfig_topic"; public static final String BIND_CONNECT_RTK_TOPIC = "rtk_connect_login_topic"; } app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -36,6 +36,8 @@ import safeluck.drive.evaluation.util.PermissionManager; import safeluck.drive.evaluation.viewmodels.MainViewModel; import safeluck.drive.evaluation.viewmodels.RTKConnAndLogin; import safeluck.drive.evaluation.viewmodels.RTKConnAndLoginViewModel; public class MainActivity extends SupportActivity { @@ -46,7 +48,8 @@ private RTKConfig mRTKConfig;//RTK配置信息 private Gson gson = new Gson(); String[] PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA}; RTKConnAndLoginViewModel rtkConnAndLoginViewModel; RTKConnAndLogin rtkConnAndLogin; private ICEventListener icEventListener = new ICEventListener() { @Override @@ -70,6 +73,32 @@ }else{ MyLog.d(TAG,"RTKConfig未取到数据"); } } if (msgCode == Constant.RTK_PLATFORM_CONNECT_STATUS||msgCode== Constant.RTK_PLATFORM_REGISTER_RESULT){ if (msgCode == Constant.RTK_PLATFORM_REGISTER_RESULT){ try { JSONObject jsonObject3 = new JSONObject((String) obj); int loginCode = jsonObject3.getInt("login_code"); MyLog.d(TAG,"RTK平台登录结果:"+loginCode); rtkConnAndLogin.setLogin_code(loginCode); } catch (JSONException e) { e.printStackTrace(); } }else{ try { JSONObject jsonObject3 = new JSONObject((String) obj); int connect_status = jsonObject3.getInt("connected"); MyLog.i(TAG,"RTK平台连接状态:"+connect_status); rtkConnAndLogin.setLogin_code(connect_status); } catch (JSONException e) { e.printStackTrace(); } } rtkConnAndLoginViewModel.getRtkConnAndLogin().postValue(rtkConnAndLogin); } } }; @@ -100,6 +129,9 @@ mRTKConfig = rtkConfig; } }); rtkConnAndLoginViewModel= ViewModelProviders.of(this).get(RTKConnAndLoginViewModel.class); rtkConnAndLogin = new RTKConnAndLogin(); mPermissionsManager = new PermissionManager(this) { @@ -147,7 +179,8 @@ loadRootFragment(R.id.fl_container,HomeFragment.newInstance()); } CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTKCONFIG_TOPIC); CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTKCONFIG_TOPIC);//发送rtk配置消息 CEventCenter.onBindEvent(true,icEventListener, Constant.BIND_CONNECT_RTK_TOPIC);//收到rtk连接 登录结果 } @@ -155,6 +188,8 @@ protected void onDestroy() { super.onDestroy(); CEventCenter.onBindEvent(false,icEventListener,Constant.BIND_RTKCONFIG_TOPIC); CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_CONNECT_RTK_TOPIC); Log.i(TAG, "onDestroy: "); } app/src/main/java/safeluck/drive/evaluation/adapter/SimpleFragmentAdapter.java
@@ -21,7 +21,7 @@ * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class SimpleFragmentAdapter extends FragmentPagerAdapter { private String[] mTitles = new String[]{"基础数据","RTK配置","驾校信息","GPS信息"}; private String[] mTitles = new String[]{"基础数据","RTK配置","GPS信息"}; public SimpleFragmentAdapter(FragmentManager fm) { super(fm); } @@ -38,11 +38,11 @@ supportFragment = RTKConfigFragment.newInstance(); //ftp break; // case 2: // supportFragment = JiaXiaoFragment.newInstance(); // //驾校信息 // break; case 2: supportFragment = JiaXiaoFragment.newInstance(); //驾校信息 break; case 3: supportFragment = GpsInfoFragment.newInstance(); break; default:break; app/src/main/java/safeluck/drive/evaluation/app.java
@@ -120,12 +120,7 @@ case Constant.RTK_PLATFORM_REGISTER_RESULT: //RTK平台登录结果 try { JSONObject jsonObject = new JSONObject(json); int rtklogincode = jsonObject.getInt("login_code"); } catch (JSONException e) { e.printStackTrace(); } CEventCenter.dispatchEvent(Constant.BIND_CONNECT_RTK_TOPIC,cmd,0,json); break; @@ -150,20 +145,8 @@ failedProjRepository.deleteAll(); break; case Constant.RTK_PLATFORM_CONNECT_STATUS: rtkConfig = rtkWorkRepository.getRTKConfigNoLive(); try { JSONObject jsonObject3 = new JSONObject(json); String ip = jsonObject3.getString("ip"); int port = jsonObject3.getInt("port"); int reg_code = jsonObject3.getInt("connected"); rtkConfig.setRegistered(reg_code); rtkConfig.setIp(ip); rtkConfig.setPort(port); } catch (JSONException e) { e.printStackTrace(); } rtkWorkRepository.insertRTKConfig(rtkConfig); CEventCenter.dispatchEvent(Constant.BIND_CONNECT_RTK_TOPIC,cmd,0,json); break; case Constant.FETCH_MAP_INFO: app/src/main/java/safeluck/drive/evaluation/fragment/BaseSettingFragment.java
@@ -59,7 +59,7 @@ tabLayout.addTab(tabLayout.newTab()); tabLayout.addTab(tabLayout.newTab()); tabLayout.addTab(tabLayout.newTab()); tabLayout.addTab(tabLayout.newTab()); // tabLayout.addTab(tabLayout.newTab()); tb = view.findViewById(R.id.toolbar); tb.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); tb.setNavigationOnClickListener(new View.OnClickListener() { app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java
@@ -99,13 +99,18 @@ break; case R.id.system_setting: //打开输入密码界面 PasswordFragment passwordFragment = findFragment(PasswordFragment.class); if (passwordFragment == null) { passwordFragment = (PasswordFragment) PasswordFragment.newInstance(); start(passwordFragment); } else { start(passwordFragment); // PasswordFragment passwordFragment = findFragment(PasswordFragment.class); // if (passwordFragment == null) { // passwordFragment = (PasswordFragment) PasswordFragment.newInstance(); // start(passwordFragment); // } else { // start(passwordFragment); // } BaseSettingFragment sysSetingFragment = findFragment(BaseSettingFragment.class); if (sysSetingFragment == null) { sysSetingFragment = (BaseSettingFragment) BaseSettingFragment.newInstance(); } startWithPop(sysSetingFragment); break; } app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
@@ -101,7 +101,7 @@ } private void sendRTKConfig2RemoteService() { MyLog.d(TAG,"主动推送RTKConfig"); CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.PUSH_RTK_PLATFORM_INFO,0,""); CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.FETCH_RTK_PLATFORM_INFO,0,""); } @Override public void onClick(View v) { app/src/main/java/safeluck/drive/evaluation/fragment/RTKConfigFragment.java
@@ -1,5 +1,6 @@ package safeluck.drive.evaluation.fragment; import android.content.Context; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,13 +12,20 @@ import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.TextView; import com.anyun.exam.lib.MyLog; import com.google.gson.Gson; import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.Constant; import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel; import safeluck.drive.evaluation.R; import safeluck.drive.evaluation.DB.rtktb.RTKConfig; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.viewmodels.RTKConnAndLogin; import safeluck.drive.evaluation.viewmodels.RTKConnAndLoginViewModel; /**FTP配置UI * MyApplication2 @@ -30,6 +38,8 @@ private static final String TAG = "RTKConfigFragment"; private EditText et_ip,et_port,et_city_id,et_city_province,et_phone; // RTK注册状态、RTK连接状态、 private TextView tv_reg,tv_connect,tv_model,tv_sn,tv_imei,tv_login; private RTKConfigViewModel rtkConfigViewModel; private RTKConfig mRtkConfig; @@ -55,8 +65,25 @@ et_city_province.setText(String.valueOf(rtkConfig.getProvince())); et_port.setText(String.valueOf(rtkConfig.getPort())); et_phone.setText(rtkConfig.getPhone()); tv_sn.setText(getResources().getString(R.string.rtk_config_sn,rtkConfig.getSn())); tv_model.setText(getResources().getString(R.string.rtk_config_model,rtkConfig.getModel())); tv_imei.setText(getResources().getString(R.string.rtk_config_imei,rtkConfig.getImei())); tv_reg.setText(getResources().getString(R.string.rtk_register_status,rtkConfig.getRegistered())); } }); RTKConnAndLoginViewModel rtkConnAndLoginViewModel = ViewModelProviders.of(this).get(RTKConnAndLoginViewModel.class); rtkConnAndLoginViewModel.getRtkConnAndLogin().observe(this, new Observer<RTKConnAndLogin>() { @Override public void onChanged(RTKConnAndLogin rtkConnAndLogin) { MyLog.i(TAG,"平台登录结果及连接状态"+rtkConnAndLogin.toString()); tv_connect.setText(getResources().getString(R.string.rtk_connect_status,rtkConnAndLogin.getConnect_status())); tv_connect.setText(getResources().getString(R.string.rtk_config_login,rtkConnAndLogin.getLogin_code())); } }); return view; } @@ -67,6 +94,13 @@ et_city_province = view.findViewById(R.id.et_provice_id); et_phone = view.findViewById(R.id.et_phone); et_port = view.findViewById(R.id.rtk_addr_port); tv_connect = view.findViewById(R.id.tv_rtk_connect);//RTK平台连接状态 tv_imei = view.findViewById(R.id.tv_rtk_imei); tv_login = view.findViewById(R.id.tv_rtk_login);//RTK平台登录结果 tv_model = view.findViewById(R.id.tv_rtk_model); tv_reg = view.findViewById(R.id.tv_rtk_reg);//RTK平台注册状态 tv_sn = view.findViewById(R.id.tv_rtk_sn); } @Override @@ -84,4 +118,17 @@ break; } } @Override public void onAttach(Context context) { super.onAttach(context); } @Override public void onDetach() { super.onDetach(); } } app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
@@ -119,7 +119,7 @@ private void sendRTKConfig2RemoteService() { MyLog.d(TAG,"主动推送RTKConfig"); CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.PUSH_RTK_PLATFORM_INFO,0,""); CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.FETCH_RTK_PLATFORM_INFO,0,""); } @Override app/src/main/java/safeluck/drive/evaluation/viewmodels/RTKConnAndLogin.java
New file @@ -0,0 +1,32 @@ package safeluck.drive.evaluation.viewmodels; import androidx.annotation.NonNull; public class RTKConnAndLogin { private int login_code = 1;//RTK平台登录结果 0-成功 其他失败 private int connect_status;//RTK平台连接状态 public int getLogin_code() { return login_code; } public void setLogin_code(int login_code) { this.login_code = login_code; } public int getConnect_status() { return connect_status; } public void setConnect_status(int connect_status) { this.connect_status = connect_status; } @Override public String toString() { return "RTKConnAndLogin{" + "login_code=" + login_code + ", connect_status=" + connect_status + '}'; } } app/src/main/java/safeluck/drive/evaluation/viewmodels/RTKConnAndLoginViewModel.java
New file @@ -0,0 +1,15 @@ package safeluck.drive.evaluation.viewmodels; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; public class RTKConnAndLoginViewModel extends ViewModel { private MutableLiveData<RTKConnAndLogin> rtkConnAndLogin; public MutableLiveData<RTKConnAndLogin> getRtkConnAndLogin(){ if (rtkConnAndLogin == null){ rtkConnAndLogin = new MutableLiveData<>(); } return rtkConnAndLogin; } } app/src/main/res/layout/layout_rtk_setting.xml
@@ -98,6 +98,73 @@ android:layout_marginBottom="10dp" android:background="@color/colorAccent" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_reg" android:text="@string/rtk_register_status" android:layout_weight="1"/> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_connect" android:text="@string/rtk_connect_status" android:layout_weight="1"/> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_imei" android:text="@string/rtk_config_imei" android:layout_weight="1"/> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:background="@color/colorAccent" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_login" android:text="@string/rtk_config_login" android:layout_weight="1"/> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_model" android:text="@string/rtk_config_model" android:layout_weight="1"/> <TextView android:textColor="@android:color/black" android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tv_rtk_sn" android:text="@string/rtk_config_sn" android:layout_weight="1"/> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:background="@color/colorAccent" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" app/src/main/res/values/strings.xml
@@ -18,4 +18,10 @@ <string name="request_permission">This sample needs camera permission.</string> <string name="camera_error">This device doesn\'t support Camera2 API.</string> <string name="rtk_addr_des">RTK平台地址:</string> <string name="rtk_register_status">RTK注册状态:%1$d</string> <string name="rtk_config_imei">IMEI:%1$s</string> <string name="rtk_config_model">Model:%1$s</string> <string name="rtk_config_sn">SN:%1$s</string> <string name="rtk_connect_status">RTK连接状态:%1$d</string> <string name="rtk_config_login">RTK登录结果:%1$d</string> </resources>