Skip to content

Commit

Permalink
Merge pull request #13 from gkravas/master
Browse files Browse the repository at this point in the history
Support CharSequence for text instead of String
  • Loading branch information
ViHtarb authored Sep 29, 2016
2 parents 610ccda + d9496ac commit 66ebbad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/com/tooltip/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.tooltip.sample;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -38,11 +45,18 @@ public void onClick(View v) {
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);

SpannableString text = new SpannableString("I`m on the bottom of menu item X");
text.setSpan(new ForegroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Drawable d = ContextCompat.getDrawable(getBaseContext(), R.mipmap.ic_launcher);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
text.setSpan(span, 31, 32, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

MenuItem menuItem = menu.findItem(R.id.action_test2);
Tooltip.Builder builder = new Tooltip.Builder(menuItem)
.setCornerRadius(10f)
.setGravity(Gravity.BOTTOM)
.setText("I`m on the bottom of menu item");
.setText(text);
builder.show();

return super.onCreateOptionsMenu(menu);
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "0.1.9"
versionName "0.2.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/tooltip/Tooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static final class Builder {
private float mLineSpacingMultiplier = 1f;

private Drawable mArrowDrawable;
private String mText;
private CharSequence mText;
private ColorStateList mTextColor;
private Typeface mTypeface = Typeface.DEFAULT;

Expand Down Expand Up @@ -636,7 +636,7 @@ public Builder setText(@StringRes int resId) {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setText(String text) {
public Builder setText(CharSequence text) {
mText = text;
return this;
}
Expand Down

0 comments on commit 66ebbad

Please sign in to comment.