Skip to content

Commit

Permalink
New MapPinDrawable dedicated to MapViews
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Mottier committed Jun 2, 2011
1 parent b64b0b5 commit 1fbbe49
Show file tree
Hide file tree
Showing 15 changed files with 456 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Exclude file used by compilators, interpreters, etc.
*/bin/*
*/gen/*
*.pyc

## Exclude Mac OS X files
*.DS_Store
*.pyc

## The following files contain private values
*/res/values/p_*.xml
1 change: 1 addition & 0 deletions GDCatalog/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="GreenDroid-GoogleAPIs_src"/>
<classpathentry kind="src" path="GreenDroid_src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 5 additions & 0 deletions GDCatalog/.project
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>GreenDroid-GoogleAPIs_src</name>
<type>2</type>
<locationURI>_android_GreenDroid_GoogleAPIs_f97e4c86/src</locationURI>
</link>
<link>
<name>GreenDroid_src</name>
<type>2</type>
Expand Down
4 changes: 4 additions & 0 deletions GDCatalog/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
android:theme="@style/Theme.GDCatalog"
android:name=".CatalogApplication">

<uses-library android:name="com.google.android.maps" />

<activity android:name=".CatalogActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -61,6 +63,8 @@
<activity android:name=".QuickActionActivity" />
<activity android:name=".SimpleAsyncImageViewActivity" />
<activity android:name=".AsyncImageViewListActivity" />

<activity android:name=".MapPinMapActivity" />

</application>

