Browse files

more Maps V2 samples

  • Loading branch information...
1 parent 472d67f commit 4e05ffc842945e0fb8c36d85eb99e78f0022ec94 @commonsguy committed Dec 17, 2012
Showing with 3,305 additions and 0 deletions.
  1. +8 −0 MapsV2/Async/.classpath
  2. +33 −0 MapsV2/Async/.project
  3. +46 −0 MapsV2/Async/AndroidManifest.xml
  4. +26 −0 MapsV2/Async/assets/markers.json
  5. BIN MapsV2/Async/libs/android-support-v4.jar
  6. +20 −0 MapsV2/Async/proguard-project.txt
  7. +16 −0 MapsV2/Async/project.properties
  8. BIN MapsV2/Async/res/drawable-hdpi/ic_launcher.png
  9. BIN MapsV2/Async/res/drawable-ldpi/ic_launcher.png
  10. BIN MapsV2/Async/res/drawable-mdpi/ic_launcher.png
  11. BIN MapsV2/Async/res/drawable-xhdpi/ic_launcher.png
  12. +5 −0 MapsV2/Async/res/layout/activity_main.xml
  13. +12 −0 MapsV2/Async/res/layout/legal.xml
  14. +35 −0 MapsV2/Async/res/layout/popup.xml
  15. +9 −0 MapsV2/Async/res/menu/activity_main.xml
  16. +13 −0 MapsV2/Async/res/values/strings.xml
  17. +100 −0 MapsV2/Async/src/com/commonsware/android/mapsv2/async/AbstractMapActivity.java
  18. +32 −0 MapsV2/Async/src/com/commonsware/android/mapsv2/async/LegalNoticesActivity.java
  19. +109 −0 MapsV2/Async/src/com/commonsware/android/mapsv2/async/MainActivity.java
  20. +87 −0 MapsV2/Async/src/com/commonsware/android/mapsv2/async/MarkerTask.java
  21. +47 −0 MapsV2/Async/src/com/commonsware/android/mapsv2/async/PopupAdapter.java
  22. +8 −0 MapsV2/Drag/.classpath
  23. +33 −0 MapsV2/Drag/.project
  24. +46 −0 MapsV2/Drag/AndroidManifest.xml
  25. BIN MapsV2/Drag/libs/android-support-v4.jar
  26. +20 −0 MapsV2/Drag/proguard-project.txt
  27. +16 −0 MapsV2/Drag/project.properties
  28. BIN MapsV2/Drag/res/drawable-hdpi/ic_launcher.png
  29. BIN MapsV2/Drag/res/drawable-ldpi/ic_launcher.png
  30. BIN MapsV2/Drag/res/drawable-mdpi/ic_launcher.png
  31. BIN MapsV2/Drag/res/drawable-xhdpi/ic_launcher.png
  32. +5 −0 MapsV2/Drag/res/layout/activity_main.xml
  33. +12 −0 MapsV2/Drag/res/layout/legal.xml
  34. +35 −0 MapsV2/Drag/res/layout/popup.xml
  35. +9 −0 MapsV2/Drag/res/menu/activity_main.xml
  36. +21 −0 MapsV2/Drag/res/values/strings.xml
  37. +100 −0 MapsV2/Drag/src/com/commonsware/android/mapsv2/drag/AbstractMapActivity.java
  38. +32 −0 MapsV2/Drag/src/com/commonsware/android/mapsv2/drag/LegalNoticesActivity.java
  39. +158 −0 MapsV2/Drag/src/com/commonsware/android/mapsv2/drag/MainActivity.java
  40. +47 −0 MapsV2/Drag/src/com/commonsware/android/mapsv2/drag/PopupAdapter.java
  41. +8 −0 MapsV2/Fallback/.classpath
  42. +33 −0 MapsV2/Fallback/.project
  43. +54 −0 MapsV2/Fallback/AndroidManifest.xml
  44. BIN MapsV2/Fallback/libs/actionbarsherlock-plugin-maps-4.0.0.jar
  45. BIN MapsV2/Fallback/libs/android-support-v4.jar
  46. +20 −0 MapsV2/Fallback/proguard-project.txt
  47. +16 −0 MapsV2/Fallback/project.properties
  48. BIN MapsV2/Fallback/res/drawable-hdpi/ic_launcher.png
  49. BIN MapsV2/Fallback/res/drawable-ldpi/ic_launcher.png
  50. BIN MapsV2/Fallback/res/drawable-mdpi/ic_launcher.png
  51. BIN MapsV2/Fallback/res/drawable-mdpi/marker.png
  52. BIN MapsV2/Fallback/res/drawable-xhdpi/ic_launcher.png
  53. +5 −0 MapsV2/Fallback/res/layout/activity_main.xml
  54. +12 −0 MapsV2/Fallback/res/layout/legal.xml
  55. +7 −0 MapsV2/Fallback/res/layout/main.xml
  56. +35 −0 MapsV2/Fallback/res/layout/popup.xml
  57. +9 −0 MapsV2/Fallback/res/menu/activity_main.xml
  58. +22 −0 MapsV2/Fallback/res/values/strings.xml
  59. +130 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/AbstractMapActivity.java
  60. +32 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/LegalNoticesActivity.java
  61. +137 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/MainActivity.java
  62. +129 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/MapFragment.java
  63. +31 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/NooYawk.java
  64. +47 −0 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/PopupAdapter.java
  65. +8 −0 MapsV2/Pager/.classpath
  66. +33 −0 MapsV2/Pager/.project
  67. +47 −0 MapsV2/Pager/AndroidManifest.xml
  68. BIN MapsV2/Pager/libs/android-support-v4.jar
  69. +20 −0 MapsV2/Pager/proguard-project.txt
  70. +16 −0 MapsV2/Pager/project.properties
  71. BIN MapsV2/Pager/res/drawable-hdpi/ic_launcher.png
  72. BIN MapsV2/Pager/res/drawable-ldpi/ic_launcher.png
  73. BIN MapsV2/Pager/res/drawable-mdpi/ic_launcher.png
  74. BIN MapsV2/Pager/res/drawable-xhdpi/ic_launcher.png
  75. +12 −0 MapsV2/Pager/res/layout/activity_main.xml
  76. +12 −0 MapsV2/Pager/res/layout/legal.xml
  77. +9 −0 MapsV2/Pager/res/menu/activity_main.xml
  78. +9 −0 MapsV2/Pager/res/values/strings.xml
  79. +100 −0 MapsV2/Pager/src/com/commonsware/android/mapsv2/pager/AbstractMapActivity.java
  80. +32 −0 MapsV2/Pager/src/com/commonsware/android/mapsv2/pager/LegalNoticesActivity.java
  81. +38 −0 MapsV2/Pager/src/com/commonsware/android/mapsv2/pager/MainActivity.java
  82. +45 −0 MapsV2/Pager/src/com/commonsware/android/mapsv2/pager/MapPageAdapter.java
  83. +8 −0 MapsV2/Poly/.classpath
  84. +33 −0 MapsV2/Poly/.project
  85. +46 −0 MapsV2/Poly/AndroidManifest.xml
  86. BIN MapsV2/Poly/libs/android-support-v4.jar
  87. +20 −0 MapsV2/Poly/proguard-project.txt
  88. +16 −0 MapsV2/Poly/project.properties
  89. BIN MapsV2/Poly/res/drawable-hdpi/ic_launcher.png
  90. BIN MapsV2/Poly/res/drawable-ldpi/ic_launcher.png
  91. BIN MapsV2/Poly/res/drawable-mdpi/ic_launcher.png
  92. BIN MapsV2/Poly/res/drawable-xhdpi/ic_launcher.png
  93. +5 −0 MapsV2/Poly/res/layout/activity_main.xml
  94. +12 −0 MapsV2/Poly/res/layout/legal.xml
  95. +35 −0 MapsV2/Poly/res/layout/popup.xml
  96. +9 −0 MapsV2/Poly/res/menu/activity_main.xml
  97. +21 −0 MapsV2/Poly/res/values/strings.xml
  98. +100 −0 MapsV2/Poly/src/com/commonsware/android/mapsv2/poly/AbstractMapActivity.java
  99. +32 −0 MapsV2/Poly/src/com/commonsware/android/mapsv2/poly/LegalNoticesActivity.java
  100. +151 −0 MapsV2/Poly/src/com/commonsware/android/mapsv2/poly/MainActivity.java
  101. +47 −0 MapsV2/Poly/src/com/commonsware/android/mapsv2/poly/PopupAdapter.java
  102. +8 −0 MapsV2/Taps/.classpath
  103. +33 −0 MapsV2/Taps/.project
  104. +46 −0 MapsV2/Taps/AndroidManifest.xml
  105. BIN MapsV2/Taps/libs/android-support-v4.jar
  106. +20 −0 MapsV2/Taps/proguard-project.txt
  107. +16 −0 MapsV2/Taps/project.properties
  108. BIN MapsV2/Taps/res/drawable-hdpi/ic_launcher.png
  109. BIN MapsV2/Taps/res/drawable-ldpi/ic_launcher.png
  110. BIN MapsV2/Taps/res/drawable-mdpi/ic_launcher.png
  111. BIN MapsV2/Taps/res/drawable-xhdpi/ic_launcher.png
  112. +5 −0 MapsV2/Taps/res/layout/activity_main.xml
  113. +12 −0 MapsV2/Taps/res/layout/legal.xml
  114. +35 −0 MapsV2/Taps/res/layout/popup.xml
  115. +9 −0 MapsV2/Taps/res/menu/activity_main.xml
  116. +21 −0 MapsV2/Taps/res/values/strings.xml
  117. +100 −0 MapsV2/Taps/src/com/commonsware/android/mapsv2/taps/AbstractMapActivity.java
  118. +32 −0 MapsV2/Taps/src/com/commonsware/android/mapsv2/taps/LegalNoticesActivity.java
  119. +138 −0 MapsV2/Taps/src/com/commonsware/android/mapsv2/taps/MainActivity.java
  120. +47 −0 MapsV2/Taps/src/com/commonsware/android/mapsv2/taps/PopupAdapter.java
