34
34
import android .net .NetworkInfo ;
35
35
import android .net .NetworkRequest ;
36
36
import android .os .Bundle ;
37
+ import android .os .Handler ;
38
+ import android .os .HandlerThread ;
37
39
import android .support .annotation .Nullable ;
38
40
import android .support .v4 .content .ContextCompat ;
39
41
import android .support .v4 .content .LocalBroadcastManager ;
42
+ import android .support .v4 .provider .FontRequest ;
43
+ import android .support .v4 .provider .FontsContractCompat ;
40
44
import android .support .v4 .view .GravityCompat ;
41
45
import android .support .v4 .widget .DrawerLayout ;
42
46
import android .support .v7 .widget .GridLayoutManager ;
50
54
import android .text .style .ImageSpan ;
51
55
import android .text .style .StyleSpan ;
52
56
import android .transition .TransitionManager ;
57
+ import android .util .Log ;
53
58
import android .view .Menu ;
54
59
import android .view .MenuItem ;
55
60
import android .view .MotionEvent ;
97
102
98
103
public class HomeActivity extends Activity {
99
104
105
+ private static final String TAG = "PlaidHomeActivity" ;
106
+
100
107
private static final int RC_SEARCH = 0 ;
101
108
private static final int RC_AUTH_DRIBBBLE_FOLLOWING = 1 ;
102
109
private static final int RC_AUTH_DRIBBBLE_USER_LIKES = 2 ;
@@ -125,6 +132,9 @@ public class HomeActivity extends Activity {
125
132
private DesignerNewsPrefs designerNewsPrefs ;
126
133
private DribbblePrefs dribbblePrefs ;
127
134
135
+ // We'll need a thread to wait
136
+ private Handler fontHandler ;
137
+
128
138
@ Override
129
139
protected void onCreate (Bundle savedInstanceState ) {
130
140
super .onCreate (savedInstanceState );
@@ -141,6 +151,26 @@ protected void onCreate(Bundle savedInstanceState) {
141
151
}
142
152
setExitSharedElementCallback (FeedAdapter .createSharedElementReenterCallback (this ));
143
153
154
+ FontRequest fontRequest = new FontRequest ("com.google.android.gms.fonts" ,
155
+ "com.google.android.gms" ,
156
+ "name=Alegreya Sans SC&weight=700" ,
157
+ R .array .com_google_android_gms_fonts_certs );
158
+ FontsContractCompat .FontRequestCallback toolbarFontCallback =
159
+ new FontsContractCompat .FontRequestCallback () {
160
+ @ Override public void onTypefaceRetrieved (Typeface typeface ) {
161
+ // If we got our font apply it to the toolbar
162
+ styleToolbar (typeface );
163
+ }
164
+ @ Override public void onTypefaceRequestFailed (int reason ) {
165
+ Log .w (TAG , "Failed to fetch Toolbar font: " + reason );
166
+ }
167
+ };
168
+
169
+ // Start async fetch on the handler thread
170
+ FontsContractCompat .requestFont (this , fontRequest , toolbarFontCallback ,
171
+ getFontHandlerThread ());
172
+
173
+
144
174
dribbblePrefs = DribbblePrefs .get (this );
145
175
designerNewsPrefs = DesignerNewsPrefs .get (this );
146
176
filtersAdapter = new FilterAdapter (this , SourceManager .getSources (this ),
@@ -247,6 +277,8 @@ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
247
277
});
248
278
setupTaskDescription ();
249
279
280
+
281
+
250
282
filtersList .setAdapter (filtersAdapter );
251
283
filtersList .setItemAnimator (new FilterAdapter .FilterAnimator ());
252
284
filtersAdapter .registerFilterChangedCallback (filtersChangedCallbacks );
@@ -695,6 +727,28 @@ private void setupTaskDescription() {
695
727
overviewIcon .recycle ();
696
728
}
697
729
730
+ private void styleToolbar (Typeface typeface ) {
731
+ // this is gross but toolbar doesn't expose it's children
732
+ for (int i = 0 ; i < toolbar .getChildCount (); i ++) {
733
+ View rawView = toolbar .getChildAt (i );
734
+ if (!(rawView instanceof TextView )) {
735
+ continue ;
736
+ }
737
+
738
+ TextView textView = (TextView ) rawView ;
739
+ textView .setTypeface (typeface );
740
+ }
741
+ }
742
+
743
+ private Handler getFontHandlerThread () {
744
+ if (fontHandler == null ) {
745
+ HandlerThread handlerThread = new HandlerThread ("fonts" );
746
+ handlerThread .start ();
747
+ fontHandler = new Handler (handlerThread .getLooper ());
748
+ }
749
+ return fontHandler ;
750
+ }
751
+
698
752
private void animateToolbar () {
699
753
// this is gross but toolbar doesn't expose it's children to animate them :(
700
754
View t = toolbar .getChildAt (0 );
0 commit comments