diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/TextViewUtils.java b/QKSMS/src/main/java/com/moez/QKSMS/common/TextViewUtils.java deleted file mode 100644 index ae96ae1f..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/TextViewUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2014 Evgeny Shishkin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.moez.QKSMS.common; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.util.AttributeSet; -import android.widget.TextView; -import com.moez.QKSMS.R; - -/** - * Utilities for working with roboto text views. - * - * @author Evgeny Shishkin - */ -public class TextViewUtils { - - private TextViewUtils() { - } - - /** - * 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 - * access the current theme, resources, etc. - * @param attrs The attributes of the XML tag that is inflating the widget. - */ - public static void initTypeface(TextView textView, Context context, AttributeSet attrs) { - Typeface typeface = null; - - if (attrs != null) { - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView); - - if (a.hasValue(R.styleable.RobotoTextView_typeface)) { - int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, TypefaceManager.Typefaces.ROBOTO_REGULAR); - typeface = TypefaceManager.obtainTypeface(context, typefaceValue); - } - - a.recycle(); - } - - if (typeface == null) { - typeface = TypefaceManager.obtainTypeface(context, TypefaceManager.Typefaces.ROBOTO_REGULAR); - } - - setTypeface(textView, typeface); - } - - /** - * Setup typeface for TextView. Wrapper over {@link android.widget.TextView#setTypeface(android.graphics.Typeface)} - * for making the font anti-aliased. - * - * @param textView The text view - * @param typeface The specify typeface - */ - public static void setTypeface(TextView textView, Typeface typeface) { - textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); - textView.setTypeface(typeface); - } - - /** - * Setup typeface for Paint. - * - * @param paint The paint - * @param typeface The specify typeface - */ - public static void setTypeface(Paint paint, Typeface typeface) { - paint.setFlags(paint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); - paint.setTypeface(typeface); - } - -} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/RobotoTextView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/RobotoTextView.java index 742e568a..5230d5e2 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/RobotoTextView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/RobotoTextView.java @@ -1,9 +1,14 @@ package com.moez.QKSMS.ui.view; import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Paint; +import android.graphics.Typeface; import android.support.v7.widget.AppCompatTextView; import android.util.AttributeSet; -import com.moez.QKSMS.common.TextViewUtils; +import android.widget.TextView; +import com.moez.QKSMS.R; +import com.moez.QKSMS.common.TypefaceManager; public class RobotoTextView extends AppCompatTextView { @@ -15,7 +20,7 @@ public class RobotoTextView extends AppCompatTextView { super(context, attrs); if (!isInEditMode()) { - TextViewUtils.initTypeface(this, context, attrs); + initTypeface(this, context, attrs); } } @@ -23,8 +28,30 @@ public class RobotoTextView extends AppCompatTextView { super(context, attrs, defStyle); if (!isInEditMode()) { - TextViewUtils.initTypeface(this, context, attrs); + initTypeface(this, context, attrs); } } + private void initTypeface(TextView textView, Context context, AttributeSet attrs) { + Typeface typeface = null; + + if (attrs != null) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView); + + if (a.hasValue(R.styleable.RobotoTextView_typeface)) { + int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, TypefaceManager.Typefaces.ROBOTO_REGULAR); + typeface = TypefaceManager.obtainTypeface(context, typefaceValue); + } + + a.recycle(); + } + + if (typeface == null) { + typeface = TypefaceManager.obtainTypeface(context, TypefaceManager.Typefaces.ROBOTO_REGULAR); + } + + textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); + textView.setTypeface(typeface); + } + }