Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7264f713 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Remotable view method for TextView.setTextSize(int, float).

The only remotable method on TextView is setTextSize(float)
which assumes "sp" dimensions, making it tricky to get exact
text sizes.

Bug: 6519374
Change-Id: I961bbdd607ca6786c0630ff1ce19186f54f6f31f
parent d7ba8143
Loading
Loading
Loading
Loading
+56 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.LayoutInflater.Filter;
import android.view.RemotableViewMethod;
@@ -1181,6 +1182,45 @@ public class RemoteViews implements Parcelable, Filter {
        public final static int TAG = 11;
    }

    /**
     * Helper action to set compound drawables on a TextView. Supports relative
     * (s/t/e/b) or cardinal (l/t/r/b) arrangement.
     */
    private class TextViewSizeAction extends Action {
        public TextViewSizeAction(int viewId, int units, float size) {
            this.viewId = viewId;
            this.units = units;
            this.size = size;
        }

        public TextViewSizeAction(Parcel parcel) {
            viewId = parcel.readInt();
            units = parcel.readInt();
            size  = parcel.readFloat();
        }

        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(TAG);
            dest.writeInt(viewId);
            dest.writeInt(units);
            dest.writeFloat(size);
        }

        @Override
        public void apply(View root, ViewGroup rootParent) {
            final Context context = root.getContext();
            final TextView target = (TextView) root.findViewById(viewId);
            if (target == null) return;
            target.setTextSize(units, size);
        }

        int viewId;
        int units;
        float size;

        public final static int TAG = 13;
    }

    /**
     * Simple class used to keep track of memory usage in a RemoteViews.
     *
@@ -1334,6 +1374,9 @@ public class RemoteViews implements Parcelable, Filter {
                    case TextViewDrawableAction.TAG:
                        mActions.add(new TextViewDrawableAction(parcel));
                        break;
                    case TextViewSizeAction.TAG:
                        mActions.add(new TextViewSizeAction(parcel));
                        break;
                    case BitmapReflectionAction.TAG:
                        mActions.add(new BitmapReflectionAction(parcel));
                        break;
@@ -1542,6 +1585,18 @@ public class RemoteViews implements Parcelable, Filter {
        setCharSequence(viewId, "setText", text);
    }

    /**
     * @hide
     * Equivalent to calling {@link TextView#setTextSize(int, float)}
     * 
     * @param viewId The id of the view whose text size should change
     * @param units The units of size (e.g. COMPLEX_UNIT_SP)
     * @param size The size of the text
     */
    public void setTextViewTextSize(int viewId, int units, float size) {
        addAction(new TextViewSizeAction(viewId, units, size));
    }

    /**
     * Equivalent to calling 
     * {@link TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)}.