Profile

Cover photo
Fahad Ayaz
Works at GDG Birmingham
Attended University of Bradford
Lives in Birmingham, UK
1,258 followers|936,636 views
AboutPostsPhotosYouTube

Stream

Fahad Ayaz

Shared publicly  - 
 
 
Preferences Support Library: Preference Fragments for API 7+, no matter the Activity
Pro-tip by +Ian Lake

Creating your preferences from XML files means less code and a consistent user experience across apps. However, this required that you use PreferenceActivity and even then you could only use PreferenceFragment on API 11+ devices. Well, no more: the Preferences Support v7 Library (http://goo.gl/BPE0M1) makes it possible to use any Activity class (such as an AppCompatActivity) with PreferenceFragmentCompat (http://goo.gl/kKXszC) and add preferences using the same preference XML files (http://goo.gl/wOcIxI), while adding support for elements such as SwitchPreference (previously only available on API 14+ devices) to all API 7+ devices.

A simple implementation would include a PreferenceFragmentCompat such as:
public class PreferencesFragment extends PreferenceFragmentCompat {
 @Override
  public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);
  }
}

You’ll also need to set preferenceTheme in your theme:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
  <!-- Set colorPrimary, colorPrimaryDark, colorAccent, etc →
  <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

Customizing the preferenceTheme allows for increased control over the styling and layouts used for each preference type without affecting other parts of your Activity.

Even better, PreferenceFragmentCompat uses RecyclerView for showing the list of preferences, allowing you to integrate scrolling techniques (http://goo.gl/119brU) with the help of the Android Design Support Library (http://goo.gl/8LN2Aj).

One thing you’ll note isn’t in here is preference headers and you’d be totally right. However, that doesn’t mean a single list of preferences need to span a 10” tablet screen. Instead, your Activity can implement OnPreferenceStartFragmentCallback (http://goo.gl/IZWZBP) to handle preferences with an app:fragment attribute or OnPreferenceStartScreenCallback (http://goo.gl/CFp5Cr) to handle PreferenceScreen preferences. This allows you to construct a ‘header’ style PreferenceFragmentCompat in one pane and use those callbacks to replace a second pane without working in two separate types of XML files.

So what about the preferences-v14 library? You’ll find it offers the same API as the preferences-v7 library, but built on framework Fragments and DialogFragments.

If you’re building apps for Android TV, you’ll find the preference-v17 library (http://goo.gl/i2A1zF) incredibly helpful - providing an optimized Leanback version of preferences via LeanbackPreferenceFragment (http://goo.gl/eLqNEv) built on top of these preference APIs.

#BuildBetterApps
32 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
Hey Dude, I don't think that's the way it's done.
10 comments on original post
2
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
Could it really be as easy as turning on a "switch"?
Scientists have turned cancerous cells back to normal by switching back on the process which stops normal cells from replicating too quickly
7 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
Google Chrome will now defer playback of autoplay media until the tab is foregrounded in the latest Dev Channel. This means no more "Where's that sound coming from?" moments when an ad for instance decides to autoplay in a tab you've specifically opened in the background.

Resources will still be preloaded if indicated but Chrome will delay the start of playback until you actually visit the tab.

This cool feature prevents obviously user annoyance but also conserves power as Chrome will only consume power once the tab is foregrounded.

Source: https://codereview.chromium.org/1292433002/
49 comments on original post
3
Mujeeb Rehman's profile photo
 
Hey whats thz , i havent understand.
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
While I can verify the truthfulness of the Australian epic level of national trolling (💜 +Paul Snedden​), the phrase "well I'm not here to fuck spiders" is pretty brilliant.

#ViaMK
84 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
Cool! (via +Sylvain Aimoz )
1
Add a comment...
Have him in circles
1,258 people
Hamza Lechhb's profile photo
Chida Sadayappan's profile photo
elvin de guzman's profile photo
Aaron Offei Nyarko's profile photo
Said Dldel's profile photo
Timothy Jeter's profile photo
Andrey Yurchenko's profile photo
Danilo Jfa's profile photo
Raghd Hamzeh's profile photo

Fahad Ayaz

Shared publicly  - 
 
 
Oh cat. Look before you leap. That didn't go to plan.
11 comments on original post
2
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
There are a lot of pre-defined shortcuts in Android Studio, including for layout files! "lh" and "lw" will pre-fill layout_height and layout_width attributes, respectively. #AndroidDev  
7 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
2
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
Android M upgrade tip: Since many libraries (most notably Google Play Services) use Apache HTTP, you may need this.
13 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
There's been many, many discussion threads about the introduction of Splash Screens to Google design guidelines. Almost in all of the discussions the same arguments for splash screens pop up.

I decided to put my responses to the common arguments in form of a blog post.
For some unfathomable reason Google decided to add Splash Screens to their design guidelines. While they now call it a "Launch screen" it's the same thing. A screen that is shown to the user while the app is loading. Unsurprisingly, this started a lot of (unhappy) discussion in the Android ...
14 comments on original post
1
Add a comment...

Fahad Ayaz

Shared publicly  - 
 
 
"We’re running image requests through Thumbor and a bit of client-side logic to serve up WebP... So far we’ve seen decreases in page load time ranging from one to three seconds, with a corresponding reduction in page size of one to two megabytes."

Great perf case study (and work in progress) by the team at Vox Media: bit.ly/1IP0Be7... and hooray WebP!

p.s. Thumbor is an open-source image optimization service, see: https://github.com/thumbor/thumbor
5 comments on original post
1
Add a comment...
People
Have him in circles
1,258 people
Hamza Lechhb's profile photo
Chida Sadayappan's profile photo
elvin de guzman's profile photo
Aaron Offei Nyarko's profile photo
Said Dldel's profile photo
Timothy Jeter's profile photo
Andrey Yurchenko's profile photo
Danilo Jfa's profile photo
Raghd Hamzeh's profile photo
Work
Occupation
Student
Employment
  • GDG Birmingham
    Manager, 2011 - present
  • Student, 2011
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Birmingham, UK
Previously
Bradford
Links
YouTube
Contributor to
Story
Introduction
Techophile, Sci-fi lover. Software Engineer. GDG Birmingham Organiser
Bragging rights
I kissed my cat and I liked it!
Education
  • University of Bradford
    Software Engineering
Basic Information
Gender
Male
Apps with Google+ Sign-in
  • AlphaBear
  • Mountain Goat Mountain
  • Monument Valley