summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Vidal <lvidal@cyngn.com>2016-02-11 15:44:24 -0800
committerLuis Vidal <lvidal@cyngn.com>2016-02-12 11:25:03 -0800
commit46c47f62bb158ffd46e3499ad6312070b10bb113 (patch)
treee80c5ca98b839a769e1153ce805a13f1c220e95c
parentbb32275e34826dd67636d5712b0651d23751b6d2 (diff)
downloadpackages_apps_ThemeChooser-46c47f62bb158ffd46e3499ad6312070b10bb113.zip
packages_apps_ThemeChooser-46c47f62bb158ffd46e3499ad6312070b10bb113.tar.gz
packages_apps_ThemeChooser-46c47f62bb158ffd46e3499ad6312070b10bb113.tar.bz2
Use Lato font on Animated Lock Screen thumbnail text
To be consistent with the rest of the text views in the chooser, we need to use Lato font on the animated lock screen thumbnail (rather than Roboto as initially requested). In order to reuse as much code as possible, LatoTextView is now extending FittedTextView. A new attribute 'autoFitText' is introduced to instruct whether fitted text is desired. Change-Id: I3209fe7f06177bc4025cbf964d0c2dd79325b9c0 TICKET: CHOOSER-113
-rw-r--r--res/layout/wallpaper_component_selection_item.xml8
-rw-r--r--res/values/attrs.xml3
-rw-r--r--res/values/styles.xml6
-rw-r--r--src/com/cyngn/theme/widget/FittedTextView.java20
-rw-r--r--src/com/cyngn/theme/widget/LatoTextView.java13
5 files changed, 39 insertions, 11 deletions
diff --git a/res/layout/wallpaper_component_selection_item.xml b/res/layout/wallpaper_component_selection_item.xml
index e36ec0a..7f1428c 100644
--- a/res/layout/wallpaper_component_selection_item.xml
+++ b/res/layout/wallpaper_component_selection_item.xml
@@ -3,6 +3,7 @@
Copyright (C) 2014 Cyanogen, Inc.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:cyngn="http://schemas.android.com/apk/res/com.cyngn.theme.chooser"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="@dimen/component_selection_cell_height"
@@ -31,16 +32,17 @@
android:background="@android:color/white"
android:layout_gravity="center_horizontal|bottom"
android:visibility="gone">
- <com.cyngn.theme.widget.FittedTextView
+ <com.cyngn.theme.widget.LatoTextView
android:layout_width="@dimen/animated_lock_screen_text_width"
android:layout_height="@dimen/animated_lock_screen_text_height"
android:includeFontPadding="false"
- android:gravity="center"
+ android:layout_gravity="center_horizontal"
android:layout_marginLeft="@dimen/animated_lock_screen_text_margin_left"
android:layout_marginRight="@dimen/animated_lock_screen_text_margin_right"
android:layout_marginTop="@dimen/animated_lock_screen_text_margin_top"
android:layout_marginBottom="@dimen/animated_lock_screen_text_margin_bottom"
style="@style/animated_lock_screen_badge_text_style"
+ cyngn:autoFitText="true"
android:text="@string/animated_lock_screen_badge_text"/>
</LinearLayout>
</FrameLayout>
@@ -52,4 +54,4 @@
android:layout_gravity="center_horizontal"
style="@style/component_title"/>
-</LinearLayout> \ No newline at end of file
+</LinearLayout>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index d78f25e..0cb7ae9 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -18,4 +18,7 @@
<attr name="maxHeight" format="dimension" />
</declare-styleable>
+ <declare-styleable name="FittedTextView">
+ <attr name="autoFitText" format="boolean" />
+ </declare-styleable>
</resources> \ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 3fca6f9..e0bc961 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -130,12 +130,12 @@
</style>
<style name="animated_lock_screen_badge_text_style">
- <item name="android:fontFamily">sans-serif</item>
- <item name="android:textStyle">bold</item>
<item name="android:alpha">0.54</item>
- <item name="android:textSize">12sp</item>
<item name="android:letterSpacing">0.2</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:textAllCaps">true</item>
+ <item name="android:gravity">center</item>
+ <item name="android:textSize">10dp</item>
+ <item name="android:maxLines">1</item>
</style>
</resources>
diff --git a/src/com/cyngn/theme/widget/FittedTextView.java b/src/com/cyngn/theme/widget/FittedTextView.java
index 78e6a16..fbe1489 100644
--- a/src/com/cyngn/theme/widget/FittedTextView.java
+++ b/src/com/cyngn/theme/widget/FittedTextView.java
@@ -18,15 +18,14 @@ import android.widget.TextView;
*/
public class FittedTextView extends TextView {
private Paint mPaint;
+ private boolean mAutoFitText = true;
public FittedTextView(Context context) {
- super(context);
- mPaint = new Paint();
+ this(context, null);
}
public FittedTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- mPaint = new Paint();
+ this(context, attrs, 0);
}
public FittedTextView(Context context, AttributeSet attrs, int defStyle) {
@@ -34,9 +33,19 @@ public class FittedTextView extends TextView {
mPaint = new Paint();
}
+ protected void setAutoFitText(boolean autoFit) {
+ mAutoFitText = autoFit;
+ }
+
+ protected boolean getAutoFitText() {
+ return mAutoFitText;
+ }
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ if (!mAutoFitText) return;
+
final float THRESHOLD = 0.5f;
final float TARGET_WIDTH = getMeasuredWidth();
String text = getText().toString();
@@ -46,6 +55,9 @@ public class FittedTextView extends TextView {
}
mPaint.set(getPaint());
+ //If it fits as is, don't touch it
+ if (mPaint.measureText(text) <= TARGET_WIDTH) return;
+
float max = 200;
float min = 2;
while(max > min) {
diff --git a/src/com/cyngn/theme/widget/LatoTextView.java b/src/com/cyngn/theme/widget/LatoTextView.java
index fe39e5c..2da46a8 100644
--- a/src/com/cyngn/theme/widget/LatoTextView.java
+++ b/src/com/cyngn/theme/widget/LatoTextView.java
@@ -10,6 +10,7 @@ import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
+import com.cyngn.theme.chooser.R;
import com.cyngn.theme.util.Utils;
import java.io.File;
@@ -17,7 +18,7 @@ import java.io.File;
/**
* A custom TextView that always uses the Lato font
*/
-public class LatoTextView extends TextView {
+public class LatoTextView extends FittedTextView {
private static final int NUM_TYPEFACE_PER_FAMILY = 4;
private static final String FONT_ASSSET_DIR = "fonts";
@@ -135,6 +136,16 @@ public class LatoTextView extends TextView {
}
setTypefaceFromAttrs(fontFamily, styleIndex);
+ TypedArray styledAttrs = context.obtainStyledAttributes(attrs,
+ R.styleable.FittedTextView, 0, 0);
+ try {
+ //Although we extend FittedTextView, we don't want all instances to auto fit the
+ //text, so we check if autoFitText has been set in the attributes. Default to false
+ boolean fit = styledAttrs.getBoolean(R.styleable.FittedTextView_autoFitText, false);
+ setAutoFitText(fit);
+ } finally {
+ styledAttrs.recycle();
+ }
}
}