Fix app headers in settings

Use SettingsPreferenceFragment's method for pinned headers where
possible, and add a frame within the fragment for them to live in
otherwise so that this view doesn't end up on the activity.

Bug: 20886475
Change-Id: I985eb1497744ea50bfabed862e5088eb89df5b61
This commit is contained in:
Jason Monk
2015-05-06 16:00:25 -04:00
parent 0d2a8d204b
commit 20f464edde
10 changed files with 48 additions and 24 deletions

View File

@@ -28,18 +28,27 @@ import android.widget.TextView;
public class AppHeader {
public static void createAppHeader(final Activity activity, Drawable icon, CharSequence label,
final Intent settingsIntent) {
createAppHeader(activity, icon, label, settingsIntent, 0);
public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
CharSequence label, final Intent settingsIntent) {
createAppHeader(fragment, icon, label, settingsIntent, 0);
}
public static void createAppHeader(final Activity activity, Drawable icon, CharSequence label,
final Intent settingsIntent, int tintColorRes) {
final View content = activity.findViewById(R.id.main_content);
final ViewGroup contentParent = (ViewGroup) content.getParent();
public static void createAppHeader(Activity activity, Drawable icon, CharSequence label,
final Intent settingsIntent, ViewGroup pinnedHeader) {
final View bar = activity.getLayoutInflater().inflate(R.layout.app_header,
contentParent, false);
pinnedHeader, false);
setupHeaderView(activity, icon, label, settingsIntent, 0, bar);
pinnedHeader.addView(bar);
}
public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
CharSequence label, Intent settingsIntent, int tintColorRes) {
View bar = fragment.setPinnedHeaderView(R.layout.app_header);
setupHeaderView(fragment.getActivity(), icon, label, settingsIntent, tintColorRes, bar);
}
private static View setupHeaderView(final Activity activity, Drawable icon, CharSequence label,
final Intent settingsIntent, int tintColorRes, View bar) {
final ImageView appIcon = (ImageView) bar.findViewById(R.id.app_icon);
appIcon.setImageDrawable(icon);
if (tintColorRes != 0) {
@@ -61,7 +70,8 @@ public class AppHeader {
}
});
}
contentParent.addView(bar, 0);
return bar;
}
}