Commit 2bbfadef8465716a10a7bc4ae60054fbed62dcdf
1 parent
34c4b7cd1c
Exists in
master
BUG修改
Showing
15 changed files
with
313 additions
and
11 deletions
Show diff stats
app/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | apply from: '../config.gradle' | 2 | apply from: '../config.gradle' |
3 | 3 | ||
4 | 4 | ||
5 | def androidId = rootProject.ext.androidId | 5 | def androidId = rootProject.ext.androidId |
6 | def support = rootProject.ext.dependencies | 6 | def support = rootProject.ext.dependencies |
7 | def url = rootProject.ext.url | 7 | def url = rootProject.ext.url |
8 | 8 | ||
9 | 9 | ||
10 | android { | 10 | android { |
11 | signingConfigs { | 11 | signingConfigs { |
12 | 12 | ||
13 | config { | 13 | config { |
14 | keyAlias 'alias' | 14 | keyAlias 'alias' |
15 | keyPassword '123456' | 15 | keyPassword '123456' |
16 | storeFile file('key.jks') | 16 | storeFile file('key.jks') |
17 | storePassword '123456' | 17 | storePassword '123456' |
18 | } | 18 | } |
19 | debug { | 19 | debug { |
20 | } | 20 | } |
21 | } | 21 | } |
22 | compileSdk 32 | 22 | compileSdk 32 |
23 | 23 | ||
24 | defaultConfig { | 24 | defaultConfig { |
25 | applicationId "com.hjx.parent" | 25 | applicationId "com.hjx.parent" |
26 | minSdk 24 | 26 | minSdk 24 |
27 | targetSdk 32 | 27 | targetSdk 32 |
28 | versionCode 1002 | 28 | versionCode 1003 |
29 | versionName "1.0.0.2" | 29 | versionName "1.0.0.3" |
30 | 30 | ||
31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
32 | } | 32 | } |
33 | 33 | ||
34 | android.applicationVariants.all { | 34 | android.applicationVariants.all { |
35 | variant -> | 35 | variant -> |
36 | variant.outputs.all { | 36 | variant.outputs.all { |
37 | //在这里修改apk文件名 | 37 | //在这里修改apk文件名 |
38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" | 38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" |
39 | } | 39 | } |
40 | } | 40 | } |
41 | buildTypes { | 41 | buildTypes { |
42 | debug { | 42 | debug { |
43 | debuggable true | 43 | debuggable true |
44 | minifyEnabled false | 44 | minifyEnabled false |
45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
46 | signingConfig signingConfigs.config | 46 | signingConfig signingConfigs.config |
47 | } | 47 | } |
48 | release { | 48 | release { |
49 | debuggable true | 49 | debuggable true |
50 | minifyEnabled false | 50 | minifyEnabled false |
51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
52 | signingConfig signingConfigs.config | 52 | signingConfig signingConfigs.config |
53 | } | 53 | } |
54 | } | 54 | } |
55 | lintOptions { | 55 | lintOptions { |
56 | checkReleaseBuilds false | 56 | checkReleaseBuilds false |
57 | abortOnError false | 57 | abortOnError false |
58 | } | 58 | } |
59 | buildFeatures { | 59 | buildFeatures { |
60 | viewBinding true | 60 | viewBinding 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 | } |
app/src/main/AndroidManifest.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
3 | xmlns:tools="http://schemas.android.com/tools" | 3 | xmlns:tools="http://schemas.android.com/tools" |
4 | package="com.hjx.parent"> | 4 | package="com.hjx.parent"> |
5 | 5 | ||
6 | 6 | ||
7 | <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> | 7 | <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> |
8 | <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- 允许程序改变网络链接状态 --> | 8 | <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- 允许程序改变网络链接状态 --> |
9 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 允许程序访问访问WIFI网络状态信息 --> | 9 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 允许程序访问访问WIFI网络状态信息 --> |
10 | <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 允许程序改变WIFI链接状态 --> | 10 | <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 允许程序改变WIFI链接状态 --> |
11 | <!-- 6.0系统需要添加权限才能获得wifi列表 --> | 11 | <!-- 6.0系统需要添加权限才能获得wifi列表 --> |
12 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | 12 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
13 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | 13 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> |
14 | <uses-permission android:name="android.permission.INTERNET" /> | 14 | <uses-permission android:name="android.permission.INTERNET" /> |
15 | <uses-permission android:name="android.permission.RECORD_AUDIO" /> | 15 | <uses-permission android:name="android.permission.RECORD_AUDIO" /> |
16 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | 16 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
17 | 17 | ||
18 | <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> | 18 | <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> |
19 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | 19 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
20 | <uses-permission android:name="android.permission.WAKE_LOCK" /> | 20 | <uses-permission android:name="android.permission.WAKE_LOCK" /> |
21 | <uses-permission android:name="android.permission.CAMERA" /> | 21 | <uses-permission android:name="android.permission.CAMERA" /> |
22 | <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | 22 | <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> |
23 | <uses-permission android:name="android.permission.VIBRATE" /> | 23 | <uses-permission android:name="android.permission.VIBRATE" /> |
24 | <uses-permission | 24 | <uses-permission |
25 | android:name="android.permission.WRITE_EXTERNAL_STORAGE" | 25 | android:name="android.permission.WRITE_EXTERNAL_STORAGE" |
26 | tools:ignore="ScopedStorage" /> | 26 | tools:ignore="ScopedStorage" /> |
27 | <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> | ||
28 | <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" /> | ||
27 | 29 | ||
30 | <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" | ||
31 | tools:ignore="ScopedStorage" /> | ||
28 | <application | 32 | <application |
29 | android:name=".App" | 33 | android:name=".App" |
30 | android:allowBackup="true" | 34 | android:allowBackup="true" |
31 | android:icon="@mipmap/icon" | 35 | android:icon="@mipmap/icon" |
32 | android:label="@string/app_name" | 36 | android:label="@string/app_name" |
33 | android:networkSecurityConfig="@xml/network_security_config" | 37 | android:networkSecurityConfig="@xml/network_security_config" |
34 | android:supportsRtl="true" | 38 | android:supportsRtl="true" |
35 | android:theme="@style/Theme.Parent"> | 39 | android:theme="@style/Theme.Parent"> |
36 | <activity | 40 | <activity |
37 | android:name=".LoginActivity" | 41 | android:name=".LoginActivity" |
38 | android:exported="true" | 42 | android:exported="true" |
39 | android:theme="@style/ThemeSplash"> | 43 | android:theme="@style/ThemeSplash"> |
40 | <intent-filter> | 44 | <intent-filter> |
41 | <action android:name="android.intent.action.MAIN" /> | 45 | <action android:name="android.intent.action.MAIN" /> |
42 | <category android:name="android.intent.category.LAUNCHER" /> | 46 | <category android:name="android.intent.category.LAUNCHER" /> |
43 | </intent-filter> | 47 | </intent-filter> |
44 | </activity> | 48 | </activity> |
45 | <activity | 49 | <activity |
46 | android:name=".MainActivity" | 50 | android:name=".MainActivity" |
47 | android:launchMode="singleTask" | 51 | android:launchMode="singleTask" |
48 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 52 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
49 | <activity | 53 | <activity |
50 | android:name=".RegisterActivity" | 54 | android:name=".RegisterActivity" |
51 | android:theme="@style/ThemeSplash" /> | 55 | android:theme="@style/ThemeSplash" /> |
52 | <activity | 56 | <activity |
53 | android:name=".UserActivity" | 57 | android:name=".UserActivity" |
54 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 58 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
55 | <activity | 59 | <activity |
56 | android:name=".YinsiActivity" | 60 | android:name=".YinsiActivity" |
57 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 61 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
58 | <activity | 62 | <activity |
59 | android:name=".QRActivity" | 63 | android:name=".QRActivity" |
60 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 64 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
61 | <activity | 65 | <activity |
62 | android:name=".AddStudentActivity" | 66 | android:name=".AddStudentActivity" |
63 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 67 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
64 | <activity | 68 | <activity |
65 | android:name=".NickActivity" | 69 | android:name=".NickActivity" |
66 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 70 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
67 | <activity | 71 | <activity |
68 | android:name=".SexActivity" | 72 | android:name=".SexActivity" |
69 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 73 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
70 | <activity | 74 | <activity |
71 | android:name=".NianActivity" | 75 | android:name=".NianActivity" |
72 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 76 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
73 | <activity | 77 | <activity |
74 | android:name=".ShenActivity" | 78 | android:name=".ShenActivity" |
75 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 79 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
76 | <activity | 80 | <activity |
77 | android:name=".UserAgreementActivity" | 81 | android:name=".UserAgreementActivity" |
78 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 82 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
79 | <activity | 83 | <activity |
80 | android:name=".AccountActivity" | 84 | android:name=".AccountActivity" |
81 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 85 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
82 | 86 | ||
83 | <activity | 87 | <activity |
84 | android:name=".ChangePwdActivity" | 88 | android:name=".ChangePwdActivity" |
85 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 89 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
86 | <activity | 90 | <activity |
87 | android:name=".EditStudentActivity" | 91 | android:name=".EditStudentActivity" |
88 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 92 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
89 | <activity | 93 | <activity |
90 | android:name=".ChooseActivity" | 94 | android:name=".ChooseActivity" |
91 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 95 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
92 | <activity | 96 | <activity |
93 | android:name=".AddTeacherActivity" | 97 | android:name=".AddTeacherActivity" |
94 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 98 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
95 | <activity | 99 | <activity |
96 | android:name=".ErrorBookActivity" | 100 | android:name=".ErrorBookActivity" |
97 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 101 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
98 | <activity | 102 | <activity |
99 | android:name=".ImageActivity" | 103 | android:name=".ImageActivity" |
100 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 104 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
101 | <activity | 105 | <activity |
102 | android:name=".ImageEditActivity" | 106 | android:name=".ImageEditActivity" |
103 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 107 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
104 | <activity | 108 | <activity |
105 | android:name=".ImageSelectActivity" | 109 | android:name=".ImageSelectActivity" |
106 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 110 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
107 | <activity | 111 | <activity |
108 | android:name=".AddSuccessActivity" | 112 | android:name=".AddSuccessActivity" |
109 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 113 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
110 | <activity | 114 | <activity |
111 | android:name=".ErrorListActivity" | 115 | android:name=".ErrorListActivity" |
112 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 116 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
113 | <activity | 117 | <activity |
114 | android:name=".ErrorDetailActivity" | 118 | android:name=".ErrorDetailActivity" |
115 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | 119 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
116 | 120 | ||
117 | <provider | 121 | <provider |
118 | android:name="androidx.core.content.FileProvider" | 122 | android:name="androidx.core.content.FileProvider" |
119 | android:authorities="com.hjx.parent.fileprovider" | 123 | android:authorities="com.hjx.parent.fileprovider" |
120 | android:exported="false" | 124 | android:exported="false" |
121 | android:grantUriPermissions="true" | 125 | android:grantUriPermissions="true" |
122 | tools:replace="android:authorities"> | 126 | tools:replace="android:authorities"> |
123 | <meta-data | 127 | <meta-data |
124 | android:name="android.support.FILE_PROVIDER_PATHS" | 128 | android:name="android.support.FILE_PROVIDER_PATHS" |
125 | android:resource="@xml/file_provider_paths" | 129 | android:resource="@xml/file_provider_paths" |
126 | tools:replace="android:resource" /> | 130 | tools:replace="android:resource" /> |
127 | </provider> | 131 | </provider> |
128 | </application> | 132 | </application> |
129 | 133 | ||
130 | </manifest> | 134 | </manifest> |
app/src/main/java/com/hjx/parent/ErrorBookActivity.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.graphics.Bitmap; | 4 | import android.graphics.Bitmap; |
5 | import android.graphics.BitmapFactory; | 5 | import android.graphics.BitmapFactory; |
6 | import android.net.Uri; | 6 | import android.net.Uri; |
7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
8 | import android.provider.MediaStore; | 8 | import android.provider.MediaStore; |
9 | import android.text.TextUtils; | 9 | import android.text.TextUtils; |
10 | import android.util.Log; | 10 | import android.util.Log; |
11 | import android.view.LayoutInflater; | 11 | import android.view.LayoutInflater; |
12 | import android.view.View; | 12 | import android.view.View; |
13 | import android.view.ViewGroup; | 13 | import android.view.ViewGroup; |
14 | import android.widget.LinearLayout; | 14 | import android.widget.LinearLayout; |
15 | import android.widget.Toast; | 15 | import android.widget.Toast; |
16 | 16 | ||
17 | import androidx.annotation.NonNull; | 17 | import androidx.annotation.NonNull; |
18 | import androidx.annotation.Nullable; | 18 | import androidx.annotation.Nullable; |
19 | import androidx.core.content.FileProvider; | 19 | import androidx.core.content.FileProvider; |
20 | import androidx.recyclerview.widget.LinearLayoutManager; | 20 | import androidx.recyclerview.widget.LinearLayoutManager; |
21 | import androidx.recyclerview.widget.RecyclerView; | 21 | import androidx.recyclerview.widget.RecyclerView; |
22 | 22 | ||
23 | import com.chad.library.adapter.base.BaseQuickAdapter; | 23 | import com.chad.library.adapter.base.BaseQuickAdapter; |
24 | import com.chad.library.adapter.base.BaseViewHolder; | 24 | import com.chad.library.adapter.base.BaseViewHolder; |
25 | import com.google.gson.Gson; | 25 | import com.google.gson.Gson; |
26 | import com.hjq.permissions.OnPermissionCallback; | 26 | import com.hjq.permissions.OnPermissionCallback; |
27 | import com.hjq.permissions.Permission; | 27 | import com.hjq.permissions.Permission; |
28 | import com.hjq.permissions.XXPermissions; | 28 | import com.hjq.permissions.XXPermissions; |
29 | import com.hjx.parent.adapter.ErrorAdapter; | 29 | import com.hjx.parent.adapter.ErrorAdapter; |
30 | import com.hjx.parent.bean.StudentBean; | 30 | import com.hjx.parent.bean.StudentBean; |
31 | import com.hjx.parent.databinding.ActivityErrorBookBinding; | 31 | import com.hjx.parent.databinding.ActivityErrorBookBinding; |
32 | import com.prws.common.base.BasePresenter; | 32 | import com.prws.common.base.BasePresenter; |
33 | import com.prws.common.bean.ImageBean; | 33 | import com.prws.common.bean.ImageBean; |
34 | import com.prws.common.bean.PageInfo; | 34 | import com.prws.common.bean.PageInfo; |
35 | import com.prws.common.bean.ResponseResult; | 35 | import com.prws.common.bean.ResponseResult; |
36 | import com.prws.common.bean.TopicBean; | 36 | import com.prws.common.bean.TopicBean; |
37 | import com.prws.common.net.NetWorks; | 37 | import com.prws.common.net.NetWorks; |
38 | import com.prws.common.utils.BitmapUtils; | 38 | import com.prws.common.utils.BitmapUtils; |
39 | import com.prws.common.utils.CommonUtil; | 39 | import com.prws.common.utils.CommonUtil; |
40 | import com.prws.common.utils.SharedPreferencesUtil; | 40 | import com.prws.common.utils.SharedPreferencesUtil; |
41 | import com.prws.common.utils.dialog.MyButtomDialog; | 41 | import com.prws.common.utils.dialog.MyButtomDialog; |
42 | import com.zhangteng.imagepicker.bean.ImageInfo; | 42 | import com.zhangteng.imagepicker.bean.ImageInfo; |
43 | import com.zhangteng.imagepicker.callback.HandlerCallBack; | 43 | import com.zhangteng.imagepicker.callback.HandlerCallBack; |
44 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 44 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
45 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 45 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
46 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 46 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
47 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 47 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
48 | import com.zhangteng.utils.IHandlerCallBack; | 48 | import com.zhangteng.utils.IHandlerCallBack; |
49 | 49 | ||
50 | import java.io.File; | 50 | import java.io.File; |
51 | import java.util.ArrayList; | 51 | import java.util.ArrayList; |
52 | import java.util.Arrays; | 52 | import java.util.Arrays; |
53 | import java.util.HashMap; | 53 | import java.util.HashMap; |
54 | import java.util.List; | 54 | import java.util.List; |
55 | import java.util.Map; | 55 | import java.util.Map; |
56 | 56 | ||
57 | import io.reactivex.Observer; | 57 | import io.reactivex.Observer; |
58 | import io.reactivex.disposables.Disposable; | 58 | import io.reactivex.disposables.Disposable; |
59 | 59 | ||
60 | public class ErrorBookActivity extends BaseActivity<ActivityErrorBookBinding> { | 60 | public class ErrorBookActivity extends BaseActivity<ActivityErrorBookBinding> { |
61 | StudentBean studentBean; | 61 | StudentBean studentBean; |
62 | private int subject; | 62 | private int subject; |
63 | private ErrorAdapter adapter; | 63 | private ErrorAdapter adapter; |
64 | private int REQUEST_CODE_IMAGE = 123; | 64 | private int REQUEST_CODE_IMAGE = 123; |
65 | private String filePath; | 65 | private String filePath; |
66 | 66 | ||
67 | @Override | 67 | @Override |
68 | public void initView(Bundle savedInstanceState) { | 68 | public void initView(Bundle savedInstanceState) { |
69 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 69 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
70 | try { | 70 | try { |
71 | studentBean = new Gson().fromJson(student, StudentBean.class); | 71 | studentBean = new Gson().fromJson(student, StudentBean.class); |
72 | } catch (Exception e) { | 72 | } catch (Exception e) { |
73 | 73 | ||
74 | } | 74 | } |
75 | binding.ivBack.setOnClickListener(new View.OnClickListener() { | 75 | binding.ivBack.setOnClickListener(new View.OnClickListener() { |
76 | @Override | 76 | @Override |
77 | public void onClick(View v) { | 77 | public void onClick(View v) { |
78 | finish(); | 78 | finish(); |
79 | } | 79 | } |
80 | }); | 80 | }); |
81 | binding.rlTakePhoto.post(new Runnable() { | 81 | binding.rlTakePhoto.post(new Runnable() { |
82 | @Override | 82 | @Override |
83 | public void run() { | 83 | public void run() { |
84 | LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) binding.rlTakePhoto.getLayoutParams(); | 84 | LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) binding.rlTakePhoto.getLayoutParams(); |
85 | layoutParams.width = CommonUtil.getScreenWidth(context); | 85 | layoutParams.width = CommonUtil.getScreenWidth(context); |
86 | layoutParams.height = CommonUtil.getScreenWidth(context) * 20 / 37; | 86 | layoutParams.height = CommonUtil.getScreenWidth(context) * 20 / 37; |
87 | binding.rlTakePhoto.setLayoutParams(layoutParams); | 87 | binding.rlTakePhoto.setLayoutParams(layoutParams); |
88 | } | 88 | } |
89 | }); | 89 | }); |
90 | binding.rlTakePhoto.setOnClickListener(new View.OnClickListener() { | 90 | binding.rlTakePhoto.setOnClickListener(new View.OnClickListener() { |
91 | @Override | 91 | @Override |
92 | public void onClick(View v) { | 92 | public void onClick(View v) { |
93 | if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | 93 | if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { |
94 | XXPermissions.with(context) | 94 | XXPermissions.with(context) |
95 | // 申请多个权限 | 95 | // 申请多个权限 |
96 | .permission(Permission.CAMERA) | 96 | .permission(Permission.CAMERA) |
97 | .request(new OnPermissionCallback() { | 97 | .request(new OnPermissionCallback() { |
98 | @Override | 98 | @Override |
99 | public void onGranted(List<String> permissions, boolean all) { | 99 | public void onGranted(List<String> permissions, boolean all) { |
100 | if (all) { | 100 | if (all) { |
101 | //开启扫码界面 | 101 | //开启扫码界面 |
102 | showButtonDialog(); | 102 | showButtonDialog(); |
103 | } else { | 103 | } else { |
104 | Toast.makeText(context, "需要权限", Toast.LENGTH_SHORT).show(); | 104 | Toast.makeText(context, "需要权限", Toast.LENGTH_SHORT).show(); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | @Override | 108 | @Override |
109 | public void onDenied(List<String> permissions, boolean never) { | 109 | public void onDenied(List<String> permissions, boolean never) { |
110 | XXPermissions.startPermissionActivity(context, permissions); | 110 | XXPermissions.startPermissionActivity(context, permissions); |
111 | } | 111 | } |
112 | }); | 112 | }); |
113 | } else { | 113 | } else { |
114 | showButtonDialog(); | 114 | showButtonDialog(); |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | }); | 118 | }); |
119 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { | 119 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { |
120 | @Override | 120 | @Override |
121 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 121 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | @Override | 125 | @Override |
126 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 126 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
127 | item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); | 127 | item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); |
128 | switch (item.getAdapterPosition()) { | 128 | switch (item.getAdapterPosition()) { |
129 | case 0: | 129 | case 0: |
130 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chinese); | 130 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chinese); |
131 | break; | 131 | break; |
132 | case 1: | 132 | case 1: |
133 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_math); | 133 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_math); |
134 | break; | 134 | break; |
135 | case 2: | 135 | case 2: |
136 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_english); | 136 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_english); |
137 | break; | 137 | break; |
138 | case 3: | 138 | case 3: |
139 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_physics); | 139 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_physics); |
140 | break; | 140 | break; |
141 | case 4: | 141 | case 4: |
142 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chemistry); | 142 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chemistry); |
143 | break; | 143 | break; |
144 | } | 144 | } |
145 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); | 145 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); |
146 | layoutParams.width = (CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 30)) / 4; | 146 | layoutParams.width = (CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 30)) / 4; |
147 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); | 147 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); |
148 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 148 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
149 | @Override | 149 | @Override |
150 | public void onClick(View v) { | 150 | public void onClick(View v) { |
151 | if (subject != item.getAdapterPosition()) { | 151 | if (subject != item.getAdapterPosition()) { |
152 | subject = item.getAdapterPosition(); | 152 | subject = item.getAdapterPosition(); |
153 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); | 153 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | }); | 156 | }); |
157 | } | 157 | } |
158 | }; | 158 | }; |
159 | binding.recycleSubject.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); | 159 | binding.recycleSubject.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); |
160 | binding.recycleSubject.setAdapter(adapter); | 160 | binding.recycleSubject.setAdapter(adapter); |
161 | subject = 0; | 161 | subject = 0; |
162 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); | 162 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); |
163 | binding.llAll.setOnClickListener(new View.OnClickListener() { | 163 | binding.llAll.setOnClickListener(new View.OnClickListener() { |
164 | @Override | 164 | @Override |
165 | public void onClick(View v) { | 165 | public void onClick(View v) { |
166 | Intent intent = new Intent(context, ErrorListActivity.class); | 166 | Intent intent = new Intent(context, ErrorListActivity.class); |
167 | startActivity(intent); | 167 | startActivity(intent); |
168 | } | 168 | } |
169 | }); | 169 | }); |
170 | } | 170 | } |
171 | 171 | ||
172 | @Override | 172 | @Override |
173 | protected ActivityErrorBookBinding getViewBinding() { | 173 | protected ActivityErrorBookBinding getViewBinding() { |
174 | return ActivityErrorBookBinding.inflate(getLayoutInflater()); | 174 | return ActivityErrorBookBinding.inflate(getLayoutInflater()); |
175 | } | 175 | } |
176 | 176 | ||
177 | private void showButtonDialog() { | 177 | private void showButtonDialog() { |
178 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); | 178 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); |
179 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); | 179 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); |
180 | dialog.setContentView(bottomView); | 180 | dialog.setContentView(bottomView); |
181 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 181 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
182 | @Override | 182 | @Override |
183 | public void onClick(View view) { | 183 | public void onClick(View view) { |
184 | dialog.dismiss(); | 184 | dialog.dismiss(); |
185 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 185 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
186 | //确保有相机来处理Intent | 186 | //确保有相机来处理Intent |
187 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 187 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
188 | File photoFile = new File(filePath); | 188 | File photoFile = new File(filePath); |
189 | if (photoFile != null) { | 189 | if (photoFile != null) { |
190 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 190 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
191 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 191 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
192 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 192 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
193 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 193 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
194 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | 194 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | }); | 197 | }); |
198 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 198 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
199 | @Override | 199 | @Override |
200 | public void onClick(View view) { | 200 | public void onClick(View view) { |
201 | dialog.dismiss(); | 201 | dialog.dismiss(); |
202 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | 202 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
203 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | 203 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) |
204 | .multiSelect(true) //是否多选 | 204 | .multiSelect(true) //是否多选 |
205 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | 205 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
206 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | 206 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
207 | .maxImageSelectable(9) //图片可选择数 | 207 | .maxImageSelectable(9) //图片可选择数 |
208 | .maxHeight(1920) //图片最大高度 | 208 | .maxHeight(1920) //图片最大高度 |
209 | .maxWidth(1920) //图片最大宽度 | 209 | .maxWidth(1920) //图片最大宽度 |
210 | .maxImageSize(10) //图片最大大小Mb | 210 | .maxImageSize(10) //图片最大大小Mb |
211 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | 211 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); |
212 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorBookActivity.this); | 212 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorBookActivity.this); |
213 | 213 | ||
214 | } | 214 | } |
215 | }); | 215 | }); |
216 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 216 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
217 | @Override | 217 | @Override |
218 | public void onClick(View view) { | 218 | public void onClick(View view) { |
219 | dialog.dismiss(); | 219 | dialog.dismiss(); |
220 | } | 220 | } |
221 | }); | 221 | }); |
222 | dialog.show(); | 222 | dialog.show(); |
223 | } | 223 | } |
224 | 224 | ||
225 | private void getError(String subject) { | 225 | private void getError(String subject) { |
226 | if (studentBean != null) { | 226 | if (studentBean != null) { |
227 | Map map = new HashMap(); | 227 | Map map = new HashMap(); |
228 | map.put("subject", subject); | 228 | map.put("subject", subject); |
229 | map.put("stuId", studentBean.getStuId()); | 229 | map.put("stuId", studentBean.getStuId()); |
230 | map.put("pageSize", 5); | 230 | map.put("pageSize", 5); |
231 | map.put("pageNum", 1); | 231 | map.put("pageNum", 1); |
232 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { | 232 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { |
233 | @Override | 233 | @Override |
234 | public void onSubscribe(Disposable d) { | 234 | public void onSubscribe(Disposable d) { |
235 | 235 | ||
236 | } | 236 | } |
237 | 237 | ||
238 | @Override | 238 | @Override |
239 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { | 239 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { |
240 | if (result.getData() != null && result.getCode() == 200) { | 240 | if (result.getData() != null && result.getCode() == 200) { |
241 | List<TopicBean> topicBeans = result.getData().getList(); | 241 | List<TopicBean> topicBeans = result.getData().getList(); |
242 | loadError(topicBeans); | 242 | loadError(topicBeans); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | @Override | 246 | @Override |
247 | public void onError(Throwable e) { | 247 | public void onError(Throwable e) { |
248 | e.toString(); | 248 | e.toString(); |
249 | } | 249 | } |
250 | 250 | ||
251 | @Override | 251 | @Override |
252 | public void onComplete() { | 252 | public void onComplete() { |
253 | 253 | ||
254 | } | 254 | } |
255 | }); | 255 | }); |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | @Override | 259 | @Override |
260 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 260 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
261 | super.onActivityResult(requestCode, resultCode, data); | 261 | super.onActivityResult(requestCode, resultCode, data); |
262 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 262 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
263 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 263 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
264 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 264 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
265 | CommonUtil.saveBitmapToUri(b, path); | 265 | CommonUtil.saveBitmapToUri(b, path); |
266 | List<String> strings = new ArrayList<>(); | 266 | List<String> strings = new ArrayList<>(); |
267 | Intent intent = new Intent(context, ImageActivity.class); | 267 | Intent intent = new Intent(context, ImageActivity.class); |
268 | strings.add(path); | 268 | strings.add(path); |
269 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 269 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
270 | startActivity(intent); | 270 | startActivity(intent); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | private void loadError(List<TopicBean> list) { | 274 | private void loadError(List<TopicBean> list) { |
275 | if (list.size() > 0) { | 275 | if (list.size() > 0) { |
276 | binding.recycleError.setVisibility(View.VISIBLE); | 276 | binding.recycleError.setVisibility(View.VISIBLE); |
277 | binding.llEmpty.setVisibility(View.GONE); | 277 | binding.llEmpty.setVisibility(View.GONE); |
278 | if (adapter != null) { | 278 | if (adapter != null) { |
279 | adapter.refresh(list); | 279 | adapter.refresh(list); |
280 | } else { | 280 | } else { |
281 | adapter = new ErrorAdapter(context, list, false); | 281 | adapter = new ErrorAdapter(context, list, false); |
282 | binding.recycleError.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false)); | 282 | binding.recycleError.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false)); |
283 | binding.recycleError.setAdapter(adapter); | 283 | binding.recycleError.setAdapter(adapter); |
284 | } | 284 | } |
285 | } else { | 285 | } else { |
286 | binding.recycleError.setVisibility(View.GONE); | 286 | binding.recycleError.setVisibility(View.GONE); |
287 | binding.llEmpty.setVisibility(View.VISIBLE); | 287 | binding.llEmpty.setVisibility(View.VISIBLE); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | 290 | ||
291 | @Override | ||
292 | protected void onResume() { | ||
293 | super.onResume(); | ||
294 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); | ||
295 | } | ||
296 | |||
291 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 297 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
292 | private String TAG = "---ImagePicker---"; | 298 | private String TAG = "---ImagePicker---"; |
293 | List<ImageInfo> photoList = new ArrayList<>(); | 299 | List<ImageInfo> photoList = new ArrayList<>(); |
294 | 300 | ||
295 | @Override | 301 | @Override |
296 | public void onStart() { | 302 | public void onStart() { |
297 | Log.i(TAG, "onStart: 开启"); | 303 | Log.i(TAG, "onStart: 开启"); |
298 | } | 304 | } |
299 | 305 | ||
300 | @Override | 306 | @Override |
301 | public void onSuccess(List<ImageInfo> photoList) { | 307 | public void onSuccess(List<ImageInfo> photoList) { |
302 | this.photoList = photoList; | 308 | this.photoList = photoList; |
303 | Log.i(TAG, "onSuccess: 返回数据"); | 309 | Log.i(TAG, "onSuccess: 返回数据"); |
304 | } | 310 | } |
305 | 311 | ||
306 | @Override | 312 | @Override |
307 | public void onCancel() { | 313 | public void onCancel() { |
308 | Log.i(TAG, "onCancel: 取消"); | 314 | Log.i(TAG, "onCancel: 取消"); |
309 | } | 315 | } |
310 | 316 | ||
311 | @Override | 317 | @Override |
312 | public void onFinish(List<ImageInfo> selectImage) { | 318 | public void onFinish(List<ImageInfo> selectImage) { |
313 | if (selectImage.size() == photoList.size()) { | 319 | if (selectImage.size() == photoList.size()) { |
314 | List<String> strings = new ArrayList<>(); | 320 | List<String> strings = new ArrayList<>(); |
315 | Intent intent = new Intent(context, ImageActivity.class); | 321 | Intent intent = new Intent(context, ImageActivity.class); |
316 | for (ImageInfo imageInfo : selectImage) { | 322 | for (ImageInfo imageInfo : selectImage) { |
317 | strings.add(imageInfo.getPath()); | 323 | strings.add(imageInfo.getPath()); |
318 | } | 324 | } |
319 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 325 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
320 | startActivity(intent); | 326 | startActivity(intent); |
321 | } | 327 | } |
322 | } | 328 | } |
323 | 329 | ||
324 | @Override | 330 | @Override |
325 | public void onError() { | 331 | public void onError() { |
326 | Log.i(TAG, "onError: 出错"); | 332 | Log.i(TAG, "onError: 出错"); |
327 | } | 333 | } |
328 | } | 334 | } |
329 | } | 335 | } |
330 | 336 |
app/src/main/java/com/hjx/parent/ErrorDetailActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | ||
4 | import android.graphics.Color; | ||
3 | import android.os.Bundle; | 5 | import android.os.Bundle; |
6 | import android.os.Handler; | ||
4 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
8 | import android.view.MotionEvent; | ||
5 | import android.view.View; | 9 | import android.view.View; |
6 | import android.webkit.WebSettings; | 10 | import android.webkit.WebSettings; |
7 | import android.widget.AdapterView; | 11 | import android.widget.AdapterView; |
8 | import android.widget.RadioButton; | 12 | import android.widget.RadioButton; |
9 | import android.widget.RadioGroup; | 13 | import android.widget.RadioGroup; |
10 | 14 | ||
11 | import com.bumptech.glide.Glide; | 15 | import com.bumptech.glide.Glide; |
12 | import com.hjx.parent.databinding.ActivityErrorDetailBinding; | 16 | import com.hjx.parent.databinding.ActivityErrorDetailBinding; |
13 | import com.hjx.parent.dialog.ErrorEditDialog; | 17 | import com.hjx.parent.dialog.ErrorEditDialog; |
14 | import com.prws.common.bean.ErrorDetailBean; | 18 | import com.prws.common.bean.ErrorDetailBean; |
15 | import com.prws.common.bean.ResponseResult; | 19 | import com.prws.common.bean.ResponseResult; |
16 | import com.prws.common.bean.TopicBean; | 20 | import com.prws.common.bean.TopicBean; |
17 | import com.prws.common.net.NetWorks; | 21 | import com.prws.common.net.NetWorks; |
18 | import com.prws.common.utils.CommonUtil; | 22 | import com.prws.common.utils.CommonUtil; |
19 | import com.prws.common.utils.StringUtils; | 23 | import com.prws.common.utils.StringUtils; |
20 | 24 | ||
21 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
22 | import java.util.HashMap; | 26 | import java.util.HashMap; |
23 | import java.util.List; | 27 | import java.util.List; |
24 | import java.util.Map; | 28 | import java.util.Map; |
25 | 29 | ||
26 | import io.reactivex.Observer; | 30 | import io.reactivex.Observer; |
27 | import io.reactivex.disposables.Disposable; | 31 | import io.reactivex.disposables.Disposable; |
28 | 32 | ||
29 | public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding> { | 33 | public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding> { |
30 | private TopicBean bean; | 34 | private TopicBean bean; |
31 | 35 | ||
32 | @Override | 36 | @Override |
33 | public void initView(Bundle savedInstanceState) { | 37 | public void initView(Bundle savedInstanceState) { |
34 | bean = (TopicBean) getIntent().getSerializableExtra("errorBean"); | 38 | bean = (TopicBean) getIntent().getSerializableExtra("errorBean"); |
35 | loadError(); | 39 | loadError(); |
36 | } | 40 | } |
37 | 41 | ||
38 | public void loadError() { | 42 | public void loadError() { |
39 | if (bean.getBean() != null) { | 43 | if (bean.getBean() != null) { |
44 | binding.tvTip.setVisibility(View.GONE); | ||
40 | ErrorDetailBean errorDetailBean = bean.getBean(); | 45 | ErrorDetailBean errorDetailBean = bean.getBean(); |
41 | if (TextUtils.isEmpty(errorDetailBean.getContent())) { | 46 | if (TextUtils.isEmpty(errorDetailBean.getContent())) { |
42 | binding.llOrigin.setVisibility(View.GONE); | 47 | binding.llOrigin.setVisibility(View.GONE); |
43 | } else { | 48 | } else { |
44 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; | 49 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
45 | StringBuilder sb = new StringBuilder(4096); | 50 | StringBuilder sb = new StringBuilder(4096); |
46 | if (!TextUtils.isEmpty(errorDetailBean.getLabel())) { | 51 | if (!TextUtils.isEmpty(errorDetailBean.getLabel())) { |
47 | sb.append(errorDetailBean.getLabel()); | 52 | sb.append(errorDetailBean.getLabel()); |
48 | } | 53 | } |
49 | sb.append(errorDetailBean.getContent()); | 54 | sb.append(errorDetailBean.getContent()); |
50 | if (errorDetailBean.getOptions() != null && errorDetailBean.getOptions().size() > 0) { | 55 | if (errorDetailBean.getOptions() != null && errorDetailBean.getOptions().size() > 0) { |
51 | sb.append("<div class='pt1'>"); | 56 | sb.append("<div class='pt1'>"); |
52 | sb.append(StringUtils.OptionsHtml(errorDetailBean.getOptions(), null)); | 57 | sb.append(StringUtils.OptionsHtml(errorDetailBean.getOptions(), null)); |
53 | sb.append("</div>"); | 58 | sb.append("</div>"); |
54 | } | 59 | } |
55 | String body = "<html><header>" + linkCss + "</header>" + sb.toString() + "</body></html>"; | 60 | String body = "<html><header>" + linkCss + "</header>" + sb.toString() + "</body></html>"; |
56 | binding.webContent.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); | 61 | binding.webContent.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
57 | binding.webContent.setVisibility(View.VISIBLE); | 62 | binding.webContent.setVisibility(View.VISIBLE); |
58 | binding.llOrigin.setVisibility(View.VISIBLE); | 63 | binding.llOrigin.setVisibility(View.VISIBLE); |
64 | binding.webContent.setOnTouchListener(new View.OnTouchListener() { | ||
65 | @Override | ||
66 | public boolean onTouch(View v, MotionEvent event) { | ||
67 | return true; | ||
68 | } | ||
69 | }); | ||
59 | } | 70 | } |
71 | |||
60 | if (TextUtils.isEmpty(errorDetailBean.getMethod())) { | 72 | if (TextUtils.isEmpty(errorDetailBean.getMethod())) { |
61 | binding.llAnalyse.setVisibility(View.GONE); | 73 | binding.llAnalyse.setVisibility(View.GONE); |
62 | } else { | 74 | } else { |
63 | binding.llAnalyse.setVisibility(View.VISIBLE); | 75 | binding.llAnalyse.setVisibility(View.VISIBLE); |
64 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; | 76 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
65 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getMethod() + "</body></html>"; | 77 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getMethod() + "</body></html>"; |
66 | binding.webAnalyse.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); | 78 | binding.webAnalyse.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
79 | binding.webAnalyse.setBackgroundColor(Color.parseColor("#F5F5F5")); | ||
67 | } | 80 | } |
68 | if (TextUtils.isEmpty(errorDetailBean.getDisplayAnswer())) { | 81 | if (TextUtils.isEmpty(errorDetailBean.getDisplayAnswer())) { |
69 | binding.llAnswer.setVisibility(View.GONE); | 82 | binding.llAnswer.setVisibility(View.GONE); |
70 | } else { | 83 | } else { |
71 | binding.llAnswer.setVisibility(View.VISIBLE); | 84 | binding.llAnswer.setVisibility(View.VISIBLE); |
72 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; | 85 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
73 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getDisplayAnswer() + "</body></html>"; | 86 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getDisplayAnswer() + "</body></html>"; |
74 | binding.webAnswer.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); | 87 | binding.webAnswer.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
88 | binding.webAnswer.setBackgroundColor(Color.parseColor("#F5F5F5")); | ||
75 | } | 89 | } |
76 | if (errorDetailBean.getPoints().size() > 0) { | 90 | if (errorDetailBean.getPoints().size() > 0) { |
77 | List<String> points = new ArrayList<>(); | 91 | List<String> points = new ArrayList<>(); |
78 | String topic = ""; | 92 | String topic = ""; |
79 | for (int j = 0; j < errorDetailBean.getPoints().size(); j++) { | 93 | for (int j = 0; j < errorDetailBean.getPoints().size(); j++) { |
80 | if (j > 0) { | 94 | if (j > 0) { |
81 | topic += "、"; | 95 | topic += "、"; |
82 | } | 96 | } |
83 | topic += errorDetailBean.getPoints().get(j).getValue(); | 97 | topic += errorDetailBean.getPoints().get(j).getValue(); |
84 | points.add(errorDetailBean.getPoints().get(j).getKey()); | 98 | points.add(errorDetailBean.getPoints().get(j).getKey()); |
85 | } | 99 | } |
86 | binding.llPoints.setVisibility(View.VISIBLE); | 100 | binding.llPoints.setVisibility(View.VISIBLE); |
87 | binding.tvPoints.setText(topic); | 101 | binding.tvPoints.setText(topic); |
88 | } else { | 102 | } else { |
89 | binding.llPoints.setVisibility(View.GONE); | 103 | binding.llPoints.setVisibility(View.GONE); |
90 | } | 104 | } |
91 | } else { | 105 | } else { |
106 | binding.tvTip.setVisibility(View.VISIBLE); | ||
92 | binding.llAnalyse.setVisibility(View.GONE); | 107 | binding.llAnalyse.setVisibility(View.GONE); |
93 | binding.llAnswer.setVisibility(View.GONE); | 108 | binding.llAnswer.setVisibility(View.GONE); |
94 | binding.llOrigin.setVisibility(View.GONE); | 109 | binding.llOrigin.setVisibility(View.GONE); |
95 | binding.llPoints.setVisibility(View.GONE); | 110 | binding.llPoints.setVisibility(View.GONE); |
96 | } | 111 | } |
97 | if (TextUtils.isEmpty(bean.getPath())) { | 112 | if (TextUtils.isEmpty(bean.getPath())) { |
98 | binding.llPic.setVisibility(View.GONE); | 113 | binding.llPic.setVisibility(View.GONE); |
99 | } else { | 114 | } else { |
100 | Glide.with(context).load(bean.getPath()).override(CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 40), CommonUtil.dpToPx(context, 90)).fitCenter().into(binding.ivTopic); | 115 | Glide.with(context).load(bean.getPath()).override(CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 40), CommonUtil.dpToPx(context, 90)).fitCenter().into(binding.ivTopic); |
101 | } | 116 | } |
102 | binding.tvTitle.setText(bean.getName()); | 117 | binding.tvTitle.setText(bean.getName()); |
103 | RadioButton typeButton = (RadioButton) binding.typeRadio.getChildAt(bean.getIsDone()); | 118 | RadioButton typeButton = (RadioButton) binding.typeRadio.getChildAt(bean.getIsDone()); |
104 | typeButton.setChecked(true); | 119 | typeButton.setChecked(true); |
105 | binding.typeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | 120 | binding.typeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
106 | @Override | 121 | @Override |
107 | public void onCheckedChanged(RadioGroup group, int checkedId) { | 122 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
108 | saveError(); | 123 | new Handler().postDelayed(new Runnable() { |
124 | @Override | ||
125 | public void run() { | ||
126 | saveError(); | ||
127 | } | ||
128 | }, 1000); | ||
129 | |||
109 | } | 130 | } |
110 | }); | 131 | }); |
111 | binding.spinnerReason.setSelection(bean.getReason()); | 132 | binding.spinnerReason.setSelection(bean.getReason()); |
112 | binding.spinnerReason.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 133 | binding.spinnerReason.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
113 | @Override | 134 | @Override |
114 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 135 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
115 | saveError(); | 136 | saveError(); |
116 | } | 137 | } |
117 | 138 | ||
118 | @Override | 139 | @Override |
119 | public void onNothingSelected(AdapterView<?> parent) { | 140 | public void onNothingSelected(AdapterView<?> parent) { |
120 | 141 | ||
121 | } | 142 | } |
122 | }); | 143 | }); |
123 | binding.ivBack.setOnClickListener(new View.OnClickListener() { | 144 | binding.ivBack.setOnClickListener(new View.OnClickListener() { |
124 | @Override | 145 | @Override |
125 | public void onClick(View v) { | 146 | public void onClick(View v) { |
126 | finish(); | 147 | finish(); |
127 | } | 148 | } |
128 | }); | 149 | }); |
129 | binding.ivEdit.setOnClickListener(new View.OnClickListener() { | 150 | binding.ivEdit.setOnClickListener(new View.OnClickListener() { |
130 | @Override | 151 | @Override |
131 | public void onClick(View v) { | 152 | public void onClick(View v) { |
132 | List<TopicBean> topicBeans = new ArrayList<>(); | 153 | List<TopicBean> topicBeans = new ArrayList<>(); |
133 | topicBeans.add(bean); | 154 | topicBeans.add(bean); |
134 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, topicBeans, new ErrorEditDialog.EditInterface() { | 155 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, topicBeans, new ErrorEditDialog.EditInterface() { |
135 | @Override | 156 | @Override |
136 | public void edit(String name, int reason) { | 157 | public void edit(String name, int reason) { |
137 | binding.tvTitle.setText(name); | 158 | binding.tvTitle.setText(name); |
138 | binding.spinnerReason.setSelection(reason); | 159 | binding.spinnerReason.setSelection(reason); |
139 | } | 160 | } |
140 | }); | 161 | }); |
141 | errorEditDialog.show(); | 162 | errorEditDialog.show(); |
142 | } | 163 | } |
143 | }); | 164 | }); |
144 | } | 165 | } |
145 | 166 | ||
146 | public void saveError() { | 167 | public void saveError() { |
147 | int done = 0; | 168 | int done = 0; |
148 | for (int i = 0; i < binding.typeRadio.getChildCount(); i++) { | 169 | for (int i = 0; i < binding.typeRadio.getChildCount(); i++) { |
149 | RadioButton rb = (RadioButton) binding.typeRadio.getChildAt(i); | 170 | RadioButton rb = (RadioButton) binding.typeRadio.getChildAt(i); |
150 | if (rb.isChecked()) { | 171 | if (rb.isChecked()) { |
151 | done = i; | 172 | done = i; |
152 | } | 173 | } |
153 | } | 174 | } |
154 | bean.setDone(done == 1); | 175 | bean.setDone(done == 1); |
155 | Map<String, Object> map = new HashMap<>(); | 176 | Map<String, Object> map = new HashMap<>(); |
156 | map.put("bookId", bean.getId()); | 177 | map.put("bookId", bean.getId()); |
157 | map.put("controlFlag", done == 1 ? 0 : 1); | 178 | map.put("controlFlag", done); |
158 | map.put("errorReason", binding.spinnerReason.getSelectedItemPosition()); | 179 | map.put("errorReason", binding.spinnerReason.getSelectedItemPosition()); |
159 | NetWorks.editError(map, new Observer<ResponseResult>() { | 180 | NetWorks.editError(map, new Observer<ResponseResult>() { |
160 | @Override | 181 | @Override |
161 | public void onSubscribe(Disposable d) { | 182 | public void onSubscribe(Disposable d) { |
162 | 183 | ||
163 | } | 184 | } |
164 | 185 | ||
165 | @Override | 186 | @Override |
166 | public void onNext(ResponseResult responseResult) { | 187 | public void onNext(ResponseResult responseResult) { |
167 | 188 | responseResult.toString(); | |
168 | } | 189 | } |
169 | 190 | ||
170 | @Override | 191 | @Override |
171 | public void onError(Throwable e) { | 192 | public void onError(Throwable e) { |
172 | 193 | ||
173 | } | 194 | } |
174 | 195 | ||
175 | @Override | 196 | @Override |
176 | public void onComplete() { | 197 | public void onComplete() { |
177 | 198 | ||
178 | } | 199 | } |
179 | }); | 200 | }); |
180 | } | 201 | } |
181 | 202 | ||
182 | @Override | 203 | @Override |
183 | protected ActivityErrorDetailBinding getViewBinding() { | 204 | protected ActivityErrorDetailBinding getViewBinding() { |
184 | return ActivityErrorDetailBinding.inflate(getLayoutInflater()); | 205 | return ActivityErrorDetailBinding.inflate(getLayoutInflater()); |
185 | } | 206 | } |
186 | } | 207 | } |
187 | 208 |
app/src/main/java/com/hjx/parent/ErrorListActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.app.Dialog; | 3 | import android.app.Dialog; |
4 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
5 | import android.content.Intent; | 5 | import android.content.Intent; |
6 | import android.graphics.Bitmap; | 6 | import android.graphics.Bitmap; |
7 | import android.graphics.BitmapFactory; | 7 | import android.graphics.BitmapFactory; |
8 | import android.graphics.Color; | 8 | import android.graphics.Color; |
9 | import android.graphics.drawable.Drawable; | 9 | import android.graphics.drawable.Drawable; |
10 | import android.net.Uri; | 10 | import android.net.Uri; |
11 | import android.os.Bundle; | 11 | import android.os.Bundle; |
12 | import android.provider.MediaStore; | 12 | import android.provider.MediaStore; |
13 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
14 | import android.util.Log; | 14 | import android.util.Log; |
15 | import android.view.KeyEvent; | 15 | import android.view.KeyEvent; |
16 | import android.view.LayoutInflater; | 16 | import android.view.LayoutInflater; |
17 | import android.view.View; | 17 | import android.view.View; |
18 | import android.widget.CompoundButton; | 18 | import android.widget.CompoundButton; |
19 | import android.widget.RadioButton; | 19 | import android.widget.RadioButton; |
20 | import android.widget.RadioGroup; | 20 | import android.widget.RadioGroup; |
21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
22 | import android.widget.Toast; | 22 | import android.widget.Toast; |
23 | 23 | ||
24 | import androidx.annotation.Nullable; | 24 | import androidx.annotation.Nullable; |
25 | import androidx.core.content.FileProvider; | 25 | import androidx.core.content.FileProvider; |
26 | import androidx.recyclerview.widget.GridLayoutManager; | 26 | import androidx.recyclerview.widget.GridLayoutManager; |
27 | import androidx.recyclerview.widget.LinearLayoutManager; | 27 | import androidx.recyclerview.widget.LinearLayoutManager; |
28 | import androidx.recyclerview.widget.RecyclerView; | 28 | import androidx.recyclerview.widget.RecyclerView; |
29 | 29 | ||
30 | import com.google.gson.Gson; | 30 | import com.google.gson.Gson; |
31 | import com.hjq.permissions.OnPermissionCallback; | 31 | import com.hjq.permissions.OnPermissionCallback; |
32 | import com.hjq.permissions.Permission; | 32 | import com.hjq.permissions.Permission; |
33 | import com.hjq.permissions.XXPermissions; | 33 | import com.hjq.permissions.XXPermissions; |
34 | import com.hjx.parent.adapter.ErrorAdapter; | 34 | import com.hjx.parent.adapter.ErrorAdapter; |
35 | import com.hjx.parent.adapter.FilterAdapter; | 35 | import com.hjx.parent.adapter.FilterAdapter; |
36 | import com.hjx.parent.adapter.LoadMoreOnScrollListener; | 36 | import com.hjx.parent.adapter.LoadMoreOnScrollListener; |
37 | import com.hjx.parent.bean.StudentBean; | 37 | import com.hjx.parent.bean.StudentBean; |
38 | import com.hjx.parent.databinding.ActivityErrorListBinding; | 38 | import com.hjx.parent.databinding.ActivityErrorListBinding; |
39 | import com.hjx.parent.dialog.ErrorEditDialog; | 39 | import com.hjx.parent.dialog.ErrorEditDialog; |
40 | import com.hjx.parent.dialog.TipDialog; | 40 | import com.hjx.parent.dialog.TipDialog; |
41 | import com.prws.common.bean.GradeAndSubject; | 41 | import com.prws.common.bean.GradeAndSubject; |
42 | import com.prws.common.bean.PageInfo; | 42 | import com.prws.common.bean.PageInfo; |
43 | import com.prws.common.bean.ResponseResult; | 43 | import com.prws.common.bean.ResponseResult; |
44 | import com.prws.common.bean.Subject; | 44 | import com.prws.common.bean.Subject; |
45 | import com.prws.common.bean.TopicBean; | 45 | import com.prws.common.bean.TopicBean; |
46 | import com.prws.common.net.NetWorks; | 46 | import com.prws.common.net.NetWorks; |
47 | import com.prws.common.utils.BitmapUtils; | 47 | import com.prws.common.utils.BitmapUtils; |
48 | import com.prws.common.utils.CommonUtil; | 48 | import com.prws.common.utils.CommonUtil; |
49 | import com.prws.common.utils.SharedPreferencesUtil; | 49 | import com.prws.common.utils.SharedPreferencesUtil; |
50 | import com.prws.common.utils.dialog.MyButtomDialog; | 50 | import com.prws.common.utils.dialog.MyButtomDialog; |
51 | import com.zhangteng.imagepicker.bean.ImageInfo; | 51 | import com.zhangteng.imagepicker.bean.ImageInfo; |
52 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 52 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
53 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 53 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
54 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 54 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
55 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 55 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
56 | import com.zhangteng.utils.IHandlerCallBack; | 56 | import com.zhangteng.utils.IHandlerCallBack; |
57 | 57 | ||
58 | import java.io.File; | 58 | import java.io.File; |
59 | import java.util.ArrayList; | 59 | import java.util.ArrayList; |
60 | import java.util.HashMap; | 60 | import java.util.HashMap; |
61 | import java.util.List; | 61 | import java.util.List; |
62 | import java.util.Map; | 62 | import java.util.Map; |
63 | 63 | ||
64 | import io.reactivex.Observer; | 64 | import io.reactivex.Observer; |
65 | import io.reactivex.disposables.Disposable; | 65 | import io.reactivex.disposables.Disposable; |
66 | 66 | ||
67 | public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> implements View.OnClickListener { | 67 | public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> implements View.OnClickListener { |
68 | private TextView last; | 68 | private TextView last; |
69 | private String subject; | 69 | private String subject; |
70 | private String grade; | 70 | private String grade; |
71 | private String manger; | 71 | private String manger; |
72 | private String type = "全部"; | 72 | private String type = "全部"; |
73 | private String time = "全部"; | 73 | private String time = "全部"; |
74 | private FilterAdapter filterAdapter; | 74 | private FilterAdapter filterAdapter; |
75 | StudentBean studentBean; | 75 | StudentBean studentBean; |
76 | private int page = 1; | 76 | private int page = 1; |
77 | private ErrorAdapter adapter; | 77 | private ErrorAdapter adapter; |
78 | private int total; | 78 | private int total; |
79 | private int REQUEST_CODE_IMAGE = 123; | 79 | private int REQUEST_CODE_IMAGE = 123; |
80 | private String filePath; | 80 | private String filePath; |
81 | 81 | ||
82 | @Override | 82 | @Override |
83 | public void initView(Bundle savedInstanceState) { | 83 | public void initView(Bundle savedInstanceState) { |
84 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 84 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
85 | try { | 85 | try { |
86 | studentBean = new Gson().fromJson(student, StudentBean.class); | 86 | studentBean = new Gson().fromJson(student, StudentBean.class); |
87 | } catch (Exception e) { | 87 | } catch (Exception e) { |
88 | 88 | ||
89 | } | 89 | } |
90 | binding.ivBack.setOnClickListener(this); | 90 | binding.ivBack.setOnClickListener(this); |
91 | binding.tvFilterGrade.setOnClickListener(this); | 91 | binding.tvFilterGrade.setOnClickListener(this); |
92 | binding.tvFilterSubject.setOnClickListener(this); | 92 | binding.tvFilterSubject.setOnClickListener(this); |
93 | binding.tvFilterMore.setOnClickListener(this); | 93 | binding.tvFilterMore.setOnClickListener(this); |
94 | binding.tvFilterManage.setOnClickListener(this); | 94 | binding.tvFilterManage.setOnClickListener(this); |
95 | binding.tvEdit.setOnClickListener(this); | 95 | binding.tvEdit.setOnClickListener(this); |
96 | binding.tvAdd.setOnClickListener(this); | 96 | binding.tvAdd.setOnClickListener(this); |
97 | binding.llDelete.setOnClickListener(this); | 97 | binding.llDelete.setOnClickListener(this); |
98 | binding.tvSave.setOnClickListener(this); | 98 | binding.tvSave.setOnClickListener(this); |
99 | binding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | 99 | binding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
100 | @Override | 100 | @Override |
101 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | 101 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
102 | adapter.checkAll(isChecked); | 102 | adapter.checkAll(isChecked); |
103 | } | 103 | } |
104 | }); | 104 | }); |
105 | RadioButton timeButton = (RadioButton) binding.groupTime.getChildAt(3); | 105 | RadioButton timeButton = (RadioButton) binding.groupTime.getChildAt(3); |
106 | timeButton.setChecked(true); | 106 | timeButton.setChecked(true); |
107 | binding.groupTime.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | 107 | binding.groupTime.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
108 | @Override | 108 | @Override |
109 | public void onCheckedChanged(RadioGroup group, int checkedId) { | 109 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
110 | RadioButton rcheck = (RadioButton) findViewById(checkedId); | 110 | RadioButton rcheck = (RadioButton) findViewById(checkedId); |
111 | time = rcheck.getText().toString(); | 111 | time = rcheck.getText().toString(); |
112 | refreshError(); | 112 | refreshError(); |
113 | } | 113 | } |
114 | }); | 114 | }); |
115 | 115 | ||
116 | RadioButton typeButton = (RadioButton) binding.groupType.getChildAt(2); | 116 | RadioButton typeButton = (RadioButton) binding.groupType.getChildAt(2); |
117 | typeButton.setChecked(true); | 117 | typeButton.setChecked(true); |
118 | binding.groupType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | 118 | binding.groupType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
119 | @Override | 119 | @Override |
120 | public void onCheckedChanged(RadioGroup group, int checkedId) { | 120 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
121 | RadioButton rcheck = (RadioButton) findViewById(checkedId); | 121 | RadioButton rcheck = (RadioButton) findViewById(checkedId); |
122 | type = rcheck.getText().toString(); | 122 | type = rcheck.getText().toString(); |
123 | refreshError(); | 123 | refreshError(); |
124 | } | 124 | } |
125 | }); | 125 | }); |
126 | refreshError(); | 126 | refreshError(); |
127 | } | 127 | } |
128 | 128 | ||
129 | @Override | 129 | @Override |
130 | protected ActivityErrorListBinding getViewBinding() { | 130 | protected ActivityErrorListBinding getViewBinding() { |
131 | return ActivityErrorListBinding.inflate(getLayoutInflater()); | 131 | return ActivityErrorListBinding.inflate(getLayoutInflater()); |
132 | } | 132 | } |
133 | 133 | ||
134 | |||
135 | |||
134 | @Override | 136 | @Override |
135 | public void onClick(View v) { | 137 | public void onClick(View v) { |
136 | switch (v.getId()) { | 138 | switch (v.getId()) { |
137 | case R.id.iv_back: | 139 | case R.id.iv_back: |
138 | finish(); | 140 | finish(); |
139 | break; | 141 | break; |
140 | case R.id.tv_filter_grade: | 142 | case R.id.tv_filter_grade: |
141 | List<String> grades = new ArrayList<>(); | 143 | List<String> grades = new ArrayList<>(); |
142 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { | 144 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { |
143 | grades.add(gradeAndSubject.getGrade().getGrade()); | 145 | grades.add(gradeAndSubject.getGrade().getGrade()); |
144 | } | 146 | } |
145 | grades.add("全部"); | 147 | grades.add("全部"); |
146 | setFilterAdapter(grades, binding.tvFilterGrade, grade); | 148 | setFilterAdapter(grades, binding.tvFilterGrade, grade); |
147 | break; | 149 | break; |
148 | case R.id.tv_filter_subject: | 150 | case R.id.tv_filter_subject: |
149 | List<String> subjects = new ArrayList<>(); | 151 | List<String> subjects = new ArrayList<>(); |
150 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { | 152 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { |
151 | for (Subject subject : gradeAndSubject.getSubjects()) { | 153 | for (Subject subject : gradeAndSubject.getSubjects()) { |
152 | if (!subjects.contains(subject.getSubject())) { | 154 | if (!subjects.contains(subject.getSubject())) { |
153 | subjects.add(subject.getSubject()); | 155 | subjects.add(subject.getSubject()); |
154 | } | 156 | } |
155 | } | 157 | } |
156 | } | 158 | } |
157 | subjects.add("全部"); | 159 | subjects.add("全部"); |
158 | setFilterAdapter(subjects, binding.tvFilterSubject, subject); | 160 | setFilterAdapter(subjects, binding.tvFilterSubject, subject); |
159 | break; | 161 | break; |
160 | case R.id.tv_filter_manage: | 162 | case R.id.tv_filter_manage: |
161 | List<String> manages = new ArrayList<>(); | 163 | List<String> manages = new ArrayList<>(); |
162 | manages.add("已掌握"); | 164 | manages.add("已掌握"); |
163 | manages.add("未掌握"); | 165 | manages.add("未掌握"); |
164 | manages.add("全部"); | 166 | manages.add("全部"); |
165 | setFilterAdapter(manages, binding.tvFilterManage, manger); | 167 | setFilterAdapter(manages, binding.tvFilterManage, manger); |
166 | break; | 168 | break; |
167 | case R.id.tv_filter_more: | 169 | case R.id.tv_filter_more: |
168 | showFilterMore(); | 170 | showFilterMore(); |
169 | break; | 171 | break; |
170 | case R.id.tv_edit: | 172 | case R.id.tv_edit: |
171 | if (adapter.edit) { | 173 | if (adapter.edit) { |
172 | adapter.setEdit(false); | 174 | adapter.setEdit(false); |
173 | binding.tvSave.setVisibility(View.GONE); | 175 | binding.tvSave.setVisibility(View.GONE); |
174 | binding.tvAdd.setVisibility(View.VISIBLE); | 176 | binding.tvAdd.setVisibility(View.VISIBLE); |
175 | binding.checkbox.setVisibility(View.GONE); | 177 | binding.checkbox.setVisibility(View.GONE); |
176 | binding.llDelete.setVisibility(View.GONE); | 178 | binding.llDelete.setVisibility(View.GONE); |
177 | binding.ivBack.setVisibility(View.VISIBLE); | 179 | binding.ivBack.setVisibility(View.VISIBLE); |
178 | binding.tvEdit.setText("编辑"); | 180 | binding.tvEdit.setText("编辑"); |
179 | } else { | 181 | } else { |
180 | adapter.setEdit(true); | 182 | adapter.setEdit(true); |
181 | binding.tvSave.setVisibility(View.VISIBLE); | 183 | binding.tvSave.setVisibility(View.VISIBLE); |
182 | binding.tvAdd.setVisibility(View.GONE); | 184 | binding.tvAdd.setVisibility(View.GONE); |
183 | binding.llDelete.setVisibility(View.VISIBLE); | 185 | binding.llDelete.setVisibility(View.VISIBLE); |
184 | binding.checkbox.setVisibility(View.VISIBLE); | 186 | binding.checkbox.setVisibility(View.VISIBLE); |
185 | binding.ivBack.setVisibility(View.GONE); | 187 | binding.ivBack.setVisibility(View.GONE); |
186 | binding.tvEdit.setText("取消"); | 188 | binding.tvEdit.setText("取消"); |
187 | } | 189 | } |
188 | adapter.notifyDataSetChanged(); | 190 | adapter.notifyDataSetChanged(); |
189 | break; | 191 | break; |
190 | case R.id.ll_delete: | 192 | case R.id.ll_delete: |
191 | showTipDialog("温馨提示", "确认删除已勾选的错题?", "取消", "确认", new TipDialog.TipDialogInterface() { | 193 | showTipDialog("温馨提示", "确认删除已勾选的错题?", "取消", "确认", new TipDialog.TipDialogInterface() { |
192 | @Override | 194 | @Override |
193 | public void onConfirm(Dialog dialog) { | 195 | public void onConfirm(Dialog dialog) { |
194 | deleteError(adapter.getChecKList()); | 196 | deleteError(adapter.getChecKList()); |
195 | dialog.dismiss(); | 197 | dialog.dismiss(); |
196 | } | 198 | } |
197 | 199 | ||
198 | @Override | 200 | @Override |
199 | public void onCancel(Dialog dialog) { | 201 | public void onCancel(Dialog dialog) { |
200 | dialog.dismiss(); | 202 | dialog.dismiss(); |
201 | } | 203 | } |
202 | }); | 204 | }); |
203 | break; | 205 | break; |
204 | case R.id.tv_add: | 206 | case R.id.tv_add: |
205 | if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | 207 | if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.MANAGE_EXTERNAL_STORAGE)) { |
206 | XXPermissions.with(context) | 208 | XXPermissions.with(context) |
207 | // 申请多个权限 | 209 | // 申请多个权限 |
208 | .permission(Permission.CAMERA) | 210 | .permission(Permission.CAMERA, Permission.MANAGE_EXTERNAL_STORAGE) |
209 | .request(new OnPermissionCallback() { | 211 | .request(new OnPermissionCallback() { |
210 | @Override | 212 | @Override |
211 | public void onGranted(List<String> permissions, boolean all) { | 213 | public void onGranted(List<String> permissions, boolean all) { |
212 | if (all) { | 214 | if (all) { |
213 | //开启扫码界面 | 215 | //开启扫码界面 |
214 | showButtonDialog(); | 216 | showButtonDialog(); |
215 | } else { | 217 | } else { |
216 | Toast.makeText(context, "需要权限", Toast.LENGTH_SHORT).show(); | 218 | Toast.makeText(context, "需要权限", Toast.LENGTH_SHORT).show(); |
217 | } | 219 | } |
218 | } | 220 | } |
219 | 221 | ||
220 | @Override | 222 | @Override |
221 | public void onDenied(List<String> permissions, boolean never) { | 223 | public void onDenied(List<String> permissions, boolean never) { |
222 | XXPermissions.startPermissionActivity(context, permissions); | 224 | XXPermissions.startPermissionActivity(context, permissions); |
223 | } | 225 | } |
224 | }); | 226 | }); |
225 | } else { | 227 | } else { |
226 | showButtonDialog(); | 228 | showButtonDialog(); |
227 | } | 229 | } |
228 | break; | 230 | break; |
229 | case R.id.tv_save: | 231 | case R.id.tv_save: |
230 | if (adapter.getChecKList().size() > 0) { | 232 | if (adapter.getChecKList().size() > 0) { |
231 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, adapter.getChecKList(), new ErrorEditDialog.EditInterface() { | 233 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, adapter.getChecKList(), new ErrorEditDialog.EditInterface() { |
232 | @Override | 234 | @Override |
233 | public void edit(String s, int i) { | 235 | public void edit(String s, int i) { |
234 | adapter.setEdit(false); | 236 | adapter.setEdit(false); |
235 | binding.tvSave.setVisibility(View.GONE); | 237 | binding.tvSave.setVisibility(View.GONE); |
236 | binding.tvAdd.setVisibility(View.VISIBLE); | 238 | binding.tvAdd.setVisibility(View.VISIBLE); |
237 | binding.checkbox.setVisibility(View.GONE); | 239 | binding.checkbox.setVisibility(View.GONE); |
238 | binding.llDelete.setVisibility(View.GONE); | 240 | binding.llDelete.setVisibility(View.GONE); |
239 | binding.ivBack.setVisibility(View.VISIBLE); | 241 | binding.ivBack.setVisibility(View.VISIBLE); |
240 | binding.tvEdit.setText("编辑"); | 242 | binding.tvEdit.setText("编辑"); |
241 | page = 1; | 243 | page = 1; |
242 | refreshError(); | 244 | refreshError(); |
243 | } | 245 | } |
244 | }); | 246 | }); |
245 | errorEditDialog.show(); | 247 | errorEditDialog.show(); |
246 | } | 248 | } |
247 | break; | 249 | break; |
248 | } | 250 | } |
249 | } | 251 | } |
250 | 252 | ||
251 | private void showButtonDialog() { | 253 | private void showButtonDialog() { |
252 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); | 254 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); |
253 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); | 255 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); |
254 | dialog.setContentView(bottomView); | 256 | dialog.setContentView(bottomView); |
255 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 257 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
256 | @Override | 258 | @Override |
257 | public void onClick(View view) { | 259 | public void onClick(View view) { |
258 | dialog.dismiss(); | 260 | dialog.dismiss(); |
259 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 261 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
260 | //确保有相机来处理Intent | 262 | //确保有相机来处理Intent |
261 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 263 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
262 | File photoFile = new File(filePath); | 264 | File photoFile = new File(filePath); |
263 | if (photoFile != null) { | 265 | if (photoFile != null) { |
264 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 266 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
265 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 267 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
266 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 268 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
267 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 269 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
268 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | 270 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); |
269 | } | 271 | } |
270 | } | 272 | } |
271 | }); | 273 | }); |
272 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 274 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
273 | @Override | 275 | @Override |
274 | public void onClick(View view) { | 276 | public void onClick(View view) { |
275 | dialog.dismiss(); | 277 | dialog.dismiss(); |
276 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | 278 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
277 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | 279 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) |
278 | .multiSelect(true) //是否多选 | 280 | .multiSelect(true) //是否多选 |
279 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | 281 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
280 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | 282 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
281 | .maxImageSelectable(9) //图片可选择数 | 283 | .maxImageSelectable(9) //图片可选择数 |
282 | .maxHeight(1920) //图片最大高度 | 284 | .maxHeight(1920) //图片最大高度 |
283 | .maxWidth(1920) //图片最大宽度 | 285 | .maxWidth(1920) //图片最大宽度 |
284 | .maxImageSize(10) //图片最大大小Mb | 286 | .maxImageSize(10) //图片最大大小Mb |
285 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | 287 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); |
286 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorListActivity.this); | 288 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorListActivity.this); |
287 | 289 | ||
288 | } | 290 | } |
289 | }); | 291 | }); |
290 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 292 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
291 | @Override | 293 | @Override |
292 | public void onClick(View view) { | 294 | public void onClick(View view) { |
293 | dialog.dismiss(); | 295 | dialog.dismiss(); |
294 | } | 296 | } |
295 | }); | 297 | }); |
296 | dialog.show(); | 298 | dialog.show(); |
297 | } | 299 | } |
298 | 300 | ||
299 | private void deleteError(List<TopicBean> topicBeans) { | 301 | private void deleteError(List<TopicBean> topicBeans) { |
300 | List<String> list = new ArrayList<>(); | 302 | List<String> list = new ArrayList<>(); |
301 | for (int i = 0; i < topicBeans.size(); i++) { | 303 | for (int i = 0; i < topicBeans.size(); i++) { |
302 | list.add(topicBeans.get(i).getId()); | 304 | list.add(topicBeans.get(i).getId()); |
303 | } | 305 | } |
304 | NetWorks.deleteError(list, new Observer<ResponseResult>() { | 306 | NetWorks.deleteError(list, new Observer<ResponseResult>() { |
305 | @Override | 307 | @Override |
306 | public void onSubscribe(Disposable d) { | 308 | public void onSubscribe(Disposable d) { |
307 | 309 | ||
308 | } | 310 | } |
309 | 311 | ||
310 | @Override | 312 | @Override |
311 | public void onNext(ResponseResult responseResult) { | 313 | public void onNext(ResponseResult responseResult) { |
312 | if (responseResult.getCode() == 200) { | 314 | if (responseResult.getCode() == 200) { |
313 | adapter.setEdit(false); | 315 | adapter.setEdit(false); |
314 | binding.tvSave.setVisibility(View.GONE); | 316 | binding.tvSave.setVisibility(View.GONE); |
315 | binding.tvAdd.setVisibility(View.VISIBLE); | 317 | binding.tvAdd.setVisibility(View.VISIBLE); |
316 | binding.checkbox.setVisibility(View.GONE); | 318 | binding.checkbox.setVisibility(View.GONE); |
317 | binding.llDelete.setVisibility(View.GONE); | 319 | binding.llDelete.setVisibility(View.GONE); |
318 | binding.ivBack.setVisibility(View.VISIBLE); | 320 | binding.ivBack.setVisibility(View.VISIBLE); |
319 | binding.tvEdit.setText("编辑"); | 321 | binding.tvEdit.setText("编辑"); |
320 | page = 1; | 322 | page = 1; |
321 | refreshError(); | 323 | refreshError(); |
322 | } | 324 | } |
323 | } | 325 | } |
324 | 326 | ||
325 | @Override | 327 | @Override |
326 | public void onError(Throwable e) { | 328 | public void onError(Throwable e) { |
327 | 329 | ||
328 | } | 330 | } |
329 | 331 | ||
330 | @Override | 332 | @Override |
331 | public void onComplete() { | 333 | public void onComplete() { |
332 | 334 | ||
333 | } | 335 | } |
334 | }); | 336 | }); |
335 | } | 337 | } |
336 | 338 | ||
337 | private void showFilterMore() { | 339 | private void showFilterMore() { |
338 | binding.recycleFilter.setVisibility(View.GONE); | 340 | binding.recycleFilter.setVisibility(View.GONE); |
339 | if (binding.llFilterMore.getVisibility() == View.VISIBLE) { | 341 | if (binding.llFilterMore.getVisibility() == View.VISIBLE) { |
340 | binding.llFilterMore.setVisibility(View.GONE); | 342 | binding.llFilterMore.setVisibility(View.GONE); |
341 | } else { | 343 | } else { |
342 | binding.llFilterMore.setVisibility(View.VISIBLE); | 344 | binding.llFilterMore.setVisibility(View.VISIBLE); |
343 | if (last != null) { | 345 | if (last != null) { |
344 | last.setTextColor(getColor(R.color.text_title)); | 346 | last.setTextColor(getColor(R.color.text_title)); |
345 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 347 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
346 | // 这一步必须要做,否则不会显示. | 348 | // 这一步必须要做,否则不会显示. |
347 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 349 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
348 | last.setCompoundDrawables(null, null, drawable, null); | 350 | last.setCompoundDrawables(null, null, drawable, null); |
349 | } | 351 | } |
350 | binding.tvFilterMore.setTextColor(Color.parseColor("#1C90F3")); | 352 | binding.tvFilterMore.setTextColor(Color.parseColor("#1C90F3")); |
351 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); | 353 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); |
352 | // 这一步必须要做,否则不会显示. | 354 | // 这一步必须要做,否则不会显示. |
353 | drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight()); | 355 | drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight()); |
354 | binding.tvFilterMore.setCompoundDrawables(null, null, drawable1, null); | 356 | binding.tvFilterMore.setCompoundDrawables(null, null, drawable1, null); |
355 | last = binding.tvFilterMore; | 357 | last = binding.tvFilterMore; |
356 | } | 358 | } |
357 | } | 359 | } |
358 | 360 | ||
359 | private void setFilterAdapter(List<String> list, TextView textView, String select) { | 361 | private void setFilterAdapter(List<String> list, TextView textView, String select) { |
360 | if (TextUtils.isEmpty(select)) { | 362 | if (TextUtils.isEmpty(select)) { |
361 | select = "全部"; | 363 | select = "全部"; |
362 | } | 364 | } |
363 | binding.llFilterMore.setVisibility(View.GONE); | 365 | binding.llFilterMore.setVisibility(View.GONE); |
364 | if (last != null && last.getId() == R.id.tv_filter_more) { | 366 | if (last != null && last.getId() == R.id.tv_filter_more) { |
365 | last.setTextColor(getColor(R.color.text_title)); | 367 | last.setTextColor(getColor(R.color.text_title)); |
366 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 368 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
367 | // 这一步必须要做,否则不会显示. | 369 | // 这一步必须要做,否则不会显示. |
368 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 370 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
369 | last.setCompoundDrawables(null, null, drawable, null); | 371 | last.setCompoundDrawables(null, null, drawable, null); |
370 | } | 372 | } |
371 | if (binding.recycleFilter.getVisibility() == View.GONE) { | 373 | if (binding.recycleFilter.getVisibility() == View.GONE) { |
372 | if (filterAdapter != null) { | 374 | if (filterAdapter != null) { |
373 | filterAdapter.refresh(list, textView, select); | 375 | filterAdapter.refresh(list, textView, select); |
374 | } else { | 376 | } else { |
375 | filterAdapter = new FilterAdapter(context, new FilterAdapter.Filter() { | 377 | filterAdapter = new FilterAdapter(context, new FilterAdapter.Filter() { |
376 | @Override | 378 | @Override |
377 | public void onSelect(TextView type, String select) { | 379 | public void onSelect(TextView type, String select) { |
378 | switch (type.getId()) { | 380 | switch (type.getId()) { |
379 | case R.id.tv_filter_grade: | 381 | case R.id.tv_filter_grade: |
380 | grade = select; | 382 | grade = select; |
381 | break; | 383 | break; |
382 | case R.id.tv_filter_subject: | 384 | case R.id.tv_filter_subject: |
383 | subject = select; | 385 | subject = select; |
384 | break; | 386 | break; |
385 | case R.id.tv_filter_manage: | 387 | case R.id.tv_filter_manage: |
386 | manger = select; | 388 | manger = select; |
387 | break; | 389 | break; |
388 | } | 390 | } |
389 | page = 1; | 391 | page = 1; |
390 | filterAdapter.refresh(select); | 392 | filterAdapter.refresh(select); |
391 | refreshError(); | 393 | refreshError(); |
392 | } | 394 | } |
393 | }, list, textView, select); | 395 | }, list, textView, select); |
394 | binding.recycleFilter.setLayoutManager(new GridLayoutManager(context, 4, LinearLayoutManager.VERTICAL, false)); | 396 | binding.recycleFilter.setLayoutManager(new GridLayoutManager(context, 4, LinearLayoutManager.VERTICAL, false)); |
395 | binding.recycleFilter.setAdapter(filterAdapter); | 397 | binding.recycleFilter.setAdapter(filterAdapter); |
396 | } | 398 | } |
397 | binding.recycleFilter.setVisibility(View.VISIBLE); | 399 | binding.recycleFilter.setVisibility(View.VISIBLE); |
398 | textView.setTextColor(Color.parseColor("#1C90F3")); | 400 | textView.setTextColor(Color.parseColor("#1C90F3")); |
399 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_blue); | 401 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_blue); |
400 | // 这一步必须要做,否则不会显示. | 402 | // 这一步必须要做,否则不会显示. |
401 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 403 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
402 | textView.setCompoundDrawables(null, null, drawable, null); | 404 | textView.setCompoundDrawables(null, null, drawable, null); |
403 | last = textView; | 405 | last = textView; |
404 | } else { | 406 | } else { |
405 | if (textView.getId() == last.getId()) { | 407 | if (textView.getId() == last.getId()) { |
406 | binding.recycleFilter.setVisibility(View.GONE); | 408 | binding.recycleFilter.setVisibility(View.GONE); |
407 | textView.setTextColor(getColor(R.color.text_title)); | 409 | textView.setTextColor(getColor(R.color.text_title)); |
408 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 410 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
409 | // 这一步必须要做,否则不会显示. | 411 | // 这一步必须要做,否则不会显示. |
410 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 412 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
411 | textView.setCompoundDrawables(null, null, drawable, null); | 413 | textView.setCompoundDrawables(null, null, drawable, null); |
412 | } else { | 414 | } else { |
413 | filterAdapter.refresh(list, textView, select); | 415 | filterAdapter.refresh(list, textView, select); |
414 | last.setTextColor(getColor(R.color.text_title)); | 416 | last.setTextColor(getColor(R.color.text_title)); |
415 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 417 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
416 | // 这一步必须要做,否则不会显示. | 418 | // 这一步必须要做,否则不会显示. |
417 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 419 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
418 | last.setCompoundDrawables(null, null, drawable, null); | 420 | last.setCompoundDrawables(null, null, drawable, null); |
419 | textView.setTextColor(Color.parseColor("#1C90F3")); | 421 | textView.setTextColor(Color.parseColor("#1C90F3")); |
420 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); | 422 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); |
421 | // 这一步必须要做,否则不会显示. | 423 | // 这一步必须要做,否则不会显示. |
422 | drawable1.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 424 | drawable1.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
423 | textView.setCompoundDrawables(null, null, drawable1, null); | 425 | textView.setCompoundDrawables(null, null, drawable1, null); |
424 | last = textView; | 426 | last = textView; |
425 | } | 427 | } |
426 | } | 428 | } |
427 | } | 429 | } |
428 | 430 | ||
429 | private void refreshError() { | 431 | private void refreshError() { |
430 | Map map = new HashMap(); | 432 | Map map = new HashMap(); |
431 | if (!TextUtils.isEmpty(subject) && !"全部".equals(subject)) { | 433 | if (!TextUtils.isEmpty(subject) && !"全部".equals(subject)) { |
432 | map.put("subject", subject); | 434 | map.put("subject", subject); |
433 | } | 435 | } |
434 | if (!TextUtils.isEmpty(grade) && !"全部".equals(grade)) { | 436 | if (!TextUtils.isEmpty(grade) && !"全部".equals(grade)) { |
435 | map.put("grade", grade); | 437 | map.put("grade", grade); |
436 | } | 438 | } |
437 | if (!TextUtils.isEmpty(time) && !"全部".equals(time)) { | 439 | if (!TextUtils.isEmpty(time) && !"全部".equals(time)) { |
438 | if ("一周内".equals(time)) { | 440 | if ("一周内".equals(time)) { |
439 | map.put("time", 6); | 441 | map.put("time", 6); |
440 | } else if ("一个月内".equals(time)) { | 442 | } else if ("一个月内".equals(time)) { |
441 | map.put("time", 30); | 443 | map.put("time", 30); |
442 | } else if ("三个月内".equals(time)) { | 444 | } else if ("三个月内".equals(time)) { |
443 | map.put("time", 90); | 445 | map.put("time", 90); |
444 | } | 446 | } |
445 | } | 447 | } |
446 | if (!TextUtils.isEmpty(type) && !"全部".equals(type)) { | 448 | if (!TextUtils.isEmpty(type) && !"全部".equals(type)) { |
447 | map.put("type", "课内".equals(type) ? 0 : 1); | 449 | map.put("type", "课内".equals(type) ? 0 : 1); |
448 | } | 450 | } |
449 | if (!TextUtils.isEmpty(manger) && !"全部".equals(manger)) { | 451 | if (!TextUtils.isEmpty(manger) && !"全部".equals(manger)) { |
450 | map.put("controlFlag", "已掌握".equals(manger) ? 0 : 1); | 452 | map.put("controlFlag", "已掌握".equals(manger) ? 0 : 1); |
451 | } | 453 | } |
452 | map.put("stuId", studentBean.getStuId()); | 454 | map.put("stuId", studentBean.getStuId()); |
453 | map.put("pageSize", 10); | 455 | map.put("pageSize", 10); |
454 | map.put("pageNum", page); | 456 | map.put("pageNum", page); |
455 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { | 457 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { |
456 | @Override | 458 | @Override |
457 | public void onSubscribe(Disposable d) { | 459 | public void onSubscribe(Disposable d) { |
458 | 460 | ||
459 | } | 461 | } |
460 | 462 | ||
461 | @Override | 463 | @Override |
462 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { | 464 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { |
463 | if (result.getData() != null && result.getCode() == 200) { | 465 | if (result.getData() != null && result.getCode() == 200) { |
464 | total = result.getData().getTotal(); | 466 | total = result.getData().getTotal(); |
465 | List<TopicBean> topicBeans = result.getData().getList(); | 467 | List<TopicBean> topicBeans = result.getData().getList(); |
466 | loadError(topicBeans); | 468 | loadError(topicBeans); |
467 | } | 469 | } |
468 | } | 470 | } |
469 | 471 | ||
470 | @Override | 472 | @Override |
471 | public void onError(Throwable e) { | 473 | public void onError(Throwable e) { |
472 | e.toString(); | 474 | e.toString(); |
473 | } | 475 | } |
474 | 476 | ||
475 | @Override | 477 | @Override |
476 | public void onComplete() { | 478 | public void onComplete() { |
477 | 479 | ||
478 | } | 480 | } |
479 | }); | 481 | }); |
480 | } | 482 | } |
481 | 483 | ||
482 | private void loadError(List<TopicBean> list) { | 484 | private void loadError(List<TopicBean> list) { |
483 | if (list.size() > 0) { | 485 | if (list.size() > 0) { |
484 | binding.recycle.setVisibility(View.VISIBLE); | 486 | binding.recycle.setVisibility(View.VISIBLE); |
485 | binding.llEmpty.setVisibility(View.GONE); | 487 | binding.llEmpty.setVisibility(View.GONE); |
486 | if (adapter != null) { | 488 | if (adapter != null) { |
487 | if (page > 1) { | 489 | if (page > 1) { |
488 | adapter.addData(list); | 490 | adapter.addData(list); |
489 | } else { | 491 | } else { |
490 | adapter.refresh(list); | 492 | adapter.refresh(list); |
491 | } | 493 | } |
492 | } else { | 494 | } else { |
493 | adapter = new ErrorAdapter(context, list, false, new ErrorAdapter.CheckInterface() { | 495 | adapter = new ErrorAdapter(context, list, false, new ErrorAdapter.CheckInterface() { |
494 | @Override | 496 | @Override |
495 | public void onErrorCheck() { | 497 | public void onErrorCheck() { |
496 | if (adapter.getChecKList().size() > 0) { | 498 | if (adapter.getChecKList().size() > 0) { |
497 | binding.tvSave.setText("批量修改标签" + "(" + adapter.getChecKList().size() + ")"); | 499 | binding.tvSave.setText("批量修改标签" + "(" + adapter.getChecKList().size() + ")"); |
498 | } else { | 500 | } else { |
499 | binding.tvSave.setText("批量修改标签"); | 501 | binding.tvSave.setText("批量修改标签"); |
500 | } | 502 | } |
501 | } | 503 | } |
502 | }); | 504 | }); |
503 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false); | 505 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false); |
504 | binding.recycle.setLayoutManager(linearLayoutManager); | 506 | binding.recycle.setLayoutManager(linearLayoutManager); |
505 | binding.recycle.setAdapter(adapter); | 507 | binding.recycle.setAdapter(adapter); |
506 | binding.recycle.addOnScrollListener(new LoadMoreOnScrollListener(linearLayoutManager) { | 508 | binding.recycle.addOnScrollListener(new LoadMoreOnScrollListener(linearLayoutManager) { |
507 | @Override | 509 | @Override |
508 | public void onLoadMore(int currentPage) { | 510 | public void onLoadMore(int currentPage) { |
509 | if (currentPage > page) { | 511 | if (currentPage > page) { |
510 | new Thread(new Runnable() { | 512 | new Thread(new Runnable() { |
511 | @Override | 513 | @Override |
512 | public void run() { | 514 | public void run() { |
513 | try { | 515 | try { |
514 | runOnUiThread(new Runnable() { | 516 | runOnUiThread(new Runnable() { |
515 | @Override | 517 | @Override |
516 | public void run() { | 518 | public void run() { |
517 | if (page * 10 < total) { | 519 | if (page * 10 < total) { |
518 | page++; | 520 | page++; |
519 | refreshError(); | 521 | refreshError(); |
520 | } | 522 | } |
521 | } | 523 | } |
522 | }); | 524 | }); |
523 | } catch (Exception e) { | 525 | } catch (Exception e) { |
524 | e.printStackTrace(); | 526 | e.printStackTrace(); |
525 | } | 527 | } |
526 | } | 528 | } |
527 | }).start(); | 529 | }).start(); |
528 | } | 530 | } |
529 | } | 531 | } |
530 | }); | 532 | }); |
531 | } | 533 | } |
532 | } else { | 534 | } else { |
533 | if (page == 1) { | 535 | if (page == 1) { |
534 | binding.recycle.setVisibility(View.GONE); | 536 | binding.recycle.setVisibility(View.GONE); |
535 | binding.llEmpty.setVisibility(View.VISIBLE); | 537 | binding.llEmpty.setVisibility(View.VISIBLE); |
536 | } | 538 | } |
537 | } | 539 | } |
538 | } | 540 | } |
539 | 541 | ||
540 | @Override | 542 | @Override |
541 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 543 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
542 | if (keyCode == KeyEvent.KEYCODE_BACK) { | 544 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
543 | if (adapter != null && adapter.edit) { | 545 | if (adapter != null && adapter.edit) { |
544 | adapter.setEdit(false); | 546 | adapter.setEdit(false); |
545 | binding.tvSave.setVisibility(View.GONE); | 547 | binding.tvSave.setVisibility(View.GONE); |
546 | binding.tvAdd.setVisibility(View.VISIBLE); | 548 | binding.tvAdd.setVisibility(View.VISIBLE); |
547 | binding.checkbox.setVisibility(View.GONE); | 549 | binding.checkbox.setVisibility(View.GONE); |
548 | binding.llDelete.setVisibility(View.GONE); | 550 | binding.llDelete.setVisibility(View.GONE); |
549 | binding.ivBack.setVisibility(View.VISIBLE); | 551 | binding.ivBack.setVisibility(View.VISIBLE); |
550 | binding.tvEdit.setText("编辑"); | 552 | binding.tvEdit.setText("编辑"); |
551 | adapter.notifyDataSetChanged(); | 553 | adapter.notifyDataSetChanged(); |
552 | } else { | 554 | } else { |
553 | finish(); | 555 | finish(); |
554 | } | 556 | } |
555 | return true; | 557 | return true; |
556 | } | 558 | } |
557 | return super.onKeyDown(keyCode, event); | 559 | return super.onKeyDown(keyCode, event); |
558 | } | 560 | } |
559 | 561 | ||
560 | @Override | 562 | @Override |
561 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 563 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
562 | super.onActivityResult(requestCode, resultCode, data); | 564 | super.onActivityResult(requestCode, resultCode, data); |
563 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 565 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
564 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 566 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
565 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 567 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
566 | CommonUtil.saveBitmapToUri(b, path); | 568 | CommonUtil.saveBitmapToUri(b, path); |
567 | List<String> strings = new ArrayList<>(); | 569 | List<String> strings = new ArrayList<>(); |
568 | Intent intent = new Intent(context, ImageActivity.class); | 570 | Intent intent = new Intent(context, ImageActivity.class); |
569 | strings.add(path); | 571 | strings.add(path); |
570 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 572 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
571 | startActivity(intent); | 573 | startActivity(intent); |
572 | } | 574 | } |
573 | } | 575 | } |
574 | 576 | ||
575 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 577 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
576 | private String TAG = "---ImagePicker---"; | 578 | private String TAG = "---ImagePicker---"; |
577 | List<ImageInfo> photoList = new ArrayList<>(); | 579 | List<ImageInfo> photoList = new ArrayList<>(); |
578 | 580 | ||
579 | @Override | 581 | @Override |
580 | public void onStart() { | 582 | public void onStart() { |
581 | Log.i(TAG, "onStart: 开启"); | 583 | Log.i(TAG, "onStart: 开启"); |
582 | } | 584 | } |
583 | 585 | ||
584 | @Override | 586 | @Override |
585 | public void onSuccess(List<ImageInfo> photoList) { | 587 | public void onSuccess(List<ImageInfo> photoList) { |
586 | this.photoList = photoList; | 588 | this.photoList = photoList; |
587 | Log.i(TAG, "onSuccess: 返回数据"); | 589 | Log.i(TAG, "onSuccess: 返回数据"); |
588 | } | 590 | } |
589 | 591 | ||
590 | @Override | 592 | @Override |
591 | public void onCancel() { | 593 | public void onCancel() { |
592 | Log.i(TAG, "onCancel: 取消"); | 594 | Log.i(TAG, "onCancel: 取消"); |
593 | } | 595 | } |
594 | 596 | ||
595 | @Override | 597 | @Override |
596 | public void onFinish(List<ImageInfo> selectImage) { | 598 | public void onFinish(List<ImageInfo> selectImage) { |
597 | if (selectImage.size() == photoList.size()) { | 599 | if (selectImage.size() == photoList.size()) { |
598 | List<String> strings = new ArrayList<>(); | 600 | List<String> strings = new ArrayList<>(); |
599 | Intent intent = new Intent(context, ImageActivity.class); | 601 | Intent intent = new Intent(context, ImageActivity.class); |
600 | for (ImageInfo imageInfo : selectImage) { | 602 | for (ImageInfo imageInfo : selectImage) { |
601 | strings.add(imageInfo.getPath()); | 603 | strings.add(imageInfo.getPath()); |
602 | } | 604 | } |
603 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 605 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
604 | startActivity(intent); | 606 | startActivity(intent); |
605 | } | 607 | } |
606 | } | 608 | } |
607 | 609 | ||
608 | @Override | 610 | @Override |
609 | public void onError() { | 611 | public void onError() { |
610 | Log.i(TAG, "onError: 出错"); | 612 | Log.i(TAG, "onError: 出错"); |
611 | } | 613 | } |
612 | } | 614 | } |
613 | 615 | ||
614 | @Override | 616 | @Override |
615 | protected void onResume() { | 617 | protected void onResume() { |
616 | refreshError(); | 618 | refreshError(); |
617 | super.onResume(); | 619 | super.onResume(); |
618 | } | 620 | } |
619 | } | 621 | } |
620 | 622 |
app/src/main/java/com/hjx/parent/MainActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import androidx.appcompat.app.AppCompatActivity; | 3 | import androidx.appcompat.app.AppCompatActivity; |
4 | import androidx.constraintlayout.widget.ConstraintLayout; | 4 | import androidx.constraintlayout.widget.ConstraintLayout; |
5 | import androidx.core.content.FileProvider; | ||
5 | 6 | ||
7 | import android.app.Dialog; | ||
8 | import android.app.ProgressDialog; | ||
9 | import android.content.Intent; | ||
6 | import android.graphics.Color; | 10 | import android.graphics.Color; |
11 | import android.net.Uri; | ||
12 | import android.os.Build; | ||
7 | import android.os.Bundle; | 13 | import android.os.Bundle; |
14 | import android.os.Looper; | ||
8 | import android.widget.ImageView; | 15 | import android.widget.ImageView; |
9 | import android.widget.TextView; | 16 | import android.widget.TextView; |
17 | import android.widget.Toast; | ||
10 | 18 | ||
11 | import com.google.gson.JsonObject; | 19 | import com.google.gson.JsonObject; |
20 | import com.hjq.permissions.OnPermissionCallback; | ||
21 | import com.hjq.permissions.Permission; | ||
22 | import com.hjq.permissions.XXPermissions; | ||
23 | import com.hjx.parent.dialog.TipDialog; | ||
12 | import com.hjx.parent.fragment.HomeFragment; | 24 | import com.hjx.parent.fragment.HomeFragment; |
13 | import com.hjx.parent.fragment.MeFragment; | 25 | import com.hjx.parent.fragment.MeFragment; |
14 | import com.prws.common.base.BaseActivity; | 26 | import com.prws.common.base.BaseActivity; |
15 | import com.prws.common.base.BasePresenter; | 27 | import com.prws.common.base.BasePresenter; |
16 | import com.prws.common.bean.GradeAndSubject; | 28 | import com.prws.common.bean.GradeAndSubject; |
17 | import com.prws.common.bean.ResponseResult; | 29 | import com.prws.common.bean.ResponseResult; |
30 | import com.prws.common.bean.UpdateBean; | ||
18 | import com.prws.common.net.NetWorks; | 31 | import com.prws.common.net.NetWorks; |
32 | import com.prws.common.utils.DownloadUtil; | ||
19 | import com.prws.common.utils.SharedPreferencesUtil; | 33 | import com.prws.common.utils.SharedPreferencesUtil; |
20 | 34 | ||
35 | import java.io.File; | ||
21 | import java.util.List; | 36 | import java.util.List; |
22 | 37 | ||
23 | import io.reactivex.Observer; | 38 | import io.reactivex.Observer; |
24 | import io.reactivex.disposables.Disposable; | 39 | import io.reactivex.disposables.Disposable; |
40 | import retrofit2.Call; | ||
41 | import retrofit2.Callback; | ||
42 | import retrofit2.Response; | ||
25 | 43 | ||
26 | public class MainActivity extends BaseActivity { | 44 | public class MainActivity extends BaseActivity { |
27 | 45 | ||
28 | @Override | 46 | @Override |
29 | protected int layoutResId() { | 47 | protected int layoutResId() { |
30 | return R.layout.activity_main; | 48 | return R.layout.activity_main; |
31 | } | 49 | } |
32 | 50 | ||
33 | @Override | 51 | @Override |
34 | public Object getContract() { | 52 | public Object getContract() { |
35 | return null; | 53 | return null; |
36 | } | 54 | } |
37 | 55 | ||
38 | @Override | 56 | @Override |
39 | public BasePresenter getPresenter() { | 57 | public BasePresenter getPresenter() { |
40 | return null; | 58 | return null; |
41 | } | 59 | } |
42 | 60 | ||
43 | 61 | ||
44 | HomeFragment homeFragment; | 62 | HomeFragment homeFragment; |
45 | MeFragment meFragment; | 63 | MeFragment meFragment; |
46 | ConstraintLayout cl_home; | 64 | ConstraintLayout cl_home; |
47 | ConstraintLayout cl_me; | 65 | ConstraintLayout cl_me; |
48 | ImageView iv_3, iv_4; | 66 | ImageView iv_3, iv_4; |
49 | TextView tv_1, tv_4; | 67 | TextView tv_1, tv_4; |
50 | 68 | ||
51 | @Override | 69 | @Override |
52 | protected void initView() { | 70 | protected void initView() { |
53 | showFragment(getHomeFragment(), R.id.rl_content); | 71 | showFragment(getHomeFragment(), R.id.rl_content); |
54 | cl_home = findViewById(R.id.cl_home); | 72 | cl_home = findViewById(R.id.cl_home); |
55 | cl_me = findViewById(R.id.cl_me); | 73 | cl_me = findViewById(R.id.cl_me); |
56 | iv_3 = findViewById(R.id.iv_3); | 74 | iv_3 = findViewById(R.id.iv_3); |
57 | iv_4 = findViewById(R.id.iv_4); | 75 | iv_4 = findViewById(R.id.iv_4); |
58 | tv_1 = findViewById(R.id.tv_1); | 76 | tv_1 = findViewById(R.id.tv_1); |
59 | tv_4 = findViewById(R.id.tv_4); | 77 | tv_4 = findViewById(R.id.tv_4); |
60 | iv_3.setBackgroundResource(R.mipmap.hoss); | 78 | iv_3.setBackgroundResource(R.mipmap.hoss); |
61 | tv_1.setTextColor(Color.parseColor("#FE5E09")); | 79 | tv_1.setTextColor(Color.parseColor("#FE5E09")); |
62 | NetWorks.getBaiduToken(new Observer<JsonObject>() { | 80 | NetWorks.getBaiduToken(new Observer<JsonObject>() { |
63 | @Override | 81 | @Override |
64 | public void onSubscribe(Disposable d) { | 82 | public void onSubscribe(Disposable d) { |
65 | 83 | ||
66 | } | 84 | } |
67 | 85 | ||
68 | @Override | 86 | @Override |
69 | public void onNext(JsonObject jsonObject) { | 87 | public void onNext(JsonObject jsonObject) { |
70 | SharedPreferencesUtil.putData("baiduToken", jsonObject.get("access_token").getAsString()); | 88 | SharedPreferencesUtil.putData("baiduToken", jsonObject.get("access_token").getAsString()); |
71 | } | 89 | } |
72 | 90 | ||
73 | @Override | 91 | @Override |
74 | public void onError(Throwable e) { | 92 | public void onError(Throwable e) { |
75 | 93 | ||
76 | } | 94 | } |
77 | 95 | ||
78 | @Override | 96 | @Override |
79 | public void onComplete() { | 97 | public void onComplete() { |
80 | 98 | ||
81 | } | 99 | } |
82 | }); | 100 | }); |
83 | NetWorks.listGradeAndSubject(new Observer<ResponseResult<List<GradeAndSubject>>>() { | 101 | NetWorks.listGradeAndSubject(new Observer<ResponseResult<List<GradeAndSubject>>>() { |
84 | @Override | 102 | @Override |
85 | public void onSubscribe(Disposable d) { | 103 | public void onSubscribe(Disposable d) { |
86 | 104 | ||
87 | } | 105 | } |
88 | 106 | ||
89 | @Override | 107 | @Override |
90 | public void onNext(ResponseResult<List<GradeAndSubject>> listResponseResult) { | 108 | public void onNext(ResponseResult<List<GradeAndSubject>> listResponseResult) { |
91 | App.getInstance().setGradeAndSubjects(listResponseResult.getData()); | 109 | App.getInstance().setGradeAndSubjects(listResponseResult.getData()); |
92 | } | 110 | } |
93 | 111 | ||
94 | @Override | 112 | @Override |
95 | public void onError(Throwable e) { | 113 | public void onError(Throwable e) { |
96 | e.toString(); | 114 | e.toString(); |
97 | } | 115 | } |
98 | 116 | ||
99 | @Override | 117 | @Override |
100 | public void onComplete() { | 118 | public void onComplete() { |
101 | 119 | ||
102 | } | 120 | } |
103 | }); | 121 | }); |
122 | checkUpdate(); | ||
104 | } | 123 | } |
105 | 124 | ||
106 | public HomeFragment getHomeFragment() { | 125 | public HomeFragment getHomeFragment() { |
107 | if (homeFragment == null) | 126 | if (homeFragment == null) |
108 | homeFragment = new HomeFragment(); | 127 | homeFragment = new HomeFragment(); |
109 | return homeFragment; | 128 | return homeFragment; |
110 | } | 129 | } |
111 | 130 | ||
112 | public MeFragment getMeFragment() { | 131 | public MeFragment getMeFragment() { |
113 | if (meFragment == null) | 132 | if (meFragment == null) |
114 | meFragment = new MeFragment(); | 133 | meFragment = new MeFragment(); |
115 | return meFragment; | 134 | return meFragment; |
116 | } | 135 | } |
117 | 136 | ||
118 | 137 | ||
119 | @Override | 138 | @Override |
120 | protected void initListener() { | 139 | protected void initListener() { |
121 | cl_home.setOnClickListener(view -> { | 140 | cl_home.setOnClickListener(view -> { |
122 | showFragment(getHomeFragment(), R.id.rl_content); | 141 | showFragment(getHomeFragment(), R.id.rl_content); |
123 | iv_3.setBackgroundResource(R.mipmap.hoss); | 142 | iv_3.setBackgroundResource(R.mipmap.hoss); |
124 | tv_1.setTextColor(Color.parseColor("#FE5E09")); | 143 | tv_1.setTextColor(Color.parseColor("#FE5E09")); |
125 | iv_4.setBackgroundResource(R.mipmap.wmus); | 144 | iv_4.setBackgroundResource(R.mipmap.wmus); |
126 | tv_4.setTextColor(Color.parseColor("#333333")); | 145 | tv_4.setTextColor(Color.parseColor("#333333")); |
127 | }); | 146 | }); |
128 | 147 | ||
129 | cl_me.setOnClickListener(view -> { | 148 | cl_me.setOnClickListener(view -> { |
130 | showFragment(getMeFragment(), R.id.rl_content); | 149 | showFragment(getMeFragment(), R.id.rl_content); |
131 | iv_3.setBackgroundResource(R.mipmap.hous); | 150 | iv_3.setBackgroundResource(R.mipmap.hous); |
132 | tv_1.setTextColor(Color.parseColor("#333333")); | 151 | tv_1.setTextColor(Color.parseColor("#333333")); |
133 | iv_4.setBackgroundResource(R.mipmap.wmss); | 152 | iv_4.setBackgroundResource(R.mipmap.wmss); |
134 | tv_4.setTextColor(Color.parseColor("#FE5E09")); | 153 | tv_4.setTextColor(Color.parseColor("#FE5E09")); |
135 | }); | 154 | }); |
136 | } | 155 | } |
137 | 156 | ||
138 | @Override | 157 | @Override |
139 | protected void initData() { | 158 | protected void initData() { |
140 | 159 | ||
141 | } | 160 | } |
142 | 161 | ||
143 | @Override | 162 | @Override |
144 | public void onNetChanged(int netWorkState) { | 163 | public void onNetChanged(int netWorkState) { |
145 | 164 | ||
146 | } | 165 | } |
166 | |||
167 | public void downloadApk(String url, int versionCode) { | ||
168 | String filepath = getExternalFilesDir("apk").getPath() + "/" + versionCode + ".apk"; | ||
169 | ProgressDialog dialog = new ProgressDialog(this); | ||
170 | dialog.setTitle("版本更新"); | ||
171 | dialog.setMessage("正在下载新版本,请稍后"); | ||
172 | dialog.setMax(100); | ||
173 | dialog.setProgress(0); | ||
174 | dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); | ||
175 | dialog.show(); | ||
176 | DownloadUtil.download(url, filepath, new DownloadUtil.OnDownloadListener() { | ||
177 | @Override | ||
178 | public void onDownloadSuccess(String path) { | ||
179 | dialog.setProgress(100); | ||
180 | dialog.dismiss(); | ||
181 | installApk(filepath); | ||
182 | } | ||
183 | |||
184 | @Override | ||
185 | public void onDownloading(int progress) { | ||
186 | dialog.setProgress(progress); | ||
187 | } | ||
188 | |||
189 | @Override | ||
190 | public void onDownloadFailed(String msg) { | ||
191 | dialog.dismiss(); | ||
192 | Looper.prepare(); | ||
193 | showToast("下载失败。"); | ||
194 | Looper.loop(); | ||
195 | } | ||
196 | }); | ||
197 | } | ||
198 | |||
199 | public void installApk(String path) { | ||
200 | //开启扫码界面 | ||
201 | Intent intentUpdate = new Intent("android.intent.action.VIEW"); | ||
202 | intentUpdate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
203 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //对Android N及以上的版本做判断 | ||
204 | Uri apkUriN = FileProvider.getUriForFile(MainActivity.this, | ||
205 | getApplicationContext().getPackageName() + ".fileprovider", new File(path)); | ||
206 | intentUpdate.addCategory("android.intent.category.DEFAULT"); | ||
207 | intentUpdate.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //天假Flag 表示我们需要什么权限 | ||
208 | intentUpdate.setDataAndType(apkUriN, "application/vnd.android.package-archive"); | ||
209 | } else { | ||
210 | Uri apkUri = Uri.fromFile(new File(path)); | ||
211 | intentUpdate.setDataAndType(apkUri, "application/vnd.android.package-archive"); | ||
212 | } | ||
213 | startActivity(intentUpdate); | ||
214 | } | ||
215 | |||
216 | public void checkUpdate() { | ||
217 | NetWorks.checkUpdate(BuildConfig.VERSION_CODE, BuildConfig.APPLICATION_ID, new Callback<ResponseResult<UpdateBean>>() { | ||
218 | @Override | ||
219 | public void onResponse(Call<ResponseResult<UpdateBean>> call, Response<ResponseResult<UpdateBean>> response) { | ||
220 | if (response.body() != null && response.body().getCode() == 200) { | ||
221 | if (response.body().getData() != null) { | ||
222 | String msg = response.body().getData().getExplain(); | ||
223 | String url = response.body().getData().getUrl(); | ||
224 | int versionCode = response.body().getData().getVersion(); | ||
225 | showUpdateDialog(msg, url, versionCode); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | |||
230 | @Override | ||
231 | public void onFailure(Call<ResponseResult<UpdateBean>> call, Throwable t) { | ||
232 | } | ||
233 | }); | ||
234 | } | ||
235 | |||
236 | public void showUpdateDialog(String msg, String url, int versionCode) { | ||
237 | TipDialog tipDialog = new TipDialog(this, "检测到新版本", msg, "升级", "取消", new TipDialog.TipDialogInterface() { | ||
238 | @Override | ||
239 | public void onConfirm(Dialog dialog) { | ||
240 | if (!XXPermissions.isGranted(MainActivity.this, Permission.MANAGE_EXTERNAL_STORAGE)) { | ||
241 | XXPermissions.with(MainActivity.this) | ||
242 | // 申请多个权限 | ||
243 | .permission(Permission.MANAGE_EXTERNAL_STORAGE) | ||
244 | .request(new OnPermissionCallback() { | ||
245 | @Override | ||
246 | public void onGranted(List<String> permissions, boolean all) { | ||
247 | if (all) { | ||
248 | //开启扫码界面 | ||
249 | downloadApk(url, versionCode); | ||
250 | } else { | ||
251 | Toast.makeText(MainActivity.this, "需要权限", Toast.LENGTH_SHORT).show(); | ||
252 | } | ||
253 | } | ||
254 | |||
255 | @Override | ||
256 | public void onDenied(List<String> permissions, boolean never) { | ||
257 | XXPermissions.startPermissionActivity(MainActivity.this, permissions); | ||
258 | } | ||
259 | }); | ||
260 | } else { | ||
261 | downloadApk(url, versionCode); | ||
262 | } | ||
263 | |||
264 | } | ||
265 | |||
266 | @Override | ||
267 | public void onCancel(Dialog dialog) { | ||
268 | dialog.dismiss(); | ||
269 | } | ||
270 | }); | ||
271 | tipDialog.show(); | ||
272 | } | ||
147 | } | 273 | } |
app/src/main/java/com/hjx/parent/adapter/ErrorAdapter.java
1 | package com.hjx.parent.adapter; | 1 | package com.hjx.parent.adapter; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.content.Intent; | 4 | import android.content.Intent; |
5 | import android.graphics.drawable.Drawable; | 5 | import android.graphics.drawable.Drawable; |
6 | import android.text.TextUtils; | 6 | import android.text.TextUtils; |
7 | import android.view.LayoutInflater; | 7 | import android.view.LayoutInflater; |
8 | import android.view.MotionEvent; | ||
8 | import android.view.View; | 9 | import android.view.View; |
9 | import android.view.ViewGroup; | 10 | import android.view.ViewGroup; |
10 | import android.webkit.WebSettings; | 11 | import android.webkit.WebSettings; |
11 | import android.widget.LinearLayout; | 12 | import android.widget.LinearLayout; |
12 | 13 | ||
13 | import androidx.annotation.NonNull; | 14 | import androidx.annotation.NonNull; |
14 | import androidx.annotation.Nullable; | 15 | import androidx.annotation.Nullable; |
15 | import androidx.recyclerview.widget.RecyclerView; | 16 | import androidx.recyclerview.widget.RecyclerView; |
16 | 17 | ||
17 | import com.bumptech.glide.Glide; | 18 | import com.bumptech.glide.Glide; |
18 | import com.bumptech.glide.request.target.SimpleTarget; | 19 | import com.bumptech.glide.request.target.SimpleTarget; |
19 | import com.bumptech.glide.request.transition.Transition; | 20 | import com.bumptech.glide.request.transition.Transition; |
20 | import com.hjx.parent.ErrorDetailActivity; | 21 | import com.hjx.parent.ErrorDetailActivity; |
21 | import com.hjx.parent.R; | 22 | import com.hjx.parent.R; |
22 | import com.hjx.parent.databinding.ItemErrorBinding; | 23 | import com.hjx.parent.databinding.ItemErrorBinding; |
23 | import com.prws.common.bean.ErrorDetailBean; | 24 | import com.prws.common.bean.ErrorDetailBean; |
24 | import com.prws.common.bean.TopicBean; | 25 | import com.prws.common.bean.TopicBean; |
25 | import com.prws.common.utils.CommonUtil; | 26 | import com.prws.common.utils.CommonUtil; |
26 | import com.prws.common.utils.StringUtils; | 27 | import com.prws.common.utils.StringUtils; |
27 | 28 | ||
28 | import java.text.SimpleDateFormat; | 29 | import java.text.SimpleDateFormat; |
29 | import java.util.ArrayList; | 30 | import java.util.ArrayList; |
30 | import java.util.List; | 31 | import java.util.List; |
31 | 32 | ||
32 | public class ErrorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | 33 | public class ErrorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
33 | private List<TopicBean> list; | 34 | private List<TopicBean> list; |
34 | private Context context; | 35 | private Context context; |
35 | public boolean edit; | 36 | public boolean edit; |
36 | private CheckInterface checkInterface; | 37 | private CheckInterface checkInterface; |
37 | 38 | ||
38 | public interface CheckInterface { | 39 | public interface CheckInterface { |
39 | void onErrorCheck(); | 40 | void onErrorCheck(); |
40 | } | 41 | } |
41 | 42 | ||
42 | public ErrorAdapter(Context context, List<TopicBean> list, boolean edit, CheckInterface checkInterface) { | 43 | public ErrorAdapter(Context context, List<TopicBean> list, boolean edit, CheckInterface checkInterface) { |
43 | this.list = list; | 44 | this.list = list; |
44 | this.context = context; | 45 | this.context = context; |
45 | this.edit = edit; | 46 | this.edit = edit; |
46 | this.checkInterface = checkInterface; | 47 | this.checkInterface = checkInterface; |
47 | } | 48 | } |
48 | 49 | ||
49 | public ErrorAdapter(Context context, List<TopicBean> list, boolean edit) { | 50 | public ErrorAdapter(Context context, List<TopicBean> list, boolean edit) { |
50 | this.list = list; | 51 | this.list = list; |
51 | this.context = context; | 52 | this.context = context; |
52 | this.edit = edit; | 53 | this.edit = edit; |
53 | } | 54 | } |
54 | 55 | ||
55 | public void checkAll(boolean check) { | 56 | public void checkAll(boolean check) { |
56 | for (TopicBean topicBean : list) { | 57 | for (TopicBean topicBean : list) { |
57 | topicBean.setCheck(check); | 58 | topicBean.setCheck(check); |
58 | } | 59 | } |
59 | notifyDataSetChanged(); | 60 | notifyDataSetChanged(); |
60 | checkInterface.onErrorCheck(); | 61 | checkInterface.onErrorCheck(); |
61 | } | 62 | } |
62 | 63 | ||
63 | public List<TopicBean> getChecKList() { | 64 | public List<TopicBean> getChecKList() { |
64 | List<TopicBean> topicBeans = new ArrayList<>(); | 65 | List<TopicBean> topicBeans = new ArrayList<>(); |
65 | for (TopicBean topicBean : list) { | 66 | for (TopicBean topicBean : list) { |
66 | if (topicBean.isCheck()) { | 67 | if (topicBean.isCheck()) { |
67 | topicBeans.add(topicBean); | 68 | topicBeans.add(topicBean); |
68 | } | 69 | } |
69 | } | 70 | } |
70 | return topicBeans; | 71 | return topicBeans; |
71 | } | 72 | } |
72 | 73 | ||
73 | public void setEdit(boolean edit) { | 74 | public void setEdit(boolean edit) { |
74 | this.edit = edit; | 75 | this.edit = edit; |
75 | notifyDataSetChanged(); | 76 | notifyDataSetChanged(); |
76 | } | 77 | } |
77 | 78 | ||
78 | public void addData(List<TopicBean> topicBeans) { | 79 | public void addData(List<TopicBean> topicBeans) { |
79 | list.addAll(topicBeans); | 80 | list.addAll(topicBeans); |
80 | notifyDataSetChanged(); | 81 | notifyDataSetChanged(); |
81 | } | 82 | } |
82 | 83 | ||
83 | public void refresh(List<TopicBean> list) { | 84 | public void refresh(List<TopicBean> list) { |
84 | this.list = list; | 85 | this.list = list; |
85 | notifyDataSetChanged(); | 86 | notifyDataSetChanged(); |
86 | } | 87 | } |
87 | 88 | ||
88 | @NonNull | 89 | @NonNull |
89 | @Override | 90 | @Override |
90 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | 91 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
91 | ItemErrorBinding itemTopicBinding = ItemErrorBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); | 92 | ItemErrorBinding itemTopicBinding = ItemErrorBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); |
92 | return new ErrorHolder(itemTopicBinding); | 93 | return new ErrorHolder(itemTopicBinding); |
93 | } | 94 | } |
94 | 95 | ||
95 | @Override | 96 | @Override |
96 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { | 97 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { |
97 | TopicBean topicBean = list.get(position); | 98 | TopicBean topicBean = list.get(position); |
98 | ErrorHolder holder = (ErrorHolder) viewHolder; | 99 | ErrorHolder holder = (ErrorHolder) viewHolder; |
99 | holder.binding.ivCheck.setVisibility(edit ? View.VISIBLE : View.GONE); | 100 | holder.binding.ivCheck.setVisibility(edit ? View.VISIBLE : View.GONE); |
100 | holder.binding.ivCheck.setImageResource(topicBean.isCheck() ? R.mipmap.ic_select : R.mipmap.ic_unselect); | 101 | holder.binding.ivCheck.setImageResource(topicBean.isCheck() ? R.mipmap.ic_select : R.mipmap.ic_unselect); |
101 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 102 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
102 | if (position == 0 || !format.format(list.get(position - 1).getTime()).equals(format.format(topicBean.getTime()))) { | 103 | if (position == 0 || !format.format(list.get(position - 1).getTime()).equals(format.format(topicBean.getTime()))) { |
103 | holder.binding.tvTime.setVisibility(View.VISIBLE); | 104 | holder.binding.tvTime.setVisibility(View.VISIBLE); |
104 | holder.binding.tvTime.setText(format.format(topicBean.getTime())); | 105 | holder.binding.tvTime.setText(format.format(topicBean.getTime())); |
105 | } else { | 106 | } else { |
106 | holder.binding.tvTime.setVisibility(View.GONE); | 107 | holder.binding.tvTime.setVisibility(View.GONE); |
107 | } | 108 | } |
108 | if (topicBean.isDone()) { | 109 | if (topicBean.isDone()) { |
109 | holder.binding.tvType.setText(context.getString(R.string.text_done)); | 110 | holder.binding.tvType.setText(context.getString(R.string.text_done)); |
110 | holder.binding.tvType.setBackgroundResource(R.drawable.bg_done_text); | 111 | holder.binding.tvType.setBackgroundResource(R.drawable.bg_done_text); |
111 | } else { | 112 | } else { |
112 | holder.binding.tvType.setText(context.getString(R.string.text_undo)); | 113 | holder.binding.tvType.setText(context.getString(R.string.text_undo)); |
113 | holder.binding.tvType.setBackgroundResource(R.drawable.bg_undo_text); | 114 | holder.binding.tvType.setBackgroundResource(R.drawable.bg_undo_text); |
114 | } | 115 | } |
115 | holder.binding.tvReason.setText("错因:" + context.getResources().getStringArray(R.array.error_reason)[topicBean.getReason()]); | 116 | holder.binding.tvReason.setText("错因:" + context.getResources().getStringArray(R.array.error_reason)[topicBean.getReason()]); |
116 | if (topicBean.getBean() != null) { | 117 | if (topicBean.getBean() != null) { |
117 | ErrorDetailBean bean = topicBean.getBean(); | 118 | ErrorDetailBean bean = topicBean.getBean(); |
118 | holder.binding.ivTopic.setVisibility(View.GONE); | 119 | holder.binding.ivTopic.setVisibility(View.GONE); |
119 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; | 120 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
120 | StringBuilder sb = new StringBuilder(4096); | 121 | StringBuilder sb = new StringBuilder(4096); |
121 | if (!TextUtils.isEmpty(bean.getLabel())) { | 122 | if (!TextUtils.isEmpty(bean.getLabel())) { |
122 | sb.append(bean.getLabel()); | 123 | sb.append(bean.getLabel()); |
123 | } | 124 | } |
124 | sb.append(bean.getContent()); | 125 | sb.append(bean.getContent()); |
125 | if (bean.getOptions() != null && bean.getOptions().size() > 0) { | 126 | if (bean.getOptions() != null && bean.getOptions().size() > 0) { |
126 | sb.append("<div class='pt1'>"); | 127 | sb.append("<div class='pt1'>"); |
127 | sb.append(StringUtils.OptionsHtml(bean.getOptions(), null)); | 128 | sb.append(StringUtils.OptionsHtml(bean.getOptions(), null)); |
128 | sb.append("</div>"); | 129 | sb.append("</div>"); |
129 | } | 130 | } |
130 | String body = "<html><header>" + linkCss + "</header>" + sb.toString() + "</body></html>"; | 131 | String body = "<html><header>" + linkCss + "</header>" + sb.toString() + "</body></html>"; |
131 | WebSettings settings = holder.binding.webview.getSettings(); | 132 | WebSettings settings = holder.binding.webview.getSettings(); |
132 | // settings.setUseWideViewPort(true);//设定支持 viewport | 133 | // settings.setUseWideViewPort(true);//设定支持 viewport |
133 | // settings.setLoadWithOverviewMode(true); //自适应屏幕 | 134 | // settings.setLoadWithOverviewMode(true); //自适应屏幕 |
134 | // settings.setBuiltInZoomControls(true); | 135 | // settings.setBuiltInZoomControls(true); |
135 | // settings.setDisplayZoomControls(false); | 136 | // settings.setDisplayZoomControls(false); |
136 | // settings.setSupportZoom(false);//设定支持缩放 | 137 | // settings.setSupportZoom(false);//设定支持缩放 |
137 | holder.binding.webview.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); | 138 | holder.binding.webview.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
138 | holder.binding.webview.setVisibility(View.VISIBLE); | 139 | holder.binding.webview.setVisibility(View.VISIBLE); |
140 | holder.binding.webview.setOnTouchListener(new View.OnTouchListener() { | ||
141 | @Override | ||
142 | public boolean onTouch(View v, MotionEvent event) { | ||
143 | if (event.getAction() == MotionEvent.ACTION_UP) { | ||
144 | if (edit) { | ||
145 | list.get(position).setCheck(!topicBean.isCheck()); | ||
146 | notifyItemChanged(position); | ||
147 | checkInterface.onErrorCheck(); | ||
148 | } else { | ||
149 | Intent intent = new Intent(context, ErrorDetailActivity.class); | ||
150 | intent.putExtra("errorBean", topicBean); | ||
151 | context.startActivity(intent); | ||
152 | } | ||
153 | } | ||
154 | return true; | ||
155 | } | ||
156 | }); | ||
139 | if (bean.getPoints().size() > 0) { | 157 | if (bean.getPoints().size() > 0) { |
140 | String topic = context.getString(R.string.topic_start); | 158 | String topic = context.getString(R.string.topic_start); |
141 | topic += ":"; | 159 | topic += ":"; |
142 | 160 | ||
143 | for (int j = 0; j < bean.getPoints().size(); j++) { | 161 | for (int j = 0; j < bean.getPoints().size(); j++) { |
144 | if (j > 0) { | 162 | if (j > 0) { |
145 | topic += "、"; | 163 | topic += "、"; |
146 | } | 164 | } |
147 | topic += bean.getPoints().get(j).getValue(); | 165 | topic += bean.getPoints().get(j).getValue(); |
148 | } | 166 | } |
149 | holder.binding.tvPoint.setText(topic); | 167 | holder.binding.tvPoint.setText(topic); |
150 | holder.binding.tvPoint.setVisibility(View.VISIBLE); | 168 | holder.binding.tvPoint.setVisibility(View.VISIBLE); |
151 | } else { | 169 | } else { |
152 | holder.binding.tvPoint.setVisibility(View.GONE); | 170 | holder.binding.tvPoint.setVisibility(View.GONE); |
153 | } | 171 | } |
154 | } else { | 172 | } else { |
155 | holder.binding.webview.setVisibility(View.GONE); | 173 | holder.binding.webview.setVisibility(View.GONE); |
156 | holder.binding.tvPoint.setVisibility(View.GONE); | 174 | holder.binding.tvPoint.setVisibility(View.GONE); |
157 | holder.binding.ivTopic.setVisibility(View.VISIBLE); | 175 | holder.binding.ivTopic.setVisibility(View.VISIBLE); |
158 | int maxWidth = CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 60); | 176 | int maxWidth = CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 60); |
159 | Glide.with(context).load(topicBean.getPath()).into(new SimpleTarget<Drawable>() { | 177 | Glide.with(context).load(topicBean.getPath()).into(new SimpleTarget<Drawable>() { |
160 | @Override | 178 | @Override |
161 | public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { | 179 | public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { |
162 | int width = resource.getIntrinsicWidth(); | 180 | int width = resource.getIntrinsicWidth(); |
163 | int height = resource.getIntrinsicHeight(); | 181 | int height = resource.getIntrinsicHeight(); |
164 | int newHeight = maxWidth * height / width; | 182 | int newHeight = maxWidth * height / width; |
165 | LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.binding.ivTopic.getLayoutParams(); | 183 | LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.binding.ivTopic.getLayoutParams(); |
166 | layoutParams.width = maxWidth; | 184 | layoutParams.width = maxWidth; |
167 | layoutParams.height = newHeight; | 185 | layoutParams.height = newHeight; |
168 | holder.binding.ivTopic.setLayoutParams(layoutParams); | 186 | holder.binding.ivTopic.setLayoutParams(layoutParams); |
169 | holder.binding.ivTopic.setImageDrawable(resource); | 187 | holder.binding.ivTopic.setImageDrawable(resource); |
170 | } | 188 | } |
171 | }); | 189 | }); |
172 | } | 190 | } |
173 | holder.itemView.setOnClickListener(new View.OnClickListener() { | 191 | holder.itemView.setOnClickListener(new View.OnClickListener() { |
174 | @Override | 192 | @Override |
175 | public void onClick(View v) { | 193 | public void onClick(View v) { |
176 | if (edit) { | 194 | if (edit) { |
177 | list.get(position).setCheck(!topicBean.isCheck()); | 195 | list.get(position).setCheck(!topicBean.isCheck()); |
178 | notifyItemChanged(position); | 196 | notifyItemChanged(position); |
179 | checkInterface.onErrorCheck(); | 197 | checkInterface.onErrorCheck(); |
180 | } else { | 198 | } else { |
181 | Intent intent = new Intent(context, ErrorDetailActivity.class); | 199 | Intent intent = new Intent(context, ErrorDetailActivity.class); |
182 | intent.putExtra("errorBean", topicBean); | 200 | intent.putExtra("errorBean", topicBean); |
183 | context.startActivity(intent); | 201 | context.startActivity(intent); |
184 | } | 202 | } |
185 | } | 203 | } |
186 | }); | 204 | }); |
187 | } | 205 | } |
188 | 206 | ||
189 | @Override | 207 | @Override |
190 | public int getItemCount() { | 208 | public int getItemCount() { |
191 | return list.size(); | 209 | return list.size(); |
192 | } | 210 | } |
193 | 211 | ||
194 | static class ErrorHolder extends RecyclerView.ViewHolder { | 212 | static class ErrorHolder extends RecyclerView.ViewHolder { |
195 | ItemErrorBinding binding; | 213 | ItemErrorBinding binding; |
196 | 214 | ||
197 | public ErrorHolder(@NonNull ItemErrorBinding itemView) { | 215 | public ErrorHolder(@NonNull ItemErrorBinding itemView) { |
198 | super(itemView.getRoot()); | 216 | super(itemView.getRoot()); |
199 | binding = itemView; | 217 | binding = itemView; |
200 | } | 218 | } |
201 | } | 219 | } |
202 | } | 220 | } |
203 | 221 |
app/src/main/res/layout/activity_error_detail.xml
1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
2 | xmlns:tools="http://schemas.android.com/tools" | 2 | xmlns:tools="http://schemas.android.com/tools" |
3 | xmlns:xxx="http://schemas.android.com/apk/res-auto" | 3 | xmlns:xxx="http://schemas.android.com/apk/res-auto" |
4 | android:layout_width="match_parent" | 4 | android:layout_width="match_parent" |
5 | android:layout_height="match_parent" | 5 | android:layout_height="match_parent" |
6 | android:background="#F5F5F5" | 6 | android:background="#F5F5F5" |
7 | android:orientation="vertical"> | 7 | android:orientation="vertical"> |
8 | 8 | ||
9 | <RelativeLayout | 9 | <RelativeLayout |
10 | android:id="@+id/rl_top" | 10 | android:id="@+id/rl_top" |
11 | android:layout_width="match_parent" | 11 | android:layout_width="match_parent" |
12 | android:layout_height="40dp" | 12 | android:layout_height="40dp" |
13 | android:background="@color/white"> | 13 | android:background="@color/white"> |
14 | 14 | ||
15 | <TextView | 15 | <TextView |
16 | android:id="@+id/tv_title" | 16 | android:id="@+id/tv_title" |
17 | android:layout_width="wrap_content" | 17 | android:layout_width="wrap_content" |
18 | android:layout_height="wrap_content" | 18 | android:layout_height="wrap_content" |
19 | android:layout_centerInParent="true" | 19 | android:layout_centerInParent="true" |
20 | android:ellipsize="end" | 20 | android:ellipsize="end" |
21 | android:maxWidth="330dp" | 21 | android:maxWidth="330dp" |
22 | android:singleLine="true" | 22 | android:singleLine="true" |
23 | android:textColor="#333333" | 23 | android:textColor="#333333" |
24 | android:textSize="18sp" /> | 24 | android:textSize="18sp" /> |
25 | 25 | ||
26 | <ImageView | 26 | <ImageView |
27 | android:id="@+id/iv_edit" | 27 | android:id="@+id/iv_edit" |
28 | android:layout_width="40dp" | 28 | android:layout_width="40dp" |
29 | android:layout_height="40dp" | 29 | android:layout_height="40dp" |
30 | android:layout_toRightOf="@+id/tv_title" | 30 | android:layout_toRightOf="@+id/tv_title" |
31 | android:padding="10dp" | 31 | android:padding="10dp" |
32 | android:src="@mipmap/ic_error_edit" /> | 32 | android:src="@mipmap/ic_error_edit" /> |
33 | 33 | ||
34 | <ImageView | 34 | <ImageView |
35 | android:id="@+id/iv_back" | 35 | android:id="@+id/iv_back" |
36 | android:layout_width="30dp" | 36 | android:layout_width="30dp" |
37 | android:layout_height="36dp" | 37 | android:layout_height="36dp" |
38 | android:layout_centerVertical="true" | 38 | android:layout_centerVertical="true" |
39 | android:layout_marginLeft="5dp" | 39 | android:layout_marginLeft="5dp" |
40 | android:padding="10dp" | 40 | android:padding="10dp" |
41 | android:src="@mipmap/icon_back" /> | 41 | android:src="@mipmap/icon_back" /> |
42 | 42 | ||
43 | </RelativeLayout> | 43 | </RelativeLayout> |
44 | 44 | ||
45 | <ScrollView | 45 | <ScrollView |
46 | android:layout_width="match_parent" | 46 | android:layout_width="match_parent" |
47 | android:layout_height="match_parent"> | 47 | android:layout_height="match_parent"> |
48 | 48 | ||
49 | <LinearLayout | 49 | <LinearLayout |
50 | android:layout_width="match_parent" | 50 | android:layout_width="match_parent" |
51 | android:layout_height="wrap_content" | 51 | android:layout_height="wrap_content" |
52 | android:background="#F5F5F5" | 52 | android:background="#F5F5F5" |
53 | android:orientation="vertical"> | 53 | android:orientation="vertical"> |
54 | 54 | ||
55 | <LinearLayout | 55 | <LinearLayout |
56 | android:id="@+id/ll_pic" | 56 | android:id="@+id/ll_pic" |
57 | android:layout_width="match_parent" | 57 | android:layout_width="match_parent" |
58 | android:layout_height="wrap_content" | 58 | android:layout_height="wrap_content" |
59 | android:background="@color/white" | 59 | android:background="@color/white" |
60 | android:orientation="vertical"> | 60 | android:orientation="vertical"> |
61 | 61 | ||
62 | <TextView | 62 | <TextView |
63 | android:layout_width="wrap_content" | 63 | android:layout_width="wrap_content" |
64 | android:layout_height="wrap_content" | 64 | android:layout_height="wrap_content" |
65 | android:layout_marginLeft="15dp" | 65 | android:layout_marginLeft="15dp" |
66 | android:layout_marginTop="15dp" | 66 | android:layout_marginTop="15dp" |
67 | android:text="原题图片" | 67 | android:text="原题图片" |
68 | android:textColor="@color/text_title" | 68 | android:textColor="@color/text_title" |
69 | android:textSize="15sp" /> | 69 | android:textSize="15sp" /> |
70 | 70 | ||
71 | <RelativeLayout | 71 | <RelativeLayout |
72 | android:layout_width="match_parent" | 72 | android:layout_width="match_parent" |
73 | android:layout_height="90dp" | 73 | android:layout_height="90dp" |
74 | android:layout_marginLeft="15dp" | 74 | android:layout_marginLeft="15dp" |
75 | android:layout_marginTop="15dp" | 75 | android:layout_marginTop="15dp" |
76 | android:layout_marginRight="15dp" | 76 | android:layout_marginRight="15dp" |
77 | android:layout_marginBottom="15dp"> | 77 | android:layout_marginBottom="15dp"> |
78 | 78 | ||
79 | <RelativeLayout | 79 | <RelativeLayout |
80 | android:layout_width="match_parent" | 80 | android:layout_width="match_parent" |
81 | android:layout_height="match_parent" | 81 | android:layout_height="match_parent" |
82 | android:background="#F5F5F5"> | 82 | android:background="#F5F5F5"> |
83 | 83 | ||
84 | <ImageView | 84 | <ImageView |
85 | android:id="@+id/iv_topic" | 85 | android:id="@+id/iv_topic" |
86 | android:layout_width="wrap_content" | 86 | android:layout_width="wrap_content" |
87 | android:layout_height="wrap_content" | 87 | android:layout_height="wrap_content" |
88 | android:layout_centerVertical="true" /> | 88 | android:layout_centerVertical="true" /> |
89 | </RelativeLayout> | 89 | </RelativeLayout> |
90 | </RelativeLayout> | 90 | </RelativeLayout> |
91 | </LinearLayout> | 91 | </LinearLayout> |
92 | 92 | ||
93 | <LinearLayout | 93 | <LinearLayout |
94 | android:id="@+id/ll_origin" | 94 | android:id="@+id/ll_origin" |
95 | android:layout_width="match_parent" | 95 | android:layout_width="match_parent" |
96 | android:layout_height="wrap_content" | 96 | android:layout_height="wrap_content" |
97 | android:background="@color/white" | 97 | android:background="@color/white" |
98 | android:orientation="vertical" | 98 | android:orientation="vertical" |
99 | tools:ignore="WebViewLayout"> | 99 | tools:ignore="WebViewLayout"> |
100 | 100 | ||
101 | <TextView | 101 | <TextView |
102 | android:layout_width="wrap_content" | 102 | android:layout_width="wrap_content" |
103 | android:layout_height="wrap_content" | 103 | android:layout_height="wrap_content" |
104 | android:layout_marginLeft="15dp" | 104 | android:layout_marginLeft="15dp" |
105 | android:layout_marginTop="15dp" | 105 | android:layout_marginTop="15dp" |
106 | android:text="题目" | 106 | android:text="题目" |
107 | android:textColor="@color/text_title" | 107 | android:textColor="@color/text_title" |
108 | android:textSize="15sp" /> | 108 | android:textSize="15sp" /> |
109 | 109 | ||
110 | <WebView | 110 | <WebView |
111 | android:id="@+id/web_content" | 111 | android:id="@+id/web_content" |
112 | android:layout_width="wrap_content" | 112 | android:layout_width="wrap_content" |
113 | android:layout_height="wrap_content" | 113 | android:layout_height="wrap_content" |
114 | android:layout_marginLeft="10dp" | 114 | android:layout_marginLeft="10dp" |
115 | android:layout_marginTop="10dp" | 115 | android:layout_marginTop="10dp" |
116 | android:layout_marginBottom="10dp" /> | 116 | android:layout_marginBottom="10dp" /> |
117 | </LinearLayout> | 117 | </LinearLayout> |
118 | 118 | ||
119 | <LinearLayout | 119 | <LinearLayout |
120 | android:id="@+id/ll_analyse" | 120 | android:id="@+id/ll_analyse" |
121 | android:layout_width="match_parent" | 121 | android:layout_width="match_parent" |
122 | android:layout_height="wrap_content" | 122 | android:layout_height="wrap_content" |
123 | android:layout_marginTop="15dp" | 123 | android:layout_marginTop="15dp" |
124 | android:background="@color/white" | 124 | android:background="@color/white" |
125 | android:orientation="vertical" | 125 | android:orientation="vertical" |
126 | tools:ignore="WebViewLayout"> | 126 | tools:ignore="WebViewLayout"> |
127 | 127 | ||
128 | <TextView | 128 | <TextView |
129 | android:layout_width="wrap_content" | 129 | android:layout_width="wrap_content" |
130 | android:layout_height="wrap_content" | 130 | android:layout_height="wrap_content" |
131 | android:layout_marginLeft="15dp" | 131 | android:layout_marginLeft="15dp" |
132 | android:layout_marginTop="15dp" | 132 | android:layout_marginTop="15dp" |
133 | android:text="解答" | 133 | android:text="解答" |
134 | android:textColor="@color/text_title" | 134 | android:textColor="@color/text_title" |
135 | android:textSize="15sp" /> | 135 | android:textSize="15sp" /> |
136 | 136 | ||
137 | <LinearLayout | 137 | <LinearLayout |
138 | android:layout_width="match_parent" | 138 | android:layout_width="match_parent" |
139 | android:layout_height="wrap_content" | 139 | android:layout_height="wrap_content" |
140 | android:layout_margin="15dp" | 140 | android:layout_margin="15dp" |
141 | android:background="@drawable/bg_soild_gray_5"> | 141 | android:background="@drawable/bg_soild_gray_5"> |
142 | 142 | ||
143 | <WebView | 143 | <WebView |
144 | android:id="@+id/web_analyse" | 144 | android:id="@+id/web_analyse" |
145 | android:background="#F5F5F5" | ||
145 | android:layout_width="wrap_content" | 146 | android:layout_width="wrap_content" |
146 | android:layout_height="wrap_content" | 147 | android:layout_height="wrap_content" |
147 | android:layout_margin="10dp" /> | 148 | android:layout_margin="10dp" /> |
148 | </LinearLayout> | 149 | </LinearLayout> |
149 | </LinearLayout> | 150 | </LinearLayout> |
150 | 151 | ||
151 | <LinearLayout | 152 | <LinearLayout |
152 | android:id="@+id/ll_answer" | 153 | android:id="@+id/ll_answer" |
153 | android:layout_width="match_parent" | 154 | android:layout_width="match_parent" |
154 | android:layout_height="wrap_content" | 155 | android:layout_height="wrap_content" |
155 | android:layout_marginTop="15dp" | 156 | android:layout_marginTop="15dp" |
156 | android:background="@color/white" | 157 | android:background="@color/white" |
157 | android:orientation="vertical" | 158 | android:orientation="vertical" |
158 | tools:ignore="WebViewLayout"> | 159 | tools:ignore="WebViewLayout"> |
159 | 160 | ||
160 | <TextView | 161 | <TextView |
161 | android:layout_width="wrap_content" | 162 | android:layout_width="wrap_content" |
162 | android:layout_height="wrap_content" | 163 | android:layout_height="wrap_content" |
163 | android:layout_marginLeft="15dp" | 164 | android:layout_marginLeft="15dp" |
164 | android:layout_marginTop="15dp" | 165 | android:layout_marginTop="15dp" |
165 | android:text="答案" | 166 | android:text="答案" |
166 | android:textColor="@color/text_title" | 167 | android:textColor="@color/text_title" |
167 | android:textSize="15sp" /> | 168 | android:textSize="15sp" /> |
168 | 169 | ||
169 | <LinearLayout | 170 | <LinearLayout |
170 | android:layout_width="match_parent" | 171 | android:layout_width="match_parent" |
171 | android:layout_height="wrap_content" | 172 | android:layout_height="wrap_content" |
172 | android:layout_margin="15dp" | 173 | android:layout_margin="15dp" |
173 | android:background="@drawable/bg_soild_gray_5"> | 174 | android:background="@drawable/bg_soild_gray_5"> |
174 | 175 | ||
175 | <WebView | 176 | <WebView |
176 | android:id="@+id/web_answer" | 177 | android:id="@+id/web_answer" |
177 | android:layout_width="wrap_content" | 178 | android:layout_width="wrap_content" |
178 | android:layout_height="wrap_content" | 179 | android:layout_height="wrap_content" |
180 | android:background="#F5F5F5" | ||
179 | android:layout_margin="10dp" /> | 181 | android:layout_margin="10dp" /> |
180 | </LinearLayout> | 182 | </LinearLayout> |
181 | </LinearLayout> | 183 | </LinearLayout> |
182 | 184 | ||
183 | <LinearLayout | 185 | <LinearLayout |
184 | android:id="@+id/ll_points" | 186 | android:id="@+id/ll_points" |
185 | android:layout_width="match_parent" | 187 | android:layout_width="match_parent" |
186 | android:layout_height="wrap_content" | 188 | android:layout_height="wrap_content" |
187 | android:layout_marginTop="15dp" | 189 | android:layout_marginTop="15dp" |
188 | android:background="@color/white" | 190 | android:background="@color/white" |
189 | android:orientation="vertical" | 191 | android:orientation="vertical" |
190 | tools:ignore="WebViewLayout"> | 192 | tools:ignore="WebViewLayout"> |
191 | 193 | ||
192 | <TextView | 194 | <TextView |
193 | android:layout_width="wrap_content" | 195 | android:layout_width="wrap_content" |
194 | android:layout_height="wrap_content" | 196 | android:layout_height="wrap_content" |
195 | android:layout_marginLeft="15dp" | 197 | android:layout_marginLeft="15dp" |
196 | android:layout_marginTop="15dp" | 198 | android:layout_marginTop="15dp" |
197 | android:text="知识点" | 199 | android:text="知识点" |
198 | android:textColor="@color/text_title" | 200 | android:textColor="@color/text_title" |
199 | android:textSize="15sp" /> | 201 | android:textSize="15sp" /> |
200 | 202 | ||
201 | <LinearLayout | 203 | <LinearLayout |
202 | android:layout_width="match_parent" | 204 | android:layout_width="match_parent" |
203 | android:layout_height="40dp" | 205 | android:layout_height="40dp" |
204 | android:layout_margin="15dp" | 206 | android:layout_margin="15dp" |
205 | android:background="@drawable/bg_soild_gray_5"> | 207 | android:background="@drawable/bg_soild_gray_5"> |
206 | 208 | ||
207 | <TextView | 209 | <TextView |
208 | android:id="@+id/tv_points" | 210 | android:id="@+id/tv_points" |
209 | android:layout_width="wrap_content" | 211 | android:layout_width="wrap_content" |
210 | android:layout_height="wrap_content" | 212 | android:layout_height="wrap_content" |
211 | android:layout_gravity="center_vertical" | 213 | android:layout_gravity="center_vertical" |
212 | android:layout_marginLeft="15dp" | 214 | android:layout_marginLeft="15dp" |
213 | android:gravity="center_vertical" | 215 | android:gravity="center_vertical" |
214 | android:textColor="#1C90F3" | 216 | android:textColor="#1C90F3" |
215 | android:textSize="14sp" /> | 217 | android:textSize="14sp" /> |
216 | </LinearLayout> | 218 | </LinearLayout> |
217 | </LinearLayout> | 219 | </LinearLayout> |
218 | 220 | ||
219 | <LinearLayout | 221 | <LinearLayout |
220 | android:id="@+id/ll_reason" | 222 | android:id="@+id/ll_reason" |
221 | android:layout_width="match_parent" | 223 | android:layout_width="match_parent" |
222 | android:layout_height="wrap_content" | 224 | android:layout_height="wrap_content" |
223 | android:layout_marginTop="15dp" | 225 | android:layout_marginTop="15dp" |
224 | android:background="@color/white" | 226 | android:background="@color/white" |
225 | android:orientation="vertical" | 227 | android:orientation="vertical" |
226 | tools:ignore="WebViewLayout"> | 228 | tools:ignore="WebViewLayout"> |
227 | 229 | ||
228 | <TextView | 230 | <TextView |
229 | android:layout_width="wrap_content" | 231 | android:layout_width="wrap_content" |
230 | android:layout_height="wrap_content" | 232 | android:layout_height="wrap_content" |
231 | android:layout_marginLeft="15dp" | 233 | android:layout_marginLeft="15dp" |
232 | android:layout_marginTop="15dp" | 234 | android:layout_marginTop="15dp" |
233 | android:text="错误原因" | 235 | android:text="错误原因" |
234 | android:textColor="@color/text_title" | 236 | android:textColor="@color/text_title" |
235 | android:textSize="15sp" /> | 237 | android:textSize="15sp" /> |
236 | 238 | ||
237 | <androidx.appcompat.widget.AppCompatSpinner | 239 | <androidx.appcompat.widget.AppCompatSpinner |
238 | android:id="@+id/spinner_reason" | 240 | android:id="@+id/spinner_reason" |
239 | style="@style/customSpinnerStyle" | 241 | style="@style/customSpinnerStyle" |
240 | android:layout_width="match_parent" | 242 | android:layout_width="match_parent" |
241 | android:layout_height="40dp" | 243 | android:layout_height="40dp" |
242 | android:layout_centerHorizontal="true" | 244 | android:layout_centerHorizontal="true" |
243 | android:layout_marginLeft="15dp" | 245 | android:layout_marginLeft="15dp" |
244 | android:layout_marginTop="15dp" | 246 | android:layout_marginTop="15dp" |
245 | android:layout_marginRight="15dp" | 247 | android:layout_marginRight="15dp" |
246 | android:layout_marginBottom="15dp" | 248 | android:layout_marginBottom="15dp" |
247 | android:background="@drawable/selector_for_custom_spinner" | 249 | android:background="@drawable/selector_for_custom_spinner" |
248 | android:entries="@array/error_reason" | 250 | android:entries="@array/error_reason" |
249 | android:popupBackground="@drawable/shape_for_custom_spinner" | 251 | android:popupBackground="@drawable/shape_for_custom_spinner" |
250 | android:scrollbars="none" /> | 252 | android:scrollbars="none" /> |
251 | </LinearLayout> | 253 | </LinearLayout> |
252 | 254 | ||
253 | <LinearLayout | 255 | <LinearLayout |
254 | android:layout_width="match_parent" | 256 | android:layout_width="match_parent" |
255 | android:layout_height="wrap_content" | 257 | android:layout_height="wrap_content" |
256 | android:layout_marginTop="15dp" | 258 | android:layout_marginTop="15dp" |
257 | android:layout_marginBottom="15dp" | 259 | android:layout_marginBottom="15dp" |
258 | android:background="@color/white" | 260 | android:background="@color/white" |
259 | android:orientation="vertical" | 261 | android:orientation="vertical" |
260 | tools:ignore="WebViewLayout"> | 262 | tools:ignore="WebViewLayout"> |
261 | 263 | ||
262 | <TextView | 264 | <TextView |
263 | android:layout_width="wrap_content" | 265 | android:layout_width="wrap_content" |
264 | android:layout_height="wrap_content" | 266 | android:layout_height="wrap_content" |
265 | android:layout_marginLeft="15dp" | 267 | android:layout_marginLeft="15dp" |
266 | android:layout_marginTop="15dp" | 268 | android:layout_marginTop="15dp" |
267 | android:text="掌握状态" | 269 | android:text="掌握状态" |
268 | android:textColor="@color/text_title" | 270 | android:textColor="@color/text_title" |
269 | android:textSize="15sp" /> | 271 | android:textSize="15sp" /> |
270 | 272 | ||
271 | <RadioGroup | 273 | <RadioGroup |
272 | android:id="@+id/type_radio" | 274 | android:id="@+id/type_radio" |
273 | android:layout_width="match_parent" | 275 | android:layout_width="match_parent" |
274 | android:layout_height="40dp" | 276 | android:layout_height="40dp" |
275 | android:layout_marginLeft="15dp" | 277 | android:layout_marginLeft="15dp" |
276 | android:layout_marginTop="15dp" | 278 | android:layout_marginTop="15dp" |
277 | android:layout_marginBottom="15dp" | 279 | android:layout_marginBottom="15dp" |
278 | android:orientation="horizontal"> | 280 | android:orientation="horizontal"> |
279 | 281 | ||
280 | <RadioButton | 282 | <RadioButton |
281 | android:layout_width="70dp" | 283 | android:layout_width="70dp" |
282 | android:layout_height="match_parent" | 284 | android:layout_height="match_parent" |
283 | android:layout_marginRight="20dp" | 285 | android:layout_marginRight="20dp" |
284 | android:background="@drawable/radio_button_selector" | 286 | android:background="@drawable/radio_button_selector" |
285 | android:button="@null" | 287 | android:button="@null" |
286 | android:gravity="center" | 288 | android:gravity="center" |
287 | android:text="已掌握" | 289 | android:text="已掌握" |
288 | android:textColor="@drawable/radio_text_selector" | 290 | android:textColor="@drawable/radio_text_selector" |
289 | android:textSize="14sp" /> | 291 | android:textSize="14sp" /> |
290 | 292 | ||
291 | <RadioButton | 293 | <RadioButton |
292 | android:layout_width="70dp" | 294 | android:layout_width="70dp" |
293 | android:layout_height="match_parent" | 295 | android:layout_height="match_parent" |
294 | android:layout_marginRight="20dp" | 296 | android:layout_marginRight="20dp" |
295 | android:background="@drawable/radio_button_selector" | 297 | android:background="@drawable/radio_button_selector" |
296 | android:button="@null" | 298 | android:button="@null" |
297 | android:gravity="center" | 299 | android:gravity="center" |
298 | android:text="未掌握" | 300 | android:text="未掌握" |
299 | android:textColor="@drawable/radio_text_selector" | 301 | android:textColor="@drawable/radio_text_selector" |
300 | android:textSize="14sp" /> | 302 | android:textSize="14sp" /> |
301 | </RadioGroup> | 303 | </RadioGroup> |
302 | </LinearLayout> | 304 | </LinearLayout> |
305 | |||
306 | <TextView | ||
307 | android:id="@+id/tv_tip" | ||
308 | android:layout_width="wrap_content" | ||
309 | android:layout_height="wrap_content" | ||
310 | android:layout_gravity="center_horizontal" | ||
311 | android:layout_marginTop="50dp" | ||
312 | android:gravity="center_horizontal" | ||
313 | android:text="家长端暂不支持错题匹配和知识点分析\n请在学生平板端完成操作" | ||
314 | android:textColor="#999999" | ||
315 | android:visibility="gone" /> | ||
303 | </LinearLayout> | 316 | </LinearLayout> |
304 | </ScrollView> | 317 | </ScrollView> |
305 | </LinearLayout> | 318 | </LinearLayout> |
app/src/main/res/values/styles.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <resources> | 2 | <resources> |
3 | 3 | ||
4 | 4 | ||
5 | <style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar"> | 5 | <style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar"> |
6 | <item name="android:windowBackground">@drawable/welcome_bg</item> | 6 | <item name="android:windowBackground">@drawable/welcome_bg</item> |
7 | <item name="colorPrimaryDark">@android:color/transparent</item> | 7 | <item name="colorPrimaryDark">@android:color/transparent</item> |
8 | <item name="windowActionBar">false</item> | 8 | <item name="windowActionBar">false</item> |
9 | <item name="windowNoTitle">true</item> | 9 | <item name="windowNoTitle">true</item> |
10 | <item name="android:windowFullscreen">true</item> | 10 | <item name="android:windowFullscreen">true</item> |
11 | </style> | 11 | </style> |
12 | 12 | ||
13 | <style name="main_bottom_navigaton_menu_item"> | 13 | <style name="main_bottom_navigaton_menu_item"> |
14 | <item name="android:layout_width">0dp</item> | 14 | <item name="android:layout_width">0dp</item> |
15 | <item name="android:layout_weight">1</item> | 15 | <item name="android:layout_weight">1</item> |
16 | <item name="android:layout_height">match_parent</item> | 16 | <item name="android:layout_height">match_parent</item> |
17 | <item name="android:background">@android:color/transparent</item> | 17 | <item name="android:background">@android:color/transparent</item> |
18 | <item name="android:button">@null</item> | 18 | <item name="android:button">@null</item> |
19 | <item name="android:gravity">center</item> | 19 | <item name="android:gravity">center</item> |
20 | <item name="android:textSize">11dp</item> | 20 | <item name="android:textSize">11dp</item> |
21 | <item name="android:drawablePadding">2dp</item> | 21 | <item name="android:drawablePadding">2dp</item> |
22 | </style> | 22 | </style> |
23 | <!--实现BottomSheetDialog圆角效果--> | 23 | <!--实现BottomSheetDialog圆角效果--> |
24 | <style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog"> | 24 | <style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog"> |
25 | <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item> | 25 | <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item> |
26 | </style> | 26 | </style> |
27 | 27 | ||
28 | <style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal"> | 28 | <style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal"> |
29 | <item name="android:background">@android:color/transparent</item> | 29 | <item name="android:background">@android:color/transparent</item> |
30 | <item name="android:navigationBarColor">@android:color/transparent</item> | 30 | <item name="android:navigationBarColor">@android:color/transparent</item> |
31 | <item name="behavior_peekHeight">500dp</item> | 31 | <item name="behavior_peekHeight">500dp</item> |
32 | </style> | 32 | </style> |
33 | 33 | ||
34 | <style name="MyAlertDialog" parent="android:Theme.Material.Dialog.Alert"> | 34 | <style name="MyAlertDialog" parent="android:Theme.Material.Dialog.Alert"> |
35 | <!--背景颜色及和透明程度--> | 35 | <!--背景颜色及和透明程度--> |
36 | <item name="android:windowBackground">@null</item> | 36 | <item name="android:windowBackground">@null</item> |
37 | <!--是否去除标题 --> | 37 | <!--是否去除标题 --> |
38 | <item name="android:windowNoTitle">true</item> | 38 | <item name="android:windowNoTitle">true</item> |
39 | <!--是否去除边框--> | 39 | <!--是否去除边框--> |
40 | <item name="android:windowFrame">@null</item> | 40 | <item name="android:windowFrame">@null</item> |
41 | <!--是否浮现在activity之上--> | 41 | <!--是否浮现在activity之上--> |
42 | <item name="android:windowIsFloating">true</item> | 42 | <item name="android:windowIsFloating">true</item> |
43 | <!--是否模糊--> | 43 | <!--是否模糊--> |
44 | <item name="android:backgroundDimEnabled">true</item> | 44 | <item name="android:backgroundDimEnabled">true</item> |
45 | <item name="android:windowIsTranslucent">true</item><!--半透明--> | 45 | <item name="android:windowIsTranslucent">true</item><!--半透明--> |
46 | <item name="android:windowSoftInputMode">stateVisible|adjustPan</item> | 46 | <item name="android:windowSoftInputMode">stateVisible|adjustPan</item> |
47 | </style> | 47 | </style> |
48 | 48 | ||
49 | <style name="customSpinnerStyle" parent="android:Widget.ListView.DropDown"> | 49 | <style name="customSpinnerStyle" parent="android:Widget.ListView.DropDown"> |
50 | <item name="divider">@color/border</item> | 50 | <item name="divider">@color/border</item> |
51 | <item name="android:scrollbars">none</item> | 51 | <item name="android:scrollbars">none</item> |
52 | <item name="android:dividerHeight">1dp</item> | 52 | <item name="android:dividerHeight">1dp</item> |
53 | <item name="android:textSize">15sp</item> | ||
53 | </style> | 54 | </style> |
54 | 55 | ||
55 | 56 | ||
56 |
build.gradle
1 | buildscript { | 1 | buildscript { |
2 | 2 | ||
3 | 3 | ||
4 | ext { | 4 | ext { |
5 | 5 | ||
6 | 6 | ||
7 | androidId = [ | 7 | androidId = [ |
8 | compileSdkVersion: 32, | 8 | compileSdkVersion: 32, |
9 | minSdkVersion : 24, | 9 | minSdkVersion : 24, |
10 | targetSdkVersion : 32, | 10 | targetSdkVersion : 32, |
11 | versionCode : 1, | 11 | versionCode : 1, |
12 | versionName : "0.0.1" | 12 | versionName : "0.0.1" |
13 | 13 | ||
14 | 14 | ||
15 | ] | 15 | ] |
16 | 16 | ||
17 | 17 | ||
18 | url = [ | 18 | url = [ |
19 | server_url : "http://192.168.3.155:8088", //http 请求指令 | 19 | server_url : "http://192.168.3.37:8088", //http 请求指令 |
20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 | 20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 |
21 | ] | 21 | ] |
22 | 22 | ||
23 | 23 | ||
24 | dependencies = [ | 24 | dependencies = [ |
25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', | 25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', |
26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', | 26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', |
27 | cardview : 'androidx.cardview:cardview:1.0.0', | 27 | cardview : 'androidx.cardview:cardview:1.0.0', |
28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', | 28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', |
29 | material : 'com.google.android.material:material:1.0.0', | 29 | material : 'com.google.android.material:material:1.0.0', |
30 | // 依赖RxAndroid 2X 的依赖库 | 30 | // 依赖RxAndroid 2X 的依赖库 |
31 | // 增加RxJava 2X 的依赖库 | 31 | // 增加RxJava 2X 的依赖库 |
32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', | 32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', |
33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', | 33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', |
34 | 34 | ||
35 | // 以下需要使用Retrofit | 35 | // 以下需要使用Retrofit |
36 | //retrofit | 36 | //retrofit |
37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', | 37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', |
38 | //Gson converter | 38 | //Gson converter |
39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', | 39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', |
40 | //RxJava2 Adapter | 40 | //RxJava2 Adapter |
41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', | 41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', |
42 | //okhttp | 42 | //okhttp |
43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', | 43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', |
44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', | 44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', |
45 | utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', | 45 | utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', |
46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', | 46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', |
47 | commons_compress: 'org.apache.commons:commons-compress:1.19', | 47 | commons_compress: 'org.apache.commons:commons-compress:1.19', |
48 | commons_c_lang : 'commons-lang:commons-lang:2.3', | 48 | commons_c_lang : 'commons-lang:commons-lang:2.3', |
49 | commons_codec : 'commons-codec:commons-codec:1.7', | 49 | commons_codec : 'commons-codec:commons-codec:1.7', |
50 | eventbus : 'org.greenrobot:eventbus:3.2.0', | 50 | eventbus : 'org.greenrobot:eventbus:3.2.0', |
51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', | 51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', |
52 | glide : 'com.github.bumptech.glide:glide:4.6.1', | 52 | glide : 'com.github.bumptech.glide:glide:4.6.1', |
53 | permissions : 'com.github.getActivity:XXPermissions:11.6', | 53 | permissions : 'com.github.getActivity:XXPermissions:11.6', |
54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' | 54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' |
55 | // push : 'com.umeng.sdk:push:4.1.0', | 55 | // push : 'com.umeng.sdk:push:4.1.0', |
56 | // litepal : 'org.litepal.android:java:3.0.0', | 56 | // litepal : 'org.litepal.android:java:3.0.0', |
57 | 57 | ||
58 | 58 | ||
59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', | 59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', |
60 | 60 | ||
61 | // | 61 | // |
62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', | 62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', |
63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', | 63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', |
64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' | 64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' |
65 | 65 | ||
66 | 66 | ||
67 | ] | 67 | ] |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | repositories { | 71 | repositories { |
72 | google() | 72 | google() |
73 | jcenter() | 73 | jcenter() |
74 | maven { url 'https://maven.aliyun.com/repository/jcenter' } | 74 | maven { url 'https://maven.aliyun.com/repository/jcenter' } |
75 | maven { url 'https://maven.aliyun.com/repository/google' } | 75 | maven { url 'https://maven.aliyun.com/repository/google' } |
76 | maven { url 'https://maven.aliyun.com/repository/central' } | 76 | maven { url 'https://maven.aliyun.com/repository/central' } |
77 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } | 77 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } |
78 | } | 78 | } |
79 | dependencies { | 79 | dependencies { |
80 | classpath 'com.android.tools.build:gradle:4.2.2' | 80 | classpath 'com.android.tools.build:gradle:4.2.2' |
81 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' | 81 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' |
82 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' | 82 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' |
83 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' | 83 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' |
84 | classpath "com.alibaba:arouter-register:1.0.2" | 84 | classpath "com.alibaba:arouter-register:1.0.2" |
85 | // NOTE: Do not place your application dependencies here; they belong | 85 | // NOTE: Do not place your application dependencies here; they belong |
86 | // in the individual module build.gradle files | 86 | // in the individual module build.gradle files |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | allprojects { | 93 | allprojects { |
94 | repositories { | 94 | repositories { |
95 | google() | 95 | google() |
96 | jcenter() | 96 | jcenter() |
97 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } | 97 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } |
98 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } | 98 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } |
99 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } | 99 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } |
100 | maven { url 'https://jitpack.io' } | 100 | maven { url 'https://jitpack.io' } |
101 | } | 101 | } |
102 | } | 102 | } |
103 | task clean(type: Delete) { | 103 | task clean(type: Delete) { |
104 | delete rootProject.buildDir | 104 | delete rootProject.buildDir |
105 | } | 105 | } |
106 | 106 |
libs/common/src/main/java/com/prws/common/base/BaseActivity.java
1 | package com.prws.common.base; | 1 | package com.prws.common.base; |
2 | 2 | ||
3 | 3 | ||
4 | import android.app.Activity; | 4 | import android.app.Activity; |
5 | import android.app.AlertDialog; | 5 | import android.app.AlertDialog; |
6 | import android.content.Context; | 6 | import android.content.Context; |
7 | import android.content.DialogInterface; | 7 | import android.content.DialogInterface; |
8 | import android.content.Intent; | 8 | import android.content.Intent; |
9 | import android.graphics.Color; | 9 | import android.graphics.Color; |
10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
11 | import android.os.IBinder; | 11 | import android.os.IBinder; |
12 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
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 | import android.view.Window; | 16 | import android.view.Window; |
17 | import android.view.WindowManager; | 17 | import android.view.WindowManager; |
18 | import android.view.inputmethod.InputMethodManager; | 18 | import android.view.inputmethod.InputMethodManager; |
19 | import android.widget.EditText; | 19 | import android.widget.EditText; |
20 | import android.widget.Toast; | 20 | import android.widget.Toast; |
21 | 21 | ||
22 | import androidx.annotation.IdRes; | 22 | import androidx.annotation.IdRes; |
23 | import androidx.annotation.Nullable; | 23 | import androidx.annotation.Nullable; |
24 | import androidx.appcompat.app.AppCompatActivity; | 24 | import androidx.appcompat.app.AppCompatActivity; |
25 | import androidx.fragment.app.Fragment; | 25 | import androidx.fragment.app.Fragment; |
26 | import androidx.fragment.app.FragmentTransaction; | 26 | import androidx.fragment.app.FragmentTransaction; |
27 | import androidx.lifecycle.Lifecycle; | 27 | import androidx.lifecycle.Lifecycle; |
28 | 28 | ||
29 | import com.developer.wang.utils.PermissionUtils; | 29 | import com.developer.wang.utils.PermissionUtils; |
30 | import com.prws.common.R; | 30 | import com.prws.common.R; |
31 | import com.prws.common.net.INetEvent; | 31 | import com.prws.common.net.INetEvent; |
32 | import com.prws.common.utils.LogUtil; | 32 | import com.prws.common.utils.LogUtil; |
33 | import com.prws.common.utils.ScreenUtils; | 33 | import com.prws.common.utils.ScreenUtils; |
34 | import com.prws.common.utils.SharedPreferencesUtil; | 34 | import com.prws.common.utils.SharedPreferencesUtil; |
35 | import com.prws.common.view.LoadingView; | 35 | import com.prws.common.view.LoadingView; |
36 | 36 | ||
37 | import org.simple.eventbus.EventBus; | 37 | import org.simple.eventbus.EventBus; |
38 | 38 | ||
39 | import java.util.ArrayList; | 39 | import java.util.ArrayList; |
40 | import java.util.List; | 40 | import java.util.List; |
41 | 41 | ||
42 | import butterknife.ButterKnife; | 42 | import butterknife.ButterKnife; |
43 | import io.reactivex.disposables.CompositeDisposable; | 43 | import io.reactivex.disposables.CompositeDisposable; |
44 | import io.reactivex.disposables.Disposable; | 44 | import io.reactivex.disposables.Disposable; |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * @author 描述:BaseActivity | 48 | * @author 描述:BaseActivity |
49 | */ | 49 | */ |
50 | public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends AppCompatActivity implements INetEvent, BaseView { | 50 | public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends AppCompatActivity implements INetEvent, BaseView { |
51 | 51 | ||
52 | 52 | ||
53 | private LoadingView loading; | 53 | private LoadingView loading; |
54 | 54 | ||
55 | public static INetEvent mINetEvent; | 55 | public static INetEvent mINetEvent; |
56 | protected final String TAG = getClass().getSimpleName(); | 56 | protected final String TAG = getClass().getSimpleName(); |
57 | private CompositeDisposable mCompositeDisposable; | 57 | private CompositeDisposable mCompositeDisposable; |
58 | protected P p; | 58 | protected P p; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * 获取布局文件 | 61 | * 获取布局文件 |
62 | * | 62 | * |
63 | * @return | 63 | * @return |
64 | */ | 64 | */ |
65 | protected abstract int layoutResId(); | 65 | protected abstract int layoutResId(); |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * 让P层做相应需求 | 68 | * 让P层做相应需求 |
69 | */ | 69 | */ |
70 | public abstract CONTRACT getContract(); | 70 | public abstract CONTRACT getContract(); |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * 子类获取具体契约 | 73 | * 子类获取具体契约 |
74 | */ | 74 | */ |
75 | public abstract P getPresenter(); | 75 | public abstract P getPresenter(); |
76 | 76 | ||
77 | @Override | 77 | @Override |
78 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 78 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
79 | super.onCreate(savedInstanceState); | 79 | super.onCreate(savedInstanceState); |
80 | setNetEvent(); | 80 | setNetEvent(); |
81 | initPresenter(); | 81 | initPresenter(); |
82 | showWhiteStatus(); | 82 | showWhiteStatus(); |
83 | setContentView(layoutResId()); | 83 | setContentView(layoutResId()); |
84 | ButterKnife.bind(this); | 84 | ButterKnife.bind(this); |
85 | registerEventBus(); | 85 | registerEventBus(); |
86 | initView(); | 86 | initView(); |
87 | initListener(); | 87 | initListener(); |
88 | initData(); | 88 | initData(); |
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | public void showWhiteStatus() { | 93 | public void showWhiteStatus() { |
94 | Window window = getWindow(); | 94 | Window window = getWindow(); |
95 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 95 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
96 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | 96 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
97 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 97 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
98 | window.setStatusBarColor(Color.TRANSPARENT); | 98 | window.setStatusBarColor(Color.TRANSPARENT); |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | @Override | 102 | @Override |
103 | protected void onResume() { | 103 | protected void onResume() { |
104 | super.onResume(); | 104 | super.onResume(); |
105 | } | 105 | } |
106 | 106 | ||
107 | protected abstract void initView(); | 107 | protected abstract void initView(); |
108 | 108 | ||
109 | protected abstract void initListener(); | 109 | protected abstract void initListener(); |
110 | 110 | ||
111 | protected abstract void initData(); | 111 | protected abstract void initData(); |
112 | 112 | ||
113 | 113 | ||
114 | private void setNetEvent() { | 114 | private void setNetEvent() { |
115 | mINetEvent = this; | 115 | mINetEvent = this; |
116 | } | 116 | } |
117 | 117 | ||
118 | private void initPresenter() { | 118 | private void initPresenter() { |
119 | p = getPresenter(); | 119 | p = getPresenter(); |
120 | if (p != null) | 120 | if (p != null) |
121 | p.bindView(this); | 121 | p.bindView(this); |
122 | } | 122 | } |
123 | 123 | ||
124 | |||
124 | public void showDialog(String title, String message, String confirm, String cancel, DialogInterface.OnClickListener cancelListener, DialogInterface.OnClickListener listener) { | 125 | public void showDialog(String title, String message, String confirm, String cancel, DialogInterface.OnClickListener cancelListener, DialogInterface.OnClickListener listener) { |
125 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | 126 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
126 | builder.setTitle(title); | 127 | builder.setTitle(title); |
127 | builder.setMessage(message); | 128 | builder.setMessage(message); |
128 | builder.setCancelable(false); | 129 | builder.setCancelable(false); |
129 | if (!TextUtils.isEmpty(cancel)) { | 130 | if (!TextUtils.isEmpty(cancel)) { |
130 | builder.setNegativeButton(cancel, cancelListener); | 131 | builder.setNegativeButton(cancel, cancelListener); |
131 | } | 132 | } |
132 | builder.setPositiveButton(confirm, listener); | 133 | builder.setPositiveButton(confirm, listener); |
133 | builder.show(); | 134 | builder.show(); |
134 | } | 135 | } |
135 | 136 | ||
136 | private void setWindow() { | 137 | private void setWindow() { |
137 | Window window = getWindow(); | 138 | Window window = getWindow(); |
138 | WindowManager.LayoutParams params = window.getAttributes(); | 139 | WindowManager.LayoutParams params = window.getAttributes(); |
139 | params.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN | 140 | params.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN |
140 | ; | 141 | ; |
141 | window.setAttributes(params); | 142 | window.setAttributes(params); |
142 | } | 143 | } |
143 | 144 | ||
144 | 145 | ||
145 | private void addNavigationBar() { | 146 | private void addNavigationBar() { |
146 | //判断是否有浮窗权限 | 147 | //判断是否有浮窗权限 |
147 | if (PermissionUtils.requestWindowManager(this)) { | 148 | if (PermissionUtils.requestWindowManager(this)) { |
148 | //开启浮窗 | 149 | //开启浮窗 |
149 | // openFloatWindow(); | 150 | // openFloatWindow(); |
150 | } else { | 151 | } else { |
151 | showAlertDialogOfFloatWindow(); | 152 | showAlertDialogOfFloatWindow(); |
152 | } | 153 | } |
153 | } | 154 | } |
154 | 155 | ||
155 | // public void openFloatWindow() { | 156 | // public void openFloatWindow() { |
156 | // if (FloatWindow.get("navigation") == null) { | 157 | // if (FloatWindow.get("navigation") == null) { |
157 | // NavigationBarView navigationBarView = new NavigationBarView(this); | 158 | // NavigationBarView navigationBarView = new NavigationBarView(this); |
158 | // FloatWindow.with(CommonApplication.getAppContext()) | 159 | // FloatWindow.with(CommonApplication.getAppContext()) |
159 | // .setView(navigationBarView) | 160 | // .setView(navigationBarView) |
160 | // .setWidth(Screen.width, 1) | 161 | // .setWidth(Screen.width, 1) |
161 | // .setHeight(WindowManager.LayoutParams.WRAP_CONTENT) | 162 | // .setHeight(WindowManager.LayoutParams.WRAP_CONTENT) |
162 | // .setX(0) | 163 | // .setX(0) |
163 | // .setY(0) | 164 | // .setY(0) |
164 | // .setMoveType(MoveType.inactive) | 165 | // .setMoveType(MoveType.inactive) |
165 | // .setDesktopShow(false) | 166 | // .setDesktopShow(false) |
166 | // .setTag("navigation") | 167 | // .setTag("navigation") |
167 | // .build(); | 168 | // .build(); |
168 | // } | 169 | // } |
169 | // if (!FloatWindow.get("navigation").isShowing()) | 170 | // if (!FloatWindow.get("navigation").isShowing()) |
170 | // FloatWindow.get("navigation").show(); | 171 | // FloatWindow.get("navigation").show(); |
171 | // | 172 | // |
172 | // } | 173 | // } |
173 | 174 | ||
174 | 175 | ||
175 | public void showAlertDialogOfFloatWindow() { | 176 | public void showAlertDialogOfFloatWindow() { |
176 | //弹窗提示用户开启权限 | 177 | //弹窗提示用户开启权限 |
177 | // new AlertDialog(this).builder().setTitle(getString(R.string.need_permission)) | 178 | // new AlertDialog(this).builder().setTitle(getString(R.string.need_permission)) |
178 | // .setMsg(getString(R.string.need_permission_window)) | 179 | // .setMsg(getString(R.string.need_permission_window)) |
179 | // .setPositiveButton(getString(R.string.open), new View.OnClickListener() { | 180 | // .setPositiveButton(getString(R.string.open), new View.OnClickListener() { |
180 | // @Override | 181 | // @Override |
181 | // public void onClick(View v) { | 182 | // public void onClick(View v) { |
182 | // Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | 183 | // Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); |
183 | // intent.setData(Uri.parse("package:" + getPackageName())); | 184 | // intent.setData(Uri.parse("package:" + getPackageName())); |
184 | // startActivity(intent); | 185 | // startActivity(intent); |
185 | // } | 186 | // } |
186 | // }).setNegativeButton(getString(R.string.cancel), new View.OnClickListener() { | 187 | // }).setNegativeButton(getString(R.string.cancel), new View.OnClickListener() { |
187 | // @Override | 188 | // @Override |
188 | // public void onClick(View v) { | 189 | // public void onClick(View v) { |
189 | // } | 190 | // } |
190 | // }).show(); | 191 | // }).show(); |
191 | LogUtil.toast("请开启浮窗权限"); | 192 | LogUtil.toast("请开启浮窗权限"); |
192 | } | 193 | } |
193 | 194 | ||
194 | 195 | ||
195 | public void showLoading(String title) { | 196 | public void showLoading(String title) { |
196 | synchronized (this) { | 197 | synchronized (this) { |
197 | if (loading != null || !isLiving(this)) return; | 198 | if (loading != null || !isLiving(this)) return; |
198 | runOnUiThread(() -> { | 199 | runOnUiThread(() -> { |
199 | loading = new LoadingView(this, R.style.CustomDialog, title); | 200 | loading = new LoadingView(this, R.style.CustomDialog, title); |
200 | loading.show(); | 201 | loading.show(); |
201 | ScreenUtils.hideBottomUIMenu(this); | 202 | ScreenUtils.hideBottomUIMenu(this); |
202 | ScreenUtils.hideDialogBottomUIMenu(loading); | 203 | ScreenUtils.hideDialogBottomUIMenu(loading); |
203 | }); | 204 | }); |
204 | } | 205 | } |
205 | } | 206 | } |
206 | 207 | ||
207 | 208 | ||
208 | public void setCanAble(boolean canAble) { | 209 | public void setCanAble(boolean canAble) { |
209 | if (loading != null) | 210 | if (loading != null) |
210 | loading.setCancelable(canAble); | 211 | loading.setCancelable(canAble); |
211 | 212 | ||
212 | } | 213 | } |
213 | 214 | ||
214 | public boolean isShowLoading() { | 215 | public boolean isShowLoading() { |
215 | if (loading == null) return false; | 216 | if (loading == null) return false; |
216 | return loading.isShowing(); | 217 | return loading.isShowing(); |
217 | } | 218 | } |
218 | 219 | ||
219 | public void dismissLoading() { | 220 | public void dismissLoading() { |
220 | runOnUiThread(() -> { | 221 | runOnUiThread(() -> { |
221 | if (loading == null || loading.isShowing() == false || !isLiving(this)) { | 222 | if (loading == null || loading.isShowing() == false || !isLiving(this)) { |
222 | Log.w(TAG, "loading == null" + | 223 | Log.w(TAG, "loading == null" + |
223 | " || loading.isShowing() == false >> return;"); | 224 | " || loading.isShowing() == false >> return;"); |
224 | return; | 225 | return; |
225 | } | 226 | } |
226 | loading.dismiss(); | 227 | loading.dismiss(); |
227 | loading = null; | 228 | loading = null; |
228 | 229 | ||
229 | }); | 230 | }); |
230 | } | 231 | } |
231 | 232 | ||
232 | 233 | ||
233 | private static boolean isLiving(Activity activity) { | 234 | private static boolean isLiving(Activity activity) { |
234 | 235 | ||
235 | if (activity == null) { | 236 | if (activity == null) { |
236 | Log.d("wisely", "activity == null"); | 237 | Log.d("wisely", "activity == null"); |
237 | return false; | 238 | return false; |
238 | } | 239 | } |
239 | 240 | ||
240 | if (activity.isFinishing()) { | 241 | if (activity.isFinishing()) { |
241 | Log.d("wisely", "activity is finishing"); | 242 | Log.d("wisely", "activity is finishing"); |
242 | return false; | 243 | return false; |
243 | } | 244 | } |
244 | 245 | ||
245 | return true; | 246 | return true; |
246 | } | 247 | } |
247 | 248 | ||
248 | 249 | ||
249 | /** | 250 | /** |
250 | * 是否需要弹窗提示更新 | 251 | * 是否需要弹窗提示更新 |
251 | */ | 252 | */ |
252 | protected void isNeedGetVersionUpdate() { | 253 | protected void isNeedGetVersionUpdate() { |
253 | // View view = findViewById(R.id.view_loading); | 254 | // View view = findViewById(R.id.view_loading); |
254 | //如果显示正在下载的页面,则不弹出更新弹窗 | 255 | //如果显示正在下载的页面,则不弹出更新弹窗 |
255 | // if (null == view || view.getVisibility() == View.VISIBLE) return; | 256 | // if (null == view || view.getVisibility() == View.VISIBLE) return; |
256 | // UpdateUtils.getVersion(this); | 257 | // UpdateUtils.getVersion(this); |
257 | } | 258 | } |
258 | 259 | ||
259 | 260 | ||
260 | /** | 261 | /** |
261 | * 全局检测网络广播的回调 处理网络变化 | 262 | * 全局检测网络广播的回调 处理网络变化 |
262 | * 注:在程序第一次启动的时候,没网并不会回调,需要自己在启动页面,或者主页自己再判断一次 | 263 | * 注:在程序第一次启动的时候,没网并不会回调,需要自己在启动页面,或者主页自己再判断一次 |
263 | * | 264 | * |
264 | * @param netWorkState 网络状态 -1:没网络 0:移动网络 1:WiFi网络 | 265 | * @param netWorkState 网络状态 -1:没网络 0:移动网络 1:WiFi网络 |
265 | */ | 266 | */ |
266 | public abstract void onNetChanged(int netWorkState); | 267 | public abstract void onNetChanged(int netWorkState); |
267 | 268 | ||
268 | @Override | 269 | @Override |
269 | public void onNetChange(int netWorkState) { | 270 | public void onNetChange(int netWorkState) { |
270 | onNetChanged(netWorkState); | 271 | onNetChanged(netWorkState); |
271 | } | 272 | } |
272 | 273 | ||
273 | @Override | 274 | @Override |
274 | protected void onDestroy() { | 275 | protected void onDestroy() { |
275 | super.onDestroy(); | 276 | super.onDestroy(); |
276 | unSubscribe(); | 277 | unSubscribe(); |
277 | cleanFragment(); | 278 | cleanFragment(); |
278 | unregisterEventBus(); | 279 | unregisterEventBus(); |
279 | if (p != null) { | 280 | if (p != null) { |
280 | p.onBindView(); | 281 | p.onBindView(); |
281 | p.cancelAllRequest(); | 282 | p.cancelAllRequest(); |
282 | } | 283 | } |
283 | } | 284 | } |
284 | 285 | ||
285 | @Override | 286 | @Override |
286 | protected void onPause() { | 287 | protected void onPause() { |
287 | super.onPause(); | 288 | super.onPause(); |
288 | 289 | ||
289 | } | 290 | } |
290 | 291 | ||
291 | private void registerEventBus() { | 292 | private void registerEventBus() { |
292 | EventBus.getDefault().register(this); | 293 | EventBus.getDefault().register(this); |
293 | } | 294 | } |
294 | 295 | ||
295 | private void unregisterEventBus() { | 296 | private void unregisterEventBus() { |
296 | EventBus.getDefault().unregister(this); | 297 | EventBus.getDefault().unregister(this); |
297 | } | 298 | } |
298 | 299 | ||
299 | public void showErrorToast() { | 300 | public void showErrorToast() { |
300 | // LogUtil.toast(MainApplication.getAppContext(), getString(R.string.service_error)); | 301 | // LogUtil.toast(MainApplication.getAppContext(), getString(R.string.service_error)); |
301 | } | 302 | } |
302 | 303 | ||
303 | public void showToast(String s) { | 304 | public void showToast(String s) { |
304 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); | 305 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); |
305 | } | 306 | } |
306 | 307 | ||
307 | private void unSubscribe() { | 308 | private void unSubscribe() { |
308 | if (mCompositeDisposable != null) { | 309 | if (mCompositeDisposable != null) { |
309 | mCompositeDisposable.clear(); | 310 | mCompositeDisposable.clear(); |
310 | } | 311 | } |
311 | } | 312 | } |
312 | 313 | ||
313 | protected void addSubscribe(Disposable disposable) { | 314 | protected void addSubscribe(Disposable disposable) { |
314 | if (mCompositeDisposable == null) { | 315 | if (mCompositeDisposable == null) { |
315 | mCompositeDisposable = new CompositeDisposable(); | 316 | mCompositeDisposable = new CompositeDisposable(); |
316 | } | 317 | } |
317 | mCompositeDisposable.add(disposable); | 318 | mCompositeDisposable.add(disposable); |
318 | } | 319 | } |
319 | 320 | ||
320 | protected void startActivity(Class clazz) { | 321 | protected void startActivity(Class clazz) { |
321 | startActivity(new Intent(this, clazz)); | 322 | startActivity(new Intent(this, clazz)); |
322 | } | 323 | } |
323 | 324 | ||
324 | /******************** 处理fragment *******************************/ | 325 | /******************** 处理fragment *******************************/ |
325 | List<Fragment> fragmentList = new ArrayList<>(); | 326 | List<Fragment> fragmentList = new ArrayList<>(); |
326 | 327 | ||
327 | protected void showFragment(Fragment fragment, @IdRes int id) { | 328 | protected void showFragment(Fragment fragment, @IdRes int id) { |
328 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | 329 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); |
329 | 330 | ||
330 | if (!fragmentList.contains(fragment)) { | 331 | if (!fragmentList.contains(fragment)) { |
331 | fragmentList.add(fragment); | 332 | fragmentList.add(fragment); |
332 | fragmentTransaction.add(id, fragment, fragment.getClass().getSimpleName()).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); | 333 | fragmentTransaction.add(id, fragment, fragment.getClass().getSimpleName()).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); |
333 | } | 334 | } |
334 | 335 | ||
335 | fragmentTransaction.show(fragment).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); | 336 | fragmentTransaction.show(fragment).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); |
336 | 337 | ||
337 | for (Fragment fragment1 : fragmentList) { | 338 | for (Fragment fragment1 : fragmentList) { |
338 | if (fragment1 != fragment) { | 339 | if (fragment1 != fragment) { |
339 | fragmentTransaction.hide(fragment1).setMaxLifecycle(fragment1, Lifecycle.State.STARTED); | 340 | fragmentTransaction.hide(fragment1).setMaxLifecycle(fragment1, Lifecycle.State.STARTED); |
340 | } | 341 | } |
341 | } | 342 | } |
342 | 343 | ||
343 | fragmentTransaction.commitAllowingStateLoss(); | 344 | fragmentTransaction.commitAllowingStateLoss(); |
344 | 345 | ||
345 | } | 346 | } |
346 | 347 | ||
347 | protected void cleanFragment() { | 348 | protected void cleanFragment() { |
348 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | 349 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); |
349 | if (fragmentList.size() > 0) { | 350 | if (fragmentList.size() > 0) { |
350 | for (Fragment fragment : fragmentList) { | 351 | for (Fragment fragment : fragmentList) { |
351 | fragmentTransaction.remove(fragment); | 352 | fragmentTransaction.remove(fragment); |
352 | } | 353 | } |
353 | try { | 354 | try { |
354 | fragmentTransaction.commitNowAllowingStateLoss(); | 355 | fragmentTransaction.commitNowAllowingStateLoss(); |
355 | } catch (Exception e) { | 356 | } catch (Exception e) { |
356 | e.printStackTrace(); | 357 | e.printStackTrace(); |
357 | } | 358 | } |
358 | } | 359 | } |
359 | fragmentList.clear(); | 360 | fragmentList.clear(); |
360 | } | 361 | } |
361 | 362 | ||
362 | //************************* 用于隐藏键盘 ***************************************// | 363 | //************************* 用于隐藏键盘 ***************************************// |
363 | @Override | 364 | @Override |
364 | public boolean dispatchTouchEvent(MotionEvent ev) { | 365 | public boolean dispatchTouchEvent(MotionEvent ev) { |
365 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { | 366 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
366 | 367 | ||
367 | View v = getCurrentFocus(); | 368 | View v = getCurrentFocus(); |
368 | if (isShouldHideInput(v, ev)) { | 369 | if (isShouldHideInput(v, ev)) { |
369 | hideSoftInput(v.getWindowToken()); | 370 | hideSoftInput(v.getWindowToken()); |
370 | } | 371 | } |
371 | } | 372 | } |
372 | return super.dispatchTouchEvent(ev); | 373 | return super.dispatchTouchEvent(ev); |
373 | } | 374 | } |
374 | 375 | ||
375 | private boolean isShouldHideInput(View v, MotionEvent event) { | 376 | private boolean isShouldHideInput(View v, MotionEvent event) { |
376 | if (v != null && (v instanceof EditText)) { | 377 | if (v != null && (v instanceof EditText)) { |
377 | int[] l = {0, 0}; | 378 | int[] l = {0, 0}; |
378 | v.getLocationInWindow(l); | 379 | v.getLocationInWindow(l); |
379 | int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left | 380 | int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left |
380 | + v.getWidth(); | 381 | + v.getWidth(); |
381 | if (event.getX() > left && event.getX() < right | 382 | if (event.getX() > left && event.getX() < right |
382 | && event.getY() > top && event.getY() < bottom) { | 383 | && event.getY() > top && event.getY() < bottom) { |
383 | // 点击EditText的事件,忽略它。 | 384 | // 点击EditText的事件,忽略它。 |
384 | return false; | 385 | return false; |
385 | } else { | 386 | } else { |
386 | return true; | 387 | return true; |
387 | } | 388 | } |
388 | } | 389 | } |
389 | 390 | ||
390 | return false; | 391 | return false; |
391 | } | 392 | } |
392 | 393 | ||
393 | /** | 394 | /** |
394 | * 多种隐藏软件盘方法的其中一种 | 395 | * 多种隐藏软件盘方法的其中一种 |
395 | * | 396 | * |
396 | * @param token | 397 | * @param token |
397 | */ | 398 | */ |
398 | private void hideSoftInput(IBinder token) { | 399 | private void hideSoftInput(IBinder token) { |
399 | LogUtil.i(TAG, "隐藏键盘"); | 400 | LogUtil.i(TAG, "隐藏键盘"); |
400 | if (token != null) { | 401 | if (token != null) { |
401 | InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | 402 | InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); |
402 | im.hideSoftInputFromWindow(token, | 403 | im.hideSoftInputFromWindow(token, |
403 | InputMethodManager.HIDE_NOT_ALWAYS); | 404 | InputMethodManager.HIDE_NOT_ALWAYS); |
404 | } | 405 | } |
405 | } | 406 | } |
406 | 407 | ||
407 | //************************* 用于隐藏键盘 end***************************************// | 408 | //************************* 用于隐藏键盘 end***************************************// |
408 | 409 | ||
409 | 410 | ||
410 | } | 411 | } |
411 | 412 |
libs/common/src/main/java/com/prws/common/bean/UpdateBean.java
File was created | 1 | package com.prws.common.bean; | |
2 | |||
3 | public class UpdateBean { | ||
4 | private String explain; | ||
5 | private Integer version; | ||
6 | private String url; | ||
7 | |||
8 | public void setExplain(String explain) { | ||
9 | this.explain = explain; | ||
10 | } | ||
11 | |||
12 | public void setVersion(Integer version) { | ||
13 | this.version = version; | ||
14 | } | ||
15 | |||
16 | public void setUrl(String url) { | ||
17 | this.url = url; | ||
18 | } | ||
19 | |||
20 | public String getExplain() { | ||
21 | return explain; | ||
22 | } | ||
23 | |||
24 | public Integer getVersion() { | ||
25 | return version; | ||
26 | } | ||
27 | |||
28 | public String getUrl() { | ||
29 | return url; | ||
30 | } | ||
31 | } | ||
32 |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
2 | 2 | ||
3 | 3 | ||
4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
7 | import com.prws.common.bean.BaseEntity; | 7 | import com.prws.common.bean.BaseEntity; |
8 | import com.prws.common.bean.CutPicBean; | 8 | import com.prws.common.bean.CutPicBean; |
9 | import com.prws.common.bean.GradeAndSubject; | 9 | import com.prws.common.bean.GradeAndSubject; |
10 | import com.prws.common.bean.PageInfo; | 10 | import com.prws.common.bean.PageInfo; |
11 | import com.prws.common.bean.ResponseResult; | 11 | import com.prws.common.bean.ResponseResult; |
12 | import com.prws.common.bean.ScheduleBean; | 12 | import com.prws.common.bean.ScheduleBean; |
13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
15 | import com.prws.common.bean.UpdateBean; | ||
15 | import com.prws.common.utils.SharedPreferencesUtil; | 16 | import com.prws.common.utils.SharedPreferencesUtil; |
16 | 17 | ||
17 | import java.io.File; | 18 | import java.io.File; |
18 | import java.util.HashMap; | 19 | import java.util.HashMap; |
19 | import java.util.List; | 20 | import java.util.List; |
20 | import java.util.Map; | 21 | import java.util.Map; |
21 | 22 | ||
22 | import io.reactivex.Observable; | 23 | import io.reactivex.Observable; |
23 | import io.reactivex.Observer; | 24 | import io.reactivex.Observer; |
24 | import io.reactivex.android.schedulers.AndroidSchedulers; | 25 | import io.reactivex.android.schedulers.AndroidSchedulers; |
25 | import io.reactivex.schedulers.Schedulers; | 26 | import io.reactivex.schedulers.Schedulers; |
26 | import okhttp3.MediaType; | 27 | import okhttp3.MediaType; |
27 | import okhttp3.MultipartBody; | 28 | import okhttp3.MultipartBody; |
28 | import okhttp3.RequestBody; | 29 | import okhttp3.RequestBody; |
29 | import okhttp3.ResponseBody; | 30 | import okhttp3.ResponseBody; |
30 | import retrofit2.Call; | 31 | import retrofit2.Call; |
31 | import retrofit2.Callback; | 32 | import retrofit2.Callback; |
32 | import retrofit2.http.Body; | 33 | import retrofit2.http.Body; |
33 | import retrofit2.http.DELETE; | 34 | import retrofit2.http.DELETE; |
34 | import retrofit2.http.FieldMap; | 35 | import retrofit2.http.FieldMap; |
35 | import retrofit2.http.FormUrlEncoded; | 36 | import retrofit2.http.FormUrlEncoded; |
36 | import retrofit2.http.GET; | 37 | import retrofit2.http.GET; |
37 | import retrofit2.http.Header; | 38 | import retrofit2.http.Header; |
38 | import retrofit2.http.HeaderMap; | 39 | import retrofit2.http.HeaderMap; |
39 | import retrofit2.http.Headers; | 40 | import retrofit2.http.Headers; |
40 | import retrofit2.http.Multipart; | 41 | import retrofit2.http.Multipart; |
41 | import retrofit2.http.POST; | 42 | import retrofit2.http.POST; |
42 | import retrofit2.http.PUT; | 43 | import retrofit2.http.PUT; |
43 | import retrofit2.http.Part; | 44 | import retrofit2.http.Part; |
44 | import retrofit2.http.PartMap; | 45 | import retrofit2.http.PartMap; |
45 | import retrofit2.http.Path; | 46 | import retrofit2.http.Path; |
46 | import retrofit2.http.Query; | 47 | import retrofit2.http.Query; |
47 | import retrofit2.http.QueryMap; | 48 | import retrofit2.http.QueryMap; |
48 | import retrofit2.http.Streaming; | 49 | import retrofit2.http.Streaming; |
49 | import retrofit2.http.Url; | 50 | import retrofit2.http.Url; |
50 | 51 | ||
51 | /** | 52 | /** |
52 | * 类名称:NetWorks | 53 | * 类名称:NetWorks |
53 | * 创建人: | 54 | * 创建人: |
54 | * <p> | 55 | * <p> |
55 | * 类描述:网络请求的操作类 | 56 | * 类描述:网络请求的操作类 |
56 | */ | 57 | */ |
57 | public class NetWorks extends RetrofitUtils { | 58 | public class NetWorks extends RetrofitUtils { |
58 | //服务器路径 | 59 | //服务器路径 |
59 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 60 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); |
60 | 61 | ||
61 | //设缓存有效期为1天 | 62 | //设缓存有效期为1天 |
62 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 63 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
63 | //查询缓存的Cache-Control设置,使用缓存 | 64 | //查询缓存的Cache-Control设置,使用缓存 |
64 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 65 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
65 | //查询网络的Cache-Control设置。不使用缓存 | 66 | //查询网络的Cache-Control设置。不使用缓存 |
66 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 67 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
67 | 68 | ||
68 | 69 | ||
69 | private interface NetService { | 70 | private interface NetService { |
70 | 71 | ||
71 | 72 | ||
72 | @GET("/api/v1/user/logout") | 73 | @GET("/api/v1/user/logout") |
73 | Observable<ResponseBody> logout(); | 74 | Observable<ResponseBody> logout(); |
74 | 75 | ||
75 | @Multipart | 76 | @Multipart |
76 | @POST("/api/v1/user/upLoadAvatar") | 77 | @POST("/api/v1/user/upLoadAvatar") |
77 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 78 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
78 | 79 | ||
79 | 80 | ||
80 | @Headers("Content-Type: application/json") | 81 | @Headers("Content-Type: application/json") |
81 | @POST("/api/v1/user/editUser") | 82 | @POST("/api/v1/user/editUser") |
82 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 83 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
83 | 84 | ||
84 | @Headers("Content-Type: application/json") | 85 | @Headers("Content-Type: application/json") |
85 | @POST("/api/v1/user/changePassword") | 86 | @POST("/api/v1/user/changePassword") |
86 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 87 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
87 | 88 | ||
88 | 89 | ||
89 | @GET("/api/v1/user/searchById") | 90 | @GET("/api/v1/user/searchById") |
90 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 91 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
91 | 92 | ||
92 | 93 | ||
93 | @Headers("Content-Type: application/json") | 94 | @Headers("Content-Type: application/json") |
94 | @POST("/api/v1/auth/login") | 95 | @POST("/api/v1/auth/login") |
95 | Observable<ResponseBody> login(@Body RequestBody body); | 96 | Observable<ResponseBody> login(@Body RequestBody body); |
96 | 97 | ||
97 | @GET("/api/v1/resource/listGradeAndSubject") | 98 | @GET("/api/v1/resource/listGradeAndSubject") |
98 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 99 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
99 | 100 | ||
100 | 101 | ||
101 | @GET("/api/v1/manager/generalQrCode") | 102 | @GET("/api/v1/manager/generalQrCode") |
102 | Observable<ResponseBody> generalQrCode(); | 103 | Observable<ResponseBody> generalQrCode(); |
103 | 104 | ||
104 | @GET("/api/v1/parent/scanAndLogin?") | 105 | @GET("/api/v1/parent/scanAndLogin?") |
105 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code); | 106 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code); |
106 | 107 | ||
107 | @GET("/api/v1/parent/getChildrenList") | 108 | @GET("/api/v1/parent/getChildrenList") |
108 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 109 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
109 | 110 | ||
110 | 111 | ||
111 | @Headers("Content-Type: application/json") | 112 | @Headers("Content-Type: application/json") |
112 | @POST("/api/v1/parent/registerParent") | 113 | @POST("/api/v1/parent/registerParent") |
113 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 114 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
114 | 115 | ||
115 | 116 | ||
116 | @GET("/api/v1/parent/listChildren") | 117 | @GET("/api/v1/parent/listChildren") |
117 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 118 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
118 | 119 | ||
119 | 120 | ||
120 | @Headers("Content-Type: application/json") | 121 | @Headers("Content-Type: application/json") |
121 | @POST("/api/v1/parent/registerStudent") | 122 | @POST("/api/v1/parent/registerStudent") |
122 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 123 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
123 | 124 | ||
124 | @Headers("Content-Type: application/json") | 125 | @Headers("Content-Type: application/json") |
125 | @POST("/api/v1/parent/bindTeacher") | 126 | @POST("/api/v1/parent/bindTeacher") |
126 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 127 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
127 | 128 | ||
128 | @Multipart | 129 | @Multipart |
129 | @POST("/api/v1/user/upLoadAvatar") | 130 | @POST("/api/v1/user/upLoadAvatar") |
130 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
131 | 132 | ||
132 | 133 | ||
133 | @Multipart | 134 | @Multipart |
134 | @POST("/api/v1/student/editStudentAvatar") | 135 | @POST("/api/v1/student/editStudentAvatar") |
135 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 136 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
136 | 137 | ||
137 | @Headers("Content-Type: application/json") | 138 | @Headers("Content-Type: application/json") |
138 | @POST("/api/v1/parent/editChild") | 139 | @POST("/api/v1/parent/editChild") |
139 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 140 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
140 | 141 | ||
141 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 142 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
142 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 143 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
143 | 144 | ||
144 | @GET("api/v1/parent/searchTeacher") | 145 | @GET("api/v1/parent/searchTeacher") |
145 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 146 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
146 | 147 | ||
147 | @POST("api/v1/question/listErrorBook") | 148 | @POST("api/v1/question/listErrorBook") |
148 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 149 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
149 | 150 | ||
150 | @POST | 151 | @POST |
151 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 152 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
152 | 153 | ||
153 | @POST | 154 | @POST |
154 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 155 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
155 | 156 | ||
156 | @POST | 157 | @POST |
157 | Observable<JsonObject> getBaiduToken(@Url String url); | 158 | Observable<JsonObject> getBaiduToken(@Url String url); |
158 | 159 | ||
159 | @Multipart | 160 | @Multipart |
160 | @POST("api/v1/pad/addErrorBook") | 161 | @POST("api/v1/pad/addErrorBook") |
161 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 162 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
162 | 163 | ||
163 | @POST("api/v1/pad/deleteStuErrorBook") | 164 | @POST("api/v1/pad/deleteStuErrorBook") |
164 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 165 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
165 | 166 | ||
166 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 167 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
167 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 168 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
168 | 169 | ||
169 | @POST("api/v1/question/editErrorBook") | 170 | @POST("api/v1/question/editErrorBook") |
170 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
172 | |||
173 | @GET("api/v1/resource/checkUpdate") | ||
174 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | ||
175 | |||
171 | } | 176 | } |
172 | 177 | ||
173 | 178 | ||
174 | public static String getHeader() { | 179 | public static String getHeader() { |
175 | return (String) SharedPreferencesUtil.getData("token", ""); | 180 | return (String) SharedPreferencesUtil.getData("token", ""); |
176 | } | 181 | } |
177 | 182 | ||
178 | public static String getBaiduToken() { | 183 | public static String getBaiduToken() { |
179 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 184 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
180 | } | 185 | } |
181 | 186 | ||
182 | 187 | ||
188 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | ||
189 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | ||
190 | } | ||
191 | |||
183 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 192 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
184 | File file = new File(path); | 193 | File file = new File(path); |
185 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 194 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
186 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 195 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
187 | Map<String, Object> map = new HashMap<>(); | 196 | Map<String, Object> map = new HashMap<>(); |
188 | map.put("condition", param); | 197 | map.put("condition", param); |
189 | setSubscribe(service_url.addError(part, map), observer); | 198 | setSubscribe(service_url.addError(part, map), observer); |
190 | } | 199 | } |
191 | 200 | ||
192 | 201 | ||
193 | public static void cut(String base64, Observer<CutPicBean> observer) { | 202 | public static void cut(String base64, Observer<CutPicBean> observer) { |
194 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 203 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
195 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 204 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
196 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 205 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
197 | } | 206 | } |
198 | 207 | ||
199 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 208 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
200 | setSubscribe(service_url.editError(getHeader(), map), observer); | 209 | setSubscribe(service_url.editError(getHeader(), map), observer); |
201 | } | 210 | } |
202 | 211 | ||
203 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 212 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
204 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 213 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
205 | } | 214 | } |
206 | 215 | ||
207 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 216 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
208 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 217 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
209 | } | 218 | } |
210 | 219 | ||
211 | public static void getBaiduToken(Observer<JsonObject> observer) { | 220 | public static void getBaiduToken(Observer<JsonObject> observer) { |
212 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); | 221 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); |
213 | } | 222 | } |
214 | 223 | ||
215 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 224 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
216 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 225 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
217 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 226 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
218 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 227 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
219 | } | 228 | } |
220 | 229 | ||
221 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 230 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
222 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 231 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
223 | } | 232 | } |
224 | 233 | ||
225 | public static void logout(Observer<ResponseBody> observer) { | 234 | public static void logout(Observer<ResponseBody> observer) { |
226 | setSubscribe(service_url.logout(), observer); | 235 | setSubscribe(service_url.logout(), observer); |
227 | } | 236 | } |
228 | 237 | ||
229 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 238 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
230 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 239 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
231 | } | 240 | } |
232 | 241 | ||
233 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 242 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
234 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 243 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
235 | } | 244 | } |
236 | 245 | ||
237 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 246 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
238 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 247 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
239 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 248 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
240 | Map<String, Object> map = new HashMap<>(); | 249 | Map<String, Object> map = new HashMap<>(); |
241 | map.put("stuId", stuId); | 250 | map.put("stuId", stuId); |
242 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 251 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
243 | } | 252 | } |
244 | 253 | ||
245 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 254 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
246 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 255 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
247 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 256 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
248 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 257 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
249 | } | 258 | } |
250 | 259 | ||
251 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 260 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
252 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 261 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
253 | } | 262 | } |
254 | 263 | ||
255 | 264 | ||
256 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 265 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
257 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 266 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
258 | } | 267 | } |
259 | 268 | ||
260 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 269 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
261 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 270 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
262 | } | 271 | } |
263 | 272 | ||
264 | 273 | ||
265 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 274 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
266 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 275 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
267 | } | 276 | } |
268 | 277 | ||
269 | 278 | ||
270 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 279 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
271 | setSubscribe(service_url.login(body), observer); | 280 | setSubscribe(service_url.login(body), observer); |
272 | } | 281 | } |
273 | 282 | ||
274 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 283 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
275 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 284 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
276 | } | 285 | } |
277 | 286 | ||
278 | 287 | ||
279 | public static void scanAndLogin(String code, Observer<ResponseBody> observer) { | 288 | public static void scanAndLogin(String code, Observer<ResponseBody> observer) { |
280 | setSubscribe(service_url.scanAndLogin(getHeader(), code), observer); | 289 | setSubscribe(service_url.scanAndLogin(getHeader(), code), observer); |
281 | } | 290 | } |
282 | 291 | ||
283 | public static void getChildrenList(Observer<ResponseBody> observer) { | 292 | public static void getChildrenList(Observer<ResponseBody> observer) { |
284 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 293 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
285 | } | 294 | } |
286 | 295 | ||
287 | 296 | ||
288 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 297 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
289 | setSubscribe(service_url.registerParent(body), observer); | 298 | setSubscribe(service_url.registerParent(body), observer); |
290 | } | 299 | } |
291 | 300 | ||
292 | 301 | ||
293 | public static void listChildren(Observer<ResponseBody> observer) { | 302 | public static void listChildren(Observer<ResponseBody> observer) { |
294 | setSubscribe(service_url.listChildren(getHeader()), observer); | 303 | setSubscribe(service_url.listChildren(getHeader()), observer); |
295 | } | 304 | } |
296 | 305 | ||
297 | 306 | ||
298 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 307 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
299 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 308 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
300 | } | 309 | } |
301 | 310 | ||
302 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 311 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
303 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 312 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
304 | } | 313 | } |
305 | 314 | ||
306 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 315 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
307 | setSubscribe(service_url.getError(getHeader(), map), observer); | 316 | setSubscribe(service_url.getError(getHeader(), map), observer); |
308 | } | 317 | } |
309 | 318 | ||
310 | 319 | ||
311 | public static RequestBody getMapRequestBody(Map map) { | 320 | public static RequestBody getMapRequestBody(Map map) { |
312 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 321 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
313 | } | 322 | } |
314 | 323 | ||
315 | 324 | ||
316 | public static RequestBody getArrayRequestBody(List list) { | 325 | public static RequestBody getArrayRequestBody(List list) { |
317 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 326 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
318 | } | 327 | } |
319 | 328 | ||
320 | public static RequestBody getFileRequestBody(File file) { | 329 | public static RequestBody getFileRequestBody(File file) { |
321 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 330 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
322 | } | 331 | } |
323 | 332 | ||
324 | public static RequestBody getFileRequestBody(byte[] bytes) { | 333 | public static RequestBody getFileRequestBody(byte[] bytes) { |
325 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 334 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
326 | } | 335 | } |
327 | 336 | ||
328 | public static RequestBody getObjectRequestBody(Object obj) { | 337 | public static RequestBody getObjectRequestBody(Object obj) { |
329 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 338 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
330 | } | 339 | } |
331 | 340 | ||
332 | public static RequestBody getStringRequestBody(String str) { | 341 | public static RequestBody getStringRequestBody(String str) { |
333 | return RequestBody.create(MediaType.parse("text/plain"), str); | 342 | return RequestBody.create(MediaType.parse("text/plain"), str); |
334 | } | 343 | } |
335 | 344 | ||
336 | 345 | ||
337 | /** | 346 | /** |
338 | * 插入观察者 | 347 | * 插入观察者 |
339 | * | 348 | * |
340 | * @param observable | 349 | * @param observable |
341 | * @param observer | 350 | * @param observer |
342 | * @param <T> | 351 | * @param <T> |
343 | */ | 352 | */ |
344 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 353 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
345 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 354 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
346 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 355 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
347 | .subscribe(observer); | 356 | .subscribe(observer); |
348 | } | 357 | } |
349 | 358 | ||
350 | } | 359 | } |
351 | 360 |
libs/common/src/main/java/com/prws/common/utils/DownloadUtil.java
File was created | 1 | package com.prws.common.utils; | |
2 | |||
3 | import java.io.File; | ||
4 | import java.io.FileOutputStream; | ||
5 | import java.io.IOException; | ||
6 | import java.io.InputStream; | ||
7 | |||
8 | import okhttp3.Call; | ||
9 | import okhttp3.Callback; | ||
10 | import okhttp3.OkHttpClient; | ||
11 | import okhttp3.Request; | ||
12 | import okhttp3.Response; | ||
13 | |||
14 | public class DownloadUtil { | ||
15 | |||
16 | public static void download(final String url, final String saveFile, final OnDownloadListener listener) { | ||
17 | Request request = new Request.Builder().url(url).build(); | ||
18 | new OkHttpClient().newCall(request).enqueue(new Callback() { | ||
19 | @Override | ||
20 | public void onFailure(Call call, IOException e) { | ||
21 | listener.onDownloadFailed(e.getMessage()); | ||
22 | } | ||
23 | |||
24 | @Override | ||
25 | public void onResponse(Call call, Response response) throws IOException { | ||
26 | InputStream is = null; | ||
27 | byte[] buf = new byte[2048]; | ||
28 | int len; | ||
29 | FileOutputStream fos = null; | ||
30 | try { | ||
31 | is = response.body().byteStream(); | ||
32 | long total = response.body().contentLength(); | ||
33 | File file = new File(saveFile); | ||
34 | fos = new FileOutputStream(file); | ||
35 | long sum = 0; | ||
36 | while ((len = is.read(buf)) != -1) { | ||
37 | fos.write(buf, 0, len); | ||
38 | sum += len; | ||
39 | int progress = (int) (sum * 1.0f / total * 100); | ||
40 | listener.onDownloading(progress); | ||
41 | } | ||
42 | fos.flush(); | ||
43 | listener.onDownloadSuccess(file.getAbsolutePath()); | ||
44 | } catch (Exception e) { | ||
45 | listener.onDownloadFailed(e.getMessage()); | ||
46 | } finally { | ||
47 | try { | ||
48 | if (is != null) | ||
49 | is.close(); | ||
50 | } catch (IOException e) { | ||
51 | e.printStackTrace(); | ||
52 | } | ||
53 | try { | ||
54 | if (fos != null) | ||
55 | fos.close(); | ||
56 | } catch (IOException e) { | ||
57 | e.printStackTrace(); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | }); | ||
62 | } | ||
63 | |||
64 | public interface OnDownloadListener { | ||
65 | void onDownloadSuccess(String path); | ||
66 | |||
67 | void onDownloading(int progress); | ||
68 | |||
69 | void onDownloadFailed(String msg); | ||
70 | } | ||
71 | } | ||
72 |
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 | } | 161 | } |
162 | if (!isEnabled()) { | 162 | if (!isEnabled()) { |
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | //draw vertex | 165 | //draw vertex |
166 | if (isValid && isUp) { | 166 | if (isValid && isUp) { |
167 | canvas.drawOval(ltVer, vertexPaint); | 167 | canvas.drawOval(ltVer, vertexPaint); |
168 | canvas.drawOval(rtVer, vertexPaint); | 168 | canvas.drawOval(rtVer, vertexPaint); |
169 | canvas.drawOval(lbVer, vertexPaint); | 169 | canvas.drawOval(lbVer, vertexPaint); |
170 | canvas.drawOval(rbVer, vertexPaint); | 170 | canvas.drawOval(rbVer, vertexPaint); |
171 | } | 171 | } |
172 | 172 | ||
173 | //draw button | 173 | //draw button |
174 | if (isValid && isUp) { | 174 | if (isValid && isUp) { |
175 | if (markedArea.width() >= CommonUtil.dpToPx(context, 40) && markedArea.height() >= CommonUtil.dpToPx(context, 40)) { | 175 | if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { |
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 | } | 178 | } |
179 | } | 179 | } |
180 | super.onDraw(canvas); | 180 | super.onDraw(canvas); |
181 | } | 181 | } |
182 | 182 | ||
183 | @Override | 183 | @Override |
184 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | 184 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
185 | super.onLayout(changed, left, top, right, bottom); | 185 | super.onLayout(changed, left, top, right, bottom); |
186 | int measuredWidth = getMeasuredWidth(); | 186 | int measuredWidth = getMeasuredWidth(); |
187 | int measuredHeight = getMeasuredHeight(); | 187 | int measuredHeight = getMeasuredHeight(); |
188 | region = new Rect(0, 0, measuredWidth, measuredHeight); | 188 | region = new Rect(0, 0, measuredWidth, measuredHeight); |
189 | Log.e("onLayout", "measuredWidth=" + measuredWidth + ";measuredHeight=" + measuredHeight); | 189 | Log.e("onLayout", "measuredWidth=" + measuredWidth + ";measuredHeight=" + measuredHeight); |
190 | } | 190 | } |
191 | 191 | ||
192 | @Override | 192 | @Override |
193 | public boolean onTouchEvent(MotionEvent event) { | 193 | public boolean onTouchEvent(MotionEvent event) { |
194 | if (!isEnabled()) { | 194 | if (!isEnabled()) { |
195 | return false; | 195 | return false; |
196 | } | 196 | } |
197 | int x = (int) event.getX(); | 197 | int x = (int) event.getX(); |
198 | int y = (int) event.getY(); | 198 | int y = (int) event.getY(); |
199 | switch (event.getAction()) { | 199 | switch (event.getAction()) { |
200 | case MotionEvent.ACTION_DOWN: | 200 | case MotionEvent.ACTION_DOWN: |
201 | isUp = false; | 201 | isUp = false; |
202 | isAdjustMode = false; | 202 | isAdjustMode = false; |
203 | isMoveMode = false; | 203 | isMoveMode = false; |
204 | isButtonClicked = false; | 204 | isButtonClicked = false; |
205 | isValid = false; | 205 | isValid = false; |
206 | adjustNum = 0; | 206 | adjustNum = 0; |
207 | downX = x; | 207 | downX = x; |
208 | downY = y; | 208 | downY = y; |
209 | if (mOnClickListener != null) { | 209 | if (mOnClickListener != null) { |
210 | mOnClickListener.onTouch(); | 210 | mOnClickListener.onTouch(); |
211 | } | 211 | } |
212 | if (isAreaContainPoint(confirmArea, x, y)) { | 212 | if (isAreaContainPoint(confirmArea, x, y)) { |
213 | isButtonClicked = true; | 213 | isButtonClicked = true; |
214 | isValid = true; | 214 | isValid = true; |
215 | invalidate(); | 215 | invalidate(); |
216 | if (mOnClickListener != null) { | 216 | if (mOnClickListener != null) { |
217 | mOnClickListener.onConfirm(markedArea); | 217 | mOnClickListener.onConfirm(markedArea); |
218 | } | 218 | } |
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 | } else if (isAreaContainPoint(ltVer, x, y)) { | 228 | } else if (isAreaContainPoint(ltVer, x, y)) { |
229 | isAdjustMode = true; | 229 | isAdjustMode = true; |
230 | adjustNum = 1; | 230 | adjustNum = 1; |
231 | } else if (isAreaContainPoint(rtVer, x, y)) { | 231 | } else if (isAreaContainPoint(rtVer, x, y)) { |
232 | isAdjustMode = true; | 232 | isAdjustMode = true; |
233 | adjustNum = 2; | 233 | adjustNum = 2; |
234 | } else if (isAreaContainPoint(lbVer, x, y)) { | 234 | } else if (isAreaContainPoint(lbVer, x, y)) { |
235 | isAdjustMode = true; | 235 | isAdjustMode = true; |
236 | adjustNum = 3; | 236 | adjustNum = 3; |
237 | } else if (isAreaContainPoint(rbVer, x, y)) { | 237 | } else if (isAreaContainPoint(rbVer, x, y)) { |
238 | isAdjustMode = true; | 238 | isAdjustMode = true; |
239 | adjustNum = 4; | 239 | adjustNum = 4; |
240 | } else if (markedArea.contains(x, y)) { | 240 | } else if (markedArea.contains(x, y)) { |
241 | isMoveMode = true; | 241 | isMoveMode = true; |
242 | } else { | 242 | } else { |
243 | isMoveMode = false; | 243 | isMoveMode = false; |
244 | startX = (int) event.getX(); | 244 | startX = (int) event.getX(); |
245 | startY = (int) event.getY(); | 245 | startY = (int) event.getY(); |
246 | endX = startX; | 246 | endX = startX; |
247 | endY = startY; | 247 | endY = startY; |
248 | } | 248 | } |
249 | break; | 249 | break; |
250 | case MotionEvent.ACTION_MOVE: | 250 | case MotionEvent.ACTION_MOVE: |
251 | if (isButtonClicked) { | 251 | if (isButtonClicked) { |
252 | break; | 252 | break; |
253 | } | 253 | } |
254 | adjustMark(x, y); | 254 | adjustMark(x, y); |
255 | break; | 255 | break; |
256 | case MotionEvent.ACTION_UP: | 256 | case MotionEvent.ACTION_UP: |
257 | isUp = true; | 257 | isUp = true; |
258 | if (markedArea.width() >= CommonUtil.dpToPx(context, 40) && markedArea.height() >= CommonUtil.dpToPx(context, 40)) { | 258 | if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { |
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 | } | 314 | } |
315 | } | 315 | } |
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); |
449 | } | 449 | } |
450 | 450 | ||
451 | } | 451 | } |
452 | 452 |