-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
51 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
65 changes: 65 additions & 0 deletions
65
app/src/main/java/org/schabi/newpipe/util/FontManager.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,65 @@ | ||
package org.schabi.newpipe.util; | ||
|
||
// import android.content.Context; | ||
import com.marcinorlowski.fonty.Fonty.Companion.context; | ||
import android.content.SharedPreferences; | ||
import androidx.preference.PreferenceManager; | ||
import com.marcinorlowski.fonty.Fonty; | ||
|
||
|
||
public final class FontManager { | ||
private FontManager() { } | ||
|
||
public static void init(final Context context) { | ||
// Apply the preferred font globally | ||
final String preferredFont = getPreferredFont(context); | ||
|
||
setUpFont(preferredFont, context); | ||
} | ||
|
||
public String getPreferredFont(final Context context) { | ||
final SharedPreferences preferences = PreferenceManager | ||
.getDefaultSharedPreferences(context); | ||
return preferences.getString("preferred_font", getString(R.string.default_font_key)); | ||
} | ||
|
||
// build the relevant font TypeFace | ||
public static void setUpFont(final String preferredFont, final Context context) { | ||
switch (preferredFont) { | ||
case "Arial": | ||
Fonty.context(context) | ||
.normalTypeface("arial.ttf") | ||
.build(); | ||
break; | ||
case "Broadway": | ||
Fonty.context(context) | ||
.normalTypeface("BROADW.TTF") | ||
.build(); | ||
break; | ||
case "Algerian": | ||
Fonty.context(context) | ||
.normalTypeface("Algerian.TTF") | ||
.build(); | ||
break; | ||
case "Bell MT": | ||
Fonty.context(context) | ||
.normalTypeface("BELL.TTF") | ||
.build(); | ||
break; | ||
case "Calibri": | ||
Fonty.context(context) | ||
.normalTypeface("calibrii.ttf") | ||
.build(); | ||
break; | ||
case "Time New Roman": | ||
Fonty.context(context) | ||
.normalTypeface("times.ttf") | ||
.build(); | ||
break; | ||
default: | ||
// do nothing | ||
break; | ||
} | ||
|
||
} | ||
} |