summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/UpdateInfo.java
blob: cd428f79e2ca8438bec6c4c0b1e0a16dad592783 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.macaroon.piztor;

import java.lang.ref.WeakReference;
import java.util.Vector;

import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.macaroon.piztor.Settings.ReCall;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class UpdateInfo extends PiztorAct {
	TextView userName, nickName;
	EditText oldPass, newPass;
	Button submit;

	static class ReCall extends Handler {
		WeakReference<UpdateInfo> outerClass;

		ReCall(UpdateInfo activity) {
			outerClass = new WeakReference<UpdateInfo>(activity);
		}

		@Override
		public void handleMessage(Message m) {
			UpdateInfo out = outerClass.get();
			if (out == null) {
				System.out.println("act被回收了");
			}
			switch (m.what) {
			case Res.Login:// 上传自己信息成功or失败
				Log.d("update location", "successfull");
				break;
			case Res.UserInfo:// 得到用户信息
				ResUserInfo userInfo = (ResUserInfo) m.obj;
				System.out.println("revieve ........" + userInfo.uinfo.size());
				Vector<RUserInfo> uinfo = userInfo.uinfo;
				for (RUserInfo info : uinfo) {
					System.out
							.println(info.latitude + "     " + info.longitude);
					UserInfo r = out.mapInfo.getUserInfo(info.uid);
					if (r != null) {
						r.setInfo(info.gid.company, info.gid.section, info.sex,
								info.nickname);
						r.setLocation(info.latitude, info.longitude);
					} else {
						r = new UserInfo(info.uid);
						r.setInfo(info.gid.company, info.gid.section, info.sex,
								info.nickname);
						r.setLocation(info.latitude, info.longitude);
						out.mapInfo.addUserInfo(r);
					}
				}
				break;
			case Res.Logout:// 登出
				out.appMgr.trigger(AppMgr.logout);
				break;
			case Res.SendMessage:
				Log.d(LogInfo.resquest, "send message successfully");
				break;
			case Res.SetPassword:
				ResSetPassword res = (ResSetPassword) m.obj;
				out.receiveMessage("修改成功,请重新登录");
				out.appMgr.trigger(AppMgr.logout);
				break;
			case -1:
				EException eException = (EException) m.obj;
				if (eException.Etype == EException.EPasswordFailedException) 
					out.receiveMessage("密码错误");
				else {
					out.appMgr.trigger(AppMgr.logout);
				}
				break;
			default:
				break;
			}
		}
	}
	ReCall handler = new ReCall(this);
	void receiveMessage(String msg) {
		Log.d("recieve message", msg);
		Toast toast = Toast.makeText(getApplicationContext(), msg,
				Toast.LENGTH_LONG);
		toast.show();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		id = "updateInfo";
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_updateinfo);
	}

	@Override
	protected void onStart() {
		super.onStart();
		oldPass = (EditText) findViewById(R.id.password_old);
		newPass = (EditText) findViewById(R.id.password_new);
		submit = (Button) findViewById(R.id.btn_submit);
		userName = (TextView) findViewById(R.id.username);
		nickName = (TextView) findViewById(R.id.nickname);
		userName.setText(app.username);
		nickName.setText(app.mapInfo.myInfo.nickname);
		submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				String oldpass = oldPass.getText().toString();
				String newpass = newPass.getText().toString();
				ReqSetPassword req = new ReqSetPassword(app.token,
						app.username, oldpass, newpass, System
								.currentTimeMillis(), 3000);
				transam.send(req);
			}
		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		transam.setHandler(handler);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.update_info, menu);
		return true;
	}

}