Bläddra i källkod

Initial commit for Location and Maps projects.

Cristian Tanas 11 år sedan
förälder
incheckning
fad7146ebe
39 ändrade filer med 901 tillägg och 0 borttagningar
  1. 30 0
      LocationLocationManager/AndroidManifest.xml
  2. BIN
      LocationLocationManager/ic_launcher-web.png
  3. BIN
      LocationLocationManager/libs/android-support-v4.jar
  4. BIN
      LocationLocationManager/res/drawable-hdpi/ic_launcher.png
  5. BIN
      LocationLocationManager/res/drawable-mdpi/ic_launcher.png
  6. BIN
      LocationLocationManager/res/drawable-xhdpi/ic_launcher.png
  7. BIN
      LocationLocationManager/res/drawable-xxhdpi/ic_launcher.png
  8. 49 0
      LocationLocationManager/res/layout/activity_main.xml
  9. 11 0
      LocationLocationManager/res/values-v11/styles.xml
  10. 12 0
      LocationLocationManager/res/values-v14/styles.xml
  11. 8 0
      LocationLocationManager/res/values/strings.xml
  12. 20 0
      LocationLocationManager/res/values/styles.xml
  13. 216 0
      LocationLocationManager/src/org/uab/android/location/locationmanager/MainActivity.java
  14. 34 0
      LocationLocationServices/AndroidManifest.xml
  15. BIN
      LocationLocationServices/ic_launcher-web.png
  16. BIN
      LocationLocationServices/libs/android-support-v4.jar
  17. BIN
      LocationLocationServices/res/drawable-hdpi/ic_launcher.png
  18. BIN
      LocationLocationServices/res/drawable-mdpi/ic_launcher.png
  19. BIN
      LocationLocationServices/res/drawable-xhdpi/ic_launcher.png
  20. BIN
      LocationLocationServices/res/drawable-xxhdpi/ic_launcher.png
  21. 49 0
      LocationLocationServices/res/layout/activity_main.xml
  22. 11 0
      LocationLocationServices/res/values-v11/styles.xml
  23. 12 0
      LocationLocationServices/res/values-v14/styles.xml
  24. 8 0
      LocationLocationServices/res/values/strings.xml
  25. 20 0
      LocationLocationServices/res/values/styles.xml
  26. 226 0
      LocationLocationServices/src/org/uab/android/location/locationservices/MainActivity.java
  27. 59 0
      MapsSimple/AndroidManifest.xml
  28. BIN
      MapsSimple/ic_launcher-web.png
  29. BIN
      MapsSimple/libs/android-support-v4.jar
  30. BIN
      MapsSimple/res/drawable-hdpi/ic_launcher.png
  31. BIN
      MapsSimple/res/drawable-mdpi/ic_launcher.png
  32. BIN
      MapsSimple/res/drawable-xhdpi/ic_launcher.png
  33. BIN
      MapsSimple/res/drawable-xxhdpi/ic_launcher.png
  34. 13 0
      MapsSimple/res/layout/activity_main.xml
  35. 11 0
      MapsSimple/res/values-v11/styles.xml
  36. 12 0
      MapsSimple/res/values-v14/styles.xml
  37. 7 0
      MapsSimple/res/values/strings.xml
  38. 20 0
      MapsSimple/res/values/styles.xml
  39. 73 0
      MapsSimple/src/org/uab/android/maps/simple/MainActivity.java

+ 30 - 0
LocationLocationManager/AndroidManifest.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.location.locationmanager"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+    
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>

BIN
LocationLocationManager/ic_launcher-web.png


BIN
LocationLocationManager/libs/android-support-v4.jar


BIN
LocationLocationManager/res/drawable-hdpi/ic_launcher.png


BIN
LocationLocationManager/res/drawable-mdpi/ic_launcher.png


BIN
LocationLocationManager/res/drawable-xhdpi/ic_launcher.png


BIN
LocationLocationManager/res/drawable-xxhdpi/ic_launcher.png


