private void startEditorDialog(int requestCode) { Intent intent = new Intent(PersonalInfoActivity.this, EditorDialogActivity.class); switch (requestCode) { case REQUEST_CODE_AGE: intent.putExtra(EditorDialogActivity.KEY_TITLE, getString(R.string.personalinfo_age)); intent.putExtra(EditorDialogActivity.KEY_TYPE, EditorDialogActivity.TYPE_DATE); Date date = new Date(); try { date = new SimpleDateFormat("yyyy-MM-dd").parse(mUserInfo.getBirthday()); } catch (Exception e) { } intent.putExtra(EditorDialogActivity.KEY_DATE, date); break; case REQUEST_CODE_PLACE: intent.putExtra(EditorDialogActivity.KEY_TITLE, getString(R.string.personalinfo_city)); intent.putExtra(EditorDialogActivity.KEY_TYPE, EditorDialogActivity.TYPE_PLACE); Integer placeid = 0; try { placeid = Integer.valueOf(mUserInfo.getCity()); } catch (Exception e) { } intent.putExtra(EditorDialogActivity.KEY_PLACE, placeid); break; case REQUEST_CODE_DESCRIPTION: intent.putExtra( EditorDialogActivity.KEY_TITLE, getString(R.string.personalinfo_description)); intent.putExtra(EditorDialogActivity.KEY_TYPE, EditorDialogActivity.TYPE_MULTI_TEXT); intent.putExtra(EditorDialogActivity.KEY_TEXT, mUserInfo.getDescription()); break; case REQUEST_CODE_SEX: intent.putExtra(EditorDialogActivity.KEY_TITLE, getString(R.string.personalinfo_sex)); intent.putExtra(EditorDialogActivity.KEY_TYPE, EditorDialogActivity.TYPE_SEX); intent.putExtra(EditorDialogActivity.KEY_SEX, mUserInfo.getSex()); default: break; } startActivityForResult(intent, requestCode); }
private void updateUserInfo() { mUserNameView.setText(mUserInfo.getName()); mHeaderPicView.setImageUrl(mUserInfo.getProtrait(), getImageLoder()); Integer post = 0; // TODO 获取文章数 mPostsView.setText(String.valueOf(post)); Integer goods = 0; // TODO 获取赞数 mGoodsView.setText(String.valueOf(goods)); String age = new String(); try { Date birthday = new SimpleDateFormat("yyyy-MM-dd").parse(mUserInfo.getBirthday()); Calendar ca = Calendar.getInstance(); ca.setTime(birthday); int birthYear = ca.get(Calendar.YEAR); ca.setTime(new Date()); int currentYear = ca.get(Calendar.YEAR); age = String.valueOf(currentYear - birthYear); } catch (Exception e) { } mAgeView.setText(age); mCityView.setText(mUserService.loadPlaceName(mUserInfo.getCity())); mDescriptionView.setText(mUserInfo.getDescription()); mSexIconView.setImageResource(UserService.SEX_DRAWABLE_MAP.get(mUserInfo.getSex())); }
@Override public void onClick(View v) { // 不是当前登录用户 if (!mUserInfo.getId().equals(mUserService.getCurrentLoginUser().getUserId())) { return; } switch (v.getId()) { case R.id.personalinfo_headerpic: if (isCurrentLoginUser()) { startAvatarPicker(); } break; case R.id.personalinfo_item_age: if (isCurrentLoginUser()) { startEditorDialog(REQUEST_CODE_AGE); } break; case R.id.personalinfo_item_city: if (isCurrentLoginUser()) { startEditorDialog(REQUEST_CODE_PLACE); } break; case R.id.personalinfo_item_description: if (isCurrentLoginUser()) { startEditorDialog(REQUEST_CODE_DESCRIPTION); } break; case R.id.personalinfo_item_sex: if (isCurrentLoginUser()) { startEditorDialog(REQUEST_CODE_SEX); } break; default: break; } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent resultIntent) { if (resultCode != RESULT_OK) { return; } switch (requestCode) { // 处理头像选择 case REQUEST_CODE_SELECT_AVATAR: Uri uri = null; if (resultIntent.getData() != null) { // 单选 uri = resultIntent.getData(); } else if (resultIntent.getClipData() != null) { // 多选 ClipData clipdata = resultIntent.getClipData(); if (clipdata.getItemCount() > 0) { uri = clipdata.getItemAt(0).getUri(); } } if (uri == null) { showToast(R.string.avatar_pic_has_not_select); return; } String path = MediaHelper.getPath(this, uri); if (TextUtils.isEmpty(path)) { showToast(R.string.avatar_pic_not_fount); return; } // 启动裁剪 Intent intent = new Intent(this, AvatarClipActivity.class); intent.putExtra(AvatarClipActivity.KEY_BITMAP_PATH, path); startActivity(intent); break; // 年龄 case REQUEST_CODE_AGE: { Serializable data = resultIntent.getSerializableExtra(EditorDialogActivity.KEY_RESULT_DATA); String dateStr = new SimpleDateFormat("yyyy-MM-dd").format((Date) data); mUserInfo.setBirthday(dateStr); updateCurrentLoginUserInfo(); } break; // TODO 地区选择 case REQUEST_CODE_PLACE: { int placeid = resultIntent.getIntExtra(EditorDialogActivity.KEY_RESULT_DATA, 0); if (placeid != 0) { mUserInfo.setCity(String.valueOf(placeid)); updateCurrentLoginUserInfo(); } } break; case REQUEST_CODE_DESCRIPTION: { String description = (String) resultIntent.getSerializableExtra(EditorDialogActivity.KEY_RESULT_DATA); mUserInfo.setDescription(description); updateCurrentLoginUserInfo(); } break; case REQUEST_CODE_SEX: { int sex = resultIntent.getIntExtra(EditorDialogActivity.KEY_RESULT_DATA, Constant.SEX_UNKONW); mUserInfo.setSex(sex); updateCurrentLoginUserInfo(); } break; default: break; } }