Merge "Set activity title from preference screen title."
This commit is contained in:
committed by
Android (Google) Code Review
commit
9d85cfe762
@@ -55,6 +55,7 @@ import com.android.internal.util.ArrayUtils;
|
|||||||
import com.android.settings.Settings.WifiSettingsActivity;
|
import com.android.settings.Settings.WifiSettingsActivity;
|
||||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||||
import com.android.settings.backup.BackupSettingsActivity;
|
import com.android.settings.backup.BackupSettingsActivity;
|
||||||
|
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||||
import com.android.settings.core.gateway.SettingsGateway;
|
import com.android.settings.core.gateway.SettingsGateway;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
|
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
|
||||||
@@ -209,8 +210,12 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
|
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
|
||||||
|
if (InstrumentedPreferenceFragment.usePreferenceScreenTitle()) {
|
||||||
|
startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, null, null, 0);
|
||||||
|
} else {
|
||||||
startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
|
startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
|
||||||
null, 0);
|
null, 0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +634,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
if (titleRes < 0) {
|
if (titleRes < 0) {
|
||||||
if (titleText != null) {
|
if (titleText != null) {
|
||||||
title = titleText.toString();
|
title = titleText.toString();
|
||||||
} else {
|
} else if (!InstrumentedPreferenceFragment.usePreferenceScreenTitle()) {
|
||||||
// There not much we can do in that case
|
// There not much we can do in that case
|
||||||
title = "";
|
title = "";
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.core;
|
package com.android.settings.core;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.XmlRes;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.core.instrumentation.Instrumentable;
|
import com.android.settings.core.instrumentation.Instrumentable;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
@@ -32,6 +39,9 @@ import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
|
|||||||
public abstract class InstrumentedPreferenceFragment extends ObservablePreferenceFragment
|
public abstract class InstrumentedPreferenceFragment extends ObservablePreferenceFragment
|
||||||
implements Instrumentable {
|
implements Instrumentable {
|
||||||
|
|
||||||
|
private static final String TAG = "InstrumentedPrefFrag";
|
||||||
|
private static final String FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE =
|
||||||
|
"settings_use_preference_screen_title";
|
||||||
protected MetricsFeatureProvider mMetricsFeatureProvider;
|
protected MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
// metrics placeholder value. Only use this for development.
|
// metrics placeholder value. Only use this for development.
|
||||||
@@ -46,6 +56,17 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
|||||||
getLifecycle().addObserver(new SurveyMixin(this, getClass().getSimpleName()));
|
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
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@@ -62,6 +83,16 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
|||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
|
||||||
|
super.addPreferencesFromResource(preferencesResId);
|
||||||
|
updateActivityTitleWithScreenTitle(getPreferenceScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean usePreferenceScreenTitle() {
|
||||||
|
return FeatureFlagUtils.isEnabled(FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
protected final Context getPrefContext() {
|
protected final Context getPrefContext() {
|
||||||
return getPreferenceManager().getContext();
|
return getPreferenceManager().getContext();
|
||||||
}
|
}
|
||||||
@@ -69,4 +100,27 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
|||||||
protected final VisibilityLoggerMixin getVisibilityLogger() {
|
protected final VisibilityLoggerMixin getVisibilityLogger() {
|
||||||
return mVisibilityLoggerMixin;
|
return mVisibilityLoggerMixin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
@StringRes
|
||||||
|
protected int getTitle() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateActivityTitleWithScreenTitle(PreferenceScreen screen) {
|
||||||
|
if (usePreferenceScreenTitle() && screen != null) {
|
||||||
|
final CharSequence title = screen.getTitle();
|
||||||
|
if (!TextUtils.isEmpty(title)) {
|
||||||
|
getActivity().setTitle(title);
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Screen title missing for fragment " + this.getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user