Merge "Update activity titles for fragments without preference screen."
This commit is contained in:
committed by
Android (Google) Code Review
commit
471bc86ae6
@@ -21,7 +21,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorDescription;
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
@@ -39,7 +39,6 @@ import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.telephony.euicc.EuiccManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -54,6 +53,7 @@ import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.password.ConfirmLockPattern;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -70,7 +70,7 @@ import java.util.List;
|
||||
*
|
||||
* This is the initial screen.
|
||||
*/
|
||||
public class MasterClear extends OptionsMenuFragment {
|
||||
public class MasterClear extends InstrumentedPreferenceFragment {
|
||||
private static final String TAG = "MasterClear";
|
||||
|
||||
private static final int KEYGUARD_REQUEST = 55;
|
||||
@@ -93,9 +93,11 @@ public class MasterClear extends OptionsMenuFragment {
|
||||
};
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.master_clear_title;
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.master_clear_title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -33,6 +33,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
@@ -47,7 +48,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
*
|
||||
* This is the confirmation screen.
|
||||
*/
|
||||
public class MasterClearConfirm extends OptionsMenuFragment {
|
||||
public class MasterClearConfirm extends InstrumentedPreferenceFragment {
|
||||
|
||||
private View mContentView;
|
||||
private boolean mEraseSdCard;
|
||||
|
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.android.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
|
||||
/**
|
||||
* Base class for a fragment that has the options menu.
|
||||
* SettingsPreferenceFragment automatically sets this, but some activities do not use
|
||||
* preferences, and we need to call setHasOptionsMenu(true) for the back button on action bar.
|
||||
* For preference fragments, use SettingsPreferenceFragment.
|
||||
*/
|
||||
public abstract class OptionsMenuFragment extends InstrumentedPreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
}
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
@@ -35,6 +35,7 @@ import android.widget.Spinner;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.password.ConfirmLockPattern;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -52,7 +53,7 @@ import java.util.List;
|
||||
*
|
||||
* This is the initial screen.
|
||||
*/
|
||||
public class ResetNetwork extends OptionsMenuFragment {
|
||||
public class ResetNetwork extends InstrumentedPreferenceFragment {
|
||||
private static final String TAG = "ResetNetwork";
|
||||
|
||||
// Arbitrary to avoid conficts
|
||||
@@ -65,9 +66,11 @@ public class ResetNetwork extends OptionsMenuFragment {
|
||||
private Button mInitiateButton;
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.reset_network_title;
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.reset_network_title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -38,6 +38,7 @@ import android.widget.Toast;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
@@ -52,7 +53,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
*
|
||||
* This is the confirmation screen.
|
||||
*/
|
||||
public class ResetNetworkConfirm extends OptionsMenuFragment {
|
||||
public class ResetNetworkConfirm extends InstrumentedPreferenceFragment {
|
||||
|
||||
private View mContentView;
|
||||
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
@@ -20,7 +20,6 @@ import static android.widget.LinearLayout.LayoutParams.MATCH_PARENT;
|
||||
import static android.widget.LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
import android.animation.LayoutTransition;
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.UiThread;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
@@ -66,6 +65,7 @@ import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.app.UnlaunchableAppActivity;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
@@ -75,7 +75,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class TrustedCredentialsSettings extends OptionsMenuFragment
|
||||
public class TrustedCredentialsSettings extends InstrumentedPreferenceFragment
|
||||
implements TrustedCredentialsDialogBuilder.DelegateInterface {
|
||||
|
||||
public static final String ARG_SHOW_NEW_FOR_USER = "ARG_SHOW_NEW_FOR_USER";
|
||||
@@ -91,12 +91,6 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
|
||||
private static final String USER_ACTION = "com.android.settings.TRUSTED_CREDENTIALS_USER";
|
||||
private static final int REQUEST_CONFIRM_CREDENTIALS = 1;
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.trusted_credentials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.TRUSTED_CREDENTIALS;
|
||||
@@ -183,10 +177,11 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
mKeyguardManager = (KeyguardManager) getActivity()
|
||||
final Activity activity = getActivity();
|
||||
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||
mKeyguardManager = (KeyguardManager) activity
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
mTrustAllCaUserId = getActivity().getIntent().getIntExtra(ARG_SHOW_NEW_FOR_USER,
|
||||
mTrustAllCaUserId = activity.getIntent().getIntExtra(ARG_SHOW_NEW_FOR_USER,
|
||||
UserHandle.USER_NULL);
|
||||
mConfirmedCredentialUsers = new ArraySet<>(2);
|
||||
mConfirmingCredentialUser = UserHandle.USER_NULL;
|
||||
@@ -206,7 +201,11 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
|
||||
getActivity().registerReceiver(mWorkProfileChangedReceiver, filter);
|
||||
activity.registerReceiver(mWorkProfileChangedReceiver, filter);
|
||||
|
||||
if (usePreferenceScreenTitle()) {
|
||||
activity.setTitle(R.string.trusted_credentials);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings;
|
||||
|
||||
import android.annotation.LayoutRes;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
@@ -86,9 +85,11 @@ public class UserCredentialsSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.user_credentials;
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.user_credentials);
|
||||
}
|
||||
}
|
||||
|
||||
protected void announceRemoval(String alias) {
|
||||
|
@@ -119,6 +119,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
static final String EXTRA_PREFERENCE_KEY = "preference_key";
|
||||
static final String EXTRA_CHECKED = "checked";
|
||||
static final String EXTRA_TITLE = "title";
|
||||
static final String EXTRA_TITLE_RES = "title_res";
|
||||
static final String EXTRA_RESOLVE_INFO = "resolve_info";
|
||||
static final String EXTRA_SUMMARY = "summary";
|
||||
static final String EXTRA_SETTINGS_TITLE = "settings_title";
|
||||
|
@@ -141,6 +141,10 @@ public final class MagnificationPreferenceFragment extends SettingsPreferenceFra
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, getString(
|
||||
R.string.accessibility_screen_magnification_navbar_title));
|
||||
if (usePreferenceScreenTitle()) {
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_navbar_title);
|
||||
}
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY,
|
||||
getActivity().getResources().getText(
|
||||
R.string.accessibility_screen_magnification_navbar_summary));
|
||||
@@ -190,6 +194,10 @@ public final class MagnificationPreferenceFragment extends SettingsPreferenceFra
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, context.getString(
|
||||
R.string.accessibility_screen_magnification_gestures_title));
|
||||
if (usePreferenceScreenTitle()) {
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_gestures_title);
|
||||
}
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY, context.getResources().getText(
|
||||
R.string.accessibility_screen_magnification_summary));
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||
|
@@ -21,16 +21,8 @@ import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
@@ -104,13 +96,6 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
// Implement this to reset a checked listener.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the res id for static preference xml for this fragment.
|
||||
*/
|
||||
protected int getPreferenceScreenResId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void installActionBarToggleSwitch() {
|
||||
mSwitchBar.show();
|
||||
onInstallSwitchBarToggleSwitch();
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
@@ -53,12 +52,9 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
||||
for (int i = 0; i < strEntryValues.length; ++i) {
|
||||
mValues[i] = Float.parseFloat(strEntryValues[i]);
|
||||
}
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.title_font_size);
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.title_font_size;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -217,6 +217,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
if (arguments.containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||
mInitialSetting = arguments.getBoolean(AccessibilitySettings.EXTRA_CHECKED);
|
||||
}
|
||||
|
||||
if (usePreferenceScreenTitle()
|
||||
&& arguments.containsKey(AccessibilitySettings.EXTRA_TITLE_RES)) {
|
||||
final int titleRes = arguments.getInt(AccessibilitySettings.EXTRA_TITLE_RES);
|
||||
if (titleRes > 0) {
|
||||
getActivity().setTitle(titleRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfigurationWarningIfNeeded() {
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFrameLayout;
|
||||
@@ -37,6 +37,14 @@ public class BackgroundCheckSummary extends InstrumentedPreferenceFragment {
|
||||
return MetricsEvent.BACKGROUND_CHECK_SUMMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.background_check_pref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// initialize the inflater
|
||||
@@ -59,10 +67,4 @@ public class BackgroundCheckSummary extends InstrumentedPreferenceFragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.background_check_pref;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -44,6 +43,10 @@ public class RunningServices extends SettingsPreferenceFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.runningservices_settings_title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,12 +112,6 @@ public class RunningServices extends SettingsPreferenceFragment {
|
||||
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.runningservices_settings_title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.RUNNING_SERVICES;
|
||||
|
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.android.settings.core;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.annotation.XmlRes;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
@@ -40,7 +39,8 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
||||
implements Instrumentable {
|
||||
|
||||
private static final String TAG = "InstrumentedPrefFrag";
|
||||
private static final String FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE =
|
||||
@VisibleForTesting
|
||||
static final String FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE =
|
||||
"settings_use_preference_screen_title";
|
||||
protected MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@@ -56,17 +56,6 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
||||
getLifecycle().addObserver(new SurveyMixin(this, getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
final int title = getTitle();
|
||||
if (title != -1) {
|
||||
getActivity().setTitle(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -81,6 +70,12 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
if (usePreferenceScreenTitle()) {
|
||||
final int resId = getPreferenceScreenResId();
|
||||
if (resId > 0) {
|
||||
addPreferencesFromResource(resId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,13 +97,9 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the resource id of the title to be used for the fragment. This is for preference
|
||||
* fragments that do not have an explicit preference screen xml, and hence the title need to be
|
||||
* specified separately. Do not use this method if the title is already specified in the
|
||||
* preference screen.
|
||||
* Get the res id for static preference xml for this fragment.
|
||||
*/
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
protected int getPreferenceScreenResId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -115,7 +115,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||
refreshAllPreferences(getLogTag());
|
||||
}
|
||||
|
||||
@@ -211,11 +210,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
*/
|
||||
protected abstract String getLogTag();
|
||||
|
||||
/**
|
||||
* Get the res id for static preference xml for this fragment.
|
||||
*/
|
||||
protected abstract int getPreferenceScreenResId();
|
||||
|
||||
/**
|
||||
* Get a list of {@link AbstractPreferenceController} for this fragment.
|
||||
*/
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
@@ -71,6 +70,10 @@ public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment impleme
|
||||
mInitialIndex = initialIndex;
|
||||
mDefaultDensity = density.getDefaultDensity();
|
||||
}
|
||||
|
||||
if (usePreferenceScreenTitle()) {
|
||||
getActivity().setTitle(R.string.screen_zoom_title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,12 +102,6 @@ public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment impleme
|
||||
return R.string.help_url_display_size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.screen_zoom_title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DISPLAY_SCREEN_ZOOM;
|
||||
|
@@ -19,7 +19,12 @@ package com.android.settings.language;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.localepicker.LocaleListEditor;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -60,4 +65,17 @@ public class PhoneLanguagePreferenceController extends AbstractPreferenceControl
|
||||
public String getPreferenceKey() {
|
||||
return KEY_PHONE_LANGUAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!InstrumentedPreferenceFragment.usePreferenceScreenTitle()
|
||||
|| !KEY_PHONE_LANGUAGE.equals(preference.getKey())) {
|
||||
return false;
|
||||
}
|
||||
Utils.startWithFragment(mContext, LocaleListEditor.class.getName(), null, null, 0,
|
||||
R.string.pref_title_lang_selection, null,
|
||||
MetricsProto.MetricsEvent.SETTINGS_LANGUAGE_CATEGORY);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -77,8 +77,6 @@ public class LocaleListEditor extends SettingsPreferenceFragment
|
||||
final View result = super.onCreateView(inflater, container, savedInstState);
|
||||
final View myLayout = inflater.inflate(R.layout.locale_order_list, (ViewGroup) result);
|
||||
|
||||
getActivity().setTitle(R.string.pref_title_lang_selection);
|
||||
|
||||
configureDragAndDrop(myLayout);
|
||||
return result;
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.nfc;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
@@ -98,6 +97,10 @@ public class AndroidBeam extends InstrumentedPreferenceFragment
|
||||
mSwitchBar.setEnabled(!mBeamDisallowedByBase);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
if (usePreferenceScreenTitle()) {
|
||||
activity.setTitle(R.string.android_beam_settings_title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,10 +134,4 @@ public class AndroidBeam extends InstrumentedPreferenceFragment
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.NFC_BEAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getTitle() {
|
||||
return R.string.android_beam_settings_title;
|
||||
}
|
||||
}
|
||||
|
@@ -31,17 +31,6 @@ public abstract class EmptyTextSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private TextView mEmpty;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||
if (usePreferenceScreenTitle()) {
|
||||
final int resId = getPreferenceScreenResId();
|
||||
if (resId > 0) {
|
||||
addPreferencesFromResource(resId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
@@ -58,9 +47,4 @@ public abstract class EmptyTextSettings extends SettingsPreferenceFragment {
|
||||
protected void setEmptyText(int text) {
|
||||
mEmpty.setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the res id for static preference xml for this fragment.
|
||||
*/
|
||||
protected abstract int getPreferenceScreenResId();
|
||||
}
|
||||
|
@@ -50,15 +50,15 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.OptionsMenuFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.fingerprint.FingerprintUiHelper;
|
||||
|
||||
/**
|
||||
* Base fragment to be shared for PIN/Pattern/Password confirmation fragments.
|
||||
*/
|
||||
public abstract class ConfirmDeviceCredentialBaseFragment extends OptionsMenuFragment
|
||||
public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedPreferenceFragment
|
||||
implements FingerprintUiHelper.Callback {
|
||||
|
||||
public static final String PACKAGE = "com.android.settings";
|
||||
|
@@ -67,10 +67,7 @@ public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFr
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||
final int resId = getPreferenceScreenResId();
|
||||
if (usePreferenceScreenTitle() && resId > 0) {
|
||||
addPreferencesFromResource(resId);
|
||||
} else {
|
||||
if (!usePreferenceScreenTitle()) {
|
||||
addPreferencesFromResource(R.xml.placeholder_prefs);
|
||||
}
|
||||
updateCandidates();
|
||||
@@ -115,13 +112,6 @@ public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFr
|
||||
onSelectionPerformed(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the res id for static preference xml for this fragment.
|
||||
*/
|
||||
protected int getPreferenceScreenResId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* A chance for subclasses to bind additional things to the preference.
|
||||
*/
|
||||
|
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
SettingsShadowSystemProperties.class
|
||||
})
|
||||
public class InstrumentedPreferenceFragmentTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
|
||||
private InstrumentedPreferenceFragmentTestable mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mPreferenceManager.getPreferenceScreen()).thenReturn(mScreen);
|
||||
|
||||
mFragment = spy(new InstrumentedPreferenceFragmentTestable());
|
||||
ReflectionHelpers.setField(mFragment, "mPreferenceManager", mPreferenceManager);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreatePreferences_preferenceScreenTitleFeatureOff_shouldNotAddPreference() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
"false");
|
||||
|
||||
mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
|
||||
|
||||
verify(mFragment, never()).addPreferencesFromResource(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreatePreferences_noPreferenceScreenResId_shouldNotAddPreference() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
|
||||
mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
|
||||
|
||||
verify(mFragment, never()).addPreferencesFromResource(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreatePreferences_gotPreferenceScreenResId_shouldAddPreferences() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
mFragment.setPreferenceScreenResId(R.xml.screen_pinning_settings);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
|
||||
mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
|
||||
|
||||
verify(mFragment).addPreferencesFromResource(R.xml.screen_pinning_settings);
|
||||
verify(mActivity, never()).setTitle(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreatePreferences_gotPrefScreenResIdAndTitle_shouldAddPreferencesAndSetTitle() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
mFragment.setPreferenceScreenResId(R.xml.screen_pinning_settings);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
final CharSequence title = "Test Title";
|
||||
when(mScreen.getTitle()).thenReturn(title);
|
||||
|
||||
mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
|
||||
|
||||
verify(mFragment).addPreferencesFromResource(R.xml.screen_pinning_settings);
|
||||
verify(mActivity).setTitle(title);
|
||||
}
|
||||
|
||||
private static class InstrumentedPreferenceFragmentTestable
|
||||
extends InstrumentedPreferenceFragment {
|
||||
|
||||
private int mScreenId = -1;
|
||||
|
||||
public InstrumentedPreferenceFragmentTestable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.VIEW_UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return mScreenId;
|
||||
}
|
||||
|
||||
public void setPreferenceScreenResId(int id) {
|
||||
mScreenId = id;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user