Skip to content

Commit b98f5b8

Browse files
committed
Added
MultiFontTextClock
1 parent e27779c commit b98f5b8

File tree

20 files changed

+259
-2
lines changed

20 files changed

+259
-2
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "26.0.1"
66
defaultConfig {
77
applicationId "fyi.multifontview"
8-
minSdkVersion 16
8+
minSdkVersion 17
99
targetSdkVersion 26
1010
versionCode 1
1111
versionName "1.0"
@@ -33,4 +33,5 @@ dependencies {
3333
compile project(':multifontswitch')
3434
compile project(':multifontradiobutton')
3535
compile project(':multifontcheckbox')
36+
compile project(':multifonttextclock')
3637
}

app/src/main/assets/fonts/Carre.ttf

5.88 KB
Binary file not shown.

app/src/main/assets/fonts/Crasns.ttf

16.4 KB
Binary file not shown.

app/src/main/assets/fonts/KGTF.ttf

34.5 KB
Binary file not shown.

app/src/main/res/layout/activity_main.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,37 @@
218218
app:layout_constraintTop_toTopOf="parent"
219219
app:layout_constraintVertical_bias="0.529" />
220220

221+
<fyi.library.multifonttextclock.MultiFontTextClock
222+
android:layout_width="wrap_content"
223+
android:layout_height="wrap_content"
224+
android:layout_marginBottom="8dp"
225+
android:layout_marginLeft="8dp"
226+
android:layout_marginRight="8dp"
227+
android:layout_marginTop="8dp"
228+
app:layout_constraintBottom_toBottomOf="parent"
229+
app:layout_constraintHorizontal_bias="0.087"
230+
app:layout_constraintLeft_toLeftOf="parent"
231+
app:layout_constraintRight_toRightOf="parent"
232+
app:layout_constraintTop_toTopOf="parent"
233+
app:layout_constraintVertical_bias="0.65"
234+
android:format12Hour="h:mm:ss a"
235+
app:typeface_from_list="Crasns.ttf"/>
236+
237+
<fyi.library.multifonttextclock.MultiFontTextClock
238+
android:id="@+id/multiFontTextClock"
239+
android:layout_width="wrap_content"
240+
android:layout_height="wrap_content"
241+
android:layout_marginBottom="8dp"
242+
android:layout_marginLeft="8dp"
243+
android:layout_marginRight="8dp"
244+
android:layout_marginTop="8dp"
245+
app:layout_constraintBottom_toBottomOf="parent"
246+
app:layout_constraintHorizontal_bias="0.816"
247+
app:layout_constraintLeft_toLeftOf="parent"
248+
app:layout_constraintRight_toRightOf="parent"
249+
app:layout_constraintTop_toTopOf="parent"
250+
app:layout_constraintVertical_bias="0.529"
251+
app:typeface_from_list="Carre.ttf" />
252+
253+
221254
</android.support.constraint.ConstraintLayout>

app/src/main/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<enum name="Respective_Slanted.ttf" value="2" />
88
<enum name="Shine.ttf" value="3" />
99
<enum name="SweetSensations.ttf" value="4" />
10+
<enum name="Crasns.ttf" value="5" />
11+
<enum name="Carre.ttf" value="6" />
12+
<enum name="KGTF.ttf" value="7" />
1013
</attr>
1114
<declare-styleable name="MultiFontTextView">
1215
<attr name="typeface_from_list" />

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
<item>Respective_Slanted.ttf</item>
1313
<item>Shine.ttf</item>
1414
<item>SweetSensations.ttf</item>
15+
<item>Crasns.ttf</item>
16+
<item>Carre.ttf</item>
17+
<item>KGTF.ttf</item>
1518
</string-array>
1619
</resources>

multifonttextclock/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

multifonttextclock/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'com.github.dcendents.android-maven'
3+
group = 'com.github.shashkiranr'
4+
5+
android {
6+
compileSdkVersion 26
7+
buildToolsVersion "26.0.1"
8+
9+
defaultConfig {
10+
minSdkVersion 17
11+
targetSdkVersion 26
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29+
exclude group: 'com.android.support', module: 'support-annotations'
30+
})
31+
compile 'com.android.support:appcompat-v7:26.+'
32+
testCompile 'junit:junit:4.12'
33+
}

