加入Facebook的Steho方便调试;使用Type 和JsonReader转化json文件为对象;使用TcpFragment页面调试数据库
6个文件已修改
58 ■■■■■ 已修改文件
app/build.gradle 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/DB/SeedDatabaseWorker.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/DB/Student.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/app.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/TcpFragment.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/layout_tcpclient.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/build.gradle
@@ -54,4 +54,5 @@
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(path: ':lib')
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.facebook.stetho:stetho:1.5.0'
}
app/src/main/java/safeluck/drive/evaluation/DB/SeedDatabaseWorker.java
@@ -16,6 +16,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -42,9 +43,11 @@
            InputStream inputStream = getApplicationContext().getAssets().open("students_file.json");
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            JsonReader jsonReader = new JsonReader(inputStreamReader);
            jsonReader.beginObject();
            Gson gson = new Gson();
           List<Student> mstus=gson.fromJson(jsonReader,Student.class);
            Type type = new TypeToken<List<Student>>(){}.getType();
           List<Student> mstus=gson.fromJson(jsonReader,   type);
           WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getstudentDao().insertAll(mstus);
        } catch (IOException e) {
            e.printStackTrace();
app/src/main/java/safeluck/drive/evaluation/DB/Student.java
@@ -16,7 +16,7 @@
    @PrimaryKey
    @NonNull
    @ColumnInfo(name = "stu_id")
    private long stu_ID;
    private long stu_id;
    @NonNull
    @ColumnInfo(name = "name")
@@ -24,26 +24,33 @@
    //身份证
    @ColumnInfo(name = "ID")
    private String mID;
    private String ID;
    //性别 0-男 1-女
    @ColumnInfo(name = "sex")
    private int sex;
    public long getStu_ID() {
        return stu_ID;
    public Student(long stu_id, @NonNull String name, String ID, int sex) {
        this.stu_id = stu_id;
        this.name = name;
        this.ID = ID;
        this.sex = sex;
    }
    public void setStu_ID(long stu_ID) {
        this.stu_ID = stu_ID;
    public long getStu_id() {
        return stu_id;
    }
    public void setStu_id(long stu_ID) {
        this.stu_id = stu_ID;
    }
    public String getID() {
        return mID;
        return ID;
    }
    public void setID(String mID) {
        this.mID = mID;
        this.ID = mID;
    }
    public int getSex() {
@@ -66,9 +73,9 @@
    @Override
    public String toString() {
        return "Student{" +
                "stu_ID=" + stu_ID +
                "stu_ID=" + stu_id +
                ", name='" + name + '\'' +
                ", mID='" + mID + '\'' +
                ", ID='" + ID + '\'' +
                ", sex=" + sex +
                '}';
    }
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -13,8 +13,8 @@
import me.yokeyword.fragmentation.helper.ExceptionHandler;
import com.anyun.exam.lib.MyLog;
import com.anyun.exam.lib.crash.CrashHandler;
import com.facebook.stetho.Stetho;
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
import safeluck.drive.evaluation.util.SystemUtil;
/**
@@ -49,7 +49,7 @@
            AYSdk.getInstance().registListener(this);
            Log.i(TAG, "onCreate: ");
            MyLog.createIfNotExist();
            Stetho.initializeWithDefaults(this);
        }
    }
app/src/main/java/safeluck/drive/evaluation/fragment/TcpFragment.java
@@ -41,6 +41,7 @@
    private Button btn_send;
    private      ConnectThread connectThread;
    private AppCompatEditText sendEditText;
    private         WokViewModel workViewModel;
    public static TcpFragment newInstance() {
        return new TcpFragment();
@@ -51,7 +52,7 @@
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_tcpclient, container, false);
        initView(view);
        WokViewModel workViewModel =ViewModelProviders.of(this).get(WokViewModel.class);
        workViewModel =ViewModelProviders.of(this).get(WokViewModel.class);
        workViewModel.getStudents().observe((LifecycleOwner) this, new Observer<List<Student>>() {
            @Override
@@ -87,10 +88,12 @@
                break;
            case R.id.btn_send:
                if (connectThread != null){
                    connectThread.sendMessage(sendEditText.getText().toString().trim());
                    sendEditText.getText().clear();
                }
//                if (connectThread != null){
////                    connectThread.sendMessage(sendEditText.getText().toString().trim());
////                    sendEditText.getText().clear();
////                }
                workViewModel.insertStudent(new Student(1002,"王五","500107198910124566",1));
                break;
        }
    }
app/src/main/res/layout/layout_tcpclient.xml
@@ -16,7 +16,7 @@
        android:layout_height="wrap_content"
        android:text="服务器IP地址:"/>
    <android.support.design.widget.TextInputEditText
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/input_ip"
@@ -34,7 +34,7 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="服务器端口号::"/>
    <android.support.design.widget.TextInputEditText
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/input_port"
@@ -47,7 +47,7 @@
        android:layout_height="wrap_content"
        android:id="@+id/btn_connect"
        android:text="连接"/>
    <android.support.v7.widget.AppCompatEditText
    <androidx.appcompat.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sendtxt"/>