+ 49 - 0
LocationLocationManager/res/layout/activity_main.xml

@@ -0,0 +1,49 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <Button
+        android:id="@+id/getLocation"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:text="@string/getLocationLabel" />
+
+    <TextView
+        android:id="@+id/locationAccuracy"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginLeft="29dp"
+        android:layout_marginTop="130dp" />
+
+    <TextView
+        android:id="@+id/locationLatitude"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationTime"
+        android:layout_below="@+id/locationTime"
+        android:layout_marginTop="18dp" />
+
+    <TextView
+        android:id="@+id/locationTime"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationAccuracy"
+        android:layout_below="@+id/locationAccuracy"
+        android:layout_marginTop="18dp" />
+
+    <TextView
+        android:id="@+id/locationLongitude"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationLatitude"
+        android:layout_below="@+id/locationLatitude"
+        android:layout_marginTop="18dp" />
+
+</RelativeLayout>

+ 11 - 0
LocationLocationManager/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
LocationLocationManager/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 8 - 0
LocationLocationManager/res/values/strings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">LocationLocationManager</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="getLocationLabel">Get location</string>
+
+</resources>

+ 20 - 0
LocationLocationManager/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 216 - 0
LocationLocationManager/src/org/uab/android/location/locationmanager/MainActivity.java

