Commit 9fbe0a119fcd9ce8a36304110c3b61161c3e3999
1 parent
4aa2829e26
Exists in
master
解决拍照无反应问题
Showing
2 changed files
with
9 additions
and
8 deletions
Show diff stats
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/FeedBackActivity.java
1 | package com.hjx.personalcenter.activity; | 1 | package com.hjx.personalcenter.activity; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.content.pm.PackageManager; | 4 | import android.content.pm.PackageManager; |
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.provider.MediaStore; | 9 | import android.provider.MediaStore; |
10 | import android.support.annotation.NonNull; | 10 | import android.support.annotation.NonNull; |
11 | import android.support.v4.content.FileProvider; | 11 | import android.support.v4.content.FileProvider; |
12 | import android.support.v7.app.AppCompatActivity; | 12 | import android.support.v7.app.AppCompatActivity; |
13 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
14 | import android.view.Gravity; | 14 | import android.view.Gravity; |
15 | import android.view.View; | 15 | import android.view.View; |
16 | import android.widget.AdapterView; | 16 | import android.widget.AdapterView; |
17 | import android.widget.EditText; | 17 | import android.widget.EditText; |
18 | import android.widget.ImageView; | 18 | import android.widget.ImageView; |
19 | import android.widget.TextView; | 19 | import android.widget.TextView; |
20 | import android.widget.Toast; | 20 | import android.widget.Toast; |
21 | 21 | ||
22 | import com.facebook.drawee.backends.pipeline.Fresco; | 22 | import com.facebook.drawee.backends.pipeline.Fresco; |
23 | import com.facebook.drawee.generic.GenericDraweeHierarchy; | 23 | import com.facebook.drawee.generic.GenericDraweeHierarchy; |
24 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; | 24 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; |
25 | import com.facebook.drawee.generic.RoundingParams; | 25 | import com.facebook.drawee.generic.RoundingParams; |
26 | import com.facebook.drawee.interfaces.DraweeController; | 26 | import com.facebook.drawee.interfaces.DraweeController; |
27 | import com.facebook.drawee.view.SimpleDraweeView; | 27 | import com.facebook.drawee.view.SimpleDraweeView; |
28 | import com.hjx.personalcenter.R; | 28 | import com.hjx.personalcenter.R; |
29 | import com.hjx.personalcenter.db.SaveParam; | 29 | import com.hjx.personalcenter.db.SaveParam; |
30 | import com.hjx.personalcenter.http.HttpManager; | 30 | import com.hjx.personalcenter.http.HttpManager; |
31 | import com.hjx.personalcenter.util.AlertUtils; | 31 | import com.hjx.personalcenter.util.AlertUtils; |
32 | import com.hjx.personalcenter.util.CropUtils; | 32 | import com.hjx.personalcenter.util.CropUtils; |
33 | import com.hjx.personalcenter.util.DialogPermission; | 33 | import com.hjx.personalcenter.util.DialogPermission; |
34 | import com.hjx.personalcenter.util.FileUtil; | 34 | import com.hjx.personalcenter.util.FileUtil; |
35 | import com.hjx.personalcenter.util.PermissionUtil; | 35 | import com.hjx.personalcenter.util.PermissionUtil; |
36 | import com.hjx.personalcenter.util.SharedPreferenceMark; | 36 | import com.hjx.personalcenter.util.SharedPreferenceMark; |
37 | import com.mylhyl.circledialog.CircleDialog; | 37 | import com.mylhyl.circledialog.CircleDialog; |
38 | import com.mylhyl.circledialog.callback.ConfigButton; | 38 | import com.mylhyl.circledialog.callback.ConfigButton; |
39 | import com.mylhyl.circledialog.callback.ConfigDialog; | 39 | import com.mylhyl.circledialog.callback.ConfigDialog; |
40 | import com.mylhyl.circledialog.params.ButtonParams; | 40 | import com.mylhyl.circledialog.params.ButtonParams; |
41 | import com.mylhyl.circledialog.params.DialogParams; | 41 | import com.mylhyl.circledialog.params.DialogParams; |
42 | 42 | ||
43 | import java.io.File; | 43 | import java.io.File; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Created by h on 2017/8/11. | 46 | * Created by h on 2017/8/11. |
47 | */ | 47 | */ |
48 | 48 | ||
49 | public class FeedBackActivity extends AppCompatActivity implements View.OnClickListener { | 49 | public class FeedBackActivity extends AppCompatActivity implements View.OnClickListener { |
50 | private ImageView iv_cance, iv_show, iv_take; | 50 | private ImageView iv_cance, iv_show, iv_take; |
51 | private EditText content, phone; | 51 | private EditText content, phone; |
52 | private TextView tv_sub; | 52 | private TextView tv_sub; |
53 | private static final int REQUEST_CODE_TAKE_PHOTO = 1; | 53 | private static final int REQUEST_CODE_TAKE_PHOTO = 1; |
54 | private static final int REQUEST_CODE_ALBUM = 2; | 54 | private static final int REQUEST_CODE_ALBUM = 2; |
55 | private static final int REQUEST_CODE_CROUP_PHOTO = 3; | 55 | private static final int REQUEST_CODE_CROUP_PHOTO = 3; |
56 | SimpleDraweeView mSimpleDraweeView; | 56 | private SimpleDraweeView mSimpleDraweeView; |
57 | String type = "个人中心"; | 57 | String type = "个人中心"; |
58 | private File file; | 58 | private File file; |
59 | private Uri uri; | 59 | private Uri uri; |
60 | 60 | ||
61 | @Override | 61 | @Override |
62 | protected void onCreate(Bundle savedInstanceState) { | 62 | protected void onCreate(Bundle savedInstanceState) { |
63 | super.onCreate(savedInstanceState); | 63 | super.onCreate(savedInstanceState); |
64 | Fresco.initialize(this); | 64 | Fresco.initialize(this); |
65 | setContentView(R.layout.activity_feedback); | 65 | setContentView(R.layout.activity_feedback); |
66 | initView(); | 66 | initView(); |
67 | initData(); | 67 | initData(); |
68 | initLister(); | 68 | initLister(); |
69 | } | 69 | } |
70 | 70 | ||
71 | private void initView() { | 71 | private void initView() { |
72 | iv_cance = (ImageView) findViewById(R.id.cancel); | 72 | iv_cance = (ImageView) findViewById(R.id.cancel); |
73 | mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.show_iv); | 73 | mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.show_iv); |
74 | iv_take = (ImageView) findViewById(R.id.iv_take); | 74 | iv_take = (ImageView) findViewById(R.id.iv_take); |
75 | content = (EditText) findViewById(R.id.feedback_content); | 75 | content = (EditText) findViewById(R.id.feedback_content); |
76 | phone = (EditText) findViewById(R.id.feedback_phone); | 76 | phone = (EditText) findViewById(R.id.feedback_phone); |
77 | tv_sub = (TextView) findViewById(R.id.feedback_sub); | 77 | tv_sub = (TextView) findViewById(R.id.feedback_sub); |
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | private void initData() { | 81 | private void initData() { |
82 | file = new File(FileUtil.getCachePath(this), "user-feedback.jpg"); | 82 | file = new File(FileUtil.getCachePath(this), "user-feedback.jpg"); |
83 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | 83 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
84 | uri = Uri.fromFile(file); | 84 | uri = Uri.fromFile(file); |
85 | } else { | 85 | } else { |
86 | //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) | 86 | //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) |
87 | uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); | 87 | uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); |
88 | } | 88 | } |
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
92 | private void initLister() { | 92 | private void initLister() { |
93 | iv_cance.setOnClickListener(this); | 93 | iv_cance.setOnClickListener(this); |
94 | iv_take.setOnClickListener(this); | 94 | iv_take.setOnClickListener(this); |
95 | tv_sub.setOnClickListener(this); | 95 | tv_sub.setOnClickListener(this); |
96 | mSimpleDraweeView.setOnClickListener(this); | 96 | mSimpleDraweeView.setOnClickListener(this); |
97 | 97 | ||
98 | } | 98 | } |
99 | 99 | ||
100 | @Override | 100 | @Override |
101 | public void onClick(View v) { | 101 | public void onClick(View v) { |
102 | String contents = content.getText().toString().trim(); | 102 | String contents = content.getText().toString().trim(); |
103 | String contants = phone.getText().toString().trim(); | 103 | String contants = phone.getText().toString().trim(); |
104 | switch (v.getId()) { | 104 | switch (v.getId()) { |
105 | case R.id.cancel: | 105 | case R.id.cancel: |
106 | finish(); | 106 | finish(); |
107 | break; | 107 | break; |
108 | case R.id.iv_take: | 108 | case R.id.iv_take: |
109 | choiceAvatar(); | 109 | choiceAvatar(); |
110 | break; | 110 | break; |
111 | case R.id.feedback_sub: | 111 | case R.id.feedback_sub: |
112 | //提交用户反馈 | 112 | //提交用户反馈 |
113 | if (TextUtils.isEmpty(contents)) { | 113 | if (TextUtils.isEmpty(contents)) { |
114 | AlertUtils.showToast(FeedBackActivity.this, "写下两点宝贵的意见或建议吧"); | 114 | AlertUtils.showToast(FeedBackActivity.this, "写下两点宝贵的意见或建议吧"); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); | 117 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); |
118 | try { | 118 | try { |
119 | HttpManager.getInstance().feedback(FeedBackActivity.this, userID, | 119 | HttpManager.getInstance().feedback(FeedBackActivity.this, userID, |
120 | contents,contants,file.getPath(),type); | 120 | contents,contants,file.getPath(),type); |
121 | } catch (Exception e) { | 121 | } catch (Exception e) { |
122 | e.printStackTrace(); | 122 | e.printStackTrace(); |
123 | } | 123 | } |
124 | break; | 124 | break; |
125 | case R.id.show_iv: | 125 | case R.id.show_iv: |
126 | 126 | ||
127 | 127 | ||
128 | break; | 128 | break; |
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | //拍摄头像 | 132 | //拍摄头像 |
133 | private void choiceAvatar() { | 133 | private void choiceAvatar() { |
134 | final String[] items = {"拍照", "从相册选择"}; | 134 | final String[] items = {"拍照", "从相册选择"}; |
135 | new CircleDialog.Builder(this) | 135 | new CircleDialog.Builder(this) |
136 | .configDialog(new ConfigDialog() { | 136 | .configDialog(new ConfigDialog() { |
137 | @Override | 137 | @Override |
138 | public void onConfig(DialogParams params) { | 138 | public void onConfig(DialogParams params) { |
139 | //增加弹出动画 | 139 | //增加弹出动画 |
140 | params.gravity = Gravity.CENTER; | 140 | params.gravity = Gravity.CENTER; |
141 | } | 141 | } |
142 | }) | 142 | }) |
143 | .setTitle("请选择图片来源") | 143 | .setTitle("请选择图片来源") |
144 | .setWidth(0.5f) | 144 | .setWidth(0.5f) |
145 | .setItems(items, new AdapterView.OnItemClickListener() { | 145 | .setItems(items, new AdapterView.OnItemClickListener() { |
146 | @Override | 146 | @Override |
147 | public void onItemClick(AdapterView<?> parent, View view, int | 147 | public void onItemClick(AdapterView<?> parent, View view, int |
148 | position, long id) { | 148 | position, long id) { |
149 | switch (position) { | 149 | switch (position) { |
150 | case 0: | 150 | case 0: |
151 | if (PermissionUtil.hasCameraPermission(FeedBackActivity.this)) { | 151 | if (PermissionUtil.hasCameraPermission(FeedBackActivity.this)) { |
152 | uploadAvatarFromPhotoRequest(); | 152 | uploadAvatarFromPhotoRequest(); |
153 | } | 153 | } |
154 | break; | 154 | break; |
155 | case 1: | 155 | case 1: |
156 | uploadAvatarFromAlbumRequest(); | 156 | uploadAvatarFromAlbumRequest(); |
157 | break; | 157 | break; |
158 | } | 158 | } |
159 | 159 | ||
160 | } | 160 | } |
161 | }) | 161 | }) |
162 | .setNegative("取消", null) | 162 | .setNegative("取消", null) |
163 | .configNegative(new ConfigButton() { | 163 | .configNegative(new ConfigButton() { |
164 | @Override | 164 | @Override |
165 | public void onConfig(ButtonParams params) { | 165 | public void onConfig(ButtonParams params) { |
166 | //取消按钮字体颜色 | 166 | //取消按钮字体颜色 |
167 | params.textColor = Color.RED; | 167 | params.textColor = Color.RED; |
168 | } | 168 | } |
169 | }) | 169 | }) |
170 | .show(); | 170 | .show(); |
171 | 171 | ||
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | //照相 | 175 | //照相 |
176 | private void uploadAvatarFromPhotoRequest() { | 176 | private void uploadAvatarFromPhotoRequest() { |
177 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 177 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
178 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 178 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
179 | intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); | 179 | intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); |
180 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | 180 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
181 | startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO); | 181 | startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO); |
182 | } | 182 | } |
183 | 183 | ||
184 | //选择图库 | 184 | //选择图库 |
185 | private void uploadAvatarFromAlbumRequest() { | 185 | private void uploadAvatarFromAlbumRequest() { |
186 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 186 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
187 | photoPickerIntent.setType("image/*"); | 187 | photoPickerIntent.setType("image/*"); |
188 | startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM); | 188 | startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM); |
189 | } | 189 | } |
190 | 190 | ||
191 | //回掉 | 191 | //回掉 |
192 | @Override | 192 | @Override |
193 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 193 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
194 | super.onActivityResult(requestCode, resultCode, data); | 194 | super.onActivityResult(requestCode, resultCode, data); |
195 | if (resultCode != -1) { | 195 | if (resultCode != -1) { |
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | if (requestCode == REQUEST_CODE_ALBUM && data != null) { | 198 | if (requestCode == REQUEST_CODE_ALBUM && data != null) { |
199 | Uri newUri; | 199 | Uri newUri; |
200 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | 200 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
201 | newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData())); | 201 | newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData())); |
202 | } else { | 202 | } else { |
203 | newUri = data.getData(); | 203 | newUri = data.getData(); |
204 | } | 204 | } |
205 | if (newUri != null) { | 205 | if (newUri != null) { |
206 | //uploadAvatarFromPhoto(); | 206 | //uploadAvatarFromPhoto(); |
207 | //裁剪图片 | 207 | //裁剪图片 |
208 | startPhotoZoom(newUri); | 208 | startPhotoZoom(newUri); |
209 | } else { | 209 | } else { |
210 | Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show(); | 210 | Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show(); |
211 | } | 211 | } |
212 | } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) { | 212 | } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) { |
213 | uploadAvatarFromPhoto(); | 213 | uploadAvatarFromPhoto(); |
214 | } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) { | 214 | } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) { |
215 | uploadAvatarFromPhoto(); | 215 | uploadAvatarFromPhoto(); |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | private void uploadAvatarFromPhoto() { | 219 | private void uploadAvatarFromPhoto() { |
220 | compressAndUploadAvatar(file.getPath()); | 220 | compressAndUploadAvatar(file.getPath()); |
221 | 221 | ||
222 | } | 222 | } |
223 | 223 | ||
224 | private void compressAndUploadAvatar(String fileSrc) { | 224 | private void compressAndUploadAvatar(String fileSrc) { |
225 | 225 | ||
226 | 226 | ||
227 | //上传到服务器 | 227 | //上传到服务器 |
228 | 228 | ||
229 | final File cover = FileUtil.getSmallBitmap(this, fileSrc); | 229 | final File cover = FileUtil.getSmallBitmap(this, fileSrc); |
230 | String mimeType = "image/*"; | 230 | String mimeType = "image/*"; |
231 | //requestBody = RequestBody.create(MediaType.parse(mimeType), file); | 231 | //requestBody = RequestBody.create(MediaType.parse(mimeType), file); |
232 | //String fileName = cover.getName(); | 232 | //String fileName = cover.getName(); |
233 | //HttpManager.getInstance().header(this, fileSrc); | 233 | //HttpManager.getInstance().header(this, fileSrc); |
234 | //photo = MultipartBody.Part.createFormData("portrait", fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()), requestBody); | 234 | //photo = MultipartBody.Part.createFormData("portrait", fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()), requestBody); |
235 | //Fresco设置圆形头像 | 235 | //Fresco设置圆形头像 |
236 | GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); | 236 | GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); |
237 | GenericDraweeHierarchy hierarchy = builder | 237 | GenericDraweeHierarchy hierarchy = builder |
238 | .setDesiredAspectRatio(1f) | 238 | .setDesiredAspectRatio(1f) |
239 | .setFailureImage(R.mipmap.blank) | 239 | .setFailureImage(R.mipmap.blank) |
240 | //圆形头像 | 240 | //圆形头像 |
241 | .setRoundingParams(RoundingParams.fromCornersRadius(0.7f)) | 241 | .setRoundingParams(RoundingParams.fromCornersRadius(0.7f)) |
242 | .build(); | 242 | .build(); |
243 | 243 | ||
244 | //加载本地图片 | 244 | //加载本地图片 |
245 | Uri uri = Uri.fromFile(cover); | 245 | Uri uri = Uri.fromFile(cover); |
246 | DraweeController controller = Fresco.newDraweeControllerBuilder() | 246 | DraweeController controller = Fresco.newDraweeControllerBuilder() |
247 | .setOldController(mSimpleDraweeView.getController()) | 247 | .setOldController(mSimpleDraweeView.getController()) |
248 | .setUri(uri) | 248 | .setUri(uri) |
249 | .build(); | 249 | .build(); |
250 | mSimpleDraweeView.setHierarchy(hierarchy); | 250 | mSimpleDraweeView.setHierarchy(hierarchy); |
251 | mSimpleDraweeView.setController(controller); | 251 | mSimpleDraweeView.setController(controller); |
252 | 252 | ||
253 | } | 253 | } |
254 | 254 | ||
255 | public void startPhotoZoom(Uri uri) { | 255 | public void startPhotoZoom(Uri uri) { |
256 | Intent intent = new Intent("com.android.camera.action.CROP"); | 256 | Intent intent = new Intent("com.android.camera.action.CROP"); |
257 | intent.setDataAndType(uri, "image/*"); | 257 | intent.setDataAndType(uri, "image/*"); |
258 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 258 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
259 | intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面. | 259 | intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面. |
260 | intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例. | 260 | intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例. |
261 | intent.putExtra("aspectY", 1);// x:y=1:1 | 261 | intent.putExtra("aspectY", 1);// x:y=1:1 |
262 | // intent.putExtra("outputX", 400);//图片输出大小 | 262 | // intent.putExtra("outputX", 400);//图片输出大小 |
263 | // intent.putExtra("outputY", 400); | 263 | // intent.putExtra("outputY", 400); |
264 | intent.putExtra("output", Uri.fromFile(file)); | 264 | intent.putExtra("output", Uri.fromFile(file)); |
265 | intent.putExtra("outputFormat", "JPEG");// 返回格式 | 265 | intent.putExtra("outputFormat", "JPEG");// 返回格式 |
266 | startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO); | 266 | startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO); |
267 | } | 267 | } |
268 | 268 | ||
269 | @Override | 269 | @Override |
270 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | 270 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
271 | switch (requestCode) { | 271 | switch (requestCode) { |
272 | 272 | ||
273 | case PermissionUtil.REQUEST_SHOWCAMERA: | 273 | case PermissionUtil.REQUEST_SHOWCAMERA: |
274 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | 274 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
275 | // Permission Granted | 275 | // Permission Granted |
276 | uploadAvatarFromPhotoRequest(); | 276 | uploadAvatarFromPhotoRequest(); |
277 | 277 | ||
278 | } else { | 278 | } else { |
279 | if (!SharedPreferenceMark.getHasShowCamera()) { | 279 | if (!SharedPreferenceMark.getHasShowCamera()) { |
280 | SharedPreferenceMark.setHasShowCamera(true); | 280 | SharedPreferenceMark.setHasShowCamera(true); |
281 | new DialogPermission(this, "关闭摄像头权限影响扫描功能"); | 281 | new DialogPermission(this, "关闭摄像头权限影响扫描功能"); |
282 | 282 | ||
283 | } else { | 283 | } else { |
284 | Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT) | 284 | Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT) |
285 | .show(); | 285 | .show(); |
286 | } | 286 | } |
287 | } | 287 | } |
288 | break; | 288 | break; |
289 | default: | 289 | default: |
290 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); | 290 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/MainActivity.java
1 | package com.hjx.personalcenter.activity; | 1 | package com.hjx.personalcenter.activity; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.content.Intent; | 4 | import android.content.Intent; |
5 | import android.content.pm.PackageManager; | 5 | import android.content.pm.PackageManager; |
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.Handler; | 9 | import android.os.Handler; |
10 | import android.os.Message; | 10 | import android.os.Message; |
11 | import android.provider.MediaStore; | 11 | import android.provider.MediaStore; |
12 | import android.support.annotation.NonNull; | 12 | import android.support.annotation.NonNull; |
13 | import android.support.v4.content.FileProvider; | 13 | import android.support.v4.content.FileProvider; |
14 | import android.support.v7.app.AppCompatActivity; | 14 | import android.support.v7.app.AppCompatActivity; |
15 | import android.support.v7.widget.LinearLayoutManager; | 15 | import android.support.v7.widget.LinearLayoutManager; |
16 | import android.support.v7.widget.RecyclerView; | 16 | import android.support.v7.widget.RecyclerView; |
17 | import android.util.Log; | 17 | import android.util.Log; |
18 | import android.view.KeyEvent; | 18 | import android.view.KeyEvent; |
19 | import android.view.View; | 19 | import android.view.View; |
20 | import android.widget.ImageView; | 20 | import android.widget.ImageView; |
21 | import android.widget.LinearLayout; | 21 | import android.widget.LinearLayout; |
22 | import android.widget.TextView; | 22 | import android.widget.TextView; |
23 | import android.widget.Toast; | 23 | import android.widget.Toast; |
24 | 24 | ||
25 | import com.facebook.drawee.backends.pipeline.Fresco; | 25 | import com.facebook.drawee.backends.pipeline.Fresco; |
26 | import com.facebook.drawee.generic.GenericDraweeHierarchy; | 26 | import com.facebook.drawee.generic.GenericDraweeHierarchy; |
27 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; | 27 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; |
28 | import com.facebook.drawee.generic.RoundingParams; | 28 | import com.facebook.drawee.generic.RoundingParams; |
29 | import com.facebook.drawee.interfaces.DraweeController; | 29 | import com.facebook.drawee.interfaces.DraweeController; |
30 | import com.facebook.drawee.view.SimpleDraweeView; | 30 | import com.facebook.drawee.view.SimpleDraweeView; |
31 | import com.hjx.personalcenter.R; | 31 | import com.hjx.personalcenter.R; |
32 | import com.hjx.personalcenter.adapter.GalleryAdapter; | 32 | import com.hjx.personalcenter.adapter.GalleryAdapter; |
33 | import com.hjx.personalcenter.adapter.VideoAdapter; | 33 | import com.hjx.personalcenter.adapter.VideoAdapter; |
34 | import com.hjx.personalcenter.customdialog.HeadDialog; | 34 | import com.hjx.personalcenter.customdialog.HeadDialog; |
35 | import com.hjx.personalcenter.customdialog.RecyclerViewSpaceItem; | 35 | import com.hjx.personalcenter.customdialog.RecyclerViewSpaceItem; |
36 | import com.hjx.personalcenter.db.SaveParam; | 36 | import com.hjx.personalcenter.db.SaveParam; |
37 | import com.hjx.personalcenter.http.HttpCode; | 37 | import com.hjx.personalcenter.http.HttpCode; |
38 | import com.hjx.personalcenter.http.HttpManager; | 38 | import com.hjx.personalcenter.http.HttpManager; |
39 | import com.hjx.personalcenter.interfaces.DialogCallBack; | 39 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
40 | import com.hjx.personalcenter.model.DefautPublishInfo; | 40 | import com.hjx.personalcenter.model.DefautPublishInfo; |
41 | import com.hjx.personalcenter.model.PesonalInfo; | 41 | import com.hjx.personalcenter.model.PesonalInfo; |
42 | import com.hjx.personalcenter.model.SignInfo; | 42 | import com.hjx.personalcenter.model.SignInfo; |
43 | import com.hjx.personalcenter.model.VideoInfo; | 43 | import com.hjx.personalcenter.model.VideoInfo; |
44 | import com.hjx.personalcenter.update.UpdateChecker; | 44 | import com.hjx.personalcenter.update.UpdateChecker; |
45 | import com.hjx.personalcenter.util.AlertUtils; | 45 | import com.hjx.personalcenter.util.AlertUtils; |
46 | import com.hjx.personalcenter.util.BrithdayStar; | 46 | import com.hjx.personalcenter.util.BrithdayStar; |
47 | import com.hjx.personalcenter.util.CropUtils; | 47 | import com.hjx.personalcenter.util.CropUtils; |
48 | import com.hjx.personalcenter.util.DialogPermission; | 48 | import com.hjx.personalcenter.util.DialogPermission; |
49 | import com.hjx.personalcenter.util.FileUtil; | 49 | import com.hjx.personalcenter.util.FileUtil; |
50 | import com.hjx.personalcenter.util.GetDevicesUtil; | 50 | import com.hjx.personalcenter.util.GetDevicesUtil; |
51 | import com.hjx.personalcenter.util.PermissionUtil; | 51 | import com.hjx.personalcenter.util.PermissionUtil; |
52 | import com.hjx.personalcenter.util.SharedPreferenceMark; | 52 | import com.hjx.personalcenter.util.SharedPreferenceMark; |
53 | import com.mylhyl.circledialog.CircleDialog; | 53 | import com.mylhyl.circledialog.CircleDialog; |
54 | import com.mylhyl.circledialog.callback.ConfigInput; | 54 | import com.mylhyl.circledialog.callback.ConfigInput; |
55 | import com.mylhyl.circledialog.params.InputParams; | 55 | import com.mylhyl.circledialog.params.InputParams; |
56 | import com.mylhyl.circledialog.view.listener.OnInputClickListener; | 56 | import com.mylhyl.circledialog.view.listener.OnInputClickListener; |
57 | import com.zaaach.toprightmenu.MenuItem; | 57 | import com.zaaach.toprightmenu.MenuItem; |
58 | import com.zaaach.toprightmenu.TopRightMenu; | 58 | import com.zaaach.toprightmenu.TopRightMenu; |
59 | 59 | ||
60 | import org.json.JSONException; | 60 | import org.json.JSONException; |
61 | import org.json.JSONObject; | 61 | import org.json.JSONObject; |
62 | 62 | ||
63 | import java.io.File; | 63 | import java.io.File; |
64 | import java.io.UnsupportedEncodingException; | 64 | import java.io.UnsupportedEncodingException; |
65 | import java.util.ArrayList; | 65 | import java.util.ArrayList; |
66 | import java.util.List; | 66 | import java.util.List; |
67 | 67 | ||
68 | public class MainActivity extends AppCompatActivity implements View.OnClickListener, DialogCallBack.CallBackView { | 68 | public class MainActivity extends AppCompatActivity implements View.OnClickListener, DialogCallBack.CallBackView { |
69 | private ImageView iv_imformatioan, iv_look_card, iv_setting, iv_sign, iv_sex; | 69 | private ImageView iv_imformatioan, iv_look_card, iv_setting, iv_sign, iv_sex; |
70 | private TextView tv_edit_presoninfo, tv_sign, | 70 | private TextView tv_edit_presoninfo, tv_sign, |
71 | tv_username, tv_username1, tv_mygad, tv_sex, tv_useinfo_adress, tv_useinfo_birthday, | 71 | tv_username, tv_username1, tv_mygad, tv_sex, tv_useinfo_adress, tv_useinfo_birthday, |
72 | tv_useinfo_qq, tv_useinfo_school, tv_useinfo_gender, tv_yangji; | 72 | tv_useinfo_qq, tv_useinfo_school, tv_useinfo_gender, tv_yangji; |
73 | private LinearLayout linel_mycuoti, linel_mynote, linel_mycollege, linel_myclass; | 73 | private LinearLayout linel_mycuoti, linel_mynote, linel_mycollege, linel_myclass; |
74 | private TopRightMenu mTopRightMenu; | 74 | private TopRightMenu mTopRightMenu; |
75 | //水平滑动 | 75 | //水平滑动 |
76 | private RecyclerView mRecyclerView; | 76 | private RecyclerView mRecyclerView; |
77 | private RecyclerView mRecyclerViewpublish; | 77 | private RecyclerView mRecyclerViewpublish; |
78 | private VideoAdapter RecyclerViewadapter; | 78 | private VideoAdapter RecyclerViewadapter; |
79 | private GalleryAdapter RecyclerViewadapterpublish; | 79 | private GalleryAdapter RecyclerViewadapterpublish; |
80 | private ArrayList<DefautPublishInfo.DataBean> defautPublishInfos = new ArrayList<>(); | 80 | private ArrayList<DefautPublishInfo.DataBean> defautPublishInfos = new ArrayList<>(); |
81 | 81 | ||
82 | private ArrayList<VideoInfo.DataBean> videoinfo = new ArrayList<>(); | 82 | private ArrayList<VideoInfo.DataBean> videoinfo = new ArrayList<>(); |
83 | private boolean showIcon = true; | 83 | private boolean showIcon = true; |
84 | private boolean dimBg = true; | 84 | private boolean dimBg = true; |
85 | private boolean needAnim = true; | 85 | private boolean needAnim = true; |
86 | private static final int REQUEST_CODE_TAKE_PHOTO = 1; | 86 | private static final int REQUEST_CODE_TAKE_PHOTO = 1; |
87 | private static final int REQUEST_CODE_ALBUM = 2; | 87 | private static final int REQUEST_CODE_ALBUM = 2; |
88 | private static final int REQUEST_CODE_CROUP_PHOTO = 3; | 88 | private static final int REQUEST_CODE_CROUP_PHOTO = 3; |
89 | SimpleDraweeView mSimpleDraweeView; | 89 | SimpleDraweeView mSimpleDraweeView; |
90 | private File file; | 90 | private File file; |
91 | private Uri uri; | 91 | private Uri uri; |
92 | Handler handler = new Handler() { | 92 | Handler handler = new Handler() { |
93 | @Override | 93 | @Override |
94 | public void handleMessage(Message msg) { | 94 | public void handleMessage(Message msg) { |
95 | super.handleMessage(msg); | 95 | super.handleMessage(msg); |
96 | switch (msg.what) { | 96 | switch (msg.what) { |
97 | case HttpCode.GETINFO: | 97 | case HttpCode.GETINFO: |
98 | PesonalInfo.DataBean cardinfoBean = (PesonalInfo.DataBean) msg.obj; | 98 | PesonalInfo.DataBean cardinfoBean = (PesonalInfo.DataBean) msg.obj; |
99 | tv_username.setText(cardinfoBean.getNickName()); | 99 | tv_username.setText(cardinfoBean.getNickName()); |
100 | tv_username1.setText(cardinfoBean.getNickName()); | 100 | tv_username1.setText(cardinfoBean.getNickName()); |
101 | tv_useinfo_adress.setText(cardinfoBean.getRegion().getRegionName()); | 101 | tv_useinfo_adress.setText(cardinfoBean.getRegion().getRegionName()); |
102 | tv_useinfo_birthday.setText(cardinfoBean.getBirthday()); | 102 | tv_useinfo_birthday.setText(cardinfoBean.getBirthday()); |
103 | tv_useinfo_qq.setText(cardinfoBean.getQq()); | 103 | tv_useinfo_qq.setText(cardinfoBean.getQq()); |
104 | tv_useinfo_school.setText(cardinfoBean.getSchool().getSchoolName()); | 104 | tv_useinfo_school.setText(cardinfoBean.getSchool().getSchoolName()); |
105 | tv_useinfo_gender.setText(cardinfoBean.getGrade().getGradeName()); | 105 | tv_useinfo_gender.setText(cardinfoBean.getGrade().getGradeName()); |
106 | String sex = cardinfoBean.getGender(); | 106 | String sex = cardinfoBean.getGender(); |
107 | if ("0".equals(sex)) { | 107 | if ("0".equals(sex)) { |
108 | tv_sex.setText("男"); | 108 | tv_sex.setText("男"); |
109 | iv_sex.setImageResource(R.mipmap.men); | 109 | iv_sex.setImageResource(R.mipmap.men); |
110 | } else { | 110 | } else { |
111 | tv_sex.setText("女"); | 111 | tv_sex.setText("女"); |
112 | iv_sex.setImageResource(R.mipmap.women); | 112 | iv_sex.setImageResource(R.mipmap.women); |
113 | } | 113 | } |
114 | mSimpleDraweeView.setImageURI(cardinfoBean.getPortrait()); | 114 | mSimpleDraweeView.setImageURI(cardinfoBean.getPortrait()); |
115 | //加载星座 | 115 | //加载星座 |
116 | BrithdayStar brithdayStar = new BrithdayStar(); | 116 | BrithdayStar brithdayStar = new BrithdayStar(); |
117 | if (cardinfoBean.getBirthday() ==null||"".equals(cardinfoBean.getBirthday())) { | 117 | if (cardinfoBean.getBirthday() ==null||"".equals(cardinfoBean.getBirthday())) { |
118 | tv_mygad.setText(""); | 118 | tv_mygad.setText(""); |
119 | } else { | 119 | } else { |
120 | String xiongzuo = brithdayStar.getConstellations(cardinfoBean.getBirthday()); | 120 | String xiongzuo = brithdayStar.getConstellations(cardinfoBean.getBirthday()); |
121 | tv_mygad.setText(xiongzuo); | 121 | tv_mygad.setText(xiongzuo); |
122 | } | 122 | } |
123 | //保存个人信息 | 123 | //保存个人信息 |
124 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTUSERNAME,cardinfoBean.getNickName()); | 124 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTUSERNAME,cardinfoBean.getNickName()); |
125 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTGRADES,cardinfoBean.getGrade().getGradeName()); | 125 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTGRADES,cardinfoBean.getGrade().getGradeName()); |
126 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSCHOOL,cardinfoBean.getSchool().getSchoolName()); | 126 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSCHOOL,cardinfoBean.getSchool().getSchoolName()); |
127 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTCONSTELLATION,cardinfoBean.getBirthday()); | 127 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTCONSTELLATION,cardinfoBean.getBirthday()); |
128 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSEX,tv_sex.getText().toString()); | 128 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSEX,tv_sex.getText().toString()); |
129 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTQQ,cardinfoBean.getQq()); | 129 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTQQ,cardinfoBean.getQq()); |
130 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTADRESS,cardinfoBean.getRegion().getRegionName()); | 130 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTADRESS,cardinfoBean.getRegion().getRegionName()); |
131 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTXINGZUO,cardinfoBean.getAddress()); | 131 | SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTXINGZUO,cardinfoBean.getAddress()); |
132 | String graderID = cardinfoBean.getGrade().getGradeId(); | 132 | String graderID = cardinfoBean.getGrade().getGradeId(); |
133 | Log.e("test","nianji"+graderID); | 133 | Log.e("test","nianji"+graderID); |
134 | SaveParam.getInstance().saveLoginParam(MainActivity.this, SaveParam.GRADENS, graderID); | 134 | SaveParam.getInstance().saveLoginParam(MainActivity.this, SaveParam.GRADENS, graderID); |
135 | String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId"); | 135 | String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId"); |
136 | //账户类型 | 136 | //账户类型 |
137 | String accounts = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT); | 137 | String accounts = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT); |
138 | String childID = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.CHILDSID); | 138 | String childID = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.CHILDSID); |
139 | 139 | ||
140 | try { | 140 | try { |
141 | Object auserID; | 141 | Object auserID; |
142 | int type; | 142 | int type; |
143 | int graderIDs = Integer.parseInt(graderID); | 143 | int graderIDs = Integer.parseInt(graderID); |
144 | if ("2".equals(accounts)) { | 144 | if ("2".equals(accounts)) { |
145 | type = Integer.parseInt(accounts); | 145 | type = Integer.parseInt(accounts); |
146 | auserID = childID; | 146 | auserID = childID; |
147 | } else { | 147 | } else { |
148 | type = Integer.parseInt(accounts); | 148 | type = Integer.parseInt(accounts); |
149 | auserID = Long.parseLong(userID); | 149 | auserID = Long.parseLong(userID); |
150 | } | 150 | } |
151 | //获取版本信息 | 151 | //获取版本信息 |
152 | //Log.e("test","nianji"+graderID+auserID+"sssss"+type); | 152 | //Log.e("test","nianji"+graderID+auserID+"sssss"+type); |
153 | HttpManager.getInstance().getpublishinfo(MainActivity.this, auserID, graderIDs, type, handler); | 153 | HttpManager.getInstance().getpublishinfo(MainActivity.this, auserID, graderIDs, type, handler); |
154 | 154 | ||
155 | } catch (NumberFormatException e) { | 155 | } catch (NumberFormatException e) { |
156 | e.printStackTrace(); | 156 | e.printStackTrace(); |
157 | } | 157 | } |
158 | 158 | ||
159 | break; | 159 | break; |
160 | case HttpCode.SIGN: | 160 | case HttpCode.SIGN: |
161 | SignInfo.DataBean dataBean = (SignInfo.DataBean) msg.obj; | 161 | SignInfo.DataBean dataBean = (SignInfo.DataBean) msg.obj; |
162 | if (dataBean.getSignature() == null) { | 162 | if (dataBean.getSignature() == null) { |
163 | tv_sign.setText("你还未设置个性签名"); | 163 | tv_sign.setText("你还未设置个性签名"); |
164 | } else { | 164 | } else { |
165 | tv_sign.setText(dataBean.getSignature()); | 165 | tv_sign.setText(dataBean.getSignature()); |
166 | } | 166 | } |
167 | 167 | ||
168 | break; | 168 | break; |
169 | case HttpCode.PUBLISH_SUCESS: | 169 | case HttpCode.PUBLISH_SUCESS: |
170 | defautPublishInfos.clear(); | 170 | defautPublishInfos.clear(); |
171 | defautPublishInfos.addAll((List<DefautPublishInfo.DataBean>) msg.obj); | 171 | defautPublishInfos.addAll((List<DefautPublishInfo.DataBean>) msg.obj); |
172 | RecyclerViewadapterpublish.notifyDataSetChanged(); | 172 | RecyclerViewadapterpublish.notifyDataSetChanged(); |
173 | break; | 173 | break; |
174 | case HttpCode.GETVIDIO_SUCESS: | 174 | case HttpCode.GETVIDIO_SUCESS: |
175 | videoinfo.clear(); | 175 | videoinfo.clear(); |
176 | videoinfo.addAll((List<VideoInfo.DataBean>) msg.obj); | 176 | videoinfo.addAll((List<VideoInfo.DataBean>) msg.obj); |
177 | RecyclerViewadapter.notifyDataSetChanged(); | 177 | RecyclerViewadapter.notifyDataSetChanged(); |
178 | break; | 178 | break; |
179 | case HttpCode.SUCHCARDINFOONE: | 179 | case HttpCode.SUCHCARDINFOONE: |
180 | JSONObject jsonObject; | 180 | JSONObject jsonObject; |
181 | String status; | 181 | String status; |
182 | try { | 182 | try { |
183 | jsonObject = new JSONObject((String) msg.obj); | 183 | jsonObject = new JSONObject((String) msg.obj); |
184 | status = jsonObject.getString("status"); | 184 | status = jsonObject.getString("status"); |
185 | if (status.equals("1")) { | 185 | if (status.equals("1")) { |
186 | tv_yangji.setVisibility(View.GONE); | 186 | tv_yangji.setVisibility(View.GONE); |
187 | iv_look_card.setVisibility(View.VISIBLE); | 187 | iv_look_card.setVisibility(View.VISIBLE); |
188 | } else if (status.equals("2001")) { | 188 | } else if (status.equals("2001")) { |
189 | tv_yangji.setVisibility(View.GONE); | 189 | tv_yangji.setVisibility(View.GONE); |
190 | iv_look_card.setVisibility(View.VISIBLE); | 190 | iv_look_card.setVisibility(View.VISIBLE); |
191 | AlertUtils.showToast(MainActivity.this, "您的机器还没有保卡信息,请重新登录"); | 191 | AlertUtils.showToast(MainActivity.this, "您的机器还没有保卡信息,请重新登录"); |
192 | SaveParam.getInstance().clearData(MainActivity.this); | 192 | SaveParam.getInstance().clearData(MainActivity.this); |
193 | Intent settingintent = new Intent(); | 193 | Intent settingintent = new Intent(); |
194 | settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class); | 194 | settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class); |
195 | startActivity(settingintent); | 195 | startActivity(settingintent); |
196 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 196 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
197 | finish(); | 197 | finish(); |
198 | } else if (status.equals("2002")) { | 198 | } else if (status.equals("2002")) { |
199 | iv_look_card.setVisibility(View.GONE); | 199 | iv_look_card.setVisibility(View.GONE); |
200 | tv_yangji.setVisibility(View.VISIBLE); | 200 | tv_yangji.setVisibility(View.VISIBLE); |
201 | 201 | ||
202 | } else { | 202 | } else { |
203 | AlertUtils.showToast(MainActivity.this, "服务器连接失败"); | 203 | AlertUtils.showToast(MainActivity.this, "服务器连接失败"); |
204 | } | 204 | } |
205 | } catch (JSONException e) { | 205 | } catch (JSONException e) { |
206 | e.printStackTrace(); | 206 | e.printStackTrace(); |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | } | 210 | } |
211 | } | 211 | } |
212 | }; | 212 | }; |
213 | 213 | ||
214 | @Override | 214 | @Override |
215 | protected void onCreate(Bundle savedInstanceState) { | 215 | protected void onCreate(Bundle savedInstanceState) { |
216 | super.onCreate(savedInstanceState); | 216 | super.onCreate(savedInstanceState); |
217 | Fresco.initialize(this); | 217 | Fresco.initialize(this); |
218 | setContentView(R.layout.activity_main); | 218 | setContentView(R.layout.activity_main); |
219 | SysApplication.getInstance().addActivity(this); | 219 | SysApplication.getInstance().addActivity(this); |
220 | initView(); | 220 | initView(); |
221 | initData(); | 221 | initData(); |
222 | initLister(); | 222 | initLister(); |
223 | updateVersion(); | 223 | updateVersion(); |
224 | } | 224 | } |
225 | 225 | ||
226 | //////版本更新 | 226 | //////版本更新 |
227 | private void updateVersion() { | 227 | private void updateVersion() { |
228 | UpdateChecker updateChecker = new UpdateChecker(this); | 228 | UpdateChecker updateChecker = new UpdateChecker(this); |
229 | updateChecker.checkForUpdates(); | 229 | updateChecker.checkForUpdates(); |
230 | 230 | ||
231 | 231 | ||
232 | } | 232 | } |
233 | 233 | ||
234 | private void initView() { | 234 | private void initView() { |
235 | iv_imformatioan = (ImageView) findViewById(R.id.iv_imformatioan); | 235 | iv_imformatioan = (ImageView) findViewById(R.id.iv_imformatioan); |
236 | iv_look_card = (ImageView) findViewById(R.id.iv_look_card); | 236 | iv_look_card = (ImageView) findViewById(R.id.iv_look_card); |
237 | tv_edit_presoninfo = (TextView) findViewById(R.id.tv_edit_presoninfo); | 237 | tv_edit_presoninfo = (TextView) findViewById(R.id.tv_edit_presoninfo); |
238 | iv_setting = (ImageView) findViewById(R.id.iv_setting); | 238 | iv_setting = (ImageView) findViewById(R.id.iv_setting); |
239 | iv_sign = (ImageView) findViewById(R.id.iv_sign); | 239 | iv_sign = (ImageView) findViewById(R.id.iv_sign); |
240 | tv_sign = (TextView) findViewById(R.id.tv_sign); | 240 | tv_sign = (TextView) findViewById(R.id.tv_sign); |
241 | //头像 | 241 | //头像 |
242 | mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.iv_head); | 242 | mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.iv_head); |
243 | //初始化个人信息 | 243 | //初始化个人信息 |
244 | iv_sex = (ImageView) findViewById(R.id.iv_sex); | 244 | iv_sex = (ImageView) findViewById(R.id.iv_sex); |
245 | tv_username = (TextView) findViewById(R.id.tv_username); | 245 | tv_username = (TextView) findViewById(R.id.tv_username); |
246 | tv_username1 = (TextView) findViewById(R.id.tv_username1); | 246 | tv_username1 = (TextView) findViewById(R.id.tv_username1); |
247 | tv_mygad = (TextView) findViewById(R.id.tv_mygad); | 247 | tv_mygad = (TextView) findViewById(R.id.tv_mygad); |
248 | tv_sex = (TextView) findViewById(R.id.tv_sex); | 248 | tv_sex = (TextView) findViewById(R.id.tv_sex); |
249 | tv_useinfo_adress = (TextView) findViewById(R.id.tv_useinfo_adress); | 249 | tv_useinfo_adress = (TextView) findViewById(R.id.tv_useinfo_adress); |
250 | tv_useinfo_birthday = (TextView) findViewById(R.id.tv_useinfo_birthday); | 250 | tv_useinfo_birthday = (TextView) findViewById(R.id.tv_useinfo_birthday); |
251 | tv_useinfo_qq = (TextView) findViewById(R.id.tv_useinfo_qq); | 251 | tv_useinfo_qq = (TextView) findViewById(R.id.tv_useinfo_qq); |
252 | tv_useinfo_school = (TextView) findViewById(R.id.tv_useinfo_school); | 252 | tv_useinfo_school = (TextView) findViewById(R.id.tv_useinfo_school); |
253 | tv_useinfo_gender = (TextView) findViewById(R.id.tv_useinfo_gender); | 253 | tv_useinfo_gender = (TextView) findViewById(R.id.tv_useinfo_gender); |
254 | tv_yangji = (TextView) findViewById(R.id.tv_yangji); | 254 | tv_yangji = (TextView) findViewById(R.id.tv_yangji); |
255 | //跳转其他应用 | 255 | //跳转其他应用 |
256 | linel_mycuoti = (LinearLayout) findViewById(R.id.linel_mycuoti); | 256 | linel_mycuoti = (LinearLayout) findViewById(R.id.linel_mycuoti); |
257 | linel_mynote = (LinearLayout) findViewById(R.id.linel_mynote); | 257 | linel_mynote = (LinearLayout) findViewById(R.id.linel_mynote); |
258 | linel_mycollege = (LinearLayout) findViewById(R.id.linel_mycollege); | 258 | linel_mycollege = (LinearLayout) findViewById(R.id.linel_mycollege); |
259 | linel_myclass = (LinearLayout) findViewById(R.id.linel_myclass); | 259 | linel_myclass = (LinearLayout) findViewById(R.id.linel_myclass); |
260 | // | 260 | // |
261 | mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal); | 261 | mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal); |
262 | mRecyclerViewpublish = (RecyclerView) findViewById(R.id.id_recyclerview_pubish); | 262 | mRecyclerViewpublish = (RecyclerView) findViewById(R.id.id_recyclerview_pubish); |
263 | 263 | ||
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | private void initData() { | 267 | private void initData() { |
268 | //初始化图片 | 268 | file = new File(FileUtil.getCachePath(this), "user-avatar.jpg"); |
269 | file = new File(FileUtil.getCachePath(this), "user-header.jpg"); | ||
270 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | 269 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
271 | uri = Uri.fromFile(file); | 270 | uri = Uri.fromFile(file); |
272 | } else { | 271 | } else { |
273 | //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) | 272 | //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) |
274 | uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); | 273 | uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); |
275 | } | 274 | } |
276 | //设置布局管理器 | 275 | //设置布局管理器 |
277 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); | 276 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); |
278 | linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); | 277 | linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
279 | 278 | ||
280 | LinearLayoutManager linearLayoutManagerpublish = new LinearLayoutManager(this); | 279 | LinearLayoutManager linearLayoutManagerpublish = new LinearLayoutManager(this); |
281 | linearLayoutManagerpublish.setOrientation(LinearLayoutManager.HORIZONTAL); | 280 | linearLayoutManagerpublish.setOrientation(LinearLayoutManager.HORIZONTAL); |
282 | 281 | ||
283 | mRecyclerView.setLayoutManager(linearLayoutManager); | 282 | mRecyclerView.setLayoutManager(linearLayoutManager); |
284 | mRecyclerView.addItemDecoration(new RecyclerViewSpaceItem(10)); | 283 | mRecyclerView.addItemDecoration(new RecyclerViewSpaceItem(10)); |
285 | 284 | ||
286 | mRecyclerViewpublish.setLayoutManager(linearLayoutManagerpublish); | 285 | mRecyclerViewpublish.setLayoutManager(linearLayoutManagerpublish); |
287 | mRecyclerViewpublish.addItemDecoration(new RecyclerViewSpaceItem(10)); | 286 | mRecyclerViewpublish.addItemDecoration(new RecyclerViewSpaceItem(10)); |
288 | 287 | ||
289 | //设置视频适配器 | 288 | //设置视频适配器 |
290 | RecyclerViewadapter = new VideoAdapter(this, videoinfo); | 289 | RecyclerViewadapter = new VideoAdapter(this, videoinfo); |
291 | RecyclerViewadapterpublish = new GalleryAdapter(this, defautPublishInfos); | 290 | RecyclerViewadapterpublish = new GalleryAdapter(this, defautPublishInfos); |
292 | 291 | ||
293 | //版本信息适配器 | 292 | //版本信息适配器 |
294 | mRecyclerView.setAdapter(RecyclerViewadapter); | 293 | mRecyclerView.setAdapter(RecyclerViewadapter); |
295 | mRecyclerViewpublish.setAdapter(RecyclerViewadapterpublish); | 294 | mRecyclerViewpublish.setAdapter(RecyclerViewadapterpublish); |
296 | 295 | ||
297 | //判断保卡信息是否为样机 | 296 | //判断保卡信息是否为样机 |
298 | String yangji = SaveParam.getInstance().getLoginParam(this, SaveParam.YANGJI); | 297 | String yangji = SaveParam.getInstance().getLoginParam(this, SaveParam.YANGJI); |
299 | String deviceNumber = GetDevicesUtil.getDevicesInfo(MainActivity.this).getDeviceNumber(); | 298 | String deviceNumber = GetDevicesUtil.getDevicesInfo(MainActivity.this).getDeviceNumber(); |
300 | if ("1".equals(yangji)) { | 299 | if ("1".equals(yangji)) { |
301 | iv_look_card.setVisibility(View.GONE); | 300 | iv_look_card.setVisibility(View.GONE); |
302 | tv_yangji.setVisibility(View.VISIBLE); | 301 | tv_yangji.setVisibility(View.VISIBLE); |
303 | } else { | 302 | } else { |
304 | HttpManager.getInstance().getcardinfo1(this, deviceNumber, handler); | 303 | HttpManager.getInstance().getcardinfo1(this, deviceNumber, handler); |
305 | 304 | ||
306 | } | 305 | } |
307 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); | 306 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); |
308 | //获取个性签名 | 307 | //获取个性签名 |
309 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); | 308 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); |
310 | try { | 309 | try { |
311 | long auserID = Long.parseLong(userID); | 310 | long auserID = Long.parseLong(userID); |
312 | int typeaccount1 = Integer.parseInt(typeaccount); | 311 | int typeaccount1 = Integer.parseInt(typeaccount); |
313 | HttpManager.getInstance().getsignatures(MainActivity.this, auserID, typeaccount1, handler); | 312 | HttpManager.getInstance().getsignatures(MainActivity.this, auserID, typeaccount1, handler); |
314 | 313 | ||
315 | } catch (NumberFormatException e) { | 314 | } catch (NumberFormatException e) { |
316 | e.printStackTrace(); | 315 | e.printStackTrace(); |
317 | } | 316 | } |
318 | 317 | ||
319 | 318 | ||
320 | } | 319 | } |
321 | 320 | ||
322 | private void initLister() { | 321 | private void initLister() { |
323 | iv_imformatioan.setOnClickListener(this); | 322 | iv_imformatioan.setOnClickListener(this); |
324 | iv_look_card.setOnClickListener(this); | 323 | iv_look_card.setOnClickListener(this); |
325 | tv_edit_presoninfo.setOnClickListener(this); | 324 | tv_edit_presoninfo.setOnClickListener(this); |
326 | iv_setting.setOnClickListener(this); | 325 | iv_setting.setOnClickListener(this); |
327 | iv_sign.setOnClickListener(this); | 326 | iv_sign.setOnClickListener(this); |
328 | mSimpleDraweeView.setOnClickListener(this); | 327 | mSimpleDraweeView.setOnClickListener(this); |
329 | linel_mycuoti.setOnClickListener(this); | 328 | linel_mycuoti.setOnClickListener(this); |
330 | linel_mynote.setOnClickListener(this); | 329 | linel_mynote.setOnClickListener(this); |
331 | linel_mycollege.setOnClickListener(this); | 330 | linel_mycollege.setOnClickListener(this); |
332 | linel_myclass.setOnClickListener(this); | 331 | linel_myclass.setOnClickListener(this); |
333 | 332 | ||
334 | } | 333 | } |
335 | 334 | ||
336 | @Override | 335 | @Override |
337 | public void onClick(View v) { | 336 | public void onClick(View v) { |
338 | switch (v.getId()) { | 337 | switch (v.getId()) { |
339 | case R.id.iv_imformatioan: | 338 | case R.id.iv_imformatioan: |
340 | Intent intent = new Intent(); | 339 | Intent intent = new Intent(); |
341 | intent.setClass(MainActivity.this, FeedBackActivity.class); | 340 | intent.setClass(MainActivity.this, FeedBackActivity.class); |
342 | startActivity(intent); | 341 | startActivity(intent); |
343 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 342 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
344 | break; | 343 | break; |
345 | case R.id.iv_look_card: | 344 | case R.id.iv_look_card: |
346 | Intent lookintent = new Intent(); | 345 | Intent lookintent = new Intent(); |
347 | lookintent.setClass(MainActivity.this, ElectronicCardLookInfoActivity.class); | 346 | lookintent.setClass(MainActivity.this, ElectronicCardLookInfoActivity.class); |
348 | startActivity(lookintent); | 347 | startActivity(lookintent); |
349 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 348 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
350 | break; | 349 | break; |
351 | case R.id.tv_edit_presoninfo: | 350 | case R.id.tv_edit_presoninfo: |
352 | Intent editintent = new Intent(); | 351 | Intent editintent = new Intent(); |
353 | editintent.setClass(MainActivity.this, ChangePresonalInfoActivity.class); | 352 | editintent.setClass(MainActivity.this, ChangePresonalInfoActivity.class); |
354 | startActivity(editintent); | 353 | startActivity(editintent); |
355 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 354 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
356 | break; | 355 | break; |
357 | case R.id.iv_head: | 356 | case R.id.iv_head: |
358 | HeadDialog.getInstance(this).show(getSupportFragmentManager(), "HeadDialog"); | 357 | HeadDialog.getInstance(this).show(getSupportFragmentManager(), "HeadDialog"); |
359 | break; | 358 | break; |
360 | case R.id.iv_setting: | 359 | case R.id.iv_setting: |
361 | mTopRightMenu = new TopRightMenu(MainActivity.this); | 360 | mTopRightMenu = new TopRightMenu(MainActivity.this); |
362 | List<MenuItem> menuItems = new ArrayList<>(); | 361 | List<MenuItem> menuItems = new ArrayList<>(); |
363 | menuItems.add(new MenuItem(R.mipmap.blank, "切换账户")); | 362 | menuItems.add(new MenuItem(R.mipmap.blank, "切换账户")); |
364 | menuItems.add(new MenuItem(R.mipmap.blank, "账户管理")); | 363 | menuItems.add(new MenuItem(R.mipmap.blank, "账户管理")); |
365 | mTopRightMenu | 364 | mTopRightMenu |
366 | .setHeight(150) //默认高度480 | 365 | .setHeight(150) //默认高度480 |
367 | .setWidth(320) //默认宽度wrap_content | 366 | .setWidth(320) //默认宽度wrap_content |
368 | .showIcon(showIcon) //显示菜单图标,默认为true | 367 | .showIcon(showIcon) //显示菜单图标,默认为true |
369 | .dimBackground(dimBg) //背景变暗,默认为true | 368 | .dimBackground(dimBg) //背景变暗,默认为true |
370 | .needAnimationStyle(needAnim) //显示动画,默认为true | 369 | .needAnimationStyle(needAnim) //显示动画,默认为true |
371 | .setAnimationStyle(R.style.TRM_ANIM_STYLE) //默认为R.style.TRM_ANIM_STYLE | 370 | .setAnimationStyle(R.style.TRM_ANIM_STYLE) //默认为R.style.TRM_ANIM_STYLE |
372 | .setOnMenuItemClickListener(new TopRightMenu.OnMenuItemClickListener() { | 371 | .setOnMenuItemClickListener(new TopRightMenu.OnMenuItemClickListener() { |
373 | @Override | 372 | @Override |
374 | public void onMenuItemClick(int position) { | 373 | public void onMenuItemClick(int position) { |
375 | switch (position) { | 374 | switch (position) { |
376 | case 0: | 375 | case 0: |
377 | new CircleDialog.Builder(MainActivity.this) | 376 | new CircleDialog.Builder(MainActivity.this) |
378 | .setCanceledOnTouchOutside(false) | 377 | .setCanceledOnTouchOutside(false) |
379 | .setWidth(0.4f) | 378 | .setWidth(0.4f) |
380 | .setCancelable(false) | 379 | .setCancelable(false) |
381 | .setText("您确定要退出,更换其他账号登录吗?") | 380 | .setText("您确定要退出,更换其他账号登录吗?") |
382 | .setNegative("取消", null) | 381 | .setNegative("取消", null) |
383 | .setPositive("确定", new View.OnClickListener() { | 382 | .setPositive("确定", new View.OnClickListener() { |
384 | @Override | 383 | @Override |
385 | public void onClick(View v) { | 384 | public void onClick(View v) { |
386 | //清除数据 | 385 | //清除数据 |
387 | SaveParam.getInstance().clearData(MainActivity.this); | 386 | SaveParam.getInstance().clearData(MainActivity.this); |
388 | Intent settingintent = new Intent(); | 387 | Intent settingintent = new Intent(); |
389 | settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class); | 388 | settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class); |
390 | startActivity(settingintent); | 389 | startActivity(settingintent); |
391 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 390 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
392 | finish(); | 391 | finish(); |
393 | } | 392 | } |
394 | }) | 393 | }) |
395 | .show(); | 394 | .show(); |
396 | break; | 395 | break; |
397 | case 1: | 396 | case 1: |
398 | Intent accontMintent = new Intent(); | 397 | Intent accontMintent = new Intent(); |
399 | accontMintent.setClass(MainActivity.this, AccountManagementActivity.class); | 398 | accontMintent.setClass(MainActivity.this, AccountManagementActivity.class); |
400 | startActivity(accontMintent); | 399 | startActivity(accontMintent); |
401 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 400 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
402 | break; | 401 | break; |
403 | } | 402 | } |
404 | } | 403 | } |
405 | }) | 404 | }) |
406 | .addMenuList(menuItems) | 405 | .addMenuList(menuItems) |
407 | .showAsDropDown(iv_setting, -250, 0); | 406 | .showAsDropDown(iv_setting, -250, 0); |
408 | break; | 407 | break; |
409 | case R.id.iv_sign: | 408 | case R.id.iv_sign: |
410 | new CircleDialog.Builder(this) | 409 | new CircleDialog.Builder(this) |
411 | .setCanceledOnTouchOutside(false) | 410 | .setCanceledOnTouchOutside(false) |
412 | .setCancelable(true) | 411 | .setCancelable(true) |
413 | .setTitle("个性签名") | 412 | .setTitle("个性签名") |
414 | .setInputHint("请输入个性签名") | 413 | .setInputHint("请输入个性签名") |
415 | .setWidth(0.5f) | 414 | .setWidth(0.5f) |
416 | .configInput(new ConfigInput() { | 415 | .configInput(new ConfigInput() { |
417 | @Override | 416 | @Override |
418 | public void onConfig(InputParams params) { | 417 | public void onConfig(InputParams params) { |
419 | // params.inputBackgroundResourceId = R.drawable.bg_input; | 418 | // params.inputBackgroundResourceId = R.drawable.bg_input; |
420 | } | 419 | } |
421 | }) | 420 | }) |
422 | .setNegative("取消", null) | 421 | .setNegative("取消", null) |
423 | .setPositiveInput("确定", new OnInputClickListener() { | 422 | .setPositiveInput("确定", new OnInputClickListener() { |
424 | @Override | 423 | @Override |
425 | public void onClick(String text, View v) { | 424 | public void onClick(String text, View v) { |
426 | if (text.equals("")) { | 425 | if (text.equals("")) { |
427 | AlertUtils.showToast(MainActivity.this, "请输入个性签名"); | 426 | AlertUtils.showToast(MainActivity.this, "请输入个性签名"); |
428 | } else { | 427 | } else { |
429 | try { | 428 | try { |
430 | String typeaccount = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT); | 429 | String typeaccount = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT); |
431 | String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId"); | 430 | String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId"); |
432 | long auserID = Long.parseLong(userID); | 431 | long auserID = Long.parseLong(userID); |
433 | int typeaccount1 = Integer.parseInt(typeaccount); | 432 | int typeaccount1 = Integer.parseInt(typeaccount); |
434 | HttpManager.getInstance().changsignature(MainActivity.this, auserID, typeaccount1, text); | 433 | HttpManager.getInstance().changsignature(MainActivity.this, auserID, typeaccount1, text); |
435 | RecyclerViewadapterpublish.notifyDataSetChanged(); | 434 | RecyclerViewadapterpublish.notifyDataSetChanged(); |
436 | } catch (NumberFormatException e) { | 435 | } catch (NumberFormatException e) { |
437 | e.printStackTrace(); | 436 | e.printStackTrace(); |
438 | } | 437 | } |
439 | 438 | ||
440 | tv_sign.setText(text); | 439 | tv_sign.setText(text); |
441 | } | 440 | } |
442 | 441 | ||
443 | } | 442 | } |
444 | }) | 443 | }) |
445 | .show(); | 444 | .show(); |
446 | break; | 445 | break; |
447 | case R.id.linel_mycuoti: | 446 | case R.id.linel_mycuoti: |
448 | AlertUtils.showToast(this, "我的错题 "); | 447 | AlertUtils.showToast(this, "我的错题 "); |
449 | break; | 448 | break; |
450 | case R.id.linel_mynote: | 449 | case R.id.linel_mynote: |
451 | AlertUtils.showToast(this, "我的笔记 "); | 450 | AlertUtils.showToast(this, "我的笔记 "); |
452 | break; | 451 | break; |
453 | case R.id.linel_mycollege: | 452 | case R.id.linel_mycollege: |
454 | AlertUtils.showToast(this, "我的收藏 "); | 453 | AlertUtils.showToast(this, "我的收藏 "); |
455 | break; | 454 | break; |
456 | case R.id.linel_myclass: | 455 | case R.id.linel_myclass: |
457 | AlertUtils.showToast(this, "我的班级 "); | 456 | AlertUtils.showToast(this, "我的班级 "); |
458 | break; | 457 | break; |
459 | } | 458 | } |
460 | 459 | ||
461 | } | 460 | } |
462 | 461 | ||
463 | @Override | 462 | @Override |
464 | protected void onPause() { | 463 | protected void onPause() { |
465 | super.onPause(); | 464 | super.onPause(); |
466 | } | 465 | } |
467 | 466 | ||
468 | @Override | 467 | @Override |
469 | protected void onResume() { | 468 | protected void onResume() { |
470 | super.onResume(); | 469 | super.onResume(); |
471 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); | 470 | String userID = SaveParam.getInstance().getLoginParam(this, "userId"); |
472 | //账户类型 | 471 | //账户类型 |
473 | String accounts = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); | 472 | String accounts = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); |
474 | try { | 473 | try { |
475 | int graderID; | 474 | int graderID; |
476 | long auserID = Long.parseLong(userID); | 475 | long auserID = Long.parseLong(userID); |
477 | int typeaccount1 = Integer.parseInt(accounts); | 476 | int typeaccount1 = Integer.parseInt(accounts); |
478 | //获取最近播放视频 | 477 | //获取最近播放视频 |
479 | HttpManager.getInstance().getstuyvidioinfo(this, auserID, handler); | 478 | HttpManager.getInstance().getstuyvidioinfo(this, auserID, handler); |
480 | //获取个人信息 | 479 | //获取个人信息 |
481 | HttpManager.getInstance().getpresonalinfo(MainActivity.this, auserID, typeaccount1, handler); | 480 | HttpManager.getInstance().getpresonalinfo(MainActivity.this, auserID, typeaccount1, handler); |
482 | 481 | ||
483 | 482 | ||
484 | } catch (NumberFormatException e) { | 483 | } catch (NumberFormatException e) { |
485 | e.printStackTrace(); | 484 | e.printStackTrace(); |
486 | } | 485 | } |
487 | 486 | ||
488 | } | 487 | } |
489 | 488 | ||
490 | //回调头像监听 | 489 | //回调头像监听 |
491 | @Override | 490 | @Override |
492 | public void heard(Context context, View v, int headpitiaon) { | 491 | public void heard(Context context, View v, int headpitiaon) { |
493 | String picUrl = ""; | 492 | String picUrl = ""; |
494 | String userID; | 493 | String userID; |
495 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); | 494 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); |
496 | if ("2".equals(typeaccount)) { | 495 | if ("2".equals(typeaccount)) { |
497 | userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID); | 496 | userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID); |
498 | } else { | 497 | } else { |
499 | userID = SaveParam.getInstance().getLoginParam(this, "userId"); | 498 | userID = SaveParam.getInstance().getLoginParam(this, "userId"); |
500 | } | 499 | } |
501 | switch (v.getId()) { | 500 | switch (v.getId()) { |
502 | //选择默认图片 | 501 | //选择默认图片 |
503 | case R.id.oktakephone: | 502 | case R.id.oktakephone: |
504 | if (headpitiaon == 1) { | 503 | if (headpitiaon == 1) { |
505 | mSimpleDraweeView.setImageDrawable(null); | 504 | mSimpleDraweeView.setImageDrawable(null); |
506 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar1); | 505 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar1); |
507 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/61e8d8cf-651f-49c9-beb2-ff1387af390a.png"; | 506 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/61e8d8cf-651f-49c9-beb2-ff1387af390a.png"; |
508 | try { | 507 | try { |
509 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); | 508 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); |
510 | } catch (UnsupportedEncodingException e) { | 509 | } catch (UnsupportedEncodingException e) { |
511 | e.printStackTrace(); | 510 | e.printStackTrace(); |
512 | } | 511 | } |
513 | } else if (headpitiaon == 2) { | 512 | } else if (headpitiaon == 2) { |
514 | mSimpleDraweeView.setImageDrawable(null); | 513 | mSimpleDraweeView.setImageDrawable(null); |
515 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar2); | 514 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar2); |
516 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/8480ff7b-42f1-4d64-b848-c8f4f3afd385.png"; | 515 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/8480ff7b-42f1-4d64-b848-c8f4f3afd385.png"; |
517 | try { | 516 | try { |
518 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); | 517 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); |
519 | } catch (UnsupportedEncodingException e) { | 518 | } catch (UnsupportedEncodingException e) { |
520 | e.printStackTrace(); | 519 | e.printStackTrace(); |
521 | } | 520 | } |
522 | } else if (headpitiaon == 3) { | 521 | } else if (headpitiaon == 3) { |
523 | mSimpleDraweeView.setImageDrawable(null); | 522 | mSimpleDraweeView.setImageDrawable(null); |
524 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar3); | 523 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar3); |
525 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/184112f4-bfe0-4db8-bc1e-6212755b241c.png"; | 524 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/184112f4-bfe0-4db8-bc1e-6212755b241c.png"; |
526 | try { | 525 | try { |
527 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); | 526 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); |
528 | } catch (UnsupportedEncodingException e) { | 527 | } catch (UnsupportedEncodingException e) { |
529 | e.printStackTrace(); | 528 | e.printStackTrace(); |
530 | } | 529 | } |
531 | } else if (headpitiaon == 4) { | 530 | } else if (headpitiaon == 4) { |
532 | mSimpleDraweeView.setImageDrawable(null); | 531 | mSimpleDraweeView.setImageDrawable(null); |
533 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar4); | 532 | mSimpleDraweeView.setImageResource(R.mipmap.default_avatar4); |
534 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/e31c9e11-9276-4bf4-a162-b66272fdc351.png"; | 533 | picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/e31c9e11-9276-4bf4-a162-b66272fdc351.png"; |
535 | try { | 534 | try { |
536 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); | 535 | HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl); |
537 | } catch (UnsupportedEncodingException e) { | 536 | } catch (UnsupportedEncodingException e) { |
538 | e.printStackTrace(); | 537 | e.printStackTrace(); |
539 | } | 538 | } |
540 | } else { | 539 | } else { |
541 | mSimpleDraweeView.setImageDrawable(null); | 540 | mSimpleDraweeView.setImageDrawable(null); |
542 | mSimpleDraweeView.setImageResource(R.mipmap.header_default); | 541 | mSimpleDraweeView.setImageResource(R.mipmap.header_default); |
543 | ; | 542 | ; |
544 | } | 543 | } |
545 | 544 | ||
546 | break; | 545 | break; |
547 | case R.id.canceltakephone: | 546 | case R.id.canceltakephone: |
548 | 547 | ||
549 | break; | 548 | break; |
550 | //拍摄和相册 | 549 | //拍摄和相册 |
551 | case R.id.take_pic: | 550 | case R.id.take_pic: |
552 | if (PermissionUtil.hasCameraPermission(MainActivity.this)) { | 551 | if (PermissionUtil.hasCameraPermission(MainActivity.this)) { |
553 | uploadAvatarFromPhotoRequest(); | 552 | uploadAvatarFromPhotoRequest(); |
554 | } | 553 | } |
555 | break; | 554 | break; |
556 | case R.id.xiangce: | 555 | case R.id.xiangce: |
557 | uploadAvatarFromAlbumRequest(); | 556 | uploadAvatarFromAlbumRequest(); |
558 | break; | 557 | break; |
559 | 558 | ||
560 | } | 559 | } |
561 | 560 | ||
562 | } | 561 | } |
563 | //照相 | 562 | //照相 |
564 | private void uploadAvatarFromPhotoRequest() { | 563 | private void uploadAvatarFromPhotoRequest() { |
565 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 564 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
566 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 565 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
567 | intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); | 566 | intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); |
568 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | 567 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
569 | startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO); | 568 | startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO); |
570 | } | 569 | } |
570 | |||
571 | //选择图库 | 571 | //选择图库 |
572 | private void uploadAvatarFromAlbumRequest() { | 572 | private void uploadAvatarFromAlbumRequest() { |
573 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 573 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
574 | photoPickerIntent.setType("image/*"); | 574 | photoPickerIntent.setType("image/*"); |
575 | startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM); | 575 | startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM); |
576 | } | 576 | } |
577 | 577 | ||
578 | //回掉 | 578 | //回掉 |
579 | @Override | 579 | @Override |
580 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 580 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
581 | super.onActivityResult(requestCode, resultCode, data); | 581 | super.onActivityResult(requestCode, resultCode, data); |
582 | if (resultCode != -1) { | 582 | if (resultCode != -1) { |
583 | return; | 583 | return; |
584 | } | 584 | } |
585 | if (requestCode == REQUEST_CODE_ALBUM && data != null) { | 585 | if (requestCode == REQUEST_CODE_ALBUM && data != null) { |
586 | Uri newUri; | 586 | Uri newUri; |
587 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | 587 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
588 | newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData())); | 588 | newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData())); |
589 | } else { | 589 | } else { |
590 | newUri = data.getData(); | 590 | newUri = data.getData(); |
591 | } | 591 | } |
592 | if (newUri != null) { | 592 | if (newUri != null) { |
593 | startPhotoZoom(newUri); | 593 | startPhotoZoom(newUri); |
594 | } else { | 594 | } else { |
595 | Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show(); | 595 | Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show(); |
596 | } | 596 | } |
597 | } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) { | 597 | } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) { |
598 | startPhotoZoom(uri); | 598 | //startPhotoZoom(uri); |
599 | uploadAvatarFromPhoto(); | ||
599 | } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) { | 600 | } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) { |
600 | uploadAvatarFromPhoto(); | 601 | uploadAvatarFromPhoto(); |
601 | } | 602 | } |
602 | } | 603 | } |
603 | 604 | ||
604 | private void uploadAvatarFromPhoto() { | 605 | private void uploadAvatarFromPhoto() { |
605 | compressAndUploadAvatar(file.getPath()); | 606 | compressAndUploadAvatar(file.getPath()); |
606 | 607 | ||
607 | } | 608 | } |
608 | 609 | ||
609 | private void compressAndUploadAvatar(String fileSrc) { | 610 | private void compressAndUploadAvatar(String fileSrc) { |
610 | 611 | ||
611 | 612 | ||
612 | //上传到服务器 | 613 | //上传到服务器 |
613 | 614 | ||
614 | final File cover = FileUtil.getSmallBitmap(this, fileSrc); | 615 | final File cover = FileUtil.getSmallBitmap(this, fileSrc); |
615 | String mimeType = "image/*"; | 616 | String mimeType = "image/*"; |
616 | //requestBody = RequestBody.create(MediaType.parse(mimeType), file); | 617 | //requestBody = RequestBody.create(MediaType.parse(mimeType), file); |
617 | //String fileName = cover.getName(); | 618 | //String fileName = cover.getName(); |
618 | String userID; | 619 | String userID; |
619 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); | 620 | String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); |
620 | if ("2".equals(typeaccount)) { | 621 | if ("2".equals(typeaccount)) { |
621 | userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID); | 622 | userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID); |
622 | } else { | 623 | } else { |
623 | userID = SaveParam.getInstance().getLoginParam(this, "userId"); | 624 | userID = SaveParam.getInstance().getLoginParam(this, "userId"); |
624 | } | 625 | } |
625 | 626 | ||
626 | //上传头像 | 627 | //上传头像 |
627 | 628 | ||
628 | try { | 629 | try { |
629 | HttpManager.getInstance().header(this, userID, typeaccount, file.getPath()); | 630 | HttpManager.getInstance().header(this, userID, typeaccount, fileSrc); |
630 | } catch (UnsupportedEncodingException e) { | 631 | } catch (UnsupportedEncodingException e) { |
631 | e.printStackTrace(); | 632 | e.printStackTrace(); |
632 | } | 633 | } |
633 | 634 | ||
634 | //photo = MultipartBody.Part.createFormData("portrait", fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()), requestBody); | ||
635 | //Fresco设置圆形头像 | ||
636 | GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); | 635 | GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); |
637 | GenericDraweeHierarchy hierarchy = builder | 636 | GenericDraweeHierarchy hierarchy = builder |
638 | .setDesiredAspectRatio(1f) | 637 | .setDesiredAspectRatio(1f) |
639 | .setFailureImage(R.mipmap.blank) | 638 | .setFailureImage(R.mipmap.header_default) |
640 | //圆形头像 | 639 | //圆形头像 |
641 | .setRoundingParams(RoundingParams.asCircle()) | 640 | .setRoundingParams(RoundingParams.asCircle()) |
642 | .build(); | 641 | .build(); |
643 | 642 | ||
644 | //加载本地图片 | 643 | //加载本地图片 |
645 | Uri uri = Uri.fromFile(cover); | 644 | Uri uri = Uri.fromFile(cover); |
646 | DraweeController controller = Fresco.newDraweeControllerBuilder() | 645 | DraweeController controller = Fresco.newDraweeControllerBuilder() |
647 | .setOldController(mSimpleDraweeView.getController()) | 646 | .setOldController(mSimpleDraweeView.getController()) |
648 | .setUri(uri) | 647 | .setUri(uri) |
649 | .build(); | 648 | .build(); |
650 | mSimpleDraweeView.setHierarchy(hierarchy); | 649 | mSimpleDraweeView.setHierarchy(hierarchy); |
651 | mSimpleDraweeView.setController(controller); | 650 | mSimpleDraweeView.setController(controller); |
652 | 651 | ||
653 | } | 652 | } |
654 | 653 | ||
655 | public void startPhotoZoom(Uri uri) { | 654 | public void startPhotoZoom(Uri uri) { |
656 | Intent intent = new Intent("com.android.camera.action.CROP"); | 655 | Intent intent = new Intent("com.android.camera.action.CROP"); |
657 | intent.setDataAndType(uri, "image/*"); | 656 | intent.setDataAndType(uri, "image/*"); |
658 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 657 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
659 | intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面. | 658 | intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面. |
660 | intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例. | 659 | intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例. |
661 | intent.putExtra("aspectY", 1);// x:y=1:1 | 660 | intent.putExtra("aspectY", 1);// x:y=1:1 |
662 | // intent.putExtra("outputX", 400);//图片输出大小 | 661 | // intent.putExtra("outputX", 400);//图片输出大小 |
663 | // intent.putExtra("outputY", 400); | 662 | // intent.putExtra("outputY", 400); |
664 | intent.putExtra("output", Uri.fromFile(file)); | 663 | intent.putExtra("output", Uri.fromFile(file)); |
665 | intent.putExtra("outputFormat", "JPEG");// 返回格式 | 664 | intent.putExtra("outputFormat", "JPEG");// 返回格式 |
666 | startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO); | 665 | startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO); |
667 | } | 666 | } |
668 | 667 | ||
669 | @Override | 668 | @Override |
670 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | 669 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
671 | switch (requestCode) { | 670 | switch (requestCode) { |
672 | 671 | ||
673 | case PermissionUtil.REQUEST_SHOWCAMERA: | 672 | case PermissionUtil.REQUEST_SHOWCAMERA: |
674 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | 673 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
675 | // Permission Granted | 674 | // Permission Granted |
676 | uploadAvatarFromPhotoRequest(); | 675 | uploadAvatarFromPhotoRequest(); |
677 | 676 | ||
678 | } else { | 677 | } else { |
679 | if (!SharedPreferenceMark.getHasShowCamera()) { | 678 | if (!SharedPreferenceMark.getHasShowCamera()) { |
680 | SharedPreferenceMark.setHasShowCamera(true); | 679 | SharedPreferenceMark.setHasShowCamera(true); |
681 | new DialogPermission(this, "关闭摄像头权限影响扫描功能"); | 680 | new DialogPermission(this, "关闭摄像头权限影响扫描功能"); |
682 | 681 | ||
683 | } else { | 682 | } else { |
684 | Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT) | 683 | Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT) |
685 | .show(); | 684 | .show(); |
686 | } | 685 | } |
687 | } | 686 | } |
688 | break; | 687 | break; |
689 | default: | 688 | default: |
690 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); | 689 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
691 | } | 690 | } |
692 | } | 691 | } |
693 | 692 | ||
693 | |||
694 | |||
694 | private long exitTime = 0; | 695 | private long exitTime = 0; |
695 | 696 | ||
696 | @Override | 697 | @Override |
697 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 698 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
698 | if (keyCode == KeyEvent.KEYCODE_BACK) { | 699 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
699 | if ((System.currentTimeMillis() - exitTime) > 2000) { | 700 | if ((System.currentTimeMillis() - exitTime) > 2000) { |
700 | Toast.makeText(getApplicationContext(), "再按一次退出程序", | 701 | Toast.makeText(getApplicationContext(), "再按一次退出程序", |
701 | Toast.LENGTH_SHORT).show(); | 702 | Toast.LENGTH_SHORT).show(); |
702 | exitTime = System.currentTimeMillis(); | 703 | exitTime = System.currentTimeMillis(); |
703 | } else { | 704 | } else { |
704 | SysApplication.getInstance().finishActivity(MainActivity.this); | 705 | SysApplication.getInstance().finishActivity(MainActivity.this); |
705 | } | 706 | } |
706 | return false; | 707 | return false; |
707 | } | 708 | } |
708 | return super.onKeyDown(keyCode, event); | 709 | return super.onKeyDown(keyCode, event); |