-
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
65 additions
and
49 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
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import androidx.preference.PreferenceManager; | ||
import com.marcinorlowski.fonty.Fonty; | ||
|
||
|
||
public final class FontManager { | ||
private FontManager() { | ||
} | ||
|
||
public void init(final Context context) { | ||
// Apply the preferred font globally | ||
final String preferredFont = getPreferredFont(this); | ||
|
||
setUpFont(preferredFont); | ||
} | ||
|
||
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 void setUpFont(final String preferredFont) { | ||
switch (preferredFont) { | ||
case "Arial": | ||
Fonty.context(this) | ||
.normalTypeface("arial.ttf") | ||
.build(); | ||
break; | ||
case "Broadway": | ||
Fonty.context(this) | ||
.normalTypeface("BROADW.TTF") | ||
.build(); | ||
break; | ||
case "Algerian": | ||
Fonty.context(this) | ||
.normalTypeface("Algerian.TTF") | ||
.build(); | ||
break; | ||
case "Bell MT": | ||
Fonty.context(this) | ||
.normalTypeface("BELL.TTF") | ||
.build(); | ||
break; | ||
case "Calibri": | ||
Fonty.context(this) | ||
.normalTypeface("calibrii.ttf") | ||
.build(); | ||
break; | ||
case "Time New Roman": | ||
Fonty.context(this) | ||
.normalTypeface("times.ttf") | ||
.build(); | ||
break; | ||
default: | ||
// do nothing | ||
break; | ||
} | ||
|
||
} | ||
} |