接入微信登录, 增加个人信息编辑页面,我的光环增加自动检测更新,登录页面增加新老用户切换
This commit is contained in:
@ -19,6 +19,7 @@ public class Config {
|
||||
|
||||
// Third-Party confs
|
||||
public static final String WECHAT_APPID = BuildConfig.WECHAT_APPID;
|
||||
public static final String WECHAT_SECRET = BuildConfig.WECHAT_SECRET;
|
||||
public static final String TENCENT_APPID = BuildConfig.TENCENT_APPID;
|
||||
public static final String WEIBO_APPKEY = BuildConfig.WEIBO_APPKEY;
|
||||
public static final String MIPUSH_APPID = BuildConfig.MIPUSH_APPID;
|
||||
|
||||
@ -12,7 +12,9 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
@ -492,6 +494,50 @@ public class DialogUtils {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊:验证手机号码
|
||||
*/
|
||||
|
||||
public static void checkPhoneNumDialog(Context context, CharSequence message, final ConfirmListener cmListener) {
|
||||
String s = message.toString();
|
||||
String sub1 = s.substring(0, 3);
|
||||
String sub2 = s.substring(3, 7);
|
||||
String sub3 = s.substring(7, 11);
|
||||
String phoneNum = StringUtils.buildString(sub1, " - ", sub2, " - ", sub3);
|
||||
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||||
.setTitle("请确定手机号:")
|
||||
.setMessage(phoneNum)
|
||||
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.create();
|
||||
alertDialog.show();
|
||||
|
||||
TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
|
||||
positiveBtn.setTextSize(13);
|
||||
positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
negativeBtn.setTextSize(13);
|
||||
negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
if (mesage != null) {
|
||||
mesage.setGravity(Gravity.CENTER);
|
||||
mesage.setTextSize(24);
|
||||
mesage.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
TextPaint tp = mesage.getPaint();
|
||||
tp.setFakeBoldText(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface ConfirmListener {
|
||||
void onConfirm();
|
||||
}
|
||||
|
||||
@ -136,10 +136,10 @@ public class LoginUtils {
|
||||
|
||||
public void WCLogin(OnLoginListener listener) {
|
||||
if (mIWXAPI != null) {
|
||||
boolean register = mIWXAPI.registerApp("wx3ffd0785fad18396");
|
||||
boolean register = mIWXAPI.registerApp(Config.WECHAT_APPID);
|
||||
|
||||
SendAuth.Req req = new SendAuth.Req();
|
||||
req.scope = "all";
|
||||
req.scope = "snsapi_userinfo";
|
||||
req.state = "光环助手";
|
||||
boolean b = mIWXAPI.sendReq(req);
|
||||
Utils.log(LoginUtils.class.getSimpleName(), "微信注册状态::" + register + "\n 发送状态::" + b);
|
||||
|
||||
@ -8,6 +8,7 @@ import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
@ -27,6 +28,8 @@ public class AboutActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.about_version_tv)
|
||||
TextView mAboutVersion;
|
||||
@BindView(R.id.setting_rl_update)
|
||||
RelativeLayout mAboutUpdateRl;
|
||||
@BindView(R.id.about_version_pb)
|
||||
ProgressBar mAboutPb;
|
||||
|
||||
@ -49,8 +52,6 @@ public class AboutActivity extends BaseActivity {
|
||||
initTitle(getString(R.string.title_about));
|
||||
|
||||
((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this));
|
||||
|
||||
UpdateManager.getInstance(this).checkUpdate(false, handler); // 自动检出更新
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,13 +60,10 @@ public class AboutActivity extends BaseActivity {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
@OnClick({R.id.about_version_tv, R.id.about_shengming})
|
||||
@OnClick({R.id.about_shengming, R.id.setting_rl_update})
|
||||
public void OnClick(View view) {
|
||||
if (view.getId() == R.id.about_version_tv) {
|
||||
String content = mAboutVersion.getText().toString();
|
||||
if (content.startsWith("发现新版本")) {
|
||||
UpdateManager.getInstance(this).checkUpdate(false, handler); // 自动检出更新
|
||||
}
|
||||
if (view.getId() == R.id.setting_rl_update) {
|
||||
UpdateManager.getInstance(AboutActivity.this).checkUpdate(false, handler); // 检出更新
|
||||
} else if (view.getId() == R.id.about_shengming) {
|
||||
Intent intent = WebActivity.getWebIntent(this);
|
||||
startActivity(intent);
|
||||
@ -88,10 +86,8 @@ public class AboutActivity extends BaseActivity {
|
||||
if (msg.what == 0) {
|
||||
final String version = (String) msg.obj;
|
||||
activity.mAboutVersion.setText(StringUtils.buildString("发现新版本 V", version));
|
||||
activity.mAboutPb.setVisibility(View.GONE);
|
||||
} else if (msg.what == 1) {
|
||||
activity.mAboutVersion.setText("已是最新版本");
|
||||
activity.mAboutPb.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@ -20,6 +21,7 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PatternUtils;
|
||||
@ -31,7 +33,7 @@ import butterknife.OnClick;
|
||||
* Created by khy on 19/06/17.
|
||||
*/
|
||||
|
||||
public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginListener{
|
||||
public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginListener {
|
||||
|
||||
|
||||
@BindView(R.id.login_phone_et)
|
||||
@ -50,6 +52,12 @@ public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginLis
|
||||
LinearLayout mLoginWechatBtn;
|
||||
@BindView(R.id.login_weibo_btn)
|
||||
LinearLayout mLoginWeiboBtn;
|
||||
@BindView(R.id.login_bottom)
|
||||
LinearLayout mLoginBottom;
|
||||
@BindView(R.id.login_bottom_olduser)
|
||||
LinearLayout mLoginBottomOlduser;
|
||||
|
||||
ImageView mOldUser;
|
||||
|
||||
Handler mHandler = new Handler() {
|
||||
@Override
|
||||
@ -91,9 +99,9 @@ public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginLis
|
||||
initTitle("登录光环助手");
|
||||
|
||||
// 添加老用户入口
|
||||
ImageView oldUser = new ImageView(this);
|
||||
oldUser.setImageResource(R.drawable.login_olduser_icon);
|
||||
oldUser.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
||||
mOldUser = new ImageView(this);
|
||||
mOldUser.setImageResource(R.drawable.login_olduser_icon);
|
||||
mOldUser.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
||||
, DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 48));
|
||||
@ -101,19 +109,31 @@ public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginLis
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
RelativeLayout reuseActionbar = (RelativeLayout) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuseActionbar.addView(oldUser, params);
|
||||
reuseActionbar.addView(mOldUser, params);
|
||||
|
||||
|
||||
mLoginPassEt.addTextChangedListener(new LoginTextWatcher(mLoginPassEt));
|
||||
mLoginPhoneEt.addTextChangedListener(new LoginTextWatcher(mLoginPhoneEt));
|
||||
|
||||
|
||||
oldUser.setOnClickListener(new View.OnClickListener() {
|
||||
mOldUser.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
toast("老用户入口");
|
||||
changeUserLogin(true);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.actionbar_rl_back).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOldUser.getVisibility() == View.GONE) {
|
||||
changeUserLogin(false);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick({R.id.login_captcha, R.id.login_hint, R.id.login_phone_btn, R.id.login_qq_btn,
|
||||
@ -122,14 +142,19 @@ public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginLis
|
||||
switch (view.getId()) {
|
||||
case R.id.login_captcha:
|
||||
String phoneNum = mLoginPhoneEt.getText().toString().trim();
|
||||
if (PatternUtils.isPhoneNum(phoneNum)) {
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.arg1 = 10;
|
||||
mHandler.sendMessage(message);
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.hint));
|
||||
mLoginCaptcha.setBackgroundResource(R.drawable.border_captcha_bg);
|
||||
mLoginCaptcha.setEnabled(false);
|
||||
if (PatternUtils.isPhoneNum(phoneNum) && phoneNum.length() == 11) {
|
||||
DialogUtils.checkPhoneNumDialog(this, phoneNum, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.arg1 = 10;
|
||||
mHandler.sendMessage(message);
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.hint));
|
||||
mLoginCaptcha.setBackgroundResource(R.drawable.border_captcha_bg);
|
||||
mLoginCaptcha.setEnabled(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast("请输入正确的手机号");
|
||||
}
|
||||
@ -177,6 +202,29 @@ public class LoginActivity extends BaseActivity implements LoginUtils.OnLoginLis
|
||||
|
||||
}
|
||||
|
||||
private void changeUserLogin(boolean isOldUser) {
|
||||
if (isOldUser) {
|
||||
mLoginBottom.setVisibility(View.GONE);
|
||||
mLoginBottomOlduser.setVisibility(View.VISIBLE);
|
||||
mOldUser.setVisibility(View.GONE);
|
||||
initTitle("老用户登录");
|
||||
} else {
|
||||
mLoginBottom.setVisibility(View.VISIBLE);
|
||||
mLoginBottomOlduser.setVisibility(View.GONE);
|
||||
mOldUser.setVisibility(View.VISIBLE);
|
||||
initTitle("登录光环助手");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && mOldUser.getVisibility() == View.GONE) {
|
||||
changeUserLogin(false);
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
private class LoginTextWatcher implements TextWatcher {
|
||||
private EditText mEditText;
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package com.gh.gamecenter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
@ -35,10 +36,10 @@ public class UserInfoActivity extends BaseActivity {
|
||||
TextView mUserinfoAreaTv;
|
||||
@BindView(R.id.userinfo_area_rl)
|
||||
RelativeLayout mUserinfoAreaRl;
|
||||
@BindView(R.id.userinfo_qq_tv)
|
||||
TextView mUserinfoQqTv;
|
||||
@BindView(R.id.userinfo_qq_rl)
|
||||
RelativeLayout mUserinfoQqRl;
|
||||
@BindView(R.id.userinfo_contact_tv)
|
||||
TextView mUserinfoContactTv;
|
||||
@BindView(R.id.userinfo_contact_rl)
|
||||
RelativeLayout mUserinfoContactRl;
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, UserInfoActivity.class);
|
||||
@ -53,6 +54,23 @@ public class UserInfoActivity extends BaseActivity {
|
||||
mUserinfoAreaTv.setText(stringExtra);
|
||||
toast(stringExtra);
|
||||
}
|
||||
|
||||
String editContent = null;
|
||||
if (data != null) {
|
||||
editContent = data.getStringExtra("editContent");
|
||||
}
|
||||
if (!TextUtils.isEmpty(editContent))
|
||||
switch (requestCode) {
|
||||
case 0x131:
|
||||
mUserinfoNicknameTv.setText(editContent);
|
||||
break;
|
||||
case 0x132:
|
||||
mUserinfoSexTv.setText(editContent);
|
||||
break;
|
||||
case 0x133:
|
||||
mUserinfoContactTv.setText(editContent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,19 +86,25 @@ public class UserInfoActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@OnClick({R.id.userinfo_icon_rl, R.id.userinfo_nickname_rl, R.id.userinfo_sex_rl,
|
||||
R.id.userinfo_area_rl, R.id.userinfo_qq_rl})
|
||||
R.id.userinfo_area_rl, R.id.userinfo_contact_rl})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.userinfo_icon_rl:
|
||||
startActivityForResult(SelectUserIconActivity.getIntent(this), 1);
|
||||
break;
|
||||
case R.id.userinfo_nickname_rl:
|
||||
String nickName = mUserinfoNicknameTv.getText().toString();
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "nickName", nickName), 0x131);
|
||||
break;
|
||||
case R.id.userinfo_sex_rl:
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "sex", null), 0x132);
|
||||
break;
|
||||
case R.id.userinfo_area_rl:
|
||||
startActivityForResult(UserAreaActivity.getIntent(this), 0x121);
|
||||
break;
|
||||
case R.id.userinfo_qq_rl:
|
||||
case R.id.userinfo_contact_rl:
|
||||
String contact = mUserinfoContactTv.getText().toString();
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "contact", contact), 0x133);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
214
app/src/main/java/com/gh/gamecenter/UserInfoEditActivity.java
Normal file
214
app/src/main/java/com/gh/gamecenter/UserInfoEditActivity.java
Normal file
@ -0,0 +1,214 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 30/06/17.
|
||||
*/
|
||||
|
||||
public class UserInfoEditActivity extends BaseActivity {
|
||||
@BindView(R.id.userinfo_sex_man)
|
||||
TextView mUserinfoSexMan;
|
||||
@BindView(R.id.userinfo_sex_woman)
|
||||
TextView mUserinfoSexWoman;
|
||||
@BindView(R.id.userinfo_edit_sex)
|
||||
LinearLayout mUserinfoEditSex;
|
||||
@BindView(R.id.userinfo_nickname_et)
|
||||
EditText mUserinfoNicknameEt;
|
||||
@BindView(R.id.userinfo_nickname_iv)
|
||||
ImageView mUserinfoNicknameIv;
|
||||
@BindView(R.id.userinfo_edit_nickname)
|
||||
RelativeLayout mUserinfoEditNickname;
|
||||
@BindView(R.id.userinfo_contact_et)
|
||||
EditText mUserinfoContactEt;
|
||||
@BindView(R.id.userinfo_contact_iv)
|
||||
ImageView mUserinfoContactIv;
|
||||
@BindView(R.id.userinfo_edit_contact)
|
||||
LinearLayout mUserinfoEditContact;
|
||||
|
||||
TextView mSaveTv;
|
||||
|
||||
private String mEditType;
|
||||
private String mEditContent;
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String editType, String editContent) {
|
||||
Intent intent = new Intent(context, UserInfoEditActivity.class);
|
||||
intent.putExtra("editType", editType);
|
||||
intent.putExtra("editContent", editContent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_userinfo_edit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mEditType = getIntent().getStringExtra("editType");
|
||||
mEditContent = getIntent().getStringExtra("editContent");
|
||||
|
||||
// 添加分享图标
|
||||
mSaveTv = new TextView(this);
|
||||
mSaveTv.setBackgroundResource(R.drawable.border_black_bg);
|
||||
mSaveTv.setVisibility(View.GONE);
|
||||
mSaveTv.setText("保存");
|
||||
mSaveTv.setTextSize(13);
|
||||
mSaveTv.setGravity(Gravity.CENTER);
|
||||
mSaveTv.setTextColor(ContextCompat.getColor(this, R.color.title));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 24));
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
params.setMargins(0, 0, DisplayUtils.dip2px(this, 18), 0);
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(mSaveTv, params);
|
||||
|
||||
initView();
|
||||
|
||||
mSaveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
String title;
|
||||
switch (mEditType) {
|
||||
case "sex":
|
||||
mUserinfoEditSex.setVisibility(View.VISIBLE);
|
||||
title = "选择性别";
|
||||
break;
|
||||
case "nickName":
|
||||
mUserinfoEditNickname.setVisibility(View.VISIBLE);
|
||||
mSaveTv.setVisibility(View.VISIBLE);
|
||||
mUserinfoNicknameEt.addTextChangedListener(new UserInfoEditTextWatcher(mUserinfoNicknameEt));
|
||||
title = "修改昵称";
|
||||
if (!TextUtils.isEmpty(mEditContent)) {
|
||||
mUserinfoNicknameEt.setText(mEditContent);
|
||||
}
|
||||
break;
|
||||
case "contact":
|
||||
mUserinfoEditContact.setVisibility(View.VISIBLE);
|
||||
mSaveTv.setVisibility(View.VISIBLE);
|
||||
mUserinfoContactEt.addTextChangedListener(new UserInfoEditTextWatcher(mUserinfoContactEt));
|
||||
title = "联系方式";
|
||||
if (!TextUtils.isEmpty(mEditContent)) {
|
||||
mUserinfoContactEt.setText(mEditContent);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
title = "";
|
||||
break;
|
||||
}
|
||||
initTitle(title);
|
||||
}
|
||||
|
||||
private void saveData() {
|
||||
Intent data = new Intent();
|
||||
if ("nickName".equals(mEditType)) {
|
||||
String value = mUserinfoNicknameEt.getText().toString();
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
data.putExtra("editContent", value);
|
||||
setResult(0x131, data);
|
||||
finish();
|
||||
} else {
|
||||
toast("昵称不能为空");
|
||||
}
|
||||
} else if ("contact".equals(mEditType)) {
|
||||
String value = mUserinfoContactEt.getText().toString();
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
data.putExtra("editContent", value);
|
||||
setResult(0x133, data);
|
||||
finish();
|
||||
} else {
|
||||
toast("请输入QQ或邮箱");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.userinfo_nickname_iv, R.id.userinfo_contact_iv, R.id.userinfo_sex_man, R.id.userinfo_sex_woman})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.userinfo_nickname_iv:
|
||||
mUserinfoNicknameEt.setText("");
|
||||
break;
|
||||
case R.id.userinfo_contact_iv:
|
||||
mUserinfoContactEt.setText("");
|
||||
break;
|
||||
case R.id.userinfo_sex_man:
|
||||
Intent data = new Intent();
|
||||
data.putExtra("editContent", "男");
|
||||
setResult(0x132, data);
|
||||
finish();
|
||||
break;
|
||||
case R.id.userinfo_sex_woman:
|
||||
Intent data2 = new Intent();
|
||||
data2.putExtra("editContent", "女");
|
||||
setResult(0x132, data2);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private class UserInfoEditTextWatcher implements TextWatcher {
|
||||
private EditText mEditText;
|
||||
|
||||
public UserInfoEditTextWatcher(EditText e) {
|
||||
mEditText = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
int tvCount = s.length();
|
||||
if (mEditText == mUserinfoNicknameEt) {
|
||||
if (tvCount > 0) {
|
||||
mUserinfoNicknameIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mUserinfoNicknameIv.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
if (tvCount > 0) {
|
||||
mUserinfoContactIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mUserinfoContactIv.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,10 +10,12 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.gamecenter.InstallActivity;
|
||||
import com.gh.gamecenter.LibaoActivity;
|
||||
import com.gh.gamecenter.LoginActivity;
|
||||
@ -22,20 +24,25 @@ import com.gh.gamecenter.SettingActivity;
|
||||
import com.gh.gamecenter.ShareGhActivity;
|
||||
import com.gh.gamecenter.SuggestSelectActivity;
|
||||
import com.gh.gamecenter.UserInfoActivity;
|
||||
import com.gh.gamecenter.entity.AppEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* @author 温冠超
|
||||
* 294299195@qq.com
|
||||
* 2015-8-8 我的光环页面
|
||||
*/
|
||||
public class PersonalFragment extends BaseFragment implements LoginUtils.OnLoginListener{
|
||||
public class PersonalFragment extends BaseFragment implements LoginUtils.OnLoginListener {
|
||||
|
||||
|
||||
@BindView(R.id.personal_login_qq)
|
||||
@ -83,6 +90,7 @@ public class PersonalFragment extends BaseFragment implements LoginUtils.OnLogin
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
|
||||
@ -100,7 +108,7 @@ public class PersonalFragment extends BaseFragment implements LoginUtils.OnLogin
|
||||
LoginUtils.getInstance(getActivity()).QQLogin(this);
|
||||
break;
|
||||
case R.id.personal_login_wechat:
|
||||
changeLoginState(true);
|
||||
LoginUtils.getInstance(getActivity()).WCLogin(this);
|
||||
break;
|
||||
case R.id.personal_login_weibo:
|
||||
LoginUtils.getInstance(getActivity()).WeiBoLogin(this);
|
||||
@ -156,6 +164,29 @@ public class PersonalFragment extends BaseFragment implements LoginUtils.OnLogin
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
String channel = AppController.getInstance().getChannel();
|
||||
RetrofitManager.
|
||||
getApi().
|
||||
getUpdate(PackageUtils.getVersionName(getContext()), channel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<AppEntity>(){
|
||||
@Override
|
||||
public void onResponse(AppEntity response) {
|
||||
super.onResponse(response);
|
||||
float version = Float.valueOf(response.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName(getContext()));
|
||||
if (version > currentVersion) {
|
||||
mPersonalSettingUpdateHint.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mPersonalSettingUpdateHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 登录成功返回
|
||||
@Override
|
||||
public void onLogin() {
|
||||
|
||||
@ -10,13 +10,18 @@ import com.tencent.mm.sdk.openapi.BaseReq;
|
||||
import com.tencent.mm.sdk.openapi.BaseResp;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
|
||||
import com.tencent.mm.sdk.openapi.SendAuth;
|
||||
import com.tencent.mm.sdk.openapi.WXAPIFactory;
|
||||
|
||||
/**
|
||||
* 微信客户端回调activity示例
|
||||
* 注意:WXEntryActivity类只能在wxapi包下
|
||||
*/
|
||||
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
|
||||
public class WXEntryActivity extends Activity implements IWXAPIEventHandler,
|
||||
WeChatUserInfoThread.OnUserInfoCallBackListener {
|
||||
|
||||
private static final int RETURN_MSG_TYPE_LOGIN = 1;
|
||||
private static final int RETURN_MSG_TYPE_SHARE = 2;
|
||||
|
||||
private IWXAPI mWxApi;
|
||||
|
||||
@ -47,19 +52,59 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
|
||||
public void onResp(BaseResp baseResp) {
|
||||
switch (baseResp.errCode) {
|
||||
case BaseResp.ErrCode.ERR_OK:
|
||||
shareResult = "分享成功";
|
||||
if (RETURN_MSG_TYPE_SHARE == baseResp.getType()) {
|
||||
shareResult = "分享成功";
|
||||
} else {
|
||||
if (baseResp instanceof SendAuth.Resp) {
|
||||
SendAuth.Resp resp = (SendAuth.Resp) baseResp;
|
||||
Utils.log("WXEntryActivity=TOKEN::" + resp.token);
|
||||
new WeChatUserInfoThread(WXEntryActivity.this, resp.token).start();
|
||||
} else {
|
||||
shareResult = "登录失败";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BaseResp.ErrCode.ERR_USER_CANCEL:
|
||||
shareResult = "分享已取消";
|
||||
if (RETURN_MSG_TYPE_SHARE == baseResp.getType()) {
|
||||
shareResult = "分享已取消";
|
||||
} else {
|
||||
shareResult = "登录已取消";
|
||||
}
|
||||
break;
|
||||
case BaseResp.ErrCode.ERR_AUTH_DENIED:
|
||||
shareResult = "分享被拒绝";
|
||||
if (RETURN_MSG_TYPE_SHARE == baseResp.getType()) {
|
||||
shareResult = "分享被拒绝";
|
||||
} else {
|
||||
shareResult = "登录被拒绝";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
shareResult = "分享错误";
|
||||
if (RETURN_MSG_TYPE_SHARE == baseResp.getType()) {
|
||||
shareResult = "分享错误";
|
||||
} else {
|
||||
shareResult = "登录错误";
|
||||
}
|
||||
break;
|
||||
}
|
||||
Utils.toast(this, shareResult);
|
||||
if (shareResult != null) {
|
||||
Utils.toast(this, shareResult);
|
||||
finishActivity();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onComplete(String userInfo, String accessToken) {
|
||||
Utils.toast(this, "登录成功");
|
||||
finishActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
Utils.toast(this, "登录失败");
|
||||
finishActivity();
|
||||
}
|
||||
private void finishActivity() {
|
||||
this.finish();
|
||||
overridePendingTransition(0, 0);//禁止退出Activity 动画
|
||||
}
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
package com.gh.gamecenter.wxapi;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by khy on 30/06/17.
|
||||
* 获取微信 accessToken 和 userInfo
|
||||
*/
|
||||
|
||||
public class WeChatUserInfoThread extends Thread {
|
||||
|
||||
private OnUserInfoCallBackListener listener;
|
||||
|
||||
private String mCode;
|
||||
|
||||
//刷新access_token有效期
|
||||
private String refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
|
||||
|
||||
public WeChatUserInfoThread(OnUserInfoCallBackListener listener, String code) {
|
||||
this.listener = listener;
|
||||
this.mCode = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
try {
|
||||
String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" +
|
||||
Config.WECHAT_APPID + "&secret=" +
|
||||
Config.WECHAT_SECRET + "&code=" +
|
||||
mCode + "&grant_type=authorization_code";
|
||||
String jsonResult = getJsonResultByUrlPath(tokenUrl);
|
||||
JSONObject jsonObject = new JSONObject(jsonResult);
|
||||
String accessToken = jsonObject.getString("access_token");
|
||||
String openid = jsonObject.getString("openid");
|
||||
|
||||
if (!TextUtils.isEmpty(accessToken) && !TextUtils.isEmpty(openid)) {
|
||||
String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken + "&openid=" + openid;
|
||||
String userInfo = getJsonResultByUrlPath(userInfoUrl);
|
||||
if (listener != null && !TextUtils.isEmpty(userInfo)) {
|
||||
listener.onComplete(userInfo, accessToken);
|
||||
}
|
||||
} else {
|
||||
if (listener != null) {
|
||||
listener.onError();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (listener != null) {
|
||||
listener.onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getJsonResultByUrlPath(String path) throws Exception {
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setDoInput(true);
|
||||
int code = conn.getResponseCode();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
Utils.log(WeChatUserInfoThread.class.getSimpleName(), "WeChatUserInfoThread-getJsonResultByUrlPath::" + code);
|
||||
if (code == 200) {
|
||||
InputStream is = conn.getInputStream();
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, len);
|
||||
}
|
||||
String str = new String(baos.toByteArray());
|
||||
Utils.log(LoginUtils.class.getSimpleName(), "WeChatUserInfoThread-Body::" + str);
|
||||
return str;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface OnUserInfoCallBackListener {
|
||||
void onComplete(String userInfo, String accessToken);
|
||||
|
||||
void onError();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user