加入Facebook的Steho方便调试;使用Type 和JsonReader转化json文件为对象;使用TcpFragment页面调试数据库
| | |
| | | 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' |
| | | } |
| | |
| | | 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; |
| | |
| | | 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(); |
| | |
| | | @PrimaryKey |
| | | @NonNull |
| | | @ColumnInfo(name = "stu_id") |
| | | private long stu_ID; |
| | | private long stu_id; |
| | | |
| | | @NonNull |
| | | @ColumnInfo(name = "name") |
| | |
| | | |
| | | //身份证 |
| | | @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() { |
| | |
| | | @Override |
| | | public String toString() { |
| | | return "Student{" + |
| | | "stu_ID=" + stu_ID + |
| | | "stu_ID=" + stu_id + |
| | | ", name='" + name + '\'' + |
| | | ", mID='" + mID + '\'' + |
| | | ", ID='" + ID + '\'' + |
| | | ", sex=" + sex + |
| | | '}'; |
| | | } |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | AYSdk.getInstance().registListener(this); |
| | | Log.i(TAG, "onCreate: "); |
| | | MyLog.createIfNotExist(); |
| | | |
| | | Stetho.initializeWithDefaults(this); |
| | | } |
| | | |
| | | } |
| | |
| | | private Button btn_send; |
| | | private ConnectThread connectThread; |
| | | private AppCompatEditText sendEditText; |
| | | private WokViewModel workViewModel; |
| | | |
| | | public static TcpFragment newInstance() { |
| | | return new TcpFragment(); |
| | |
| | | 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 |
| | |
| | | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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" |
| | |
| | | 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" |
| | |
| | | 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"/> |