Expand Down
4 changes: 2 additions & 2 deletions GDCatalog/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-4
android.library.reference.1=../GreenDroid
target=Google Inc.:Google APIs:4
android.library.reference.1=../GreenDroid-GoogleAPIs
25 changes: 25 additions & 0 deletions GDCatalog/res/layout/map_pin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright (C) 2011 Cyril Mottier (http://www.cyrilmottier.com)
**
** 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.
*/
-->
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="@string/google_map_api_key_debug" />
1 change: 1 addition & 0 deletions GDCatalog/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="quick_action_label">QuickAction</string>
<string name="simple_async_image_view_label">Simple AsyncImageView</string>
<string name="async_image_view_list_view_label">AsyncImageView in ListView</string>
<string name="map_pin_drawable_label">MapPinDrawable</string>

<string name="about">About</string>
<string name="license">License</string>
Expand Down
1 change: 1 addition & 0 deletions GDCatalog/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="quick_action_label">Démo QuickAction</string>
<string name="simple_async_image_view_label">AsyncImageView simple</string>
<string name="async_image_view_list_view_label">AsyncImageView dans une ListView</string>
<string name="map_pin_drawable_label">MapPinDrawable</string>

<string name="about">A propos</string>
<string name="license">Licence</string>
Expand Down
6 changes: 5 additions & 1 deletion GDCatalog/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
-->

<resources>


<!-- Release key is in the p_strings.xml file ignored by Git -->
<string name="google_map_api_key_debug">0IgVgWFseCoAyOOEFSXlrEhfjQE99UGBY_sh2CA</string>

<string name="app_name">GDCatalog</string>
<string name="app_url">http://github.com/cyrilmottier/GreenDroid</string>

Expand All @@ -34,6 +37,7 @@
<string name="quick_action_label">QuickAction</string>
<string name="simple_async_image_view_label">Simple AsyncImageView</string>
<string name="async_image_view_list_view_label">AsyncImageView in ListView</string>
<string name="map_pin_drawable_label">MapPinDrawable</string>

<string name="about">About</string>
<string name="license">License</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
adapter.add(createTextItem(R.string.quick_action_label, QuickActionActivity.class));
adapter.add(createTextItem(R.string.simple_async_image_view_label, SimpleAsyncImageViewActivity.class));
adapter.add(createTextItem(R.string.async_image_view_list_view_label, AsyncImageViewListActivity.class));
adapter.add(createTextItem(R.string.map_pin_drawable_label, MapPinMapActivity.class));

setListAdapter(adapter);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright (C) 2011 Cyril Mottier (http://www.cyrilmottier.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cyrilmottier.android.gdcatalog;

import greendroid.app.GDMapActivity;
import greendroid.graphics.drawable.DrawableStateSet;
import greendroid.graphics.drawable.MapPinDrawable;

import java.util.ArrayList;
import java.util.Random;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class MapPinMapActivity extends GDMapActivity {

private static Random sRandom = new Random();

private static final int[] PRESSED_STATE = {
android.R.attr.state_pressed
};

//@formatter:off
private static final OverlayItem[] sFrance = {
new OverlayItem(new GeoPoint(48635600, -1510600), "Mont Saint Michel", null),
new OverlayItem(new GeoPoint(48856700, 2351000), "Paris", null),
new OverlayItem(new GeoPoint(44837400, -576100), "Bordeaux", null),
new OverlayItem(new GeoPoint(48593100, -647500), "Domfront", null)
};

private static final OverlayItem[] sEurope = {
new OverlayItem(new GeoPoint(55755800, 37617600), "Moscow", null),
new OverlayItem(new GeoPoint(59332800, 18064500), "Stockholm", null),
new OverlayItem(new GeoPoint(59939000, 30315800), "Saint Petersburg", null),
new OverlayItem(new GeoPoint(60169800, 24938200), "Helsinki", null),
new OverlayItem(new GeoPoint(60451400, 22268700), "Turku", null),
new OverlayItem(new GeoPoint(65584200, 22154700), "LuleŒ", null),
new OverlayItem(new GeoPoint(59438900, 24754500), "Talinn", null),
new OverlayItem(new GeoPoint(66498700, 25721100), "Rovaniemi", null)
};

private static final OverlayItem[] sUSAEastCoast = {
new OverlayItem(new GeoPoint(40714400, -74006000), "New York City", null),
new OverlayItem(new GeoPoint(39952300, -75163800), "Philadelphia", null),
new OverlayItem(new GeoPoint(38895100, -77036400), "Washington", null),
new OverlayItem(new GeoPoint(41374800, -83651300), "Bowling Green", null),
new OverlayItem(new GeoPoint(42331400, -83045800), "Detroit", null)
};

private static final OverlayItem[] sUSAWestCoast = {
new OverlayItem(new GeoPoint(37774900, -122419400), "San Francisco", null),
new OverlayItem(new GeoPoint(37770600, -119510800), "Yosemite National Park", null),
new OverlayItem(new GeoPoint(36878200, -121947300), "Monteray Bay", null),
new OverlayItem(new GeoPoint(35365800, -120849900), "Morro Bay", null),
new OverlayItem(new GeoPoint(34420800, -119698200), "Santa Barbara", null),
new OverlayItem(new GeoPoint(34052200, -118243700), "Los Angeles", null),
new OverlayItem(new GeoPoint(32715300, -117157300), "San Diego", null),
new OverlayItem(new GeoPoint(36114600, -115172800), "Las Vegas", null),
new OverlayItem(new GeoPoint(36220100, -116881700), "Death Valley", null),
new OverlayItem(new GeoPoint(36355200, -112661200), "Grand Canyon", null),
new OverlayItem(new GeoPoint(37289900, -113048900), "Zion National Park", null),
new OverlayItem(new GeoPoint(37628300, -112167700), "Bryce Canyon", null),
new OverlayItem(new GeoPoint(36936900, -111483800), "Lake Powell", null),
};

private static final OverlayItem[][] sAreas = {
sFrance, sEurope, sUSAEastCoast, sUSAWestCoast
};
//@formatter:on

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setActionBarContentView(R.layout.map_pin);

final MapView mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);

final Resources r = getResources();

for (int i = 0; i < sAreas.length; i++) {
final OverlayItem[] items = sAreas[i];

ColorStateList pinCsl = createRandomColorStateList();
ColorStateList dotCsl = createRandomColorStateList();
BasicItemizedOverlay itemizedOverlay = new BasicItemizedOverlay(new MapPinDrawable(r, pinCsl, dotCsl));

for (int j = 0; j < items.length; j++) {
itemizedOverlay.addOverlay(items[j]);
}

mapView.getOverlays().add(itemizedOverlay);
}
}

@Override
protected boolean isRouteDisplayed() {
return false;
}

private class BasicItemizedOverlay extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

public BasicItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}

public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}

@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}

@Override
public int size() {
return mOverlays.size();
}

@Override
protected boolean onTap(int index) {
return true;
}

}

private ColorStateList createRandomColorStateList() {

int[][] states = new int[2][];
int[] colors = new int[2];

final int randomColor = randomColor();

states[0] = PRESSED_STATE;
colors[0] = addRGB(randomColor, -50);

states[1] = DrawableStateSet.EMPTY_STATE_SET;
colors[1] = randomColor;

return new ColorStateList(states, colors);
}

private static final int randomColor() {
int r = sRandom.nextInt(256);
int g = sRandom.nextInt(256);
int b = sRandom.nextInt(256);
return Color.rgb(r, g, b);
}

private static int addRGB(int color, int amount) {
int r = constrain(Color.red(color) + amount, 0, 255);
int g = constrain(Color.green(color) + amount, 0, 255);
int b = constrain(Color.blue(color) + amount, 0, 255);
return Color.rgb(r, g, b);
}

public static int constrain(int amount, int low, int high) {
return amount < low ? low : (amount > high ? high : amount);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1fbbe49

Please sign in to comment.