@@ -0,0 +1,216 @@
+package org.uab.android.location.locationmanager;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Color;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+	
+	static final long POLLING_FREQ = 10 * 1000;
+	static final float MIN_DISTANCE = 10.0f;
+	
+	// LocationManager object to request the device's location
+	LocationManager locationManager;
+	
+	// Location object to store the current "best" location
+	Location		currentBestLocation;
+	
+	TextView	locationAccuracyTv;
+	TextView	locationTimeTv;
+	TextView	locationLatitudeTv;
+	TextView	locationLongitudeTv;
+	
+	Button		getLocationButton;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		// Get a reference to the LocationManager
+		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+		if ( locationManager == null ) finish();
+		
+		locationAccuracyTv = (TextView) findViewById(R.id.locationAccuracy);
+		locationTimeTv = (TextView) findViewById(R.id.locationTime);
+		locationLatitudeTv = (TextView) findViewById(R.id.locationLatitude);
+		locationLongitudeTv = (TextView) findViewById(R.id.locationLongitude);
+		
+		getLocationButton = (Button) findViewById(R.id.getLocation);
+		getLocationButton.setOnClickListener(new View.OnClickListener() {
+			
+			// When the user clicks on the "Get location" button, first obtain the last known location.
+			// Update the display based on the obtained value.
+			// Finally, request location updates to get new location values.
+			@Override
+			public void onClick(View v) {
+				
+				currentBestLocation = getBestLastKnownLocation();
+				if ( currentBestLocation != null ) {
+					
+					updateDisplay(currentBestLocation);
+				}
+				else {
+					
+					locationAccuracyTv.setText("No initial reading available.");
+				}
+				
+				requestLocationUpdates();
+			}
+		});
+		
+	}
+	
+	@Override
+	protected void onPause() {
+		super.onPause();
+		
+		// Unregister the locationListener from location updates
+		locationManager.removeUpdates(locationListener);
+	}
+	
+	/**
+	 * Updates the TextViews with the information on the new location.
+	 * 
+	 * @param location Location object with the new location value.
+	 */
+	private void updateDisplay(Location location) {
+		
+		locationAccuracyTv.setText("Accuracy: " + location.getAccuracy());
+		locationTimeTv.setText("Time: " + 
+				new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault())
+						.format(new Date(location.getTime()))
+						);
+		locationLatitudeTv.setText("Latitude: " + location.getLatitude());
+		locationLongitudeTv.setText("Longitude: " + location.getLongitude());
+	}
+	
+	/**
+	 * Changes the text color of all the TextViews.
+	 * 
+	 * @param color The color of the text.
+	 */
+	private void setTextViewColor(int color) {
+		
+		locationAccuracyTv.setTextColor(color);
+		locationTimeTv.setTextColor(color);
+		locationLatitudeTv.setTextColor(color);
+		locationLongitudeTv.setTextColor(color);
+	}
+	
+	/**
+	 * Obtains the last best known location from all the available location providers.
+	 * 
+	 * @return The last best known location.
+	 */
+	private Location getBestLastKnownLocation() {
+		
+		Location bestLocation = null;
+		float bestAccuracy = Float.MAX_VALUE;
+		
+		// Get a list of all the location providers available.
+		List<String> knownProviders = locationManager.getAllProviders();
+		
+		for ( String provider : knownProviders ) {
+			
+			// Get the last known location from each location provider.
+			Location location = locationManager.getLastKnownLocation(provider);
+			
+			if ( location != null ) {
+				
+				float accuracy = location.getAccuracy();
+				
+				// Compare location values from different providers based only on the accuracy of the reading.
+				if ( accuracy < bestAccuracy ) {
+					
+					bestLocation = location;
+					bestAccuracy = accuracy;
+				}
+			}
+		}
+		
+		return bestLocation;
+	}
+	
+	/**
+	 * Registers the locationListener object to receive location updates from 
+	 * the NETWORK_PROVIDER and the GPS_PROVIDER.
+	 */
+	private void requestLocationUpdates() {
+		
+		// Register for network location updates
+		if ( locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null ) {
+
+			locationManager.requestLocationUpdates(
+					LocationManager.NETWORK_PROVIDER, 	// Location provider
+					POLLING_FREQ, 						// Update frequency
+					MIN_DISTANCE, 						// Update the location only if the device has moved at least MIN_DISTANCE
+					locationListener					// LocationListener object to receive location update callbacks
+					);
+		}
+
+		// Register for GPS location updates
+		if ( locationManager.getProvider(LocationManager.GPS_PROVIDER) != null ) {
+
+			locationManager.requestLocationUpdates(
+					LocationManager.GPS_PROVIDER, 		// Location provider
+					POLLING_FREQ, 						// Update frequency
+					MIN_DISTANCE, 						// Update the location only if the device has moved at least MIN_DISTANCE
+					locationListener					// LocationListener object to receive location update callbacks
+					);
+		}
+	}
+	
+	LocationListener locationListener = new LocationListener() {
+		
+		@Override
+		public void onStatusChanged(String provider, int status, Bundle extras) {
+			// TODO Auto-generated method stub
+			
+		}
+		
+		@Override
+		public void onProviderEnabled(String provider) {
+			// TODO Auto-generated method stub
+			
+		}
+		
+		@Override
+		public void onProviderDisabled(String provider) {
+			// TODO Auto-generated method stub
+			
+		}
+		
+		// The location provider has registered a change in the device's location
+		@Override
+		public void onLocationChanged(Location location) {
+			
+			// Keep the new location value if there is no previous value or 
+			// if the accuracy of the new value is better than the accuracy of the current value
+			if ( currentBestLocation == null
+					|| currentBestLocation.getAccuracy() > location.getAccuracy() ) {
+				
+				currentBestLocation = location;
+				
+				// Update the display with the new location info
+				updateDisplay(location);
+				
+				// Change the TextViews text color to green
+				setTextViewColor(Color.GREEN);
+			}
+			
+		}
+	};
+}

+ 34 - 0
LocationLocationServices/AndroidManifest.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.location.locationservices"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+    
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="org.uab.android.location.locationservices.MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <meta-data 
+            android:name="com.google.android.gms.version"
+            android:value="@integer/google_play_services_version"/>
+    </application>
+
+</manifest>

BIN
LocationLocationServices/ic_launcher-web.png


BIN
LocationLocationServices/libs/android-support-v4.jar


BIN
LocationLocationServices/res/drawable-hdpi/ic_launcher.png


