Skip to content
Merged
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
52 changes: 14 additions & 38 deletions library/src/com/google/maps/android/ui/IconGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class IconGenerator {
public IconGenerator(Context context) {
mContext = context;
mBackground = new BubbleDrawable(mContext.getResources());
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 @@ -66,8 +70,6 @@ public IconGenerator(Context context) {
* @param text the text content to display inside the icon.
*/
public Bitmap makeIcon(String text) {
ensureViewsSetUp();

if (mTextView != null) {
mTextView.setText(text);
}
Expand All @@ -82,19 +84,17 @@ public Bitmap makeIcon(String text) {
* applicable.
*/
public Bitmap makeIcon() {
ViewGroup container = getContainer();

int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
container.measure(measureSpec, measureSpec);
mContainer.measure(measureSpec, measureSpec);

int measuredWidth = container.getMeasuredWidth();
int measuredHeight = container.getMeasuredHeight();
int measuredWidth = mContainer.getMeasuredWidth();
int measuredHeight = mContainer.getMeasuredHeight();

container.layout(0, 0, measuredWidth, measuredHeight);
mContainer.layout(0, 0, measuredWidth, measuredHeight);

if (mRotation == 1 || mRotation == 3) {
measuredHeight = container.getMeasuredWidth();
measuredWidth = container.getMeasuredHeight();
measuredHeight = mContainer.getMeasuredWidth();
measuredWidth = mContainer.getMeasuredHeight();
}

Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
Expand All @@ -113,7 +113,7 @@ public Bitmap makeIcon() {
canvas.translate(0, measuredHeight);
canvas.rotate(270);
}
container.draw(canvas);
mContainer.draw(canvas);
return r;
}

Expand All @@ -124,7 +124,6 @@ public Bitmap makeIcon() {
* #setTextAppearance} and {@link #makeIcon(String)} will operate upon that {@link TextView}.
*/
public void setContentView(View contentView) {
ensureViewsSetUp();
mRotationLayout.removeAllViews();
mRotationLayout.addView(contentView);
mContentView = contentView;
Expand All @@ -138,7 +137,6 @@ public void setContentView(View contentView) {
* @param degrees the amount the contents should be rotated, as a multiple of 90 degrees.
*/
public void setContentRotation(int degrees) {
ensureViewsSetUp();
mRotationLayout.setViewRotation(degrees);
}

Expand Down Expand Up @@ -190,7 +188,6 @@ private float rotateAnchor(float u, float v) {
* @param resid the identifier of the resource.
*/
public void setTextAppearance(Context context, int resid) {
ensureViewsSetUp();
if (mTextView != null) {
mTextView.setTextAppearance(context, resid);
}
Expand Down Expand Up @@ -232,36 +229,16 @@ public void setColor(int color) {
@SuppressWarnings("deprecation")
// View#setBackgroundDrawable is compatible with pre-API level 16 (Jelly Bean).
public void setBackground(Drawable background) {
getContainer().setBackgroundDrawable(background);
mContainer.setBackgroundDrawable(background);

// Force setting of padding.
// setBackgroundDrawable does not call setPadding if the background has 0 padding.
if (background != null) {
Rect rect = new Rect();
background.getPadding(rect);
getContainer().setPadding(rect.left, rect.top, rect.right, rect.bottom);
mContainer.setPadding(rect.left, rect.top, rect.right, rect.bottom);
} else {
getContainer().setPadding(0, 0, 0, 0);
}
}

/**
* Not thread safe.
*/
private ViewGroup getContainer() {
ensureViewsSetUp();
return mContainer;
}

/**
* Ensure views are ready. This allows us to lazily inflate the main layout.
*/
private void ensureViewsSetUp() {
if (mContainer == null) {
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);
mContainer.setPadding(0, 0, 0, 0);
}
}

Expand All @@ -275,7 +252,6 @@ private void ensureViewsSetUp() {
* @param bottom the bottom padding in pixels.
*/
public void setContentPadding(int left, int top, int right, int bottom) {
ensureViewsSetUp();
mContentView.setPadding(left, top, right, bottom);
}

Expand Down