From 5373405e28da1d90eadc2c8ae870050cec6c03b3 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 13 Nov 2013 11:01:09 +0100 Subject: [PATCH] Removing the unnecessary dependency. --- SecretCodes/project.properties | 3 +- SecretCodes/res/layout/activity_main.xml | 2 +- SecretCodes/res/layout/dialog_about.xml | 4 +- SecretCodes/res/layout/row_code.xml | 7 +- SecretCodes/res/values/attrs.xml | 88 ++++++++++++ .../secretcodes/roboto/RobotoTextView.java | 58 ++++++++ .../roboto/RobotoTypefaceManager.java | 125 ++++++++++++++++++ .../simon/marquis/secretcodes/util/Utils.java | 4 +- 8 files changed, 280 insertions(+), 11 deletions(-) create mode 100644 SecretCodes/res/values/attrs.xml create mode 100644 SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTextView.java create mode 100644 SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTypefaceManager.java diff --git a/SecretCodes/project.properties b/SecretCodes/project.properties index 5712332..b49129f 100644 --- a/SecretCodes/project.properties +++ b/SecretCodes/project.properties @@ -12,5 +12,4 @@ # Project target. target=android-19 -android.library.reference.1=../../../../../adt-bundle-windows/sdk/extras/android/support/v7/appcompat -android.library.reference.2=../../Roboto +android.library.reference.1=..\\..\\..\\..\\..\\adt-bundle-windows\\sdk\\extras\\android\\support\\v7\\appcompat diff --git a/SecretCodes/res/layout/activity_main.xml b/SecretCodes/res/layout/activity_main.xml index f84a6af..69385ca 100644 --- a/SecretCodes/res/layout/activity_main.xml +++ b/SecretCodes/res/layout/activity_main.xml @@ -55,7 +55,7 @@ android:alpha="0.3" android:src="@drawable/ic_empty_view" /> - - - + limitations under the License. +--> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTextView.java b/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTextView.java new file mode 100644 index 0000000..335e9b5 --- /dev/null +++ b/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTextView.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 Simon Marquis (http://www.simon-marquis.fr) + * + * 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 fr.simon.marquis.secretcodes.roboto; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.widget.TextView; +import fr.simon.marquis.secretcodes.R; + +public class RobotoTextView extends TextView { + + public RobotoTextView(Context context) { + super(context); + onInitTypeface(context, null, 0); + } + + public RobotoTextView(Context context, AttributeSet attrs) { + super(context, attrs); + onInitTypeface(context, attrs, 0); + } + + public RobotoTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + onInitTypeface(context, attrs, defStyle); + } + + private void onInitTypeface(Context context, AttributeSet attrs, int defStyle) { + if (isInEditMode()) { + return; + } + + int typefaceValue = 0; + if (attrs != null) { + TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView, defStyle, 0); + typefaceValue = values.getInt(R.styleable.RobotoTextView_typeface, 0); + values.recycle(); + } + + Typeface robotoTypeface = RobotoTypefaceManager.obtaintTypeface(context, typefaceValue); + setTypeface(robotoTypeface); + } + +} diff --git a/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTypefaceManager.java b/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTypefaceManager.java new file mode 100644 index 0000000..48998c1 --- /dev/null +++ b/SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTypefaceManager.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2013 Simon Marquis (http://www.simon-marquis.fr) + * + * 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 fr.simon.marquis.secretcodes.roboto; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.SparseArray; + +public class RobotoTypefaceManager { + + public final static int ROBOTO_THIN = 0; + public final static int ROBOTO_THIN_ITALIC = 1; + public final static int ROBOTO_LIGHT = 2; + public final static int ROBOTO_LIGHT_ITALIC = 3; + public final static int ROBOTO_REGULAR = 4; + public final static int ROBOTO_ITALIC = 5; + public final static int ROBOTO_MEDIUM = 6; + public final static int ROBOTO_MEDIUM_ITALIC = 7; + public final static int ROBOTO_BOLD = 8; + public final static int ROBOTO_BOLD_ITALIC = 9; + public final static int ROBOTO_BLACK = 10; + public final static int ROBOTO_BLACK_ITALIC = 11; + public final static int ROBOTO_CONDENSED = 12; + public final static int ROBOTO_CONDENSED_ITALIC = 13; + public final static int ROBOTO_CONDENSED_BOLD = 14; + public final static int ROBOTO_CONDENSED_BOLD_ITALIC = 15; + public final static int ROBOTOSLAB_THIN = 16; + public final static int ROBOTOSLAB_LIGHT = 17; + public final static int ROBOTOSLAB_REGULAR = 18; + public final static int ROBOTOSLAB_BOLD = 19; + + private final static SparseArray mTypefaces = new SparseArray(20); + + public static Typeface obtaintTypeface(Context context, int typefaceValue) throws IllegalArgumentException { + Typeface typeface = mTypefaces.get(typefaceValue); + if (typeface == null) { + typeface = createTypeface(context, typefaceValue); + mTypefaces.put(typefaceValue, typeface); + } + return typeface; + } + + private static Typeface createTypeface(Context context, int typefaceValue) throws IllegalArgumentException { + Typeface typeface; + switch (typefaceValue) { + case ROBOTO_THIN: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Thin.ttf"); + break; + case ROBOTO_THIN_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-ThinItalic.ttf"); + break; + case ROBOTO_LIGHT: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf"); + break; + case ROBOTO_LIGHT_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-LightItalic.ttf"); + break; + case ROBOTO_REGULAR: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf"); + break; + case ROBOTO_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Italic.ttf"); + break; + case ROBOTO_MEDIUM: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); + break; + case ROBOTO_MEDIUM_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-MediumItalic.ttf"); + break; + case ROBOTO_BOLD: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); + break; + case ROBOTO_BOLD_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldItalic.ttf"); + break; + case ROBOTO_BLACK: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf"); + break; + case ROBOTO_BLACK_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BlackItalic.ttf"); + break; + case ROBOTO_CONDENSED: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Condensed.ttf"); + break; + case ROBOTO_CONDENSED_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-CondensedItalic.ttf"); + break; + case ROBOTO_CONDENSED_BOLD: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldCondensed.ttf"); + break; + case ROBOTO_CONDENSED_BOLD_ITALIC: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldCondensedItalic.ttf"); + break; + case ROBOTOSLAB_THIN: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Thin.ttf"); + break; + case ROBOTOSLAB_LIGHT: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Light.ttf"); + break; + case ROBOTOSLAB_REGULAR: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Regular.ttf"); + break; + case ROBOTOSLAB_BOLD: + typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Bold.ttf"); + break; + default: + throw new IllegalArgumentException("Unknown `typeface` attribute value " + typefaceValue); + } + return typeface; + } + +} diff --git a/SecretCodes/src/fr/simon/marquis/secretcodes/util/Utils.java b/SecretCodes/src/fr/simon/marquis/secretcodes/util/Utils.java index 84c199e..045ee63 100644 --- a/SecretCodes/src/fr/simon/marquis/secretcodes/util/Utils.java +++ b/SecretCodes/src/fr/simon/marquis/secretcodes/util/Utils.java @@ -34,10 +34,8 @@ import android.text.Spannable; import android.text.SpannableString; import android.util.Log; - -import com.roboto.RobotoTypefaceManager; - import fr.simon.marquis.secretcodes.model.SecretCode; +import fr.simon.marquis.secretcodes.roboto.RobotoTypefaceManager; public class Utils {