Skip to content

Commit

Permalink
获取个人信息,部分页面修改
Browse files Browse the repository at this point in the history
  • Loading branch information
846425567 committed Aug 19, 2015
1 parent 1fa761c commit 579d16e
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 83 deletions.
112 changes: 108 additions & 4 deletions src/main/java/cn/sdu/online/findteam/activity/InfoPersonActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,40 @@

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import cn.sdu.online.findteam.R;
import cn.sdu.online.findteam.fragment.BuildTeamFragment;
import cn.sdu.online.findteam.net.NetCore;
import cn.sdu.online.findteam.resource.DialogDefine;
import cn.sdu.online.findteam.resource.RoundImageView;
import cn.sdu.online.findteam.share.MyApplication;
import cn.sdu.online.findteam.util.AndTools;
import cn.sdu.online.findteam.util.ChangeHeader;


Expand All @@ -34,14 +50,33 @@ public class InfoPersonActivity extends Activity implements View.OnClickListener
private RoundImageView head;

private ChangeHeader changeHeader;
Dialog dialog;
View contentView;
JSONObject person;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_info_person);

dialog = DialogDefine.createLoadingDialog(InfoPersonActivity.this,
"加载中...");
isEdited = false;
dialog.show();
if(!AndTools.isNetworkAvailable(MyApplication.getInstance())){
if (dialog != null){
dialog.dismiss();
Toast.makeText(InfoPersonActivity.this,"当前网络不可用!",Toast.LENGTH_SHORT).show();
return;
}
}
findview();
Thread loadUserInfo = new Thread(new loadUserInfo());
loadUserInfo.start();
/* setContentView(R.layout.activity_info_person);*/


/* isEdited = false;
bt_return = (Button) findViewById(R.id.bt_return);
text_nickname = (EditText) findViewById(R.id.text_nickname);
text_introduction = (EditText) findViewById(R.id.text_introduction);
Expand All @@ -62,7 +97,77 @@ public void onCreate(Bundle savedInstanceState) {
text_edit.setOnClickListener(this);
bt_return.setOnClickListener(this);
head.setOnClickListener(this);
head.setOnClickListener(this);*/
}