BIN
LocationLocationServices/res/drawable-mdpi/ic_launcher.png


BIN
LocationLocationServices/res/drawable-xhdpi/ic_launcher.png


BIN
LocationLocationServices/res/drawable-xxhdpi/ic_launcher.png


+ 49 - 0
LocationLocationServices/res/layout/activity_main.xml

@@ -0,0 +1,49 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <Button
+        android:id="@+id/getLocation"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:text="@string/getLocationLabel" />
+
+    <TextView
+        android:id="@+id/locationAccuracy"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginLeft="29dp"
+        android:layout_marginTop="130dp" />
+
+    <TextView
+        android:id="@+id/locationLatitude"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationTime"
+        android:layout_below="@+id/locationTime"
+        android:layout_marginTop="18dp" />
+
+    <TextView
+        android:id="@+id/locationTime"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationAccuracy"
+        android:layout_below="@+id/locationAccuracy"
+        android:layout_marginTop="18dp" />
+
+    <TextView
+        android:id="@+id/locationLongitude"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@+id/locationLatitude"
+        android:layout_below="@+id/locationLatitude"
+        android:layout_marginTop="18dp" />
+
+</RelativeLayout>

+ 11 - 0
LocationLocationServices/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
LocationLocationServices/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 8 - 0
LocationLocationServices/res/values/strings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">LocationLocationServices</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="getLocationLabel">Get location</string>
+
+</resources>

+ 20 - 0
LocationLocationServices/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 226 - 0
LocationLocationServices/src/org/uab/android/location/locationservices/MainActivity.java

