This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing the unnecessary dependency.
- Loading branch information
1 parent
e74e6fb
commit 5373405
Showing
8 changed files
with
280 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
58 changes: 58 additions & 0 deletions
58
SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTextView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
125 changes: 125 additions & 0 deletions
125
SecretCodes/src/fr/simon/marquis/secretcodes/roboto/RobotoTypefaceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters