summaryrefslogblamecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/Main.java
blob: fe49ab6d9e5a91f9abb2a45e52a4c19e445c7da2 (plain) (tree)
1
2
3
4
5
6
7
8
9



                            




                                       
                             


                                  
                                




















                                                                                   

                                                                                                            





                                                               
                                    



                                                      
                               
                                                                     
                                                  
                                                                             
                                      
                                                                            

                                                                          
                                      











                                                                                                           
                                                                          




                                                                    

                                                                                               

                                                                                                   
                                                                          

                                      

























                                                     




                              




                                                                     





                                                                                             
                                              

                                                                                                        

                                                       

                                              














                                                                                        

                                                                                                        

























































                                                                                        

                                                                             









                                                                                    
                        

                                                        
                                                                 




                                                                        
                                                                  

                         





                                                                           
                                                               
         








                                                               




                                                                                        
                             

         
 
package com.macaroon.piztor;

import java.util.Timer;
import java.util.TimerTask;
import android.annotation.SuppressLint;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Main extends PiztorAct {
	final static int SearchButtonPress = 1;
	final static int FetchButtonPress = 2;
	final static int FocuseButtonPress = 3;
	final static int SuccessFetch = 4;
	final static int FailedFetch = 5;
	final static int TimerFlush = 6;
	ActMgr actMgr;
	ImageButton btnSearch, btnFetch, btnFocus, btnSettings;
	Timer autodate;
	@SuppressLint("HandlerLeak")
	Handler fromGPS = new Handler() {
		@Override
		public void handleMessage(Message m) {
			if (m.what != 0) {
				Location l = (Location) m.obj;
				if (l == null)
					System.out.println("fuck!!!");
				else {
					ReqUpdate r = new ReqUpdate(UserInfo.token,
							UserInfo.username, l.getLatitude(),
							l.getLongitude(), System.currentTimeMillis(), 1000);
					AppMgr.transam.send(r);
				}
			}
		}
	};

	@SuppressLint("HandlerLeak")
	Handler fromTransam = new Handler() {
		@Override
		public void handleMessage(Message m) {
			switch (m.what) {
			case 1:
				ResUpdate update = (ResUpdate) m.obj;
				if (update.s == 0)
					System.out.println("update success");
				else {
					System.out.println("update failed");
					actMgr.trigger(AppMgr.errorToken);
				}
				break;
			case 2:
				ResLocation location = (ResLocation) m.obj;
				if (location.s == 0) {
					for (int i = 0; i < location.n; i++) {
						System.out.println(location.l.get(i).i + " : "
								+ location.l.get(i).lat + " "
								+ location.l.get(i).lot);
					}
					actMgr.trigger(SuccessFetch);
				} else {
					System.out
							.println("resquest for location must be wrong!!!");
					actMgr.trigger(AppMgr.errorToken);
				}
				break;
			case 3:
				ResUserinfo r = (ResUserinfo) m.obj;
				if (r.s == 0) {
					System.out.println("id : " + r.uid + " sex :  " + r.sex
							+ " group : " + r.gid);
				} else {
					System.out.println("reqest for userInfo must be wrong!!!");
					actMgr.trigger(AppMgr.errorToken);
				}
				break;
			default:
				break;
			}

		}
	};

	String cause(int t) {
		switch (t) {
		case SearchButtonPress:
			return "Search Button Press";
		case FetchButtonPress:
			return "Fetch Button Press";
		case FocuseButtonPress:
			return "Focuse Button Press";
		case SuccessFetch:
			return "Success Fetch";
		case FailedFetch:
			return "Failed Fetch";
		case TimerFlush:
			return "TimerFlush";
		default:
			return "Fuck!!!";
		}
	}

	// TODO flush map view
	void flushMap() {

	}

	class StartStatus extends ActStatus {

		@Override
		void enter(int e) {
			System.out.println("enter start status!!!!");
			if (e == ActMgr.Create) {
				AppMgr.transam.send(new ReqUserinfo(UserInfo.token,
						UserInfo.username, UserInfo.id, System
								.currentTimeMillis(),