package fishrungames.kobserver;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;

import android.content.Context;
import android.location.LocationManager;


import fishrungames.kobserver.GetMessageTimerTask;

public class JniWrapper
{
    static {
        System.loadLibrary("KObserver");
    }
    
    
    
    public static Timer UpdateTimer;
    
    public static MessagesActivity messagesActivity = null;
	
    public static boolean connected = false;
    
    //Info to be saved
    
    public static String LastName = new String();
    public static String FirstName = new String();
    public static String MiddleName = new String();
    public static String ContactNumber = new String();
    public static int MapState;
    public static int UikNumber;
    public static int Status;
    public static float PosX;
    public static float PosY;

    
    public static ArrayList<String> messages_headers = new ArrayList<String>(Arrays.asList("Подключение установлено"));
    public static ArrayList<String> messages_texts = new ArrayList<String>(Arrays.asList("Подключение к серверу успешно установлено"));
    
    public static ConnectActivity connectActivity;
   
    public static native void Open(String addr, String port);
    public static native void Close();
    
    public static void OnConnectSuccessful()
    {
    	connectActivity.goToMainMenu();
    	connected = true;
    }
    
    public static native void UpdateUserInfo(String lastName, String firstName, String middleName, String contactNumber, int mapState, int Uik, int Status, float posX, float posY);
    
    public static native void SetAlarmCommon();
    
    public static native void SetAlarmExclusion();
    
    public static native void SetAlarmInjection();
    
    public static native void SetAlarmCarousel();
    
    public static native void SetAlarmAssault();
    
    public static native void SendMessage(String msg);
    
    public static native String GetLastMessageHeader();
    
    public static native String GetLastMessageText();
    
    public static native int GetNumberOfUsers();
    public static native int GetUserUik(int i);
    public static native float GetUserPosX(int i);
    public static native float GetUserPosY(int i);
    public static native int GetUserMapState(int i);
    public static native String GetUserDescription(int i);
    
    public static native float GetMapCenterPosX();
    public static native float GetMapCenterPosY();
    public static native int GetMapCenterZoom();
   
    
    public static native float SetPosition(float x, float y);
    
    public static native void ChangeMapType(int mapType);
    
    public static void StartGetMessageTimer()
    {
    	UpdateTimer = new Timer();
    	
    	
    	UpdateTimer.schedule(new GetMessageTimerTask(), 0, 100);
    }
    
    public static void StopGetMessageTimer()
    {
    	UpdateTimer = null;
    }
    
    public static LocationManager locationManager = null;
    
    public static void StartUpdateMapLocation(MainMenuActivity act)
    {
    	locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE);
    	
    	//Use both =)
        //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler());
    	locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler());
    	
    }
    
}