Commit d37e980ebbef954a2d5193d97cb8c9c7321ac22b
1 parent
16a469f2c7
Exists in
master
BUG修改
Showing
9 changed files
with
142 additions
and
32 deletions
Show diff stats
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 | 24 | ||
25 | <application | 25 | <application |
26 | android:name=".MyApplication" | 26 | android:name=".MyApplication" |
27 | android:allowBackup="true" | 27 | android:allowBackup="true" |
28 | android:icon="@mipmap/icon" | 28 | android:icon="@mipmap/icon" |
29 | android:label="@string/app_name" | 29 | android:label="@string/app_name" |
30 | android:networkSecurityConfig="@xml/network_security_config" | 30 | android:networkSecurityConfig="@xml/network_security_config" |
31 | android:supportsRtl="true" | 31 | android:supportsRtl="true" |
32 | android:theme="@style/Theme.Parent"> | 32 | android:theme="@style/Theme.Parent"> |
33 | <activity | 33 | <activity |
34 | android:name=".LoginActivity" | 34 | android:name=".LoginActivity" |
35 | android:exported="true" | 35 | android:exported="true" |
36 | android:theme="@style/ThemeSplash"> | 36 | android:theme="@style/ThemeSplash"> |
37 | <intent-filter> | 37 | <intent-filter> |
38 | <action android:name="android.intent.action.MAIN" /> | 38 | <action android:name="android.intent.action.MAIN" /> |
39 | <category android:name="android.intent.category.LAUNCHER" /> | 39 | <category android:name="android.intent.category.LAUNCHER" /> |
40 | </intent-filter> | 40 | </intent-filter> |
41 | </activity> | 41 | </activity> |
42 | <activity | 42 | <activity |
43 | android:name=".MainActivity" | 43 | android:name=".MainActivity" |
44 | android:launchMode="singleTask" | 44 | android:launchMode="singleTask" |
45 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 45 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
46 | <activity | 46 | <activity |
47 | android:name=".RegisterActivity" | 47 | android:name=".RegisterActivity" |
48 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 48 | android:theme="@style/ThemeSplash" /> |
49 | <activity | 49 | <activity |
50 | android:name=".UserActivity" | 50 | android:name=".UserActivity" |
51 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 51 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
52 | <activity | 52 | <activity |
53 | android:name=".YinsiActivity" | 53 | android:name=".YinsiActivity" |
54 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 54 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
55 | <activity | 55 | <activity |
56 | android:name=".QRActivity" | 56 | android:name=".QRActivity" |
57 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 57 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
58 | <activity | 58 | <activity |
59 | android:name=".AddStudentActivity" | 59 | android:name=".AddStudentActivity" |
60 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 60 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
61 | <activity | 61 | <activity |
62 | android:name=".NickActivity" | 62 | android:name=".NickActivity" |
63 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 63 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
64 | <activity | 64 | <activity |
65 | android:name=".SexActivity" | 65 | android:name=".SexActivity" |
66 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 66 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
67 | <activity | 67 | <activity |
68 | android:name=".NianActivity" | 68 | android:name=".NianActivity" |
69 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 69 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
70 | <activity | 70 | <activity |
71 | android:name=".ShenActivity" | 71 | android:name=".ShenActivity" |
72 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 72 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
73 | <activity | 73 | <activity |
74 | android:name=".AccountActivity" | 74 | android:name=".AccountActivity" |
75 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 75 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
76 | 76 | ||
77 | <activity | 77 | <activity |
78 | android:name=".ChangePwdActivity" | 78 | android:name=".ChangePwdActivity" |
79 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 79 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
80 | <activity | 80 | <activity |
81 | android:name=".EditStudentActivity" | 81 | android:name=".EditStudentActivity" |
82 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 82 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
83 | <activity | 83 | <activity |
84 | android:name=".ChooseActivity" | 84 | android:name=".ChooseActivity" |
85 | android:theme="@style/Theme.AppCompat.NoActionBar" /> | 85 | android:theme="@style/Theme.AppCompat.NoActionBar" /> |
86 | 86 | ||
87 | <provider | 87 | <provider |
88 | android:name="androidx.core.content.FileProvider" | 88 | android:name="androidx.core.content.FileProvider" |
89 | android:authorities="com.hjx.parent.fileprovider" | 89 | android:authorities="com.hjx.parent.fileprovider" |
90 | android:exported="false" | 90 | android:exported="false" |
91 | android:grantUriPermissions="true"> | 91 | android:grantUriPermissions="true"> |
92 | <meta-data | 92 | <meta-data |
93 | android:name="android.support.FILE_PROVIDER_PATHS" | 93 | android:name="android.support.FILE_PROVIDER_PATHS" |
94 | android:resource="@xml/file_provider_paths" | 94 | android:resource="@xml/file_provider_paths" |
95 | tools:replace="android:resource" /> | 95 | tools:replace="android:resource" /> |
96 | </provider> | 96 | </provider> |
97 | </application> | 97 | </application> |
98 | 98 | ||
99 | </manifest> | 99 | </manifest> |
app/src/main/java/com/hjx/parent/AccountActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.app.AlertDialog; | 3 | import android.app.AlertDialog; |
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.net.NetworkRequest; | 7 | import android.net.NetworkRequest; |
8 | import android.net.Uri; | 8 | import android.net.Uri; |
9 | import android.os.Build; | 9 | import android.os.Build; |
10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
11 | import android.os.Environment; | 11 | import android.os.Environment; |
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.LayoutInflater; | 15 | import android.view.LayoutInflater; |
16 | import android.view.View; | 16 | import android.view.View; |
17 | import android.widget.ImageView; | 17 | import android.widget.ImageView; |
18 | import android.widget.TextView; | 18 | import android.widget.TextView; |
19 | import android.widget.Toast; | 19 | import android.widget.Toast; |
20 | 20 | ||
21 | import androidx.core.content.FileProvider; | 21 | import androidx.core.content.FileProvider; |
22 | 22 | ||
23 | import com.bumptech.glide.Glide; | 23 | import com.bumptech.glide.Glide; |
24 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 24 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
25 | import com.bumptech.glide.request.RequestOptions; | 25 | import com.bumptech.glide.request.RequestOptions; |
26 | import com.google.android.material.bottomsheet.BottomSheetDialog; | 26 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
27 | import com.hjq.permissions.OnPermissionCallback; | ||
28 | import com.hjq.permissions.Permission; | ||
29 | import com.hjq.permissions.XXPermissions; | ||
27 | import com.prws.common.base.BaseActivity; | 30 | import com.prws.common.base.BaseActivity; |
28 | import com.prws.common.base.BasePresenter; | 31 | import com.prws.common.base.BasePresenter; |
29 | import com.prws.common.bean.ResponseResult; | 32 | import com.prws.common.bean.ResponseResult; |
30 | import com.prws.common.net.NetWorks; | 33 | import com.prws.common.net.NetWorks; |
31 | import com.prws.common.utils.LogUtil; | 34 | import com.prws.common.utils.LogUtil; |
32 | import com.prws.common.utils.ScreenUtils; | 35 | import com.prws.common.utils.ScreenUtils; |
33 | import com.prws.common.utils.SharedPreferencesUtil; | 36 | import com.prws.common.utils.SharedPreferencesUtil; |
34 | 37 | ||
35 | import org.json.JSONObject; | 38 | import org.json.JSONObject; |
36 | 39 | ||
37 | import java.io.File; | 40 | import java.io.File; |
38 | import java.io.FileOutputStream; | 41 | import java.io.FileOutputStream; |
39 | import java.io.IOException; | 42 | import java.io.IOException; |
40 | import java.util.HashMap; | 43 | import java.util.HashMap; |
44 | import java.util.List; | ||
41 | import java.util.Map; | 45 | import java.util.Map; |
42 | 46 | ||
43 | import butterknife.BindView; | 47 | import butterknife.BindView; |
44 | import butterknife.OnClick; | 48 | import butterknife.OnClick; |
45 | import io.reactivex.Observer; | 49 | import io.reactivex.Observer; |
46 | import io.reactivex.disposables.Disposable; | 50 | import io.reactivex.disposables.Disposable; |
47 | import okhttp3.ResponseBody; | 51 | import okhttp3.ResponseBody; |
48 | 52 | ||
49 | public class AccountActivity extends BaseActivity { | 53 | public class AccountActivity extends BaseActivity { |
50 | 54 | ||
51 | 55 | ||
52 | @Override | 56 | @Override |
53 | protected int layoutResId() { | 57 | protected int layoutResId() { |
54 | return R.layout.activity_setac; | 58 | return R.layout.activity_setac; |
55 | } | 59 | } |
56 | 60 | ||
57 | @Override | 61 | @Override |
58 | public Object getContract() { | 62 | public Object getContract() { |
59 | return null; | 63 | return null; |
60 | } | 64 | } |
61 | 65 | ||
62 | @Override | 66 | @Override |
63 | public BasePresenter getPresenter() { | 67 | public BasePresenter getPresenter() { |
64 | return null; | 68 | return null; |
65 | } | 69 | } |
66 | 70 | ||
67 | private static int CAMERA_REQUEST_CODE = 343; | 71 | private static int CAMERA_REQUEST_CODE = 343; |
68 | private static int ALBUM_REQUEST_CODE = 456; | 72 | private static int ALBUM_REQUEST_CODE = 456; |
69 | private static int CROP_REQUEST_CODE = 234; | 73 | private static int CROP_REQUEST_CODE = 234; |
70 | private File tempFile; | 74 | private File tempFile; |
71 | private String path; | 75 | private String path; |
72 | TextView tv_6; | 76 | TextView tv_6; |
73 | @BindView(R.id.iv_3) | 77 | @BindView(R.id.iv_3) |
74 | ImageView iv_3; | 78 | ImageView iv_3; |
75 | 79 | ||
76 | @Override | 80 | @Override |
77 | protected void initView() { | 81 | protected void initView() { |
78 | tv_6 = findViewById(R.id.tv_6); | 82 | tv_6 = findViewById(R.id.tv_6); |
79 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); | 83 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); |
80 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 84 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); |
81 | if(!TextUtils.isEmpty(photo)){ | 85 | if (!TextUtils.isEmpty(photo)) { |
82 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); | 86 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); |
83 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 87 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
84 | Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3); | 88 | Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3); |
85 | } | 89 | } |
86 | if (phone != null && phone.length() > 0) | 90 | if (phone != null && phone.length() > 0) |
87 | tv_6.setText(phone); | 91 | tv_6.setText(phone); |
88 | } | 92 | } |
89 | 93 | ||
90 | @Override | 94 | @Override |
91 | protected void initListener() { | 95 | protected void initListener() { |
92 | findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed()); | 96 | findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed()); |
93 | findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class)); | 97 | findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class)); |
94 | } | 98 | } |
95 | 99 | ||
96 | @Override | 100 | @Override |
97 | protected void initData() { | 101 | protected void initData() { |
98 | 102 | ||
99 | } | 103 | } |
100 | 104 | ||
101 | @Override | 105 | @Override |
102 | public void onNetChanged(int netWorkState) { | 106 | public void onNetChanged(int netWorkState) { |
103 | 107 | ||
104 | } | 108 | } |
105 | 109 | ||
106 | private void uploadAvatar(File file) { | 110 | private void uploadAvatar(File file) { |
107 | 111 | ||
108 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { | 112 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { |
109 | @Override | 113 | @Override |
110 | public void onSubscribe(Disposable d) { | 114 | public void onSubscribe(Disposable d) { |
111 | 115 | ||
112 | } | 116 | } |
113 | 117 | ||
114 | @Override | 118 | @Override |
115 | public void onNext(ResponseResult<Map<String, String>> responseBody) { | 119 | public void onNext(ResponseResult<Map<String, String>> responseBody) { |
116 | if (responseBody.getData() != null && responseBody.getCode() == 200) { | 120 | if (responseBody.getData() != null && responseBody.getCode() == 200) { |
117 | path = responseBody.getData().get("imageUrl"); | 121 | path = responseBody.getData().get("imageUrl"); |
118 | editUser(path); | 122 | editUser(path); |
119 | } | 123 | } |
120 | } | 124 | } |
121 | 125 | ||
122 | @Override | 126 | @Override |
123 | public void onError(Throwable e) { | 127 | public void onError(Throwable e) { |
124 | e.toString(); | 128 | e.toString(); |
125 | } | 129 | } |
126 | 130 | ||
127 | @Override | 131 | @Override |
128 | public void onComplete() { | 132 | public void onComplete() { |
129 | 133 | ||
130 | } | 134 | } |
131 | }); | 135 | }); |
132 | } | 136 | } |
133 | 137 | ||
134 | public void editUser(String path) { | 138 | public void editUser(String path) { |
135 | Map map = new HashMap(); | 139 | Map map = new HashMap(); |
136 | map.put("userId", SharedPreferencesUtil.getData("userId", "")); | 140 | map.put("userId", SharedPreferencesUtil.getData("userId", "")); |
137 | map.put("photo", path); | 141 | map.put("photo", path); |
138 | 142 | ||
139 | NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 143 | NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
140 | @Override | 144 | @Override |
141 | public void onSubscribe(Disposable d) { | 145 | public void onSubscribe(Disposable d) { |
142 | 146 | ||
143 | } | 147 | } |
144 | 148 | ||
145 | @Override | 149 | @Override |
146 | public void onNext(ResponseBody responseBody) { | 150 | public void onNext(ResponseBody responseBody) { |
147 | try { | 151 | try { |
148 | String str = responseBody.string().toString(); | 152 | String str = responseBody.string().toString(); |
149 | LogUtil.e(TAG, "----" + str); | 153 | LogUtil.e(TAG, "----" + str); |
150 | JSONObject jo = new JSONObject(str); | 154 | JSONObject jo = new JSONObject(str); |
151 | boolean isSucceed = jo.getBoolean("success"); | 155 | boolean isSucceed = jo.getBoolean("success"); |
152 | if (isSucceed) { | 156 | if (isSucceed) { |
153 | SharedPreferencesUtil.putData("photo", path); | 157 | SharedPreferencesUtil.putData("photo", path); |
154 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); | 158 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); |
155 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 159 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
156 | Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3); | 160 | Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3); |
157 | Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show(); | 161 | Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show(); |
158 | } else { | 162 | } else { |
159 | Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 163 | Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
160 | } | 164 | } |
161 | } catch (Exception e) { | 165 | } catch (Exception e) { |
162 | e.printStackTrace(); | 166 | e.printStackTrace(); |
163 | Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 167 | Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
164 | } | 168 | } |
165 | } | 169 | } |
166 | 170 | ||
167 | @Override | 171 | @Override |
168 | public void onError(Throwable e) { | 172 | public void onError(Throwable e) { |
169 | 173 | ||
170 | } | 174 | } |
171 | 175 | ||
172 | @Override | 176 | @Override |
173 | public void onComplete() { | 177 | public void onComplete() { |
174 | 178 | ||
175 | } | 179 | } |
176 | }); | 180 | }); |
177 | } | 181 | } |
178 | 182 | ||
179 | public File saveImage(String name, Bitmap bmp) { | 183 | public File saveImage(String name, Bitmap bmp) { |
180 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); | 184 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); |
181 | if (!appDir.exists()) { | 185 | if (!appDir.exists()) { |
182 | appDir.mkdir(); | 186 | appDir.mkdir(); |
183 | } | 187 | } |
184 | String fileName = name + ".jpg"; | 188 | String fileName = name + ".jpg"; |
185 | File file = new File(appDir, fileName); | 189 | File file = new File(appDir, fileName); |
186 | try { | 190 | try { |
187 | FileOutputStream fos = new FileOutputStream(file); | 191 | FileOutputStream fos = new FileOutputStream(file); |
188 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); | 192 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); |
189 | fos.flush(); | 193 | fos.flush(); |
190 | fos.close(); | 194 | fos.close(); |
191 | return file; | 195 | return file; |
192 | } catch (IOException e) { | 196 | } catch (IOException e) { |
193 | Log.d("dsadsadsa", e.getLocalizedMessage()); | 197 | Log.d("dsadsadsa", e.getLocalizedMessage()); |
194 | e.printStackTrace(); | 198 | e.printStackTrace(); |
195 | } | 199 | } |
196 | return null; | 200 | return null; |
197 | } | 201 | } |
198 | 202 | ||
199 | @Override | 203 | @Override |
200 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | 204 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
201 | super.onActivityResult(requestCode, resultCode, intent); | 205 | super.onActivityResult(requestCode, resultCode, intent); |
202 | if (requestCode == CAMERA_REQUEST_CODE) { | 206 | if (requestCode == CAMERA_REQUEST_CODE) { |
203 | if (resultCode == RESULT_OK) { | 207 | if (resultCode == RESULT_OK) { |
204 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 | 208 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 |
205 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 209 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
206 | Uri contentUri = FileProvider.getUriForFile(this, | 210 | Uri contentUri = FileProvider.getUriForFile(this, |
207 | this.getPackageName() + ".fileprovider", tempFile); | 211 | this.getPackageName() + ".fileprovider", tempFile); |
208 | cropPhoto(contentUri); | 212 | cropPhoto(contentUri); |
209 | } else { | 213 | } else { |
210 | cropPhoto(Uri.fromFile(tempFile)); | 214 | cropPhoto(Uri.fromFile(tempFile)); |
211 | } | 215 | } |
212 | } | 216 | } |
213 | } else if (requestCode == ALBUM_REQUEST_CODE) { | 217 | } else if (requestCode == ALBUM_REQUEST_CODE) { |
214 | if (resultCode == RESULT_OK) { | 218 | if (resultCode == RESULT_OK) { |
215 | Uri uri = intent.getData(); | 219 | Uri uri = intent.getData(); |
216 | cropPhoto(uri); | 220 | cropPhoto(uri); |
217 | } | 221 | } |
218 | } else if (requestCode == CROP_REQUEST_CODE) { | 222 | } else if (requestCode == CROP_REQUEST_CODE) { |
219 | if (intent == null) { | 223 | if (intent == null) { |
220 | return; | 224 | return; |
221 | } | 225 | } |
222 | Bundle bundle = intent.getExtras(); | 226 | Bundle bundle = intent.getExtras(); |
223 | if (bundle != null) { | 227 | if (bundle != null) { |
224 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 | 228 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 |
225 | Bitmap image = bundle.getParcelable("data"); | 229 | Bitmap image = bundle.getParcelable("data"); |
226 | //设置到ImageView上 | 230 | //设置到ImageView上 |
227 | //也可以进行一些保存、压缩等操作后上传 | 231 | //也可以进行一些保存、压缩等操作后上传 |
228 | File file = saveImage("head_output", image); | 232 | File file = saveImage("head_output", image); |
229 | uploadAvatar(file); | 233 | uploadAvatar(file); |
230 | // Log.d("dsadsadsa",path); | 234 | // Log.d("dsadsadsa",path); |
231 | } | 235 | } |
232 | } | 236 | } |
233 | } | 237 | } |
234 | 238 | ||
235 | private void getPicFromCamera() { | 239 | private void getPicFromCamera() { |
236 | //用于保存调用相机拍照后所生成的文件 | 240 | //用于保存调用相机拍照后所生成的文件 |
237 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); | 241 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); |
238 | //跳转到调用系统相机 | 242 | //跳转到调用系统相机 |
239 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 243 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
240 | //判断版本 | 244 | //判断版本 |
241 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri | 245 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri |
242 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 246 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
243 | Uri contentUri = FileProvider.getUriForFile(this, | 247 | Uri contentUri = FileProvider.getUriForFile(this, |
244 | this.getPackageName() + ".fileprovider", tempFile); | 248 | this.getPackageName() + ".fileprovider", tempFile); |
245 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); | 249 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); |
246 | } else { //否则使用Uri.fromFile(file)方法获取Uri | 250 | } else { //否则使用Uri.fromFile(file)方法获取Uri |
247 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); | 251 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); |
248 | } | 252 | } |
249 | startActivityForResult(intent, CAMERA_REQUEST_CODE); | 253 | startActivityForResult(intent, CAMERA_REQUEST_CODE); |
250 | } | 254 | } |
251 | 255 | ||
252 | private void cropPhoto(Uri uri) { | 256 | private void cropPhoto(Uri uri) { |
253 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); | 257 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); |
254 | Intent intent = new Intent("com.android.camera.action.CROP"); | 258 | Intent intent = new Intent("com.android.camera.action.CROP"); |
255 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 259 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
256 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 | 260 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 |
257 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 261 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
258 | } | 262 | } |
259 | intent.setDataAndType(uri, "image/*"); | 263 | intent.setDataAndType(uri, "image/*"); |
260 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 | 264 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 |
261 | intent.putExtra("scale", true);// 设置缩放 | 265 | intent.putExtra("scale", true);// 设置缩放 |
262 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 | 266 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 |
263 | intent.putExtra("aspectX", 1); | 267 | intent.putExtra("aspectX", 1); |
264 | intent.putExtra("aspectY", 1); | 268 | intent.putExtra("aspectY", 1); |
265 | //上述两个属性控制裁剪框的缩放比例。 | 269 | //上述两个属性控制裁剪框的缩放比例。 |
266 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 | 270 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 |
267 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 | 271 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 |
268 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, | 272 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, |
269 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 | 273 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 |
270 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap | 274 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap |
271 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 | 275 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 |
272 | startActivityForResult(intent, CROP_REQUEST_CODE); | 276 | startActivityForResult(intent, CROP_REQUEST_CODE); |
273 | } | 277 | } |
274 | 278 | ||
275 | /** | 279 | /** |
276 | * 从相册获取图片 | 280 | * 从相册获取图片 |
277 | */ | 281 | */ |
278 | private void getPicFromAlbm() { | 282 | private void getPicFromAlbm() { |
279 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 283 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
280 | photoPickerIntent.setType("image/*"); | 284 | photoPickerIntent.setType("image/*"); |
281 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); | 285 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); |
282 | } | 286 | } |
283 | 287 | ||
284 | @OnClick(R.id.iv_3) | 288 | @OnClick(R.id.iv_3) |
285 | public void showButtonDialog(View view) { | 289 | public void showButtonDialog(View view) { |
286 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); | 290 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); |
287 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); | 291 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); |
288 | dialog.setContentView(bottomView); | 292 | dialog.setContentView(bottomView); |
289 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 293 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
290 | @Override | 294 | @Override |
291 | public void onClick(View view) { | 295 | public void onClick(View view) { |
292 | dialog.dismiss(); | 296 | dialog.dismiss(); |
293 | getPicFromCamera(); | 297 | if (!XXPermissions.isGranted(AccountActivity.this, Permission.CAMERA)) { |
298 | XXPermissions.with(AccountActivity.this) | ||
299 | // 申请多个权限 | ||
300 | .permission(Permission.CAMERA) | ||
301 | .request(new OnPermissionCallback() { | ||
302 | @Override | ||
303 | public void onGranted(List<String> permissions, boolean all) { | ||
304 | if (all) { | ||
305 | //开启扫码界面 | ||
306 | getPicFromCamera(); | ||
307 | } else { | ||
308 | Toast.makeText(AccountActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | @Override | ||
313 | public void onDenied(List<String> permissions, boolean never) { | ||
314 | XXPermissions.startPermissionActivity(AccountActivity.this, permissions); | ||
315 | } | ||
316 | }); | ||
317 | } else { | ||
318 | getPicFromCamera(); | ||
319 | } | ||
294 | } | 320 | } |
295 | }); | 321 | }); |
296 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 322 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
297 | @Override | 323 | @Override |
298 | public void onClick(View view) { | 324 | public void onClick(View view) { |
299 | dialog.dismiss(); | 325 | dialog.dismiss(); |
300 | getPicFromAlbm(); | 326 | getPicFromAlbm(); |
301 | } | 327 | } |
302 | }); | 328 | }); |
303 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 329 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
304 | @Override | 330 | @Override |
305 | public void onClick(View view) { | 331 | public void onClick(View view) { |
306 | dialog.dismiss(); | 332 | dialog.dismiss(); |
307 | } | 333 | } |
308 | }); | 334 | }); |
309 | dialog.show(); | 335 | dialog.show(); |
310 | } | 336 | } |
311 | 337 | ||
312 | @OnClick(R.id.logout) | 338 | @OnClick(R.id.logout) |
313 | public void logout(View view) { | 339 | public void logout(View view) { |
314 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | 340 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
315 | builder.setTitle("温馨提示"); | 341 | builder.setTitle("温馨提示"); |
316 | builder.setMessage("是否退出登录?"); | 342 | builder.setMessage("是否退出登录?"); |
317 | builder.setCancelable(false); | 343 | builder.setCancelable(false); |
318 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { | 344 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { |
319 | @Override | 345 | @Override |
320 | public void onClick(DialogInterface dialogInterface, int i) { | 346 | public void onClick(DialogInterface dialogInterface, int i) { |
321 | dialogInterface.dismiss(); | 347 | dialogInterface.dismiss(); |
322 | } | 348 | } |
323 | }); | 349 | }); |
324 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { | 350 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { |
325 | @Override | 351 | @Override |
326 | public void onClick(DialogInterface dialogInterface, int i) { | 352 | public void onClick(DialogInterface dialogInterface, int i) { |
327 | SharedPreferencesUtil.clear(AccountActivity.this); | 353 | SharedPreferencesUtil.clear(AccountActivity.this); |
328 | dialogInterface.dismiss(); | 354 | dialogInterface.dismiss(); |
329 | setResult(1001); | 355 | setResult(1001); |
330 | finish(); | 356 | finish(); |
331 | } | 357 | } |
332 | }); | 358 | }); |
333 | builder.show(); | 359 | builder.show(); |
334 | } | 360 | } |
335 | 361 | ||
336 | } | 362 | } |
app/src/main/java/com/hjx/parent/AddStudentActivity.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.Color; | 5 | import android.graphics.Color; |
6 | import android.net.Uri; | 6 | import android.net.Uri; |
7 | import android.os.Build; | 7 | import android.os.Build; |
8 | import android.os.Bundle; | 8 | import android.os.Bundle; |
9 | import android.os.Environment; | 9 | import android.os.Environment; |
10 | import android.provider.MediaStore; | 10 | import android.provider.MediaStore; |
11 | import android.util.Log; | 11 | import android.util.Log; |
12 | import android.view.LayoutInflater; | 12 | import android.view.LayoutInflater; |
13 | import android.view.View; | 13 | import android.view.View; |
14 | import android.widget.Button; | 14 | import android.widget.Button; |
15 | import android.widget.ImageView; | 15 | import android.widget.ImageView; |
16 | import android.widget.TextView; | 16 | import android.widget.TextView; |
17 | import android.widget.Toast; | 17 | import android.widget.Toast; |
18 | 18 | ||
19 | import androidx.core.content.FileProvider; | 19 | import androidx.core.content.FileProvider; |
20 | 20 | ||
21 | import com.bumptech.glide.Glide; | 21 | import com.bumptech.glide.Glide; |
22 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 22 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
23 | import com.bumptech.glide.request.RequestOptions; | 23 | import com.bumptech.glide.request.RequestOptions; |
24 | import com.google.android.material.bottomsheet.BottomSheetDialog; | 24 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
25 | import com.hjq.permissions.OnPermissionCallback; | ||
26 | import com.hjq.permissions.Permission; | ||
27 | import com.hjq.permissions.XXPermissions; | ||
25 | import com.prws.common.base.BaseActivity; | 28 | import com.prws.common.base.BaseActivity; |
26 | import com.prws.common.base.BasePresenter; | 29 | import com.prws.common.base.BasePresenter; |
27 | import com.prws.common.bean.ResponseResult; | 30 | import com.prws.common.bean.ResponseResult; |
28 | import com.prws.common.net.NetWorks; | 31 | import com.prws.common.net.NetWorks; |
29 | import com.prws.common.utils.LogUtil; | 32 | import com.prws.common.utils.LogUtil; |
30 | import com.prws.common.utils.ScreenUtils; | 33 | import com.prws.common.utils.ScreenUtils; |
31 | import com.prws.common.utils.SharedPreferencesUtil; | 34 | import com.prws.common.utils.SharedPreferencesUtil; |
32 | 35 | ||
33 | import org.json.JSONObject; | 36 | import org.json.JSONObject; |
34 | 37 | ||
35 | import java.io.File; | 38 | import java.io.File; |
36 | import java.io.FileOutputStream; | 39 | import java.io.FileOutputStream; |
37 | import java.io.IOException; | 40 | import java.io.IOException; |
38 | import java.util.HashMap; | 41 | import java.util.HashMap; |
42 | import java.util.List; | ||
39 | import java.util.Map; | 43 | import java.util.Map; |
40 | 44 | ||
41 | import butterknife.BindView; | 45 | import butterknife.BindView; |
42 | import butterknife.OnClick; | 46 | import butterknife.OnClick; |
43 | import io.reactivex.Observer; | 47 | import io.reactivex.Observer; |
44 | import io.reactivex.disposables.Disposable; | 48 | import io.reactivex.disposables.Disposable; |
45 | import okhttp3.ResponseBody; | 49 | import okhttp3.ResponseBody; |
46 | 50 | ||
47 | public class AddStudentActivity extends BaseActivity { | 51 | public class AddStudentActivity extends BaseActivity { |
48 | @Override | 52 | @Override |
49 | protected int layoutResId() { | 53 | protected int layoutResId() { |
50 | return R.layout.activity_add_stu; | 54 | return R.layout.activity_add_stu; |
51 | } | 55 | } |
52 | 56 | ||
53 | @Override | 57 | @Override |
54 | public Object getContract() { | 58 | public Object getContract() { |
55 | return null; | 59 | return null; |
56 | } | 60 | } |
57 | 61 | ||
58 | @Override | 62 | @Override |
59 | public BasePresenter getPresenter() { | 63 | public BasePresenter getPresenter() { |
60 | return null; | 64 | return null; |
61 | } | 65 | } |
62 | 66 | ||
63 | View view_2; | 67 | View view_2; |
64 | View view_3; | 68 | View view_3; |
65 | View view_4; | 69 | View view_4; |
66 | View view_5; | 70 | View view_5; |
67 | Button btn_next; | 71 | Button btn_next; |
68 | TextView tv_name, tv_sex, tv_nian, tv_shen; | 72 | TextView tv_name, tv_sex, tv_nian, tv_shen; |
69 | @BindView(R.id.iv_avatar) | 73 | @BindView(R.id.iv_avatar) |
70 | ImageView iv_avatar; | 74 | ImageView iv_avatar; |
71 | 75 | ||
72 | @Override | 76 | @Override |
73 | protected void initView() { | 77 | protected void initView() { |
74 | view_2 = findViewById(R.id.view_2); | 78 | view_2 = findViewById(R.id.view_2); |
75 | view_3 = findViewById(R.id.view_3); | 79 | view_3 = findViewById(R.id.view_3); |
76 | view_4 = findViewById(R.id.view_4); | 80 | view_4 = findViewById(R.id.view_4); |
77 | view_5 = findViewById(R.id.view_5); | 81 | view_5 = findViewById(R.id.view_5); |
78 | tv_name = findViewById(R.id.tv_name); | 82 | tv_name = findViewById(R.id.tv_name); |
79 | tv_sex = findViewById(R.id.tv_sex); | 83 | tv_sex = findViewById(R.id.tv_sex); |
80 | tv_nian = findViewById(R.id.tv_nian); | 84 | tv_nian = findViewById(R.id.tv_nian); |
81 | tv_shen = findViewById(R.id.tv_shen); | 85 | tv_shen = findViewById(R.id.tv_shen); |
82 | btn_next = findViewById(R.id.btn_next); | 86 | btn_next = findViewById(R.id.btn_next); |
83 | } | 87 | } |
84 | 88 | ||
85 | boolean isName = false; | 89 | boolean isName = false; |
86 | boolean isSex = false; | 90 | boolean isSex = false; |
87 | boolean isNian = false; | 91 | boolean isNian = false; |
88 | boolean isShen = false; | 92 | boolean isShen = false; |
89 | private static int CAMERA_REQUEST_CODE = 343; | 93 | private static int CAMERA_REQUEST_CODE = 343; |
90 | private static int ALBUM_REQUEST_CODE = 456; | 94 | private static int ALBUM_REQUEST_CODE = 456; |
91 | private static int CROP_REQUEST_CODE = 234; | 95 | private static int CROP_REQUEST_CODE = 234; |
92 | private File tempFile; | 96 | private File tempFile; |
93 | private String path; | 97 | private String path; |
94 | 98 | ||
95 | @Override | 99 | @Override |
96 | protected void onStart() { | 100 | protected void onStart() { |
97 | super.onStart(); | 101 | super.onStart(); |
98 | String name = (String) SharedPreferencesUtil.getData("setName", ""); | 102 | String name = (String) SharedPreferencesUtil.getData("setName", ""); |
99 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); | 103 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); |
100 | String nian = (String) SharedPreferencesUtil.getData("setNian", "") + SharedPreferencesUtil.getData("setXueq", ""); | 104 | String nian = (String) SharedPreferencesUtil.getData("setNian", "") + SharedPreferencesUtil.getData("setXueq", ""); |
101 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); | 105 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); |
102 | 106 | ||
103 | if (name != null && name.length() > 0) { | 107 | if (name != null && name.length() > 0) { |
104 | tv_name.setText(name); | 108 | tv_name.setText(name); |
105 | isName = true; | 109 | isName = true; |
106 | } else { | 110 | } else { |
107 | isName = false; | 111 | isName = false; |
108 | } | 112 | } |
109 | if (sex != null && sex.length() > 0) { | 113 | if (sex != null && sex.length() > 0) { |
110 | tv_sex.setText(sex); | 114 | tv_sex.setText(sex); |
111 | isSex = true; | 115 | isSex = true; |
112 | } else { | 116 | } else { |
113 | isSex = false; | 117 | isSex = false; |
114 | } | 118 | } |
115 | if (nian != null && nian.length() > 0) { | 119 | if (nian != null && nian.length() > 0) { |
116 | tv_nian.setText(nian); | 120 | tv_nian.setText(nian); |
117 | isNian = true; | 121 | isNian = true; |
118 | } else { | 122 | } else { |
119 | isNian = false; | 123 | isNian = false; |
120 | } | 124 | } |
121 | if (shen != null && shen.length() > 0) { | 125 | if (shen != null && shen.length() > 0) { |
122 | tv_shen.setText(shen); | 126 | tv_shen.setText(shen); |
123 | isShen = true; | 127 | isShen = true; |
124 | } else { | 128 | } else { |
125 | isShen = false; | 129 | isShen = false; |
126 | } | 130 | } |
127 | 131 | ||
128 | if (isName && isSex && isNian && isShen) { | 132 | if (isName && isSex && isNian && isShen) { |
129 | btn_next.setTextColor(Color.WHITE); | 133 | btn_next.setTextColor(Color.WHITE); |
130 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); | 134 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); |
131 | } | 135 | } |
132 | 136 | ||
133 | } | 137 | } |
134 | 138 | ||
135 | @Override | 139 | @Override |
136 | protected void initListener() { | 140 | protected void initListener() { |
137 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); | 141 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); |
138 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); | 142 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); |
139 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); | 143 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); |
140 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); | 144 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); |
141 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); | 145 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); |
142 | btn_next.setOnClickListener(view -> { | 146 | btn_next.setOnClickListener(view -> { |
143 | if (isName && isSex && isNian && isShen) { | 147 | if (isName && isSex && isNian && isShen) { |
144 | addStudent(); | 148 | addStudent(); |
145 | } else { | 149 | } else { |
146 | Toast.makeText(this, "请完成设置后点击", Toast.LENGTH_SHORT).show(); | 150 | Toast.makeText(this, "请完成设置后点击", Toast.LENGTH_SHORT).show(); |
147 | } | 151 | } |
148 | }); | 152 | }); |
149 | } | 153 | } |
150 | 154 | ||
151 | @Override | 155 | @Override |
152 | protected void onDestroy() { | 156 | protected void onDestroy() { |
153 | super.onDestroy(); | 157 | super.onDestroy(); |
154 | SharedPreferencesUtil.putData("setName", ""); | 158 | SharedPreferencesUtil.putData("setName", ""); |
155 | SharedPreferencesUtil.putData("setSex", ""); | 159 | SharedPreferencesUtil.putData("setSex", ""); |
156 | SharedPreferencesUtil.putData("setNian", ""); | 160 | SharedPreferencesUtil.putData("setNian", ""); |
157 | SharedPreferencesUtil.putData("setShen", ""); | 161 | SharedPreferencesUtil.putData("setShen", ""); |
158 | SharedPreferencesUtil.putData("setXueq", ""); | 162 | SharedPreferencesUtil.putData("setXueq", ""); |
159 | SharedPreferencesUtil.putData("grade", 0); | 163 | SharedPreferencesUtil.putData("grade", 0); |
160 | } | 164 | } |
161 | 165 | ||
162 | 166 | ||
163 | public void addStudent() { | 167 | public void addStudent() { |
164 | String name = (String) SharedPreferencesUtil.getData("setName", ""); | 168 | String name = (String) SharedPreferencesUtil.getData("setName", ""); |
165 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); | 169 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); |
166 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); | 170 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); |
167 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); | 171 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); |
168 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); | 172 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); |
169 | 173 | ||
170 | 174 | ||
171 | Map map = new HashMap(); | 175 | Map map = new HashMap(); |
172 | map.put("nickName", name); | 176 | map.put("nickName", name); |
173 | map.put("gender", "男".equals(sex) ? 0 : 1); | 177 | map.put("gender", "男".equals(sex) ? 0 : 1); |
174 | map.put("gradeId", SharedPreferencesUtil.getData("grade", 1)); | 178 | map.put("gradeId", SharedPreferencesUtil.getData("grade", 1)); |
175 | map.put("parentIdentity", shen); | 179 | map.put("parentIdentity", shen); |
176 | map.put("term", xueq); | 180 | map.put("term", xueq); |
177 | if (path != null) { | 181 | if (path != null) { |
178 | map.put("photo", path); | 182 | map.put("photo", path); |
179 | } | 183 | } |
180 | 184 | ||
181 | NetWorks.registerStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 185 | NetWorks.registerStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
182 | @Override | 186 | @Override |
183 | public void onSubscribe(Disposable d) { | 187 | public void onSubscribe(Disposable d) { |
184 | 188 | ||
185 | } | 189 | } |
186 | 190 | ||
187 | @Override | 191 | @Override |
188 | public void onNext(ResponseBody responseBody) { | 192 | public void onNext(ResponseBody responseBody) { |
189 | try { | 193 | try { |
190 | 194 | ||
191 | String str = responseBody.string().toString(); | 195 | String str = responseBody.string().toString(); |
192 | LogUtil.e(TAG, "----" + str); | 196 | LogUtil.e(TAG, "----" + str); |
193 | JSONObject jo = new JSONObject(str); | 197 | JSONObject jo = new JSONObject(str); |
194 | boolean isSucceed = jo.getBoolean("success"); | 198 | boolean isSucceed = jo.getBoolean("success"); |
195 | if (isSucceed) { | 199 | if (isSucceed) { |
196 | finish(); | 200 | finish(); |
197 | } else { | 201 | } else { |
198 | Toast.makeText(AddStudentActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 202 | Toast.makeText(AddStudentActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
199 | } | 203 | } |
200 | } catch (Exception e) { | 204 | } catch (Exception e) { |
201 | e.printStackTrace(); | 205 | e.printStackTrace(); |
202 | Toast.makeText(AddStudentActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 206 | Toast.makeText(AddStudentActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
203 | } | 207 | } |
204 | 208 | ||
205 | } | 209 | } |
206 | 210 | ||
207 | @Override | 211 | @Override |
208 | public void onError(Throwable e) { | 212 | public void onError(Throwable e) { |
209 | 213 | ||
210 | } | 214 | } |
211 | 215 | ||
212 | @Override | 216 | @Override |
213 | public void onComplete() { | 217 | public void onComplete() { |
214 | 218 | ||
215 | } | 219 | } |
216 | 220 | ||
217 | }); | 221 | }); |
218 | } | 222 | } |
219 | 223 | ||
220 | @Override | 224 | @Override |
221 | protected void initData() { | 225 | protected void initData() { |
222 | 226 | ||
223 | } | 227 | } |
224 | 228 | ||
225 | @Override | 229 | @Override |
226 | public void onNetChanged(int netWorkState) { | 230 | public void onNetChanged(int netWorkState) { |
227 | 231 | ||
228 | } | 232 | } |
229 | 233 | ||
230 | @OnClick(R.id.iv_avatar) | 234 | @OnClick(R.id.iv_avatar) |
231 | public void showButtonDialog(View view) { | 235 | public void showButtonDialog(View view) { |
232 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); | 236 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); |
233 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); | 237 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); |
234 | dialog.setContentView(bottomView); | 238 | dialog.setContentView(bottomView); |
235 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 239 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
236 | @Override | 240 | @Override |
237 | public void onClick(View view) { | 241 | public void onClick(View view) { |
238 | dialog.dismiss(); | 242 | dialog.dismiss(); |
239 | getPicFromCamera(); | 243 | if (!XXPermissions.isGranted(AddStudentActivity.this, Permission.CAMERA)) { |
244 | XXPermissions.with(AddStudentActivity.this) | ||
245 | // 申请多个权限 | ||
246 | .permission(Permission.CAMERA) | ||
247 | .request(new OnPermissionCallback() { | ||
248 | @Override | ||
249 | public void onGranted(List<String> permissions, boolean all) { | ||
250 | if (all) { | ||
251 | //开启扫码界面 | ||
252 | getPicFromCamera(); | ||
253 | } else { | ||
254 | Toast.makeText(AddStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | @Override | ||
259 | public void onDenied(List<String> permissions, boolean never) { | ||
260 | XXPermissions.startPermissionActivity(AddStudentActivity.this, permissions); | ||
261 | } | ||
262 | }); | ||
263 | } else { | ||
264 | getPicFromCamera(); | ||
265 | } | ||
240 | } | 266 | } |
241 | }); | 267 | }); |
242 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 268 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
243 | @Override | 269 | @Override |
244 | public void onClick(View view) { | 270 | public void onClick(View view) { |
245 | dialog.dismiss(); | 271 | dialog.dismiss(); |
246 | getPicFromAlbm(); | 272 | getPicFromAlbm(); |
247 | } | 273 | } |
248 | }); | 274 | }); |
249 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 275 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
250 | @Override | 276 | @Override |
251 | public void onClick(View view) { | 277 | public void onClick(View view) { |
252 | dialog.dismiss(); | 278 | dialog.dismiss(); |
253 | } | 279 | } |
254 | }); | 280 | }); |
255 | dialog.show(); | 281 | dialog.show(); |
256 | } | 282 | } |
257 | 283 | ||
258 | private void cropPhoto(Uri uri) { | 284 | private void cropPhoto(Uri uri) { |
259 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); | 285 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); |
260 | Intent intent = new Intent("com.android.camera.action.CROP"); | 286 | Intent intent = new Intent("com.android.camera.action.CROP"); |
261 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 287 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
262 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 | 288 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 |
263 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 289 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
264 | } | 290 | } |
265 | intent.setDataAndType(uri, "image/*"); | 291 | intent.setDataAndType(uri, "image/*"); |
266 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 | 292 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 |
267 | intent.putExtra("scale", true);// 设置缩放 | 293 | intent.putExtra("scale", true);// 设置缩放 |
268 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 | 294 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 |
269 | intent.putExtra("aspectX", 1); | 295 | intent.putExtra("aspectX", 1); |
270 | intent.putExtra("aspectY", 1); | 296 | intent.putExtra("aspectY", 1); |
271 | //上述两个属性控制裁剪框的缩放比例。 | 297 | //上述两个属性控制裁剪框的缩放比例。 |
272 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 | 298 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 |
273 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 | 299 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 |
274 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, | 300 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, |
275 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 | 301 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 |
276 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap | 302 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap |
277 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 | 303 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 |
278 | startActivityForResult(intent, CROP_REQUEST_CODE); | 304 | startActivityForResult(intent, CROP_REQUEST_CODE); |
279 | } | 305 | } |
280 | 306 | ||
281 | @Override | 307 | @Override |
282 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | 308 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
283 | super.onActivityResult(requestCode, resultCode, intent); | 309 | super.onActivityResult(requestCode, resultCode, intent); |
284 | if (requestCode == CAMERA_REQUEST_CODE) { | 310 | if (requestCode == CAMERA_REQUEST_CODE) { |
285 | if (resultCode == RESULT_OK) { | 311 | if (resultCode == RESULT_OK) { |
286 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 | 312 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 |
287 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 313 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
288 | Uri contentUri = FileProvider.getUriForFile(AddStudentActivity.this, | 314 | Uri contentUri = FileProvider.getUriForFile(AddStudentActivity.this, |
289 | this.getPackageName() + ".fileprovider", tempFile); | 315 | this.getPackageName() + ".fileprovider", tempFile); |
290 | cropPhoto(contentUri); | 316 | cropPhoto(contentUri); |
291 | } else { | 317 | } else { |
292 | cropPhoto(Uri.fromFile(tempFile)); | 318 | cropPhoto(Uri.fromFile(tempFile)); |
293 | } | 319 | } |
294 | } | 320 | } |
295 | } else if (requestCode == ALBUM_REQUEST_CODE) { | 321 | } else if (requestCode == ALBUM_REQUEST_CODE) { |
296 | if (resultCode == RESULT_OK) { | 322 | if (resultCode == RESULT_OK) { |
297 | Uri uri = intent.getData(); | 323 | Uri uri = intent.getData(); |
298 | cropPhoto(uri); | 324 | cropPhoto(uri); |
299 | } | 325 | } |
300 | } else if (requestCode == CROP_REQUEST_CODE) { | 326 | } else if (requestCode == CROP_REQUEST_CODE) { |
301 | if (intent == null) { | 327 | if (intent == null) { |
302 | return; | 328 | return; |
303 | } | 329 | } |
304 | Bundle bundle = intent.getExtras(); | 330 | Bundle bundle = intent.getExtras(); |
305 | if (bundle != null) { | 331 | if (bundle != null) { |
306 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 | 332 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 |
307 | Bitmap image = bundle.getParcelable("data"); | 333 | Bitmap image = bundle.getParcelable("data"); |
308 | //设置到ImageView上 | 334 | //设置到ImageView上 |
309 | //也可以进行一些保存、压缩等操作后上传 | 335 | //也可以进行一些保存、压缩等操作后上传 |
310 | File file = saveImage("head_output", image); | 336 | File file = saveImage("head_output", image); |
311 | uploadAvatar(file); | 337 | uploadAvatar(file); |
312 | // Log.d("dsadsadsa",path); | 338 | // Log.d("dsadsadsa",path); |
313 | } | 339 | } |
314 | } | 340 | } |
315 | } | 341 | } |
316 | 342 | ||
317 | private void uploadAvatar(File file) { | 343 | private void uploadAvatar(File file) { |
318 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); | ||
319 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | ||
320 | Glide.with(this).load(file).apply(options).into(iv_avatar); | ||
321 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { | 344 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { |
322 | @Override | 345 | @Override |
323 | public void onSubscribe(Disposable d) { | 346 | public void onSubscribe(Disposable d) { |
324 | 347 | ||
325 | } | 348 | } |
326 | 349 | ||
327 | @Override | 350 | @Override |
328 | public void onNext(ResponseResult<Map<String, String>> responseBody) { | 351 | public void onNext(ResponseResult<Map<String, String>> responseBody) { |
329 | if (responseBody.getData() != null && responseBody.getCode() == 200) { | 352 | if (responseBody.getData() != null && responseBody.getCode() == 200) { |
330 | path = responseBody.getData().get("imageUrl"); | 353 | path = responseBody.getData().get("imageUrl"); |
354 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AddStudentActivity.this, 45)); | ||
355 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | ||
356 | Glide.with(AddStudentActivity.this).load(path).apply(options).into(iv_avatar); | ||
331 | } | 357 | } |
332 | } | 358 | } |
333 | 359 | ||
334 | @Override | 360 | @Override |
335 | public void onError(Throwable e) { | 361 | public void onError(Throwable e) { |
336 | e.toString(); | 362 | e.toString(); |
337 | } | 363 | } |
338 | 364 | ||
339 | @Override | 365 | @Override |
340 | public void onComplete() { | 366 | public void onComplete() { |
341 | 367 | ||
342 | } | 368 | } |
343 | }); | 369 | }); |
344 | } | 370 | } |
345 | 371 | ||
346 | public File saveImage(String name, Bitmap bmp) { | 372 | public File saveImage(String name, Bitmap bmp) { |
347 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); | 373 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); |
348 | if (!appDir.exists()) { | 374 | if (!appDir.exists()) { |
349 | appDir.mkdir(); | 375 | appDir.mkdir(); |
350 | } | 376 | } |
351 | String fileName = name + ".jpg"; | 377 | String fileName = name + ".jpg"; |
352 | File file = new File(appDir, fileName); | 378 | File file = new File(appDir, fileName); |
353 | try { | 379 | try { |
354 | FileOutputStream fos = new FileOutputStream(file); | 380 | FileOutputStream fos = new FileOutputStream(file); |
355 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); | 381 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); |
356 | fos.flush(); | 382 | fos.flush(); |
357 | fos.close(); | 383 | fos.close(); |
358 | return file; | 384 | return file; |
359 | } catch (IOException e) { | 385 | } catch (IOException e) { |
360 | Log.d("dsadsadsa", e.getLocalizedMessage()); | 386 | Log.d("dsadsadsa", e.getLocalizedMessage()); |
361 | e.printStackTrace(); | 387 | e.printStackTrace(); |
362 | } | 388 | } |
363 | return null; | 389 | return null; |
364 | } | 390 | } |
365 | 391 | ||
366 | private void getPicFromCamera() { | 392 | private void getPicFromCamera() { |
367 | //用于保存调用相机拍照后所生成的文件 | 393 | //用于保存调用相机拍照后所生成的文件 |
368 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); | 394 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); |
369 | //跳转到调用系统相机 | 395 | //跳转到调用系统相机 |
370 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 396 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
371 | //判断版本 | 397 | //判断版本 |
372 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri | 398 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri |
373 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 399 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
374 | Uri contentUri = FileProvider.getUriForFile(AddStudentActivity.this, | 400 | Uri contentUri = FileProvider.getUriForFile(AddStudentActivity.this, |
375 | this.getPackageName() + ".fileprovider", tempFile); | 401 | this.getPackageName() + ".fileprovider", tempFile); |
376 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); | 402 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); |
377 | } else { //否则使用Uri.fromFile(file)方法获取Uri | 403 | } else { //否则使用Uri.fromFile(file)方法获取Uri |
378 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); | 404 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); |
379 | } | 405 | } |
380 | startActivityForResult(intent, CAMERA_REQUEST_CODE); | 406 | startActivityForResult(intent, CAMERA_REQUEST_CODE); |
381 | } | 407 | } |
382 | 408 | ||
383 | /** | 409 | /** |
384 | * 从相册获取图片 | 410 | * 从相册获取图片 |
385 | */ | 411 | */ |
386 | private void getPicFromAlbm() { | 412 | private void getPicFromAlbm() { |
387 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 413 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
388 | photoPickerIntent.setType("image/*"); | 414 | photoPickerIntent.setType("image/*"); |
389 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); | 415 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); |
390 | } | 416 | } |
app/src/main/java/com/hjx/parent/ChooseActivity.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.text.TextUtils; | 4 | import android.text.TextUtils; |
5 | import android.view.View; | 5 | import android.view.View; |
6 | import android.widget.ImageView; | 6 | import android.widget.ImageView; |
7 | 7 | ||
8 | import androidx.annotation.NonNull; | 8 | import androidx.annotation.NonNull; |
9 | import androidx.recyclerview.widget.LinearLayoutManager; | 9 | import androidx.recyclerview.widget.LinearLayoutManager; |
10 | import androidx.recyclerview.widget.RecyclerView; | 10 | import androidx.recyclerview.widget.RecyclerView; |
11 | 11 | ||
12 | import com.bumptech.glide.Glide; | 12 | import com.bumptech.glide.Glide; |
13 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 13 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
14 | import com.bumptech.glide.request.RequestOptions; | 14 | import com.bumptech.glide.request.RequestOptions; |
15 | import com.chad.library.adapter.base.BaseQuickAdapter; | 15 | import com.chad.library.adapter.base.BaseQuickAdapter; |
16 | import com.chad.library.adapter.base.BaseViewHolder; | 16 | import com.chad.library.adapter.base.BaseViewHolder; |
17 | import com.google.gson.Gson; | 17 | import com.google.gson.Gson; |
18 | import com.hjx.parent.bean.StudentBean; | 18 | import com.hjx.parent.bean.StudentBean; |
19 | import com.prws.common.base.BaseActivity; | 19 | import com.prws.common.base.BaseActivity; |
20 | import com.prws.common.base.BasePresenter; | 20 | import com.prws.common.base.BasePresenter; |
21 | import com.prws.common.net.NetWorks; | 21 | import com.prws.common.net.NetWorks; |
22 | import com.prws.common.utils.LogUtil; | 22 | import com.prws.common.utils.LogUtil; |
23 | import com.prws.common.utils.ScreenUtils; | 23 | import com.prws.common.utils.ScreenUtils; |
24 | import com.prws.common.utils.SharedPreferencesUtil; | 24 | import com.prws.common.utils.SharedPreferencesUtil; |
25 | 25 | ||
26 | import org.json.JSONArray; | 26 | import org.json.JSONArray; |
27 | import org.json.JSONObject; | 27 | import org.json.JSONObject; |
28 | 28 | ||
29 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
30 | 30 | ||
31 | import butterknife.BindView; | 31 | import butterknife.BindView; |
32 | import butterknife.OnClick; | 32 | import butterknife.OnClick; |
33 | import io.reactivex.Observer; | 33 | import io.reactivex.Observer; |
34 | import io.reactivex.disposables.Disposable; | 34 | import io.reactivex.disposables.Disposable; |
35 | import okhttp3.ResponseBody; | 35 | import okhttp3.ResponseBody; |
36 | 36 | ||
37 | public class ChooseActivity extends BaseActivity { | 37 | public class ChooseActivity extends BaseActivity { |
38 | @BindView(R.id.recycle) | 38 | @BindView(R.id.recycle) |
39 | RecyclerView recycle; | 39 | RecyclerView recycle; |
40 | private int select = 0; | 40 | private int select = 0; |
41 | 41 | ||
42 | @Override | 42 | @Override |
43 | protected int layoutResId() { | 43 | protected int layoutResId() { |
44 | return R.layout.choose_activity; | 44 | return R.layout.choose_activity; |
45 | } | 45 | } |
46 | 46 | ||
47 | @Override | 47 | @Override |
48 | public Object getContract() { | 48 | public Object getContract() { |
49 | return null; | 49 | return null; |
50 | } | 50 | } |
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | public BasePresenter getPresenter() { | 53 | public BasePresenter getPresenter() { |
54 | return null; | 54 | return null; |
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | protected void initView() { | 58 | protected void initView() { |
59 | 59 | ||
60 | } | 60 | } |
61 | 61 | ||
62 | @Override | 62 | @Override |
63 | protected void initListener() { | 63 | protected void initListener() { |
64 | 64 | ||
65 | } | 65 | } |
66 | 66 | ||
67 | @Override | 67 | @Override |
68 | protected void initData() { | 68 | protected void initData() { |
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | @Override | 72 | @Override |
73 | public void onNetChanged(int netWorkState) { | 73 | public void onNetChanged(int netWorkState) { |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | @Override | 77 | @Override |
78 | protected void onResume() { | 78 | protected void onResume() { |
79 | super.onResume(); | 79 | super.onResume(); |
80 | loadChildList(); | 80 | loadChildList(); |
81 | } | 81 | } |
82 | 82 | ||
83 | ArrayList<StudentBean> alist = new ArrayList<>(); | 83 | ArrayList<StudentBean> alist = new ArrayList<>(); |
84 | 84 | ||
85 | public void loadChildList() { | 85 | public void loadChildList() { |
86 | NetWorks.listChildren(new Observer<ResponseBody>() { | 86 | NetWorks.listChildren(new Observer<ResponseBody>() { |
87 | @Override | 87 | @Override |
88 | public void onSubscribe(Disposable d) { | 88 | public void onSubscribe(Disposable d) { |
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | public void onNext(ResponseBody responseBody) { | 93 | public void onNext(ResponseBody responseBody) { |
94 | try { | 94 | try { |
95 | 95 | ||
96 | String str = responseBody.string().toString(); | 96 | String str = responseBody.string().toString(); |
97 | 97 | ||
98 | 98 | ||
99 | LogUtil.e("TAG", "----" + str); | 99 | LogUtil.e("TAG", "----" + str); |
100 | JSONObject jo = new JSONObject(str); | 100 | JSONObject jo = new JSONObject(str); |
101 | boolean isSucceed = jo.getBoolean("success"); | 101 | boolean isSucceed = jo.getBoolean("success"); |
102 | if (isSucceed) { | 102 | if (isSucceed) { |
103 | JSONArray jarr = jo.getJSONArray("data"); | 103 | JSONArray jarr = jo.getJSONArray("data"); |
104 | alist.clear(); | 104 | alist.clear(); |
105 | for (int i = 0; i < jarr.length(); i++) { | 105 | for (int i = 0; i < jarr.length(); i++) { |
106 | JSONObject jo2 = jarr.getJSONObject(i); | 106 | JSONObject jo2 = jarr.getJSONObject(i); |
107 | Gson gson = new Gson(); | 107 | Gson gson = new Gson(); |
108 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); | 108 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); |
109 | alist.add(sb); | 109 | alist.add(sb); |
110 | } | 110 | } |
111 | loadList(); | 111 | loadList(); |
112 | } else { | 112 | } else { |
113 | 113 | ||
114 | } | 114 | } |
115 | } catch (Exception e) { | 115 | } catch (Exception e) { |
116 | e.printStackTrace(); | 116 | e.printStackTrace(); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | @Override | 120 | @Override |
121 | public void onError(Throwable e) { | 121 | public void onError(Throwable e) { |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | @Override | 125 | @Override |
126 | public void onComplete() { | 126 | public void onComplete() { |
127 | 127 | ||
128 | } | 128 | } |
129 | }); | 129 | }); |
130 | } | 130 | } |
131 | 131 | ||
132 | public void loadList() { | 132 | public void loadList() { |
133 | StudentBean sb = new StudentBean(); | 133 | StudentBean sb = new StudentBean(); |
134 | sb.setNickName("添加学生"); | 134 | sb.setNickName("添加学生"); |
135 | alist.add(sb); | 135 | alist.add(sb); |
136 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 136 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
137 | try { | 137 | try { |
138 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 138 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
139 | for (int i = 0; i < alist.size(); i++) { | 139 | for (int i = 0; i < alist.size(); i++) { |
140 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { | 140 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { |
141 | select = i; | 141 | select = i; |
142 | break; | 142 | break; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } catch (Exception e) { | 145 | } catch (Exception e) { |
146 | 146 | ||
147 | } | 147 | } |
148 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { | 148 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { |
149 | @Override | 149 | @Override |
150 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 150 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
151 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 151 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
152 | item.setText(R.id.tv_name, studentBean.getNickName()); | 152 | item.setText(R.id.tv_name, studentBean.getNickName()); |
153 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 153 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
154 | item.setVisible(R.id.rl_add, true); | 154 | item.setVisible(R.id.rl_add, true); |
155 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 155 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
156 | @Override | 156 | @Override |
157 | public void onClick(View view) { | 157 | public void onClick(View view) { |
158 | startActivity(new Intent(ChooseActivity.this, AddStudentActivity.class)); | 158 | startActivity(new Intent(ChooseActivity.this, AddStudentActivity.class)); |
159 | } | 159 | } |
160 | }); | 160 | }); |
161 | } else { | 161 | } else { |
162 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); | 162 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); |
163 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); | 163 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); |
164 | item.setVisible(R.id.rl_add, false); | 164 | item.setVisible(R.id.rl_add, false); |
165 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 165 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
166 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 166 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
167 | } else { | 167 | } else { |
168 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); | 168 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); |
169 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 169 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
170 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 170 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
171 | } | 171 | } |
172 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); | 172 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); |
173 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 173 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
174 | @Override | 174 | @Override |
175 | public void onClick(View view) { | 175 | public void onClick(View view) { |
176 | select = item.getAdapterPosition(); | 176 | select = item.getAdapterPosition(); |
177 | notifyDataSetChanged(); | 177 | notifyDataSetChanged(); |
178 | } | 178 | } |
179 | }); | 179 | }); |
180 | } | 180 | } |
181 | } | 181 | } |
182 | }; | 182 | }; |
183 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); | 183 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); |
184 | recycle.setAdapter(adapter); | 184 | recycle.setAdapter(adapter); |
185 | } | 185 | } |
186 | 186 | ||
187 | @OnClick(R.id.tv_confirm) | 187 | @OnClick(R.id.tv_confirm) |
188 | public void confirm(View view) { | 188 | public void confirm(View view) { |
189 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { | 189 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { |
190 | StudentBean studentBean = alist.get(select); | 190 | StudentBean studentBean = alist.get(select); |
191 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); | 191 | if (studentBean.getStuId() != null) { |
192 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 192 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); |
193 | startActivity(intent); | 193 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
194 | finish(); | 194 | startActivity(intent); |
195 | finish(); | ||
196 | } | ||
195 | } | 197 | } |
196 | } | 198 | } |
197 | } | 199 | } |
198 | 200 |
app/src/main/java/com/hjx/parent/EditStudentActivity.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.Color; | 5 | import android.graphics.Color; |
6 | import android.net.Uri; | 6 | import android.net.Uri; |
7 | import android.os.Build; | 7 | import android.os.Build; |
8 | import android.os.Bundle; | 8 | import android.os.Bundle; |
9 | import android.os.Environment; | 9 | import android.os.Environment; |
10 | import android.provider.MediaStore; | 10 | import android.provider.MediaStore; |
11 | import android.text.TextUtils; | 11 | import android.text.TextUtils; |
12 | import android.util.Log; | 12 | import android.util.Log; |
13 | import android.view.LayoutInflater; | 13 | import android.view.LayoutInflater; |
14 | import android.view.View; | 14 | import android.view.View; |
15 | import android.widget.Button; | 15 | import android.widget.Button; |
16 | import android.widget.ImageView; | 16 | import android.widget.ImageView; |
17 | import android.widget.TextView; | 17 | import android.widget.TextView; |
18 | import android.widget.Toast; | 18 | import android.widget.Toast; |
19 | 19 | ||
20 | import androidx.core.content.FileProvider; | 20 | import androidx.core.content.FileProvider; |
21 | 21 | ||
22 | import com.bumptech.glide.Glide; | 22 | import com.bumptech.glide.Glide; |
23 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 23 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
24 | import com.bumptech.glide.request.RequestOptions; | 24 | import com.bumptech.glide.request.RequestOptions; |
25 | import com.google.android.material.bottomsheet.BottomSheetDialog; | 25 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
26 | import com.google.gson.Gson; | 26 | import com.google.gson.Gson; |
27 | import com.hjq.permissions.OnPermissionCallback; | ||
28 | import com.hjq.permissions.Permission; | ||
29 | import com.hjq.permissions.XXPermissions; | ||
27 | import com.hjx.parent.bean.StudentBean; | 30 | import com.hjx.parent.bean.StudentBean; |
28 | import com.prws.common.base.BaseActivity; | 31 | import com.prws.common.base.BaseActivity; |
29 | import com.prws.common.base.BasePresenter; | 32 | import com.prws.common.base.BasePresenter; |
30 | import com.prws.common.bean.ResponseResult; | 33 | import com.prws.common.bean.ResponseResult; |
31 | import com.prws.common.net.NetWorks; | 34 | import com.prws.common.net.NetWorks; |
32 | import com.prws.common.utils.LogUtil; | 35 | import com.prws.common.utils.LogUtil; |
33 | import com.prws.common.utils.ScreenUtils; | 36 | import com.prws.common.utils.ScreenUtils; |
34 | import com.prws.common.utils.SharedPreferencesUtil; | 37 | import com.prws.common.utils.SharedPreferencesUtil; |
35 | 38 | ||
36 | import org.json.JSONObject; | 39 | import org.json.JSONObject; |
37 | 40 | ||
38 | import java.io.File; | 41 | import java.io.File; |
39 | import java.io.FileOutputStream; | 42 | import java.io.FileOutputStream; |
40 | import java.io.IOException; | 43 | import java.io.IOException; |
41 | import java.util.HashMap; | 44 | import java.util.HashMap; |
45 | import java.util.List; | ||
42 | import java.util.Map; | 46 | import java.util.Map; |
43 | 47 | ||
44 | import butterknife.BindView; | 48 | import butterknife.BindView; |
45 | import butterknife.OnClick; | 49 | import butterknife.OnClick; |
46 | import io.reactivex.Observer; | 50 | import io.reactivex.Observer; |
47 | import io.reactivex.disposables.Disposable; | 51 | import io.reactivex.disposables.Disposable; |
48 | 52 | ||
49 | public class EditStudentActivity extends BaseActivity { | 53 | public class EditStudentActivity extends BaseActivity { |
50 | View view_2; | 54 | View view_2; |
51 | View view_3; | 55 | View view_3; |
52 | View view_4; | 56 | View view_4; |
53 | View view_5; | 57 | View view_5; |
54 | Button btn_next; | 58 | Button btn_next; |
55 | TextView tv_name, tv_sex, tv_nian, tv_shen; | 59 | TextView tv_name, tv_sex, tv_nian, tv_shen; |
56 | @BindView(R.id.iv_avatar) | 60 | @BindView(R.id.iv_avatar) |
57 | ImageView iv_avatar; | 61 | ImageView iv_avatar; |
58 | @BindView(R.id.tv_teacher) | 62 | @BindView(R.id.tv_teacher) |
59 | TextView tv_teacher; | 63 | TextView tv_teacher; |
60 | @BindView(R.id.iv_teacher) | 64 | @BindView(R.id.iv_teacher) |
61 | ImageView iv_teacher; | 65 | ImageView iv_teacher; |
62 | private static int CAMERA_REQUEST_CODE = 343; | 66 | private static int CAMERA_REQUEST_CODE = 343; |
63 | private static int ALBUM_REQUEST_CODE = 456; | 67 | private static int ALBUM_REQUEST_CODE = 456; |
64 | private static int CROP_REQUEST_CODE = 234; | 68 | private static int CROP_REQUEST_CODE = 234; |
65 | private File tempFile; | 69 | private File tempFile; |
66 | private String path; | 70 | private String path; |
67 | StudentBean studentBean; | 71 | StudentBean studentBean; |
68 | 72 | ||
69 | @Override | 73 | @Override |
70 | protected int layoutResId() { | 74 | protected int layoutResId() { |
71 | return R.layout.activity_edit_stu; | 75 | return R.layout.activity_edit_stu; |
72 | } | 76 | } |
73 | 77 | ||
74 | @Override | 78 | @Override |
75 | public Object getContract() { | 79 | public Object getContract() { |
76 | return null; | 80 | return null; |
77 | } | 81 | } |
78 | 82 | ||
79 | @Override | 83 | @Override |
80 | public BasePresenter getPresenter() { | 84 | public BasePresenter getPresenter() { |
81 | return null; | 85 | return null; |
82 | } | 86 | } |
83 | 87 | ||
84 | @Override | 88 | @Override |
85 | protected void initView() { | 89 | protected void initView() { |
86 | view_2 = findViewById(R.id.view_2); | 90 | view_2 = findViewById(R.id.view_2); |
87 | view_3 = findViewById(R.id.view_3); | 91 | view_3 = findViewById(R.id.view_3); |
88 | view_4 = findViewById(R.id.view_4); | 92 | view_4 = findViewById(R.id.view_4); |
89 | view_5 = findViewById(R.id.view_5); | 93 | view_5 = findViewById(R.id.view_5); |
90 | tv_name = findViewById(R.id.tv_name); | 94 | tv_name = findViewById(R.id.tv_name); |
91 | tv_sex = findViewById(R.id.tv_sex); | 95 | tv_sex = findViewById(R.id.tv_sex); |
92 | tv_nian = findViewById(R.id.tv_nian); | 96 | tv_nian = findViewById(R.id.tv_nian); |
93 | tv_shen = findViewById(R.id.tv_shen); | 97 | tv_shen = findViewById(R.id.tv_shen); |
94 | btn_next = findViewById(R.id.btn_next); | 98 | btn_next = findViewById(R.id.btn_next); |
95 | } | 99 | } |
96 | 100 | ||
97 | @Override | 101 | @Override |
98 | protected void onStart() { | 102 | protected void onStart() { |
99 | super.onStart(); | 103 | super.onStart(); |
100 | String name = (String) SharedPreferencesUtil.getData("setName", ""); | 104 | String name = (String) SharedPreferencesUtil.getData("setName", ""); |
101 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); | 105 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); |
102 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); | 106 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); |
103 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); | 107 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); |
104 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); | 108 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); |
105 | btn_next.setTextColor(Color.WHITE); | 109 | btn_next.setTextColor(Color.WHITE); |
106 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); | 110 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); |
107 | studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class); | 111 | studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class); |
108 | if (name != null && name.length() > 0) { | 112 | if (name != null && name.length() > 0) { |
109 | studentBean.setNickName(name); | 113 | studentBean.setNickName(name); |
110 | } | 114 | } |
111 | if (sex != null && sex.length() > 0) { | 115 | if (sex != null && sex.length() > 0) { |
112 | studentBean.setGender("男".equals(sex) ? 0 : 1); | 116 | studentBean.setGender("男".equals(sex) ? 0 : 1); |
113 | } | 117 | } |
114 | if (nian != null && nian.length() > 0) { | 118 | if (nian != null && nian.length() > 0) { |
115 | studentBean.setGrade(nian); | 119 | studentBean.setGrade(nian); |
116 | studentBean.setGradeId((Integer) SharedPreferencesUtil.getData("grade", 1)); | 120 | studentBean.setGradeId((Integer) SharedPreferencesUtil.getData("grade", 1)); |
117 | } | 121 | } |
118 | if (xueq != null && xueq.length() > 0) { | 122 | if (xueq != null && xueq.length() > 0) { |
119 | studentBean.setTerm(xueq); | 123 | studentBean.setTerm(xueq); |
120 | } | 124 | } |
121 | if (shen != null && shen.length() > 0) { | 125 | if (shen != null && shen.length() > 0) { |
122 | studentBean.setParentIdentity(shen); | 126 | studentBean.setParentIdentity(shen); |
123 | } | 127 | } |
124 | tv_name.setText(studentBean.getNickName()); | 128 | tv_name.setText(studentBean.getNickName()); |
125 | tv_nian.setText(studentBean.getGrade() + studentBean.getTerm()); | 129 | tv_nian.setText(studentBean.getGrade() + studentBean.getTerm()); |
126 | tv_sex.setText(studentBean.getGender() == 0 ? "男" : "女"); | 130 | tv_sex.setText(studentBean.getGender() == 0 ? "男" : "女"); |
127 | tv_shen.setText(studentBean.getParentIdentity()); | 131 | tv_shen.setText(studentBean.getParentIdentity()); |
128 | if (!TextUtils.isEmpty(studentBean.getPhoto())) { | 132 | if (!TextUtils.isEmpty(studentBean.getPhoto())) { |
129 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); | 133 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); |
130 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 134 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
131 | Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar); | 135 | Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar); |
132 | } else { | 136 | } else { |
133 | iv_avatar.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 137 | iv_avatar.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
134 | } | 138 | } |
135 | if (!"虚拟".equals(studentBean.getTeacherIdentity())) { | 139 | if (!"虚拟".equals(studentBean.getTeacherIdentity())) { |
136 | tv_teacher.setText(studentBean.getTeacherName()); | 140 | tv_teacher.setText(studentBean.getTeacherName()); |
137 | if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { | 141 | if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { |
138 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25)); | 142 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25)); |
139 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 143 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
140 | Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher); | 144 | Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher); |
141 | } else { | 145 | } else { |
142 | iv_teacher.setImageResource(studentBean.getSex() == 0 ? R.mipmap.ic_teacher_male : R.mipmap.ic_teacher_female); | 146 | iv_teacher.setImageResource(studentBean.getSex() == 0 ? R.mipmap.ic_teacher_male : R.mipmap.ic_teacher_female); |
143 | } | 147 | } |
144 | } else { | 148 | } else { |
145 | iv_teacher.setVisibility(View.GONE); | 149 | iv_teacher.setVisibility(View.GONE); |
146 | } | 150 | } |
147 | 151 | ||
148 | } | 152 | } |
149 | 153 | ||
150 | @Override | 154 | @Override |
151 | protected void initListener() { | 155 | protected void initListener() { |
152 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); | 156 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); |
153 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); | 157 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); |
154 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); | 158 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); |
155 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); | 159 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); |
156 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); | 160 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); |
157 | btn_next.setOnClickListener(view -> { | 161 | btn_next.setOnClickListener(view -> { |
158 | editStudent(); | 162 | editStudent(); |
159 | }); | 163 | }); |
160 | } | 164 | } |
161 | 165 | ||
162 | public void editStudent() { | 166 | public void editStudent() { |
163 | Map map = new HashMap(); | 167 | Map map = new HashMap(); |
164 | map.put("nickName", studentBean.getNickName()); | 168 | map.put("nickName", studentBean.getNickName()); |
165 | map.put("gender", studentBean.getGender()); | 169 | map.put("gender", studentBean.getGender()); |
166 | map.put("gradeId", studentBean.getGradeId()); | 170 | map.put("gradeId", studentBean.getGradeId()); |
167 | map.put("parentIdentity", studentBean.getParentIdentity()); | 171 | map.put("parentIdentity", studentBean.getParentIdentity()); |
168 | map.put("term", studentBean.getTerm()); | 172 | map.put("term", studentBean.getTerm()); |
169 | map.put("stuId", studentBean.getStuId()); | 173 | map.put("stuId", studentBean.getStuId()); |
170 | NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() { | 174 | NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() { |
171 | @Override | 175 | @Override |
172 | public void onSubscribe(Disposable d) { | 176 | public void onSubscribe(Disposable d) { |
173 | 177 | ||
174 | } | 178 | } |
175 | 179 | ||
176 | @Override | 180 | @Override |
177 | public void onNext(ResponseResult responseResult) { | 181 | public void onNext(ResponseResult responseResult) { |
178 | try { | 182 | try { |
179 | boolean isSucceed = responseResult.getSuccess(); | 183 | boolean isSucceed = responseResult.getSuccess(); |
180 | if (isSucceed) { | 184 | if (isSucceed) { |
181 | finish(); | 185 | finish(); |
182 | } else { | 186 | } else { |
183 | Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show(); | 187 | Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show(); |
184 | } | 188 | } |
185 | } catch (Exception e) { | 189 | } catch (Exception e) { |
186 | 190 | ||
187 | } | 191 | } |
188 | } | 192 | } |
189 | 193 | ||
190 | @Override | 194 | @Override |
191 | public void onError(Throwable e) { | 195 | public void onError(Throwable e) { |
192 | 196 | ||
193 | } | 197 | } |
194 | 198 | ||
195 | @Override | 199 | @Override |
196 | public void onComplete() { | 200 | public void onComplete() { |
197 | 201 | ||
198 | } | 202 | } |
199 | }); | 203 | }); |
200 | } | 204 | } |
201 | 205 | ||
202 | @Override | 206 | @Override |
203 | protected void initData() { | 207 | protected void initData() { |
204 | 208 | ||
205 | } | 209 | } |
206 | 210 | ||
207 | @Override | 211 | @Override |
208 | public void onNetChanged(int netWorkState) { | 212 | public void onNetChanged(int netWorkState) { |
209 | 213 | ||
210 | } | 214 | } |
211 | 215 | ||
212 | private void cropPhoto(Uri uri) { | 216 | private void cropPhoto(Uri uri) { |
213 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); | 217 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); |
214 | Intent intent = new Intent("com.android.camera.action.CROP"); | 218 | Intent intent = new Intent("com.android.camera.action.CROP"); |
215 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 219 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
216 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 | 220 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 |
217 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 221 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
218 | } | 222 | } |
219 | intent.setDataAndType(uri, "image/*"); | 223 | intent.setDataAndType(uri, "image/*"); |
220 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 | 224 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 |
221 | intent.putExtra("scale", true);// 设置缩放 | 225 | intent.putExtra("scale", true);// 设置缩放 |
222 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 | 226 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 |
223 | intent.putExtra("aspectX", 1); | 227 | intent.putExtra("aspectX", 1); |
224 | intent.putExtra("aspectY", 1); | 228 | intent.putExtra("aspectY", 1); |
225 | //上述两个属性控制裁剪框的缩放比例。 | 229 | //上述两个属性控制裁剪框的缩放比例。 |
226 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 | 230 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 |
227 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 | 231 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 |
228 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, | 232 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, |
229 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 | 233 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 |
230 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap | 234 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap |
231 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 | 235 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 |
232 | startActivityForResult(intent, CROP_REQUEST_CODE); | 236 | startActivityForResult(intent, CROP_REQUEST_CODE); |
233 | } | 237 | } |
234 | 238 | ||
235 | @Override | 239 | @Override |
236 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | 240 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
237 | super.onActivityResult(requestCode, resultCode, intent); | 241 | super.onActivityResult(requestCode, resultCode, intent); |
238 | if (requestCode == CAMERA_REQUEST_CODE) { | 242 | if (requestCode == CAMERA_REQUEST_CODE) { |
239 | if (resultCode == RESULT_OK) { | 243 | if (resultCode == RESULT_OK) { |
240 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 | 244 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 |
241 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 245 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
242 | Uri contentUri = FileProvider.getUriForFile(this, | 246 | Uri contentUri = FileProvider.getUriForFile(this, |
243 | this.getPackageName() + ".fileprovider", tempFile); | 247 | this.getPackageName() + ".fileprovider", tempFile); |
244 | cropPhoto(contentUri); | 248 | cropPhoto(contentUri); |
245 | } else { | 249 | } else { |
246 | cropPhoto(Uri.fromFile(tempFile)); | 250 | cropPhoto(Uri.fromFile(tempFile)); |
247 | } | 251 | } |
248 | } | 252 | } |
249 | } else if (requestCode == ALBUM_REQUEST_CODE) { | 253 | } else if (requestCode == ALBUM_REQUEST_CODE) { |
250 | if (resultCode == RESULT_OK) { | 254 | if (resultCode == RESULT_OK) { |
251 | Uri uri = intent.getData(); | 255 | Uri uri = intent.getData(); |
252 | cropPhoto(uri); | 256 | cropPhoto(uri); |
253 | } | 257 | } |
254 | } else if (requestCode == CROP_REQUEST_CODE) { | 258 | } else if (requestCode == CROP_REQUEST_CODE) { |
255 | if (intent == null) { | 259 | if (intent == null) { |
256 | return; | 260 | return; |
257 | } | 261 | } |
258 | Bundle bundle = intent.getExtras(); | 262 | Bundle bundle = intent.getExtras(); |
259 | if (bundle != null) { | 263 | if (bundle != null) { |
260 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 | 264 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 |
261 | Bitmap image = bundle.getParcelable("data"); | 265 | Bitmap image = bundle.getParcelable("data"); |
262 | //设置到ImageView上 | 266 | //设置到ImageView上 |
263 | //也可以进行一些保存、压缩等操作后上传 | 267 | //也可以进行一些保存、压缩等操作后上传 |
264 | File file = saveImage("head_output", image); | 268 | File file = saveImage("head_output", image); |
265 | uploadAvatar(file); | 269 | uploadAvatar(file); |
266 | // Log.d("dsadsadsa",path); | 270 | // Log.d("dsadsadsa",path); |
267 | } | 271 | } |
268 | } | 272 | } |
269 | } | 273 | } |
270 | 274 | ||
271 | private void uploadAvatar(File file) { | 275 | private void uploadAvatar(File file) { |
272 | NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() { | 276 | NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() { |
273 | @Override | 277 | @Override |
274 | public void onSubscribe(Disposable d) { | 278 | public void onSubscribe(Disposable d) { |
275 | 279 | ||
276 | } | 280 | } |
277 | 281 | ||
278 | @Override | 282 | @Override |
279 | public void onNext(ResponseResult<Map<String, String>> responseBody) { | 283 | public void onNext(ResponseResult<Map<String, String>> responseBody) { |
280 | if (responseBody.getData() != null && responseBody.getCode() == 200) { | 284 | if (responseBody.getData() != null && responseBody.getCode() == 200) { |
281 | String filePath = responseBody.getData().get("imageUrl"); | 285 | String filePath = responseBody.getData().get("imageUrl"); |
282 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45)); | 286 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45)); |
283 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 287 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
284 | Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar); | 288 | Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar); |
285 | } | 289 | } |
286 | } | 290 | } |
287 | 291 | ||
288 | @Override | 292 | @Override |
289 | public void onError(Throwable e) { | 293 | public void onError(Throwable e) { |
290 | e.toString(); | 294 | e.toString(); |
291 | } | 295 | } |
292 | 296 | ||
293 | @Override | 297 | @Override |
294 | public void onComplete() { | 298 | public void onComplete() { |
295 | 299 | ||
296 | } | 300 | } |
297 | }); | 301 | }); |
298 | } | 302 | } |
299 | 303 | ||
300 | public File saveImage(String name, Bitmap bmp) { | 304 | public File saveImage(String name, Bitmap bmp) { |
301 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); | 305 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); |
302 | if (!appDir.exists()) { | 306 | if (!appDir.exists()) { |
303 | appDir.mkdir(); | 307 | appDir.mkdir(); |
304 | } | 308 | } |
305 | String fileName = name + ".jpg"; | 309 | String fileName = name + ".jpg"; |
306 | File file = new File(appDir, fileName); | 310 | File file = new File(appDir, fileName); |
307 | try { | 311 | try { |
308 | FileOutputStream fos = new FileOutputStream(file); | 312 | FileOutputStream fos = new FileOutputStream(file); |
309 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); | 313 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); |
310 | fos.flush(); | 314 | fos.flush(); |
311 | fos.close(); | 315 | fos.close(); |
312 | return file; | 316 | return file; |
313 | } catch (IOException e) { | 317 | } catch (IOException e) { |
314 | Log.d("dsadsadsa", e.getLocalizedMessage()); | 318 | Log.d("dsadsadsa", e.getLocalizedMessage()); |
315 | e.printStackTrace(); | 319 | e.printStackTrace(); |
316 | } | 320 | } |
317 | return null; | 321 | return null; |
318 | } | 322 | } |
319 | 323 | ||
320 | private void getPicFromCamera() { | 324 | private void getPicFromCamera() { |
321 | //用于保存调用相机拍照后所生成的文件 | 325 | //用于保存调用相机拍照后所生成的文件 |
322 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); | 326 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); |
323 | //跳转到调用系统相机 | 327 | //跳转到调用系统相机 |
324 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 328 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
325 | //判断版本 | 329 | //判断版本 |
326 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri | 330 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri |
327 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 331 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
328 | Uri contentUri = FileProvider.getUriForFile(this, | 332 | Uri contentUri = FileProvider.getUriForFile(this, |
329 | this.getPackageName() + ".fileprovider", tempFile); | 333 | this.getPackageName() + ".fileprovider", tempFile); |
330 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); | 334 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); |
331 | } else { //否则使用Uri.fromFile(file)方法获取Uri | 335 | } else { //否则使用Uri.fromFile(file)方法获取Uri |
332 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); | 336 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); |
333 | } | 337 | } |
334 | startActivityForResult(intent, CAMERA_REQUEST_CODE); | 338 | startActivityForResult(intent, CAMERA_REQUEST_CODE); |
335 | } | 339 | } |
336 | 340 | ||
337 | /** | 341 | /** |
338 | * 从相册获取图片 | 342 | * 从相册获取图片 |
339 | */ | 343 | */ |
340 | private void getPicFromAlbm() { | 344 | private void getPicFromAlbm() { |
341 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 345 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
342 | photoPickerIntent.setType("image/*"); | 346 | photoPickerIntent.setType("image/*"); |
343 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); | 347 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); |
344 | } | 348 | } |
345 | 349 | ||
346 | @Override | 350 | @Override |
347 | protected void onDestroy() { | 351 | protected void onDestroy() { |
348 | super.onDestroy(); | 352 | super.onDestroy(); |
349 | SharedPreferencesUtil.putData("setName", ""); | 353 | SharedPreferencesUtil.putData("setName", ""); |
350 | SharedPreferencesUtil.putData("setSex", ""); | 354 | SharedPreferencesUtil.putData("setSex", ""); |
351 | SharedPreferencesUtil.putData("setNian", ""); | 355 | SharedPreferencesUtil.putData("setNian", ""); |
352 | SharedPreferencesUtil.putData("setShen", ""); | 356 | SharedPreferencesUtil.putData("setShen", ""); |
353 | SharedPreferencesUtil.putData("setXueq", ""); | 357 | SharedPreferencesUtil.putData("setXueq", ""); |
354 | SharedPreferencesUtil.putData("grade", 0); | 358 | SharedPreferencesUtil.putData("grade", 0); |
355 | } | 359 | } |
356 | 360 | ||
357 | @OnClick(R.id.iv_avatar) | 361 | @OnClick(R.id.iv_avatar) |
358 | public void showButtonDialog(View view) { | 362 | public void showButtonDialog(View view) { |
359 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); | 363 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); |
360 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); | 364 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); |
361 | dialog.setContentView(bottomView); | 365 | dialog.setContentView(bottomView); |
362 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 366 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
363 | @Override | 367 | @Override |
364 | public void onClick(View view) { | 368 | public void onClick(View view) { |
365 | dialog.dismiss(); | 369 | dialog.dismiss(); |
366 | getPicFromCamera(); | 370 | if (!XXPermissions.isGranted(EditStudentActivity.this, Permission.CAMERA)) { |
371 | XXPermissions.with(EditStudentActivity.this) | ||
372 | // 申请多个权限 | ||
373 | .permission(Permission.CAMERA) | ||
374 | .request(new OnPermissionCallback() { | ||
375 | @Override | ||
376 | public void onGranted(List<String> permissions, boolean all) { | ||
377 | if (all) { | ||
378 | //开启扫码界面 | ||
379 | getPicFromCamera(); | ||
380 | } else { | ||
381 | Toast.makeText(EditStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | ||
382 | } | ||
383 | } | ||
384 | |||
385 | @Override | ||
386 | public void onDenied(List<String> permissions, boolean never) { | ||
387 | XXPermissions.startPermissionActivity(EditStudentActivity.this, permissions); | ||
388 | } | ||
389 | }); | ||
390 | } else { | ||
391 | getPicFromCamera(); | ||
392 | } | ||
393 | |||
367 | } | 394 | } |
368 | }); | 395 | }); |
369 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 396 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
370 | @Override | 397 | @Override |
371 | public void onClick(View view) { | 398 | public void onClick(View view) { |
372 | dialog.dismiss(); | 399 | dialog.dismiss(); |
373 | getPicFromAlbm(); | 400 | getPicFromAlbm(); |
374 | } | 401 | } |
375 | }); | 402 | }); |
376 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 403 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
377 | @Override | 404 | @Override |
378 | public void onClick(View view) { | 405 | public void onClick(View view) { |
379 | dialog.dismiss(); | 406 | dialog.dismiss(); |
380 | } | 407 | } |
381 | }); | 408 | }); |
382 | dialog.show(); | 409 | dialog.show(); |
383 | } | 410 | } |
384 | } | 411 | } |
385 | 412 |
app/src/main/java/com/hjx/parent/NianActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.app.AlertDialog; | 3 | import android.app.AlertDialog; |
4 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
5 | import android.view.View; | 5 | import android.view.View; |
6 | import android.widget.TextView; | 6 | import android.widget.TextView; |
7 | import android.widget.Toast; | 7 | import android.widget.Toast; |
8 | 8 | ||
9 | import com.google.gson.Gson; | 9 | import com.google.gson.Gson; |
10 | import com.prws.common.bean.GradeAndSubject; | 10 | import com.prws.common.bean.GradeAndSubject; |
11 | import com.prws.common.base.BaseActivity; | 11 | import com.prws.common.base.BaseActivity; |
12 | import com.prws.common.base.BasePresenter; | 12 | import com.prws.common.base.BasePresenter; |
13 | import com.prws.common.bean.ResponseResult; | 13 | import com.prws.common.bean.ResponseResult; |
14 | import com.prws.common.net.NetWorks; | 14 | import com.prws.common.net.NetWorks; |
15 | import com.prws.common.utils.SharedPreferencesUtil; | 15 | import com.prws.common.utils.SharedPreferencesUtil; |
16 | 16 | ||
17 | import java.io.IOException; | 17 | import java.io.IOException; |
18 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | 20 | ||
21 | import butterknife.BindView; | 21 | import butterknife.BindView; |
22 | import butterknife.OnClick; | 22 | import butterknife.OnClick; |
23 | import io.reactivex.Observer; | 23 | import io.reactivex.Observer; |
24 | import io.reactivex.disposables.Disposable; | 24 | import io.reactivex.disposables.Disposable; |
25 | import okhttp3.ResponseBody; | 25 | import okhttp3.ResponseBody; |
26 | 26 | ||
27 | public class NianActivity extends BaseActivity { | 27 | public class NianActivity extends BaseActivity { |
28 | @Override | 28 | @Override |
29 | protected int layoutResId() { | 29 | protected int layoutResId() { |
30 | return R.layout.activity_set_nian; | 30 | return R.layout.activity_set_nian; |
31 | } | 31 | } |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | public Object getContract() { | 34 | public Object getContract() { |
35 | return null; | 35 | return null; |
36 | } | 36 | } |
37 | 37 | ||
38 | @Override | 38 | @Override |
39 | public BasePresenter getPresenter() { | 39 | public BasePresenter getPresenter() { |
40 | return null; | 40 | return null; |
41 | } | 41 | } |
42 | 42 | ||
43 | @BindView(R.id.tv_nian) | 43 | @BindView(R.id.tv_nian) |
44 | TextView tv_nian; | 44 | TextView tv_nian; |
45 | @BindView(R.id.tv_xq) | 45 | @BindView(R.id.tv_xq) |
46 | TextView tv_xq; | 46 | TextView tv_xq; |
47 | private int gradeId; | 47 | private int gradeId; |
48 | List<GradeAndSubject> list; | ||
48 | 49 | ||
49 | @Override | 50 | @Override |
50 | protected void initView() { | 51 | protected void initView() { |
51 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); | 52 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); |
52 | findViewById(R.id.tv_ok).setOnClickListener(view -> { | 53 | findViewById(R.id.tv_ok).setOnClickListener(view -> { |
53 | SharedPreferencesUtil.putData("setNian", tv_nian.getText()); | 54 | SharedPreferencesUtil.putData("setNian", tv_nian.getText()); |
54 | SharedPreferencesUtil.putData("setXueq", tv_xq.getText()); | 55 | SharedPreferencesUtil.putData("setXueq", tv_xq.getText()); |
55 | SharedPreferencesUtil.putData("grade", gradeId); | 56 | SharedPreferencesUtil.putData("grade", gradeId); |
56 | finish(); | 57 | finish(); |
57 | }); | 58 | }); |
59 | getGradeAndSubject(); | ||
58 | } | 60 | } |
59 | 61 | ||
60 | @OnClick(R.id.view_3) | 62 | @OnClick(R.id.view_3) |
61 | public void changeTerm(View view) { | 63 | public void changeTerm(View view) { |
62 | String[] strings = {"上学期", "下学期"}; | 64 | String[] strings = {"上学期", "下学期"}; |
63 | AlertDialog.Builder builder = new AlertDialog.Builder(NianActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | 65 | AlertDialog.Builder builder = new AlertDialog.Builder(NianActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
64 | builder.setTitle("请选择学期"); | 66 | builder.setTitle("请选择学期"); |
65 | builder.setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() { | 67 | builder.setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() { |
66 | @Override | 68 | @Override |
67 | public void onClick(DialogInterface dialogInterface, int i) { | 69 | public void onClick(DialogInterface dialogInterface, int i) { |
68 | tv_xq.setText(strings[i]); | 70 | tv_xq.setText(strings[i]); |
69 | dialogInterface.dismiss(); | 71 | dialogInterface.dismiss(); |
70 | } | 72 | } |
71 | }); | 73 | }); |
72 | builder.setCancelable(false); | 74 | builder.setCancelable(false); |
73 | builder.show(); | 75 | builder.show(); |
74 | } | 76 | } |
75 | 77 | ||
78 | |||
76 | @OnClick(R.id.view_2) | 79 | @OnClick(R.id.view_2) |
77 | public void getGradeAndSubject(View view) { | 80 | public void showGradeDialog(View view) { |
81 | if (list!=null&&list.size() > 0) { | ||
82 | |||
83 | } else { | ||
84 | getGradeAndSubject(); | ||
85 | } | ||
86 | List<String> stringList = new ArrayList<>(); | ||
87 | for (GradeAndSubject gradeAndSubject : list) { | ||
88 | stringList.add(gradeAndSubject.getGrade().getGrade()); | ||
89 | } | ||
90 | String[] strings = stringList.toArray(new String[stringList.size()]); | ||
91 | AlertDialog.Builder builder = new AlertDialog.Builder(NianActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | ||
92 | builder.setTitle("请选择年级"); | ||
93 | builder.setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() { | ||
94 | @Override | ||
95 | public void onClick(DialogInterface dialogInterface, int i) { | ||
96 | tv_nian.setText(list.get(i).getGrade().getGrade()); | ||
97 | gradeId = list.get(i).getGrade().getId(); | ||
98 | dialogInterface.dismiss(); | ||
99 | } | ||
100 | }); | ||
101 | builder.setCancelable(false); | ||
102 | builder.show(); | ||
103 | } | ||
104 | |||
105 | public void getGradeAndSubject() { | ||
78 | NetWorks.listGradeAndSubject(new Observer<ResponseResult<List<GradeAndSubject>>>() { | 106 | NetWorks.listGradeAndSubject(new Observer<ResponseResult<List<GradeAndSubject>>>() { |
79 | @Override | 107 | @Override |
80 | public void onSubscribe(Disposable d) { | 108 | public void onSubscribe(Disposable d) { |
81 | 109 | ||
82 | } | 110 | } |
83 | 111 | ||
84 | @Override | 112 | @Override |
85 | public void onNext(ResponseResult<List<GradeAndSubject>> listResponseResult) { | 113 | public void onNext(ResponseResult<List<GradeAndSubject>> listResponseResult) { |
86 | if (listResponseResult != null && listResponseResult.getCode() == 200) { | 114 | if (listResponseResult != null && listResponseResult.getCode() == 200) { |
87 | List<GradeAndSubject> list = listResponseResult.getData(); | 115 | list = listResponseResult.getData(); |
88 | List<String> stringList = new ArrayList<>(); | 116 | tv_nian.setText(list.get(0).getGrade().getGrade()); |
89 | for (GradeAndSubject gradeAndSubject : list) { | 117 | gradeId = list.get(0).getGrade().getId(); |
90 | stringList.add(gradeAndSubject.getGrade().getGrade()); | ||
91 | } | ||
92 | String[] strings = stringList.toArray(new String[stringList.size()]); | ||
93 | AlertDialog.Builder builder = new AlertDialog.Builder(NianActivity.this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | ||
94 | builder.setTitle("请选择年级"); | ||
95 | builder.setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() { | ||
96 | @Override | ||
97 | public void onClick(DialogInterface dialogInterface, int i) { | ||
98 | tv_nian.setText(list.get(i).getGrade().getGrade()); | ||
99 | gradeId = list.get(i).getGrade().getId(); | ||
100 | dialogInterface.dismiss(); | ||
101 | } | ||
102 | }); | ||
103 | builder.setCancelable(false); | ||
104 | builder.show(); | ||
105 | } | 118 | } |
106 | } | 119 | } |
107 | 120 | ||
108 | @Override | 121 | @Override |
109 | public void onError(Throwable e) { | 122 | public void onError(Throwable e) { |
110 | e.toString(); | 123 | e.toString(); |
111 | } | 124 | } |
112 | 125 | ||
113 | @Override | 126 | @Override |
114 | public void onComplete() { | 127 | public void onComplete() { |
115 | 128 | ||
116 | } | 129 | } |
117 | }); | 130 | }); |
118 | } | 131 | } |
119 | 132 | ||
120 | @Override | 133 | @Override |
app/src/main/java/com/hjx/parent/RegisterActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.telephony.PhoneNumberUtils; | 5 | import android.telephony.PhoneNumberUtils; |
6 | import android.text.InputType; | 6 | import android.text.InputType; |
7 | import android.widget.Button; | 7 | import android.widget.Button; |
8 | import android.widget.CheckBox; | 8 | import android.widget.CheckBox; |
9 | import android.widget.EditText; | 9 | import android.widget.EditText; |
10 | import android.widget.ImageView; | 10 | import android.widget.ImageView; |
11 | import android.widget.TextView; | 11 | import android.widget.TextView; |
12 | import android.widget.Toast; | 12 | import android.widget.Toast; |
13 | 13 | ||
14 | import androidx.annotation.Nullable; | 14 | import androidx.annotation.Nullable; |
15 | 15 | ||
16 | import com.google.gson.Gson; | 16 | import com.google.gson.Gson; |
17 | import com.hjq.permissions.OnPermissionCallback; | 17 | import com.hjq.permissions.OnPermissionCallback; |
18 | import com.hjq.permissions.Permission; | 18 | import com.hjq.permissions.Permission; |
19 | import com.hjq.permissions.XXPermissions; | 19 | import com.hjq.permissions.XXPermissions; |
20 | import com.hjx.parent.bean.RegisterBean; | 20 | import com.hjx.parent.bean.RegisterBean; |
21 | import com.prws.common.base.BaseActivity; | 21 | import com.prws.common.base.BaseActivity; |
22 | import com.prws.common.base.BasePresenter; | 22 | import com.prws.common.base.BasePresenter; |
23 | import com.prws.common.bean.BaseEntity; | 23 | import com.prws.common.bean.BaseEntity; |
24 | import com.prws.common.net.NetWorks; | 24 | import com.prws.common.net.NetWorks; |
25 | import com.prws.common.utils.Common; | ||
25 | import com.prws.common.utils.GsonUtil; | 26 | import com.prws.common.utils.GsonUtil; |
26 | import com.prws.common.utils.LogUtil; | 27 | import com.prws.common.utils.LogUtil; |
27 | import com.prws.common.utils.SharedPreferencesUtil; | 28 | import com.prws.common.utils.SharedPreferencesUtil; |
28 | import com.uuzuche.lib_zxing.activity.CaptureActivity; | 29 | import com.uuzuche.lib_zxing.activity.CaptureActivity; |
29 | import com.uuzuche.lib_zxing.activity.CodeUtils; | 30 | import com.uuzuche.lib_zxing.activity.CodeUtils; |
30 | 31 | ||
31 | import org.json.JSONObject; | 32 | import org.json.JSONObject; |
32 | 33 | ||
33 | import java.io.IOException; | 34 | import java.io.IOException; |
34 | import java.util.HashMap; | 35 | import java.util.HashMap; |
35 | import java.util.List; | 36 | import java.util.List; |
36 | import java.util.Map; | 37 | import java.util.Map; |
37 | 38 | ||
38 | import io.reactivex.Observer; | 39 | import io.reactivex.Observer; |
39 | import io.reactivex.disposables.Disposable; | 40 | import io.reactivex.disposables.Disposable; |
40 | import okhttp3.ResponseBody; | 41 | import okhttp3.ResponseBody; |
41 | 42 | ||
42 | public class RegisterActivity extends BaseActivity { | 43 | public class RegisterActivity extends BaseActivity { |
43 | 44 | ||
44 | EditText et_phone; | 45 | EditText et_phone; |
45 | EditText et_pwd; | 46 | EditText et_pwd; |
46 | EditText et_pwd_2; | 47 | EditText et_pwd_2; |
47 | ImageView iv_show; | 48 | ImageView iv_show; |
48 | ImageView iv_show_2; | 49 | ImageView iv_show_2; |
49 | ImageView iv_delete; | 50 | ImageView iv_delete; |
50 | Button btn_reg; | 51 | Button btn_reg; |
51 | TextView tv_log; | 52 | TextView tv_log; |
52 | CheckBox cb_1; | 53 | CheckBox cb_1; |
53 | TextView tv_user; | 54 | TextView tv_user; |
54 | TextView tv_ys; | 55 | TextView tv_ys; |
55 | 56 | ||
56 | 57 | ||
57 | @Override | 58 | @Override |
58 | protected int layoutResId() { | 59 | protected int layoutResId() { |
59 | return R.layout.activity_register; | 60 | return R.layout.activity_register; |
60 | } | 61 | } |
61 | 62 | ||
62 | @Override | 63 | @Override |
63 | public Object getContract() { | 64 | public Object getContract() { |
64 | return null; | 65 | return null; |
65 | } | 66 | } |
66 | 67 | ||
67 | @Override | 68 | @Override |
68 | public BasePresenter getPresenter() { | 69 | public BasePresenter getPresenter() { |
69 | return null; | 70 | return null; |
70 | } | 71 | } |
71 | 72 | ||
72 | @Override | 73 | @Override |
73 | protected void initView() { | 74 | protected void initView() { |
74 | et_phone = findViewById(R.id.et_phone); | 75 | et_phone = findViewById(R.id.et_phone); |
75 | et_pwd = findViewById(R.id.et_pwd); | 76 | et_pwd = findViewById(R.id.et_pwd); |
76 | iv_show = findViewById(R.id.iv_4); | 77 | iv_show = findViewById(R.id.iv_4); |
77 | iv_show_2 = findViewById(R.id.iv_6); | 78 | iv_show_2 = findViewById(R.id.iv_6); |
78 | et_pwd_2 = findViewById(R.id.et_pwd_2); | 79 | et_pwd_2 = findViewById(R.id.et_pwd_2); |
79 | iv_delete = findViewById(R.id.iv_2); | 80 | iv_delete = findViewById(R.id.iv_2); |
80 | btn_reg = findViewById(R.id.btn_1); | 81 | btn_reg = findViewById(R.id.btn_1); |
81 | tv_log = findViewById(R.id.tv_2); | 82 | tv_log = findViewById(R.id.tv_2); |
82 | cb_1 = findViewById(R.id.cb_1); | 83 | cb_1 = findViewById(R.id.cb_1); |
83 | tv_user = findViewById(R.id.tv_4); | 84 | tv_user = findViewById(R.id.tv_4); |
84 | tv_ys = findViewById(R.id.tv_6); | 85 | tv_ys = findViewById(R.id.tv_6); |
85 | 86 | ||
86 | 87 | ||
87 | } | 88 | } |
88 | 89 | ||
89 | @Override | 90 | @Override |
90 | protected void initListener() { | 91 | protected void initListener() { |
91 | iv_delete.setOnClickListener(view -> { | 92 | iv_delete.setOnClickListener(view -> { |
92 | et_phone.setText(""); | 93 | et_phone.setText(""); |
93 | }); | 94 | }); |
94 | iv_show.setOnClickListener(view -> { | 95 | iv_show.setOnClickListener(view -> { |
95 | 96 | ||
96 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { | 97 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { |
97 | iv_show.setBackgroundResource(R.mipmap.yc); | 98 | iv_show.setBackgroundResource(R.mipmap.yc); |
98 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | 99 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
99 | } else { | 100 | } else { |
100 | iv_show.setBackgroundResource(R.mipmap.xs); | 101 | iv_show.setBackgroundResource(R.mipmap.xs); |
101 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | 102 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
105 | }); | 106 | }); |
106 | 107 | ||
107 | iv_show_2.setOnClickListener(view -> { | 108 | iv_show_2.setOnClickListener(view -> { |
108 | 109 | ||
109 | if (iv_show_2.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { | 110 | if (iv_show_2.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { |
110 | iv_show_2.setBackgroundResource(R.mipmap.yc); | 111 | iv_show_2.setBackgroundResource(R.mipmap.yc); |
111 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | 112 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
112 | } else { | 113 | } else { |
113 | iv_show_2.setBackgroundResource(R.mipmap.xs); | 114 | iv_show_2.setBackgroundResource(R.mipmap.xs); |
114 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | 115 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
115 | } | 116 | } |
116 | 117 | ||
117 | 118 | ||
118 | }); | 119 | }); |
119 | 120 | ||
120 | 121 | ||
121 | btn_reg.setOnClickListener(view -> { | 122 | btn_reg.setOnClickListener(view -> { |
122 | 123 | ||
123 | String phone = et_phone.getText().toString().trim(); | 124 | String phone = et_phone.getText().toString().trim(); |
124 | String pwd = et_pwd.getText().toString().trim(); | 125 | String pwd = et_pwd.getText().toString().trim(); |
125 | String pwd2 = et_pwd_2.getText().toString().trim(); | 126 | String pwd2 = et_pwd_2.getText().toString().trim(); |
126 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { | 127 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { |
127 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); | 128 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); |
128 | return; | 129 | return; |
129 | } | 130 | } |
131 | if (pwd.length() < 6 || pwd.length() > 16 || pwd2.length() < 6 || pwd2.length() > 16) { | ||
132 | Toast.makeText(this, "密码必须为6-16位,数字或字母", Toast.LENGTH_SHORT).show(); | ||
133 | } | ||
134 | if (!Common.isValidPhoneNumber(phone)) { | ||
135 | Toast.makeText(this, "请输入有效手机号", Toast.LENGTH_SHORT).show(); | ||
136 | return; | ||
137 | } | ||
130 | 138 | ||
131 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { | 139 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { |
132 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); | 140 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); |
133 | return; | 141 | return; |
134 | } | 142 | } |
135 | 143 | ||
136 | if (!cb_1.isChecked()) { | 144 | if (!cb_1.isChecked()) { |
137 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); | 145 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); |
138 | return; | 146 | return; |
139 | } | 147 | } |
140 | if (!pwd.equals(pwd2)) { | 148 | if (!pwd.equals(pwd2)) { |
141 | Toast.makeText(this, "两次密码需要一致", Toast.LENGTH_SHORT).show(); | 149 | Toast.makeText(this, "两次密码需要一致", Toast.LENGTH_SHORT).show(); |
142 | return; | 150 | return; |
143 | } | 151 | } |
144 | 152 | ||
145 | reg(phone, pwd); | 153 | reg(phone, pwd); |
146 | 154 | ||
147 | }); | 155 | }); |
148 | 156 | ||
149 | tv_log.setOnClickListener(view -> { | 157 | tv_log.setOnClickListener(view -> { |
150 | startActivity(LoginActivity.class); | 158 | startActivity(LoginActivity.class); |
151 | finish(); | 159 | finish(); |
152 | }); | 160 | }); |
153 | 161 | ||
154 | tv_ys.setOnClickListener(view -> { | 162 | tv_ys.setOnClickListener(view -> { |
155 | startActivity(YinsiActivity.class); | 163 | startActivity(YinsiActivity.class); |
156 | }); | 164 | }); |
157 | tv_user.setOnClickListener(view -> { | 165 | tv_user.setOnClickListener(view -> { |
158 | startActivity(UserActivity.class); | 166 | startActivity(UserActivity.class); |
159 | }); | 167 | }); |
160 | } | 168 | } |
161 | 169 | ||
162 | public void reg(final String phone, String pwd) { | 170 | public void reg(final String phone, String pwd) { |
163 | 171 | ||
164 | Map map = new HashMap(); | 172 | Map map = new HashMap(); |
165 | map.put("username", phone); | 173 | map.put("username", phone); |
166 | map.put("password", pwd); | 174 | map.put("password", pwd); |
167 | 175 | ||
168 | 176 | ||
169 | NetWorks.registerParent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 177 | NetWorks.registerParent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
170 | @Override | 178 | @Override |
171 | public void onSubscribe(Disposable d) { | 179 | public void onSubscribe(Disposable d) { |
172 | 180 | ||
173 | } | 181 | } |
174 | 182 | ||
175 | @Override | 183 | @Override |
176 | public void onNext(ResponseBody responseBody) { | 184 | public void onNext(ResponseBody responseBody) { |
177 | String str = null; | 185 | String str = null; |
178 | try { | 186 | try { |
179 | str = responseBody.string(); | 187 | str = responseBody.string(); |
180 | } catch (IOException e) { | 188 | } catch (IOException e) { |
181 | e.printStackTrace(); | 189 | e.printStackTrace(); |
182 | } | 190 | } |
183 | 191 | ||
184 | if (str == null || str.length() == 0) { | 192 | if (str == null || str.length() == 0) { |
185 | Toast.makeText(RegisterActivity.this, "服务器繁忙", Toast.LENGTH_SHORT).show(); | 193 | Toast.makeText(RegisterActivity.this, "服务器繁忙", Toast.LENGTH_SHORT).show(); |
186 | return; | 194 | return; |
187 | } | 195 | } |
188 | 196 | ||
189 | RegisterBean registerBean = new Gson().fromJson(str, RegisterBean.class); | 197 | RegisterBean registerBean = new Gson().fromJson(str, RegisterBean.class); |
190 | 198 | ||
191 | if (!registerBean.isSuccess()) { | 199 | if (!registerBean.isSuccess()) { |
192 | Toast.makeText(RegisterActivity.this, registerBean.getMsg(), Toast.LENGTH_SHORT).show(); | 200 | Toast.makeText(RegisterActivity.this, registerBean.getMsg(), Toast.LENGTH_SHORT).show(); |
193 | return; | 201 | return; |
194 | } | 202 | } |
195 | 203 | ||
196 | if (registerBean.getData().getUserName() != null && registerBean.getData().getUserName().length() > 0) { | 204 | if (registerBean.getData().getUserName() != null && registerBean.getData().getUserName().length() > 0) { |
197 | SharedPreferencesUtil.putData("phone", phone); | 205 | SharedPreferencesUtil.putData("phone", phone); |
198 | SharedPreferencesUtil.putData("role", registerBean.getData().getUserName()); | 206 | SharedPreferencesUtil.putData("role", registerBean.getData().getUserName()); |
199 | SharedPreferencesUtil.putData("userId", registerBean.getData().getUserName()); | 207 | SharedPreferencesUtil.putData("userId", registerBean.getData().getUserName()); |
200 | login(phone, pwd); | 208 | login(phone, pwd); |
201 | 209 | ||
202 | } | 210 | } |
203 | 211 | ||
204 | 212 | ||
205 | } | 213 | } |
206 | 214 | ||
207 | @Override | 215 | @Override |
208 | public void onError(Throwable e) { | 216 | public void onError(Throwable e) { |
209 | 217 | ||
210 | } | 218 | } |
211 | 219 | ||
212 | @Override | 220 | @Override |
213 | public void onComplete() { | 221 | public void onComplete() { |
214 | 222 | ||
215 | } | 223 | } |
216 | }); | 224 | }); |
217 | } | 225 | } |
218 | 226 | ||
219 | public void login(final String phone, String pwd) { | 227 | public void login(final String phone, String pwd) { |
220 | Map map = new HashMap(); | 228 | Map map = new HashMap(); |
221 | map.put("username", phone); | 229 | map.put("username", phone); |
222 | map.put("password", pwd); | 230 | map.put("password", pwd); |
223 | 231 | ||
224 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 232 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
225 | @Override | 233 | @Override |
226 | public void onSubscribe(Disposable d) { | 234 | public void onSubscribe(Disposable d) { |
227 | 235 | ||
228 | } | 236 | } |
229 | 237 | ||
230 | @Override | 238 | @Override |
231 | public void onNext(ResponseBody responseBody) { | 239 | public void onNext(ResponseBody responseBody) { |
232 | try { | 240 | try { |
233 | String str = responseBody.string().toString(); | 241 | String str = responseBody.string().toString(); |
234 | LogUtil.e(TAG, "----" + str); | 242 | LogUtil.e(TAG, "----" + str); |
235 | JSONObject jo = new JSONObject(str); | 243 | JSONObject jo = new JSONObject(str); |
236 | boolean isSucceed = jo.getBoolean("success"); | 244 | boolean isSucceed = jo.getBoolean("success"); |
237 | if (isSucceed) { | 245 | if (isSucceed) { |
238 | JSONObject jo2 = jo.getJSONObject("data"); | 246 | JSONObject jo2 = jo.getJSONObject("data"); |
239 | SharedPreferencesUtil.putData("phone", phone); | 247 | SharedPreferencesUtil.putData("phone", phone); |
240 | SharedPreferencesUtil.putData("role", jo2.getString("role")); | 248 | SharedPreferencesUtil.putData("role", jo2.getString("role")); |
241 | SharedPreferencesUtil.putData("userId", jo2.getString("userId")); | 249 | SharedPreferencesUtil.putData("userId", jo2.getString("userId")); |
242 | SharedPreferencesUtil.putData("token", jo2.getString("token")); | 250 | SharedPreferencesUtil.putData("token", jo2.getString("token")); |
243 | startActivity(ChooseActivity.class); | 251 | startActivity(ChooseActivity.class); |
244 | } else { | 252 | } else { |
245 | Toast.makeText(RegisterActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 253 | Toast.makeText(RegisterActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
246 | } | 254 | } |
247 | } catch (Exception e) { | 255 | } catch (Exception e) { |
248 | e.printStackTrace(); | 256 | e.printStackTrace(); |
249 | Toast.makeText(RegisterActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 257 | Toast.makeText(RegisterActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
250 | } | 258 | } |
251 | 259 | ||
252 | } | 260 | } |
253 | 261 | ||
254 | @Override | 262 | @Override |
255 | public void onError(Throwable e) { | 263 | public void onError(Throwable e) { |
256 | 264 | ||
257 | } | 265 | } |
258 | 266 | ||
259 | @Override | 267 | @Override |
260 | public void onComplete() { | 268 | public void onComplete() { |
261 | 269 | ||
262 | } | 270 | } |
263 | }); | 271 | }); |
264 | } | 272 | } |
265 | 273 | ||
266 | public void goQRView() { | 274 | public void goQRView() { |
267 | 275 | ||
268 | if (!XXPermissions.isGranted(this, Permission.CAMERA)) { | 276 | if (!XXPermissions.isGranted(this, Permission.CAMERA)) { |
269 | XXPermissions.with(this) | 277 | XXPermissions.with(this) |
270 | // 申请多个权限 | 278 | // 申请多个权限 |
271 | .permission(Permission.CAMERA) | 279 | .permission(Permission.CAMERA) |
272 | .request(new OnPermissionCallback() { | 280 | .request(new OnPermissionCallback() { |
273 | @Override | 281 | @Override |
274 | public void onGranted(List<String> permissions, boolean all) { | 282 | public void onGranted(List<String> permissions, boolean all) { |
275 | if (all) { | 283 | if (all) { |
276 | //开启扫码界面 | 284 | //开启扫码界面 |
277 | startQRView(); | 285 | startQRView(); |
278 | 286 | ||
279 | } else { | 287 | } else { |
280 | Toast.makeText(RegisterActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | 288 | Toast.makeText(RegisterActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); |
281 | } | 289 | } |
282 | } | 290 | } |
283 | 291 | ||
284 | @Override | 292 | @Override |
285 | public void onDenied(List<String> permissions, boolean never) { | 293 | public void onDenied(List<String> permissions, boolean never) { |
286 | XXPermissions.startPermissionActivity(RegisterActivity.this, permissions); | 294 | XXPermissions.startPermissionActivity(RegisterActivity.this, permissions); |
287 | } | 295 | } |
288 | }); | 296 | }); |
289 | 297 | ||
290 | 298 | ||
291 | } else { | 299 | } else { |
292 | startQRView(); | 300 | startQRView(); |
293 | } | 301 | } |
294 | 302 | ||
295 | 303 | ||
296 | } | 304 | } |
297 | 305 | ||
298 | public void startQRView() { | 306 | public void startQRView() { |
299 | 307 | ||
300 | startActivity(QRActivity.class); | 308 | startActivity(QRActivity.class); |
301 | finish(); | 309 | finish(); |
302 | 310 | ||
303 | } | 311 | } |
304 | 312 | ||
305 | 313 | ||
306 | @Override | 314 | @Override |
307 | protected void initData() { | 315 | protected void initData() { |
308 | 316 | ||
309 | } | 317 | } |
310 | 318 | ||
311 | @Override | 319 | @Override |
312 | public void onNetChanged(int netWorkState) { | 320 | public void onNetChanged(int netWorkState) { |
313 | 321 | ||
314 | } | 322 | } |
315 | } | 323 | } |
app/src/main/res/layout/activity_register.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 | xmlns:app="http://schemas.android.com/apk/res-auto" | 3 | xmlns:app="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="@mipmap/bg"> | 6 | android:background="@mipmap/bg"> |
7 | 7 | ||
8 | 8 | ||
9 | <TextView | 9 | <TextView |
10 | android:layout_width="wrap_content" | 10 | android:layout_width="wrap_content" |
11 | android:layout_height="wrap_content" | 11 | android:layout_height="wrap_content" |
12 | android:layout_marginLeft="30dp" | 12 | android:layout_marginLeft="30dp" |
13 | android:layout_marginTop="64dp" | 13 | android:layout_marginTop="64dp" |
14 | android:text="注册" | 14 | android:text="注册" |
15 | android:textColor="#333333" | 15 | android:textColor="#333333" |
16 | android:textSize="25dp" | 16 | android:textSize="25dp" |
17 | android:textStyle="bold" | 17 | android:textStyle="bold" |
18 | app:layout_constraintLeft_toLeftOf="parent" | 18 | app:layout_constraintLeft_toLeftOf="parent" |
19 | app:layout_constraintTop_toTopOf="parent" /> | 19 | app:layout_constraintTop_toTopOf="parent" /> |
20 | 20 | ||
21 | <View | 21 | <View |
22 | android:id="@+id/view_1" | 22 | android:id="@+id/view_1" |
23 | android:layout_width="315dp" | 23 | android:layout_width="315dp" |
24 | android:layout_height="50dp" | 24 | android:layout_height="50dp" |
25 | android:layout_marginTop="166dp" | 25 | android:layout_marginTop="166dp" |
26 | android:background="@drawable/bg_solid_white" | 26 | android:background="@drawable/bg_solid_white" |
27 | app:layout_constraintLeft_toLeftOf="parent" | 27 | app:layout_constraintLeft_toLeftOf="parent" |
28 | app:layout_constraintRight_toRightOf="parent" | 28 | app:layout_constraintRight_toRightOf="parent" |
29 | app:layout_constraintTop_toTopOf="parent" /> | 29 | app:layout_constraintTop_toTopOf="parent" /> |
30 | 30 | ||
31 | <ImageView | 31 | <ImageView |
32 | android:id="@+id/iv_1" | 32 | android:id="@+id/iv_1" |
33 | android:layout_width="16dp" | 33 | android:layout_width="16dp" |
34 | android:layout_height="18dp" | 34 | android:layout_height="18dp" |
35 | android:layout_marginLeft="20dp" | 35 | android:layout_marginLeft="20dp" |
36 | android:background="@mipmap/sjh" | 36 | android:background="@mipmap/sjh" |
37 | app:layout_constraintBottom_toBottomOf="@id/view_1" | 37 | app:layout_constraintBottom_toBottomOf="@id/view_1" |
38 | app:layout_constraintLeft_toLeftOf="@id/view_1" | 38 | app:layout_constraintLeft_toLeftOf="@id/view_1" |
39 | app:layout_constraintTop_toTopOf="@id/view_1" /> | 39 | app:layout_constraintTop_toTopOf="@id/view_1" /> |
40 | 40 | ||
41 | <ImageView | 41 | <ImageView |
42 | android:id="@+id/iv_2" | 42 | android:id="@+id/iv_2" |
43 | android:layout_width="13dp" | 43 | android:layout_width="13dp" |
44 | android:layout_height="13dp" | 44 | android:layout_height="13dp" |
45 | android:layout_marginRight="20dp" | 45 | android:layout_marginRight="20dp" |
46 | android:background="@mipmap/sc" | 46 | android:background="@mipmap/sc" |
47 | app:layout_constraintBottom_toBottomOf="@id/view_1" | 47 | app:layout_constraintBottom_toBottomOf="@id/view_1" |
48 | app:layout_constraintRight_toRightOf="@id/view_1" | 48 | app:layout_constraintRight_toRightOf="@id/view_1" |
49 | app:layout_constraintTop_toTopOf="@id/view_1" /> | 49 | app:layout_constraintTop_toTopOf="@id/view_1" /> |
50 | 50 | ||
51 | <EditText | 51 | <EditText |
52 | android:id="@+id/et_phone" | 52 | android:id="@+id/et_phone" |
53 | android:layout_width="0dp" | 53 | android:layout_width="0dp" |
54 | android:layout_height="0dp" | 54 | android:layout_height="0dp" |
55 | android:layout_marginLeft="46dp" | 55 | android:layout_marginLeft="46dp" |
56 | android:background="@android:color/transparent" | 56 | android:background="@android:color/transparent" |
57 | android:gravity="left|center_vertical" | 57 | android:gravity="left|center_vertical" |
58 | android:hint="请输入手机号" | 58 | android:hint="请输入手机号" |
59 | android:inputType="number" | 59 | android:inputType="number" |
60 | android:maxLength="11" | 60 | android:maxLength="11" |
61 | android:textColor="#333333" | 61 | android:textColor="#333333" |
62 | android:textColorHint="#999999" | 62 | android:textColorHint="#999999" |
63 | android:textSize="16dp" | 63 | android:textSize="16dp" |
64 | app:layout_constraintBottom_toBottomOf="@id/view_1" | 64 | app:layout_constraintBottom_toBottomOf="@id/view_1" |
65 | app:layout_constraintLeft_toLeftOf="@id/view_1" | 65 | app:layout_constraintLeft_toLeftOf="@id/view_1" |
66 | app:layout_constraintRight_toLeftOf="@id/iv_2" | 66 | app:layout_constraintRight_toLeftOf="@id/iv_2" |
67 | app:layout_constraintTop_toTopOf="@id/view_1" /> | 67 | app:layout_constraintTop_toTopOf="@id/view_1" /> |
68 | 68 | ||
69 | 69 | ||
70 | <View | 70 | <View |
71 | android:id="@+id/view_2" | 71 | android:id="@+id/view_2" |
72 | android:layout_width="315dp" | 72 | android:layout_width="315dp" |
73 | android:layout_height="50dp" | 73 | android:layout_height="50dp" |
74 | android:layout_marginTop="241dp" | 74 | android:layout_marginTop="241dp" |
75 | android:background="@drawable/bg_solid_white" | 75 | android:background="@drawable/bg_solid_white" |
76 | app:layout_constraintLeft_toLeftOf="parent" | 76 | app:layout_constraintLeft_toLeftOf="parent" |
77 | app:layout_constraintRight_toRightOf="parent" | 77 | app:layout_constraintRight_toRightOf="parent" |
78 | app:layout_constraintTop_toTopOf="parent" /> | 78 | app:layout_constraintTop_toTopOf="parent" /> |
79 | 79 | ||
80 | <ImageView | 80 | <ImageView |
81 | android:id="@+id/iv_3" | 81 | android:id="@+id/iv_3" |
82 | android:layout_width="16dp" | 82 | android:layout_width="16dp" |
83 | android:layout_height="18dp" | 83 | android:layout_height="18dp" |
84 | android:layout_marginLeft="20dp" | 84 | android:layout_marginLeft="20dp" |
85 | android:background="@mipmap/mm" | 85 | android:background="@mipmap/mm" |
86 | app:layout_constraintBottom_toBottomOf="@id/view_2" | 86 | app:layout_constraintBottom_toBottomOf="@id/view_2" |
87 | app:layout_constraintLeft_toLeftOf="@id/view_2" | 87 | app:layout_constraintLeft_toLeftOf="@id/view_2" |
88 | app:layout_constraintTop_toTopOf="@id/view_2" /> | 88 | app:layout_constraintTop_toTopOf="@id/view_2" /> |
89 | 89 | ||
90 | <ImageView | 90 | <ImageView |
91 | android:id="@+id/iv_4" | 91 | android:id="@+id/iv_4" |
92 | android:layout_width="20dp" | 92 | android:layout_width="20dp" |
93 | android:layout_height="16dp" | 93 | android:layout_height="16dp" |
94 | android:layout_marginRight="20dp" | 94 | android:layout_marginRight="20dp" |
95 | android:background="@mipmap/xs" | 95 | android:background="@mipmap/xs" |
96 | app:layout_constraintBottom_toBottomOf="@id/view_2" | 96 | app:layout_constraintBottom_toBottomOf="@id/view_2" |
97 | app:layout_constraintRight_toRightOf="@id/view_2" | 97 | app:layout_constraintRight_toRightOf="@id/view_2" |
98 | app:layout_constraintTop_toTopOf="@id/view_2" /> | 98 | app:layout_constraintTop_toTopOf="@id/view_2" /> |
99 | 99 | ||
100 | <EditText | 100 | <EditText |
101 | android:id="@+id/et_pwd" | 101 | android:id="@+id/et_pwd" |
102 | android:layout_width="0dp" | 102 | android:layout_width="0dp" |
103 | android:layout_height="0dp" | 103 | android:layout_height="0dp" |
104 | android:layout_marginLeft="46dp" | 104 | android:layout_marginLeft="46dp" |
105 | android:layout_marginRight="20dp" | 105 | android:layout_marginRight="20dp" |
106 | android:background="@android:color/transparent" | 106 | android:background="@android:color/transparent" |
107 | android:gravity="left|center_vertical" | 107 | android:gravity="left|center_vertical" |
108 | android:hint="请输入密码" | 108 | android:hint="请输入密码" |
109 | android:inputType="textPassword" | 109 | android:inputType="textPassword" |
110 | android:textColor="#333333" | 110 | android:textColor="#333333" |
111 | android:textColorHint="#999999" | 111 | android:textColorHint="#999999" |
112 | android:textSize="16dp" | 112 | android:textSize="16dp" |
113 | app:layout_constraintBottom_toBottomOf="@id/view_2" | 113 | app:layout_constraintBottom_toBottomOf="@id/view_2" |
114 | app:layout_constraintLeft_toLeftOf="@id/view_2" | 114 | app:layout_constraintLeft_toLeftOf="@id/view_2" |
115 | app:layout_constraintRight_toLeftOf="@id/iv_4" | 115 | app:layout_constraintRight_toLeftOf="@id/iv_4" |
116 | app:layout_constraintTop_toTopOf="@id/view_2" /> | 116 | app:layout_constraintTop_toTopOf="@id/view_2" /> |
117 | 117 | ||
118 | 118 | ||
119 | <View | 119 | <View |
120 | android:id="@+id/view_3" | 120 | android:id="@+id/view_3" |
121 | android:layout_width="315dp" | 121 | android:layout_width="315dp" |
122 | android:layout_height="50dp" | 122 | android:layout_height="50dp" |
123 | android:layout_marginTop="316dp" | 123 | android:layout_marginTop="316dp" |
124 | android:background="@drawable/bg_solid_white" | 124 | android:background="@drawable/bg_solid_white" |
125 | app:layout_constraintLeft_toLeftOf="parent" | 125 | app:layout_constraintLeft_toLeftOf="parent" |
126 | app:layout_constraintRight_toRightOf="parent" | 126 | app:layout_constraintRight_toRightOf="parent" |
127 | app:layout_constraintTop_toTopOf="parent" /> | 127 | app:layout_constraintTop_toTopOf="parent" /> |
128 | 128 | ||
129 | <ImageView | 129 | <ImageView |
130 | android:id="@+id/iv_5" | 130 | android:id="@+id/iv_5" |
131 | android:layout_width="16dp" | 131 | android:layout_width="16dp" |
132 | android:layout_height="18dp" | 132 | android:layout_height="18dp" |
133 | android:layout_marginLeft="20dp" | 133 | android:layout_marginLeft="20dp" |
134 | android:background="@mipmap/mm" | 134 | android:background="@mipmap/mm" |
135 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 135 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
136 | app:layout_constraintLeft_toLeftOf="@id/view_3" | 136 | app:layout_constraintLeft_toLeftOf="@id/view_3" |
137 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 137 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
138 | 138 | ||
139 | <ImageView | 139 | <ImageView |
140 | android:id="@+id/iv_6" | 140 | android:id="@+id/iv_6" |
141 | android:layout_width="20dp" | 141 | android:layout_width="20dp" |
142 | android:layout_height="16dp" | 142 | android:layout_height="16dp" |
143 | android:layout_marginRight="20dp" | 143 | android:layout_marginRight="20dp" |
144 | android:background="@mipmap/xs" | 144 | android:background="@mipmap/xs" |
145 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 145 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
146 | app:layout_constraintRight_toRightOf="@id/view_3" | 146 | app:layout_constraintRight_toRightOf="@id/view_3" |
147 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 147 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
148 | 148 | ||
149 | <EditText | 149 | <EditText |
150 | android:id="@+id/et_pwd_2" | 150 | android:id="@+id/et_pwd_2" |
151 | android:layout_width="0dp" | 151 | android:layout_width="0dp" |
152 | android:layout_height="0dp" | 152 | android:layout_height="0dp" |
153 | android:layout_marginLeft="46dp" | 153 | android:layout_marginLeft="46dp" |
154 | android:layout_marginRight="20dp" | 154 | android:layout_marginRight="20dp" |
155 | android:background="@android:color/transparent" | 155 | android:background="@android:color/transparent" |
156 | android:gravity="left|center_vertical" | 156 | android:gravity="left|center_vertical" |
157 | android:hint="再次输入密码" | 157 | android:hint="再次输入密码" |
158 | android:inputType="textPassword" | 158 | android:inputType="textPassword" |
159 | android:textColor="#333333" | 159 | android:textColor="#333333" |
160 | android:textColorHint="#999999" | 160 | android:textColorHint="#999999" |
161 | android:textSize="16dp" | 161 | android:textSize="16dp" |
162 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 162 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
163 | app:layout_constraintLeft_toLeftOf="@id/view_3" | 163 | app:layout_constraintLeft_toLeftOf="@id/view_3" |
164 | app:layout_constraintRight_toLeftOf="@id/iv_6" | 164 | app:layout_constraintRight_toLeftOf="@id/iv_6" |
165 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 165 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
166 | 166 | ||
167 | <TextView | 167 | <TextView |
168 | android:layout_width="wrap_content" | 168 | android:layout_width="wrap_content" |
169 | android:layout_height="wrap_content" | 169 | android:layout_height="wrap_content" |
170 | android:layout_marginLeft="45dp" | 170 | android:layout_marginLeft="45dp" |
171 | android:layout_marginTop="10dp" | 171 | android:layout_marginTop="10dp" |
172 | android:text="6-16位密码,数字或字母" | 172 | android:text="6-16位密码,数字或字母" |
173 | android:textColor="#999999" | 173 | android:textColor="#999999" |
174 | android:textSize="13dp" | 174 | android:textSize="13dp" |
175 | app:layout_constraintLeft_toLeftOf="@id/view_3" | 175 | app:layout_constraintLeft_toLeftOf="@id/view_3" |
176 | app:layout_constraintTop_toBottomOf="@id/view_3" /> | 176 | app:layout_constraintTop_toBottomOf="@id/view_3" /> |
177 | 177 | ||
178 | <Button | 178 | <Button |
179 | android:id="@+id/btn_1" | 179 | android:id="@+id/btn_1" |
180 | android:layout_width="315dp" | 180 | android:layout_width="315dp" |
181 | android:layout_height="50dp" | 181 | android:layout_height="50dp" |
182 | android:layout_marginTop="428dp" | 182 | android:layout_marginTop="428dp" |
183 | android:background="@drawable/bg_solid_btn" | 183 | android:background="@drawable/bg_solid_btn" |
184 | android:text="注册" | 184 | android:text="注册" |
185 | android:textColor="@color/white" | 185 | android:textColor="@color/white" |
186 | android:textSize="18dp" | 186 | android:textSize="18dp" |
187 | app:layout_constraintLeft_toLeftOf="parent" | 187 | app:layout_constraintLeft_toLeftOf="parent" |
188 | app:layout_constraintRight_toRightOf="parent" | 188 | app:layout_constraintRight_toRightOf="parent" |
189 | app:layout_constraintTop_toTopOf="parent" /> | 189 | app:layout_constraintTop_toTopOf="parent" /> |
190 | 190 | ||
191 | <TextView | 191 | <TextView |
192 | android:id="@+id/tv_1" | 192 | android:id="@+id/tv_1" |
193 | android:layout_width="wrap_content" | 193 | android:layout_width="wrap_content" |
194 | android:layout_height="wrap_content" | 194 | android:layout_height="wrap_content" |
195 | android:layout_marginLeft="85dp" | 195 | android:layout_marginLeft="85dp" |
196 | android:layout_marginTop="15dp" | 196 | android:layout_marginTop="15dp" |
197 | android:text="已有账号,立即" | 197 | android:text="已有账号,立即" |
198 | android:textColor="#666666" | 198 | android:textColor="#666666" |
199 | android:textSize="17dp" | 199 | android:textSize="17dp" |
200 | app:layout_constraintLeft_toLeftOf="@id/btn_1" | 200 | app:layout_constraintLeft_toLeftOf="@id/btn_1" |
201 | app:layout_constraintTop_toBottomOf="@id/btn_1" /> | 201 | app:layout_constraintTop_toBottomOf="@id/btn_1" /> |
202 | 202 | ||
203 | <TextView | 203 | <TextView |
204 | android:id="@+id/tv_2" | 204 | android:id="@+id/tv_2" |
205 | android:layout_width="wrap_content" | 205 | android:layout_width="wrap_content" |
206 | android:layout_height="wrap_content" | 206 | android:layout_height="wrap_content" |
207 | android:layout_marginTop="15dp" | 207 | android:layout_marginTop="15dp" |
208 | android:text="登陆" | 208 | android:text="登录" |
209 | android:textColor="#FE5E09" | 209 | android:textColor="#FE5E09" |
210 | android:textSize="17dp" | 210 | android:textSize="17dp" |
211 | app:layout_constraintLeft_toRightOf="@id/tv_1" | 211 | app:layout_constraintLeft_toRightOf="@id/tv_1" |
212 | app:layout_constraintTop_toBottomOf="@id/btn_1" /> | 212 | app:layout_constraintTop_toBottomOf="@id/btn_1" /> |
213 | 213 | ||
214 | 214 | ||
215 | <CheckBox | 215 | <CheckBox |
216 | android:id="@+id/cb_1" | 216 | android:id="@+id/cb_1" |
217 | android:layout_width="wrap_content" | 217 | android:layout_width="wrap_content" |
218 | android:layout_height="wrap_content" | 218 | android:layout_height="wrap_content" |
219 | android:layout_marginLeft="67dp" | 219 | android:layout_marginLeft="67dp" |
220 | android:layout_marginBottom="50dp" | 220 | android:layout_marginBottom="50dp" |
221 | android:background="@android:color/transparent" | 221 | android:background="@android:color/transparent" |
222 | app:layout_constraintBottom_toBottomOf="parent" | 222 | app:layout_constraintBottom_toBottomOf="parent" |
223 | app:layout_constraintLeft_toLeftOf="parent" /> | 223 | app:layout_constraintLeft_toLeftOf="parent" /> |
224 | 224 | ||
225 | <TextView | 225 | <TextView |
226 | android:id="@+id/tv_3" | 226 | android:id="@+id/tv_3" |
227 | android:layout_width="wrap_content" | 227 | android:layout_width="wrap_content" |
228 | android:layout_height="wrap_content" | 228 | android:layout_height="wrap_content" |
229 | android:layout_marginLeft="5dp" | 229 | android:layout_marginLeft="5dp" |
230 | android:text="已阅读并同意《" | 230 | android:text="已阅读并同意《" |
231 | android:textColor="#999999" | 231 | android:textColor="#999999" |
232 | android:textSize="12dp" | 232 | android:textSize="12dp" |
233 | app:layout_constraintBottom_toBottomOf="@id/cb_1" | 233 | app:layout_constraintBottom_toBottomOf="@id/cb_1" |
234 | app:layout_constraintLeft_toRightOf="@id/cb_1" | 234 | app:layout_constraintLeft_toRightOf="@id/cb_1" |
235 | app:layout_constraintTop_toTopOf="@id/cb_1" /> | 235 | app:layout_constraintTop_toTopOf="@id/cb_1" /> |
236 | 236 | ||
237 | <TextView | 237 | <TextView |
238 | android:id="@+id/tv_4" | 238 | android:id="@+id/tv_4" |
239 | android:layout_width="wrap_content" | 239 | android:layout_width="wrap_content" |
240 | android:layout_height="wrap_content" | 240 | android:layout_height="wrap_content" |
241 | android:text="用户协议" | 241 | android:text="用户协议" |
242 | android:textColor="#FE5E09" | 242 | android:textColor="#FE5E09" |
243 | android:textSize="12dp" | 243 | android:textSize="12dp" |
244 | app:layout_constraintBottom_toBottomOf="@id/cb_1" | 244 | app:layout_constraintBottom_toBottomOf="@id/cb_1" |
245 | app:layout_constraintLeft_toRightOf="@id/tv_3" | 245 | app:layout_constraintLeft_toRightOf="@id/tv_3" |
246 | app:layout_constraintTop_toTopOf="@id/cb_1" /> | 246 | app:layout_constraintTop_toTopOf="@id/cb_1" /> |
247 | 247 | ||
248 | <TextView | 248 | <TextView |
249 | android:id="@+id/tv_5" | 249 | android:id="@+id/tv_5" |
250 | android:layout_width="wrap_content" | 250 | android:layout_width="wrap_content" |
251 | android:layout_height="wrap_content" | 251 | android:layout_height="wrap_content" |
252 | android:text="》和《" | 252 | android:text="》和《" |
253 | android:textColor="#999999" | 253 | android:textColor="#999999" |
254 | android:textSize="12dp" | 254 | android:textSize="12dp" |
255 | app:layout_constraintBottom_toBottomOf="@id/cb_1" | 255 | app:layout_constraintBottom_toBottomOf="@id/cb_1" |
256 | app:layout_constraintLeft_toRightOf="@id/tv_4" | 256 | app:layout_constraintLeft_toRightOf="@id/tv_4" |
257 | app:layout_constraintTop_toTopOf="@id/cb_1" /> | 257 | app:layout_constraintTop_toTopOf="@id/cb_1" /> |
258 | 258 | ||
259 | <TextView | 259 | <TextView |
260 | android:id="@+id/tv_6" | 260 | android:id="@+id/tv_6" |
261 | android:layout_width="wrap_content" | 261 | android:layout_width="wrap_content" |
262 | android:layout_height="wrap_content" | 262 | android:layout_height="wrap_content" |
263 | android:text="隐私政策" | 263 | android:text="隐私政策" |
264 | android:textColor="#FE5E09" | 264 | android:textColor="#FE5E09" |
265 | android:textSize="12dp" | 265 | android:textSize="12dp" |
266 | app:layout_constraintBottom_toBottomOf="@id/cb_1" | 266 | app:layout_constraintBottom_toBottomOf="@id/cb_1" |
267 | app:layout_constraintLeft_toRightOf="@id/tv_5" | 267 | app:layout_constraintLeft_toRightOf="@id/tv_5" |
268 | app:layout_constraintTop_toTopOf="@id/cb_1" /> | 268 | app:layout_constraintTop_toTopOf="@id/cb_1" /> |
269 | 269 | ||
270 | <TextView | 270 | <TextView |
271 | android:id="@+id/tv_7" | 271 | android:id="@+id/tv_7" |
272 | android:layout_width="wrap_content" | 272 | android:layout_width="wrap_content" |
273 | android:layout_height="wrap_content" | 273 | android:layout_height="wrap_content" |
274 | android:text="》" | 274 | android:text="》" |
275 | android:textColor="#999999" | 275 | android:textColor="#999999" |
276 | android:textSize="12dp" | 276 | android:textSize="12dp" |
277 | app:layout_constraintBottom_toBottomOf="@id/cb_1" | 277 | app:layout_constraintBottom_toBottomOf="@id/cb_1" |
278 | app:layout_constraintLeft_toRightOf="@id/tv_6" | 278 | app:layout_constraintLeft_toRightOf="@id/tv_6" |
279 | app:layout_constraintTop_toTopOf="@id/cb_1" /> | 279 | app:layout_constraintTop_toTopOf="@id/cb_1" /> |
280 | 280 | ||
281 | 281 | ||
282 | </androidx.constraintlayout.widget.ConstraintLayout> | 282 | </androidx.constraintlayout.widget.ConstraintLayout> |
libs/common/src/main/java/com/prws/common/utils/Common.java
1 | package com.prws.common.utils; | 1 | package com.prws.common.utils; |
2 | 2 | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.app.Dialog; | 4 | import android.app.Dialog; |
5 | import android.content.Context; | 5 | import android.content.Context; |
6 | import android.net.ConnectivityManager; | 6 | import android.net.ConnectivityManager; |
7 | import android.net.NetworkInfo; | 7 | import android.net.NetworkInfo; |
8 | import android.os.Handler; | 8 | import android.os.Handler; |
9 | import android.os.Looper; | 9 | import android.os.Looper; |
10 | import android.view.View; | 10 | import android.view.View; |
11 | import android.view.inputmethod.InputMethodManager; | 11 | import android.view.inputmethod.InputMethodManager; |
12 | 12 | ||
13 | import androidx.annotation.StringRes; | 13 | import androidx.annotation.StringRes; |
14 | import androidx.fragment.app.FragmentManager; | 14 | import androidx.fragment.app.FragmentManager; |
15 | 15 | ||
16 | import com.prws.common.CommonApplication; | 16 | import com.prws.common.CommonApplication; |
17 | import com.prws.common.utils.acmanager.ActivityManager; | 17 | import com.prws.common.utils.acmanager.ActivityManager; |
18 | 18 | ||
19 | 19 | ||
20 | import java.io.BufferedReader; | 20 | import java.io.BufferedReader; |
21 | import java.io.InputStreamReader; | 21 | import java.io.InputStreamReader; |
22 | import java.lang.reflect.Field; | 22 | import java.lang.reflect.Field; |
23 | import java.lang.reflect.InvocationTargetException; | 23 | import java.lang.reflect.InvocationTargetException; |
24 | import java.text.DateFormat; | 24 | import java.text.DateFormat; |
25 | import java.text.SimpleDateFormat; | 25 | import java.text.SimpleDateFormat; |
26 | import java.util.Calendar; | 26 | import java.util.Calendar; |
27 | import java.util.Date; | 27 | import java.util.Date; |
28 | import java.util.Map; | 28 | import java.util.Map; |
29 | import java.util.TimeZone; | 29 | import java.util.TimeZone; |
30 | import java.util.Timer; | 30 | import java.util.Timer; |
31 | import java.util.TimerTask; | 31 | import java.util.TimerTask; |
32 | import java.util.regex.Matcher; | 32 | import java.util.regex.Matcher; |
33 | import java.util.regex.Pattern; | 33 | import java.util.regex.Pattern; |
34 | 34 | ||
35 | public class Common { | 35 | public class Common { |
36 | 36 | ||
37 | // static AdvertisementDialog dialog; | 37 | // static AdvertisementDialog dialog; |
38 | // public static void showAdvertisement(FragmentManager manager){ | 38 | // public static void showAdvertisement(FragmentManager manager){ |
39 | // try { | 39 | // try { |
40 | // if (dialog!=null){ | 40 | // if (dialog!=null){ |
41 | //// dialog.dismiss(); | 41 | //// dialog.dismiss(); |
42 | //// dialog = null; | 42 | //// dialog = null; |
43 | // dialog.show(manager,"tag"); | 43 | // dialog.show(manager,"tag"); |
44 | // return; | 44 | // return; |
45 | // } | 45 | // } |
46 | // dialog = new AdvertisementDialog(); | 46 | // dialog = new AdvertisementDialog(); |
47 | // dialog.show(manager,"tag"); | 47 | // dialog.show(manager,"tag"); |
48 | // | 48 | // |
49 | // ScreenUtils.hideDialogBottomUIMenu(dialog); | 49 | // ScreenUtils.hideDialogBottomUIMenu(dialog); |
50 | //// ScreenUtils.hideBottomUIMenu(Common.getGlobleActivity()); | 50 | //// ScreenUtils.hideBottomUIMenu(Common.getGlobleActivity()); |
51 | // } catch (Exception e) { | 51 | // } catch (Exception e) { |
52 | // e.printStackTrace(); | 52 | // e.printStackTrace(); |
53 | // } | 53 | // } |
54 | // | 54 | // |
55 | // | 55 | // |
56 | // } | 56 | // } |
57 | 57 | ||
58 | public static boolean isValidPhoneNumber(String phoneNumber) { | ||
59 | if ((phoneNumber != null) && (!phoneNumber.isEmpty())) { | ||
60 | return Pattern.matches("^1[3-9]\\d{9}$", phoneNumber); | ||
61 | } | ||
62 | return false; | ||
63 | } | ||
64 | |||
65 | |||
58 | public static byte[] hexStrToBinaryStr(String hexString) { | 66 | public static byte[] hexStrToBinaryStr(String hexString) { |
59 | if (hexString == null) { | 67 | if (hexString == null) { |
60 | return null; | 68 | return null; |
61 | } | 69 | } |
62 | hexString = hexString.replaceAll(" ", ""); | 70 | hexString = hexString.replaceAll(" ", ""); |
63 | 71 | ||
64 | int len = hexString.length(); | 72 | int len = hexString.length(); |
65 | int index = 0; | 73 | int index = 0; |
66 | 74 | ||
67 | byte[] bytes = new byte[len / 2]; | 75 | byte[] bytes = new byte[len / 2]; |
68 | 76 | ||
69 | while (index < len) { | 77 | while (index < len) { |
70 | String sub = hexString.substring(index, index + 2); | 78 | String sub = hexString.substring(index, index + 2); |
71 | bytes[index / 2] = (byte) Integer.parseInt(sub, 16); | 79 | bytes[index / 2] = (byte) Integer.parseInt(sub, 16); |
72 | index += 2; | 80 | index += 2; |
73 | } | 81 | } |
74 | return bytes; | 82 | return bytes; |
75 | } | 83 | } |
76 | 84 | ||
77 | public static String doubleArrToString(Double[] arr) { | 85 | public static String doubleArrToString(Double[] arr) { |
78 | String str = ""; | 86 | String str = ""; |
79 | if (arr != null && arr.length > 0) { | 87 | if (arr != null && arr.length > 0) { |
80 | for (Double d : arr) { | 88 | for (Double d : arr) { |
81 | if (str.length() > 0) | 89 | if (str.length() > 0) |
82 | str += ","; | 90 | str += ","; |
83 | str += String.format("%.2f", d); | 91 | str += String.format("%.2f", d); |
84 | } | 92 | } |
85 | } | 93 | } |
86 | return str; | 94 | return str; |
87 | } | 95 | } |
88 | 96 | ||
89 | public static byte[] byteMerger(byte[] bt1, byte[] bt2) { | 97 | public static byte[] byteMerger(byte[] bt1, byte[] bt2) { |
90 | byte[] bt3 = new byte[bt1.length + bt2.length]; | 98 | byte[] bt3 = new byte[bt1.length + bt2.length]; |
91 | System.arraycopy(bt1, 0, bt3, 0, bt1.length); | 99 | System.arraycopy(bt1, 0, bt3, 0, bt1.length); |
92 | System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length); | 100 | System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length); |
93 | return bt3; | 101 | return bt3; |
94 | } | 102 | } |
95 | 103 | ||
96 | 104 | ||
97 | /** | 105 | /** |
98 | * 传入Data类型日期,返回字符串类型时间(ISO8601标准时间) | 106 | * 传入Data类型日期,返回字符串类型时间(ISO8601标准时间) |
99 | * | 107 | * |
100 | * @param date | 108 | * @param date |
101 | * @return | 109 | * @return |
102 | */ | 110 | */ |
103 | public static String getISO8601Timestamp(Date date) { | 111 | public static String getISO8601Timestamp(Date date) { |
104 | TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); | 112 | TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); |
105 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); | 113 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
106 | df.setTimeZone(tz); | 114 | df.setTimeZone(tz); |
107 | String nowAsISO = df.format(date); | 115 | String nowAsISO = df.format(date); |
108 | return nowAsISO; | 116 | return nowAsISO; |
109 | } | 117 | } |
110 | 118 | ||
111 | 119 | ||
112 | 120 | ||
113 | 121 | ||
114 | 122 | ||
115 | 123 | ||
116 | /** | 124 | /** |
117 | * 判断是否包含中文 | 125 | * 判断是否包含中文 |
118 | * | 126 | * |
119 | * @param ssid | 127 | * @param ssid |
120 | * @return | 128 | * @return |
121 | */ | 129 | */ |
122 | public static boolean isContainChinese(String ssid) { | 130 | public static boolean isContainChinese(String ssid) { |
123 | String regEx = "[\u4e00-\u9fa5]"; | 131 | String regEx = "[\u4e00-\u9fa5]"; |
124 | Pattern pattern = Pattern.compile(regEx); | 132 | Pattern pattern = Pattern.compile(regEx); |
125 | Matcher m = pattern.matcher(ssid); | 133 | Matcher m = pattern.matcher(ssid); |
126 | if (m.find()) { | 134 | if (m.find()) { |
127 | return true; | 135 | return true; |
128 | } | 136 | } |
129 | return false; | 137 | return false; |
130 | } | 138 | } |
131 | 139 | ||
132 | public static boolean isNumber(String str) { | 140 | public static boolean isNumber(String str) { |
133 | String reg = "^[0-9]+(.[0-9]+)?$"; | 141 | String reg = "^[0-9]+(.[0-9]+)?$"; |
134 | return str.matches(reg); | 142 | return str.matches(reg); |
135 | } | 143 | } |
136 | 144 | ||
137 | /** | 145 | /** |
138 | * 日期转中文字符串 | 146 | * 日期转中文字符串 |
139 | * 月和日 不包含年 | 147 | * 月和日 不包含年 |
140 | */ | 148 | */ |
141 | private static final String[] CN_NUMBER_NAME = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; | 149 | private static final String[] CN_NUMBER_NAME = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; |
142 | 150 | ||
143 | public static String getCNDateStr(Date date) { | 151 | public static String getCNDateStr(Date date) { |
144 | if (date == null) | 152 | if (date == null) |
145 | date = new Date(); | 153 | date = new Date(); |
146 | 154 | ||
147 | Calendar cal = Calendar.getInstance(); // 使用日历类 | 155 | Calendar cal = Calendar.getInstance(); // 使用日历类 |
148 | cal.setTime(date); | 156 | cal.setTime(date); |
149 | String year = String.valueOf(cal.get(Calendar.YEAR)); // 得到年 | 157 | String year = String.valueOf(cal.get(Calendar.YEAR)); // 得到年 |
150 | String month = String.valueOf(cal.get(Calendar.MONTH) + 1); // 得到月,因为从0开始的,所以要加1 | 158 | String month = String.valueOf(cal.get(Calendar.MONTH) + 1); // 得到月,因为从0开始的,所以要加1 |
151 | String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); // 得到天 | 159 | String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); // 得到天 |
152 | 160 | ||
153 | StringBuilder cnDate = new StringBuilder(); | 161 | StringBuilder cnDate = new StringBuilder(); |
154 | // for (int i = 0; i < year.length(); i++) { | 162 | // for (int i = 0; i < year.length(); i++) { |
155 | // cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(year.charAt(i)))]); | 163 | // cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(year.charAt(i)))]); |
156 | // } | 164 | // } |
157 | // | 165 | // |
158 | // cnDate.append("年"); | 166 | // cnDate.append("年"); |
159 | 167 | ||
160 | for (int i = 0; i < month.length(); i++) { | 168 | for (int i = 0; i < month.length(); i++) { |
161 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(month.charAt(i)))]); | 169 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(month.charAt(i)))]); |
162 | } | 170 | } |
163 | 171 | ||
164 | cnDate.append("月"); | 172 | cnDate.append("月"); |
165 | 173 | ||
166 | if (day.length() == 2) { | 174 | if (day.length() == 2) { |
167 | Integer value = Integer.valueOf(String.valueOf(day.charAt(0))); | 175 | Integer value = Integer.valueOf(String.valueOf(day.charAt(0))); |
168 | if (!value.equals(1)) { | 176 | if (!value.equals(1)) { |
169 | cnDate.append(CN_NUMBER_NAME[value]); | 177 | cnDate.append(CN_NUMBER_NAME[value]); |
170 | } | 178 | } |
171 | cnDate.append("十"); | 179 | cnDate.append("十"); |
172 | if (!String.valueOf(day.charAt(1)).equals("0")) { | 180 | if (!String.valueOf(day.charAt(1)).equals("0")) { |
173 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(day.charAt(1)))]); | 181 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(day.charAt(1)))]); |
174 | } | 182 | } |
175 | } else { | 183 | } else { |
176 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(day.charAt(0)))]); | 184 | cnDate.append(CN_NUMBER_NAME[Integer.valueOf(String.valueOf(day.charAt(0)))]); |
177 | } | 185 | } |
178 | 186 | ||
179 | cnDate.append("日"); | 187 | cnDate.append("日"); |
180 | return cnDate.toString(); | 188 | return cnDate.toString(); |
181 | } | 189 | } |
182 | 190 | ||
183 | public static Activity getGlobleActivity() throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException { | 191 | public static Activity getGlobleActivity() throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException { |
184 | Class activityThreadClass = Class.forName("android.app.ActivityThread"); | 192 | Class activityThreadClass = Class.forName("android.app.ActivityThread"); |
185 | Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); | 193 | Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); |
186 | Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); | 194 | Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); |
187 | activitiesField.setAccessible(true); | 195 | activitiesField.setAccessible(true); |
188 | Map activities = (Map) activitiesField.get(activityThread); | 196 | Map activities = (Map) activitiesField.get(activityThread); |
189 | for (Object activityRecord : activities.values()) { | 197 | for (Object activityRecord : activities.values()) { |
190 | Class activityRecordClass = activityRecord.getClass(); | 198 | Class activityRecordClass = activityRecord.getClass(); |
191 | Field pausedField = activityRecordClass.getDeclaredField("paused"); | 199 | Field pausedField = activityRecordClass.getDeclaredField("paused"); |
192 | pausedField.setAccessible(true); | 200 | pausedField.setAccessible(true); |
193 | if (!pausedField.getBoolean(activityRecord)) { | 201 | if (!pausedField.getBoolean(activityRecord)) { |
194 | Field activityField = activityRecordClass.getDeclaredField("activity"); | 202 | Field activityField = activityRecordClass.getDeclaredField("activity"); |
195 | activityField.setAccessible(true); | 203 | activityField.setAccessible(true); |
196 | Activity activity = (Activity) activityField.get(activityRecord); | 204 | Activity activity = (Activity) activityField.get(activityRecord); |
197 | return activity; | 205 | return activity; |
198 | } | 206 | } |
199 | } | 207 | } |
200 | return null; | 208 | return null; |
201 | } | 209 | } |
202 | 210 | ||
203 | /** | 211 | /** |
204 | * 判断当前显示的activity是否为哪个 | 212 | * 判断当前显示的activity是否为哪个 |
205 | * 可用于测温 | 213 | * 可用于测温 |
206 | * @param clazz 例如:Common.class | 214 | * @param clazz 例如:Common.class |
207 | * @return | 215 | * @return |
208 | */ | 216 | */ |
209 | public static boolean isTopActivity(Class clazz){ | 217 | public static boolean isTopActivity(Class clazz){ |
210 | if (ActivityManager.getInstance().getCurrentActivity() == null)return false; | 218 | if (ActivityManager.getInstance().getCurrentActivity() == null)return false; |
211 | return ActivityManager.getInstance().getCurrentActivity().getClass().getSimpleName().equals(clazz.getSimpleName()); | 219 | return ActivityManager.getInstance().getCurrentActivity().getClass().getSimpleName().equals(clazz.getSimpleName()); |
212 | } | 220 | } |
213 | 221 | ||
214 | 222 | ||
215 | public static String getString(@StringRes int strId){ | 223 | public static String getString(@StringRes int strId){ |
216 | if (ActivityManager.getInstance().getCurrentActivity() == null) return ""; | 224 | if (ActivityManager.getInstance().getCurrentActivity() == null) return ""; |
217 | return ActivityManager.getInstance().getCurrentActivity().getString(strId); | 225 | return ActivityManager.getInstance().getCurrentActivity().getString(strId); |
218 | } | 226 | } |
219 | 227 | ||
220 | 228 | ||
221 | 229 | ||
222 | 230 | ||
223 | public static String getFromAssets(String fileName) { | 231 | public static String getFromAssets(String fileName) { |
224 | try { | 232 | try { |
225 | InputStreamReader inputReader = new InputStreamReader(CommonApplication.getAppContext().getAssets().open(fileName)); | 233 | InputStreamReader inputReader = new InputStreamReader(CommonApplication.getAppContext().getAssets().open(fileName)); |
226 | BufferedReader bufReader = new BufferedReader(inputReader); | 234 | BufferedReader bufReader = new BufferedReader(inputReader); |
227 | String line = ""; | 235 | String line = ""; |
228 | String Result = ""; | 236 | String Result = ""; |
229 | while ((line = bufReader.readLine()) != null) | 237 | while ((line = bufReader.readLine()) != null) |
230 | Result += line; | 238 | Result += line; |
231 | return Result; | 239 | return Result; |
232 | } catch (Exception e) { | 240 | } catch (Exception e) { |
233 | e.printStackTrace(); | 241 | e.printStackTrace(); |
234 | } | 242 | } |
235 | return null; | 243 | return null; |
236 | } | 244 | } |
237 | 245 | ||
238 | /** | 246 | /** |
239 | * 此方法只是关闭软键盘 | 247 | * 此方法只是关闭软键盘 |
240 | */ | 248 | */ |
241 | public static void hideSoftKeyboard() { | 249 | public static void hideSoftKeyboard() { |
242 | try { | 250 | try { |
243 | Activity activity = getGlobleActivity(); | 251 | Activity activity = getGlobleActivity(); |
244 | InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); | 252 | InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); |
245 | if (imm.isActive() && activity.getCurrentFocus() != null) { | 253 | if (imm.isActive() && activity.getCurrentFocus() != null) { |
246 | if (activity.getCurrentFocus().getWindowToken() != null) { | 254 | if (activity.getCurrentFocus().getWindowToken() != null) { |
247 | imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), | 255 | imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), |
248 | InputMethodManager.HIDE_NOT_ALWAYS); | 256 | InputMethodManager.HIDE_NOT_ALWAYS); |
249 | } | 257 | } |
250 | } | 258 | } |
251 | } catch (Exception e) { | 259 | } catch (Exception e) { |
252 | 260 | ||
253 | } | 261 | } |
254 | } | 262 | } |
255 | 263 | ||
256 | /** | 264 | /** |
257 | * 判断网络是否连接 | 265 | * 判断网络是否连接 |
258 | */ | 266 | */ |
259 | public static boolean isNetworkAvailable() { | 267 | public static boolean isNetworkAvailable() { |
260 | ConnectivityManager connectivityManager = (ConnectivityManager) CommonApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE); | 268 | ConnectivityManager connectivityManager = (ConnectivityManager) CommonApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
261 | NetworkInfo info = connectivityManager.getActiveNetworkInfo(); | 269 | NetworkInfo info = connectivityManager.getActiveNetworkInfo(); |
262 | if (info != null && info.isAvailable()) { | 270 | if (info != null && info.isAvailable()) { |
263 | return true; | 271 | return true; |
264 | } else { | 272 | } else { |
265 | return false; | 273 | return false; |
266 | } | 274 | } |
267 | } | 275 | } |
268 | 276 | ||
269 | public static Boolean isAppInstalled(String packageName) { | 277 | public static Boolean isAppInstalled(String packageName) { |
270 | try { | 278 | try { |
271 | CommonApplication.getAppContext().getPackageManager().getPackageInfo(packageName, 0); | 279 | CommonApplication.getAppContext().getPackageManager().getPackageInfo(packageName, 0); |
272 | return true; | 280 | return true; |
273 | } catch (Exception e) { | 281 | } catch (Exception e) { |
274 | e.printStackTrace(); | 282 | e.printStackTrace(); |
275 | return false; | 283 | return false; |
276 | } | 284 | } |
277 | } | 285 | } |
278 | 286 | ||
279 | } | 287 | } |
280 | 288 |