// Path: at.attentec.com/android/at.attentec.client/src/com/attentec/AttentecService.java
// public interface ServiceUpdateUIListener {
// 	/** Tell UI to update. */
// 	void updateUI();
// 
// 	/** End UI Activity. */
// 	void endActivity();
// }


import java.io.ByteArrayInputStream;
import java.text.ParseException;
import java.util.Date;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import com.attentec.AttentecService.ServiceUpdateUIListener;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

/***
 * Copyright (c) 2010 Attentec AB, http://www.attentec.se
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.attentec;




/**
 * Shows a map with contacts at their location, with
 * clickable markers for easy contact.
 *
 * @author David Granqvist
 * @author Malte Lenz
 * @author Johannes Nordkvist
 *
 */
public class CloseToYou extends MapActivity {



	/**
	 * Tag used for logging.
	 */
	private static final String TAG = "Attentec";

	/** Minimum distance to show on screen, so defines a limit on max zoom-in. */
	private static final int MAX_ZOOM = 3000;

	/** Maximum distance to show on screen. */
	private static final int MIN_ZOOM = 3000000;

	// Declares map and its controller.
	/** Instance of the map view. */
	private MapView mapView;
	/** Instance of the map controller. */
	private MapController mc;

	/** Database adapter. */
	private DatabaseAdapter dbh;

	/** Overlay that should show my location. */
	private MyLocationOverlay mlo;

	/** Database cursor for handling locations. */
	private Cursor locationcursor;

	/** Used to show contact info dialog. */
	private long dialogid;

	/** Used to show contact info dialog. */
	private ContactDialogCreator cdc;

	/** Resources . */
	private Resources res;

	/** Maximum latitude that should be showed on the map. */
	private int maxLat = Integer.MIN_VALUE;
	/** Maximum longitude that should be showed on the map. */
	private int maxLng = Integer.MIN_VALUE;
	/** Minimum latitude that should be showed on the map. */
	private int minLat = Integer.MAX_VALUE;
	/** Minimum longitude that should be showed on the map. */
	private int minLng = Integer.MAX_VALUE;

	/** Vertical padding for map bounds. */
	private final Float vpadding = 0.1f;
	/** Bottom padding for map bounds. */
	private final Float hpaddingBottom = 0.1f;
	/** Top padding for map bounds. */
	private final Float hpaddingTop = 0.4f;

	/** Used for converting to GeoPoint integer. */
	private static final int ONE_MILLION = 1000000;
	/** Minimum length for contact info (email/phone). */
	private static final int MINIMUM_ACCEPTED_CONTACT_INFO_LENGTH = 4;

	private ContactItemizedOverlay itemizedOverlay;

	/* Called when the activity is first created. */
	@Override
	public final void onCreate(final Bundle savedInstanceState) {
		Log.d(TAG, "CloseToYou onCreate");

		super.onCreate(savedInstanceState);
		setContentView(R.layout.closetoyou);

		res = getResources();

		//Setup database connection
		dbh = new DatabaseAdapter(this);
		dbh.open();

		locationcursor = dbh.getLocations();
		locationcursor.moveToFirst();
		startManagingCursor(locationcursor);

		//Setup the map
		mapView = (MapView) findViewById(R.id.mapView);
		//Create ContactItemizedOverlay for mapView
		itemizedOverlay = new ContactItemizedOverlay(new ColorDrawable(), mapView);
		mapView.setBuiltInZoomControls(true);
		mapView.displayZoomControls(true);
		mapView.setSatellite(true);
		mc = mapView.getController();


// Path: at.attentec.com/android/at.attentec.client/src/com/attentec/AttentecService.java
// public interface ServiceUpdateUIListener {
// 	/** Tell UI to update. */
// 	void updateUI();
// 
// 	/** End UI Activity. */
// 	void endActivity();
// }


// Path: at.attentec.com/android/at.attentec.client/src/com/attentec/CloseToYou.java
import java.io.ByteArrayInputStream;
import java.text.ParseException;
import java.util.Date;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import com.attentec.AttentecService.ServiceUpdateUIListener;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

/***
 * Copyright (c) 2010 Attentec AB, http://www.attentec.se
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.attentec;




/**
 * Shows a map with contacts at their location, with
 * clickable markers for easy contact.
 *
 * @author David Granqvist
 * @author Malte Lenz
 * @author Johannes Nordkvist
 *
 */
public class CloseToYou extends MapActivity {



	/**
	 * Tag used for logging.
	 */
	private static final String TAG = "Attentec";

	/** Minimum distance to show on screen, so defines a limit on max zoom-in. */
	private static final int MAX_ZOOM = 3000;

	/** Maximum distance to show on screen. */
	private static final int MIN_ZOOM = 3000000;

	// Declares map and its controller.
	/** Instance of the map view. */
	private MapView mapView;
	/** Instance of the map controller. */
	private MapController mc;

	/** Database adapter. */
	private DatabaseAdapter dbh;

	/** Overlay that should show my location. */
	private MyLocationOverlay mlo;

	/** Database cursor for handling locations. */
	private Cursor locationcursor;

	/** Used to show contact info dialog. */
	private long dialogid;

	/** Used to show contact info dialog. */
	private ContactDialogCreator cdc;

	/** Resources . */
	private Resources res;

	/** Maximum latitude that should be showed on the map. */
	private int maxLat = Integer.MIN_VALUE;
	/** Maximum longitude that should be showed on the map. */
	private int maxLng = Integer.MIN_VALUE;
	/** Minimum latitude that should be showed on the map. */
	private int minLat = Integer.MAX_VALUE;
	/** Minimum longitude that should be showed on the map. */
	private int minLng = Integer.MAX_VALUE;

	/** Vertical padding for map bounds. */
	private final Float vpadding = 0.1f;
	/** Bottom padding for map bounds. */
	private final Float hpaddingBottom = 0.1f;
	/** Top padding for map bounds. */
	private final Float hpaddingTop = 0.4f;

	/** Used for converting to GeoPoint integer. */
	private static final int ONE_MILLION = 1000000;
	/** Minimum length for contact info (email/phone). */
	private static final int MINIMUM_ACCEPTED_CONTACT_INFO_LENGTH = 4;

	private ContactItemizedOverlay itemizedOverlay;

	/* Called when the activity is first created. */
	@Override
	public final void onCreate(final Bundle savedInstanceState) {
		Log.d(TAG, "CloseToYou onCreate");

		super.onCreate(savedInstanceState);
		setContentView(R.layout.closetoyou);

		res = getResources();

		//Setup database connection
		dbh = new DatabaseAdapter(this);
		dbh.open();

		locationcursor = dbh.getLocations();
		locationcursor.moveToFirst();
		startManagingCursor(locationcursor);

		//Setup the map
		mapView = (MapView) findViewById(R.id.mapView);
		//Create ContactItemizedOverlay for mapView
		itemizedOverlay = new ContactItemizedOverlay(new ColorDrawable(), mapView);
		mapView.setBuiltInZoomControls(true);
		mapView.displayZoomControls(true);
		mapView.setSatellite(true);
		mc = mapView.getController();


		AttentecService.setCloseToYouUpdateListener(new ServiceUpdateUIListener() {
