summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/MainActivity.java
blob: 483112d2f366109cd3cba87cc870b5b483f92e67 (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
package com.macaroon.piztor;

import java.util.Vector;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {
	public String token = "";
	public String uname = "";
	public int com;
	public int sec;
	public int step = 0;
	Transam t;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t = new Transam("192.168.1.171",2223,handler);
		Thread thread = new Thread(t);
		thread.start();
		
    }

    Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				token = ((ResLogin) msg.obj ).t;
				uname = ((ResLogin) msg.obj ).uinfo.username;
				com = ((ResLogin) msg.obj ).uinfo.gid.company;
				sec = ((ResLogin) msg.obj ).uinfo.gid.section;
				System.out.println(com);
				System.out.println(sec);
				System.out.println(((ResLogin) msg.obj ).uinfo.sex);
				for(int i=0;i<((ResLogin) msg.obj ).subscribeNumber;i++){
					System.out.println(((ResLogin) msg.obj ).sublist.get(i).company);	
					System.out.println(((ResLogin) msg.obj ).sublist.get(i).section);
				}
				System.out.println(token);			
				break;
			case 2:
				ResUserInfo r = (ResUserInfo) msg.obj ;
				System.out.println(r.number);
				for(int i=0;i<r.number;i++){
					System.out.println(r.uinfo.get(i).nickname);	
					System.out.println(r.uinfo.get(i).latitude);
					System.out.println(r.uinfo.get(i).longitude);
				}
				break;
			case 100:
				System.out.println(((ResPushMessage) msg.obj).message);
				break;
			case 101:
				int nn = ((ResPushLocation)msg.obj).n;
				Vector<RLocation> ll = ((ResPushLocation)msg.obj).l;
				for(int i=0;i<nn;i++){
					System.out.println(ll.get(i).latitude + " " + ll.get(i).longitude);
				}
				break;
			case -1:
				System.out.println(-1);
			}
			super.handleMessage(msg);
		}
	};
	
	
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    
   
	
    
    public void sendMessage(View view) {
    	
    		if(step == 0){
    		long time = System.currentTimeMillis();
    		ReqLogin r = new ReqLogin("hello","world",time,2000);   		
    		t.send(r);
    		step++;
    		}
    		else if(step == 1){
    			long time = System.currentTimeMillis();
    			ReqUpdate r = new ReqUpdate (token,uname,123.456,654.321,time,2000);  	
        		t.send(r);
        		step++;
    		}
    		else if(step == 2){
    			long time = System.currentTimeMillis();
    			ReqSendMessage r = new ReqSendMessage (token,uname,"wurusai",time,2000); 
        		t.send(r);
        		step++;
    		}
    		else if(step == 3){
    			long time = System.currentTimeMillis();
    			ReqLogout r = new ReqLogout(token,uname,time,2000);
        		t.send(r);
        		step++;
    		}

    	
    	
    }
    
    
	
	
    
    
    
      
   
    
    
}