Commit f262303aa8a5bb3e44c7f2a839a3828d17034bd8
1 parent
49236c7b5f
Exists in
master
去掉设置密码功能
Showing
2 changed files
with
5 additions
and
2 deletions
Show diff stats
app/src/main/java/com/hjx/parent/AccountActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; | 3 | import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; |
4 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; | 4 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
5 | 5 | ||
6 | import android.app.AlertDialog; | 6 | import android.app.AlertDialog; |
7 | import android.content.DialogInterface; | 7 | import android.content.DialogInterface; |
8 | import android.content.Intent; | 8 | import android.content.Intent; |
9 | import android.graphics.Bitmap; | 9 | import android.graphics.Bitmap; |
10 | import android.net.NetworkRequest; | 10 | import android.net.NetworkRequest; |
11 | import android.net.Uri; | 11 | import android.net.Uri; |
12 | import android.os.Build; | 12 | import android.os.Build; |
13 | import android.os.Bundle; | 13 | import android.os.Bundle; |
14 | import android.os.Environment; | 14 | import android.os.Environment; |
15 | import android.provider.MediaStore; | 15 | import android.provider.MediaStore; |
16 | import android.text.TextUtils; | 16 | import android.text.TextUtils; |
17 | import android.util.Log; | 17 | import android.util.Log; |
18 | import android.view.LayoutInflater; | 18 | import android.view.LayoutInflater; |
19 | import android.view.View; | 19 | import android.view.View; |
20 | import android.widget.ImageView; | 20 | import android.widget.ImageView; |
21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
22 | import android.widget.Toast; | 22 | import android.widget.Toast; |
23 | 23 | ||
24 | import androidx.core.content.FileProvider; | 24 | import androidx.core.content.FileProvider; |
25 | 25 | ||
26 | import com.bumptech.glide.Glide; | 26 | import com.bumptech.glide.Glide; |
27 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 27 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
28 | import com.bumptech.glide.request.RequestOptions; | 28 | import com.bumptech.glide.request.RequestOptions; |
29 | import com.google.android.material.bottomsheet.BottomSheetDialog; | 29 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
30 | import com.hjq.permissions.OnPermissionCallback; | 30 | import com.hjq.permissions.OnPermissionCallback; |
31 | import com.hjq.permissions.Permission; | 31 | import com.hjq.permissions.Permission; |
32 | import com.hjq.permissions.XXPermissions; | 32 | import com.hjq.permissions.XXPermissions; |
33 | import com.prws.common.base.BaseActivity; | 33 | import com.prws.common.base.BaseActivity; |
34 | import com.prws.common.base.BasePresenter; | 34 | import com.prws.common.base.BasePresenter; |
35 | import com.prws.common.bean.ResponseResult; | 35 | import com.prws.common.bean.ResponseResult; |
36 | import com.prws.common.net.NetWorks; | 36 | import com.prws.common.net.NetWorks; |
37 | import com.prws.common.utils.LogUtil; | 37 | import com.prws.common.utils.LogUtil; |
38 | import com.prws.common.utils.ScreenUtils; | 38 | import com.prws.common.utils.ScreenUtils; |
39 | import com.prws.common.utils.SharedPreferencesUtil; | 39 | import com.prws.common.utils.SharedPreferencesUtil; |
40 | 40 | ||
41 | import org.json.JSONObject; | 41 | import org.json.JSONObject; |
42 | 42 | ||
43 | import java.io.File; | 43 | import java.io.File; |
44 | import java.io.FileOutputStream; | 44 | import java.io.FileOutputStream; |
45 | import java.io.IOException; | 45 | import java.io.IOException; |
46 | import java.util.HashMap; | 46 | import java.util.HashMap; |
47 | import java.util.List; | 47 | import java.util.List; |
48 | import java.util.Map; | 48 | import java.util.Map; |
49 | 49 | ||
50 | import butterknife.BindView; | 50 | import butterknife.BindView; |
51 | import butterknife.OnClick; | 51 | import butterknife.OnClick; |
52 | import io.reactivex.Observer; | 52 | import io.reactivex.Observer; |
53 | import io.reactivex.disposables.Disposable; | 53 | import io.reactivex.disposables.Disposable; |
54 | import okhttp3.ResponseBody; | 54 | import okhttp3.ResponseBody; |
55 | 55 | ||
56 | public class AccountActivity extends BaseActivity { | 56 | public class AccountActivity extends BaseActivity { |
57 | 57 | ||
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | protected int layoutResId() { | 60 | protected int layoutResId() { |
61 | return R.layout.activity_setac; | 61 | return R.layout.activity_setac; |
62 | } | 62 | } |
63 | 63 | ||
64 | @Override | 64 | @Override |
65 | public Object getContract() { | 65 | public Object getContract() { |
66 | return null; | 66 | return null; |
67 | } | 67 | } |
68 | 68 | ||
69 | @Override | 69 | @Override |
70 | public BasePresenter getPresenter() { | 70 | public BasePresenter getPresenter() { |
71 | return null; | 71 | return null; |
72 | } | 72 | } |
73 | 73 | ||
74 | private static int CAMERA_REQUEST_CODE = 343; | 74 | private static int CAMERA_REQUEST_CODE = 343; |
75 | private static int ALBUM_REQUEST_CODE = 456; | 75 | private static int ALBUM_REQUEST_CODE = 456; |
76 | private static int CROP_REQUEST_CODE = 234; | 76 | private static int CROP_REQUEST_CODE = 234; |
77 | private File tempFile; | 77 | private File tempFile; |
78 | private String path; | 78 | private String path; |
79 | TextView tv_6; | 79 | TextView tv_6; |
80 | @BindView(R.id.iv_3) | 80 | @BindView(R.id.iv_3) |
81 | ImageView iv_3; | 81 | ImageView iv_3; |
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | protected void initView() { | 84 | protected void initView() { |
85 | tv_6 = findViewById(R.id.tv_6); | 85 | tv_6 = findViewById(R.id.tv_6); |
86 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); | 86 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); |
87 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 87 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); |
88 | if (!TextUtils.isEmpty(photo)) { | 88 | if (!TextUtils.isEmpty(photo)) { |
89 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); | 89 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); |
90 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 90 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
91 | Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3); | 91 | Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3); |
92 | } | 92 | } |
93 | if (phone != null && phone.length() > 0) | 93 | if (phone != null && phone.length() > 0) |
94 | tv_6.setText(phone); | 94 | tv_6.setText(phone); |
95 | } | 95 | } |
96 | 96 | ||
97 | @Override | 97 | @Override |
98 | protected void initListener() { | 98 | protected void initListener() { |
99 | findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed()); | 99 | findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed()); |
100 | findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class)); | 100 | //findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class)); |
101 | } | 101 | } |
102 | 102 | ||
103 | @Override | 103 | @Override |
104 | protected void initData() { | 104 | protected void initData() { |
105 | 105 | ||
106 | } | 106 | } |
107 | 107 | ||
108 | @Override | 108 | @Override |
109 | public void onNetChanged(int netWorkState) { | 109 | public void onNetChanged(int netWorkState) { |
110 | 110 | ||
111 | } | 111 | } |
112 | 112 | ||
113 | private void uploadAvatar(File file) { | 113 | private void uploadAvatar(File file) { |
114 | 114 | ||
115 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { | 115 | NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { |
116 | @Override | 116 | @Override |
117 | public void onSubscribe(Disposable d) { | 117 | public void onSubscribe(Disposable d) { |
118 | 118 | ||
119 | } | 119 | } |
120 | 120 | ||
121 | @Override | 121 | @Override |
122 | public void onNext(ResponseResult<Map<String, String>> responseBody) { | 122 | public void onNext(ResponseResult<Map<String, String>> responseBody) { |
123 | if (responseBody.getData() != null && responseBody.getCode() == 200) { | 123 | if (responseBody.getData() != null && responseBody.getCode() == 200) { |
124 | path = responseBody.getData().get("imageUrl"); | 124 | path = responseBody.getData().get("imageUrl"); |
125 | editUser(path); | 125 | editUser(path); |
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | @Override | 129 | @Override |
130 | public void onError(Throwable e) { | 130 | public void onError(Throwable e) { |
131 | e.toString(); | 131 | e.toString(); |
132 | } | 132 | } |
133 | 133 | ||
134 | @Override | 134 | @Override |
135 | public void onComplete() { | 135 | public void onComplete() { |
136 | 136 | ||
137 | } | 137 | } |
138 | }); | 138 | }); |
139 | } | 139 | } |
140 | 140 | ||
141 | public void editUser(String path) { | 141 | public void editUser(String path) { |
142 | Map map = new HashMap(); | 142 | Map map = new HashMap(); |
143 | map.put("userId", SharedPreferencesUtil.getData("userId", "")); | 143 | map.put("userId", SharedPreferencesUtil.getData("userId", "")); |
144 | map.put("photo", path); | 144 | map.put("photo", path); |
145 | 145 | ||
146 | NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 146 | NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
147 | @Override | 147 | @Override |
148 | public void onSubscribe(Disposable d) { | 148 | public void onSubscribe(Disposable d) { |
149 | 149 | ||
150 | } | 150 | } |
151 | 151 | ||
152 | @Override | 152 | @Override |
153 | public void onNext(ResponseBody responseBody) { | 153 | public void onNext(ResponseBody responseBody) { |
154 | try { | 154 | try { |
155 | String str = responseBody.string().toString(); | 155 | String str = responseBody.string().toString(); |
156 | LogUtil.e(TAG, "----" + str); | 156 | LogUtil.e(TAG, "----" + str); |
157 | JSONObject jo = new JSONObject(str); | 157 | JSONObject jo = new JSONObject(str); |
158 | boolean isSucceed = jo.getBoolean("success"); | 158 | boolean isSucceed = jo.getBoolean("success"); |
159 | if (isSucceed) { | 159 | if (isSucceed) { |
160 | SharedPreferencesUtil.putData("photo", path); | 160 | SharedPreferencesUtil.putData("photo", path); |
161 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); | 161 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); |
162 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 162 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
163 | Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3); | 163 | Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3); |
164 | Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show(); | 164 | Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show(); |
165 | } else { | 165 | } else { |
166 | Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 166 | Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
167 | } | 167 | } |
168 | } catch (Exception e) { | 168 | } catch (Exception e) { |
169 | e.printStackTrace(); | 169 | e.printStackTrace(); |
170 | Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 170 | Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | @Override | 174 | @Override |
175 | public void onError(Throwable e) { | 175 | public void onError(Throwable e) { |
176 | 176 | ||
177 | } | 177 | } |
178 | 178 | ||
179 | @Override | 179 | @Override |
180 | public void onComplete() { | 180 | public void onComplete() { |
181 | 181 | ||
182 | } | 182 | } |
183 | }); | 183 | }); |
184 | } | 184 | } |
185 | 185 | ||
186 | public File saveImage(String name, Bitmap bmp) { | 186 | public File saveImage(String name, Bitmap bmp) { |
187 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); | 187 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); |
188 | if (!appDir.exists()) { | 188 | if (!appDir.exists()) { |
189 | appDir.mkdir(); | 189 | appDir.mkdir(); |
190 | } | 190 | } |
191 | String fileName = name + ".jpg"; | 191 | String fileName = name + ".jpg"; |
192 | File file = new File(appDir, fileName); | 192 | File file = new File(appDir, fileName); |
193 | try { | 193 | try { |
194 | FileOutputStream fos = new FileOutputStream(file); | 194 | FileOutputStream fos = new FileOutputStream(file); |
195 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); | 195 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); |
196 | fos.flush(); | 196 | fos.flush(); |
197 | fos.close(); | 197 | fos.close(); |
198 | return file; | 198 | return file; |
199 | } catch (IOException e) { | 199 | } catch (IOException e) { |
200 | Log.d("dsadsadsa", e.getLocalizedMessage()); | 200 | Log.d("dsadsadsa", e.getLocalizedMessage()); |
201 | e.printStackTrace(); | 201 | e.printStackTrace(); |
202 | } | 202 | } |
203 | return null; | 203 | return null; |
204 | } | 204 | } |
205 | 205 | ||
206 | @Override | 206 | @Override |
207 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | 207 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
208 | super.onActivityResult(requestCode, resultCode, intent); | 208 | super.onActivityResult(requestCode, resultCode, intent); |
209 | if (requestCode == CAMERA_REQUEST_CODE) { | 209 | if (requestCode == CAMERA_REQUEST_CODE) { |
210 | if (resultCode == RESULT_OK) { | 210 | if (resultCode == RESULT_OK) { |
211 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 | 211 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 |
212 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 212 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
213 | Uri contentUri = FileProvider.getUriForFile(this, | 213 | Uri contentUri = FileProvider.getUriForFile(this, |
214 | this.getPackageName() + ".fileprovider", tempFile); | 214 | this.getPackageName() + ".fileprovider", tempFile); |
215 | cropPhoto(contentUri); | 215 | cropPhoto(contentUri); |
216 | } else { | 216 | } else { |
217 | cropPhoto(Uri.fromFile(tempFile)); | 217 | cropPhoto(Uri.fromFile(tempFile)); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | } else if (requestCode == ALBUM_REQUEST_CODE) { | 220 | } else if (requestCode == ALBUM_REQUEST_CODE) { |
221 | if (resultCode == RESULT_OK) { | 221 | if (resultCode == RESULT_OK) { |
222 | Uri uri = intent.getData(); | 222 | Uri uri = intent.getData(); |
223 | cropPhoto(uri); | 223 | cropPhoto(uri); |
224 | } | 224 | } |
225 | } else if (requestCode == CROP_REQUEST_CODE) { | 225 | } else if (requestCode == CROP_REQUEST_CODE) { |
226 | if (intent == null) { | 226 | if (intent == null) { |
227 | return; | 227 | return; |
228 | } | 228 | } |
229 | Bundle bundle = intent.getExtras(); | 229 | Bundle bundle = intent.getExtras(); |
230 | if (bundle != null) { | 230 | if (bundle != null) { |
231 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 | 231 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 |
232 | Bitmap image = bundle.getParcelable("data"); | 232 | Bitmap image = bundle.getParcelable("data"); |
233 | //设置到ImageView上 | 233 | //设置到ImageView上 |
234 | //也可以进行一些保存、压缩等操作后上传 | 234 | //也可以进行一些保存、压缩等操作后上传 |
235 | File file = saveImage("head_output", image); | 235 | File file = saveImage("head_output", image); |
236 | uploadAvatar(file); | 236 | uploadAvatar(file); |
237 | // Log.d("dsadsadsa",path); | 237 | // Log.d("dsadsadsa",path); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | private void getPicFromCamera() { | 242 | private void getPicFromCamera() { |
243 | //用于保存调用相机拍照后所生成的文件 | 243 | //用于保存调用相机拍照后所生成的文件 |
244 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); | 244 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); |
245 | //跳转到调用系统相机 | 245 | //跳转到调用系统相机 |
246 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 246 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
247 | //判断版本 | 247 | //判断版本 |
248 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri | 248 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri |
249 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 249 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
250 | Uri contentUri = FileProvider.getUriForFile(this, | 250 | Uri contentUri = FileProvider.getUriForFile(this, |
251 | this.getPackageName() + ".fileprovider", tempFile); | 251 | this.getPackageName() + ".fileprovider", tempFile); |
252 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); | 252 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); |
253 | } else { //否则使用Uri.fromFile(file)方法获取Uri | 253 | } else { //否则使用Uri.fromFile(file)方法获取Uri |
254 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); | 254 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); |
255 | } | 255 | } |
256 | startActivityForResult(intent, CAMERA_REQUEST_CODE); | 256 | startActivityForResult(intent, CAMERA_REQUEST_CODE); |
257 | } | 257 | } |
258 | 258 | ||
259 | private void cropPhoto(Uri uri) { | 259 | private void cropPhoto(Uri uri) { |
260 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); | 260 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); |
261 | Intent intent = new Intent("com.android.camera.action.CROP"); | 261 | Intent intent = new Intent("com.android.camera.action.CROP"); |
262 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 262 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
263 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 | 263 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 |
264 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 264 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
265 | } | 265 | } |
266 | intent.setDataAndType(uri, "image/*"); | 266 | intent.setDataAndType(uri, "image/*"); |
267 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 | 267 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 |
268 | intent.putExtra("scale", true);// 设置缩放 | 268 | intent.putExtra("scale", true);// 设置缩放 |
269 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 | 269 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 |
270 | intent.putExtra("aspectX", 1); | 270 | intent.putExtra("aspectX", 1); |
271 | intent.putExtra("aspectY", 1); | 271 | intent.putExtra("aspectY", 1); |
272 | //上述两个属性控制裁剪框的缩放比例。 | 272 | //上述两个属性控制裁剪框的缩放比例。 |
273 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 | 273 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 |
274 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 | 274 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 |
275 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, | 275 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, |
276 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 | 276 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 |
277 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap | 277 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap |
278 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 | 278 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 |
279 | startActivityForResult(intent, CROP_REQUEST_CODE); | 279 | startActivityForResult(intent, CROP_REQUEST_CODE); |
280 | } | 280 | } |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * 从相册获取图片 | 283 | * 从相册获取图片 |
284 | */ | 284 | */ |
285 | private void getPicFromAlbm() { | 285 | private void getPicFromAlbm() { |
286 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 286 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
287 | photoPickerIntent.setType("image/*"); | 287 | photoPickerIntent.setType("image/*"); |
288 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); | 288 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); |
289 | } | 289 | } |
290 | 290 | ||
291 | @OnClick(R.id.iv_3) | 291 | @OnClick(R.id.iv_3) |
292 | public void showButtonDialog(View view) { | 292 | public void showButtonDialog(View view) { |
293 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); | 293 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); |
294 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); | 294 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); |
295 | dialog.setContentView(bottomView); | 295 | dialog.setContentView(bottomView); |
296 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 296 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
297 | @Override | 297 | @Override |
298 | public void onClick(View view) { | 298 | public void onClick(View view) { |
299 | dialog.dismiss(); | 299 | dialog.dismiss(); |
300 | if (!XXPermissions.isGranted(AccountActivity.this, Permission.CAMERA)) { | 300 | if (!XXPermissions.isGranted(AccountActivity.this, Permission.CAMERA)) { |
301 | XXPermissions.with(AccountActivity.this) | 301 | XXPermissions.with(AccountActivity.this) |
302 | // 申请多个权限 | 302 | // 申请多个权限 |
303 | .permission(Permission.CAMERA) | 303 | .permission(Permission.CAMERA) |
304 | .request(new OnPermissionCallback() { | 304 | .request(new OnPermissionCallback() { |
305 | @Override | 305 | @Override |
306 | public void onGranted(List<String> permissions, boolean all) { | 306 | public void onGranted(List<String> permissions, boolean all) { |
307 | if (all) { | 307 | if (all) { |
308 | //开启扫码界面 | 308 | //开启扫码界面 |
309 | getPicFromCamera(); | 309 | getPicFromCamera(); |
310 | } else { | 310 | } else { |
311 | Toast.makeText(AccountActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | 311 | Toast.makeText(AccountActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
315 | @Override | 315 | @Override |
316 | public void onDenied(List<String> permissions, boolean never) { | 316 | public void onDenied(List<String> permissions, boolean never) { |
317 | XXPermissions.startPermissionActivity(AccountActivity.this, permissions); | 317 | XXPermissions.startPermissionActivity(AccountActivity.this, permissions); |
318 | } | 318 | } |
319 | }); | 319 | }); |
320 | } else { | 320 | } else { |
321 | getPicFromCamera(); | 321 | getPicFromCamera(); |
322 | } | 322 | } |
323 | } | 323 | } |
324 | }); | 324 | }); |
325 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 325 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
326 | @Override | 326 | @Override |
327 | public void onClick(View view) { | 327 | public void onClick(View view) { |
328 | dialog.dismiss(); | 328 | dialog.dismiss(); |
329 | getPicFromAlbm(); | 329 | getPicFromAlbm(); |
330 | } | 330 | } |
331 | }); | 331 | }); |
332 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 332 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
333 | @Override | 333 | @Override |
334 | public void onClick(View view) { | 334 | public void onClick(View view) { |
335 | dialog.dismiss(); | 335 | dialog.dismiss(); |
336 | } | 336 | } |
337 | }); | 337 | }); |
338 | dialog.show(); | 338 | dialog.show(); |
339 | } | 339 | } |
340 | 340 | ||
341 | @OnClick(R.id.logout) | 341 | @OnClick(R.id.logout) |
342 | public void logout(View view) { | 342 | public void logout(View view) { |
343 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | 343 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
344 | builder.setTitle("温馨提示"); | 344 | builder.setTitle("温馨提示"); |
345 | builder.setMessage("是否退出登录?"); | 345 | builder.setMessage("是否退出登录?"); |
346 | builder.setCancelable(false); | 346 | builder.setCancelable(false); |
347 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { | 347 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { |
348 | @Override | 348 | @Override |
349 | public void onClick(DialogInterface dialogInterface, int i) { | 349 | public void onClick(DialogInterface dialogInterface, int i) { |
350 | dialogInterface.dismiss(); | 350 | dialogInterface.dismiss(); |
351 | } | 351 | } |
352 | }); | 352 | }); |
353 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { | 353 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { |
354 | @Override | 354 | @Override |
355 | public void onClick(DialogInterface dialogInterface, int i) { | 355 | public void onClick(DialogInterface dialogInterface, int i) { |
356 | SharedPreferencesUtil.clear(AccountActivity.this); | 356 | SharedPreferencesUtil.clear(AccountActivity.this); |
357 | restartApp(); | 357 | restartApp(); |
358 | } | 358 | } |
359 | }); | 359 | }); |
360 | builder.show(); | 360 | builder.show(); |
361 | } | 361 | } |
362 | 362 | ||
363 | private void restartApp() { | 363 | private void restartApp() { |
364 | //重启app,这一步一定要加上,如果不重启app,可能打开新的页面显示的语言会不正确 | 364 | //重启app,这一步一定要加上,如果不重启app,可能打开新的页面显示的语言会不正确 |
365 | Intent intent = new Intent(this, SmsLoginActivity.class); | 365 | Intent intent = new Intent(this, SmsLoginActivity.class); |
366 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); | 366 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); |
367 | startActivity(intent); | 367 | startActivity(intent); |
368 | android.os.Process.killProcess(android.os.Process.myPid()); | 368 | android.os.Process.killProcess(android.os.Process.myPid()); |
369 | System.exit(0); | 369 | System.exit(0); |
370 | } | 370 | } |
371 | 371 | ||
372 | } | 372 | } |
app/src/main/res/layout/activity_setac.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="#F4F6F8"> | 6 | android:background="#F4F6F8"> |
7 | 7 | ||
8 | <View | 8 | <View |
9 | android:id="@+id/view_1" | 9 | android:id="@+id/view_1" |
10 | android:layout_width="match_parent" | 10 | android:layout_width="match_parent" |
11 | android:layout_height="44dp" | 11 | android:layout_height="44dp" |
12 | android:background="@android:color/white" | 12 | android:background="@android:color/white" |
13 | app:layout_constraintTop_toTopOf="parent" /> | 13 | app:layout_constraintTop_toTopOf="parent" /> |
14 | 14 | ||
15 | <TextView | 15 | <TextView |
16 | android:layout_width="wrap_content" | 16 | android:layout_width="wrap_content" |
17 | android:layout_height="wrap_content" | 17 | android:layout_height="wrap_content" |
18 | android:text="账号设置" | 18 | android:text="账号设置" |
19 | android:textColor="#333333" | 19 | android:textColor="#333333" |
20 | android:textSize="18dp" | 20 | android:textSize="18dp" |
21 | app:layout_constraintBottom_toBottomOf="@id/view_1" | 21 | app:layout_constraintBottom_toBottomOf="@id/view_1" |
22 | app:layout_constraintLeft_toLeftOf="@id/view_1" | 22 | app:layout_constraintLeft_toLeftOf="@id/view_1" |
23 | app:layout_constraintRight_toRightOf="@id/view_1" | 23 | app:layout_constraintRight_toRightOf="@id/view_1" |
24 | app:layout_constraintTop_toTopOf="@id/view_1" /> | 24 | app:layout_constraintTop_toTopOf="@id/view_1" /> |
25 | 25 | ||
26 | <ImageView | 26 | <ImageView |
27 | android:id="@+id/iv_back" | 27 | android:id="@+id/iv_back" |
28 | android:layout_width="10dp" | 28 | android:layout_width="10dp" |
29 | android:layout_height="16dp" | 29 | android:layout_height="16dp" |
30 | android:layout_marginLeft="15dp" | 30 | android:layout_marginLeft="15dp" |
31 | android:background="@mipmap/icon_back" | 31 | android:background="@mipmap/icon_back" |
32 | app:layout_constraintBottom_toBottomOf="@id/view_1" | 32 | app:layout_constraintBottom_toBottomOf="@id/view_1" |
33 | app:layout_constraintLeft_toLeftOf="parent" | 33 | app:layout_constraintLeft_toLeftOf="parent" |
34 | app:layout_constraintTop_toTopOf="@id/view_1" /> | 34 | app:layout_constraintTop_toTopOf="@id/view_1" /> |
35 | 35 | ||
36 | <View | 36 | <View |
37 | android:layout_width="match_parent" | 37 | android:layout_width="match_parent" |
38 | android:layout_height="1dp" | 38 | android:layout_height="1dp" |
39 | android:background="#EEEEEE" | 39 | android:background="#EEEEEE" |
40 | app:layout_constraintTop_toBottomOf="@id/view_1" /> | 40 | app:layout_constraintTop_toBottomOf="@id/view_1" /> |
41 | 41 | ||
42 | <View | 42 | <View |
43 | android:id="@+id/view_3" | 43 | android:id="@+id/view_3" |
44 | android:layout_width="match_parent" | 44 | android:layout_width="match_parent" |
45 | android:layout_height="80dp" | 45 | android:layout_height="80dp" |
46 | android:layout_marginLeft="15dp" | 46 | android:layout_marginLeft="15dp" |
47 | android:layout_marginTop="90dp" | 47 | android:layout_marginTop="90dp" |
48 | android:layout_marginRight="15dp" | 48 | android:layout_marginRight="15dp" |
49 | android:background="@drawable/bg_solid_white_10" | 49 | android:background="@drawable/bg_solid_white_10" |
50 | app:layout_constraintLeft_toLeftOf="parent" | 50 | app:layout_constraintLeft_toLeftOf="parent" |
51 | app:layout_constraintRight_toRightOf="parent" | 51 | app:layout_constraintRight_toRightOf="parent" |
52 | app:layout_constraintTop_toTopOf="parent" /> | 52 | app:layout_constraintTop_toTopOf="parent" /> |
53 | 53 | ||
54 | <ImageView | 54 | <ImageView |
55 | android:id="@+id/iv_3" | 55 | android:id="@+id/iv_3" |
56 | android:layout_width="57dp" | 56 | android:layout_width="57dp" |
57 | android:layout_height="57dp" | 57 | android:layout_height="57dp" |
58 | android:layout_marginRight="31dp" | 58 | android:layout_marginRight="31dp" |
59 | android:background="@mipmap/ic_parent_avatar" | 59 | android:background="@mipmap/ic_parent_avatar" |
60 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 60 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
61 | app:layout_constraintRight_toRightOf="@id/view_3" | 61 | app:layout_constraintRight_toRightOf="@id/view_3" |
62 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 62 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
63 | 63 | ||
64 | <TextView | 64 | <TextView |
65 | android:id="@+id/tv_3" | 65 | android:id="@+id/tv_3" |
66 | android:layout_width="wrap_content" | 66 | android:layout_width="wrap_content" |
67 | android:layout_height="wrap_content" | 67 | android:layout_height="wrap_content" |
68 | android:layout_marginLeft="15dp" | 68 | android:layout_marginLeft="15dp" |
69 | android:text="头像" | 69 | android:text="头像" |
70 | android:textColor="#333333" | 70 | android:textColor="#333333" |
71 | android:textSize="15dp" | 71 | android:textSize="15dp" |
72 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 72 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
73 | app:layout_constraintLeft_toLeftOf="@id/view_3" | 73 | app:layout_constraintLeft_toLeftOf="@id/view_3" |
74 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 74 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
75 | 75 | ||
76 | <ImageView | 76 | <ImageView |
77 | android:layout_width="5.5dp" | 77 | android:layout_width="5.5dp" |
78 | android:layout_height="9.5dp" | 78 | android:layout_height="9.5dp" |
79 | android:layout_marginRight="15dp" | 79 | android:layout_marginRight="15dp" |
80 | android:background="@mipmap/ycaj" | 80 | android:background="@mipmap/ycaj" |
81 | app:layout_constraintBottom_toBottomOf="@id/view_3" | 81 | app:layout_constraintBottom_toBottomOf="@id/view_3" |
82 | app:layout_constraintRight_toRightOf="@id/view_3" | 82 | app:layout_constraintRight_toRightOf="@id/view_3" |
83 | app:layout_constraintTop_toTopOf="@id/view_3" /> | 83 | app:layout_constraintTop_toTopOf="@id/view_3" /> |
84 | 84 | ||
85 | <View | 85 | <View |
86 | android:id="@+id/view_4" | 86 | android:id="@+id/view_4" |
87 | android:layout_width="match_parent" | 87 | android:layout_width="match_parent" |
88 | android:layout_height="90dp" | 88 | android:layout_height="52dp" |
89 | android:layout_marginLeft="15dp" | 89 | android:layout_marginLeft="15dp" |
90 | android:layout_marginTop="185dp" | 90 | android:layout_marginTop="185dp" |
91 | android:layout_marginRight="15dp" | 91 | android:layout_marginRight="15dp" |
92 | android:background="@drawable/bg_solid_white_10" | 92 | android:background="@drawable/bg_solid_white_10" |
93 | app:layout_constraintLeft_toLeftOf="parent" | 93 | app:layout_constraintLeft_toLeftOf="parent" |
94 | app:layout_constraintRight_toRightOf="parent" | 94 | app:layout_constraintRight_toRightOf="parent" |
95 | app:layout_constraintTop_toTopOf="parent" /> | 95 | app:layout_constraintTop_toTopOf="parent" /> |
96 | 96 | ||
97 | <TextView | 97 | <TextView |
98 | android:id="@+id/tv_4" | 98 | android:id="@+id/tv_4" |
99 | android:layout_width="wrap_content" | 99 | android:layout_width="wrap_content" |
100 | android:layout_height="wrap_content" | 100 | android:layout_height="wrap_content" |
101 | android:layout_marginLeft="15dp" | 101 | android:layout_marginLeft="15dp" |
102 | android:layout_marginTop="15dp" | 102 | android:layout_marginTop="15dp" |
103 | android:text="账户" | 103 | android:text="账户" |
104 | android:textColor="#333333" | 104 | android:textColor="#333333" |
105 | android:textSize="15dp" | 105 | android:textSize="15dp" |
106 | app:layout_constraintLeft_toLeftOf="@id/view_4" | 106 | app:layout_constraintLeft_toLeftOf="@id/view_4" |
107 | app:layout_constraintTop_toTopOf="@id/view_4" /> | 107 | app:layout_constraintTop_toTopOf="@id/view_4" /> |
108 | 108 | ||
109 | <TextView | 109 | <TextView |
110 | android:visibility="invisible" | ||
110 | android:id="@+id/tv_5" | 111 | android:id="@+id/tv_5" |
111 | android:layout_width="wrap_content" | 112 | android:layout_width="wrap_content" |
112 | android:layout_height="wrap_content" | 113 | android:layout_height="wrap_content" |
113 | android:layout_marginLeft="15dp" | 114 | android:layout_marginLeft="15dp" |
114 | android:layout_marginTop="60dp" | 115 | android:layout_marginTop="60dp" |
115 | android:text="密码" | 116 | android:text="密码" |
116 | android:textColor="#333333" | 117 | android:textColor="#333333" |
117 | android:textSize="15dp" | 118 | android:textSize="15dp" |
118 | app:layout_constraintLeft_toLeftOf="@id/view_4" | 119 | app:layout_constraintLeft_toLeftOf="@id/view_4" |
119 | app:layout_constraintTop_toTopOf="@id/view_4" /> | 120 | app:layout_constraintTop_toTopOf="@id/view_4" /> |
120 | 121 | ||
121 | <TextView | 122 | <TextView |
122 | android:id="@+id/tv_6" | 123 | android:id="@+id/tv_6" |
123 | android:layout_width="wrap_content" | 124 | android:layout_width="wrap_content" |
124 | android:layout_height="wrap_content" | 125 | android:layout_height="wrap_content" |
125 | android:layout_marginTop="15dp" | 126 | android:layout_marginTop="15dp" |
126 | android:layout_marginRight="15dp" | 127 | android:layout_marginRight="15dp" |
127 | android:text="123" | 128 | android:text="123" |
128 | android:textColor="#666666" | 129 | android:textColor="#666666" |
129 | android:textSize="15dp" | 130 | android:textSize="15dp" |
130 | app:layout_constraintRight_toRightOf="@id/view_4" | 131 | app:layout_constraintRight_toRightOf="@id/view_4" |
131 | app:layout_constraintTop_toTopOf="@id/view_4" /> | 132 | app:layout_constraintTop_toTopOf="@id/view_4" /> |
132 | 133 | ||
133 | <ImageView | 134 | <ImageView |
135 | android:visibility="invisible" | ||
134 | android:layout_width="5.5dp" | 136 | android:layout_width="5.5dp" |
135 | android:layout_height="9.5dp" | 137 | android:layout_height="9.5dp" |
136 | android:layout_marginRight="15dp" | 138 | android:layout_marginRight="15dp" |
137 | android:background="@mipmap/ycaj" | 139 | android:background="@mipmap/ycaj" |
138 | app:layout_constraintBottom_toBottomOf="@id/tv_7" | 140 | app:layout_constraintBottom_toBottomOf="@id/tv_7" |
139 | app:layout_constraintRight_toRightOf="@id/view_4" | 141 | app:layout_constraintRight_toRightOf="@id/view_4" |
140 | app:layout_constraintTop_toTopOf="@id/tv_7" /> | 142 | app:layout_constraintTop_toTopOf="@id/tv_7" /> |
141 | 143 | ||
142 | <TextView | 144 | <TextView |
145 | android:visibility="invisible" | ||
143 | android:id="@+id/tv_7" | 146 | android:id="@+id/tv_7" |
144 | android:layout_width="wrap_content" | 147 | android:layout_width="wrap_content" |
145 | android:layout_height="wrap_content" | 148 | android:layout_height="wrap_content" |
146 | android:layout_marginTop="60dp" | 149 | android:layout_marginTop="60dp" |
147 | android:layout_marginRight="31dp" | 150 | android:layout_marginRight="31dp" |
148 | android:text="已设置" | 151 | android:text="已设置" |
149 | android:textColor="#666666" | 152 | android:textColor="#666666" |
150 | android:textSize="15dp" | 153 | android:textSize="15dp" |
151 | app:layout_constraintRight_toRightOf="@id/view_4" | 154 | app:layout_constraintRight_toRightOf="@id/view_4" |
152 | app:layout_constraintTop_toTopOf="@id/view_4" /> | 155 | app:layout_constraintTop_toTopOf="@id/view_4" /> |
153 | 156 | ||
154 | <Button | 157 | <Button |
155 | android:id="@+id/logout" | 158 | android:id="@+id/logout" |
156 | android:layout_width="315dp" | 159 | android:layout_width="315dp" |
157 | android:layout_height="50dp" | 160 | android:layout_height="50dp" |
158 | android:layout_marginBottom="120dp" | 161 | android:layout_marginBottom="120dp" |
159 | android:background="@drawable/bg_solid_btn" | 162 | android:background="@drawable/bg_solid_btn" |
160 | android:text="退出登录" | 163 | android:text="退出登录" |
161 | android:textColor="@color/white" | 164 | android:textColor="@color/white" |
162 | android:textSize="18dp" | 165 | android:textSize="18dp" |
163 | app:layout_constraintBottom_toBottomOf="parent" | 166 | app:layout_constraintBottom_toBottomOf="parent" |
164 | app:layout_constraintLeft_toLeftOf="parent" | 167 | app:layout_constraintLeft_toLeftOf="parent" |
165 | app:layout_constraintRight_toRightOf="parent" /> | 168 | app:layout_constraintRight_toRightOf="parent" /> |
166 | </androidx.constraintlayout.widget.ConstraintLayout> | 169 | </androidx.constraintlayout.widget.ConstraintLayout> |