Add option to select Lato Font Family.

Adds the option to select Google's Lato Font family in QKSMS.
Changes RobotoTextViewUtils and RobotoTypefaceManager to be generic.
Changes font family options to reflect actual family. IE:
Regular -> Roboto Regular.

This translation is complete for most languages. Languages vastly
different from english will need some small changes in this area.
This commit is contained in:
Kyle Gospodnetich
2015-08-17 14:45:37 -07:00
committed by Moez Bhatti
parent ef333a6681
commit 64f253a91a
45 changed files with 182 additions and 70 deletions
@@ -121,12 +121,12 @@ public class FontManager {
}
// Otherwise, get the heavy font weight.
if (fontWeight == RobotoTypefaceManager.TextWeight.LIGHT) {
return RobotoTypefaceManager.TextWeight.NORMAL;
} else if (fontFamily == RobotoTypefaceManager.FontFamily.ROBOTO) {
return RobotoTypefaceManager.TextWeight.MEDIUM;
if (fontWeight == TypefaceManager.TextWeight.LIGHT) {
return TypefaceManager.TextWeight.NORMAL;
} else if (fontFamily == TypefaceManager.FontFamily.ROBOTO || fontFamily == TypefaceManager.FontFamily.LATO) {
return TypefaceManager.TextWeight.MEDIUM;
} else {
return RobotoTypefaceManager.TextWeight.BOLD;
return TypefaceManager.TextWeight.BOLD;
}
}
}
@@ -29,13 +29,13 @@ import com.moez.QKSMS.R;
*
* @author Evgeny Shishkin
*/
public class RobotoTextViewUtils {
public class TextViewUtils {
private RobotoTextViewUtils() {
private TextViewUtils() {
}
/**
* Typeface initialization using the attributes. Used in RobotoTextView constructor.
* Typeface initialization using the attributes. Used in TextView constructor.
*
* @param textView The roboto text view
* @param context The context the widget is running in, through which it can
@@ -49,15 +49,15 @@ public class RobotoTextViewUtils {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView);
if (a.hasValue(R.styleable.RobotoTextView_typeface)) {
int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, RobotoTypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = RobotoTypefaceManager.obtainTypeface(context, typefaceValue);
int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, TypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = TypefaceManager.obtainTypeface(context, typefaceValue);
}
a.recycle();
}
if (typeface == null) {
typeface = RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_REGULAR);
}
setTypeface(textView, typeface);
@@ -6,7 +6,7 @@ import android.util.SparseArray;
/**
* Stripped down version of https://github.com/johnkil/Android-RobotoTextView/blob/master/robototextview/src/main/java/com/devspark/robototextview/util/RobotoTypefaceManager.java
*/
public class RobotoTypefaceManager {
public class TypefaceManager {
private final static SparseArray<android.graphics.Typeface> mTypefaces = new SparseArray<>();
@@ -113,6 +113,58 @@ public class RobotoTypefaceManager {
throw new IllegalArgumentException("`textWeight` attribute value " + textWeight +
" is not supported for this font family " + fontFamily);
}
} else if (fontFamily == FontFamily.LATO) {
if (textWeight == TextWeight.NORMAL) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_REGULAR;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.THIN) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_THIN;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.LIGHT) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_LIGHT;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.MEDIUM) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_MEDIUM;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.BOLD) {
switch (textStyle) {
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else {
throw new IllegalArgumentException("`textWeight` attribute value " + textWeight +
" is not supported for this font family " + fontFamily);
}
} else {
throw new IllegalArgumentException("Unknown `fontFamily` attribute value " + fontFamily);
}
@@ -143,6 +195,18 @@ public class RobotoTypefaceManager {
case Typeface.ROBOTO_CONDENSED_BOLD:
typefacePath = "fonts/RobotoCondensed-Bold.ttf";
break;
case Typeface.LATO_THIN:
typefacePath = "fonts/Lato-Hairline.ttf";
break;
case Typeface.LATO_LIGHT:
typefacePath = "fonts/Lato-Light.ttf";
break;
case Typeface.LATO_REGULAR:
typefacePath = "fonts/Lato-Regular.ttf";
break;
case Typeface.LATO_MEDIUM:
typefacePath = "fonts/Lato-Bold.ttf";
break;
default:
throw new IllegalArgumentException("Unknown `typeface` attribute value " + typefaceValue);
}
@@ -158,11 +222,16 @@ public class RobotoTypefaceManager {
public final static int ROBOTO_CONDENSED_LIGHT = 12;
public final static int ROBOTO_CONDENSED_REGULAR = 14;
public final static int ROBOTO_CONDENSED_BOLD = 16;
public final static int LATO_THIN = 22;
public final static int LATO_LIGHT = 24;
public final static int LATO_REGULAR = 26;
public final static int LATO_MEDIUM = 28;
}
public class FontFamily {
public static final int ROBOTO = 0;
public static final int ROBOTO_CONDENSED = 1;
public static final int LATO = 2;
}
public class TextWeight {
@@ -17,7 +17,7 @@ import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.Units;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
@@ -205,7 +205,7 @@ public class ContactHelper {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTypeface(RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_LIGHT));
paint.setTypeface(TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_LIGHT));
paint.setTextSize(length / 2);
Rect bounds = new Rect();
@@ -10,7 +10,7 @@ import com.android.ex.chips.RecipientEditTextView;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;
@@ -57,8 +57,8 @@ public class AutoCompleteContactView extends RecipientEditTextView implements Li
@Override
public void refresh() {
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, FontManager.getFontFamily(mContext),
FontManager.getFontWeight(mContext, false), RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, FontManager.getFontFamily(mContext),
FontManager.getFontWeight(mContext, false), TypefaceManager.TextStyle.NORMAL));
setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY));
setTextColor(ThemeManager.getTextOnBackgroundPrimary());
@@ -24,7 +24,7 @@ import android.widget.ImageView;
import com.moez.QKSMS.R;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.ImageUtils;
import com.moez.QKSMS.common.utils.PhoneNumberUtils;
import com.moez.QKSMS.common.utils.Units;
@@ -77,7 +77,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
mPaint.setTextSize(Units.dpToPx(context, 32));
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setAntiAlias(true);
mPaint.setTypeface(RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_LIGHT));
mPaint.setTypeface(TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_LIGHT));
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AvatarView, defStyle, 0);
for (int i = 0; i < a.getIndexCount(); i++) {
@@ -11,7 +11,7 @@ import android.util.TypedValue;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;
@@ -97,8 +97,8 @@ public class QKEditText extends android.widget.EditText implements LiveView {
// Typeface and colors
int fontFamily = FontManager.getFontFamily(mContext);
int fontWeight = FontManager.getFontWeight(mContext, false);
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
TypefaceManager.TextStyle.NORMAL));
setTextColor(ThemeManager.getTextOnBackgroundPrimary());
setHintTextColor(ThemeManager.getTextOnBackgroundSecondary());
@@ -11,7 +11,7 @@ import android.widget.TextView;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.MessageUtils;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
@@ -162,8 +162,8 @@ public class QKTextView extends TextView implements LiveView {
// Typeface
int fontFamily = FontManager.getFontFamily(mContext);
int fontWeight = FontManager.getFontWeight(mContext, FontManager.getIsFontHeavy(mType));
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
TypefaceManager.TextStyle.NORMAL));
// Text size and color
setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, mType));
@@ -3,7 +3,7 @@ package com.moez.QKSMS.ui.view;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import com.moez.QKSMS.common.RobotoTextViewUtils;
import com.moez.QKSMS.common.TextViewUtils;
public class RobotoTextView extends AppCompatTextView {
@@ -15,7 +15,7 @@ public class RobotoTextView extends AppCompatTextView {
super(context, attrs);
if (!isInEditMode()) {
RobotoTextViewUtils.initTypeface(this, context, attrs);
TextViewUtils.initTypeface(this, context, attrs);
}
}
@@ -23,7 +23,7 @@ public class RobotoTextView extends AppCompatTextView {
super(context, attrs, defStyle);
if (!isInEditMode()) {
RobotoTextViewUtils.initTypeface(this, context, attrs);
TextViewUtils.initTypeface(this, context, attrs);
}
}