Compare View

switch
from
...
to
 
Commits (5)
1 apply plugin: 'com.android.application' 1 apply plugin: 'com.android.application'
2 2
3 3
4 def androidId = rootProject.ext.androidId 4 def androidId = rootProject.ext.androidId
5 def support = rootProject.ext.dependencies 5 def support = rootProject.ext.dependencies
6 def url = rootProject.ext.url 6 def url = rootProject.ext.url
7 7
8 8
9 android { 9 android {
10 signingConfigs { 10 signingConfigs {
11 11
12 config { 12 config {
13 keyAlias 'alias' 13 keyAlias 'alias'
14 keyPassword '123456' 14 keyPassword '123456'
15 storeFile file('key.jks') 15 storeFile file('key.jks')
16 storePassword '123456' 16 storePassword '123456'
17 } 17 }
18 debug { 18 debug {
19 } 19 }
20 } 20 }
21 compileSdk 32 21 compileSdk 32
22 22
23 defaultConfig { 23 defaultConfig {
24 applicationId "com.hjx.parent" 24 applicationId "com.hjx.parent"
25 minSdk 26 25 minSdk 26
26 targetSdk 32 26 targetSdk 32
27 versionCode 1009 27 versionCode 1010
28 versionName "1.0.09" 28 versionName "1.0.10"
29 29
30 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 30 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31 } 31 }
32 32
33 android.applicationVariants.all { 33 android.applicationVariants.all {
34 variant -> 34 variant ->
35 variant.outputs.all { 35 variant.outputs.all {
36 //在这里修改apk文件名 36 //在这里修改apk文件名
37 outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" 37 outputFileName = "parent-${variant.name}-v${variant.versionName}.apk"
38 } 38 }
39 } 39 }
40 buildTypes { 40 buildTypes {
41 debug { 41 debug {
42 debuggable true 42 debuggable true
43 minifyEnabled false 43 minifyEnabled false
44 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 44 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
45 signingConfig signingConfigs.config 45 signingConfig signingConfigs.config
46 } 46 }
47 release { 47 release {
48 debuggable true 48 debuggable true
49 minifyEnabled false 49 minifyEnabled false
50 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 50 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
51 signingConfig signingConfigs.config 51 signingConfig signingConfigs.config
52 } 52 }
53 } 53 }
54 lintOptions { 54 lintOptions {
55 checkReleaseBuilds false 55 checkReleaseBuilds false
56 abortOnError false 56 abortOnError false
57 } 57 }
58 buildFeatures { 58 buildFeatures {
59 viewBinding true 59 viewBinding true
60 dataBinding true 60 dataBinding true
61 } 61 }
62 compileOptions { 62 compileOptions {
63 sourceCompatibility JavaVersion.VERSION_1_8 63 sourceCompatibility JavaVersion.VERSION_1_8
64 targetCompatibility JavaVersion.VERSION_1_8 64 targetCompatibility JavaVersion.VERSION_1_8
65 } 65 }
66 } 66 }
67 67
68 dependencies { 68 dependencies {
69 support.each { k, v -> implementation v } 69 support.each { k, v -> implementation v }
70 api project(path: ':libs:common') 70 api project(path: ':libs:common')
71 implementation 'androidx.appcompat:appcompat:1.5.1' 71 implementation 'androidx.appcompat:appcompat:1.5.1'
72 implementation 'com.google.android.material:material:1.6.1' 72 implementation 'com.google.android.material:material:1.6.1'
73 implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 73 implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
74 implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' 74 implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50'
75 implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' 75 implementation 'com.github.ForgetAll:LoadingDialog:1.1.2'
76 implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' 76 implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0'
77 //使用的三方 77 //使用的三方
78 implementation 'com.yalantis:ucrop:2.2.0' 78 implementation 'com.yalantis:ucrop:2.2.0'
79 implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' 79 implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0'
80 implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' 80 implementation 'com.github.DL-ZhangTeng:Utils:2.2.0'
81 81
82 // rx 82 // rx
83 implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") 83 implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2")
84 implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") 84 implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2")
85 85
86 implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") 86 implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
87 implementation("com.contrarywind:Android-PickerView:4.1.9") 87 implementation("com.contrarywind:Android-PickerView:4.1.9")
88 88
89 implementation 'com.google.android:flexbox:1.0.0' 89 implementation 'com.google.android:flexbox:1.0.0'
90 90
91 // 沉浸式状态栏和他的Kotlin拓展 91 // 沉浸式状态栏和他的Kotlin拓展
92 implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' 92 implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
93 implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' 93 implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
94 94
95 // 图片查看 95 // 图片查看
96 implementation 'com.github.chrisbanes:PhotoView:2.0.0' 96 implementation 'com.github.chrisbanes:PhotoView:2.0.0'
97 97
98 implementation 'com.jakewharton:butterknife:10.2.3' 98 implementation 'com.jakewharton:butterknife:10.2.3'
99 annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' 99 annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
100 } 100 }
app/src/main/java/com/hjx/parent/HomeworkDetailActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.widget.ImageView; 6 import android.widget.ImageView;
7 import android.widget.TextView; 7 import android.widget.TextView;
8 8
9 import androidx.annotation.NonNull; 9 import androidx.annotation.NonNull;
10 import androidx.annotation.Nullable; 10 import androidx.annotation.Nullable;
11 11
12 import com.bumptech.glide.Glide; 12 import com.bumptech.glide.Glide;
13 import com.chad.library.adapter.base.BaseQuickAdapter; 13 import com.chad.library.adapter.base.BaseQuickAdapter;
14 import com.chad.library.adapter.base.BaseViewHolder; 14 import com.chad.library.adapter.base.BaseViewHolder;
15 import com.hjx.parent.databinding.ActivityHomeworkDetailBinding; 15 import com.hjx.parent.databinding.ActivityHomeworkDetailBinding;
16 import com.hjx.parent.dialog.EditHomeworkDialog; 16 import com.hjx.parent.dialog.EditHomeworkDialog;
17 import com.hjx.parent.dialog.MsgConfirmDialog; 17 import com.hjx.parent.dialog.MsgConfirmDialog;
18 import com.hjx.parent.rx.BaseRxActivity; 18 import com.hjx.parent.rx.BaseRxActivity;
19 import com.prws.common.bean.ResponseResult; 19 import com.prws.common.bean.ResponseResult;
20 import com.prws.common.bean.Student; 20 import com.prws.common.bean.Student;
21 import com.prws.common.bean.homework.HomeWork; 21 import com.prws.common.bean.homework.HomeWork;
22 import com.prws.common.bean.homework.HomeworkList; 22 import com.prws.common.bean.homework.HomeworkList;
23 import com.prws.common.net.NetWorks; 23 import com.prws.common.net.NetWorks;
24 24
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 import java.util.HashMap; 26 import java.util.HashMap;
27 import java.util.Map; 27 import java.util.Map;
28 28
29 public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> { 29 public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> {
30 30
31 private HomeworkList mData; 31 private HomeworkList mData;
32 private Student student; 32 private Student student;
33 33
34 private Adapter mAdapter = new Adapter(); 34 private Adapter mAdapter = new Adapter();
35 private EditHomeworkDialog mDialog; 35 private EditHomeworkDialog mDialog;
36 private MsgConfirmDialog noAnalyseDialog; 36 private MsgConfirmDialog noAnalyseDialog;
37 37
38 @Override 38 @Override
39 public void initView(Bundle savedInstanceState) { 39 public void initView(Bundle savedInstanceState) {
40 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); 40 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());
41 mData = (HomeworkList) getIntent().getSerializableExtra("data"); 41 mData = (HomeworkList) getIntent().getSerializableExtra("data");
42 student = (Student) getIntent().getSerializableExtra("student"); 42 student = (Student) getIntent().getSerializableExtra("student");
43 mDialog = new EditHomeworkDialog(this, mData); 43 mDialog = new EditHomeworkDialog(this, mData);
44 noAnalyseDialog = new MsgConfirmDialog.Builder(this) 44 noAnalyseDialog = new MsgConfirmDialog.Builder(this)
45 .setNegative("").setPositive("好的") 45 .setNegative("").setPositive("好的")
46 .setMessage("尚未完成解析制作,\n请先去好记星平板端制作解析").build(); 46 .setMessage("尚未完成解析制作,\n请先去好记星平板端制作解析").build();
47 binding.tvTitle.setText(mData.getName()); 47 binding.tvTitle.setText(mData.getName());
48 48
49 binding.recyclerView.setAdapter(mAdapter); 49 binding.recyclerView.setAdapter(mAdapter);
50 getDetail(); 50 getDetail();
51 51
52 binding.btnFeedback.setOnClickListener(v -> { 52 binding.btnFeedback.setOnClickListener(v -> {
53 if (mAdapter.getData().size() == 0) return; 53 if (mAdapter.getData().size() == 0) return;
54 // if (mData.getCompleteFlag() == 0) { 54 // if (mData.getCompleteFlag() == 0) {
55 // noAnalyseDialog.show(); 55 // noAnalyseDialog.show();
56 // return; 56 // return;
57 // } 57 // }
58 Intent intent = new Intent(this, HomeworkSelectActivity.class); 58 Intent intent = new Intent(this, HomeworkSelectActivity.class);
59 intent.putExtra("data", mData); 59 intent.putExtra("data", mData);
60 intent.putExtra("student", student); 60 intent.putExtra("student", student);
61 intent.putExtra("list", new ArrayList<>(mAdapter.getData())); 61 intent.putExtra("list", new ArrayList<>(mAdapter.getData()));
62 startActivityForResult(intent, 0xA01); 62 startActivityForResult(intent, 0xA01);
63 }); 63 });
64 binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> { 64 binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> {
65 edit(data); 65 edit(data);
66 })); 66 }));
67 } 67 }
68 68
69 @Override 69 @Override
70 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 70 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
71 super.onActivityResult(requestCode, resultCode, data); 71 super.onActivityResult(requestCode, resultCode, data);
72 if (requestCode == 0xA01 && resultCode == RESULT_OK) { 72 if (requestCode == 0xA01 && resultCode == RESULT_OK) {
73 finish(); 73 finish();
74 } 74 }
75 } 75 }
76 76
77 @SuppressLint("CheckResult") 77 @SuppressLint("CheckResult")
78 private void getDetail() { 78 private void getDetail() {
79 NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId()) 79 NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId())
80 .compose(transformSingle()) 80 .compose(transformSingle())
81 .map(ResponseResult::getData) 81 .map(ResponseResult::getData)
82 .subscribe((list, th) -> { 82 .subscribe((list, th) -> {
83 if (th != null) th.printStackTrace(); 83 if (th != null) th.printStackTrace();
84 mAdapter.setNewData(list); 84 mAdapter.setNewData(list);
85 }); 85 });
86 } 86 }
87 87
88 @SuppressLint("CheckResult") 88 @SuppressLint("CheckResult")
89 private void edit(HomeworkList data) { 89 private void edit(HomeworkList data) {
90 Map<String, Object> body = new HashMap<>(); 90 Map<String, Object> body = new HashMap<>();
91 body.put("homeworkId", data.getId()); 91 body.put("homeworkId", data.getId());
92 body.put("name", data.getName()); 92 body.put("name", data.getName());
93 body.put("grade", data.getGrade()); 93 body.put("grade", data.getGrade());
94 body.put("subject", data.getSubject()); 94 body.put("subject", data.getSubject());
95 body.put("term", data.getTerm()); 95 body.put("term", data.getTerm());
96 body.put("uploadTime", data.uploadTime); 96 body.put("uploadTime", data.uploadTime);
97 body.put("stuId", student.stuId); 97 body.put("stuId", student.stuId);
98 showLoadingDialog("请稍等···"); 98 showLoadingDialog("请稍等···");
99 NetWorks.service_url.editHomework(NetWorks.getHeader(), body) 99 NetWorks.service_url.editHomework(NetWorks.getHeader(), body)
100 .compose(transformSingle()) 100 .compose(transformSingle())
101 .subscribe((response, th) -> { 101 .subscribe((response, th) -> {
102 if (th != null) th.printStackTrace(); 102 if (th != null) th.printStackTrace();
103 if (response != null && response.getSuccess()) { 103 if (response != null && response.getSuccess()) {
104 cancelLoadingDialog(); 104 cancelLoadingDialog();
105 binding.tvTitle.setText(data.getName()); 105 binding.tvTitle.setText(data.getName());
106 } else { 106 } else {
107 loadFail(response == null ? "" : response.getMsg()); 107 loadFail(response == null ? "" : response.getMsg());
108 } 108 }
109 }); 109 });
110 } 110 }
111 111
112 @Override 112 @Override
113 protected ActivityHomeworkDetailBinding getViewBinding() { 113 protected ActivityHomeworkDetailBinding getViewBinding() {
114 return ActivityHomeworkDetailBinding.inflate(getLayoutInflater()); 114 return ActivityHomeworkDetailBinding.inflate(getLayoutInflater());
115 } 115 }
116 116
117 static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 117 static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
118 118
119 public Adapter() { 119 public Adapter() {
120 super(R.layout.item_homework_detail); 120 super(R.layout.item_homework_detail);
121 } 121 }
122 122
123 @SuppressLint("SetTextI18n") 123 @SuppressLint("SetTextI18n")
124 @Override 124 @Override
125 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 125 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
126 TextView tvNumber = holder.getView(R.id.tvNumber); 126 TextView tvNumber = holder.getView(R.id.tvNumber);
127 ImageView imageView = holder.getView(R.id.ivTopic); 127 ImageView imageView = holder.getView(R.id.ivTopic);
128 int number = getData().indexOf(homeWork) + 1; 128 int number = getData().indexOf(homeWork) + 1;
129 tvNumber.setText("第" + number + "题"); 129 tvNumber.setText("第" + number + "题");
130 Glide.with(mContext).load(homeWork.url).into(imageView); 130 Glide.with(mContext).load(homeWork.url).into(imageView);
131 131
132 holder.itemView.setOnClickListener(v -> { 132 holder.itemView.setOnClickListener(v -> {
133 Intent intent = new Intent(mContext, HomeworkTopicActivity.class); 133 Intent intent = new Intent(mContext, HomeworkTopicActivity.class);
134 intent.putExtra("position", getData().indexOf(homeWork)); 134 intent.putExtra("position", getData().indexOf(homeWork));
135 intent.putExtra("list", new ArrayList<>(getData())); 135 intent.putExtra("list", new ArrayList<>(getData()));
136 mContext.startActivity(intent); 136 mContext.startActivity(intent);
137 }); 137 });
138 } 138 }
139 } 139 }
140 } 140 }
141 141
app/src/main/java/com/hjx/parent/HomeworkFeedbackActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.view.View; 6 import android.view.View;
7 import android.widget.ImageView; 7 import android.widget.ImageView;
8 import android.widget.RadioButton; 8 import android.widget.RadioButton;
9 import android.widget.Toast; 9 import android.widget.Toast;
10 10
11 import androidx.annotation.NonNull; 11 import androidx.annotation.NonNull;
12 import androidx.annotation.Nullable; 12 import androidx.annotation.Nullable;
13 13
14 import com.bumptech.glide.Glide; 14 import com.bumptech.glide.Glide;
15 import com.chad.library.adapter.base.BaseQuickAdapter; 15 import com.chad.library.adapter.base.BaseQuickAdapter;
16 import com.chad.library.adapter.base.BaseViewHolder; 16 import com.chad.library.adapter.base.BaseViewHolder;
17 import com.google.android.flexbox.FlexboxLayoutManager; 17 import com.google.android.flexbox.FlexboxLayoutManager;
18 import com.google.gson.Gson; 18 import com.google.gson.Gson;
19 import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; 19 import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding;
20 import com.hjx.parent.rx.BaseRxActivity; 20 import com.hjx.parent.rx.BaseRxActivity;
21 import com.prws.common.bean.Student; 21 import com.prws.common.bean.Student;
22 import com.prws.common.bean.homework.Correction; 22 import com.prws.common.bean.homework.Correction;
23 import com.prws.common.bean.homework.CorrectionPoint; 23 import com.prws.common.bean.homework.CorrectionPoint;
24 import com.prws.common.bean.homework.CorrectionSer;
24 import com.prws.common.bean.homework.CorrectionSer; 25 import com.prws.common.bean.homework.HomeWork;
25 import com.prws.common.bean.homework.HomeWork; 26 import com.prws.common.bean.homework.HomeworkList;
26 import com.prws.common.bean.homework.HomeworkList; 27 import com.prws.common.bean.homework.KeyValue;
27 import com.prws.common.bean.homework.KeyValue; 28 import com.prws.common.net.NetWorks;
28 import com.prws.common.net.NetWorks; 29
29 30 import java.text.DecimalFormat;
30 import java.text.DecimalFormat; 31 import java.text.SimpleDateFormat;
31 import java.text.SimpleDateFormat; 32 import java.util.ArrayList;
32 import java.util.ArrayList; 33 import java.util.HashMap;
33 import java.util.HashMap; 34 import java.util.HashSet;
34 import java.util.HashSet; 35 import java.util.List;
35 import java.util.List; 36 import java.util.Locale;
36 import java.util.Locale; 37 import java.util.Map;
37 import java.util.Map; 38 import java.util.Set;
38 import java.util.Set; 39
39 40 public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> {
40 public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { 41 private Student student;
41 private Student student; 42 private HomeworkList mData;
42 private HomeworkList mData; 43 private ArrayList<HomeWork> mList;
43 private ArrayList<HomeWork> mList; 44 private List<Correction> corrections = new ArrayList<>();
44 private List<Correction> corrections = new ArrayList<>(); 45
45 46 @SuppressWarnings("unchecked")
46 @SuppressWarnings("unchecked") 47 @Override
47 @Override 48 public void initView(Bundle savedInstanceState) {
48 public void initView(Bundle savedInstanceState) { 49 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());
49 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); 50 student = (Student) getIntent().getSerializableExtra("student");
50 student = (Student) getIntent().getSerializableExtra("student"); 51 mData = (HomeworkList) getIntent().getSerializableExtra("data");
51 mData = (HomeworkList) getIntent().getSerializableExtra("data"); 52 mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list");
52 mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); 53
53 54 binding.tvStuName.setText(student.stuName);
54 binding.tvStuName.setText(student.stuName); 55 binding.tvGrade.setText(student.grade);
55 binding.tvGrade.setText(student.grade); 56
56 57 List<HomeWork> errorList = new ArrayList<>();
57 List<HomeWork> errorList = new ArrayList<>(); 58 int correctNo = 0;
58 int correctNo = 0; 59 for (HomeWork homeWork: mList) {
59 for (HomeWork homeWork: mList) { 60 homeWork.state = 1;
60 homeWork.state = 1; 61 homeWork.index = mList.indexOf(homeWork);
61 homeWork.index = mList.indexOf(homeWork); 62 corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0));
62 corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0)); 63 if (!homeWork.check) correctNo ++;
63 if (!homeWork.check) correctNo ++; 64 else errorList.add(homeWork);
64 else errorList.add(homeWork); 65 }
65 } 66 binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size()));
66 binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size())); 67
67 68 binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this));
68 binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); 69 NumberAdapter numberAdapter = new NumberAdapter(mList);
69 NumberAdapter numberAdapter = new NumberAdapter(mList); 70 binding.rvCorrect.setAdapter(numberAdapter);
70 binding.rvCorrect.setAdapter(numberAdapter); 71 binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE);
71 binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); 72 binding.rvError.setAdapter(new EvalAdapter(errorList));
72 binding.rvError.setAdapter(new EvalAdapter(errorList)); 73 if (errorList.isEmpty()) {
73 if (errorList.isEmpty()) { 74 binding.flEval.setVisibility(View.GONE);
74 binding.flEval.setVisibility(View.GONE); 75 }
75 } 76
76 77 binding.btnDetail.setOnClickListener(v -> {
77 binding.btnDetail.setOnClickListener(v -> { 78 viewTopicDetail(0);
78 viewTopicDetail(0); 79 });
79 }); 80 numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> {
80 numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { 81 viewTopicDetail(i);
81 viewTopicDetail(i); 82 });
82 }); 83 binding.btnPublish.setOnClickListener(v -> submit());
83 binding.btnPublish.setOnClickListener(v -> submit()); 84 }
84 } 85
85 86 private void viewTopicDetail(int position) {
86 private void viewTopicDetail(int position) { 87 Intent intent = new Intent(this, HomeworkTopicActivity.class);
87 Intent intent = new Intent(this, HomeworkTopicActivity.class); 88 intent.putExtra("list", mList);
88 intent.putExtra("list", mList); 89 intent.putExtra("position", position);
89 intent.putExtra("position", position); 90 startActivity(intent);
90 startActivity(intent); 91 }
91 } 92
92 93 @SuppressLint("CheckResult")
93 @SuppressLint("CheckResult") 94 private void submit() {
94 private void submit() { 95 Map<String, Object> body = new HashMap<>();
95 Map<String, Object> body = new HashMap<>(); 96 body.put("homeworkId", mData.getId());
96 body.put("homeworkId", mData.getId()); 97 body.put("comment", binding.etComment.getText().toString());
97 body.put("comment", binding.etComment.getText().toString()); 98 body.put("stuId", student.stuId);
98 body.put("stuId", student.stuId); 99 body.put("points", countPoint());
99 body.put("points", countPoint()); 100 body.put("correctionList", corrections);
101 body.put("extra", buildExtra());
100 body.put("correctionList", corrections); 102 NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body)
101 body.put("extra", buildExtra()); 103 .compose(transformSingle())
102 NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) 104 .subscribe((response, th) -> {
103 .compose(transformSingle()) 105 if (th != null) th.printStackTrace();
104 .subscribe((response, th) -> { 106 if (response != null && response.getSuccess()) {
105 if (th != null) th.printStackTrace(); 107 Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show();
106 if (response != null && response.getSuccess()) { 108
107 Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); 109 Intent intent = new Intent(this, HomeworkShareActivity.class);
108 110 intent.putExtra("student", student);
109 Intent intent = new Intent(this, HomeworkShareActivity.class); 111 intent.putExtra("id", mData.getId());
110 intent.putExtra("student", student); 112 intent.putExtra("grade", mData.getGrade());
111 intent.putExtra("id", mData.getId()); 113 intent.putExtra("subject", mData.getSubject());
112 intent.putExtra("grade", mData.getGrade()); 114 String name = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(mData.uploadTime);
113 intent.putExtra("subject", mData.getSubject()); 115 intent.putExtra("name", name);
114 String name = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(mData.uploadTime); 116 startActivity(intent);
115 intent.putExtra("name", name); 117
116 startActivity(intent); 118 setResult(RESULT_OK);
117 119 finish();
118 setResult(RESULT_OK); 120 } else {
119 finish(); 121 Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show();
120 } else { 122 }
121 Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show(); 123 });
122 } 124 }
123 }); 125
126 private String buildExtra() {
127 if (mList == null || mList.isEmpty()) return null;
128 List<CorrectionSer> maps = new ArrayList<>();
129 for (HomeWork item: mList) {
130 maps.add(item.toSer());
131 }
132 Gson gson = new Gson();
133 return gson.toJson(maps);
134 }
135
124 } 136 @SuppressLint("CheckResult")
125 137 private List<CorrectionPoint> countPoint() {
126 private String buildExtra() { 138 Set<KeyValue> set = new HashSet<>();
127 if (mList == null || mList.isEmpty()) return null; 139 Map<String, Integer> totalTimes = new HashMap<>();
128 List<CorrectionSer> maps = new ArrayList<>(); 140 Map<String, Integer> correctTimes = new HashMap<>();
129 for (HomeWork item: mList) { 141 Map<String, Integer> underTimes = new HashMap<>();
130 maps.add(item.toSer()); 142 Map<String, Integer> baseTimes = new HashMap<>();
131 } 143 Map<String, Integer> normalTimes = new HashMap<>();
132 Gson gson = new Gson(); 144 Gson gson = new Gson();
133 return gson.toJson(maps); 145 for (HomeWork homeWork: mList) {
134 } 146 homeWork.formatPoints(gson);
135 147
136 @SuppressLint("CheckResult") 148 set.addAll(homeWork.pointsObj);
137 private List<CorrectionPoint> countPoint() { 149 for (KeyValue keyValue: homeWork.pointsObj) {
138 Set<KeyValue> set = new HashSet<>(); 150 String key = keyValue.Key;
139 Map<String, Integer> totalTimes = new HashMap<>(); 151 if (totalTimes.containsKey(key)) {
140 Map<String, Integer> correctTimes = new HashMap<>(); 152 totalTimes.put(key, totalTimes.get(key) + 1);
141 Map<String, Integer> underTimes = new HashMap<>(); 153 } else {
142 Map<String, Integer> baseTimes = new HashMap<>(); 154 totalTimes.put(key, 1);
143 Map<String, Integer> normalTimes = new HashMap<>(); 155 }
144 Gson gson = new Gson(); 156 if (!homeWork.check) {
145 for (HomeWork homeWork: mList) { 157 if (correctTimes.containsKey(key)) {
146 homeWork.formatPoints(gson); 158 correctTimes.put(key, correctTimes.get(key) + 1);
147 159 } else {
148 set.addAll(homeWork.pointsObj); 160 correctTimes.put(key, 1);
149 for (KeyValue keyValue: homeWork.pointsObj) { 161 }
150 String key = keyValue.Key; 162 } else if (homeWork.state == 1) {
151 if (totalTimes.containsKey(key)) { 163 if (underTimes.containsKey(key)) {
152 totalTimes.put(key, totalTimes.get(key) + 1); 164 underTimes.put(key, underTimes.get(key) + 1);
153 } else { 165 } else {
154 totalTimes.put(key, 1); 166 underTimes.put(key, 1);
155 } 167 }
156 if (!homeWork.check) { 168 } else if (homeWork.state == 2) {
157 if (correctTimes.containsKey(key)) { 169 if (baseTimes.containsKey(key)) {
158 correctTimes.put(key, correctTimes.get(key) + 1); 170 baseTimes.put(key, baseTimes.get(key) + 1);
159 } else { 171 } else {
160 correctTimes.put(key, 1); 172 baseTimes.put(key, 1);
161 } 173 }
162 } else if (homeWork.state == 1) { 174 } else if (homeWork.state == 3) {
163 if (underTimes.containsKey(key)) { 175 if (normalTimes.containsKey(key)) {
164 underTimes.put(key, underTimes.get(key) + 1); 176 normalTimes.put(key, normalTimes.get(key) + 1);
165 } else { 177 } else {
166 underTimes.put(key, 1); 178 normalTimes.put(key, 1);
167 } 179 }
168 } else if (homeWork.state == 2) { 180 }
169 if (baseTimes.containsKey(key)) { 181 }
170 baseTimes.put(key, baseTimes.get(key) + 1); 182 }
171 } else { 183 List<CorrectionPoint> points = new ArrayList<>();
172 baseTimes.put(key, 1); 184 for (KeyValue obj: set) {
173 } 185 CorrectionPoint point = new CorrectionPoint();
174 } else if (homeWork.state == 3) { 186 point.pointId = obj.Key;
175 if (normalTimes.containsKey(key)) { 187 point.pointName = obj.Value;
176 normalTimes.put(key, normalTimes.get(key) + 1); 188 point.totalCount = ifNull(totalTimes.get(obj.Key), 1);
177 } else { 189 point.correctCount = ifNull(correctTimes.get(obj.Key), 0);
178 normalTimes.put(key, 1); 190 point.understandCount = ifNull(underTimes.get(obj.Key), 0);
179 } 191 point.basicCount = ifNull(baseTimes.get(obj.Key), 0);
180 } 192 point.normalCount = ifNull(normalTimes.get(obj.Key), 0);
181 } 193
182 } 194 points.add(point);
183 List<CorrectionPoint> points = new ArrayList<>(); 195 }
184 for (KeyValue obj: set) { 196
185 CorrectionPoint point = new CorrectionPoint(); 197 return points;
186 point.pointId = obj.Key; 198 }
187 point.pointName = obj.Value; 199
188 point.totalCount = ifNull(totalTimes.get(obj.Key), 1); 200 private int ifNull(Integer src, int defaultVal) {
189 point.correctCount = ifNull(correctTimes.get(obj.Key), 0); 201 if (src == null) return defaultVal;
190 point.understandCount = ifNull(underTimes.get(obj.Key), 0); 202 else return src;
191 point.basicCount = ifNull(baseTimes.get(obj.Key), 0); 203 }
192 point.normalCount = ifNull(normalTimes.get(obj.Key), 0); 204
193 205
194 points.add(point); 206 @Override
195 } 207 protected ActivityHomeworkFeedbackBinding getViewBinding() {
196 208 return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater());
197 return points; 209 }
198 } 210
199 211 static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
200 private int ifNull(Integer src, int defaultVal) { 212
201 if (src == null) return defaultVal; 213 public NumberAdapter(List<HomeWork> list) {
202 else return src; 214 super(R.layout.item_feedback_num, list);
203 } 215 }
204 216
205 217 @Override
206 @Override 218 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
207 protected ActivityHomeworkFeedbackBinding getViewBinding() { 219 int position = getData().indexOf(homeWork);
208 return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); 220 holder.setText(R.id.tvNum, String.valueOf(position + 1));
209 } 221 if (homeWork.check) {
210 222 holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small);
211 static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 223 } else {
212 224 holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small);
213 public NumberAdapter(List<HomeWork> list) { 225 }
214 super(R.layout.item_feedback_num, list); 226 }
215 } 227 }
216 228
217 @Override 229 static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
218 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 230
219 int position = getData().indexOf(homeWork); 231 public EvalAdapter(@Nullable List<HomeWork> data) {
220 holder.setText(R.id.tvNum, String.valueOf(position + 1)); 232 super(R.layout.item_homework_eval, data);
221 if (homeWork.check) { 233 }
222 holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); 234
223 } else { 235 @Override
224 holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); 236 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
225 } 237 holder.itemView.setClipToOutline(true);
226 } 238 holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1));
227 } 239 ImageView iv = holder.getView(R.id.ivTopic);
228 240 Glide.with(mContext).load(homeWork.url).into(iv);
229 static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 241
230 242 RadioButton chk1 = holder.getView(R.id.chk1);
231 public EvalAdapter(@Nullable List<HomeWork> data) { 243 RadioButton chk2 = holder.getView(R.id.chk2);
232 super(R.layout.item_homework_eval, data); 244 RadioButton chk3 = holder.getView(R.id.chk3);
233 } 245 chk1.setOnCheckedChangeListener((v, b) -> {
234 246 if (b) {
235 @Override 247 homeWork.state = 1;
236 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 248 }
237 holder.itemView.setClipToOutline(true); 249 });
238 holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); 250 chk2.setOnCheckedChangeListener((v, b) -> {
239 ImageView iv = holder.getView(R.id.ivTopic); 251 if (b) {
240 Glide.with(mContext).load(homeWork.url).into(iv); 252 homeWork.state = 2;
241 253 }
242 RadioButton chk1 = holder.getView(R.id.chk1); 254 });
243 RadioButton chk2 = holder.getView(R.id.chk2); 255 chk3.setOnCheckedChangeListener((v, b) -> {
244 RadioButton chk3 = holder.getView(R.id.chk3); 256 if (b) {
245 chk1.setOnCheckedChangeListener((v, b) -> { 257 homeWork.state = 3;
246 if (b) { 258 }
247 homeWork.state = 1; 259 });
248 } 260 chk1.setChecked(homeWork.state == 1);
249 }); 261 chk2.setChecked(homeWork.state == 2);
250 chk2.setOnCheckedChangeListener((v, b) -> { 262 chk3.setChecked(homeWork.state == 3);
251 if (b) { 263 }
252 homeWork.state = 2; 264 }
253 } 265 }
254 }); 266
app/src/main/java/com/hjx/parent/LoginActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.content.Intent; 3 import android.content.Intent;
4 import android.os.Bundle; 4 import android.os.Bundle;
5 import android.telephony.PhoneNumberUtils; 5 import android.telephony.PhoneNumberUtils;
6 import android.text.InputType; 6 import android.text.InputType;
7 import android.text.TextUtils; 7 import android.text.TextUtils;
8 import android.text.method.HideReturnsTransformationMethod; 8 import android.text.method.HideReturnsTransformationMethod;
9 import android.text.method.PasswordTransformationMethod; 9 import android.text.method.PasswordTransformationMethod;
10 import android.widget.Button; 10 import android.widget.Button;
11 import android.widget.CheckBox; 11 import android.widget.CheckBox;
12 import android.widget.EditText; 12 import android.widget.EditText;
13 import android.widget.ImageView; 13 import android.widget.ImageView;
14 import android.widget.TextView; 14 import android.widget.TextView;
15 import android.widget.Toast; 15 import android.widget.Toast;
16 16
17 import androidx.appcompat.app.AppCompatActivity; 17 import androidx.appcompat.app.AppCompatActivity;
18 18
19 import com.prws.common.base.BaseActivity; 19 import com.prws.common.base.BaseActivity;
20 import com.prws.common.base.BasePresenter; 20 import com.prws.common.base.BasePresenter;
21 import com.prws.common.bean.BaseEntity; 21 import com.prws.common.bean.BaseEntity;
22 import com.prws.common.net.NetWorks; 22 import com.prws.common.net.NetWorks;
23 import com.prws.common.utils.LogUtil; 23 import com.prws.common.utils.LogUtil;
24 import com.prws.common.utils.SharedPreferencesUtil; 24 import com.prws.common.utils.SharedPreferencesUtil;
25 import com.prws.common.utils.acmanager.ActivityManager; 25 import com.prws.common.utils.acmanager.ActivityManager;
26 26
27 import org.json.JSONObject; 27 import org.json.JSONObject;
28 28
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.util.HashMap; 30 import java.util.HashMap;
31 import java.util.Map; 31 import java.util.Map;
32 32
33 import io.reactivex.Observer; 33 import io.reactivex.Observer;
34 import io.reactivex.disposables.Disposable; 34 import io.reactivex.disposables.Disposable;
35 import okhttp3.ResponseBody; 35 import okhttp3.ResponseBody;
36 36
37 37
38 public class LoginActivity extends BaseActivity { 38 public class LoginActivity extends BaseActivity {
39 39
40 40
41 EditText et_phone; 41 EditText et_phone;
42 EditText et_pwd; 42 EditText et_pwd;
43 ImageView iv_show; 43 ImageView iv_show;
44 ImageView iv_delete; 44 ImageView iv_delete;
45 Button btn_login; 45 Button btn_login;
46 46
47 47
48 @Override 48 @Override
49 protected int layoutResId() { 49 protected int layoutResId() {
50 return R.layout.activity_login; 50 return R.layout.activity_login;
51 } 51 }
52 52
53 @Override 53 @Override
54 public Object getContract() { 54 public Object getContract() {
55 return null; 55 return null;
56 } 56 }
57 57
58 @Override 58 @Override
59 public BasePresenter getPresenter() { 59 public BasePresenter getPresenter() {
60 return null; 60 return null;
61 } 61 }
62 62
63 63
64 @Override 64 @Override
65 protected void initView() { 65 protected void initView() {
66 et_phone = findViewById(R.id.et_phone); 66 et_phone = findViewById(R.id.et_phone);
67 et_pwd = findViewById(R.id.et_pwd); 67 et_pwd = findViewById(R.id.et_pwd);
68 iv_show = findViewById(R.id.iv_4); 68 iv_show = findViewById(R.id.iv_4);
69 iv_delete = findViewById(R.id.iv_2); 69 iv_delete = findViewById(R.id.iv_2);
70 btn_login = findViewById(R.id.btn_1); 70 btn_login = findViewById(R.id.btn_1);
71 71
72 String student = (String) SharedPreferencesUtil.getData("student", ""); 72 String student = (String) SharedPreferencesUtil.getData("student", "");
73 73
74 if (!TextUtils.isEmpty(student)) { 74 if (!TextUtils.isEmpty(student)) {
75 LogUtil.e(TAG, "role 不是空----"); 75 LogUtil.e(TAG, "role 不是空----");
76 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { 76 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) {
77 Intent intent = new Intent(this, MainActivity.class); 77 Intent intent = new Intent(this, MainActivity.class);
78 startActivity(intent); 78 startActivity(intent);
79 finish(); 79 finish();
80 } else { 80 } else {
81 Intent intent = new Intent(this, TeacherMainActivity.class); 81 Intent intent = new Intent(this, TeacherMainActivity.class);
82 startActivity(intent); 82 startActivity(intent);
83 finish(); 83 finish();
84 } 84 }
85 return; 85 return;
86 } else { 86 } else {
87 LogUtil.e(TAG, "role 是空----"); 87 LogUtil.e(TAG, "role 是空----");
88 } 88 }
89 89
90 findViewById(R.id.tvBack).setOnClickListener(v -> { 90 findViewById(R.id.tvBack).setOnClickListener(v -> {
91 Intent intent = new Intent(this, SmsLoginActivity.class); 91 Intent intent = new Intent(this, SmsLoginActivity.class);
92 intent.putExtra("fromLogin", true);
93 startActivity(intent);
92 intent.putExtra("fromLogin", true); 94 finish();
93 startActivity(intent); 95 });
94 finish(); 96
95 }); 97 }
96 98
97 } 99 @Override
98 100 protected void initListener() {
99 @Override 101 iv_delete.setOnClickListener(view -> {
100 protected void initListener() { 102 et_phone.setText("");
101 iv_delete.setOnClickListener(view -> { 103 });
102 et_phone.setText(""); 104 iv_show.setOnClickListener(view -> {
103 }); 105 if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) {
104 iv_show.setOnClickListener(view -> { 106 iv_show.setBackgroundResource(R.mipmap.yc);
105 if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { 107 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
106 iv_show.setBackgroundResource(R.mipmap.yc); 108 et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
107 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 109 } else {
108 et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); 110 iv_show.setBackgroundResource(R.mipmap.xs);
109 } else { 111 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
110 iv_show.setBackgroundResource(R.mipmap.xs); 112 et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
111 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 113 }
112 et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); 114 });
113 } 115
114 }); 116
115 117 btn_login.setOnClickListener(view -> {
116 118
117 btn_login.setOnClickListener(view -> { 119 String phone = et_phone.getText().toString().trim();
118 120 String pwd = et_pwd.getText().toString().trim();
119 String phone = et_phone.getText().toString().trim(); 121 if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) {
120 String pwd = et_pwd.getText().toString().trim(); 122 Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show();
121 if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { 123 return;
122 Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); 124 }
123 return; 125
124 } 126 if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) {
125 127 Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show();
126 if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { 128 return;
127 Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); 129 }
128 return; 130
129 } 131 // if (!cb_1.isChecked()) {
130 132 // Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show();
131 // if (!cb_1.isChecked()) { 133 // return;
132 // Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); 134 // }
133 // return; 135
134 // } 136 login(phone, pwd);
135 137
136 login(phone, pwd); 138 });
137 139
138 }); 140 // tv_ys.setOnClickListener(view -> {
139 141 // startActivity(YinsiActivity.class);
140 // tv_ys.setOnClickListener(view -> { 142 // });
141 // startActivity(YinsiActivity.class); 143 // tv_user.setOnClickListener(view -> {
142 // }); 144 // startActivity(UserAgreementActivity.class);
143 // tv_user.setOnClickListener(view -> { 145 // });
144 // startActivity(UserAgreementActivity.class); 146 }
145 // }); 147
146 } 148 public void login(final String phone, String pwd) {
147 149
148 public void login(final String phone, String pwd) { 150 Map map = new HashMap();
149 151 map.put("username", phone);
150 Map map = new HashMap(); 152 map.put("password", pwd);
151 map.put("username", phone); 153
152 map.put("password", pwd); 154
153 155 NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() {
154 156 @Override
155 NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { 157 public void onSubscribe(Disposable d) {
156 @Override 158
157 public void onSubscribe(Disposable d) { 159 }
158 160
159 } 161 @Override
160 162 public void onNext(ResponseBody responseBody) {
161 @Override 163 try {
162 public void onNext(ResponseBody responseBody) { 164 String str = responseBody.string().toString();
163 try { 165 LogUtil.e(TAG, "----" + str);
164 String str = responseBody.string().toString(); 166 JSONObject jo = new JSONObject(str);
165 LogUtil.e(TAG, "----" + str); 167 boolean isSucceed = jo.getBoolean("success");
166 JSONObject jo = new JSONObject(str); 168 if (isSucceed) {
167 boolean isSucceed = jo.getBoolean("success"); 169 JSONObject jo2 = jo.getJSONObject("data");
168 if (isSucceed) { 170 String role = jo2.getString("role");
169 JSONObject jo2 = jo.getJSONObject("data"); 171 if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) {
170 String role = jo2.getString("role"); 172 SharedPreferencesUtil.putData("phone", phone);
171 if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) { 173 SharedPreferencesUtil.putData("role", role);
172 SharedPreferencesUtil.putData("phone", phone); 174 SharedPreferencesUtil.putData("userId", jo2.getString("id"));
173 SharedPreferencesUtil.putData("role", role); 175 SharedPreferencesUtil.putData("token", jo2.getString("token"));
174 SharedPreferencesUtil.putData("userId", jo2.getString("id")); 176 SharedPreferencesUtil.putData("name", jo2.getString("username"));
175 SharedPreferencesUtil.putData("token", jo2.getString("token")); 177 SharedPreferencesUtil.putData("photo", jo2.getString("photo"));
176 SharedPreferencesUtil.putData("name", jo2.getString("username")); 178 startActivity(TeacherChooseActivity.class);
177 SharedPreferencesUtil.putData("photo", jo2.getString("photo")); 179 finish();
178 startActivity(TeacherChooseActivity.class); 180 } else {
179 finish(); 181 showToast("您没有权限");
180 } else { 182 }
181 showToast("您没有权限"); 183
182 } 184 } else {
183 185 Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show();
184 } else { 186 }
185 Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); 187 } catch (Exception e) {
186 } 188 e.printStackTrace();
187 } catch (Exception e) { 189 Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show();
188 e.printStackTrace(); 190 }
189 Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); 191 }
190 } 192
191 } 193 @Override
192 194 public void onError(Throwable e) {
193 @Override 195
194 public void onError(Throwable e) { 196 }
195 197
196 } 198 @Override
197 199 public void onComplete() {
198 @Override 200
199 public void onComplete() { 201 }
200 202 });
201 } 203 }
202 }); 204
203 } 205
204 206 @Override
205 207 protected void initData() {
206 @Override 208
207 protected void initData() { 209 }
208 210
209 } 211 @Override
210 212 public void onNetChanged(int netWorkState) {
211 @Override 213
212 public void onNetChanged(int netWorkState) { 214 }
213 215 }
app/src/main/java/com/hjx/parent/SmsLoginActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.telephony.PhoneNumberUtils; 6 import android.telephony.PhoneNumberUtils;
7 import android.text.TextUtils; 7 import android.text.TextUtils;
8 import android.view.View; 8 import android.view.View;
9 import android.widget.Toast; 9 import android.widget.Toast;
10 10
11 import com.hjx.parent.databinding.ActivitySmsLoginBinding; 11 import com.hjx.parent.databinding.ActivitySmsLoginBinding;
12 import com.hjx.parent.rx.BaseRxActivity; 12 import com.hjx.parent.rx.BaseRxActivity;
13 import com.prws.common.bean.Student; 13 import com.prws.common.bean.Student;
14 import com.prws.common.net.NetWorks; 14 import com.prws.common.net.NetWorks;
15 import com.prws.common.utils.LogUtil; 15 import com.prws.common.utils.LogUtil;
16 import com.prws.common.utils.SharedPreferencesUtil; 16 import com.prws.common.utils.SharedPreferencesUtil;
17 17
18 import java.util.HashMap; 18 import java.util.HashMap;
19 import java.util.List; 19 import java.util.List;
20 import java.util.Map; 20 import java.util.Map;
21 import java.util.concurrent.TimeUnit; 21 import java.util.concurrent.TimeUnit;
22 22
23 import io.reactivex.Observable; 23 import io.reactivex.Observable;
24 import io.reactivex.android.schedulers.AndroidSchedulers; 24 import io.reactivex.android.schedulers.AndroidSchedulers;
25 import io.reactivex.disposables.Disposable; 25 import io.reactivex.disposables.Disposable;
26 26
27 public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> { 27 public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> {
28 private final NetWorks.NetService api = NetWorks.service_url; 28 private final NetWorks.NetService api = NetWorks.service_url;
29 @Override 29 @Override
30 public void initView(Bundle savedInstanceState) { 30 public void initView(Bundle savedInstanceState) {
31 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 31 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
32 32
33 String student = (String) SharedPreferencesUtil.getData("student", ""); 33 String student = (String) SharedPreferencesUtil.getData("student", "");
34 34
35 if (!TextUtils.isEmpty(student)) { 35 if (!TextUtils.isEmpty(student)) {
36 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { 36 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) {
37 Intent intent = new Intent(this, MainActivity.class); 37 Intent intent = new Intent(this, MainActivity.class);
38 startActivity(intent); 38 startActivity(intent);
39 finish(); 39 finish();
40 } else { 40 } else {
41 Intent intent = new Intent(this, TeacherMainActivity.class); 41 Intent intent = new Intent(this, TeacherMainActivity.class);
42 startActivity(intent); 42 startActivity(intent);
43 finish(); 43 finish();
44 } 44 }
45 return; 45 return;
46 } 46 }
47 47
48 binding.tvEntrance.setOnClickListener(v -> { 48 binding.tvEntrance.setOnClickListener(v -> {
49 startActivity(new Intent(this, LoginActivity.class)); 49 startActivity(new Intent(this, LoginActivity.class));
50 finish(); 50 finish();
51 }); 51 });
52 binding.btnGetCode.setOnClickListener(v -> { 52 binding.btnGetCode.setOnClickListener(v -> {
53 String phone = binding.etPhone.getText().toString().trim(); 53 String phone = binding.etPhone.getText().toString().trim();
54 if (phone.isEmpty()) { 54 if (phone.isEmpty()) {
55 showToast("请输入手机号"); 55 showToast("请输入手机号");
56 return; 56 return;
57 } 57 }
58 sendCode(phone); 58 sendCode(phone);
59 }); 59 });
60 binding.btnLogin.setOnClickListener(v -> { 60 binding.btnLogin.setOnClickListener(v -> {
61 61
62 String phone = binding.etPhone.getText().toString().trim(); 62 String phone = binding.etPhone.getText().toString().trim();
63 String code = binding.etCode.getText().toString().trim(); 63 String code = binding.etCode.getText().toString().trim();
64 if (phone.isEmpty() || code.isEmpty()) { 64 if (phone.isEmpty() || code.isEmpty()) {
65 Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show(); 65 Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show();
66 return; 66 return;
67 } 67 }
68 68
69 if (!binding.chkPermission.isChecked()) { 69 if (!binding.chkPermission.isChecked()) {
70 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); 70 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show();
71 return; 71 return;
72 } 72 }
73 login(phone, code); 73 login(phone, code);
74 }); 74 });
75 75
76 binding.tv6.setOnClickListener(view -> { 76 binding.tv6.setOnClickListener(view -> {
77 startActivity(new Intent(this, YinsiActivity.class)); 77 startActivity(new Intent(this, YinsiActivity.class));
78 }); 78 });
79 binding.tv4.setOnClickListener(view -> { 79 binding.tv4.setOnClickListener(view -> {
80 startActivity(new Intent(this, UserAgreementActivity.class)); 80 startActivity(new Intent(this, UserAgreementActivity.class));
81 }); 81 });
82
83 if (!getIntent().getBooleanExtra("fromLogin", false)) {
84 startActivity(new Intent(this, LoginActivity.class));
85 finish();
86 }
82 87 }
83 if (!getIntent().getBooleanExtra("fromLogin", false)) { 88
84 startActivity(new Intent(this, LoginActivity.class)); 89 @SuppressLint("CheckResult")
85 finish(); 90 private void login(String phone, String code) {
86 } 91 binding.btnLogin.setEnabled(false);
87 } 92 Map<String, String> body = new HashMap<>();
88 93 body.put("phone", phone);
89 @SuppressLint("CheckResult") 94 body.put("code", code);
90 private void login(String phone, String code) { 95 api.smsLogin(body)
91 binding.btnLogin.setEnabled(false); 96 .compose(transformSingle())
92 Map<String, String> body = new HashMap<>(); 97 .subscribe((response, th) -> {
93 body.put("phone", phone); 98 binding.btnLogin.setEnabled(true);
94 body.put("code", code); 99 if (handleResponseData(response, th)) {
95 api.smsLogin(body) 100 List<Student> list = response.getData().parentInfoList;
96 .compose(transformSingle()) 101 if (list == null || list.isEmpty()) {
97 .subscribe((response, th) -> { 102 showToast("未注册学生, 无法登录");
98 binding.btnLogin.setEnabled(true); 103 return;
99 if (handleResponseData(response, th)) { 104 }
100 List<Student> list = response.getData().parentInfoList; 105 SharedPreferencesUtil.putData("phone", phone);
101 if (list == null || list.isEmpty()) { 106 SharedPreferencesUtil.putData("role", "parent");
102 showToast("未注册学生, 无法登录"); 107 SharedPreferencesUtil.putData("userId", response.getData().id);
103 return; 108 SharedPreferencesUtil.putData("token", response.getData().token);
104 } 109 SharedPreferencesUtil.putData("name", response.getData().username);
105 SharedPreferencesUtil.putData("phone", phone); 110 startActivity(new Intent(this, ChooseActivity.class));
106 SharedPreferencesUtil.putData("role", "parent"); 111 finish();
107 SharedPreferencesUtil.putData("userId", response.getData().id); 112 }
108 SharedPreferencesUtil.putData("token", response.getData().token); 113 });
109 SharedPreferencesUtil.putData("name", response.getData().username); 114 }
110 startActivity(new Intent(this, ChooseActivity.class)); 115
111 finish(); 116 @SuppressLint({"SetTextI18n", "CheckResult"})
112 } 117 private void sendCode(String phone) {
113 }); 118 binding.btnGetCode.setEnabled(false);
114 } 119 api.smsCode(phone)
115 120 .compose(transformSingle())
116 @SuppressLint({"SetTextI18n", "CheckResult"}) 121 .subscribe((response, th) -> {
117 private void sendCode(String phone) { 122 if (handleResponse(response, th)) {
118 binding.btnGetCode.setEnabled(false); 123 showToast("验证码已发送");
119 api.smsCode(phone) 124 timeDown();
120 .compose(transformSingle()) 125 } else {
121 .subscribe((response, th) -> { 126 if (disposable != null) disposable.dispose();
122 if (handleResponse(response, th)) { 127 binding.btnGetCode.setText("获取验证码");
123 showToast("验证码已发送"); 128 binding.btnGetCode.setEnabled(true);
124 timeDown(); 129 }
125 } else { 130 });
126 if (disposable != null) disposable.dispose(); 131 }
127 binding.btnGetCode.setText("获取验证码"); 132
128 binding.btnGetCode.setEnabled(true); 133 private int timeDown = 0;
129 } 134 private Disposable disposable;
130 }); 135 @SuppressLint("SetTextI18n")
131 } 136 private void timeDown() {
132 137 timeDown = 60;
133 private int timeDown = 0; 138 disposable = Observable
134 private Disposable disposable; 139 .interval(0, 1, TimeUnit.SECONDS)
135 @SuppressLint("SetTextI18n") 140 .observeOn(AndroidSchedulers.mainThread())
136 private void timeDown() { 141 .subscribe(l -> {
137 timeDown = 60; 142 if (--timeDown <= 0) {
138 disposable = Observable 143 if (disposable != null) disposable.dispose();
139 .interval(0, 1, TimeUnit.SECONDS) 144 binding.btnGetCode.setText("获取验证码");
140 .observeOn(AndroidSchedulers.mainThread()) 145 binding.btnGetCode.setEnabled(true);
141 .subscribe(l -> { 146 } else {
142 if (--timeDown <= 0) { 147 binding.btnGetCode.setText("获取验证码(" + timeDown + "s)");
143 if (disposable != null) disposable.dispose(); 148 binding.btnGetCode.setEnabled(false);
144 binding.btnGetCode.setText("获取验证码"); 149 }
145 binding.btnGetCode.setEnabled(true); 150 }, Throwable::printStackTrace);
146 } else { 151 }
147 binding.btnGetCode.setText("获取验证码(" + timeDown + "s)"); 152
148 binding.btnGetCode.setEnabled(false); 153 @Override
149 } 154 protected void onDestroy() {
150 }, Throwable::printStackTrace); 155 super.onDestroy();
151 } 156 if (disposable != null) disposable.dispose();
152 157 }
153 @Override 158
154 protected void onDestroy() { 159 @Override
155 super.onDestroy(); 160 protected ActivitySmsLoginBinding getViewBinding() {
156 if (disposable != null) disposable.dispose(); 161 return ActivitySmsLoginBinding.inflate(getLayoutInflater());
157 } 162 }
158 163 }
159 @Override 164
app/src/main/res/layout/dialog_add_error.xml
1 <androidx.core.widget.NestedScrollView 1 <androidx.core.widget.NestedScrollView
2 xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent"
3 android:layout_width="match_parent" 4 android:layout_height="match_parent">
4 android:layout_height="match_parent"> 5 <LinearLayout
5 <LinearLayout
6 android:layout_width="match_parent"
7 android:layout_height="wrap_content"
8 android:background="@drawable/bg_solid_white_10_top"
9 android:orientation="vertical">
10
11 <RelativeLayout
12 android:layout_width="match_parent"
13 android:layout_height="50dp">
14
15 <TextView
16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content"
18 android:layout_centerInParent="true"
19 android:text="加入错题本"
20 android:textColor="@color/text_title"
21 android:textSize="17sp"
22 android:textStyle="bold" />
23
24 <ImageView
25 android:id="@+id/iv_back"
26 android:layout_width="35dp"
27 android:layout_height="35dp"
28 android:layout_alignParentRight="true"
29 android:layout_centerVertical="true"
30 android:layout_marginRight="10dp"
31 android:padding="10dp"
32 android:src="@mipmap/ic_close" />
33 </RelativeLayout>
34
35 <androidx.recyclerview.widget.RecyclerView
36 android:id="@+id/list_item"
37 android:layout_width="match_parent"
38 android:layout_height="30dp"
39 android:layout_marginLeft="20dp"
40 android:layout_marginTop="10dp" 6 android:layout_width="match_parent"
41 android:layout_marginRight="20dp" /> 7 android:layout_height="wrap_content"
42 8 android:background="@drawable/bg_solid_white_10_top"
43 <RelativeLayout 9 android:orientation="vertical">
44 android:layout_width="match_parent"
45 android:layout_height="90dp" 10
46 android:layout_marginLeft="20dp" 11 <RelativeLayout
47 android:layout_marginTop="20dp" 12 android:layout_width="match_parent"
48 android:layout_marginRight="20dp"> 13 android:layout_height="50dp">
49
50 <RelativeLayout 14
51 android:layout_width="match_parent" 15 <TextView
52 android:layout_height="match_parent"
53 android:background="#F5F5F5"> 16 android:layout_width="wrap_content"
54 17 android:layout_height="wrap_content"
55 <ImageView 18 android:layout_centerInParent="true"
56 android:id="@+id/iv_topic" 19 android:text="加入错题本"
57 android:layout_width="wrap_content" 20 android:textColor="@color/text_title"
58 android:layout_height="wrap_content" 21 android:textSize="17sp"
59 android:layout_centerVertical="true" /> 22 android:textStyle="bold" />
60 </RelativeLayout>
61 </RelativeLayout>
62
63 <TextView
64 android:layout_width="wrap_content"
65 android:layout_height="wrap_content"
66 android:layout_centerVertical="true"
67 android:layout_marginLeft="20dp"
68 android:layout_marginTop="20dp"
69 android:text="年级" 23
70 android:textColor="@color/text_title" 24 <ImageView
71 android:textSize="15sp" 25 android:id="@+id/iv_back"
72 android:textStyle="bold" /> 26 android:layout_width="35dp"
73 27 android:layout_height="35dp"
74 <androidx.appcompat.widget.AppCompatSpinner 28 android:layout_alignParentRight="true"
75 android:id="@+id/spinner_grade" 29 android:layout_centerVertical="true"
76 style="@style/customSpinnerStyle" 30 android:layout_marginRight="10dp"
77 android:layout_width="match_parent" 31 android:padding="10dp"
78 android:layout_height="40dp" 32 android:src="@mipmap/ic_close" />
79 android:layout_centerHorizontal="true" 33 </RelativeLayout>
80 android:layout_marginLeft="20dp"
81 android:layout_marginTop="10dp"
82 android:layout_marginRight="20dp"
83 android:background="@drawable/selector_for_custom_spinner"
84 android:popupBackground="@drawable/shape_for_custom_spinner"
85 android:scrollbars="none" />
86
87 <TextView
88 android:layout_width="wrap_content"
89 android:layout_height="wrap_content"
90 android:layout_centerVertical="true"
91 android:layout_marginLeft="20dp"
92 android:layout_marginTop="20dp"
93 android:text="学期" 34
94 android:textColor="@color/text_title" 35 <androidx.recyclerview.widget.RecyclerView
95 android:textSize="15sp" 36 android:id="@+id/list_item"
96 android:textStyle="bold" /> 37 android:layout_width="match_parent"
97 38 android:layout_height="30dp"
98 <androidx.appcompat.widget.AppCompatSpinner 39 android:layout_marginLeft="20dp"
99 android:id="@+id/spinner_grade1" 40 android:layout_marginTop="10dp"
100 style="@style/customSpinnerStyle" 41 android:layout_marginRight="20dp" />
101 android:layout_width="match_parent"
102 android:layout_height="40dp"
103 android:layout_centerHorizontal="true"
104 android:layout_marginLeft="20dp"
105 android:layout_marginTop="10dp"
106 android:layout_marginRight="20dp"
107 android:background="@drawable/selector_for_custom_spinner" 42
108 android:entries="@array/grade_array" 43 <RelativeLayout
109 android:popupBackground="@drawable/shape_for_custom_spinner" 44 android:layout_width="match_parent"
110 android:scrollbars="none" /> 45 android:layout_height="90dp"
111 46 android:layout_marginLeft="20dp"
112 <TextView 47 android:layout_marginTop="20dp"
113 android:layout_width="wrap_content" 48 android:layout_marginRight="20dp">
114 android:layout_height="wrap_content"
115 android:layout_centerVertical="true"
116 android:layout_marginLeft="20dp"
117 android:layout_marginTop="20dp"
118 android:text="科目" 49
119 android:textColor="@color/text_title" 50 <RelativeLayout
120 android:textSize="15sp" 51 android:layout_width="match_parent"
121 android:textStyle="bold" /> 52 android:layout_height="match_parent"
122 53 android:background="#F5F5F5">
123 <androidx.appcompat.widget.AppCompatSpinner
124 android:id="@+id/spinner_subject"
125 style="@style/customSpinnerStyle"
126 android:layout_width="match_parent"
127 android:layout_height="40dp"
128 android:layout_centerHorizontal="true"
129 android:layout_marginLeft="20dp"
130 android:layout_marginTop="10dp"
131 android:layout_marginRight="20dp"
132 android:background="@drawable/selector_for_custom_spinner" 54
133 android:entries="@array/filter_subject" 55 <ImageView
134 android:popupBackground="@drawable/shape_for_custom_spinner" 56 android:id="@+id/iv_topic"
135 android:scrollbars="none" /> 57 android:layout_width="wrap_content"
136 58 android:layout_height="wrap_content"
137 <TextView 59 android:layout_centerVertical="true" />
138 android:layout_width="wrap_content" 60 </RelativeLayout>
139 android:layout_height="wrap_content" 61 </RelativeLayout>
140 android:layout_centerVertical="true"
141 android:layout_marginLeft="20dp"
142 android:layout_marginTop="20dp"
143 android:text="错误原因" 62
144 android:textColor="@color/text_title" 63 <TextView
145 android:textSize="15sp" 64 android:layout_width="wrap_content"
146 android:textStyle="bold" /> 65 android:layout_height="wrap_content"
147 66 android:layout_centerVertical="true"
148 <androidx.appcompat.widget.AppCompatSpinner 67 android:layout_marginLeft="20dp"
149 android:id="@+id/spinner_reason" 68 android:layout_marginTop="20dp"
150 style="@style/customSpinnerStyle" 69 android:text="年级"
151 android:layout_width="match_parent" 70 android:textColor="@color/text_title"
152 android:layout_height="40dp" 71 android:textSize="15sp"
153 android:layout_centerHorizontal="true" 72 android:textStyle="bold" />
154 android:layout_marginLeft="20dp"
155 android:layout_marginTop="10dp"
156 android:layout_marginRight="20dp"
157 android:background="@drawable/selector_for_custom_spinner" 73
158 android:entries="@array/filter_subject" 74 <androidx.appcompat.widget.AppCompatSpinner
159 android:popupBackground="@drawable/shape_for_custom_spinner" 75 android:id="@+id/spinner_grade"
160 android:scrollbars="none" /> 76 style="@style/customSpinnerStyle"
161 77 android:layout_width="match_parent"
162 <TextView 78 android:layout_height="40dp"
163 android:id="@+id/tv_student" 79 android:layout_centerHorizontal="true"
164 android:layout_width="wrap_content" 80 android:layout_marginLeft="20dp"
165 android:layout_height="wrap_content" 81 android:layout_marginTop="10dp"
166 android:layout_centerVertical="true" 82 android:layout_marginRight="20dp"
167 android:layout_marginLeft="20dp" 83 android:background="@drawable/selector_for_custom_spinner"
168 android:layout_marginTop="20dp" 84 android:popupBackground="@drawable/shape_for_custom_spinner"
169 android:text="学生" 85 android:scrollbars="none" />
170 android:textColor="@color/text_title" 86
171 android:visibility="gone" 87 <TextView
172 android:textSize="15sp" 88 android:layout_width="wrap_content"
173 android:textStyle="bold" /> 89 android:layout_height="wrap_content"
174 90 android:layout_centerVertical="true"
175 <androidx.appcompat.widget.AppCompatSpinner 91 android:layout_marginLeft="20dp"
176 android:id="@+id/spinner_student" 92 android:layout_marginTop="20dp"
177 style="@style/customSpinnerStyle" 93 android:text="学期"
178 android:layout_width="match_parent" 94 android:textColor="@color/text_title"
179 android:layout_height="40dp" 95 android:textSize="15sp"
180 android:layout_centerHorizontal="true" 96 android:textStyle="bold" />
181 android:layout_marginLeft="20dp"
182 android:layout_marginTop="10dp"
183 android:layout_marginRight="20dp"
184 android:visibility="gone"
185 android:background="@drawable/selector_for_custom_spinner" 97
186 android:entries="@array/filter_subject" 98 <androidx.appcompat.widget.AppCompatSpinner
187 android:popupBackground="@drawable/shape_for_custom_spinner" 99 android:id="@+id/spinner_grade1"
188 android:scrollbars="none" /> 100 style="@style/customSpinnerStyle"
189 101 android:layout_width="match_parent"
190 <TextView 102 android:layout_height="40dp"
191 android:layout_width="wrap_content" 103 android:layout_centerHorizontal="true"
192 android:layout_height="wrap_content" 104 android:layout_marginLeft="20dp"
193 android:layout_centerVertical="true" 105 android:layout_marginTop="10dp"
194 android:layout_marginLeft="20dp" 106 android:layout_marginRight="20dp"
195 android:layout_marginTop="20dp" 107 android:background="@drawable/selector_for_custom_spinner"
108 android:entries="@array/grade_array"
109 android:popupBackground="@drawable/shape_for_custom_spinner"
110 android:scrollbars="none" />
196 android:text="来源" 111
197 android:textColor="@color/text_title" 112 <TextView
198 android:textSize="15sp" 113 android:layout_width="wrap_content"
199 android:textStyle="bold" /> 114 android:layout_height="wrap_content"
200 115 android:layout_centerVertical="true"
201 <RadioGroup 116 android:layout_marginLeft="20dp"
202 android:id="@+id/type_radio" 117 android:layout_marginTop="20dp"
203 android:layout_width="match_parent" 118 android:text="科目"
119 android:textColor="@color/text_title"
120 android:textSize="15sp"
121 android:textStyle="bold" />
204 android:layout_height="40dp" 122
205 android:layout_marginLeft="20dp" 123 <androidx.appcompat.widget.AppCompatSpinner
206 android:layout_marginTop="10dp" 124 android:id="@+id/spinner_subject"
207 android:orientation="horizontal"> 125 style="@style/customSpinnerStyle"
126 android:layout_width="match_parent"
127 android:layout_height="40dp"
128 android:layout_centerHorizontal="true"
129 android:layout_marginLeft="20dp"
130 android:layout_marginTop="10dp"
208 131 android:layout_marginRight="20dp"
209 <RadioButton 132 android:background="@drawable/selector_for_custom_spinner"
210 android:layout_width="65dp" 133 android:entries="@array/filter_subject"
211 android:layout_height="match_parent" 134 android:popupBackground="@drawable/shape_for_custom_spinner"
212 android:layout_marginRight="20dp" 135 android:scrollbars="none" />
213 android:background="@drawable/radio_button_selector" 136
214 android:button="@null" 137 <TextView
138 android:layout_width="wrap_content"
139 android:layout_height="wrap_content"
140 android:layout_centerVertical="true"
141 android:layout_marginLeft="20dp"
142 android:layout_marginTop="20dp"
143 android:text="错误原因"
144 android:textColor="@color/text_title"
145 android:textSize="15sp"
146 android:textStyle="bold" />
215 android:gravity="center" 147
216 android:text="课内" 148 <androidx.appcompat.widget.AppCompatSpinner
217 android:textColor="@drawable/radio_text_selector" 149 android:id="@+id/spinner_reason"
218 android:textSize="14sp" /> 150 style="@style/customSpinnerStyle"
151 android:layout_width="match_parent"
152 android:layout_height="40dp"
153 android:layout_centerHorizontal="true"
154 android:layout_marginLeft="20dp"
155 android:layout_marginTop="10dp"
219 156 android:layout_marginRight="20dp"
220 <RadioButton 157 android:background="@drawable/selector_for_custom_spinner"
221 android:layout_width="65dp" 158 android:entries="@array/filter_subject"
222 android:layout_height="match_parent" 159 android:popupBackground="@drawable/shape_for_custom_spinner"
223 android:layout_marginRight="20dp" 160 android:scrollbars="none" />
224 android:background="@drawable/radio_button_selector"
225 android:button="@null"
226 android:gravity="center"
227 android:text="课外" 161
162 <TextView
163 android:id="@+id/tv_student"
164 android:layout_width="wrap_content"
165 android:layout_height="wrap_content"
166 android:layout_centerVertical="true"
167 android:layout_marginLeft="20dp"
168 android:layout_marginTop="20dp"
169 android:text="学生"
170 android:textColor="@color/text_title"
171 android:visibility="gone"
172 android:textSize="15sp"
173 android:textStyle="bold" />
228 android:textColor="@drawable/radio_text_selector" 174
libs/common/src/main/java/com/prws/common/bean/homework/CorrectionSer.java
File was created 1 package com.prws.common.bean.homework;
2
3 public class CorrectionSer {
4 public String brief;
5 public int correction; // 0 对, 1 错
6 public int state; // 1: 已听懂; 2: 基本听懂; 3: 一般听懂
7
8 public CorrectionSer() {
9 }
10
11 public CorrectionSer(String brief, int correction, int state) {
12 this.brief = brief;
13 this.correction = correction;
14 this.state = state;
15 }
16 }
1 package com.prws.common.bean.homework; 17
libs/common/src/main/java/com/prws/common/bean/homework/HomeWork.java
1 package com.prws.common.bean.homework; 1 package com.prws.common.bean.homework;
2 2
3 import com.google.gson.Gson; 3 import com.google.gson.Gson;
4 import com.google.gson.annotations.SerializedName; 4 import com.google.gson.annotations.SerializedName;
5 import com.google.gson.reflect.TypeToken; 5 import com.google.gson.reflect.TypeToken;
6 6
7 import java.io.Serializable; 7 import java.io.Serializable;
8 import java.util.ArrayList; 8 import java.util.ArrayList;
9 import java.util.List; 9 import java.util.List;
10 10
11 public class HomeWork implements Serializable { 11 public class HomeWork implements Serializable {
12 12
13 @SerializedName(value = "homeworkId", alternate = "id") 13 @SerializedName(value = "homeworkId", alternate = "id")
14 public String homeworkId; 14 public String homeworkId;
15 public String brief; 15 public String brief;
16 public String url; 16 public String url;
17 public String analyseUrl; 17 public String analyseUrl;
18 public String analyseVideoUrl; 18 public String analyseVideoUrl;
19 public Integer correction; 19 public Integer correction;
20 public String answer; 20 public String answer;
21 public String points; 21 public String points;
22 22
23 public boolean check = false; //选中为错题 23 public boolean check = false; //选中为错题
24 public transient int index = 0; 24 public transient int index = 0;
25 public transient int state = 1; 25 public transient int state = 1;
26 26
27 public transient List<KeyValue> pointsObj; 27 public transient List<KeyValue> pointsObj;
28 public void formatPoints(Gson gson) { 28 public void formatPoints(Gson gson) {
29 if (points == null) { 29 if (points == null) {
30 pointsObj = new ArrayList<>(); 30 pointsObj = new ArrayList<>();
31 return; 31 return;
32 } 32 }
33 try { 33 try {
34 pointsObj = gson.fromJson(points, new TypeToken<List<KeyValue>>(){}.getType()); 34 pointsObj = gson.fromJson(points, new TypeToken<List<KeyValue>>(){}.getType());
35 } catch (Exception e) { 35 } catch (Exception e) {
36 e.printStackTrace(); 36 e.printStackTrace();
37 pointsObj = new ArrayList<>(); 37 pointsObj = new ArrayList<>();
38 } 38 }
39 } 39 }
40 40
41 public CorrectionSer toSer() {
42 return new CorrectionSer(brief, check ? 1 : 0, state);
43 }
41 public CorrectionSer toSer() { 44 }
42 return new CorrectionSer(brief, check ? 1 : 0, state); 45
libs/common/src/main/java/com/prws/common/widget/MarkSizeView.java
1 package com.prws.common.widget; 1 package com.prws.common.widget;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 import android.content.res.TypedArray; 4 import android.content.res.TypedArray;
5 import android.graphics.Bitmap; 5 import android.graphics.Bitmap;
6 import android.graphics.BitmapFactory; 6 import android.graphics.BitmapFactory;
7 import android.graphics.Canvas; 7 import android.graphics.Canvas;
8 import android.graphics.Color; 8 import android.graphics.Color;
9 import android.graphics.Paint; 9 import android.graphics.Paint;
10 import android.graphics.Rect; 10 import android.graphics.Rect;
11 import android.graphics.RectF; 11 import android.graphics.RectF;
12 import android.util.AttributeSet; 12 import android.util.AttributeSet;
13 import android.util.Log; 13 import android.util.Log;
14 import android.view.MotionEvent; 14 import android.view.MotionEvent;
15 import android.view.View; 15 import android.view.View;
16 16
17 import com.prws.common.R; 17 import com.prws.common.R;
18 import com.prws.common.utils.CommonUtil; 18 import com.prws.common.utils.CommonUtil;
19 19
20 20
21 /** 21 /**
22 * Created by Administrator on 2016/11/28. 22 * Created by Administrator on 2016/11/28.
23 */ 23 */
24 public class MarkSizeView extends View { 24 public class MarkSizeView extends View {
25 private final String Tag = "MarkSizeView"; 25 private final String Tag = "MarkSizeView";
26 private static final int DEFAULT_MARKED_COLOR = Color.parseColor("#ffd84e43"); 26 private static final int DEFAULT_MARKED_COLOR = Color.parseColor("#ffd84e43");
27 private static final int DEFAULT_UNMARKED_COLOR = Color.parseColor("#00000000"); 27 private static final int DEFAULT_UNMARKED_COLOR = Color.parseColor("#00000000");
28 private static final int DEFAULT_STROKE_COLOR = Color.parseColor("#009688"); 28 private static final int DEFAULT_STROKE_COLOR = Color.parseColor("#009688");
29 private static final int DEFAULT_STROKE_WIDTH = 2;//dp 29 private static final int DEFAULT_STROKE_WIDTH = 2;//dp
30 private static final int DEFAULT_VERTEX_COLOR = Color.parseColor("#009688"); 30 private static final int DEFAULT_VERTEX_COLOR = Color.parseColor("#009688");
31 private static final int DEFAULT_CONFIRM_BUTTON_RES = R.mipmap.select_confirm; 31 private static final int DEFAULT_CONFIRM_BUTTON_RES = R.mipmap.select_confirm;
32 private static final int DEFAULT_CANCEL_BUTTON_RES = R.mipmap.select_cancel; 32 private static final int DEFAULT_CANCEL_BUTTON_RES = R.mipmap.select_cancel;
33 private static final int DEFAULT_BACK_ROUND_RES = R.color.white; 33 private static final int DEFAULT_BACK_ROUND_RES = R.color.white;
34 34
35 private static final int BUTTON_EXTRA_WIDTH = 8; 35 private static final int BUTTON_EXTRA_WIDTH = 8;
36 36
37 private static final int DEFAULT_VERTEX_WIDTH = 20;//dp 37 private static final int DEFAULT_VERTEX_WIDTH = 20;//dp
38 38
39 39
40 private int markedColor = DEFAULT_MARKED_COLOR; 40 private int markedColor = DEFAULT_MARKED_COLOR;
41 private int unmarkedColor = DEFAULT_UNMARKED_COLOR; 41 private int unmarkedColor = DEFAULT_UNMARKED_COLOR;
42 private int strokeColor = DEFAULT_STROKE_COLOR; 42 private int strokeColor = DEFAULT_STROKE_COLOR;
43 private int strokeWidth = DEFAULT_STROKE_WIDTH;//dp 43 private int strokeWidth = DEFAULT_STROKE_WIDTH;//dp
44 private int vertexColor = DEFAULT_VERTEX_COLOR; 44 private int vertexColor = DEFAULT_VERTEX_COLOR;
45 private int confirmButtonRes = DEFAULT_CONFIRM_BUTTON_RES; 45 private int confirmButtonRes = DEFAULT_CONFIRM_BUTTON_RES;
46 private int cancelButtonRes = DEFAULT_CANCEL_BUTTON_RES; 46 private int cancelButtonRes = DEFAULT_CANCEL_BUTTON_RES;
47 private int backGroundRes = DEFAULT_BACK_ROUND_RES; 47 private int backGroundRes = DEFAULT_BACK_ROUND_RES;
48 private int vertexWidth = DEFAULT_VERTEX_WIDTH; 48 private int vertexWidth = DEFAULT_VERTEX_WIDTH;
49 private int mActionGap; 49 private int mActionGap;
50 50
51 51
52 private Paint unMarkPaint, markPaint, vertexPaint, mBitPaint; 52 private Paint unMarkPaint, markPaint, vertexPaint, mBitPaint;
53 53
54 private int downX, downY; 54 private int downX, downY;
55 private int startX, startY; 55 private int startX, startY;
56 private int endX, endY; 56 private int endX, endY;
57 57
58 private Rect markedArea; 58 private Rect markedArea;
59 private Rect confirmArea, cancelArea; 59 private Rect confirmArea, cancelArea;
60 private RectF ltVer, rtVer, lbVer, rbVer; 60 private RectF ltVer, rtVer, lbVer, rbVer;
61 private boolean isValid = false; 61 private boolean isValid = false;
62 private boolean isUp = false; 62 private boolean isUp = false;
63 private boolean isMoveMode = false; 63 private boolean isMoveMode = false;
64 private boolean isAdjustMode = false; 64 private boolean isAdjustMode = false;
65 private boolean isButtonClicked = false; 65 private boolean isButtonClicked = false;
66 private int adjustNum = 0; 66 private int adjustNum = 0;
67 67
68 private Bitmap confirmBitmap, cancelBitmap, backGroundBitmap; 68 private Bitmap confirmBitmap, cancelBitmap, backGroundBitmap;
69 69
70 private onClickListener mOnClickListener; 70 private onClickListener mOnClickListener;
71 71
72 private Context context; 72 private Context context;
73 private Rect region; 73 private Rect region;
74 74
75 public MarkSizeView(Context context) { 75 public MarkSizeView(Context context) {
76 super(context); 76 super(context);
77 init(context, null); 77 init(context, null);
78 } 78 }
79 79
80 public MarkSizeView(Context context, AttributeSet attrs) { 80 public MarkSizeView(Context context, AttributeSet attrs) {
81 super(context, attrs); 81 super(context, attrs);
82 init(context, attrs); 82 init(context, attrs);
83 } 83 }
84 84
85 private void init(Context context, AttributeSet attrs) { 85 private void init(Context context, AttributeSet attrs) {
86 this.context = context; 86 this.context = context;
87 if (attrs != null) { 87 if (attrs != null) {
88 TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MarkSizeView); 88 TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MarkSizeView);
89 markedColor = typedArray.getColor(R.styleable.MarkSizeView_markedColor, DEFAULT_MARKED_COLOR); 89 markedColor = typedArray.getColor(R.styleable.MarkSizeView_markedColor, DEFAULT_MARKED_COLOR);
90 unmarkedColor = typedArray.getColor(R.styleable.MarkSizeView_unMarkedColor, DEFAULT_UNMARKED_COLOR); 90 unmarkedColor = typedArray.getColor(R.styleable.MarkSizeView_unMarkedColor, DEFAULT_UNMARKED_COLOR);
91 strokeColor = typedArray.getColor(R.styleable.MarkSizeView_strokesColor, DEFAULT_STROKE_COLOR); 91 strokeColor = typedArray.getColor(R.styleable.MarkSizeView_strokesColor, DEFAULT_STROKE_COLOR);
92 strokeWidth = typedArray.getDimensionPixelSize(R.styleable.MarkSizeView_strokeWidth, DEFAULT_STROKE_WIDTH); 92 strokeWidth = typedArray.getDimensionPixelSize(R.styleable.MarkSizeView_strokeWidth, DEFAULT_STROKE_WIDTH);
93 vertexColor = typedArray.getColor(R.styleable.MarkSizeView_vertexColor, DEFAULT_VERTEX_COLOR); 93 vertexColor = typedArray.getColor(R.styleable.MarkSizeView_vertexColor, DEFAULT_VERTEX_COLOR);
94 vertexWidth = typedArray.getDimensionPixelSize(R.styleable.MarkSizeView_vertexWidth, DEFAULT_VERTEX_WIDTH); 94 vertexWidth = typedArray.getDimensionPixelSize(R.styleable.MarkSizeView_vertexWidth, DEFAULT_VERTEX_WIDTH);
95 confirmButtonRes = typedArray.getResourceId(R.styleable.MarkSizeView_confirmButtonRes, DEFAULT_CONFIRM_BUTTON_RES); 95 confirmButtonRes = typedArray.getResourceId(R.styleable.MarkSizeView_confirmButtonRes, DEFAULT_CONFIRM_BUTTON_RES);
96 cancelButtonRes = typedArray.getResourceId(R.styleable.MarkSizeView_cancleButtonRes, DEFAULT_CANCEL_BUTTON_RES); 96 cancelButtonRes = typedArray.getResourceId(R.styleable.MarkSizeView_cancleButtonRes, DEFAULT_CANCEL_BUTTON_RES);
97 backGroundRes = typedArray.getResourceId(R.styleable.MarkSizeView_backGroundRes, DEFAULT_BACK_ROUND_RES); 97 backGroundRes = typedArray.getResourceId(R.styleable.MarkSizeView_backGroundRes, DEFAULT_BACK_ROUND_RES);
98 } 98 }
99 99
100 unMarkPaint = new Paint(); 100 unMarkPaint = new Paint();
101 unMarkPaint.setColor(unmarkedColor); 101 unMarkPaint.setColor(unmarkedColor);
102 unMarkPaint.setAntiAlias(true); 102 unMarkPaint.setAntiAlias(true);
103 103
104 markPaint = new Paint(); 104 markPaint = new Paint();
105 markPaint.setAntiAlias(true); 105 markPaint.setAntiAlias(true);
106 markPaint.setStrokeWidth(strokeWidth); //线的宽度 106 markPaint.setStrokeWidth(strokeWidth); //线的宽度
107 107
108 vertexPaint = new Paint(); 108 vertexPaint = new Paint();
109 vertexPaint.setColor(vertexColor); 109 vertexPaint.setColor(vertexColor);
110 vertexPaint.setAntiAlias(true); 110 vertexPaint.setAntiAlias(true);
111 111
112 mBitPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 112 mBitPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
113 mBitPaint.setFilterBitmap(true); 113 mBitPaint.setFilterBitmap(true);
114 mBitPaint.setDither(true); 114 mBitPaint.setDither(true);
115 115
116 markedArea = new Rect(); 116 markedArea = new Rect();
117 confirmArea = new Rect(); 117 confirmArea = new Rect();
118 cancelArea = new Rect(); 118 cancelArea = new Rect();
119 119
120 ltVer = new RectF(); 120 ltVer = new RectF();
121 rtVer = new RectF(); 121 rtVer = new RectF();
122 lbVer = new RectF(); 122 lbVer = new RectF();
123 rbVer = new RectF(); 123 rbVer = new RectF();
124 124
125 confirmBitmap = BitmapFactory.decodeResource(getResources(), confirmButtonRes); 125 confirmBitmap = BitmapFactory.decodeResource(getResources(), confirmButtonRes);
126 cancelBitmap = BitmapFactory.decodeResource(getResources(), cancelButtonRes); 126 cancelBitmap = BitmapFactory.decodeResource(getResources(), cancelButtonRes);
127 backGroundBitmap = BitmapFactory.decodeResource(getResources(), backGroundRes); 127 backGroundBitmap = BitmapFactory.decodeResource(getResources(), backGroundRes);
128 128
129 mActionGap = CommonUtil.dpToPx(context, 15); 129 mActionGap = CommonUtil.dpToPx(context, 15);
130 } 130 }
131 131
132 private int imageWidth; 132 private int imageWidth;
133 private int imageHeight; 133 private int imageHeight;
134 134
135 public void setSize(int imageWidth, int imageHeight) { 135 public void setSize(int imageWidth, int imageHeight) {
136 this.imageWidth = imageWidth; 136 this.imageWidth = imageWidth;
137 this.imageHeight = imageHeight; 137 this.imageHeight = imageHeight;
138 } 138 }
139 139
140 @Override 140 @Override
141 protected void onDraw(Canvas canvas) { 141 protected void onDraw(Canvas canvas) {
142 Log.d(toString(), "onDraw"); 142 Log.d(toString(), "onDraw");
143 143
144 int width = imageWidth > 0 ? imageWidth : getWidth(); 144 int width = imageWidth > 0 ? imageWidth : getWidth();
145 int height = imageHeight > 0 ? imageHeight : getHeight(); 145 int height = imageHeight > 0 ? imageHeight : getHeight();
146 //draw unmarked 146 //draw unmarked
147 Rect rect = new Rect(0, 0, width, height); 147 Rect rect = new Rect(0, 0, width, height);
148 if (backGroundBitmap != null) 148 if (backGroundBitmap != null)
149 canvas.drawBitmap(backGroundBitmap, null, rect, mBitPaint); 149 canvas.drawBitmap(backGroundBitmap, null, rect, mBitPaint);
150 canvas.drawRect(rect, unMarkPaint); 150 canvas.drawRect(rect, unMarkPaint);
151 //draw marked 151 //draw marked
152 if (isValid || !isEnabled()) { 152 if (isValid || !isEnabled()) {
153 markPaint.setStyle(Paint.Style.FILL); 153 markPaint.setStyle(Paint.Style.FILL);
154 markPaint.setColor(markedColor); 154 markPaint.setColor(markedColor);
155 155
156 canvas.drawRect(markedArea, markPaint); 156 canvas.drawRect(markedArea, markPaint);
157 157
158 markPaint.setStyle(Paint.Style.STROKE);//不填充 158 markPaint.setStyle(Paint.Style.STROKE);//不填充
159 markPaint.setColor(strokeColor); 159 markPaint.setColor(strokeColor);
160 canvas.drawRect(markedArea, markPaint); 160 canvas.drawRect(markedArea, markPaint);
161 setTranslationZ(8);
161 setTranslationZ(8); 162 }
162 } 163 if (!isEnabled()) {
163 if (!isEnabled()) { 164 return;
164 return; 165 }
165 } 166 //draw vertex
166 //draw vertex 167 if (isValid && isUp) {
167 if (isValid && isUp) { 168 canvas.drawOval(ltVer, vertexPaint);
168 canvas.drawOval(ltVer, vertexPaint); 169 canvas.drawOval(rtVer, vertexPaint);
169 canvas.drawOval(rtVer, vertexPaint); 170 canvas.drawOval(lbVer, vertexPaint);
170 canvas.drawOval(lbVer, vertexPaint); 171 canvas.drawOval(rbVer, vertexPaint);
171 canvas.drawOval(rbVer, vertexPaint); 172 }
172 } 173
173 174 //draw button
174 //draw button 175 if (isValid && isUp) {
175 if (isValid && isUp) { 176 canvas.drawBitmap(confirmBitmap, null, confirmArea, mBitPaint);
176 canvas.drawBitmap(confirmBitmap, null, confirmArea, mBitPaint); 177 canvas.drawBitmap(cancelBitmap, null, cancelArea, mBitPaint);
177 canvas.drawBitmap(cancelBitmap, null, cancelArea, mBitPaint);
178 }
179 super.onDraw(canvas); 178 }
180 } 179 super.onDraw(canvas);
181 180 }
182 @Override 181
183 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 182 @Override
184 super.onLayout(changed, left, top, right, bottom); 183 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
185 int measuredWidth = getMeasuredWidth(); 184 super.onLayout(changed, left, top, right, bottom);
186 int measuredHeight = getMeasuredHeight(); 185 int measuredWidth = getMeasuredWidth();
187 region = new Rect(0, 0, measuredWidth, measuredHeight); 186 int measuredHeight = getMeasuredHeight();
188 Log.e("onLayout", "measuredWidth=" + measuredWidth + ";measuredHeight=" + measuredHeight); 187 region = new Rect(0, 0, measuredWidth, measuredHeight);
189 } 188 Log.e("onLayout", "measuredWidth=" + measuredWidth + ";measuredHeight=" + measuredHeight);
190 189 }
191 @Override 190
192 public boolean onTouchEvent(MotionEvent event) { 191 @Override
193 if (!isEnabled()) { 192 public boolean onTouchEvent(MotionEvent event) {
194 return false; 193 if (!isEnabled()) {
195 } 194 return false;
196 int x = (int) event.getX(); 195 }
197 int y = (int) event.getY(); 196 int x = (int) event.getX();
198 switch (event.getAction()) { 197 int y = (int) event.getY();
199 case MotionEvent.ACTION_DOWN: 198 switch (event.getAction()) {
200 isUp = false; 199 case MotionEvent.ACTION_DOWN:
201 isAdjustMode = false; 200 isUp = false;
202 isMoveMode = false; 201 isAdjustMode = false;
203 isButtonClicked = false; 202 isMoveMode = false;
204 isValid = false; 203 isButtonClicked = false;
205 adjustNum = 0; 204 isValid = false;
206 downX = x; 205 adjustNum = 0;
207 downY = y; 206 downX = x;
208 if (mOnClickListener != null) { 207 downY = y;
209 mOnClickListener.onTouch(); 208 if (mOnClickListener != null) {
210 } 209 mOnClickListener.onTouch();
211 if (isAreaContainPoint(confirmArea, x, y)) { 210 }
212 isButtonClicked = true; 211 if (isAreaContainPoint(confirmArea, x, y)) {
213 isValid = true; 212 isButtonClicked = true;
214 invalidate(); 213 isValid = true;
215 if (mOnClickListener != null) { 214 invalidate();
216 mOnClickListener.onConfirm(markedArea); 215 if (mOnClickListener != null) {
217 } 216 mOnClickListener.onConfirm(markedArea);
218 setTranslationZ(0); 217 }
218 setTranslationZ(0);
219 } else if (isAreaContainPoint(cancelArea, x, y)) { 219 } else if (isAreaContainPoint(cancelArea, x, y)) {
220 isButtonClicked = true; 220 isButtonClicked = true;
221 isValid = true; 221 isValid = true;
222 if (mOnClickListener != null) { 222 if (mOnClickListener != null) {
223 mOnClickListener.onCancel(); 223 mOnClickListener.onCancel();
224 isValid = false; 224 isValid = false;
225 startX = startY = endX = endY = 0; 225 startX = startY = endX = endY = 0;
226 adjustMark(0, 0); 226 adjustMark(0, 0);
227 } 227 }
228 setTranslationZ(0);
228 setTranslationZ(0); 229 } else if (isAreaContainPoint(ltVer, x, y)) {
229 } else if (isAreaContainPoint(ltVer, x, y)) { 230 isAdjustMode = true;
230 isAdjustMode = true; 231 adjustNum = 1;
231 adjustNum = 1; 232 } else if (isAreaContainPoint(rtVer, x, y)) {
232 } else if (isAreaContainPoint(rtVer, x, y)) { 233 isAdjustMode = true;
233 isAdjustMode = true; 234 adjustNum = 2;
234 adjustNum = 2; 235 } else if (isAreaContainPoint(lbVer, x, y)) {
235 } else if (isAreaContainPoint(lbVer, x, y)) { 236 isAdjustMode = true;
236 isAdjustMode = true; 237 adjustNum = 3;
237 adjustNum = 3; 238 } else if (isAreaContainPoint(rbVer, x, y)) {
238 } else if (isAreaContainPoint(rbVer, x, y)) { 239 isAdjustMode = true;
239 isAdjustMode = true; 240 adjustNum = 4;
240 adjustNum = 4; 241 } else if (markedArea.contains(x, y)) {
241 } else if (markedArea.contains(x, y)) { 242 isMoveMode = true;
242 isMoveMode = true; 243 } else {
243 } else { 244 isMoveMode = false;
244 isMoveMode = false; 245 startX = (int) event.getX();
245 startX = (int) event.getX(); 246 startY = (int) event.getY();
246 startY = (int) event.getY(); 247 endX = startX;
247 endX = startX; 248 endY = startY;
248 endY = startY; 249 }
249 } 250 break;
250 break; 251 case MotionEvent.ACTION_MOVE:
251 case MotionEvent.ACTION_MOVE: 252 if (isButtonClicked) {
252 if (isButtonClicked) { 253 break;
253 break; 254 }
254 } 255 adjustMark(x, y);
255 adjustMark(x, y); 256 break;
256 break; 257 case MotionEvent.ACTION_UP:
257 case MotionEvent.ACTION_UP: 258 isUp = true;
258 isUp = true; 259 if (isButtonClicked) {
259 if (isButtonClicked) { 260 break;
260 break; 261 }
261 } 262 adjustMark(x, y);
262 adjustMark(x, y); 263 startX = markedArea.left;
263 startX = markedArea.left; 264 startY = markedArea.top;
264 startY = markedArea.top; 265 endX = markedArea.right;
265 endX = markedArea.right; 266 endY = markedArea.bottom;
266 endY = markedArea.bottom; 267
267 268 if (markedArea.width() > confirmBitmap.getWidth() * 3 + mActionGap * 3 && markedArea.height() > confirmBitmap.getHeight() * 5) {
268 if (markedArea.width() > confirmBitmap.getWidth() * 3 + mActionGap * 3 && markedArea.height() > confirmBitmap.getHeight() * 5) { 269 //显示在选区的内底部
269 //显示在选区的内底部 270 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap,
270 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, 271 endY - confirmBitmap.getHeight() - mActionGap,
271 endY - confirmBitmap.getHeight() - mActionGap, 272 endX - mActionGap,
272 endX - mActionGap, 273 endY - mActionGap);
273 endY - mActionGap); 274
274 275 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
275 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 276 endY - confirmBitmap.getHeight() - mActionGap,
276 endY - confirmBitmap.getHeight() - mActionGap, 277 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
277 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 278 endY - mActionGap);
278 endY - mActionGap); 279 } else if (endY > getHeight() - confirmBitmap.getHeight() * 3) {
279 } else if (endY > getHeight() - confirmBitmap.getHeight() * 3) { 280 //显示在选区的上面
280 //显示在选区的上面 281 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap,
281 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, 282 startY - confirmBitmap.getHeight() - mActionGap,
282 startY - confirmBitmap.getHeight() - mActionGap, 283 endX - mActionGap,
283 endX - mActionGap, 284 startY - mActionGap);
284 startY - mActionGap); 285
285 286 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
286 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 287 startY - confirmBitmap.getHeight() - mActionGap,
287 startY - confirmBitmap.getHeight() - mActionGap, 288 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
288 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 289 startY - mActionGap);
289 startY - mActionGap); 290 } else {
290 } else { 291 //显示在选区的下面
291 //显示在选区的下面 292 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap,
292 confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, 293 endY + mActionGap,
293 endY + mActionGap, 294 endX - mActionGap,
294 endX - mActionGap, 295 endY + confirmBitmap.getHeight() + mActionGap);
295 endY + confirmBitmap.getHeight() + mActionGap); 296
296 297 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
297 cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 298 endY + mActionGap,
298 endY + mActionGap, 299 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15),
299 endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), 300 endY + confirmBitmap.getHeight() + mActionGap);
300 endY + confirmBitmap.getHeight() + mActionGap); 301 }
301 }
302 302
303 if (cancelArea.left < 0) { 303 if (cancelArea.left < 0) {
304 int cancelAreaLeftMargin = Math.abs(cancelArea.left) + mActionGap; 304 int cancelAreaLeftMargin = Math.abs(cancelArea.left) + mActionGap;
305 cancelArea.left = cancelArea.left + cancelAreaLeftMargin; 305 cancelArea.left = cancelArea.left + cancelAreaLeftMargin;
306 cancelArea.right = cancelArea.right + cancelAreaLeftMargin; 306 cancelArea.right = cancelArea.right + cancelAreaLeftMargin;
307 confirmArea.left = confirmArea.left + cancelAreaLeftMargin; 307 confirmArea.left = confirmArea.left + cancelAreaLeftMargin;
308 confirmArea.right = confirmArea.right + cancelAreaLeftMargin; 308 confirmArea.right = confirmArea.right + cancelAreaLeftMargin;
309 } 309 }
310 310
311 if (!isValid) { 311 if (!isValid) {
312 if (mOnClickListener != null) { 312 if (mOnClickListener != null) {
313 mOnClickListener.onCancel(); 313 mOnClickListener.onCancel();
314 }
315 setTranslationZ(0); 314 }
315 setTranslationZ(0);
316 } 316 }
317 break; 317 break;
318 case MotionEvent.ACTION_CANCEL: 318 case MotionEvent.ACTION_CANCEL:
319 isUp = true; 319 isUp = true;
320 break; 320 break;
321 } 321 }
322 postInvalidate(); 322 postInvalidate();
323 return true; 323 return true;
324 } 324 }
325 325
326 /** 326 /**
327 * 是否在按钮点击范围 327 * 是否在按钮点击范围
328 * 328 *
329 * @param area 329 * @param area
330 * @param x 330 * @param x
331 * @param y 331 * @param y
332 * @return 332 * @return
333 */ 333 */
334 private boolean isAreaContainPoint(Rect area, int x, int y) { 334 private boolean isAreaContainPoint(Rect area, int x, int y) {
335 Rect newArea = new Rect(area.left - BUTTON_EXTRA_WIDTH, area.top - BUTTON_EXTRA_WIDTH, area.right + BUTTON_EXTRA_WIDTH, area.bottom + BUTTON_EXTRA_WIDTH); 335 Rect newArea = new Rect(area.left - BUTTON_EXTRA_WIDTH, area.top - BUTTON_EXTRA_WIDTH, area.right + BUTTON_EXTRA_WIDTH, area.bottom + BUTTON_EXTRA_WIDTH);
336 if (newArea.contains(x, y)) { 336 if (newArea.contains(x, y)) {
337 return true; 337 return true;
338 } 338 }
339 return false; 339 return false;
340 } 340 }
341 341
342 private void adjustMark(int x, int y) { 342 private void adjustMark(int x, int y) {
343 if (isAdjustMode) { 343 if (isAdjustMode) {
344 //拖动四个顶点 344 //拖动四个顶点
345 int moveMentX = x - downX; 345 int moveMentX = x - downX;
346 int moveMentY = y - downY; 346 int moveMentY = y - downY;
347 347
348 switch (adjustNum) { 348 switch (adjustNum) {
349 case 1: 349 case 1:
350 startX = startX + moveMentX; 350 startX = startX + moveMentX;
351 startY = startY + moveMentY; 351 startY = startY + moveMentY;
352 break; 352 break;
353 case 2: 353 case 2:
354 endX = endX + moveMentX; 354 endX = endX + moveMentX;
355 startY = startY + moveMentY; 355 startY = startY + moveMentY;
356 break; 356 break;
357 case 3: 357 case 3:
358 startX = startX + moveMentX; 358 startX = startX + moveMentX;
359 endY = endY + moveMentY; 359 endY = endY + moveMentY;
360 break; 360 break;
361 case 4: 361 case 4:
362 endX = endX + moveMentX; 362 endX = endX + moveMentX;
363 endY = endY + moveMentY; 363 endY = endY + moveMentY;
364 break; 364 break;
365 } 365 }
366 downX = x; 366 downX = x;
367 downY = y; 367 downY = y;
368 } else if (isMoveMode) { 368 } else if (isMoveMode) {
369 //移动矩形框 369 //移动矩形框
370 int moveMentX = x - downX; 370 int moveMentX = x - downX;
371 int moveMentY = y - downY; 371 int moveMentY = y - downY;
372 372
373 startX = startX + moveMentX; 373 startX = startX + moveMentX;
374 startY = startY + moveMentY; 374 startY = startY + moveMentY;
375 375
376 endX = endX + moveMentX; 376 endX = endX + moveMentX;
377 endY = endY + moveMentY; 377 endY = endY + moveMentY;
378 378
379 downX = x; 379 downX = x;
380 downY = y; 380 downY = y;
381 } else { 381 } else {
382 //绘制矩形框 382 //绘制矩形框
383 endX = x; 383 endX = x;
384 endY = y; 384 endY = y;
385 } 385 }
386 Log.e(Tag, "startX=" + startX + ";startY=" + startY + ";endX=" + endX + ";endY=" + endY); 386 Log.e(Tag, "startX=" + startX + ";startY=" + startY + ";endX=" + endX + ";endY=" + endY);
387 Rect rect = new Rect(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY)); 387 Rect rect = new Rect(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY));
388 if (region.contains(rect)) { 388 if (region.contains(rect)) {
389 //当方框的区域不超出View的宽高值时才绘制 389 //当方框的区域不超出View的宽高值时才绘制
390 markedArea.set(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY)); 390 markedArea.set(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY));
391 } 391 }
392 ltVer.set(markedArea.left - vertexWidth / 2, markedArea.top - vertexWidth / 2, markedArea.left + vertexWidth / 2, markedArea.top + vertexWidth / 2); 392 ltVer.set(markedArea.left - vertexWidth / 2, markedArea.top - vertexWidth / 2, markedArea.left + vertexWidth / 2, markedArea.top + vertexWidth / 2);
393 rtVer.set(markedArea.right - vertexWidth / 2, markedArea.top - vertexWidth / 2, markedArea.right + vertexWidth / 2, markedArea.top + vertexWidth / 2); 393 rtVer.set(markedArea.right - vertexWidth / 2, markedArea.top - vertexWidth / 2, markedArea.right + vertexWidth / 2, markedArea.top + vertexWidth / 2);
394 lbVer.set(markedArea.left - vertexWidth / 2, markedArea.bottom - vertexWidth / 2, markedArea.left + vertexWidth / 2, markedArea.bottom + vertexWidth / 2); 394 lbVer.set(markedArea.left - vertexWidth / 2, markedArea.bottom - vertexWidth / 2, markedArea.left + vertexWidth / 2, markedArea.bottom + vertexWidth / 2);
395 rbVer.set(markedArea.right - vertexWidth / 2, markedArea.bottom - vertexWidth / 2, markedArea.right + vertexWidth / 2, markedArea.bottom + vertexWidth / 2); 395 rbVer.set(markedArea.right - vertexWidth / 2, markedArea.bottom - vertexWidth / 2, markedArea.right + vertexWidth / 2, markedArea.bottom + vertexWidth / 2);
396 if (markedArea.height() * markedArea.width() > 200) { 396 if (markedArea.height() * markedArea.width() > 200) {
397 isValid = true; 397 isValid = true;
398 } else { 398 } else {
399 isValid = false; 399 isValid = false;
400 } 400 }
401 } 401 }
402 402
403 private boolean isAreaContainPoint(RectF area, int x, int y) { 403 private boolean isAreaContainPoint(RectF area, int x, int y) {
404 RectF newArea = new RectF(area.left - BUTTON_EXTRA_WIDTH, area.top - BUTTON_EXTRA_WIDTH, area.right + BUTTON_EXTRA_WIDTH, area.bottom + BUTTON_EXTRA_WIDTH); 404 RectF newArea = new RectF(area.left - BUTTON_EXTRA_WIDTH, area.top - BUTTON_EXTRA_WIDTH, area.right + BUTTON_EXTRA_WIDTH, area.bottom + BUTTON_EXTRA_WIDTH);
405 if (newArea.contains(x, y)) { 405 if (newArea.contains(x, y)) {
406 return true; 406 return true;
407 } 407 }
408 return false; 408 return false;
409 } 409 }
410 410
411 public interface onClickListener { 411 public interface onClickListener {
412 void onConfirm(Rect markedArea); 412 void onConfirm(Rect markedArea);
413 413
414 void onCancel(); 414 void onCancel();
415 415
416 void onTouch(); 416 void onTouch();
417 } 417 }
418 418
419 public void setmOnClickListener(onClickListener mOnClickListener) { 419 public void setmOnClickListener(onClickListener mOnClickListener) {
420 this.mOnClickListener = mOnClickListener; 420 this.mOnClickListener = mOnClickListener;
421 } 421 }
422 422
423 public void setBackGroundRes(int backGroundRes) { 423 public void setBackGroundRes(int backGroundRes) {
424 Bitmap backGroundBitmap = BitmapFactory.decodeResource(getResources(), backGroundRes); 424 Bitmap backGroundBitmap = BitmapFactory.decodeResource(getResources(), backGroundRes);
425 this.backGroundBitmap = backGroundBitmap; 425 this.backGroundBitmap = backGroundBitmap;
426 postInvalidate(); 426 postInvalidate();
427 } 427 }
428 428
429 public void setBackGroundBitmap(Bitmap backGroundBitmap) { 429 public void setBackGroundBitmap(Bitmap backGroundBitmap) {
430 this.backGroundBitmap = backGroundBitmap; 430 this.backGroundBitmap = backGroundBitmap;
431 postInvalidate(); 431 postInvalidate();
432 } 432 }
433 433
434 public Bitmap getBackGroundBitmap() { 434 public Bitmap getBackGroundBitmap() {
435 return backGroundBitmap; 435 return backGroundBitmap;
436 } 436 }
437 437
438 public void setUnmarkedColor(int unmarkedColor) { 438 public void setUnmarkedColor(int unmarkedColor) {
439 this.unmarkedColor = unmarkedColor; 439 this.unmarkedColor = unmarkedColor;
440 unMarkPaint.setColor(unmarkedColor); 440 unMarkPaint.setColor(unmarkedColor);
441 invalidate(); 441 invalidate();
442 } 442 }
443 443
444 public void reset() { 444 public void reset() {
445 isUp = false; 445 isUp = false;
446 isValid = false; 446 isValid = false;
447 startX = startY = endX = endY = 0; 447 startX = startY = endX = endY = 0;
448 adjustMark(0, 0); 448 adjustMark(0, 0);