Create NetworkScorerPicker preference controller to set preference summary.
Bug: 35854552 Test: make ROBOTEST_FILTER=NetworkScorerPickerPreferenceControllerTest RunSettingsRoboTests -j40 Change-Id: I6dbd18abd67613ed0f85a52f1a3e13fdab0dca6c
This commit is contained in:
@@ -56,6 +56,13 @@ public class NetworkScoreManagerWrapper {
|
||||
return mNetworkScoreManager.getActiveScorerPackage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns metadata about the active scorer or <code>null</code> if there is no active scorer.
|
||||
*/
|
||||
@Nullable
|
||||
public NetworkScorerAppData getActiveScorer() {
|
||||
return mNetworkScoreManager.getActiveScorer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the active scorer to a new package and clear existing scores.
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.NetworkScorerAppData;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
|
||||
/**
|
||||
* {@link PreferenceController} that shows the active network scorer and toggles the preference
|
||||
* based on {@link Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED}.
|
||||
*/
|
||||
public class NetworkScorerPickerPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_NETWORK_SCORER_PICKER = "network_scorer_picker";
|
||||
|
||||
private final NetworkScoreManagerWrapper mNetworkScoreManager;
|
||||
|
||||
public NetworkScorerPickerPreferenceController(Context context,
|
||||
NetworkScoreManagerWrapper networkScoreManager) {
|
||||
super(context);
|
||||
mNetworkScoreManager = networkScoreManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NETWORK_SCORER_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
boolean enabled = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
|
||||
preference.setEnabled(enabled);
|
||||
if (!enabled) {
|
||||
preference.setSummary(null);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkScorerAppData scorer = mNetworkScoreManager.getActiveScorer();
|
||||
if (scorer == null) {
|
||||
preference.setSummary(mContext.getString(
|
||||
R.string.network_scorer_picker_none_preference));
|
||||
} else {
|
||||
preference.setSummary(scorer.getRecommendationServiceLabel());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user