View
8 MapsV2/Async/.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/Async/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MapsV2Async</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/Async/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.async"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="16"/>
+
+ <permission
+ android:name="com.commonsware.android.mapsv2.async.permission.MAPS_RECEIVE"
+ android:protectionLevel="signature"/>
+
+ <uses-permission android:name="com.commonsware.android.mapsv2.async.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="AIzaSyC4iyT46cB00IdKGcy5EmAxK5uCOQX2Oy8"/>
+ </application>
+
+</manifest>
View
26 MapsV2/Async/assets/markers.json
@@ -0,0 +1,26 @@
+[
+ {
+ "lat": 40.748963847316034,
+ "lon": -73.96807193756104,
+ "title": "UN",
+ "snippet": "United Nations"
+ },
+ {
+ "lat": 40.76866299974387,
+ "lon": -73.98268461227417,
+ "title": "Lincoln Center",
+ "snippet": "Home of Jazz at Lincoln Center"
+ },
+ {
+ "lat": 40.765136435316755,
+ "lon": -73.97989511489868,
+ "title": "Carnegie Hall",
+ "snippet": "Where you go with practice, practice, practice"
+ },
+ {
+ "lat": 40.70686417491799,
+ "lon": -74.01572942733765,
+ "title": "The Downtown Club",
+ "snippet": "Original home of the Heisman Trophy"
+ }
+]
View
BIN MapsV2/Async/libs/android-support-v4.jar
Binary file not shown.
View
20 MapsV2/Async/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/Async/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/Async/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/Async/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/Async/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/Async/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/Async/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/Async/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/Async/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/Async/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
13 MapsV2/Async/res/values/strings.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">MapsV2 Async</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="icon">CommonsWare logo</string>
+
+</resources>
View
100 MapsV2/Async/src/com/commonsware/android/mapsv2/async/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.async;
+
+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/Async/src/com/commonsware/android/mapsv2/async/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.async;
+
+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
109 MapsV2/Async/src/com/commonsware/android/mapsv2/async/MainActivity.java
@@ -0,0 +1,109 @@
+/***
+ 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.async;
+
+import android.os.Build;
+import android.os.Bundle;
+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.OnInfoWindowClickListener;
+import com.google.android.gms.maps.SupportMapFragment;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.Marker;
+
+public class MainActivity extends AbstractMapActivity implements
+ OnNavigationListener, OnInfoWindowClickListener {
+ 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();
+ CameraUpdate center=
+ CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
+ -73.98180484771729));
+ CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
+
+ map.moveCamera(center);
+ map.animateCamera(zoom);
+
+ new MarkerTask(this, map).execute("markers.json");
+
+ map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
+ map.setOnInfoWindowClickListener(this);
+ }
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ map.setMapType(MAP_TYPES[itemPosition]);
+
+ return(true);
+ }
+
+ @Override
+ public void onInfoWindowClick(Marker marker) {
+ Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
+ }
+
+ 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);
+ }
+}
View
87 MapsV2/Async/src/com/commonsware/android/mapsv2/async/MarkerTask.java
@@ -0,0 +1,87 @@
+/***
+ 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.async;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.os.AsyncTask;
+import android.util.Log;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.MarkerOptions;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+class MarkerTask extends AsyncTask<String, Void, Void> {
+ private AssetManager assets=null;
+ private Exception e=null;
+ private GoogleMap map;
+ private ArrayList<MarkerOptions> markers=
+ new ArrayList<MarkerOptions>();
+
+ MarkerTask(Context ctxt, GoogleMap map) {
+ assets=ctxt.getAssets();
+ this.map=map;
+ }
+
+ @Override
+ protected Void doInBackground(String... params) {
+ try {
+ InputStream raw=assets.open(params[0]);
+ BufferedReader in=
+ new BufferedReader(new InputStreamReader(raw));
+ String str;
+ StringBuilder buf=new StringBuilder();
+
+ while ((str=in.readLine()) != null) {
+ buf.append(str);
+ }
+
+ in.close();
+
+ JSONArray jsonArray=new JSONArray(buf.toString());
+
+ for (int i=0; i < jsonArray.length(); i++) {
+ JSONObject json=jsonArray.getJSONObject(i);
+ LatLng location=
+ new LatLng(json.getDouble("lat"), json.getDouble("lon"));
+
+ markers.add(new MarkerOptions().position(location)
+ .title(json.getString("title"))
+ .snippet(json.getString("snippet")));
+ }
+ }
+ catch (Exception e) {
+ this.e=e;
+ }
+
+ return(null);
+ }
+
+ @Override
+ public void onPostExecute(Void unused) {
+ for (MarkerOptions marker : markers) {
+ map.addMarker(marker);
+ }
+
+ if (e != null) {
+ Log.e(getClass().getSimpleName(), "Exception parsing JSON", e);
+ }
+ }
+}
View
47 MapsV2/Async/src/com/commonsware/android/mapsv2/async/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.async;
+
+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);
+ }
+}
View
8 MapsV2/Drag/.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/Drag/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MapsV2Drag</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/Drag/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.drag"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="16"/>
+
+ <permission
+ android:name="com.commonsware.android.mapsv2.drag.permission.MAPS_RECEIVE"
+ android:protectionLevel="signature"/>
+
+ <uses-permission android:name="com.commonsware.android.mapsv2.drag.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/Drag/libs/android-support-v4.jar
Binary file not shown.
View
20 MapsV2/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/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/Drag/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">MapsV2 Drag</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/Drag/src/com/commonsware/android/mapsv2/drag/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.drag;
+
+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/Drag/src/com/commonsware/android/mapsv2/drag/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.drag;
+
+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/Drag/src/com/commonsware/android/mapsv2/drag/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.drag;
+
+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.OnInfoWindowClickListener;
+import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
+import com.google.android.gms.maps.SupportMapFragment;
+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,
+ OnMarkerDragListener {
+ 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();
+
+ 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.setOnMarkerDragListener(this);
+ }
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ map.setMapType(MAP_TYPES[itemPosition]);
+
+ return(true);
+ }
+
+ @Override
+ public void onInfoWindowClick(Marker marker) {
+ Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onMarkerDragStart(Marker marker) {
+ LatLng position=marker.getPosition();
+
+ Log.d(getClass().getSimpleName(), String.format("Drag from %f:%f",
+ position.latitude,
+ position.longitude));
+ }
+
+ @Override
+ public void onMarkerDrag(Marker marker) {
+ LatLng position=marker.getPosition();
+
+ Log.d(getClass().getSimpleName(),
+ String.format("Dragging to %f:%f", position.latitude,
+ position.longitude));
+ }
+
+ @Override
+ public void onMarkerDragEnd(Marker marker) {
+ LatLng position=marker.getPosition();
+
+ Log.d(getClass().getSimpleName(), String.format("Dragged to %f:%f",
+ position.latitude,
+ position.longitude));
+ }
+
+ 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))
+ .draggable(true));
+ }
+}
View
47 MapsV2/Drag/src/com/commonsware/android/mapsv2/drag/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.drag;
+
+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);
+ }
+}
View
8 MapsV2/Fallback/.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/Fallback/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MapsV2Fallback</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
54 MapsV2/Fallback/AndroidManifest.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.commonsware.android.mapsv2.fallback"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="11"
+ android:targetSdkVersion="16"/>
+
+ <permission
+ android:name="com.commonsware.android.mapsv2.fallback.permission.MAPS_RECEIVE"
+ android:protectionLevel="signature"/>
+
+ <uses-permission android:name="com.commonsware.android.mapsv2.fallback.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">
+ <uses-library
+ android:name="com.google.android.maps"
+ android:required="false"/>
+
+ <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="com.commonsware.android.mapsv2.fallback.LegalNoticesActivity">
+ </activity>
+ <activity
+ android:name=".NooYawk"
+ android:label="@string/app_name">
+ </activity>
+
+ <meta-data
+ android:name="com.google.android.maps.v2.API_KEY"
+ android:value="AIzaSyCis4NzxMw1aJyvUIrjGILjPkSdxrRfof4"/>
+ </application>
+
+</manifest>
View
BIN MapsV2/Fallback/libs/actionbarsherlock-plugin-maps-4.0.0.jar
Binary file not shown.
View
BIN MapsV2/Fallback/libs/android-support-v4.jar
Binary file not shown.
View
20 MapsV2/Fallback/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/Fallback/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=Google Inc.:Google APIs: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/Fallback/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/Fallback/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/Fallback/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/Fallback/res/drawable-mdpi/marker.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/Fallback/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/Fallback/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/Fallback/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
7 MapsV2/Fallback/res/layout/main.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<fragment xmlns:android="http://schemas.android.com/apk/res/android"
+ android:name="com.commonsware.android.mapsv2.fallback.MapFragment"
+ android:id="@+id/map_fragment"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+/>
View
35 MapsV2/Fallback/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/Fallback/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
22 MapsV2/Fallback/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">MapsV2 Fallback</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>
+ <string name="no_mapping_engines">No mapping engines available!</string>
+
+</resources>
View
130 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/AbstractMapActivity.java
@@ -0,0 +1,130 @@
+/***
+ 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.fallback;
+
+import android.app.ActivityManager;
+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 isV2Possible() {
+ ActivityManager mgr=
+ (ActivityManager)getSystemService(ACTIVITY_SERVICE);
+
+ if (mgr.getDeviceConfigurationInfo().reqGlEsVersion >= 0x20000) {
+ int status=
+ GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
+
+ if (status != ConnectionResult.SERVICE_INVALID) {
+ return(true);
+ }
+ }
+
+ return(false);
+ }
+
+ protected boolean isV1Available() {
+ try {
+ Class.forName("com.google.android.maps.MapActivity");
+
+ return(true);
+ }
+ catch (Exception e) {
+ // that's OK
+ }
+
+ return(false);
+ }
+
+ protected boolean prepareV2() {
+ 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/Fallback/src/com/commonsware/android/mapsv2/fallback/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.fallback;
+
+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
137 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/MainActivity.java
@@ -0,0 +1,137 @@
+/***
+ 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.fallback;
+
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+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.OnInfoWindowClickListener;
+import com.google.android.gms.maps.SupportMapFragment;
+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 {
+ 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 (isV2Possible()) {
+ if (prepareV2()) {
+ setContentView(R.layout.activity_main);
+
+ SupportMapFragment mapFrag=
+ (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
+
+ initListNav();
+
+ map=mapFrag.getMap();
+
+ 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);
+ }
+ }
+ else if (isV1Available()) {
+ startActivity(new Intent(this, NooYawk.class));
+ finish();
+ }
+ else {
+ Toast.makeText(this, R.string.no_mapping_engines, Toast.LENGTH_LONG).show();
+ finish();
+ }
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ map.setMapType(MAP_TYPES[itemPosition]);
+
+ return(true);
+ }
+
+ @Override
+ public void onInfoWindowClick(Marker marker) {
+ Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
+ }
+
+ 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
129 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/MapFragment.java
@@ -0,0 +1,129 @@
+/***
+ Copyright (c) 2008-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.fallback;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.Toast;
+import java.util.ArrayList;
+import java.util.List;
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.ItemizedOverlay;
+import com.google.android.maps.MapView;
+import com.google.android.maps.MyLocationOverlay;
+import com.google.android.maps.OverlayItem;
+
+public class MapFragment extends Fragment {
+ private MapView map=null;
+ private MyLocationOverlay me=null;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater,
+ ViewGroup container,
+ Bundle savedInstanceState) {
+ setHasOptionsMenu(true);
+
+ return(new FrameLayout(getActivity()));
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ map=
+ new MapView(getActivity(),
+ "0mjl6OufrY-tHs6WFurtL7rsYyEMpdEqBCbyjXg");
+ map.setClickable(true);
+
+ map.getController().setCenter(getPoint(40.76793169992044,
+ -73.98180484771729));
+ map.getController().setZoom(17);
+ map.setBuiltInZoomControls(true);
+
+ map.getOverlays().add(new SitesOverlay());
+
+ me=new MyLocationOverlay(getActivity(), map);
+ map.getOverlays().add(me);
+
+ ((ViewGroup)getView()).addView(map);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ me.enableCompass();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ me.disableCompass();
+ }
+
+ private static GeoPoint getPoint(double lat, double lon) {
+ return(new GeoPoint((int)(lat * 1000000.0), (int)(lon * 1000000.0)));
+ }
+
+ private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
+ private List<OverlayItem> items=new ArrayList<OverlayItem>();
+
+ public SitesOverlay() {
+ super(
+ boundCenterBottom(getResources().getDrawable(R.drawable.marker)));
+
+ items.add(new OverlayItem(getPoint(40.748963847316034,
+ -73.96807193756104), "UN",
+ "United Nations"));
+ items.add(new OverlayItem(getPoint(40.76866299974387,
+ -73.98268461227417),
+ "Lincoln Center",
+ "Home of Jazz at Lincoln Center"));
+ items.add(new OverlayItem(getPoint(40.765136435316755,
+ -73.97989511489868),
+ "Carnegie Hall",
+ "Where you go with practice, practice, practice"));
+ items.add(new OverlayItem(getPoint(40.70686417491799,
+ -74.01572942733765),
+ "The Downtown Club",
+ "Original home of the Heisman Trophy"));
+
+ populate();
+ }
+
+ @Override
+ protected OverlayItem createItem(int i) {
+ return(items.get(i));
+ }
+
+ @Override
+ protected boolean onTap(int i) {
+ Toast.makeText(getActivity(), items.get(i).getSnippet(),
+ Toast.LENGTH_LONG).show();
+
+ return(true);
+ }
+
+ @Override
+ public int size() {
+ return(items.size());
+ }
+ }
+}
View
31 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/NooYawk.java
@@ -0,0 +1,31 @@
+/***
+ Copyright (c) 2008-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.fallback;
+
+import android.os.Bundle;
+import com.actionbarsherlock.app.SherlockMapActivity;
+
+public class NooYawk extends SherlockMapActivity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+
+ @Override
+ protected boolean isRouteDisplayed() {
+ return(false);
+ }
+}
View
47 MapsV2/Fallback/src/com/commonsware/android/mapsv2/fallback/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.
+