Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeIcon takes CharSequence not String #244

Merged
merged 1 commit into from
Feb 17, 2016
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
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