Skip to content
elihart edited this page Mar 21, 2013 · 5 revisions

Overview

This class provides a dialog to choose a font. All fonts available on the device will be detected and displayed as a list. We can bundle more TTF files to allow the user to choose from a wider variety of fonts.

The dialog was built with inspiration from the FontPreference class made by George Yunaev under Apache 2.0 and found at

http://www.ulduzsoft.com/2012/01/fontpreference-dialog-for-android/

The font picker is built on the FontManager class that searches the phone for available fonts, and returns their names and pathnames in a hashmap.

http://www.ulduzsoft.com/2012/01/enumerating-the-fonts-on-android-platform/

Use this class by calling

`FontPickerDialog dlg = new FontPickerDialog(); dlg.show(getFragmentManager(), "font_picker");`

"font_picker" can be any text. It simply names the fragment in case you need to access it later

Features

The FontPickerDialog extends DialogFragment. It defines an interface for a FontPickerDialogListener. To use this dialog you must implement FontPickerDialog.FontPickerDialogListener which defines the method onFontSelected(FontPickerDialog dialog).

This callback function returns the dialog object after the user has selected a font. You can call getSelectedFont() on the dialog object to obtain the file path of the font that was selected.

The dialog is arranged as a listview. Each font that the FontManager finds on the phone is represented as a textview, with the text being the name of the font, and written in the style of the font itself.

Users can scroll through the list, and select a font by clicking on an option. On click the dialog is closed and the choice is returned to the caller.

There is a cancel button available if the user chooses not to use one of the fonts.

Bugs

Planned Features

  1. Bundle TTF fonts to allow for better font variety.
  2. Improve the layout of the dialog.
Clone this wiki locally