JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

addIcons adds height to textView with Spannable #117

Closed jlhonora closed 9 years ago

jlhonora commented 9 years ago

I'm facing a strange issue regarding TextView height when calling addIcons. I'm using release 1.0.11, due to API level restrictions (I need >= 10, current min is 11). Using the following view:

    <LinearLayout
        android:id="@+id/main_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title_label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="3dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

I'm setting the text this way:

SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("1001");
Spannable iconSpannable = new SpannableString(fontString);
iconSpannable.setSpan(new ForegroundColorSpan(color), 0, fontString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(iconSpannable);

TextView titleView = (TextView) v.findViewById(R.id.title_label);
titleView.setText(builder, TextView.BufferType.SPANNABLE);

and it looks fine (no added icons of course, red frame added by me):

device-2015-09-07-150533

But when I add:

Iconify.addIcons(titleView);

there's an added height to the TextView (again, red frame added by me, depicts the full height of the TextView, retrieved by UI automator):

device-2015-09-07-150647

How can I prevent this? Am I doing something wrong? I'd rather use the {fa-tag color} built-in, but I can't migrate to 2.0.X due to API level restrictions.

Thanks in advance, great library.

JoanZapata commented 9 years ago

I'm not sure I understand which TextView is displaying what. I'll see if I can lower the min API for version 2.0.X.

jlhonora commented 9 years ago

Added view id and image highlighting for clarity.

Regarding API level, that would be excellent!

jlhonora commented 9 years ago

API level >= 4 could be supported with small changes https://github.com/JoanZapata/android-iconify/compare/master...jlhonora:master . Basically the difference is

diff --git a/android-iconify/src/main/java/com/joanzapata/iconify/internal/CustomTypefaceSpan.java b/android-iconify/src/main/java/com/joanzapata/iconify/internal/CustomTypefaceSpan.java
index 3d907eb..282cc44 100644
--- a/android-iconify/src/main/java/com/joanzapata/iconify/internal/CustomTypefaceSpan.java
+++ b/android-iconify/src/main/java/com/joanzapata/iconify/internal/CustomTypefaceSpan.java
@@ -29,7 +30,7 @@ public class CustomTypefaceSpan extends ReplacementSpan {
         this.iconSizePx = iconSizePx;
         this.iconSizeRatio = iconSizeRatio;
         this.iconColor = iconColor;
-        if (rotate) {
+        if (rotate && Build.VERSION.SDK_INT >= 11) {

The icon rotation wouldn't work though, since ValueAnimator was introduced in API level 11.

I'd rather encapsulate the API level check in a single method, but the linter doesn't like that.

If you like the changes I can make a PR.

JoanZapata commented 9 years ago

I didn't want to have different behaviors on lower API levels, I can see the issues coming like "icons are not rotating on my Nokia 3310!". :smile:

I'll spend some time on implementing the rotation in an API 4 compatible way. If that proves impossible or too hard to maintain, then I'll gladly merge your code. :)

JoanZapata commented 9 years ago

2.0.10 release will be compatible with API 4, spinning included. :)

jlhonora commented 8 years ago

Excellent!

Took a while to follow up on this, sorry :)