| | |
| | | package safeluck.drive.evaluation.fragment; |
| | | |
| | | import android.content.Intent; |
| | | import android.net.Uri; |
| | | import android.os.Bundle; |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.lifecycle.ViewModelProviders; |
| | | |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | |
| | | import com.anyun.exam.lib.util.ByteUtil; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.charset.Charset; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | |
| | | import safeluck.drive.evaluation.MainActivity; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.bean.ExamPlatformData; |
| | | import safeluck.drive.evaluation.util.CThreadPoolExecutor; |
| | | import safeluck.drive.evaluation.util.FileUtil; |
| | | import safeluck.drive.evaluation.viewmodels.ExamPlatformModel; |
| | | |
| | | /** |
| | | * 基础数据设置 |
| | |
| | | public class BaseDatasFragment extends SupportFragment implements View.OnClickListener { |
| | | |
| | | private static final String TAG = BaseDatasFragment.class.getSimpleName(); |
| | | private static final int REQUEST_CODE_MAP = 100; |
| | | private static final int REQUEST_CODE_CAR = 101; |
| | | private int request_code = REQUEST_CODE_MAP; |
| | | private Button btn_inspect_signal; |
| | | private Button btn_config_signal; |
| | | private Button btn_mcu_upgrade; |
| | | private Button btn_mcu_upgrade,btn_map_select; |
| | | private EditText et_ip,et_port; |
| | | // private ExamPlatformModel examPlatformModel; |
| | | public static SupportFragment newInstance() { |
| | | return new BaseDatasFragment(); |
| | | } |
| | |
| | | |
| | | View view = inflater.inflate(R.layout.layout_base_datas, container, false); |
| | | initView(view); |
| | | // examPlatformModel = ViewModelProviders.of(this).get(ExamPlatformModel.class); |
| | | return view; |
| | | } |
| | | |
| | |
| | | et_port.setText(ExamPlatformData.getInstance().getPlatformPort()+""); |
| | | btn_inspect_signal = view.findViewById(R.id.btn_inpsect_signal); |
| | | btn_mcu_upgrade = view.findViewById(R.id.btn_mcu_upgrade); |
| | | btn_map_select = view.findViewById(R.id.btn_map_select); |
| | | view.findViewById(R.id.btn_car_select).setOnClickListener(this); |
| | | btn_mcu_upgrade.setOnClickListener(this); |
| | | btn_map_select.setOnClickListener(this); |
| | | btn_inspect_signal.setOnClickListener(this); |
| | | btn_config_signal = view.findViewById(R.id.btn_signal_conf); |
| | | btn_config_signal.setOnClickListener(this); |
| | |
| | | ExamPlatformData.getInstance().insertPlatformPort(Integer.parseInt(et_port.getText().toString().trim())); |
| | | } |
| | | break; |
| | | case R.id.btn_car_select://车辆模型和地图公用一套代码 区别在于REQUEST_CODE |
| | | request_code = REQUEST_CODE_CAR; |
| | | openFileMgr(); |
| | | break; |
| | | case R.id.btn_map_select: |
| | | request_code = REQUEST_CODE_MAP; |
| | | openFileMgr(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void openFileMgr() { |
| | | Intent intent = new Intent(); |
| | | intent.setAction(Intent.ACTION_GET_CONTENT); |
| | | intent.setType("*/*"); |
| | | intent.addCategory(Intent.CATEGORY_OPENABLE); |
| | | try { |
| | | startActivityForResult(intent, request_code); |
| | | } catch (android.content.ActivityNotFoundException e) { |
| | | e.printStackTrace(); |
| | | Toast.makeText(_mActivity, "请安装文件管理器", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | if (REQUEST_CODE_MAP == requestCode){ |
| | | final Uri uri= data.getData(); |
| | | Log.i(TAG, "onActivityResult: "+uri.getPath()); |
| | | ExamPlatformData.getInstance().setNewMapPath(uri.getPath()); |
| | | CThreadPoolExecutor.runInBackground(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | byte[] fileContent = FileUtil.readFile(uri.getPath()); |
| | | if (fileContent != null){ |
| | | String str = new String(fileContent); |
| | | Log.i(TAG, "文件内容:"+str); |
| | | AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,str); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | }else if (requestCode == REQUEST_CODE_CAR){ |
| | | final Uri uri= data.getData(); |
| | | Log.i(TAG, "onActivityResult: "+uri.getPath()); |
| | | ExamPlatformData.getInstance().setCarModelPath(uri.getPath()); |
| | | CThreadPoolExecutor.runInBackground(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | byte[] fileContent = FileUtil.readFile(uri.getPath()); |
| | | if (fileContent != null){ |
| | | String str = new String(fileContent); |
| | | Log.i(TAG, "文件内容:"+str); |
| | | AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,str); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | } |