typeface

17
Typeface @KeithYokoma - Drivemode, Inc. potatotips #9

Upload: keishin-yokomaku

Post on 06-Aug-2015

28 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Typeface

Typeface@KeithYokoma - Drivemode, Inc.

potatotips #9

Page 2: Typeface

About myself• KeithYokoma

• Keishin Yokomaku

• Drivemode, Inc.

• GitHub: https://github.com/KeithYokoma

• e-Book: http://amzn.to/1mZNydv

2

Page 3: Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

Typeface

TypefaceTypeface Typeface Typeface

Typeface Typeface Typeface

3

Page 4: Typeface

4 http://bit.ly/1rjOdtN

Page 5: Typeface

Typeface• Cool

• Nice

• Beautiful

• Android provides Roboto by default

5

Page 6: Typeface

Typeface• If you would like to change the typeface…

TextView#setTypeface(Typeface)

Paint#setTypeface(Typeface)

Button#setTypeface(Typeface)

EditText#setTypeface(Typeface)

6

Page 7: Typeface

Typeface• Read Typeface from your assets

Typeface.createFromAsset(AssetManager, String)

7

Page 8: Typeface

Typeface• Read Typeface from your assets

!

• Caution!

Typeface.createFromAsset(AssetManager, String)

Typeface.createFromAsset leaks asset stream!http://bit.ly/1rVOkir

8

Page 9: Typeface

Typeface• Workaround: cache

private final Hashtable<String, Typeface> mCache = new Hashtable<String, Typeface>();!private final Application mApplication;!!public synchronized Typeface get(String name) {!! Typeface typeface = mCache.get(name);!! if(typeface == null) {!! ! try {!! ! ! typeface = Typeface.createFromAsset(mApplication.getAssets(), name);!! ! } catch (Exception exp) {!! ! ! return null;!! ! }!! ! mCache.put(name, typeface);!! }!! return typeface;!}

9

Page 10: Typeface

Typeface• If you would like to change the typeface for

ActionBar title

Dialog button texts

Dialog message text

ActionBar tab text

All text views in the view group

blah blah blah…

10

Page 11: Typeface

Typeface• Got it, we introduce you our library!

TypefaceHelper - http://bit.ly/1AxfqLz

11

Page 12: Typeface

Typeface• First, initialize the object in your Application.

public class SampleApp extends Application {!! @Override!! public void onCreate() {!! ! super.onCreate();!! ! TypefaceHelper.initialize(this);!! }!!! @Override!! public void onTerminate() {!! ! TypefaceHelper.destroy();!! ! super.onTerminate();!! }!}

12

Page 13: Typeface

Typeface• Set your Typeface.

public class SampleActivity extends Activity {!!! TextView mTextView;!!! @Override!! public void onCreate(Bundle icicle) {!! ! // …!! ! TypefaceHelper helper = TypefaceHelper.getInstance();!! ! helper.setTypeface(this, “MyFont.ttf”);!! ! helper.setTypeface(mTextView, “Another.ttf”);!! }!}

13

Page 14: Typeface

Typeface• That's it. Just do it!

14

Page 15: Typeface

Typeface• You can set your Typeface to…

• All views that is a child of TextView.

• All TextViews that is belong to ViewGroup.

• Activity, Fragment, Dialog.

• Canvas(thanks to Nohana team!)

15

Page 16: Typeface

Typeface• Works in progress

1. OptionsMenu

2. Preferences

3. Set typeface by annotation

16

Page 17: Typeface

Typeface@KeithYokoma - Drivemode, Inc.

potatotips #9