From fb299a7bbbf2ab85ef9765143d4e1f37fe32feba Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期一, 06 一月 2020 11:26:28 +0800
Subject: [PATCH] AYSdk ,IAYExamInterface,SvrManager添加at_sendCmd(String)

---
 app/src/main/res/layout/layout_train_exit.xml                                  |    3 +
 app/src/main/java/safeluck/drive/evaluation/app.java                           |    2 +
 lib/src/main/java/com/anyun/exam/lib/SvrManager.java                           |   10 +++++
 app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java        |   32 ++++++++++++++++
 app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java |   17 ++++++++
 5 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/app.java b/app/src/main/java/safeluck/drive/evaluation/app.java
index 8187146..6d194ad 100644
--- a/app/src/main/java/safeluck/drive/evaluation/app.java
+++ b/app/src/main/java/safeluck/drive/evaluation/app.java
@@ -15,6 +15,7 @@
 import com.anyun.exam.lib.crash.CrashHandler;
 import com.facebook.stetho.Stetho;
 
+import safeluck.drive.evaluation.cEventCenter.CEventCenter;
 import safeluck.drive.evaluation.util.SystemUtil;
 
 /**
@@ -70,6 +71,7 @@
     @Override
     public void callBackMsg(String json) {
         MyLog.d(TAG, "鏀跺埌==" + json);
+        CEventCenter.dispatchEvent("train",0,0,json);
     }
 
 
diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
index bbb0ad3..6b9695e 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
@@ -5,11 +5,14 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
 import android.widget.ListView;
 
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+
+import com.anyun.exam.lib.AYSdk;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -26,9 +29,10 @@
  * 閭锛�632393724@qq.com
  * All Rights Saved! Chongqing AnYun Tech co. LTD
  */
-public class NetWorkTrainFragment extends SupportFragment {
+public class NetWorkTrainFragment extends SupportFragment implements View.OnClickListener {
 
     private ListView mListView ;
+    private Button btn_start_exam;
     private ScoreAdapter mScoreAdapter;
 
     private List<ScoreBean> mArrayList = new ArrayList<>();
@@ -49,6 +53,8 @@
         mListView = view.findViewById(R.id.lv);
         mScoreAdapter = new ScoreAdapter(_mActivity);
         mListView.setAdapter(mScoreAdapter);
+        btn_start_exam = view.findViewById(R.id.btn_start);
+        btn_start_exam.setOnClickListener(this);
         mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null));
         mArrayList.add(new ScoreBean(12,"鐩磋杞集","鍚庤疆鑳庡帇绾�"));
         mArrayList.add(new ScoreBean(100,"鍊掕溅鍏ュ簱","鏈郴瀹夊叏甯�"));
@@ -59,4 +65,13 @@
         mScoreAdapter.addDatas(mArrayList);
 
     }
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()){
+            case R.id.btn_start:
+                AYSdk.getInstance().at_sendCmd("AT+BEGIN_EXAM:0\r\n");
+                break;
+        }
+    }
 }
diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
index d2a793d..518cb39 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
@@ -1,5 +1,6 @@
 package safeluck.drive.evaluation.fragment;
 
+import android.content.Context;
 import android.os.Bundle;
 
 import androidx.annotation.NonNull;
@@ -11,10 +12,12 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
 import android.widget.ListView;
 import android.widget.Toast;
 
 import java.util.ArrayList;
+import java.util.EventListener;
 import java.util.List;
 
 import me.yokeyword.fragmentation.SupportFragment;
@@ -26,6 +29,8 @@
 import safeluck.drive.evaluation.R;
 import safeluck.drive.evaluation.adapter.ScoreAdapter;
 import safeluck.drive.evaluation.bean.ScoreBean;
+import safeluck.drive.evaluation.cEventCenter.CEventCenter;
+import safeluck.drive.evaluation.cEventCenter.ICEventListener;
 
 /**鍗曟満璁粌UI
  * MyApplication2
@@ -37,12 +42,31 @@
 
     private static final String TAG = TrainFragment.class.getSimpleName();
     private ListView mListView ;
+    private Button btn_train;
     private ScoreAdapter mScoreAdapter;
 
     private int item_id;
 
     private List<ScoreBean> mArrayList = new ArrayList<>();
 
+    private ICEventListener eventListener =new ICEventListener() {
+        @Override
+        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
+            Log.i(TAG, "onCEvent: "+(String)obj);
+        }
+    };
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        CEventCenter.onBindEvent(true, eventListener,"train");
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        CEventCenter.onBindEvent(false,eventListener,"train");
+    }
 
     public static SupportFragment newInstance(){
         return new TrainFragment();
@@ -83,10 +107,15 @@
         return view;
     }
     private void initView(View view) {
+
         mListView = view.findViewById(R.id.lv);
         view.findViewById(R.id.view_map).setOnClickListener(this);
+        btn_train = view.findViewById(R.id.btn_start);
+        btn_train.setOnClickListener(this);
+        btn_train.setText("寮�濮嬭缁�");
         mScoreAdapter = new ScoreAdapter(_mActivity);
         mListView.setAdapter(mScoreAdapter);
+
         mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null));
         mArrayList.add(new ScoreBean(12,"鐩磋杞集","鍚庤疆鑳庡帇绾�"));
         mArrayList.add(new ScoreBean(100,"鍊掕溅鍏ュ簱","鏈郴瀹夊叏甯�"));
@@ -107,6 +136,9 @@
                     start(passwordFragment);
                 }
                 break;
+            case R.id.btn_start:
+                Toast.makeText(_mActivity, "寮�濮嬪方瀵�", Toast.LENGTH_SHORT).show();
+                break;
         }
     }
 }
diff --git a/app/src/main/res/layout/layout_train_exit.xml b/app/src/main/res/layout/layout_train_exit.xml
index 00ed465..2405699 100644
--- a/app/src/main/res/layout/layout_train_exit.xml
+++ b/app/src/main/res/layout/layout_train_exit.xml
@@ -23,6 +23,7 @@
         android:textSize="20sp"
         android:layout_below="@+id/btn_return"
         android:padding="10dp"
+        android:id="@+id/btn_start"
         android:textColor="@android:color/white"
-        android:text="寮�濮嬭缁�"/>
+        android:text="寮�濮嬭�冭瘯"/>
 </RelativeLayout>
diff --git a/lib/src/main/java/com/anyun/exam/lib/SvrManager.java b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
index 128fff3..8335ad4 100644
--- a/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
+++ b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
@@ -69,6 +69,16 @@
         }
     }
 
+    public void at_sendCmd(String s) {
+        if (!checkRemoteIsNull()){
+//            try {
+//                remoteInterface.at_sendCmd(s);
+//            } catch (RemoteException e) {
+//                e.printStackTrace();
+//            }
+        }
+    }
+
     class MyServiceConn implements ServiceConnection {
         @Override
         public void onServiceConnected(ComponentName name, IBinder service) {

--
Gitblit v1.8.0