@@ -0,0 +1,226 @@
+package org.uab.android.location.locationservices;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.location.Location;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GooglePlayServicesClient;
+import com.google.android.gms.common.GooglePlayServicesUtil;
+import com.google.android.gms.location.LocationClient;
+import com.google.android.gms.location.LocationRequest;
+
+public class MainActivity extends Activity implements 
+				GooglePlayServicesClient.ConnectionCallbacks,
+				GooglePlayServicesClient.OnConnectionFailedListener, 
+				com.google.android.gms.location.LocationListener {
+	
+	static final long POLLING_FREQ = 10 * 1000;
+	static final long FASTEST_UPDATE_FREQ = 2 * 1000;
+	static final float MIN_DISTANCE = 10.0f;
+	
+	// LocationClient object to request the device's location
+	LocationClient	locationClient;
+	
+	// LocationRequest object that holds accuracy and frequency parameters
+	LocationRequest	locationRequest;
+	
+	// Current best location estimate
+	Location		currentBestLocation;
+	
+	TextView	locationAccuracyTv;
+	TextView	locationTimeTv;
+	TextView	locationLatitudeTv;
+	TextView	locationLongitudeTv;
+	
+	Button		getLocationButton;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		// Create a new LocationClient object. This class will handle callbacks.
+		locationClient = new LocationClient(this, this, this);
+		
+		// Create and define the LocationRequest
+		locationRequest = LocationRequest.create();
+		
+		// Use high accuracy
+		locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
+		
+		// Update every 10 seconds
+		locationRequest.setInterval(POLLING_FREQ);
+		
+		// Receive updates no more often that every 2 seconds
+		locationRequest.setFastestInterval(FASTEST_UPDATE_FREQ);
+		
+		locationAccuracyTv = (TextView) findViewById(R.id.locationAccuracy);
+		locationTimeTv = (TextView) findViewById(R.id.locationTime);
+		locationLatitudeTv = (TextView) findViewById(R.id.locationLatitude);
+		locationLongitudeTv = (TextView) findViewById(R.id.locationLongitude);
+		
+		getLocationButton = (Button) findViewById(R.id.getLocation);
+		getLocationButton.setOnClickListener(new View.OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// Connect to LocationServices
+				locationClient.connect();
+			}
+		});
+		
+	}
+	
+	@Override
+	protected void onPause() {
+		super.onPause();
+		
+		if ( locationClient != null ) {
+			// Stop updates
+			locationClient.removeLocationUpdates(this);
+			
+			// Disconnect from LocationServices
+			locationClient.disconnect();
+		}
+	}
+	
+	/**
+	 * Updates the TextViews with the information on the new location.
+	 * 
+	 * @param location Location object with the new location value.
+	 */
+	private void updateDisplay(Location location) {
+		
+		locationAccuracyTv.setText("Accuracy: " + location.getAccuracy());
+		locationTimeTv.setText("Time: " + 
+				new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault())
+						.format(new Date(location.getTime()))
+						);
+		locationLatitudeTv.setText("Latitude: " + location.getLatitude());
+		locationLongitudeTv.setText("Longitude: " + location.getLongitude());
+	}
+	
+	/**
+	 * Changes the text color of all the TextViews.
+	 * 
+	 * @param color The color of the text.
+	 */
+	private void setTextViewColor(int color) {
+		
+		locationAccuracyTv.setTextColor(color);
+		locationTimeTv.setTextColor(color);
+		locationLatitudeTv.setTextColor(color);
+		locationLongitudeTv.setTextColor(color);
+	}
+	
+	/**
+	 * Obtains the last best known location from all the available location providers.
+	 * 
+	 * @return The last best known location.
+	 */
+	private Location getBestLastKnownLocation() {
+		
+		Location bestLocation = null;
+		float bestAccuracy = Float.MAX_VALUE;
+		
+		// Get the best most recent location currently available
+		currentBestLocation = locationClient.getLastLocation();
+		
+		if ( currentBestLocation != null ) {
+			
+			float accuracy = currentBestLocation.getAccuracy();
+			
+			if ( accuracy < bestAccuracy ) {
+				
+				bestLocation = currentBestLocation;
+				bestAccuracy = accuracy;
+			}
+		}
+		
+		return bestLocation;
+	}
+	
+	/**
+	 * Request location updates from the LocationServices
+	 */
+	private void requestLocationUpdates() {
+		
+		// Get additional location updates
+		locationClient.requestLocationUpdates(locationRequest, this);
+	}
+
+	@Override
+	public void onConnected(Bundle connectionHint) {
+		
+		if ( isGooglePlayServicesAvailable() ) {
+			
+			// Get best last known location measurement
+			currentBestLocation = getBestLastKnownLocation();
+			
+			// Update the display with the obtained location measurement
+			if ( currentBestLocation != null ) {
+				
+				updateDisplay(currentBestLocation);
+			}
+			else {
+				
+				locationAccuracyTv.setText("No initial reading available.");
+			}
+			
+			// Request additional location updates
+			requestLocationUpdates();
+		}
+	}
+
+	@Override
+	public void onDisconnected() {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	@Override
+	public void onConnectionFailed(ConnectionResult result) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	@Override
+	public void onLocationChanged(Location location) {
+		
+		// Keep the new location value if there is no previous value or 
+		// if the accuracy of the new value is better than the accuracy of the current value
+		if ( currentBestLocation == null
+				|| currentBestLocation.getAccuracy() > location.getAccuracy() ) {
+			
+			currentBestLocation = location;
+			
+			// Update the display with the new location info
+			updateDisplay(location);
+			
+			// Change the TextViews text color to green
+			setTextViewColor(Color.GREEN);
+		}
+	}
+	
+	/**
+	 * Check whether GooglePlay Services are available on the device.
+	 * 
+	 * @return GooglePlay Services status on the device.
+	 */
+	private boolean isGooglePlayServicesAvailable() {
+		
+		int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
+		return (ConnectionResult.SUCCESS == resultCode);
+	}
+	
+}

