diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-02-15 18:22:46 -0800 |
---|---|---|
committer | Luis Vidal <lvidal@cyngn.com> | 2016-02-15 18:22:46 -0800 |
commit | 6a2a6f522ea6674e94d3b166b9af7f85e5a12098 (patch) | |
tree | aa71ecbeabbaa08c2cd2f1d1a75f6c0af2dc6526 /src | |
parent | 46c47f62bb158ffd46e3499ad6312070b10bb113 (diff) | |
download | packages_apps_ThemeChooser-6a2a6f522ea6674e94d3b166b9af7f85e5a12098.zip packages_apps_ThemeChooser-6a2a6f522ea6674e94d3b166b9af7f85e5a12098.tar.gz packages_apps_ThemeChooser-6a2a6f522ea6674e94d3b166b9af7f85e5a12098.tar.bz2 |
Allow FittedTextView to control whether text should be expanded
A new API setAutoExpand has been introduced to allow subclasses
to control whether the text should be expanded to fill out the
view. This is particulary useful to instruct the class not to
resize the text if it fits 'as is' keeping the original font
size
Change-Id: Ie23d2b2f6f5c31fa7befe602e1bfc441c614ec72
TICKET: CHOOSER-115
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/widget/FittedTextView.java | 11 | ||||
-rw-r--r-- | src/com/cyngn/theme/widget/LatoTextView.java | 1 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/com/cyngn/theme/widget/FittedTextView.java b/src/com/cyngn/theme/widget/FittedTextView.java index fbe1489..2406a59 100644 --- a/src/com/cyngn/theme/widget/FittedTextView.java +++ b/src/com/cyngn/theme/widget/FittedTextView.java @@ -18,7 +18,11 @@ import android.widget.TextView; */ public class FittedTextView extends TextView { private Paint mPaint; + //If set to true, the text will be resized to fit the view. private boolean mAutoFitText = true; + //Used to instruct whether the text should be expanded to fill out the view, even if the text + //fits without being resized + private boolean mAutoExpand = true; public FittedTextView(Context context) { this(context, null); @@ -41,6 +45,10 @@ public class FittedTextView extends TextView { return mAutoFitText; } + protected void setAutoExpand(boolean autoExpand) { + mAutoExpand = autoExpand; + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -55,8 +63,7 @@ public class FittedTextView extends TextView { } mPaint.set(getPaint()); - //If it fits as is, don't touch it - if (mPaint.measureText(text) <= TARGET_WIDTH) return; + if (mPaint.measureText(text) <= TARGET_WIDTH && !mAutoExpand) return; float max = 200; float min = 2; diff --git a/src/com/cyngn/theme/widget/LatoTextView.java b/src/com/cyngn/theme/widget/LatoTextView.java index 2da46a8..9ced870 100644 --- a/src/com/cyngn/theme/widget/LatoTextView.java +++ b/src/com/cyngn/theme/widget/LatoTextView.java @@ -136,6 +136,7 @@ public class LatoTextView extends FittedTextView { } setTypefaceFromAttrs(fontFamily, styleIndex); + setAutoExpand(false); TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.FittedTextView, 0, 0); try { |