LoginActivity.java

This commit is contained in:
ram 2016-08-18 21:32:25 +08:00
parent 76e0c6fb5f
commit 39fb66d3ec
1 changed files with 16 additions and 16 deletions

View File

@ -42,7 +42,7 @@ import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError; import com.tencent.tauth.UiError;
/** /**
* 登陆界面 * 鐧婚檰鐣岄潰
* *
* @date 2014-4-24 * @date 2014-4-24
* @author Stone * @author Stone
@ -66,7 +66,7 @@ public class LoginActivity extends Activity implements OnClickListener {
private ImageView mNewLoginButton; private ImageView mNewLoginButton;
private TextView backInfo; private TextView backInfo;
// QQ登陆 // QQ鐧婚檰
private static Tencent mTencent; private static Tencent mTencent;
// private QQAuth mQQAuth; // private QQAuth mQQAuth;
@ -97,12 +97,12 @@ public class LoginActivity extends Activity implements OnClickListener {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// 初始化 Bmob SDK // 鍒濆<EFBFBD> Bmob SDK
// 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ID // 浣跨敤鏃惰灏嗙浜屼釜鍙傛暟Application ID鏇挎崲鎴愪綘鍦˙mob鏈嶅姟鍣ㄧ鍒涘缓鐨凙pplication ID
Bmob.initialize(this, "252a2c58d0dc9a78a5411501c62ce0de"); Bmob.initialize(this, "252a2c58d0dc9a78a5411501c62ce0de");
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
// QQ登陆, 获取实例 // QQ鐧婚檰, 鑾峰彇瀹炰緥
// mQQAuth = QQAuth.createInstance(APP_ID, // mQQAuth = QQAuth.createInstance(APP_ID,
// this.getApplicationContext()); // this.getApplicationContext());
mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext()); mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext());
@ -134,7 +134,7 @@ public class LoginActivity extends Activity implements OnClickListener {
etPassword.setText(sp.getString("password", null)); etPassword.setText(sp.getString("password", null));
} }
// 保存用户的登陆记录 // 淇濆瓨鐢ㄦ埛鐨勭櫥闄嗚<EFBFBD>
private void saveUserInfo(String username, String password) { private void saveUserInfo(String username, String password) {
SharedPreferences sp = getSharedPreferences("UserInfo", 0); SharedPreferences sp = getSharedPreferences("UserInfo", 0);
Editor editor = sp.edit(); Editor editor = sp.edit();
@ -157,15 +157,15 @@ public class LoginActivity extends Activity implements OnClickListener {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
// 登陆 // 鐧婚檰
case R.id.btn_login: case R.id.btn_login:
username = etUsername.getText().toString(); username = etUsername.getText().toString();
password = etPassword.getText().toString(); password = etPassword.getText().toString();
if (!Util.isNetworkConnected(this)) { if (!Util.isNetworkConnected(this)) {
toast("木有网络 ( ⊙ o ⊙ ) "); toast("鏈ㄦ湁缃戠粶 ( 鈯<> o 鈯<> ) ");
} else if (username.equals("") || password.equals("")) { } else if (username.equals("") || password.equals("")) {
toast("请输入账号和密码"); toast("璇疯緭鍏ヨ处鍙峰拰瀵嗙爜");
break; break;
} else { } else {
final User bu2 = new User(); final User bu2 = new User();
@ -174,10 +174,10 @@ public class LoginActivity extends Activity implements OnClickListener {
bu2.login(this, new InsertListener() { bu2.login(this, new InsertListener() {
@Override @Override
public void onSuccess() { public void onSuccess() {
toast("欢迎进入 在这里 服务系统"); toast("娆㈣繋杩涘叆 鍦ㄨ繖閲<E7B996> 鏈嶅姟绯荤粺");
// 保存用户信息 // 淇濆瓨鐢ㄦ埛淇
saveUserInfo(username, password); saveUserInfo(username, password);
// 跳转到主页 // 璺宠浆鍒颁富椤<EFBFBD>
User.userId = bu2.getObjectId(); User.userId = bu2.getObjectId();
Intent toHome = new Intent(LoginActivity.this, BaseActivity.class); Intent toHome = new Intent(LoginActivity.this, BaseActivity.class);
startActivity(toHome); startActivity(toHome);
@ -187,7 +187,7 @@ public class LoginActivity extends Activity implements OnClickListener {
@Override @Override
public void onFailure(String msg) { public void onFailure(String msg) {
toast("用户名或密码错误"); toast("鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒");
} }
}); });
} }
@ -227,15 +227,15 @@ public class LoginActivity extends Activity implements OnClickListener {
@Override @Override
public void onComplete(Object response) { public void onComplete(Object response) {
if (null == response) { if (null == response) {
Util.showResultDialog(LoginActivity.this, "返回为空", "登录失败"); Util.showResultDialog(LoginActivity.this, "杩斿洖涓虹┖", "鐧诲綍澶辫触");
return; return;
} }
JSONObject jsonResponse = (JSONObject) response; JSONObject jsonResponse = (JSONObject) response;
if (null != jsonResponse && jsonResponse.length() == 0) { if (null != jsonResponse && jsonResponse.length() == 0) {
Util.showResultDialog(LoginActivity.this, "返回为空", "登录失败"); Util.showResultDialog(LoginActivity.this, "杩斿洖涓虹┖", "鐧诲綍澶辫触");
return; return;
} }
// Util.showResultDialog(LoginActivity.this, response.toString(), "登录成功"); // Util.showResultDialog(LoginActivity.this, response.toString(), "鐧诲綍鎴愬姛");
doComplete((JSONObject) response); doComplete((JSONObject) response);
try { try {
User.userId = jsonResponse.getString("openid"); User.userId = jsonResponse.getString("openid");