Use Builder to replace the Uitls.addFooterPreference

Fixes: 139163212
Test: manual test
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.bluetooth
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accounts
Change-Id: I861434b81c07db785e6f1cfb3e34871ffba41e5f
This commit is contained in:
Sunny Shao
2019-08-09 11:42:04 +08:00
parent 7be752269b
commit 7e866b670e
5 changed files with 113 additions and 169 deletions

View File

@@ -92,7 +92,6 @@ import android.widget.ListView;
import android.widget.TabWidget; import android.widget.TabWidget;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.annotation.NonNull;
import androidx.core.graphics.drawable.IconCompat; import androidx.core.graphics.drawable.IconCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
@@ -106,7 +105,6 @@ import com.android.settings.core.FeatureFlags;
import com.android.settings.development.featureflags.FeatureFlagPersistent; import com.android.settings.development.featureflags.FeatureFlagPersistent;
import com.android.settings.password.ChooseLockSettingsHelper; import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settingslib.widget.ActionBarShadowController; import com.android.settingslib.widget.ActionBarShadowController;
import com.android.settingslib.widget.FooterPreference;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Iterator; import java.util.Iterator;
@@ -223,7 +221,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses. * Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
*
* @param context the application context * @param context the application context
* @return the formatted and newline-separated IP addresses, or null if none. * @return the formatted and newline-separated IP addresses, or null if none.
*/ */
@@ -260,9 +257,8 @@ public final class Utils extends com.android.settingslib.Utils {
// many cases, because the constructor takes the only string as the language // many cases, because the constructor takes the only string as the language
// code. So : new Locale("en", "US").toString() => "en_US" // code. So : new Locale("en", "US").toString() => "en_US"
// And : new Locale("en_US").toString() => "en_us" // And : new Locale("en_US").toString() => "en_us"
if (null == localeStr) { if (null == localeStr)
return Locale.getDefault(); return Locale.getDefault();
}
String[] brokenDownLocale = localeStr.split("_", 3); String[] brokenDownLocale = localeStr.split("_", 3);
// split may not return a 0-length array. // split may not return a 0-length array.
if (1 == brokenDownLocale.length) { if (1 == brokenDownLocale.length) {
@@ -504,8 +500,7 @@ public final class Utils extends com.android.settingslib.Utils {
* Lookup both {@link Intent#EXTRA_USER} and {@link Intent#EXTRA_USER_ID} in the bundle * Lookup both {@link Intent#EXTRA_USER} and {@link Intent#EXTRA_USER_ID} in the bundle
* and return the {@link UserHandle} object. Return {@code null} if nothing is found. * and return the {@link UserHandle} object. Return {@code null} if nothing is found.
*/ */
private static @Nullable private static @Nullable UserHandle getUserHandleFromBundle(Bundle bundle) {
UserHandle getUserHandleFromBundle(Bundle bundle) {
if (bundle == null) { if (bundle == null) {
return null; return null;
} }
@@ -546,7 +541,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Queries for the UserInfo of a user. Returns null if the user doesn't exist (was removed). * Queries for the UserInfo of a user. Returns null if the user doesn't exist (was removed).
*
* @param userManager Instance of UserManager * @param userManager Instance of UserManager
* @param checkUser The user to check the existence of. * @param checkUser The user to check the existence of.
* @return UserInfo of the user or null for non-existent user. * @return UserInfo of the user or null for non-existent user.
@@ -631,7 +625,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Returns an accessible SpannableString. * Returns an accessible SpannableString.
*
* @param displayText the text to display * @param displayText the text to display
* @param accessibileText the text text-to-speech engines should read * @param accessibileText the text text-to-speech engines should read
*/ */
@@ -842,7 +835,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Launches an intent which may optionally have a user id defined. * Launches an intent which may optionally have a user id defined.
*
* @param fragment Fragment to use to launch the activity. * @param fragment Fragment to use to launch the activity.
* @param intent Intent to launch. * @param intent Intent to launch.
*/ */
@@ -872,7 +864,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Returns if a given user is a profile of another user. * Returns if a given user is a profile of another user.
*
* @param user The user whose profiles wibe checked. * @param user The user whose profiles wibe checked.
* @param profile The (potential) profile. * @param profile The (potential) profile.
* @return if the profile is actually a profile * @return if the profile is actually a profile
@@ -898,7 +889,6 @@ public final class Utils extends com.android.settingslib.Utils {
/** /**
* Return {@code true} if the supplied package is device owner or profile owner of at * Return {@code true} if the supplied package is device owner or profile owner of at
* least one user. * least one user.
*
* @param userManager used to get profile owner app for each user * @param userManager used to get profile owner app for each user
* @param devicePolicyManager used to check whether it is device owner app * @param devicePolicyManager used to check whether it is device owner app
* @param packageName package to check about * @param packageName package to check about
@@ -1075,24 +1065,4 @@ public final class Utils extends com.android.settingslib.Utils {
ActionBarShadowController.attachToView(activity, lifecycle, scrollView); ActionBarShadowController.attachToView(activity, lifecycle, scrollView);
} }
} }
/**
* Add a footer preference into preference group.
*
* @param group The parent {@link PreferenceGroup} of the footer preference.
* @param key The key value of the footer preference.
* @param title The title of the footer preference.
*/
public static void addFooterPreference(@NonNull Context context, @NonNull PreferenceGroup group,
String key, CharSequence title) {
final FooterPreference footerPreference = new FooterPreference(context);
footerPreference.setSelectable(false);
if (!TextUtils.isEmpty(key)) {
footerPreference.setKey(key);
}
if (!TextUtils.isEmpty(title)) {
footerPreference.setTitle(title);
}
group.addPreference(footerPreference);
}
} }

View File

@@ -42,7 +42,6 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -460,7 +459,8 @@ public class AccountSyncSettings extends AccountPreferenceBase {
syncPref.setChecked(oneTimeSyncMode || syncEnabled); syncPref.setChecked(oneTimeSyncMode || syncEnabled);
} }
if (syncIsFailing) { if (syncIsFailing) {
createFooterPreference(); getPreferenceScreen().addPreference(new FooterPreference.Builder(
getActivity()).setTitle(R.string.sync_is_failing).build());
} }
} }
@@ -553,11 +553,4 @@ public class AccountSyncSettings extends AccountPreferenceBase {
| DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_SHOW_TIME); | DateUtils.FORMAT_SHOW_TIME);
} }
@VisibleForTesting
void createFooterPreference() {
final FooterPreference footerPreference = new FooterPreference(getActivity());
footerPreference.setTitle(R.string.sync_is_failing);
getPreferenceScreen().addPreference(footerPreference);
}
} }

