Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Removing the unnecessary dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMarquis committed Nov 13, 2013
1 parent e74e6fb commit 5373405
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 11 deletions.
3 changes: 1 addition & 2 deletions SecretCodes/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion SecretCodes/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:alpha="0.3"
android:src="@drawable/ic_empty_view" />

<com.roboto.RobotoTextView
<fr.simon.marquis.secretcodes.roboto.RobotoTextView
android:id="@+id/emptyViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions SecretCodes/res/layout/dialog_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:orientation="vertical"
android:showDividers="middle" >

<com.roboto.RobotoTextView
<fr.simon.marquis.secretcodes.roboto.RobotoTextView
android:id="@+id/app_name_and_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -40,7 +40,7 @@
android:layout_height="0dp"
android:layout_weight="1" >

<com.roboto.RobotoTextView
<fr.simon.marquis.secretcodes.roboto.RobotoTextView
android:id="@+id/about_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
7 changes: 4 additions & 3 deletions SecretCodes/res/layout/row_code.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
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.-->
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_background"
Expand Down Expand Up @@ -47,7 +48,7 @@
android:layout_toRightOf="@id/item_image"
android:orientation="vertical" >

<com.roboto.RobotoTextView
<fr.simon.marquis.secretcodes.roboto.RobotoTextView
android:id="@+id/item_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -57,7 +58,7 @@
android:textAppearance="?android:attr/textAppearanceMedium"
app:typeface="robotoslab_regular" />

<com.roboto.RobotoTextView
<fr.simon.marquis.secretcodes.roboto.RobotoTextView
android:id="@+id/item_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
88 changes: 88 additions & 0 deletions SecretCodes/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<resources>

<declare-styleable name="RobotoTextView">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoAutoCompleteTextView">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoButton">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoCheckBox">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoCheckedTextView">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoChronometer">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoCompoundButton">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoDigitalClock">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoEditText">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoExtractEditText">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoMultiAutoCompleteTextView">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoRadioButton">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoSwitch">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoTextClock">
<attr name="typeface" />
</declare-styleable>
<declare-styleable name="RobotoToggleButton">
<attr name="typeface" />
</declare-styleable>

<attr name="typeface" format="enum">
<enum name="roboto_thin" value="0" />
<enum name="roboto_thin_italic" value="1" />
<enum name="roboto_light" value="2" />
<enum name="roboto_light_italic" value="3" />
<enum name="roboto_regular" value="4" />
<enum name="roboto_italic" value="5" />
<enum name="roboto_medium" value="6" />
<enum name="roboto_medium_italic" value="7" />
<enum name="roboto_bold" value="8" />
<enum name="roboto_bold_italic" value="9" />
<enum name="roboto_black" value="10" />
<enum name="roboto_black_italic" value="11" />
<enum name="roboto_condensed" value="12" />
<enum name="roboto_condensed_italic" value="13" />
<enum name="roboto_condensed_bold" value="14" />
<enum name="roboto_condensed_bold_italic" value="15" />
<enum name="robotoslab_thin" value="16" />
<enum name="robotoslab_light" value="17" />
<enum name="robotoslab_regular" value="18" />
<enum name="robotoslab_bold" value="19" />
</attr>

</resources>
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Typeface> mTypefaces = new SparseArray<Typeface>(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;
}

}
4 changes: 1 addition & 3 deletions SecretCodes/src/fr/simon/marquis/secretcodes/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 5373405

Please sign in to comment.