+ 59 - 0
MapsSimple/AndroidManifest.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.maps.simple"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+    
+    <!-- Permission to connect to the Internet to obtain the map's tiles -->
+    <uses-permission android:name="android.permission.INTERNET" />
+    
+    <!-- Permission to check the current Internet connection of the device -->
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    
+    <!-- Permission to write maps data to external storage -->
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    
+    <!-- Permission to access the Maps services -->
+    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
+    
+    <permission
+        android:name="org.uab.deic.android.solutions.unit6.permission.MAPS_RECEIVE"
+        android:protectionLevel="signature" />
+    <uses-permission android:name="org.uab.deic.android.solutions.unit6.permission.MAPS_RECEIVE" />
+    
+    <!-- Enforce that the device has OpenGL v2 installed to use this application -->
+    <uses-feature
+        android:glEsVersion="0x00020000"
+        android:required="true" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <!-- Metadata tag to inform on the GooglePlay Services version installed -->
+        <meta-data 
+            android:name="com.google.android.gms.version"
+            android:value="@integer/google_play_services_version" />
+        
+        <!-- GoogleMaps API Key obtained through the Google Developer Console -->
+        <meta-data
+            android:name="com.google.android.maps.v2.API_KEY"
+            android:value="AIzaSyBv17vANOoCzA3jNa8yAaVXtPap6tlEmhg" />
+    </application>
+
+</manifest>

BIN
MapsSimple/ic_launcher-web.png


BIN
MapsSimple/libs/android-support-v4.jar


BIN
MapsSimple/res/drawable-hdpi/ic_launcher.png


BIN
MapsSimple/res/drawable-mdpi/ic_launcher.png


BIN
MapsSimple/res/drawable-xhdpi/ic_launcher.png


BIN
MapsSimple/res/drawable-xxhdpi/ic_launcher.png


+ 13 - 0
MapsSimple/res/layout/activity_main.xml

@@ -0,0 +1,13 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <fragment
+        android:id="@+id/map"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:name="com.google.android.gms.maps.MapFragment"/>
+
+</RelativeLayout>

+ 11 - 0
MapsSimple/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
MapsSimple/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 7 - 0
MapsSimple/res/values/strings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">MapsSimple</string>
+    <string name="hello_world">Hello world!</string>
+
+</resources>

+ 20 - 0
MapsSimple/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 73 - 0
MapsSimple/src/org/uab/android/maps/simple/MainActivity.java

@@ -0,0 +1,73 @@
+package org.uab.android.maps.simple;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.google.android.gms.maps.CameraUpdateFactory;
+import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.MapFragment;
+import com.google.android.gms.maps.model.CameraPosition;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.MarkerOptions;
+
+public class MainActivity extends Activity {
+	
+	// The Map object
+	private GoogleMap		mGMap;
+	
+	// CameraPosition targeting Syndey, Australia
+	static final CameraPosition SYDNEY = 
+			new CameraPosition.Builder()
+				.target(new LatLng(-33.891614, 151.276417))
+				.zoom(15.5f)
+				.bearing(300)
+				.tilt(45)
+				.build();
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		setUpMapIfNeeded();
+	}
+	
+	/**
+	 * Obtains a reference to the Map object from the underlying fragment if needed.
+	 */
+	private void setUpMapIfNeeded() {
+		
+		// Check if we didn't already instantiated the map
+		if ( mGMap == null ) {
+			
+			mGMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
+			
+			// Check if we were able to successfully return a map object
+			if ( mGMap != null ) {
+				
+				// Perform setup operation on the map object
+				setUpMap();
+			}
+			
+		}
+	}
+	
+	/**
+	 * Sets up initial configuration on the Map object
+	 */
+	private void setUpMap() {
+		
+		// Use terrain maps
+		mGMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
+		
+		// Animate the current map view to Sydney, Australia.
+		mGMap.animateCamera(CameraUpdateFactory.newCameraPosition(SYDNEY));
+		
+		// Add a marker on the map at the specified location
+		mGMap.addMarker(new MarkerOptions()
+				.position(new LatLng(-33.891614, 151.276417))
+				.title("Sydney")
+				.snippet("Population: 4,692,813 (January 1st 2012)")
+				);
+	}
+}