Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Binary file removed library/res/drawable-xhdpi/bubble_blue.9.png
Binary file not shown.
Binary file removed library/res/drawable-xhdpi/bubble_green.9.png
Binary file not shown.
Binary file added library/res/drawable-xhdpi/bubble_mask.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed library/res/drawable-xhdpi/bubble_orange.9.png
Binary file not shown.
Binary file removed library/res/drawable-xhdpi/bubble_purple.9.png
Binary file not shown.
Binary file removed library/res/drawable-xhdpi/bubble_red.9.png
Binary file not shown.
Binary file added library/res/drawable-xhdpi/bubble_shadow.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed library/res/drawable-xhdpi/bubble_white.9.png
Binary file not shown.
Binary file added library/res/drawable-xxhdpi/bubble_mask.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/res/drawable-xxhdpi/bubble_shadow.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions library/res/layout/text_bubble.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bubble_white"
android:orientation="vertical">

<com.google.maps.android.ui.RotationLayout
Expand All @@ -18,8 +17,7 @@
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:textAppearance="@style/Bubble.TextAppearance.Dark" />
android:paddingTop="5dp"/>

</com.google.maps.android.ui.RotationLayout>

Expand Down
81 changes: 81 additions & 0 deletions library/src/com/google/maps/android/ui/BubbleDrawable.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
29 changes: 21 additions & 8 deletions library/src/com/google/maps/android/ui/IconGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
}

Expand Down