Use small icon in location and vpn settings UI

Fixes: 65182905
Test: rerun tests
Change-Id: I18aa5c5bb4c8f573872cda3d003506c4dff5177c
This commit is contained in:
Fan Zhang
2017-10-30 13:19:34 -07:00
parent fdf96975e3
commit fc29247da4
7 changed files with 69 additions and 59 deletions

View File

@@ -1,45 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
-->
<!-- text that appears when the recent app list is empty -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingEnd="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dip"
android:layout_marginEnd="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@android:id/title"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>
</LinearLayout>

View File

@@ -16,6 +16,8 @@
package com.android.settings.accounts; package com.android.settings.accounts;
import static android.content.Intent.EXTRA_USER;
import android.accounts.Account; import android.accounts.Account;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@@ -25,12 +27,10 @@ import android.os.UserManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener; import android.support.v7.preference.Preference.OnPreferenceClickListener;
import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.widget.AppPreference;
import static android.content.Intent.EXTRA_USER; public class AccountTypePreference extends AppPreference implements OnPreferenceClickListener {
public class AccountTypePreference extends Preference implements OnPreferenceClickListener {
/** /**
* Title of the tile that is shown to the user. * Title of the tile that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title * @attr ref android.R.styleable#PreferenceHeader_title

View File

@@ -16,15 +16,14 @@
package com.android.settings.accounts; package com.android.settings.accounts;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v7.preference.Preference;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedPreference;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/** /**
* ProviderPreference is used to display an image to the left of a provider name. * ProviderPreference is used to display an image to the left of a provider name.
* The preference ultimately calls AccountManager.addAccount() for the account type. * The preference ultimately calls AccountManager.addAccount() for the account type.
@@ -35,6 +34,7 @@ public class ProviderPreference extends RestrictedPreference {
public ProviderPreference( public ProviderPreference(
Context context, String accountType, Drawable icon, CharSequence providerName) { Context context, String accountType, Drawable icon, CharSequence providerName) {
super(context); super(context);
setUseSmallIcon(true);
mAccountType = accountType; mAccountType = accountType;
setIcon(icon); setIcon(icon);
setPersistent(false); setPersistent(false);

View File

@@ -43,9 +43,9 @@ import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.dashboard.SummaryLoader; import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable; import com.android.settings.search.Indexable;
import com.android.settings.widget.AppPreference;
import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.location.RecentLocationApps;
@@ -211,21 +211,19 @@ public class LocationSettings extends LocationSettingsBase
List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size()); List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
for (final RecentLocationApps.Request request : recentLocationRequests) { for (final RecentLocationApps.Request request : recentLocationRequests) {
RestrictedPreference pref = new RestrictedPreference(getPrefContext()); final AppPreference pref = new AppPreference(getPrefContext());
pref.setSummary(request.contentDescription); pref.setSummary(request.contentDescription);
pref.setIcon(request.icon); pref.setIcon(request.icon);
pref.setTitle(request.label); pref.setTitle(request.label);
pref.setOnPreferenceClickListener( pref.setOnPreferenceClickListener(
new PackageEntryClickedListener(request.packageName, request.userHandle)); new PackageEntryClickedListener(request.packageName, request.userHandle));
recentLocationPrefs.add(pref); recentLocationPrefs.add(pref);
} }
if (recentLocationRequests.size() > 0) { if (recentLocationRequests.size() > 0) {
addPreferencesSorted(recentLocationPrefs, mCategoryRecentLocationRequests); addPreferencesSorted(recentLocationPrefs, mCategoryRecentLocationRequests);
} else { } else {
// If there's no item to display, add a "No recent apps" item. // If there's no item to display, add a "No recent apps" item.
Preference banner = new Preference(getPrefContext()); Preference banner = new AppPreference(getPrefContext());
banner.setLayoutResource(R.layout.location_list_no_item);
banner.setTitle(R.string.location_no_recent_apps); banner.setTitle(R.string.location_no_recent_apps);
banner.setSelectable(false); banner.setSelectable(false);
mCategoryRecentLocationRequests.addPreference(banner); mCategoryRecentLocationRequests.addPreference(banner);

View File

@@ -40,6 +40,8 @@ import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.Xml; import android.util.Xml;
import com.android.settings.widget.AppPreference;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@@ -268,7 +270,7 @@ class SettingsInjector {
PackageManager pm = mContext.getPackageManager(); PackageManager pm = mContext.getPackageManager();
Drawable appIcon = pm.getDrawable(info.packageName, info.iconId, null); Drawable appIcon = pm.getDrawable(info.packageName, info.iconId, null);
Drawable icon = pm.getUserBadgedIcon(appIcon, info.mUserHandle); Drawable icon = pm.getUserBadgedIcon(appIcon, info.mUserHandle);
Preference pref = new Preference(prefContext); Preference pref = new AppPreference(prefContext);
pref.setTitle(info.title); pref.setTitle(info.title);
pref.setSummary(null); pref.setSummary(null);
pref.setIcon(icon); pref.setIcon(icon);

View File

@@ -16,6 +16,8 @@
package com.android.settings.vpn2; package com.android.settings.vpn2;
import static com.android.internal.net.LegacyVpnInfo.STATE_CONNECTED;
import android.content.Context; import android.content.Context;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.text.TextUtils; import android.text.TextUtils;
@@ -23,7 +25,6 @@ import android.view.View;
import com.android.internal.net.VpnProfile; import com.android.internal.net.VpnProfile;
import com.android.settings.R; import com.android.settings.R;
import static com.android.internal.net.LegacyVpnInfo.STATE_CONNECTED;
/** /**
* {@link android.support.v7.preference.Preference} tracks the underlying legacy vpn profile and * {@link android.support.v7.preference.Preference} tracks the underlying legacy vpn profile and
@@ -35,6 +36,7 @@ public class LegacyVpnPreference extends ManageablePreference {
LegacyVpnPreference(Context context) { LegacyVpnPreference(Context context) {
super(context, null /* attrs */); super(context, null /* attrs */);
setIcon(R.drawable.ic_vpn_key); setIcon(R.drawable.ic_vpn_key);
setUseSmallIcon(true);
} }
public VpnProfile getProfile() { public VpnProfile getProfile() {

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 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.
*/
package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ProviderPreferenceTest {
private Context mContext;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
}
@Test
public void shouldUseSmallIcon() {
final ProviderPreference providerPreference = new ProviderPreference(
mContext, "account_type", null /* icon */, "provider_name");
final boolean useSmallIcon =
ReflectionHelpers.getField(providerPreference, "mUseSmallIcon");
assertThat(useSmallIcon).isTrue();
}
}