Permalink
Browse files

another Maps V2 sample project

  • Loading branch information...
1 parent c5e2fb9 commit 892b790a1518af85a7debe2470c3cba6542bf51e @commonsguy committed Dec 26, 2012
View
8 MapsV2/Camera/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 MapsV2/Camera/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MapsV2Camera</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
46 MapsV2/Camera/AndroidManifest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.commonsware.android.mapsv2.camera"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="16"/>
+
+ <permission
+ android:name="com.commonsware.android.mapsv2.camera.permission.MAPS_RECEIVE"
+ android:protectionLevel="signature"/>
+
+ <uses-permission android:name="com.commonsware.android.mapsv2.camera.permission.MAPS_RECEIVE"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
+
+ <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/Theme.Sherlock.Light.DarkActionBar">
+ <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>
+ <activity android:name="LegalNoticesActivity">
+ </activity>
+
+ <meta-data
+ android:name="com.google.android.maps.v2.API_KEY"
+ android:value="AIzaSyApXrquq0wzEvuLV3sXATJ27gmOKAx5cxI"/>
+ </application>
+
+</manifest>
View
BIN MapsV2/Camera/libs/android-support-v4.jar
Binary file not shown.
View
20 MapsV2/Camera/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
View
16 MapsV2/Camera/project.properties
@@ -0,0 +1,16 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-17
+android.library.reference.1=../../external/ActionBarSherlock
+android.library.reference.2=../../../../../../../../../opt/android-sdk-linux_x86/extras/google/google_play_services/libproject/google-play-services_lib
View
BIN MapsV2/Camera/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN MapsV2/Camera/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN MapsV2/Camera/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN MapsV2/Camera/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
5 MapsV2/Camera/res/layout/activity_main.xml
@@ -0,0 +1,5 @@
+<fragment xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/map"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ class="com.google.android.gms.maps.SupportMapFragment"/>
View
12 MapsV2/Camera/res/layout/legal.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TextView
+ android:id="@+id/legal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+</ScrollView>
View
35 MapsV2/Camera/res/layout/popup.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:padding="2dip"
+ android:src="@drawable/ic_launcher"
+ android:contentDescription="@string/icon"/>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="25sp"
+ android:textStyle="bold"/>
+
+ <TextView
+ android:id="@+id/snippet"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="15sp"/>
+ </LinearLayout>
+
+</LinearLayout>
View
9 MapsV2/Camera/res/menu/activity_main.xml
@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/legal"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="@string/legal"/>
+
+</menu>
View
21 MapsV2/Camera/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">MapsV2 Camera</string>
+ <string name="legal">Legal Notices</string>
+ <string name="no_maps">Google Maps V2 not available!</string>
+ <string name="normal">Normal</string>
+ <string name="hybrid">Hybrid</string>
+ <string name="satellite">Satellite</string>
+ <string name="terrain">Terrain</string>
+ <string name="un">UN</string>
+ <string name="united_nations">United Nations</string>
+ <string name="lincoln_center">Lincoln Center</string>
+ <string name="lincoln_center_snippet">Home of Jazz at Lincoln Center</string>
+ <string name="carnegie_hall">Carnegie Hall</string>
+ <string name="practice_x3">Where you go with practice, practice, practice</string>
+ <string name="downtown_club">The Downtown Club</string>
+ <string name="heisman_trophy">Original home of the Heisman Trophy</string>
+ <string name="icon">CommonsWare logo</string>
+
+</resources>
View
100 MapsV2/Camera/src/com/commonsware/android/mapsv2/camera/AbstractMapActivity.java
@@ -0,0 +1,100 @@
+/***
+ Copyright (c) 2012 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.mapsv2.camera;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.widget.Toast;
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GooglePlayServicesUtil;
+
+public class AbstractMapActivity extends SherlockFragmentActivity {
+ protected static final String TAG_ERROR_DIALOG_FRAGMENT="errorDialog";
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getSupportMenuInflater().inflate(R.menu.activity_main, menu);
+
+ return(super.onCreateOptionsMenu(menu));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.legal) {
+ startActivity(new Intent(this, LegalNoticesActivity.class));
+
+ return(true);
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ protected boolean readyToGo() {
+ int status=
+ GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
+
+ if (status == ConnectionResult.SUCCESS) {
+ return(true);
+ }
+ else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
+ ErrorDialogFragment.newInstance(status)
+ .show(getSupportFragmentManager(),
+ TAG_ERROR_DIALOG_FRAGMENT);
+ }
+ else {
+ Toast.makeText(this, R.string.no_maps, Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ return(false);
+ }
+
+ public static class ErrorDialogFragment extends DialogFragment {
+ static final String ARG_STATUS="status";
+
+ static ErrorDialogFragment newInstance(int status) {
+ Bundle args=new Bundle();
+
+ args.putInt(ARG_STATUS, status);
+
+ ErrorDialogFragment result=new ErrorDialogFragment();
+
+ result.setArguments(args);
+
+ return(result);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ Bundle args=getArguments();
+
+ return GooglePlayServicesUtil.getErrorDialog(args.getInt(ARG_STATUS),
+ getActivity(), 0);
+ }
+
+ @Override
+ public void onDismiss(DialogInterface dlg) {
+ if (getActivity() != null) {
+ getActivity().finish();
+ }
+ }
+ }
+}
View
32 MapsV2/Camera/src/com/commonsware/android/mapsv2/camera/LegalNoticesActivity.java
@@ -0,0 +1,32 @@
+/***
+ Copyright (c) 2012 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.mapsv2.camera;
+
+import android.os.Bundle;
+import android.widget.TextView;
+import com.actionbarsherlock.app.SherlockActivity;
+import com.google.android.gms.common.GooglePlayServicesUtil;
+
+public class LegalNoticesActivity extends SherlockActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.legal);
+
+ TextView legal=(TextView)findViewById(R.id.legal);
+
+ legal.setText(GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this));
+ }
+}
View
158 MapsV2/Camera/src/com/commonsware/android/mapsv2/camera/MainActivity.java
@@ -0,0 +1,158 @@
+/***
+ Copyright (c) 2012 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.mapsv2.camera;
+
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.ArrayAdapter;
+import android.widget.Toast;
+import java.util.ArrayList;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
+import com.google.android.gms.maps.CameraUpdate;
+import com.google.android.gms.maps.CameraUpdateFactory;
+import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
+import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
+import com.google.android.gms.maps.SupportMapFragment;
+import com.google.android.gms.maps.model.CameraPosition;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.Marker;
+import com.google.android.gms.maps.model.MarkerOptions;
+
+public class MainActivity extends AbstractMapActivity implements
+ OnNavigationListener, OnInfoWindowClickListener,
+ OnCameraChangeListener {
+ private static final String STATE_NAV="nav";
+ private static final int[] MAP_TYPE_NAMES= { R.string.normal,
+ R.string.hybrid, R.string.satellite, R.string.terrain };
+ private static final int[] MAP_TYPES= { GoogleMap.MAP_TYPE_NORMAL,
+ GoogleMap.MAP_TYPE_HYBRID, GoogleMap.MAP_TYPE_SATELLITE,
+ GoogleMap.MAP_TYPE_TERRAIN };
+ private GoogleMap map=null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (readyToGo()) {
+ setContentView(R.layout.activity_main);
+
+ SupportMapFragment mapFrag=
+ (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
+
+ initListNav();
+
+ map=mapFrag.getMap();
+
+ if (savedInstanceState == null) {
+ CameraUpdate center=
+ CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
+ -73.98180484771729));
+ CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
+
+ map.moveCamera(center);
+ map.animateCamera(zoom);
+ }
+
+ addMarker(map, 40.748963847316034, -73.96807193756104,
+ R.string.un, R.string.united_nations);
+ addMarker(map, 40.76866299974387, -73.98268461227417,
+ R.string.lincoln_center,
+ R.string.lincoln_center_snippet);
+ addMarker(map, 40.765136435316755, -73.97989511489868,
+ R.string.carnegie_hall, R.string.practice_x3);
+ addMarker(map, 40.70686417491799, -74.01572942733765,
+ R.string.downtown_club, R.string.heisman_trophy);
+
+ map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
+ map.setOnInfoWindowClickListener(this);
+ map.setOnCameraChangeListener(this);
+ }
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ map.setMapType(MAP_TYPES[itemPosition]);
+
+ return(true);
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+
+ savedInstanceState.putInt(STATE_NAV,
+ getSupportActionBar().getSelectedNavigationIndex());
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ getSupportActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_NAV));
+ }
+
+ @Override
+ public void onInfoWindowClick(Marker marker) {
+ Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onCameraChange(CameraPosition position) {
+ Log.d(getClass().getSimpleName(),
+ String.format("lat: %f, lon: %f, zoom: %f, tilt: %f",
+ position.target.latitude,
+ position.target.longitude, position.zoom,
+ position.tilt));
+ }
+
+ private void initListNav() {
+ ArrayList<String> items=new ArrayList<String>();
+ ArrayAdapter<String> nav=null;
+ ActionBar bar=getSupportActionBar();
+
+ for (int type : MAP_TYPE_NAMES) {
+ items.add(getString(type));
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ nav=
+ new ArrayAdapter<String>(
+ bar.getThemedContext(),
+ android.R.layout.simple_spinner_item,
+ items);
+ }
+ else {
+ nav=
+ new ArrayAdapter<String>(
+ this,
+ android.R.layout.simple_spinner_item,
+ items);
+ }
+
+ nav.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ bar.setListNavigationCallbacks(nav, this);
+ }
+
+ private void addMarker(GoogleMap map, double lat, double lon,
+ int title, int snippet) {
+ map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
+ .title(getString(title))
+ .snippet(getString(snippet)));
+ }
+}
View
47 MapsV2/Camera/src/com/commonsware/android/mapsv2/camera/PopupAdapter.java
@@ -0,0 +1,47 @@
+/***
+ Copyright (c) 2012 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.mapsv2.camera;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
+import com.google.android.gms.maps.model.Marker;
+
+class PopupAdapter implements InfoWindowAdapter {
+ LayoutInflater inflater=null;
+
+ PopupAdapter(LayoutInflater inflater) {
+ this.inflater=inflater;
+ }
+
+ @Override
+ public View getInfoWindow(Marker marker) {
+ return(null);
+ }
+
+ @Override
+ public View getInfoContents(Marker marker) {
+ View popup=inflater.inflate(R.layout.popup, null);
+
+ TextView tv=(TextView)popup.findViewById(R.id.title);
+
+ tv.setText(marker.getTitle());
+ tv=(TextView)popup.findViewById(R.id.snippet);
+ tv.setText(marker.getSnippet());
+
+ return(popup);
+ }
+}

0 comments on commit 892b790

Please sign in to comment.