Commit b22473b2 authored by Keyvan Amiri's avatar Keyvan Amiri
Browse files

Reworked permission UI on TV into the new side-panel leanback style

Reworked all the permission UIs on TV to mesh with the rest of the
settings rendered as leanback-styled side panels with title bars.
The permissions consist of the following components:
   * Each individual app permission listing
   ** Listing of all the permissions together with the apps using
   those permissions

Bug: 27344882
Bug: 22481180

Change-Id: I4ab05efd9a4ea6fab7971b89f13d65591a2be8ee
parent 68aee0af
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/defaultBrandColor"
android:elevation="@dimen/lb_preference_decor_title_container_elevation"
android:orientation="vertical">
<FrameLayout
android:id="@+id/decor_title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/defaultBrandColor"
android:elevation="@dimen/lb_preference_decor_title_container_elevation"
android:transitionGroup="false"
>
<TextView
android:id="@+id/decor_title"
android:layout_width="match_parent"
android:layout_height="@dimen/lb_preference_decor_title_text_height"
android:layout_marginTop="@dimen/lb_preference_decor_title_margin_top"
android:layout_marginStart="@dimen/lb_preference_decor_title_margin_start"
android:layout_marginEnd="@dimen/lb_preference_decor_title_margin_end"
android:fontFamily="sans-serif-condensed"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="@dimen/lb_preference_decor_title_text_size"
android:textColor="?android:attr/textColorPrimary"
/>
</FrameLayout>
</LinearLayout>
......@@ -15,99 +15,33 @@
~ limitations under the License
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:filterTouchesWhenObscured="true">
<FrameLayout
android:layout_width="@dimen/lb_action_section_width"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:background="@color/lb_action_fragment_background">
android:layout_width="@dimen/lb_settings_pane_width"
android:layout_height="match_parent"
android:background="@color/lb_preference_decor_list_background"
android:layout_gravity="end">
<FrameLayout
android:id="@+id/prefs_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/prefs_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/no_permissions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_permissions"
android:gravity="center"
android:textAppearance="@android:style/TextAppearance.Large"
/>
android:id="@+id/no_permissions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_permissions"
android:gravity="center"
android:textAppearance="@android:style/TextAppearance.Large"
/>
</FrameLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="@dimen/lb_content_section_width"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:background="@color/lb_dialog_activity_background"
android:paddingStart="@dimen/lb_content_fragment_start_padding"
android:paddingEnd="@dimen/lb_content_fragment_delimiter_padding" >
<ImageView
android:id="@+id/lb_icon"
android:layout_width="@dimen/lb_content_fragment_icon_width"
android:layout_height="@dimen/lb_content_fragment_icon_width"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/lb_content_fragment_delimiter_padding"
android:maxHeight="@dimen/lb_content_fragment_max_icon_height"
android:minHeight="@dimen/lb_content_fragment_icon_width"
android:scaleType="fitCenter"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/lb_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/lb_icon"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:maxLines="2"
android:paddingBottom="@dimen/lb_content_fragment_title_text_bottom_padding"
android:paddingTop="@dimen/lb_content_fragment_title_text_top_padding"
android:textColor="@color/lb_content_title_text_color"
android:textSize="@dimen/lb_content_fragment_title_text_size"/>
<TextView
android:id="@+id/lb_breadcrumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/lb_title"
android:layout_alignWithParentIfMissing="true"
android:layout_toStartOf="@id/lb_icon"
android:ellipsize="end"
android:fontFamily="sans-serif-condensed"
android:singleLine="true"
android:textColor="@color/lb_content_breadcrumb_text_color"
android:textSize="@dimen/lb_content_fragment_breadcrumb_text_size" />
<TextView
android:id="@+id/lb_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/lb_title"
android:layout_toStartOf="@id/lb_icon"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:gravity="end"
android:maxLines="6"
android:textColor="@color/lb_content_description_text_color"
android:textSize="@dimen/lb_content_fragment_description_text_size"
android:lineSpacingExtra="3dp"/>
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
......@@ -22,6 +22,8 @@
<color name="lb_action_fragment_background">#FF111111</color>
<color name="lb_dialog_activity_background">#77000000</color>
<color name="lb_header_banner_color">#1f292d</color>
<color name="grant_permissions_background_color">#ff263238</color>
<color name="grant_permissions_app_color">@color/grant_permissions_white_text_alpha_100</color>
<color name="grant_permissions_progress_color">@color/grant_permissions_white_text_alpha_100</color>
......
......@@ -28,4 +28,11 @@
<!-- Preference row title for showing system apps. -->
<string name="preference_show_system_apps">Show system apps</string>
<!--decor title displayed as the page title for different TV permission screens-->
<string name="app_permissions_decor_title">App permissions</string>
<string name="manage_permissions_decor_title">App permissions</string>
<string name="permission_apps_decor_title"><xliff:g id="permission" example="Camera">%1$s</xliff:g> permissions</string>
<string name="additional_permissions_decor_title">Additional permissions</string>
<string name="system_apps_decor_title"><xliff:g id="permission" example="Camera">%1$s</xliff:g> permissions</string>
</resources>
......@@ -17,7 +17,11 @@
<resources>
<style name="Settings" parent="Theme.Leanback">
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Permissions</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Leanback</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.8</item>
</style>
<style name="GrantPermissions" parent="Theme.Leanback">
......
......@@ -177,20 +177,6 @@ public final class AppPermissionsFragment extends SettingsWithHeader
if (ab != null) {
ab.setTitle(R.string.app_permissions);
}
ViewGroup rootView = (ViewGroup) fragment.getView();
ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
iconView.setImageDrawable(icon);
}
TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(R.string.app_permissions);
}
TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(label);
}
}
private void loadPreferences() {
......
......@@ -124,23 +124,6 @@ public final class ManagePermissionsFragment extends PermissionsFrameFragment
if (context == null || rootView == null) {
return;
}
ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
// Set the icon as the background instead of the image because ImageView
// doesn't properly scale vector drawables beyond their intrinsic size
Drawable icon = context.getDrawable(R.drawable.ic_lock);
icon.setTint(context.getColor(R.color.off_white));
iconView.setBackground(icon);
}
TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(R.string.app_permissions);
}
TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(R.string.app_permissions_breadcrumb);
}
}
private void updatePermissionsUi() {
......
......@@ -155,22 +155,6 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
if (ab != null) {
ab.setTitle(fragment.getString(R.string.permission_title, label));
}
final ViewGroup rootView = (ViewGroup) fragment.getView();
final ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
// Set the icon as the background instead of the image because ImageView
// doesn't properly scale vector drawables beyond their intrinsic size
iconView.setBackground(icon);
}
final TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(label);
}
final TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(R.string.app_permissions);
}
}
private void setOnPermissionsLoadedListener(Callback callback) {
......
......@@ -139,7 +139,7 @@ public final class AllAppPermissionsFragment extends SettingsWithHeader {
infoIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
.setData(Uri.fromParts("package", mPackageInfo.packageName, null));
}
setHeader(icon, label, infoIntent);
setHeader(icon, label, infoIntent, null);
if (mPackageInfo.requestedPermissions != null) {
for (int i = 0; i < mPackageInfo.requestedPermissions.length; i++) {
......
......@@ -28,25 +28,27 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v17.leanback.widget.VerticalGridView;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.packageinstaller.R;
import com.android.packageinstaller.permission.model.AppPermissionGroup;
import com.android.packageinstaller.permission.model.AppPermissions;
......@@ -103,6 +105,7 @@ public final class AppPermissionsFragment extends SettingsWithHeader
return;
}
mAppPermissions = new AppPermissions(activity, packageInfo, null, true, new Runnable() {
@Override
public void run() {
......@@ -176,25 +179,18 @@ public final class AppPermissionsFragment extends SettingsWithHeader
Drawable icon = appInfo.loadIcon(pm);
CharSequence label = appInfo.loadLabel(pm);
fragment.setHeader(icon, label, infoIntent);
fragment.setHeader(icon, label, infoIntent, fragment.getString(
R.string.app_permissions_decor_title));
}
ActionBar ab = activity.getActionBar();
if (ab != null) {
ab.setTitle(R.string.app_permissions);
}
@Override
protected void updateHeader() {
ViewGroup rootView = (ViewGroup) fragment.getView();
ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
iconView.setImageDrawable(icon);
}
TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(R.string.app_permissions);
}
TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(label);
super.updateHeader();
Preference headerLineTwo = getPreferenceScreen().findPreference(HEADER_PREFERENCE_KEY);
if (headerLineTwo != null) {
headerLineTwo.setTitle(mLabel);
headerLineTwo.setIcon(mIcon);
}
}
......@@ -207,6 +203,22 @@ public final class AppPermissionsFragment extends SettingsWithHeader
PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
// Setting the second-line header that contains the app banner icon and its name.
// The styling used is the same as a leanback preference with a customized background color.
Preference headerLineTwo = new Preference(context) {
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.itemView.setBackgroundColor(
getResources().getColor(R.color.lb_header_banner_color));
}
};
headerLineTwo.setKey(HEADER_PREFERENCE_KEY);
headerLineTwo.setSelectable(false);
headerLineTwo.setTitle(mLabel);
headerLineTwo.setIcon(mIcon);
screen.addPreference(headerLineTwo);
if (mExtraScreen != null) {
mExtraScreen.removeAll();
}
......@@ -379,7 +391,8 @@ public final class AppPermissionsFragment extends SettingsWithHeader
public void onCreate(Bundle savedInstanceState) {
mOuterFragment = (AppPermissionsFragment) getTargetFragment();
super.onCreate(savedInstanceState);
setHeader(mOuterFragment.mIcon, mOuterFragment.mLabel, mOuterFragment.mInfoIntent);
setHeader(mOuterFragment.mIcon, mOuterFragment.mLabel, mOuterFragment.mInfoIntent,
null);
setHasOptionsMenu(true);
}
......
......@@ -42,7 +42,7 @@ import com.android.packageinstaller.util.Utils;
import java.util.List;
public final class ManagePermissionsFragment extends PermissionsFrameFragment
public final class ManagePermissionsFragment extends SettingsWithHeader
implements PermissionGroups.PermissionsGroupsChangeCallback, OnPreferenceClickListener {
private static final String LOG_TAG = "ManagePermissionsFragment";
......@@ -117,30 +117,15 @@ public final class ManagePermissionsFragment extends PermissionsFrameFragment
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bindPermissionUi(getActivity(), getView());
bindPermissionUi(this, getView());
}
private static void bindPermissionUi(@Nullable Context context, @Nullable View rootView) {
if (context == null || rootView == null) {
private static void bindPermissionUi(SettingsWithHeader fragment, @Nullable View rootView) {
if (fragment == null || rootView == null) {
return;
}
ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
// Set the icon as the background instead of the image because ImageView
// doesn't properly scale vector drawables beyond their intrinsic size
Drawable icon = context.getDrawable(R.drawable.ic_lock);
icon.setTint(context.getColor(R.color.off_white));
iconView.setBackground(icon);
}
TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(R.string.app_permissions);
}
TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(R.string.app_permissions_breadcrumb);
}
fragment.setHeader(null, null, null, fragment.getString(
R.string.manage_permissions_decor_title));
}
private void updatePermissionsUi() {
......@@ -227,7 +212,7 @@ public final class ManagePermissionsFragment extends PermissionsFrameFragment
}
}
public static class AdditionalPermissionsFragment extends PermissionsFrameFragment {
public static class AdditionalPermissionsFragment extends SettingsWithHeader {
@Override
public void onCreate(Bundle icicle) {
setLoading(true /* loading */, false /* animate */);
......@@ -255,7 +240,15 @@ public final class ManagePermissionsFragment extends PermissionsFrameFragment
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bindPermissionUi(getActivity(), getView());
bindPermissionUi(this, getView());
}
private static void bindPermissionUi(SettingsWithHeader fragment, @Nullable View rootView) {
if (fragment == null || rootView == null) {
return;
}
fragment.setHeader(null, null, null,
fragment.getString(R.string.additional_permissions_decor_title));
}
@Override
......
......@@ -15,6 +15,7 @@
*/
package com.android.packageinstaller.permission.ui.television;
import android.annotation.Nullable;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Fragment;
......@@ -53,7 +54,7 @@ import com.android.packageinstaller.util.Utils;
import java.util.ArrayList;
import java.util.List;
public final class PermissionAppsFragment extends PermissionsFrameFragment implements Callback,
public final class PermissionAppsFragment extends SettingsWithHeader implements Callback,
OnPreferenceChangeListener {
private static final int MENU_SHOW_SYSTEM = Menu.FIRST;
......@@ -150,29 +151,12 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
bindUi(this, mPermissionApps);
}
private static void bindUi(Fragment fragment, PermissionApps permissionApps) {
private static void bindUi(SettingsWithHeader fragment, PermissionApps permissionApps) {
final Drawable icon = permissionApps.getIcon();
final CharSequence label = permissionApps.getLabel();
final ActionBar ab = fragment.getActivity().getActionBar();
if (ab != null) {
ab.setTitle(fragment.getString(R.string.permission_title, label));
}
final ViewGroup rootView = (ViewGroup) fragment.getView();
final ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
if (iconView != null) {
// Set the icon as the background instead of the image because ImageView
// doesn't properly scale vector drawables beyond their intrinsic size
iconView.setBackground(icon);
}
final TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
if (titleView != null) {
titleView.setText(label);
}
final TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
if (breadcrumbView != null) {
breadcrumbView.setText(R.string.app_permissions);
}
fragment.setHeader(null, null, null,
fragment.getString(R.string.permission_apps_decor_title, label));
}
private void setOnPermissionsLoadedListener(Callback callback) {
......@@ -397,7 +381,7 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
}
}
public static class SystemAppsFragment extends PermissionsFrameFragment implements Callback {
public static class SystemAppsFragment extends SettingsWithHeader implements Callback {
PermissionAppsFragment mOuterFragment;
@Override
......@@ -424,6 +408,14 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
bindUi(this, permissionApps);
}
private static void bindUi(SettingsWithHeader fragment, PermissionApps permissionApps) {
final CharSequence label = permissionApps.getLabel();
fragment.setHeader(null, null, null,
fragment.getString(R.string.system_apps_decor_title, label));
}
@Override
public void onPermissionsLoaded(PermissionApps permissionApps) {
setPreferenceScreen();
......
......@@ -22,7 +22,6 @@ import android.support.v14.preference.PreferenceFragment;
import android.support.v17.leanback.widget.VerticalGridView;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.AdapterDataObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -30,18 +29,19 @@ import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.R;
public abstract class PermissionsFrameFragment extends PreferenceFragment {
private static final float WINDOW_ALIGNMENT_OFFSET_PERCENT = 50;
// Key identifying the preference used on TV as the extra header in a permission fragment.
// This is to distinguish it from the rest of the preferences
protected static final String HEADER_PREFERENCE_KEY = "HeaderPreferenceKey";
private ViewGroup mPreferencesContainer;
// TV-specific instance variables
@Nullable private VerticalGridView mGridView;
// TV-specific instance variable
@Nullable private RecyclerView mGridView;
private View mLoadingView;
private ViewGroup mPrefsView;
......@@ -132,18 +132,13 @@ public abstract class PermissionsFrameFragment extends PreferenceFragment {
@Override
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
if (DeviceUtils.isTelevision(getContext())) {
mGridView = (VerticalGridView) inflater.inflate(
R.layout.leanback_preferences_list, parent, false);
mGridView.setWindowAlignmentOffset(0);
mGridView.setWindowAlignmentOffsetPercent(WINDOW_ALIGNMENT_OFFSET_PERCENT);
mGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
mGridView.setFocusScrollStrategy(VerticalGridView.FOCUS_SCROLL_ALIGNED);
return mGridView;
} else {
return super.onCreateRecyclerView(inflater, parent, savedInstanceState);
}
Bundle savedInstanceState) {
VerticalGridView verticalGridView = (VerticalGridView) inflater.inflate(
R.layout.leanback_preferences_list, parent, false);
verticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
verticalGridView.setFocusScrollStrategy(VerticalGridView.FOCUS_SCROLL_ALIGNED);
mGridView = verticalGridView;
return mGridView;
}
@Override
......@@ -154,7 +149,7 @@ public abstract class PermissionsFrameFragment extends PreferenceFragment {
final TextView emptyView = (TextView) getView().findViewById(R.id.no_permissions);
onSetEmptyText(emptyView);
final RecyclerView recyclerView = getListView();
adapter.registerAdapterDataObserver(new AdapterDataObserver() {
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
checkEmpty();
......@@ -171,18 +166,20 @@ public abstract class PermissionsFrameFragment extends PreferenceFragment {
}
private void checkEmpty() {
boolean isEmpty = adapter.getItemCount() == 0;
boolean isEmpty = isPreferenceListEmpty();
emptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
recyclerView.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
recyclerView.setVisibility(isEmpty && adapter.getItemCount() == 0 ?
View.GONE : View.VISIBLE);
if (!isEmpty && mGridView != null) {
mGridView.requestFocus();
}
}
});
boolean isEmpty = adapter.getItemCount() == 0;
boolean isEmpty = isPreferenceListEmpty();
emptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
recyclerView.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
recyclerView.setVisibility(isEmpty && adapter.getItemCount() == 0 ?
View.GONE : View.VISIBLE);
if (!isEmpty && mGridView != null) {
mGridView.requestFocus();
}
......@@ -191,6 +188,13 @@ public abstract class PermissionsFrameFragment extends PreferenceFragment {
return adapter;
}
private boolean isPreferenceListEmpty() {
PreferenceScreen screen = getPreferenceScreen();
return screen.getPreferenceCount() == 0 || (
screen.getPreferenceCount() == 1 &&
(screen.findPreference(HEADER_PREFERENCE_KEY) != null));
}
/**
* Hook for subclasses to change the default text of the empty view.
* Base implementation leaves the default empty view text.
......@@ -200,4 +204,3 @@ public abstract class PermissionsFrameFragment extends PreferenceFragment {
protected void onSetEmptyText(TextView textView) {
}
}
......@@ -25,7 +25,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.R;
......@@ -36,50 +35,40 @@ public abstract class SettingsWithHeader extends PermissionsFrameFragment
protected Intent mInfoIntent;
protected Drawable mIcon;
protected CharSequence mLabel;
protected CharSequence mDecorTitle;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
if (!DeviceUtils.isTelevision(getContext())) {
mHeader = inflater.inflate(R.layout.header, root, false);
getPreferencesContainer().addView(mHeader, 0);
updateHeader();
}
mHeader = inflater.inflate(R.layout.header, root, false);
getPreferencesContainer().addView(mHeader, 0);
updateHeader();
return root;
}
public void setHeader(Drawable icon, CharSequence label, Intent infoIntent) {
public void setHeader(Drawable icon, CharSequence label, Intent infoIntent,
CharSequence decorTitle) {
mIcon = icon;
mLabel = label;
mInfoIntent = infoIntent;
mDecorTitle = decorTitle;
updateHeader();
}
private void updateHeader() {
if (mHeader != null) {
final ImageView appIcon = (ImageView) mHeader.findViewById(R.id.icon);
appIcon.setImageDrawable(mIcon);
final TextView appName = (TextView) mHeader.findViewById(R.id.name);
appName.setText(mLabel);
public View getHeader() {
return mHeader;
}
final View info = mHeader.findViewById(R.id.info);
if (mInfoIntent == null) {
info.setVisibility(View.GONE);
} else {
info.setVisibility(View.VISIBLE);
info.setClickable(true);
info.setOnClickListener(this);
}
}
protected void updateHeader() {
final TextView decorTitle = (TextView) mHeader.findViewById(R.id.decor_title);
decorTitle.setText(mDecorTitle);
}
@Override
public void onClick(View v) {
getActivity().startActivity(mInfoIntent);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment