diff --git a/demo/src/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java b/demo/src/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java index ad82d77de..0d2f95e8d 100644 --- a/demo/src/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java +++ b/demo/src/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java @@ -1,5 +1,6 @@ package com.google.maps.android.utils.demo; +import android.graphics.Color; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; @@ -15,8 +16,8 @@ protected void startDemo() { IconGenerator iconFactory = new IconGenerator(this); addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094)); - iconFactory.setStyle(IconGenerator.STYLE_BLUE); - addIcon(iconFactory, "Blue style", new LatLng(-33.9360, 151.2070)); + iconFactory.setColor(Color.CYAN); + addIcon(iconFactory, "Custom color", new LatLng(-33.9360, 151.2070)); iconFactory.setRotation(90); iconFactory.setStyle(IconGenerator.STYLE_RED); diff --git a/library/res/drawable-xhdpi/bubble_blue.9.png b/library/res/drawable-xhdpi/bubble_blue.9.png deleted file mode 100644 index 4e8e57a77..000000000 Binary files a/library/res/drawable-xhdpi/bubble_blue.9.png and /dev/null differ diff --git a/library/res/drawable-xhdpi/bubble_green.9.png b/library/res/drawable-xhdpi/bubble_green.9.png deleted file mode 100644 index e6ceb5ddd..000000000 Binary files a/library/res/drawable-xhdpi/bubble_green.9.png and /dev/null differ diff --git a/library/res/drawable-xhdpi/bubble_mask.9.png b/library/res/drawable-xhdpi/bubble_mask.9.png new file mode 100644 index 000000000..9fea79ab8 Binary files /dev/null and b/library/res/drawable-xhdpi/bubble_mask.9.png differ diff --git a/library/res/drawable-xhdpi/bubble_orange.9.png b/library/res/drawable-xhdpi/bubble_orange.9.png deleted file mode 100644 index 080bf7ff5..000000000 Binary files a/library/res/drawable-xhdpi/bubble_orange.9.png and /dev/null differ diff --git a/library/res/drawable-xhdpi/bubble_purple.9.png b/library/res/drawable-xhdpi/bubble_purple.9.png deleted file mode 100644 index 04afe98d4..000000000 Binary files a/library/res/drawable-xhdpi/bubble_purple.9.png and /dev/null differ diff --git a/library/res/drawable-xhdpi/bubble_red.9.png b/library/res/drawable-xhdpi/bubble_red.9.png deleted file mode 100644 index 02911e073..000000000 Binary files a/library/res/drawable-xhdpi/bubble_red.9.png and /dev/null differ diff --git a/library/res/drawable-xhdpi/bubble_shadow.9.png b/library/res/drawable-xhdpi/bubble_shadow.9.png new file mode 100644 index 000000000..9ffe1bddb Binary files /dev/null and b/library/res/drawable-xhdpi/bubble_shadow.9.png differ diff --git a/library/res/drawable-xhdpi/bubble_white.9.png b/library/res/drawable-xhdpi/bubble_white.9.png deleted file mode 100644 index 6bba5f26a..000000000 Binary files a/library/res/drawable-xhdpi/bubble_white.9.png and /dev/null differ diff --git a/library/res/drawable-xxhdpi/bubble_mask.9.png b/library/res/drawable-xxhdpi/bubble_mask.9.png new file mode 100644 index 000000000..43cbc57c4 Binary files /dev/null and b/library/res/drawable-xxhdpi/bubble_mask.9.png differ diff --git a/library/res/drawable-xxhdpi/bubble_shadow.9.png b/library/res/drawable-xxhdpi/bubble_shadow.9.png new file mode 100644 index 000000000..67764cc20 Binary files /dev/null and b/library/res/drawable-xxhdpi/bubble_shadow.9.png differ diff --git a/library/res/layout/text_bubble.xml b/library/res/layout/text_bubble.xml index ece97dd67..422bdc9db 100644 --- a/library/res/layout/text_bubble.xml +++ b/library/res/layout/text_bubble.xml @@ -2,7 +2,6 @@ + android:paddingTop="5dp"/> diff --git a/library/src/com/google/maps/android/ui/BubbleDrawable.java b/library/src/com/google/maps/android/ui/BubbleDrawable.java new file mode 100644 index 000000000..79369cd49 --- /dev/null +++ b/library/src/com/google/maps/android/ui/BubbleDrawable.java @@ -0,0 +1,81 @@ +/* + * Copyright 2013 Google Inc. + * + * 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.google.maps.android.ui; + +import android.content.res.Resources; +import android.graphics.*; +import android.graphics.drawable.Drawable; + +import com.google.maps.android.R; + +/** + * Draws a bubble with a shadow, filled with any color. + */ +class BubbleDrawable extends Drawable { + + private final Drawable mShadow; + private final Drawable mMask; + private int mColor = Color.WHITE; + + public BubbleDrawable(Resources res) { + mMask = res.getDrawable(R.drawable.bubble_mask); + mShadow = res.getDrawable(R.drawable.bubble_shadow); + } + + public void setColor(int color) { + mColor = color; + } + + @Override + public void draw(Canvas canvas) { + mMask.draw(canvas); + canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); + mShadow.draw(canvas); + } + + @Override + public void setAlpha(int alpha) { + throw new UnsupportedOperationException(); + } + + @Override + public void setColorFilter(ColorFilter cf) { + throw new UnsupportedOperationException(); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + @Override + public void setBounds(int left, int top, int right, int bottom) { + mMask.setBounds(left, top, right, bottom); + mShadow.setBounds(left, top, right, bottom); + } + + @Override + public void setBounds(Rect bounds) { + mMask.setBounds(bounds); + mShadow.setBounds(bounds); + } + + @Override + public boolean getPadding(Rect padding) { + return mMask.getPadding(padding); + } +} diff --git a/library/src/com/google/maps/android/ui/IconGenerator.java b/library/src/com/google/maps/android/ui/IconGenerator.java index 78f2af198..4a95f4d5f 100644 --- a/library/src/com/google/maps/android/ui/IconGenerator.java +++ b/library/src/com/google/maps/android/ui/IconGenerator.java @@ -50,12 +50,14 @@ public class IconGenerator { private float mAnchorU = 0.5f; private float mAnchorV = 1f; + private BubbleDrawable mBackground; /** * Creates a new IconGenerator with the default style. */ public IconGenerator(Context context) { mContext = context; + mBackground = new BubbleDrawable(mContext.getResources()); } /** @@ -208,10 +210,20 @@ public void setTextAppearance(int resid) { * Sets the style of the icon. The style consists of a background and text appearance. */ public void setStyle(int style) { - setBackground(mContext.getResources().getDrawable(getBackground(style))); + setColor(getStyleColor(style)); setTextAppearance(mContext, getTextStyle(style)); } + /** + * Sets the background to the default, with a given color tint. + * + * @param color the color for the background tint. + */ + public void setColor(int color) { + mBackground.setColor(color); + setBackground(mBackground); + } + /** * Set the background to a given Drawable, or remove the background. * @@ -249,6 +261,7 @@ private void ensureViewsSetUp() { mContainer = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.text_bubble, null); mRotationLayout = (RotationLayout) mContainer.getChildAt(0); mContentView = mTextView = (TextView) mRotationLayout.findViewById(R.id.text); + setStyle(STYLE_DEFAULT); } } @@ -274,22 +287,22 @@ public void setContentPadding(int left, int top, int right, int bottom) { public static final int STYLE_PURPLE = 6; public static final int STYLE_ORANGE = 7; - private static int getBackground(int style) { + private static int getStyleColor(int style) { switch (style) { default: case STYLE_DEFAULT: case STYLE_WHITE: - return R.drawable.bubble_white; + return 0xffffffff; case STYLE_RED: - return R.drawable.bubble_red; + return 0xffcc0000; case STYLE_BLUE: - return R.drawable.bubble_blue; + return 0xff0099cc; case STYLE_GREEN: - return R.drawable.bubble_green; + return 0xff669900; case STYLE_PURPLE: - return R.drawable.bubble_purple; + return 0xff9933cc; case STYLE_ORANGE: - return R.drawable.bubble_orange; + return 0xffff8800; } }