class loadUserInfo implements Runnable {
@Override
public void run() {
try {
String info = new NetCore().getUserInfo("");
if (!info.equals("")) {
JSONTokener jsonParser = new JSONTokener(info);
// 此时还未读取任何json文本,直接读取就是一个JSONObject对象。
// 如果此时的读取位置在"name" : 了,那么nextValue就是"yuanzhifei89"(String)
try {
person = (JSONObject) jsonParser.nextValue();
if (person != null){
Message message = new Message();
handler.sendMessage(message);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
text_phonenumber.setText(person.getString("contact"));
text_nickname.setText(person.getString("username"));
text_introduction.setText(person.getString("introduce"));
text_email.setText(person.getString("mail"));
text_realname.setText(person.getString("realName"));
text_gender.setText(person.getString("sex"));
} catch (JSONException e) {
e.printStackTrace();
}
if (dialog != null) {
dialog.dismiss();
}
InfoPersonActivity.this.setContentView(contentView);
}
};

private void findview() {
contentView = View.inflate(InfoPersonActivity.this, R.layout.activity_info_person, null);
bt_return = (Button) contentView.findViewById(R.id.bt_return);
text_nickname = (EditText) contentView.findViewById(R.id.text_nickname);
text_introduction = (EditText) contentView.findViewById(R.id.text_introduction);
text_tag1 = (EditText) contentView.findViewById(R.id.text_tag1);
text_tag2 = (EditText) contentView.findViewById(R.id.text_tag2);
text_tag3 = (EditText) contentView.findViewById(R.id.text_tag3);
text_realname = (EditText) contentView.findViewById(R.id.text_realname);
text_gender = (EditText) contentView.findViewById(R.id.text_gender);
text_dress = (EditText) contentView.findViewById(R.id.text_dress);
text_school = (EditText) contentView.findViewById(R.id.text_school);
text_phonenumber = (EditText) contentView.findViewById(R.id.text_phonenumber);
text_email = (EditText) contentView.findViewById(R.id.text_email);
text_edit = (TextView) contentView.findViewById(R.id.text_edit);
head = (RoundImageView) contentView.findViewById(R.id.head);
relativeLayout = (RelativeLayout) contentView.findViewById(R.id.info_person_headlayout);
relativeLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
getWindowManager().getDefaultDisplay().getWidth()));

text_edit.setOnClickListener(InfoPersonActivity.this);
bt_return.setOnClickListener(InfoPersonActivity.this);
head.setOnClickListener(InfoPersonActivity.this);
}

@Override
Expand Down Expand Up @@ -183,8 +288,7 @@ public void onClick(DialogInterface dialog,
}
}
}).show();
}
else {
} else {
Intent intent = new Intent();
intent.setClass(InfoPersonActivity.this, ImgShowerActivity.class);
intent.putExtra("bitmap", getBytes(head.getBmp()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import cn.sdu.online.findteam.net.NetCore;
import cn.sdu.online.findteam.resource.DialogDefine;
import cn.sdu.online.findteam.share.DemoUtil;
import cn.sdu.online.findteam.share.MyApplication;
import cn.sdu.online.findteam.util.AndTools;
import cn.sdu.online.findteam.util.LoginUtils;

Expand Down Expand Up @@ -91,6 +92,11 @@ public void onClick(View v) {
return;
}

if (!AndTools.isNetworkAvailable(MyApplication.getInstance())){
Toast.makeText(LoginActivity.this, "当前网络不可用!", Toast.LENGTH_SHORT).show();
return;
}

// 打开progressDialog
dialog = DialogDefine.createLoadingDialog(LoginActivity.this,
"登陆中...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import cn.sdu.online.findteam.entity.User;
import cn.sdu.online.findteam.net.NetCore;
import cn.sdu.online.findteam.share.DemoUtil;
import cn.sdu.online.findteam.share.MyApplication;
import cn.sdu.online.findteam.util.AndTools;
import cn.sdu.online.findteam.util.LoginUtils;

Expand Down Expand Up @@ -57,7 +58,7 @@ public void run() {
startActivity(intent);
OriginActivity.this.finish();
} else {
if (!AuthService.getInstance().isLogin()) {
if (!AuthService.getInstance().isLogin() || !AndTools.isNetworkAvailable(MyApplication.getInstance())) {
Bundle bundle = new Bundle();
bundle.putString("fail", "初始化聊天功能失败,请重新选择帐号登录");
Message message = new Message();
Expand Down
90 changes: 74 additions & 16 deletions src/main/java/cn/sdu/online/findteam/activity/RegisterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import cn.sdu.online.findteam.net.NetCore;
import cn.sdu.online.findteam.resource.DialogDefine;
import cn.sdu.online.findteam.share.DemoUtil;
import cn.sdu.online.findteam.share.MyApplication;
import cn.sdu.online.findteam.util.AndTools;
import cn.sdu.online.findteam.util.LoginUtils;

Expand All @@ -43,6 +44,7 @@ public class RegisterActivity extends Activity implements View.OnClickListener {
private Dialog dialog;
SharedPreferences preferences;
SharedPreferences.Editor editor;
User user;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -63,7 +65,10 @@ private void initView() {

@Override
public void onClick(View v) {
Log.v("输入格式", registeremail.getText().toString());
if (!AndTools.isNetworkAvailable(MyApplication.getInstance())){
Toast.makeText(RegisterActivity.this, "当前网络不可用!", Toast.LENGTH_SHORT).show();
return;
}
String name = registername.getText().toString();
String email = registeremail.getText().toString();
String password = registerpassword.getText().toString();
Expand Down Expand Up @@ -97,7 +102,7 @@ public void run() {
}

private Bundle startRegister(String name, String email, String password, String confirm) {
User user = new User();
user = new User();
user.setName(name);
user.setEmail(email);
user.setPassword(password);
Expand All @@ -108,9 +113,7 @@ private Bundle startRegister(String name, String email, String password, String
String messageResult = "";
try {
codeResult = new JSONObject(jsonResult).getInt("code");
Log.v("后台的数据", codeResult + "");
messageResult = new JSONObject(jsonResult).getString("msg");
Log.v("后台的数据", messageResult);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down Expand Up @@ -162,14 +165,8 @@ public void handleMessage(Message message) {
return;
}

DemoUtil.getExecutor().execute(new Runnable() {
@Override
public void run() {
String username = registername.getText().toString();
ALoginParam params = LoginUtils.loginRequest(username, registerpassword.getText().toString());
registerWuKong(params, username);
}
});
Thread loginThread = new Thread(new LoginThread());
loginThread.start();
break;

default:
Expand All @@ -178,7 +175,7 @@ public void run() {
}
};

private void registerWuKong(ALoginParam param, final String nickname){
private void loginWuKong(ALoginParam param, final String nickname) {
AuthService.getInstance().login(param, new com.alibaba.wukong.Callback<AuthInfo>() {
@Override
public void onSuccess(AuthInfo data) {
Expand All @@ -187,15 +184,15 @@ public void onSuccess(AuthInfo data) {
editor = preferences.edit();
editor.remove("loginName").apply();
editor.remove("loginPassword").apply();
editor.putString("loginName", registername.getText().toString()).apply();
editor.putString("loginPassword", registerpassword.getText().toString()).apply();
editor.putString("loginName", user.getName()).apply();
editor.putString("loginPassword", user.getPassword()).apply();

Intent intent = new Intent();
if (MainActivity.mainActivity != null) {
MainActivity.mainActivity.finish();
}
intent.setClass(RegisterActivity.this, MainActivity.class);
intent.putExtra("loginIdentity", "<##用户##>" + registername.getText().toString());
intent.putExtra("loginIdentity", "<##用户##>" + user.getName());
intent.putExtra("loginID", preferences.getLong("loginID", 0));
if (dialog != null) {
dialog.dismiss();
Expand All @@ -221,4 +218,65 @@ public void onProgress(AuthInfo s, int i) {
}
});
}

class LoginThread implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
Bundle result = startLogin();
Message message = new Message();
message.setData(result);
loginHandler.sendMessage(message);
}
}

private Bundle startLogin() {
String jsonResult = new NetCore().Login(user);
int codeResult = 404;
String messageResult = "";
try {
codeResult = new JSONObject(jsonResult).getInt("code");
messageResult = new JSONObject(jsonResult).getString("msg");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bundle bundle = new Bundle();
bundle.putInt("code", codeResult);
bundle.putString("msg", messageResult);
return bundle;
}

Handler loginHandler = new Handler() {
public void handleMessage(Message message) {
final Bundle bundle = message.getData();
if (bundle.getInt("code") == NetCore.LOGIN_ERROR) {
// 登录失败
if (dialog != null) {
dialog.dismiss();
}
Toast.makeText(RegisterActivity.this,
bundle.getString("msg"), Toast.LENGTH_SHORT)
.show();
} else if (bundle.getInt("code") > NetCore.LOGIN_ERROR) {
// 登录成功
if (dialog != null) {
dialog.dismiss();
}

if (bundle.getString("msg").trim().length() == 0) {
Toast.makeText(RegisterActivity.this, "网络错误!", Toast.LENGTH_SHORT).show();
return;
}

DemoUtil.getExecutor().execute(new Runnable() {
@Override
public void run() {
ALoginParam params = LoginUtils.loginRequest(user.getName(), user.getPassword());
loginWuKong(params, user.getName());
}
});
}
}
};
}
Loading

0 comments on commit 579d16e

Please sign in to comment.