package com.example.admin.s20172285_0917_02;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.location.LocationListener;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.skt.Tmap.TMapCircle;
import com.skt.Tmap.TMapData;
import com.skt.Tmap.TMapGpsManager;
import com.skt.Tmap.TMapMarkerItem;
import com.skt.Tmap.TMapPOIItem;
import com.skt.Tmap.TMapPoint;
import com.skt.Tmap.TMapView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity
        implements TMapView.OnLongClickListenerCallback,
        LocationListener, TMapGpsManager.onLocationChangedCallback{

    private TMapView tMapView = null;
    TMapGpsManager gps = null;
    public  static  String mApiKey = null;
    public  static  String mBizAppID = null;
    private static final  String TAG = "Test Temp";
    Bitmap icon1, icon2;
    TMapCircle tCircle;
    TMapData tMapData;
    TMapPoint point2= null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LinearLayout liner =(LinearLayout) findViewById(R.id.linear);
        tMapView= new TMapView(this);
        mApiKey="20f65378-ed7f-4148-ac91-bfff34cca044";
        tMapView.setSKTMapApiKey(mApiKey);
        liner.addView(tMapView);
        setContentView(liner);

        gps =new TMapGpsManager(MainActivity.this);
        gps.setMinTime(1);
        gps.setMinDistance(1);
        gps.setProvider(gps.NETWORK_PROVIDER);
        gps.OpenGps();

        tMapData=new TMapData();

        tMapView.setZoomLevel(16);
        //tMapView.setIconVisibility(true);
        tMapView.setCompassMode(true);
        tMapView.setSightVisible(true);
        tMapView.setMapPosition(TMapView.POSITION_NAVI);
        tMapView.setTrackingMode(true);
    }

    @Override
    public void  onLocationChanged(Location location){

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras){

    }
    @Override
    public void onProviderEnabled(String provider){

    }
    @Override
    public void onProviderDisabled(String provider){

    }
    @Override
    public void onLongPressEvent(ArrayList<TMapMarkerItem> arrayList,
                                 ArrayList<TMapPOIItem> arrayList1, TMapPoint tMapPoint){

 //      tMapView.setIconVisibility(false);
//        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon3);

 //       Toast.makeText(getBaseContext(), String.valueOf(tMapPoint.getLatitude())+","
 //               +String.valueOf(tMapPoint.getLongitude()), Toast.LENGTH_SHORT).show();
 //       tMapView.setIcon(bitmap);
//        tMapView.setIconVisibility(true);

        TMapPoint point= new TMapPoint(tMapPoint.getLatitude(), tMapPoint.getLongitude());
        TMapMarkerItem item1 =new TMapMarkerItem();
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon3);
        item1.setTMapPoint(point);
        item1.setName("Target");
        item1.setVisible(item1.VISIBLE);
        item1.setIcon(bitmap);
        item1.setCalloutTitle("넘버1");
        item1.setCalloutSubTitle("위치추적");
        item1.setCanShowCallout(true);
        item1.setCanShowCallout(true);
        Bitmap bitmap_i =BitmapFactory.decodeResource(getResources(), R.drawable.icon4);
        item1.setCalloutRightButtonImage(bitmap_i);
        tMapView.addMarkerItem("ID_01", item1);
    }
    @Override
    public void onLocationChange(Location location){
        tMapView.setCenterPoint(location.getLongitude(), location.getLatitude());
        tMapView.setLocationPoint(location.getLongitude(), location.getLatitude());
    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
        gps.CloseGps();
    }

    @Override
    protected void onPause(){ super.onPause();}
}
