Snap for 5231632 from b2778bd40c to qt-release
Change-Id: Ia8663eac9adb1b297d14765217a7a8df53f7761b
This commit is contained in:
@@ -2595,7 +2595,7 @@
|
||||
android:exported="true"
|
||||
android:permission="android.permission.NETWORK_SETTINGS">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.wifi.NETWORK_REQUEST" />
|
||||
<action android:name="com.android.settings.wifi.action.NETWORK_REQUEST" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@@ -25,5 +25,5 @@
|
||||
<androidx.slice.widget.SliceView
|
||||
android:id="@+id/slice_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="@dimen/slice_preference_group_height"/>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -370,4 +370,6 @@
|
||||
<dimen name="qrcode_size">264dp</dimen>
|
||||
<dimen name="qrcode_preview_size">360dp</dimen>
|
||||
|
||||
<!-- Height for slice preference, which contains 6 items at most -->
|
||||
<dimen name="slice_preference_group_height">360dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -7147,7 +7147,7 @@
|
||||
<!-- Sound: Other sounds: Title for the option enabling touch sounds for screen locking sounds. [CHAR LIMIT=30] -->
|
||||
<string name="screen_locking_sounds_title">Screen locking sounds</string>
|
||||
|
||||
<!-- Sound: Other sounds: Title for the option enabling charging sounds and vibration. [CHAR LIMIT=30] -->
|
||||
<!-- Sound: Other sounds: Title for the option enabling charging sounds and vibration. [CHAR LIMIT=50] -->
|
||||
<string name="charging_sounds_title">Charging sounds and vibration</string>
|
||||
|
||||
<!-- Sound: Other sounds: Title for the option enabling docking sounds. [CHAR LIMIT=30] -->
|
||||
@@ -7355,6 +7355,12 @@
|
||||
<!-- Do not disturb: Label for button that will turn off zen mode. [CHAR LIMIT=30] -->
|
||||
<string name="zen_mode_button_turn_off">Turn off now</string>
|
||||
|
||||
<!-- Setting title for controlling how caption text display in real time [CHAR LIMIT=40]-->
|
||||
<string name="live_captions_title">Live Caption</string>
|
||||
|
||||
<!-- Setting summary for controlling how caption text display in real time [CHAR LIMIT=NONE]-->
|
||||
<string name="live_captions_summary">Auto-convert on-device audio to captions</string>
|
||||
|
||||
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
|
||||
<string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
|
||||
|
||||
|
||||
@@ -124,6 +124,12 @@
|
||||
android:key="audio_and_captions_category"
|
||||
android:title="@string/audio_and_captions_category_title">
|
||||
|
||||
<Preference
|
||||
android:key="live_caption"
|
||||
android:title="@string/live_captions_title"
|
||||
android:summary="@string/live_captions_summary"
|
||||
settings:controller="com.android.settings.accessibility.LiveCaptionPreferenceController"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="toggle_master_mono"
|
||||
android:title="@string/accessibility_toggle_master_mono_title"
|
||||
|
||||
@@ -91,7 +91,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
|
||||
private static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
|
||||
|
||||
private static final String[] CATEGORIES = new String[] {
|
||||
private static final String[] CATEGORIES = new String[]{
|
||||
CATEGORY_SCREEN_READER, CATEGORY_AUDIO_AND_CAPTIONS, CATEGORY_DISPLAY,
|
||||
CATEGORY_INTERACTION_CONTROL, CATEGORY_EXPERIMENTAL, CATEGORY_DOWNLOADED_SERVICES
|
||||
};
|
||||
@@ -132,7 +132,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
"accessibility_content_timeout_preference_fragment";
|
||||
private static final String ACCESSIBILITY_CONTROL_TIMEOUT_PREFERENCE =
|
||||
"accessibility_control_timeout_preference_fragment";
|
||||
|
||||
private static final String LIVE_CAPTION_PREFERENCE_KEY =
|
||||
"live_caption";
|
||||
|
||||
// Extras passed to sub-fragments.
|
||||
static final String EXTRA_PREFERENCE_KEY = "preference_key";
|
||||
@@ -232,9 +233,11 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
private Preference mDisplayDaltonizerPreferenceScreen;
|
||||
private Preference mHearingAidPreference;
|
||||
private Preference mVibrationPreferenceScreen;
|
||||
private Preference mLiveCaptionPreference;
|
||||
private SwitchPreference mToggleInversionPreference;
|
||||
private ColorInversionPreferenceController mInversionPreferenceController;
|
||||
private AccessibilityHearingAidPreferenceController mHearingAidPreferenceController;
|
||||
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
||||
|
||||
private int mLongPressTimeoutDefault;
|
||||
|
||||
@@ -293,6 +296,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
(context, HEARING_AID_PREFERENCE);
|
||||
mHearingAidPreferenceController.setFragmentManager(getFragmentManager());
|
||||
getLifecycle().addObserver(mHearingAidPreferenceController);
|
||||
|
||||
mLiveCaptionPreferenceController = new LiveCaptionPreferenceController(context,
|
||||
LIVE_CAPTION_PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -481,6 +487,10 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
// Captioning.
|
||||
mCaptioningPreferenceScreen = findPreference(CAPTIONING_PREFERENCE_SCREEN);
|
||||
|
||||
// Live caption
|
||||
mLiveCaptionPreference = findPreference(LIVE_CAPTION_PREFERENCE_KEY);
|
||||
mLiveCaptionPreferenceController.displayPreference(getPreferenceScreen());
|
||||
|
||||
// Display magnification.
|
||||
mDisplayMagnificationPreferenceScreen = findPreference(
|
||||
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
||||
@@ -716,6 +726,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
|
||||
mHearingAidPreferenceController.updateState(mHearingAidPreference);
|
||||
|
||||
mLiveCaptionPreferenceController.updateState(mLiveCaptionPreference);
|
||||
|
||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED,
|
||||
mCaptioningPreferenceScreen);
|
||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||
@@ -736,7 +748,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
|
||||
void updateAccessibilityTimeoutSummary(ContentResolver resolver, Preference pref) {
|
||||
|
||||
String[] timeoutSummarys = getResources().getStringArray(
|
||||
R.array.accessibility_timeout_summaries);
|
||||
int[] timeoutValues = getResources().getIntArray(
|
||||
@@ -805,7 +816,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
pref.setSummary(entries[index]);
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
@VisibleForTesting
|
||||
void updateVibrationSummary(Preference pref) {
|
||||
final Context context = getContext();
|
||||
final Vibrator vibrator = context.getSystemService(Vibrator.class);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LiveCaptionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final Intent LIVE_CAPTION_INTENT = new Intent(
|
||||
"com.android.settings.action.live_caption");
|
||||
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
public LiveCaptionPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mPackageManager = context.getPackageManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final List<ResolveInfo> resolved =
|
||||
mPackageManager.queryIntentActivities(LIVE_CAPTION_INTENT, 0 /* flags */);
|
||||
return resolved != null && !resolved.isEmpty()
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
preference.setIntent(LIVE_CAPTION_INTENT);
|
||||
}
|
||||
}
|
||||
@@ -369,11 +369,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
mPreferenceControllers.values()) {
|
||||
for (AbstractPreferenceController controller : controllerList) {
|
||||
final String key = controller.getPreferenceKey();
|
||||
if(TextUtils.isEmpty(key)) {
|
||||
Log.d(TAG, String.format("Preference key is %s in Controller %s",
|
||||
key, controller.getClass().getSimpleName()));
|
||||
continue;
|
||||
}
|
||||
final Preference preference = screen.findPreference(key);
|
||||
if (preference != null) {
|
||||
preference.setVisible(visible && controller.isAvailable());
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
/**
|
||||
* A custom preference that provides inline checkbox and tappable target.
|
||||
*/
|
||||
public class ChannelSummaryPreference extends TwoTargetPreference {
|
||||
|
||||
private Context mContext;
|
||||
private Intent mIntent;
|
||||
private CheckBox mCheckBox;
|
||||
private boolean mChecked;
|
||||
private boolean mEnableCheckBox = true;
|
||||
|
||||
public ChannelSummaryPreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.preference_checkable_two_target);
|
||||
mContext = context;
|
||||
setWidgetLayoutResource(R.layout.zen_rule_widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
View settingsWidget = view.findViewById(android.R.id.widget_frame);
|
||||
View divider = view.findViewById(R.id.two_target_divider);
|
||||
if (mIntent != null) {
|
||||
divider.setVisibility(View.VISIBLE);
|
||||
settingsWidget.setVisibility(View.VISIBLE);
|
||||
settingsWidget.setOnClickListener(v -> mContext.startActivity(mIntent));
|
||||
} else {
|
||||
divider.setVisibility(View.GONE);
|
||||
settingsWidget.setVisibility(View.GONE);
|
||||
settingsWidget.setOnClickListener(null);
|
||||
}
|
||||
|
||||
View checkboxContainer = view.findViewById(R.id.checkbox_container);
|
||||
if (checkboxContainer != null) {
|
||||
checkboxContainer.setOnClickListener(mOnCheckBoxClickListener);
|
||||
}
|
||||
mCheckBox = (CheckBox) view.findViewById(com.android.internal.R.id.checkbox);
|
||||
if (mCheckBox != null) {
|
||||
mCheckBox.setChecked(mChecked);
|
||||
mCheckBox.setEnabled(mEnableCheckBox);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return mChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntent(Intent intent) {
|
||||
mIntent = intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
mOnCheckBoxClickListener.onClick(null);
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
mChecked = checked;
|
||||
if (mCheckBox != null) {
|
||||
mCheckBox.setChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCheckBoxEnabled(boolean enabled) {
|
||||
mEnableCheckBox = enabled;
|
||||
if (mCheckBox != null) {
|
||||
mCheckBox.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
private View.OnClickListener mOnCheckBoxClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mCheckBox != null && !mCheckBox.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
setChecked(!mChecked);
|
||||
if (!callChangeListener(mChecked)) {
|
||||
setChecked(!mChecked);
|
||||
} else {
|
||||
persistBoolean(mChecked);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -273,8 +273,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
|
||||
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
||||
final NotificationChannel channel, final boolean groupBlocked) {
|
||||
MasterCheckBoxPreference channelPref = new MasterCheckBoxPreference(
|
||||
getPrefContext());
|
||||
ChannelSummaryPreference channelPref = new ChannelSummaryPreference(getPrefContext());
|
||||
channelPref.setCheckBoxEnabled(mSuspendedAppsAdmin == null
|
||||
&& isChannelBlockable(channel)
|
||||
&& isChannelConfigurable(channel)
|
||||
|
||||
@@ -44,6 +44,7 @@ public class SlicePreference extends LayoutPreference {
|
||||
private void init() {
|
||||
mSliceView = findViewById(R.id.slice_view);
|
||||
mSliceView.showTitleItems(true);
|
||||
mSliceView.setScrollable(false);
|
||||
}
|
||||
|
||||
public void onSliceUpdated(Slice slice) {
|
||||
|
||||
@@ -50,7 +50,6 @@ public class SlicePreferenceController extends BasePreferenceController implemen
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mSlicePreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LiveCaptionPreferenceControllerTest {
|
||||
|
||||
private LiveCaptionPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new LiveCaptionPreferenceController(RuntimeEnvironment.application,
|
||||
"test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_canResolveIntent_shouldReturnAvailable() {
|
||||
final ShadowPackageManager pm = Shadows.shadowOf(
|
||||
RuntimeEnvironment.application.getPackageManager());
|
||||
pm.addResolveInfoForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT,
|
||||
new ResolveInfo());
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noResolveIntent_shouldReturnUnavailable() {
|
||||
final ShadowPackageManager pm = Shadows.shadowOf(
|
||||
RuntimeEnvironment.application.getPackageManager());
|
||||
pm.setResolveInfosForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT,
|
||||
Collections.emptyList());
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.notification;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ChannelSummaryPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewPreference_shouldSetLayout() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
assertThat(preference.getLayoutResource()).isEqualTo(
|
||||
R.layout.preference_checkable_two_target);
|
||||
assertThat(preference.getWidgetLayoutResource()).isEqualTo(
|
||||
R.layout.zen_rule_widget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_shouldUpdateButtonCheckedState() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
inflater.inflate(R.layout.preference_checkable_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(R.id.checkbox_container);
|
||||
inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
|
||||
final CheckBox toggle = (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
preference.setChecked(true);
|
||||
assertThat(toggle.isChecked()).isTrue();
|
||||
|
||||
preference.setChecked(false);
|
||||
assertThat(toggle.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCheckboxEnabled_shouldUpdateButtonEnabledState() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
inflater.inflate(R.layout.preference_checkable_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(R.id.checkbox_container);
|
||||
inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
|
||||
final CheckBox toggle = (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
preference.setCheckBoxEnabled(true);
|
||||
assertThat(toggle.isEnabled()).isTrue();
|
||||
|
||||
preference.setCheckBoxEnabled(false);
|
||||
assertThat(toggle.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCheckBoxEnabled_shouldUpdateButtonEnabledState_beforeViewBound() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
inflater.inflate(R.layout.preference_checkable_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(R.id.checkbox_container);
|
||||
inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
|
||||
final CheckBox toggle = (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox);
|
||||
|
||||
preference.setCheckBoxEnabled(false);
|
||||
preference.onBindViewHolder(holder);
|
||||
assertThat(toggle.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickWidgetView_shouldToggleButton() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
inflater.inflate(R.layout.preference_checkable_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(R.id.checkbox_container);
|
||||
assertThat(widgetView).isNotNull();
|
||||
|
||||
inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
|
||||
final CheckBox toggle = (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
widgetView.performClick();
|
||||
assertThat(toggle.isChecked()).isTrue();
|
||||
|
||||
widgetView.performClick();
|
||||
assertThat(toggle.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickWidgetView_shouldNotToggleButtonIfDisabled() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
inflater.inflate(R.layout.preference_checkable_two_target, null));
|
||||
final LinearLayout widgetView = holder.itemView.findViewById(R.id.checkbox_container);
|
||||
assertThat(widgetView).isNotNull();
|
||||
|
||||
inflater.inflate(R.layout.preference_widget_checkbox, widgetView, true);
|
||||
final CheckBox toggle = (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox);
|
||||
preference.onBindViewHolder(holder);
|
||||
toggle.setEnabled(false);
|
||||
|
||||
widgetView.performClick();
|
||||
assertThat(toggle.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickWidgetView_shouldNotifyPreferenceChanged() {
|
||||
final ChannelSummaryPreference preference = new ChannelSummaryPreference(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
LayoutInflater.from(mContext).inflate(
|
||||
R.layout.preference_checkable_two_target, null));
|
||||
final View widgetView = holder.findViewById(R.id.checkbox_container);
|
||||
final Preference.OnPreferenceChangeListener
|
||||
listener = mock(Preference.OnPreferenceChangeListener.class);
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
preference.setChecked(false);
|
||||
widgetView.performClick();
|
||||
verify(listener).onPreferenceChange(preference, true);
|
||||
|
||||
preference.setChecked(true);
|
||||
widgetView.performClick();
|
||||
verify(listener).onPreferenceChange(preference, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user