Add summary provider for system tile.
Refactored getLocaleNames() into a FeatureProvider interface so it's reusable and testable. Bug: 31801428 Test: RunSettingsRoboTests Change-Id: I2d31a66a4b32cfa7a364a4cfef1f6eea87084577
This commit is contained in:
@@ -5919,6 +5919,8 @@
|
||||
<string name="network_dashboard_title">Network & Internet</string>
|
||||
<!-- Title for setting tile leading to Connected devices settings [CHAR LIMIT=40]-->
|
||||
<string name="connected_devices_dashboard_title">Connected devices</string>
|
||||
<!-- Summary text for system preference tile, showing current display language of device [CHAR LIMIT=NONE]-->
|
||||
<string name="system_dashboard_summary">Language: <xliff:g id="language">%1$s</xliff:g></string>
|
||||
|
||||
<!-- Search strings -->
|
||||
<!-- Text to describe the search results fragment title [CHAR LIMIT=16] -->
|
||||
|
@@ -234,8 +234,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
if (tile.icon != null) {
|
||||
pref.setIcon(tile.icon.loadDrawable(context));
|
||||
}
|
||||
final Intent intent = new Intent(tile.intent);
|
||||
if (intent != null) {
|
||||
if (tile.intent != null) {
|
||||
final Intent intent = new Intent(tile.intent);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
|
||||
getActivity().startActivityForResult(intent, 0);
|
||||
|
@@ -32,7 +32,6 @@ import android.hardware.input.InputManager;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.LocaleList;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.System;
|
||||
import android.speech.tts.TtsEngines;
|
||||
@@ -51,8 +50,6 @@ import android.view.inputmethod.InputMethodSubtype;
|
||||
import android.view.textservice.SpellCheckerInfo;
|
||||
import android.view.textservice.TextServicesManager;
|
||||
|
||||
import com.android.internal.app.LocaleHelper;
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings.KeyboardLayoutPickerActivity;
|
||||
@@ -63,6 +60,8 @@ import com.android.settings.UserDictionarySettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.VoiceInputOutputSettings;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
@@ -74,7 +73,6 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
@@ -275,7 +273,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
|
||||
if (!mShowsOnlyFullImeAndKeyboardList) {
|
||||
if (mLanguagePref != null) {
|
||||
String localeNames = getLocaleNames(getActivity());
|
||||
final String localeNames = FeatureFactory.getFactory(getContext())
|
||||
.getLocaleFeatureProvider().getLocaleNames();
|
||||
mLanguagePref.setSummary(localeNames);
|
||||
}
|
||||
|
||||
@@ -349,14 +348,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private static String getLocaleNames(Context context) {
|
||||
final LocaleList locales = LocalePicker.getLocales();
|
||||
final Locale displayLocale = Locale.getDefault();
|
||||
return LocaleHelper.toSentenceCase(
|
||||
LocaleHelper.getDisplayLocaleList(
|
||||
locales, displayLocale, 2 /* Show up to two locales from the list */),
|
||||
displayLocale);
|
||||
}
|
||||
|
||||
|
||||
private void saveInputMethodSelectorVisibility(String value) {
|
||||
try {
|
||||
@@ -667,16 +659,18 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private LocaleFeatureProvider mLocaleFeatureProvider;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mLocaleFeatureProvider = FeatureFactory.getFactory(context).getLocaleFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
String localeNames = getLocaleNames(mContext);
|
||||
String localeNames = mLocaleFeatureProvider.getLocaleNames();
|
||||
mSummaryLoader.setSummary(this, localeNames);
|
||||
}
|
||||
}
|
||||
@@ -701,7 +695,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
|
||||
// Locale picker.
|
||||
if (context.getAssets().getLocales().length > 1) {
|
||||
String localeNames = getLocaleNames(context);
|
||||
String localeNames = FeatureFactory.getFactory(context).getLocaleFeatureProvider()
|
||||
.getLocaleNames();
|
||||
SearchIndexableRaw indexable = new SearchIndexableRaw(context);
|
||||
indexable.key = KEY_PHONE_LANGUAGE;
|
||||
indexable.title = context.getString(R.string.phone_language);
|
||||
|
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.localepicker;
|
||||
|
||||
public interface LocaleFeatureProvider {
|
||||
|
||||
/**
|
||||
* Returns displayable string of device locales.
|
||||
*/
|
||||
String getLocaleNames();
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.localepicker;
|
||||
|
||||
import android.os.LocaleList;
|
||||
|
||||
import com.android.internal.app.LocaleHelper;
|
||||
import com.android.internal.app.LocalePicker;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocaleFeatureProviderImpl implements LocaleFeatureProvider {
|
||||
@Override
|
||||
public String getLocaleNames() {
|
||||
final LocaleList locales = LocalePicker.getLocales();
|
||||
final Locale displayLocale = Locale.getDefault();
|
||||
return LocaleHelper.toSentenceCase(
|
||||
LocaleHelper.getDisplayLocaleList(
|
||||
locales, displayLocale, 2 /* Show up to two locales from the list */),
|
||||
displayLocale);
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
|
||||
/**
|
||||
* Abstract class for creating feature controllers. Allows OEM implementations to define their own
|
||||
@@ -70,6 +71,9 @@ public abstract class FeatureFactory {
|
||||
|
||||
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
|
||||
|
||||
public abstract LocaleFeatureProvider getLocaleFeatureProvider();
|
||||
|
||||
|
||||
public static final class FactoryNotFoundException extends RuntimeException {
|
||||
public FactoryNotFoundException(Throwable throwable) {
|
||||
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
|
||||
|
@@ -24,6 +24,8 @@ import com.android.settings.core.instrumentation.MetricsFeatureProviderImpl;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
||||
|
||||
/**
|
||||
* {@link FeatureFactory} implementation for AOSP Settings.
|
||||
@@ -33,6 +35,7 @@ public final class FeatureFactoryImpl extends FeatureFactory {
|
||||
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private DashboardFeatureProviderImpl mDashboardFeatureProvider;
|
||||
private LocaleFeatureProvider mLocaleFeatureProvider;
|
||||
|
||||
@Override
|
||||
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
||||
@@ -60,4 +63,11 @@ public final class FeatureFactoryImpl extends FeatureFactory {
|
||||
return mDashboardFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleFeatureProvider getLocaleFeatureProvider() {
|
||||
if (mLocaleFeatureProvider == null) {
|
||||
mLocaleFeatureProvider = new LocaleFeatureProviderImpl();
|
||||
}
|
||||
return mLocaleFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -22,8 +22,10 @@ import android.provider.SearchIndexableResource;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
|
||||
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
@@ -66,6 +68,34 @@ public class SystemDashboardFragment extends DashboardFragment {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Summary
|
||||
*/
|
||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private final LocaleFeatureProvider mLocaleFeatureProvider;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mLocaleFeatureProvider = FeatureFactory.getFactory(context).getLocaleFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
final String language = mContext.getString(
|
||||
R.string.system_dashboard_summary, mLocaleFeatureProvider.getLocaleNames());
|
||||
mSummaryLoader.setSummary(this, language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
|
||||
(context, summaryLoader) -> new SummaryProvider(context, summaryLoader);
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.system;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import com.google.common.truth.Truth;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.android.settings.system.SystemDashboardFragment.SUMMARY_PROVIDER_FACTORY;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SystemDashboardFragmentTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSummaryProvider() {
|
||||
Truth.assertThat(SUMMARY_PROVIDER_FACTORY).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_isListening_shouldNotifySummaryLoader() {
|
||||
final SummaryLoader.SummaryProvider summaryProvider =
|
||||
SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, mSummaryLoader);
|
||||
summaryProvider.setListening(true);
|
||||
|
||||
verify(mSummaryLoader).setSummary(eq(summaryProvider), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_notListening_shouldNotNotifySummaryLoader() {
|
||||
final SummaryLoader.SummaryProvider summaryProvider =
|
||||
SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, mSummaryLoader);
|
||||
summaryProvider.setListening(false);
|
||||
|
||||
verify(mSummaryLoader, never()).setSummary(eq(summaryProvider), anyString());
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.overlay.SupportFeatureProvider;
|
||||
|
||||
@@ -37,6 +38,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final MetricsFeatureProvider metricsFeatureProvider;
|
||||
public final PowerUsageFeatureProvider powerUsageFeatureProvider;
|
||||
public final DashboardFeatureProvider dashboardFeatureProvider;
|
||||
public final LocaleFeatureProvider localeFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -63,6 +65,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
metricsFeatureProvider = mock(MetricsFeatureProvider.class);
|
||||
powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
|
||||
dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
|
||||
localeFeatureProvider = mock(LocaleFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,4 +87,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
|
||||
return dashboardFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleFeatureProvider getLocaleFeatureProvider() {
|
||||
return localeFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user