| | |
| | | import android.annotation.SuppressLint; |
| | | import android.app.Activity; |
| | | import android.app.AlertDialog; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.graphics.Color; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.util.Base64; |
| | |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.google.gson.Gson; |
| | | import com.lcjian.library.util.Environment; |
| | | import com.lcjian.library.util.SingleToast; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.tencent.mm.opensdk.modelmsg.SendAuth; |
| | | import com.umeng.socialize.UMAuthListener; |
| | | import com.umeng.socialize.UMShareAPI; |
| | | import com.umeng.socialize.bean.SHARE_MEDIA; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.entity.vo.UserInfoVO; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.dialog.LoadingDialogUtil; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.GlideCircleTransform; |
| | | import com.weikou.beibeivideo.util.SelectPicUtil; |
| | |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.Calendar; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Created by weikou2015 on 2016/10/27. |
| | | */ |
| | | |
| | | public class PersonInfoActivity extends BaseActivity implements View.OnClickListener { |
| | | |
| | | private String TAG = PersonInfoActivity.class.getSimpleName(); |
| | | |
| | | private LinearLayout ll_portrait; |
| | | private LinearLayout ll_nickName; |
| | |
| | | private TextView tv_birthday; |
| | | private TextView tv_sex; |
| | | private TextView tv_autograph; |
| | | |
| | | private TextView tv_qq; |
| | | private TextView tv_wx; |
| | | private TextView tv_phone; |
| | | |
| | | private TextView tv_bind_qq; |
| | | private TextView tv_bind_wx; |
| | | private TextView tv_bind_phone; |
| | | |
| | | private Dialog loadingDialog; |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle arg0) { |
| | |
| | | tv_sex = (TextView) findViewById(R.id.tv_sex); |
| | | tv_autograph = (TextView) findViewById(R.id.tv_autograph); |
| | | |
| | | tv_qq = findViewById(R.id.tv_qq); |
| | | tv_wx = findViewById(R.id.tv_wx); |
| | | tv_phone = findViewById(R.id.tv_phone); |
| | | |
| | | tv_bind_qq = findViewById(R.id.tv_bind_qq); |
| | | tv_bind_wx = findViewById(R.id.tv_bind_wx); |
| | | tv_bind_phone = findViewById(R.id.tv_bind_phone); |
| | | |
| | | |
| | | ll_portrait.setOnClickListener(this); |
| | | ll_nickName.setOnClickListener(this); |
| | | ll_birthday.setOnClickListener(this); |
| | | ll_sex.setOnClickListener(this); |
| | | ll_autograph.setOnClickListener(this); |
| | | findViewById(R.id.tv_back).setOnClickListener(this); |
| | | findViewById(R.id.tv_top_right).setOnClickListener(this); |
| | | getPersonInfo(); |
| | | tv_bind_qq.setOnClickListener(this); |
| | | tv_bind_wx.setOnClickListener(this); |
| | | tv_bind_phone.setOnClickListener(this); |
| | | loadingDialog = LoadingDialogUtil.getLoadingDialog(this, ""); |
| | | |
| | | } |
| | | |
| | | private String sign = ""; |
| | |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | JSONObject data = jsonObject.optJSONObject("Data"); |
| | | UserInfoVO userInfoVO = new Gson().fromJson(data.toString(), UserInfoVO.class); |
| | | |
| | | Glide.with(PersonInfoActivity.this).load(BeibeiConstant.addPreFix(userInfoVO.getPortrait())). |
| | | placeholder(R.drawable.ic_portrait_default).error(R.drawable.ic_portrait_default).into(iv_portrait); |
| | | tv_nickName.setText(userInfoVO.getNickName()); |
| | | tv_birthday.setText(userInfoVO.getBirthday()); |
| | | tv_sex.setText(Integer.parseInt(userInfoVO.getSex()) == 0 ? "女" : "男"); |
| | | sign = userInfoVO.getSign(); |
| | | tv_autograph.setText(sign); |
| | | setData(userInfoVO); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void setData(UserInfoVO userInfoVO) { |
| | | Glide.with(PersonInfoActivity.this).load(BeibeiConstant.addPreFix(userInfoVO.getPortrait())). |
| | | placeholder(R.drawable.ic_portrait_default).error(R.drawable.ic_portrait_default).transform(new GlideCircleTransform(getApplicationContext())).into(iv_portrait); |
| | | if (!StringUtils.isEmpty(userInfoVO.getNickName())) { |
| | | tv_nickName.setText(userInfoVO.getNickName()); |
| | | tv_nickName.setTextColor(Color.WHITE); |
| | | } else { |
| | | tv_nickName.setText("未填写"); |
| | | tv_nickName.setTextColor(Color.GRAY); |
| | | } |
| | | |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getBirthday())) { |
| | | tv_birthday.setText(userInfoVO.getBirthday()); |
| | | tv_birthday.setTextColor(Color.WHITE); |
| | | } else { |
| | | tv_birthday.setText("未填写"); |
| | | tv_birthday.setTextColor(Color.GRAY); |
| | | } |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getSex())) { |
| | | tv_sex.setText(Integer.parseInt(userInfoVO.getSex()) == 0 ? "女" : "男"); |
| | | tv_sex.setTextColor(Color.WHITE); |
| | | } else { |
| | | tv_sex.setText("未填写"); |
| | | tv_sex.setTextColor(Color.GRAY); |
| | | } |
| | | |
| | | sign = userInfoVO.getSign(); |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getSign())) { |
| | | tv_autograph.setText(userInfoVO.getSign()); |
| | | tv_autograph.setTextColor(Color.WHITE); |
| | | } else { |
| | | tv_autograph.setText("未填写"); |
| | | tv_autograph.setTextColor(Color.GRAY); |
| | | } |
| | | |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getQqOpenId())) { |
| | | tv_qq.setText(userInfoVO.getQqNickName()); |
| | | tv_bind_qq.setVisibility(View.GONE); |
| | | tv_qq.setVisibility(View.VISIBLE); |
| | | } else { |
| | | tv_bind_qq.setVisibility(View.VISIBLE); |
| | | tv_qq.setVisibility(View.GONE); |
| | | } |
| | | |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getWxUnionId())) { |
| | | tv_wx.setText(userInfoVO.getWxName()); |
| | | tv_bind_wx.setVisibility(View.GONE); |
| | | tv_wx.setVisibility(View.VISIBLE); |
| | | } else { |
| | | tv_bind_wx.setVisibility(View.VISIBLE); |
| | | tv_wx.setVisibility(View.GONE); |
| | | } |
| | | |
| | | |
| | | if (!StringUtils.isEmpty(userInfoVO.getPhone())) { |
| | | tv_phone.setText(userInfoVO.getPhone()); |
| | | tv_bind_phone.setVisibility(View.GONE); |
| | | tv_phone.setVisibility(View.VISIBLE); |
| | | } else { |
| | | tv_bind_phone.setVisibility(View.VISIBLE); |
| | | tv_phone.setVisibility(View.GONE); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | String imgBase64 = ""; |
| | | |
| | | @Override |
| | | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | // TODO Auto-generated method stub |
| | | super.onActivityResult(requestCode, resultCode, data); |
| | | UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); |
| | | if (resultCode == Activity.RESULT_OK) { |
| | | Bitmap bm = null; |
| | | bm = SelectPicUtil.onActivityResult(this, requestCode, |
| | |
| | | case R.id.ll_autograph://个性签名 |
| | | getAutograph(); |
| | | break; |
| | | case R.id.tv_top_right://完成个人信息的修改 |
| | | break; |
| | | |
| | | case R.id.tv_bind_qq: |
| | | //绑定QQ |
| | | { |
| | | if (LoginActivity.isQQClientAvailable(getApplicationContext())) { |
| | | // qq登录逻辑处理 点击登录后需要暂时锁定返回键和返回功能 不然会报错 |
| | | UMShareAPI.get(getApplicationContext()).getPlatformInfo(PersonInfoActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() { |
| | | |
| | | @Override |
| | | public void onStart(SHARE_MEDIA share_media) { |
| | | if (loadingDialog != null && !loadingDialog.isShowing()) |
| | | loadingDialog.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) { |
| | | Log.d(TAG, "onComplete"); |
| | | if (loadingDialog != null && loadingDialog.isShowing()) |
| | | loadingDialog.dismiss(); |
| | | String nickName = map.get("name"); |
| | | String openid = map.get("openid"); |
| | | String portrait = map.get("iconurl"); |
| | | String sex = map.get("gender"); |
| | | String province = map.get("province"); |
| | | String city = map.get("city"); |
| | | if (StringUtils.isEmpty(openid)) { |
| | | return; |
| | | } |
| | | |
| | | BeibeiVideoAPI.bindQQ(PersonInfoActivity.this, UserUtil.getLoginUid(getApplicationContext()), nickName, portrait, openid, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | Toast.makeText(PersonInfoActivity.this, "QQ绑定成功", Toast.LENGTH_SHORT).show(); |
| | | getPersonInfo(); |
| | | } else { |
| | | Toast.makeText(PersonInfoActivity.this, jsonObject.optString("Error"), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) { |
| | | throwable.printStackTrace(); |
| | | Log.d(TAG, "onError"); |
| | | if (loadingDialog != null && loadingDialog.isShowing()) |
| | | loadingDialog.dismiss(); |
| | | |
| | | Toast.makeText(PersonInfoActivity.this, "QQ授权出错,请稍后再试", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel(SHARE_MEDIA share_media, int i) { |
| | | Log.d(TAG, "onCancel"); |
| | | if (loadingDialog != null && loadingDialog.isShowing()) |
| | | loadingDialog.dismiss(); |
| | | } |
| | | }); |
| | | } else { |
| | | Toast.makeText(this, "QQ不可用,请查询手机是否安装QQ...", Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | break; |
| | | case R.id.tv_bind_wx: { |
| | | if (LoginActivity.isWXClientAvailable(getApplicationContext())) { |
| | | SendAuth.Req req = new SendAuth.Req(); |
| | | req.scope = "snsapi_userinfo"; |
| | | req.state = "bind"; |
| | | BeibeiVideoApplication.application.mWxApi.sendReq(req); |
| | | } else { |
| | | Toast.makeText(this, "微信不可用,请查询手机是否安装微信...", Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | break; |
| | | case R.id.tv_bind_phone: { |
| | | Intent intent = new Intent(this, PhoneLoginActivity.class); |
| | | intent.putExtra("login", false); |
| | | startActivity(intent); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | getPersonInfo(); |
| | | } |
| | | |
| | | |
| | | } |