View File

@@ -175,7 +175,8 @@ public class FingerprintSettings extends SubSettings {
updateDialog(); updateDialog();
} }
public void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString) { public void onRemovalError(Fingerprint fp, int errMsgId,
CharSequence errString) {
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null) { if (activity != null) {
Toast.makeText(activity, errString, Toast.LENGTH_SHORT); Toast.makeText(activity, errString, Toast.LENGTH_SHORT);
@@ -220,7 +221,7 @@ public class FingerprintSettings extends SubSettings {
}; };
/** /**
* @param errMsgId *
*/ */
protected void handleError(int errMsgId, CharSequence msg) { protected void handleError(int errMsgId, CharSequence msg) {
switch (errMsgId) { switch (errMsgId) {
@@ -425,11 +426,8 @@ public class FingerprintSettings extends SubSettings {
if (context == null) { if (context == null) {
return; return;
} }
root.addPreference(new FooterPreference.Builder(context).setTitle(
final FooterPreference footerPreference = new FooterPreference(context); mFooterTitle).build());
footerPreference.setTitle(mFooterTitle);
footerPreference.setSelectable(false);
root.addPreference(footerPreference);
} }
private static String genKey(int id) { private static String genKey(int id) {
@@ -522,7 +520,8 @@ public class FingerprintSettings extends SubSettings {
RenameDialog renameDialog = new RenameDialog(); RenameDialog renameDialog = new RenameDialog();
Bundle args = new Bundle(); Bundle args = new Bundle();
if (mFingerprintsRenaming.containsKey(fp.getBiometricId())) { if (mFingerprintsRenaming.containsKey(fp.getBiometricId())) {
final Fingerprint f = new Fingerprint(mFingerprintsRenaming.get(fp.getBiometricId()), final Fingerprint f = new Fingerprint(
mFingerprintsRenaming.get(fp.getBiometricId()),
fp.getGroupId(), fp.getBiometricId(), fp.getDeviceId()); fp.getGroupId(), fp.getBiometricId(), fp.getDeviceId());
args.putParcelable("fingerprint", f); args.putParcelable("fingerprint", f);
} else { } else {

View File

@@ -15,8 +15,6 @@
*/ */
package com.android.settings.accounts; package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -26,9 +24,7 @@ import android.content.Context;
import android.os.UserHandle; import android.os.UserHandle;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import com.android.settings.testutils.shadow.ShadowAuthenticationHelper;
import com.android.settings.testutils.shadow.ShadowContentResolver; import com.android.settings.testutils.shadow.ShadowContentResolver;
import org.junit.After; import org.junit.After;
@@ -37,7 +33,6 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.androidx.fragment.FragmentController;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -62,18 +57,4 @@ public class AccountSyncSettingsTest {
settings.onPreferenceTreeClick(preference); settings.onPreferenceTreeClick(preference);
// no crash // no crash
} }
@Test
@Config(shadows = {ShadowAuthenticationHelper.class})
public void createFooterPreference_shouldReturnFooter() {
final AccountSyncSettings settings = FragmentController.of(new AccountSyncSettings())
.create()
.get();
settings.createFooterPreference();
final Preference footer = settings.getPreferenceScreen().findPreference(
"footer_preference");
assertThat(footer).isNotNull();
}
} }

View File

@@ -19,7 +19,6 @@ import static com.android.settings.bluetooth.BluetoothDetailsMacAddressControlle
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import com.android.settings.Utils;
import com.android.settingslib.widget.FooterPreference; import com.android.settingslib.widget.FooterPreference;
import org.junit.Test; import org.junit.Test;
@@ -34,9 +33,11 @@ public class BluetoothDetailsMacAddressControllerTest extends BluetoothDetailsCo
public void setUp() { public void setUp() {
super.setUp(); super.setUp();
mController = mController =
new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice, mLifecycle); new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice,
mLifecycle);
setupDevice(mDeviceConfig); setupDevice(mDeviceConfig);
Utils.addFooterPreference(mContext, mScreen, KEY_DEVICE_DETAILS_FOOTER, null /* title */); mScreen.addPreference(new FooterPreference.Builder(mContext).setKey(
KEY_DEVICE_DETAILS_FOOTER).build());
} }
@Test @Test