Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from schul-cloud/54-add-pt-sans
Browse files Browse the repository at this point in the history
add pt sans
  • Loading branch information
Langleu authored Jun 15, 2017
2 parents 6dccdf5 + a70ed22 commit 4835b1a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ android {
'src/main/res/layouts',
'src/main/res'
]
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}

Expand Down
Binary file added app/src/main/assets/fonts/ptsans.ttf
Binary file not shown.
Binary file added app/src/main/assets/fonts/ptsans_caption.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.schulcloud.mobile.injection.component.ApplicationComponent;
import org.schulcloud.mobile.injection.component.DaggerApplicationComponent;
import org.schulcloud.mobile.injection.module.ApplicationModule;
import org.schulcloud.mobile.util.TypefaceUtil;

import io.fabric.sdk.android.Fabric;
import timber.log.Timber;
Expand All @@ -28,6 +29,9 @@ public void onCreate() {
Timber.plant(new Timber.DebugTree());
Fabric.with(this, new Crashlytics());
}

// override font
TypefaceUtil.overrideFont(getApplicationContext(), "SERIF", "fonts/ptsans.ttf");
}

public ApplicationComponent getComponent() {
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/util/TypefaceUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.schulcloud.mobile.util;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

import java.lang.reflect.Field;

import timber.log.Timber;

public class TypefaceUtil {

/**
* Using reflection to override default typeface
* NOTICE: DO NOT FORGET TO SET TYPEFACE FOR APP THEME AS DEFAULT TYPEFACE WHICH WILL BE OVERRIDDEN
* @param context to work with assets
* @param defaultFontNameToOverride for example "monospace"
* @param customFontFileNameInAssets file name of the font from assets
*/
public static void overrideFont(Context context, String defaultFontNameToOverride, String customFontFileNameInAssets) {
try {
final Typeface customFontTypeface = Typeface.createFromAsset(context.getAssets(), customFontFileNameInAssets);

final Field defaultFontTypefaceField = Typeface.class.getDeclaredField(defaultFontNameToOverride);
defaultFontTypefaceField.setAccessible(true);
defaultFontTypefaceField.set(null, customFontTypeface);
} catch (Exception e) {
Timber.e("Can not set custom font " + customFontFileNameInAssets + " instead of " + defaultFontNameToOverride);
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary_dark</item>
<item name="android:typeface">serif</item>
<item name="drawerArrowStyle">@style/BarStyle</item>
</style>

Expand Down

0 comments on commit 4835b1a

Please sign in to comment.