Skip to content

Commit

Permalink
Merge pull request #244 from jonathan-caryl/master
Browse files Browse the repository at this point in the history
makeIcon takes CharSequence not String
  • Loading branch information
markmcd committed Feb 17, 2016
2 parents a4562a2 + 39700db commit 8d39220
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
package com.google.maps.android.utils.demo;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.ui.IconGenerator;

import static android.graphics.Typeface.BOLD;
import static android.graphics.Typeface.ITALIC;
import static android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;

public class IconGeneratorDemoActivity extends BaseDemoActivity {

@Override
Expand All @@ -47,14 +54,29 @@ protected void startDemo() {
iconFactory.setContentRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_GREEN);
addIcon(iconFactory, "ContentRotate=90", new LatLng(-33.7677, 151.244));

iconFactory.setRotation(0);
iconFactory.setContentRotation(0);
iconFactory.setStyle(IconGenerator.STYLE_ORANGE);
addIcon(iconFactory, makeCharSequence(), new LatLng(-33.77720, 151.12412));
}

private void addIcon(IconGenerator iconFactory, String text, LatLng position) {
private void addIcon(IconGenerator iconFactory, CharSequence text, LatLng position) {
MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).
position(position).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());

getMap().addMarker(markerOptions);
}

private CharSequence makeCharSequence() {
String prefix = "Mixing ";
String suffix = "different fonts";
String sequence = prefix + suffix;
SpannableStringBuilder ssb = new SpannableStringBuilder(sequence);
ssb.setSpan(new StyleSpan(ITALIC), 0, prefix.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(new StyleSpan(BOLD), prefix.length(), sequence.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
return ssb;
}
}
2 changes: 1 addition & 1 deletion library/src/com/google/maps/android/ui/IconGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IconGenerator(Context context) {
*
* @param text the text content to display inside the icon.
*/
public Bitmap makeIcon(String text) {
public Bitmap makeIcon(CharSequence text) {
if (mTextView != null) {
mTextView.setText(text);
}
Expand Down

0 comments on commit 8d39220

Please sign in to comment.