multifonttextclock/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/shashi/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package fyi.library.multifonttextclock;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("fyi.library.multifonttextclock.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
package="fyi.library.multifonttextclock">
4+
5+
<application android:allowBackup="true" android:label="@string/app_name"
6+
android:supportsRtl="true">
7+
8+
</application>
9+
10+
</manifest>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fyi.library.multifonttextclock;
2+
3+
4+
import android.content.Context;
5+
import android.graphics.Typeface;
6+
7+
import java.util.HashMap;
8+
9+
/*
10+
This font loader class is obtained from Future Studio - "Custom Fonts on Android — Extending TextView"
11+
for more info please visit https://futurestud.io
12+
*
13+
* */
14+
public class FontLoader {
15+
private static HashMap<String, Typeface> fontMapCache = new HashMap<>();
16+
17+
public static Typeface getTypeface(Context context, String fontname) {
18+
Typeface typeface = fontMapCache.get(fontname);
19+
20+
if (typeface == null) {
21+
try {
22+
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + fontname);
23+
} catch (Exception e) {
24+
return null;
25+
}
26+
27+
fontMapCache.put(fontname, typeface);
28+
}
29+
30+
return typeface;
31+
}
32+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package fyi.library.multifonttextclock;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.graphics.Typeface;
6+
import android.util.AttributeSet;
7+
import android.util.Log;
8+
import android.widget.TextClock;
9+
10+
11+
public class MultiFontTextClock extends TextClock {
12+
13+
private static final String LOG_TAG = "MultiFontTextClock";
14+
15+
public MultiFontTextClock(Context context) {
16+
super(context);
17+
}
18+
19+
public MultiFontTextClock(Context context, AttributeSet attrs) {
20+
super(context, attrs);
21+
initializeCustomTypeface(attrs, context);
22+
}
23+
24+
public MultiFontTextClock(Context context, AttributeSet attrs, int defStyleAttr) {
25+
super(context, attrs, defStyleAttr);
26+
initializeCustomTypeface(attrs, context);
27+
}
28+
29+
private void initializeCustomTypeface(AttributeSet attrs, Context context) {
30+
if (attrs != null) {
31+
32+
TypedArray attributesArray = context.obtainStyledAttributes(attrs,
33+
R.styleable.MultiFontTextClock);
34+
int fontID = attributesArray.getInt(R.styleable.MultiFontTextClock_typeface_from_list, -1);
35+
String[] fontStringArray = context.getResources().getStringArray(R.array.customFonts);
36+
37+
//if a typeface is selected for the TextClock and if the font names are declared in the
38+
// string array customFonts then load that typeface from cache
39+
if ((fontID != -1) && (fontStringArray.length != 0)) {
40+
try {
41+
Typeface myTypeface = FontLoader.getTypeface(context, fontStringArray[fontID]);
42+
setTypeface(myTypeface);
43+
} catch (Exception e) {
44+
e.printStackTrace();
45+
}
46+
} else {
47+
Log.e(LOG_TAG, "Either of the string array CustomFonts or" +
48+
" attribute typeface_from_list is not present" + fontID);
49+
}
50+
attributesArray.recycle();
51+
}
52+
53+
}
54+
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<attr name="typeface_from_list">
5+
6+
</attr>
7+
<declare-styleable name="MultiFontTextClock">
8+
<attr name="typeface_from_list" />
9+
</declare-styleable>
10+
</resources>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<string name="app_name">multifonttextclock</string>
3+
<string-array name="customFonts">
4+
5+
</string-array>
6+
</resources>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fyi.library.multifonttextclock;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() throws Exception {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':multifonttextview', ':multifontbutton', ':multifontedittext', ':multifontswitch', ':multifontradiobutton', ':multifontcheckbox'
1+
include ':app', ':multifonttextview', ':multifontbutton', ':multifontedittext', ':multifontswitch', ':multifontradiobutton', ':multifontcheckbox', ':multifonttextclock'

0 commit comments

Comments
 (0)