This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from schul-cloud/54-add-pt-sans
add pt sans
- Loading branch information
Showing
6 changed files
with
37 additions
and
0 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
Binary file not shown.
Binary file not shown.
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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/schulcloud/mobile/util/TypefaceUtil.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,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); | ||
} | ||
} | ||
} |
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