Snap for 12855999 from 64624ae43f to 25Q2-release
Change-Id: Ief2d8fd9fe60a6619fc1b1145d35775f17f5dba2
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/main_frame"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start|center_vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/icon_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="56dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:hyphenationFrequency="normalFast"
|
||||
android:lineBreakWordStyle="phrase"
|
||||
android:ellipsize="marquee" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:hyphenationFrequency="normalFast"
|
||||
android:lineBreakWordStyle="phrase"
|
||||
android:maxLines="10" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<!-- Preference should place its actual preference widget here. -->
|
||||
<LinearLayout
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:paddingHorizontal="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:minWidth="58dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -28,23 +28,28 @@
|
||||
android:key="flash_notifications_illustration"
|
||||
settings:searchable="false"
|
||||
settings:lottie_rawRes="@drawable/flash_notifications_illustration"
|
||||
settings:controller="com.android.settings.accessibility.FlashNotificationIllustrationPreferenceController"/>
|
||||
settings:controller="com.android.settings.accessibility.FlashNotificationIllustrationPreferenceController" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="camera_flash_notification_preference"
|
||||
android:persistent="false"
|
||||
android:title="@string/camera_flash_notification_title"
|
||||
settings:controller="com.android.settings.accessibility.CameraFlashNotificationPreferenceController" />
|
||||
<PreferenceCategory
|
||||
android:key="flash_notifications_category"
|
||||
android:layout="@layout/settingslib_preference_category_no_title">
|
||||
<SwitchPreferenceCompat
|
||||
android:key="camera_flash_notification_preference"
|
||||
android:persistent="false"
|
||||
android:title="@string/camera_flash_notification_title"
|
||||
settings:controller="com.android.settings.accessibility.CameraFlashNotificationPreferenceController" />
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="screen_flash_notification_preference"
|
||||
android:persistent="false"
|
||||
android:title="@string/screen_flash_notification_title"
|
||||
settings:controller="com.android.settings.accessibility.ScreenFlashNotificationPreferenceController" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="screen_flash_notification_preference"
|
||||
android:persistent="false"
|
||||
android:title="@string/screen_flash_notification_title"
|
||||
settings:controller="com.android.settings.accessibility.ScreenFlashNotificationPreferenceController" />
|
||||
|
||||
<com.android.settings.accessibility.FlashNotificationsPreviewPreference
|
||||
<com.android.settingslib.widget.ButtonPreference
|
||||
android:key="flash_notifications_preview"
|
||||
android:title="@string/flash_notifications_preview"
|
||||
settings:buttonPreferenceSize="extra"
|
||||
settings:buttonPreferenceType="filled"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.accessibility.FlashNotificationsPreviewPreferenceController" />
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
/**
|
||||
* Preference for Flash notifications preview.
|
||||
*/
|
||||
public class FlashNotificationsPreviewPreference extends Preference {
|
||||
private Drawable mBackgroundEnabled;
|
||||
private Drawable mBackgroundDisabled;
|
||||
@ColorInt
|
||||
private int mTextColorDisabled;
|
||||
|
||||
public FlashNotificationsPreviewPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public FlashNotificationsPreviewPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public FlashNotificationsPreviewPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public FlashNotificationsPreviewPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayoutResource(R.layout.flash_notification_preview_preference);
|
||||
mBackgroundEnabled = getContext().getDrawable(
|
||||
com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
|
||||
mBackgroundDisabled = getContext().getDrawable(R.drawable.switch_bar_bg_disabled);
|
||||
mTextColorDisabled = Utils.getColorAttrDefaultColor(getContext(),
|
||||
android.R.attr.textColorPrimary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final boolean enabled = isEnabled();
|
||||
final View frame = holder.findViewById(R.id.frame);
|
||||
if (frame != null) {
|
||||
frame.setBackground(enabled ? mBackgroundEnabled : mBackgroundDisabled);
|
||||
}
|
||||
final TextView title = (TextView) holder.findViewById(android.R.id.title);
|
||||
if (title != null) {
|
||||
@ColorInt final int textColorEnabled = title.getCurrentTextColor();
|
||||
title.setAlpha(enabled ? 1f : 0.38f);
|
||||
title.setTextColor(enabled ? textColorEnabled : mTextColorDisabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.ButtonPreference;
|
||||
|
||||
/**
|
||||
* Controller for flash notifications preview.
|
||||
@@ -48,7 +49,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
public class FlashNotificationsPreviewPreferenceController extends
|
||||
BasePreferenceController implements LifecycleEventObserver {
|
||||
|
||||
private Preference mPreference;
|
||||
private ButtonPreference mPreference;
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -74,19 +75,14 @@ public class FlashNotificationsPreviewPreferenceController extends
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
Intent intent = new Intent(ACTION_FLASH_NOTIFICATION_START_PREVIEW);
|
||||
intent.putExtra(EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE, TYPE_SHORT_PREVIEW);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
|
||||
return true;
|
||||
if (mPreference != null) {
|
||||
mPreference.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(ACTION_FLASH_NOTIFICATION_START_PREVIEW);
|
||||
intent.putExtra(EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE, TYPE_SHORT_PREVIEW);
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
|
||||
});
|
||||
}
|
||||
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,22 +18,23 @@ package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.SettingsThemeHelper;
|
||||
import com.android.settingslib.widget.TwoTargetPreference;
|
||||
|
||||
/**
|
||||
* Preference that can enable accessibility shortcut and let users choose which shortcut type they
|
||||
* prefer to use.
|
||||
*/
|
||||
public class ShortcutPreference extends Preference {
|
||||
public class ShortcutPreference extends TwoTargetPreference {
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the toggle or settings has been
|
||||
@@ -61,8 +62,6 @@ public class ShortcutPreference extends Preference {
|
||||
|
||||
ShortcutPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.accessibility_shortcut_secondary_action);
|
||||
setWidgetLayoutResource(androidx.preference.R.layout.preference_widget_switch_compat);
|
||||
setIconSpaceReserved(false);
|
||||
// Treat onSettingsClicked as this preference's click.
|
||||
setOnPreferenceClickListener(preference -> {
|
||||
@@ -71,25 +70,30 @@ public class ShortcutPreference extends Preference {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return SettingsThemeHelper.isExpressiveTheme(getContext())
|
||||
? com.android.settingslib.widget.theme.R.layout
|
||||
.settingslib_expressive_preference_switch
|
||||
: androidx.preference.R.layout.preference_widget_switch_compat;
|
||||
}
|
||||
|
||||
int getSwitchResId() {
|
||||
return SettingsThemeHelper.isExpressiveTheme(getContext())
|
||||
? com.android.settingslib.widget.theme.R.id.switchWidget
|
||||
: androidx.preference.R.id.switchWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final TypedValue outValue = new TypedValue();
|
||||
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
|
||||
outValue, true);
|
||||
|
||||
final LinearLayout mainFrame = holder.itemView.findViewById(R.id.main_frame);
|
||||
if (mainFrame != null) {
|
||||
mainFrame.setOnClickListener(view -> callOnSettingsClicked());
|
||||
mainFrame.setClickable(mSettingsEditable);
|
||||
mainFrame.setFocusable(mSettingsEditable);
|
||||
mainFrame.setBackgroundResource(
|
||||
mSettingsEditable ? outValue.resourceId : /* Remove background */ 0);
|
||||
final View widgetFrame = holder.findViewById(android.R.id.widget_frame);
|
||||
if (widgetFrame instanceof LinearLayout linearLayout) {
|
||||
linearLayout.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
|
||||
}
|
||||
|
||||
CompoundButton switchWidget =
|
||||
holder.itemView.findViewById(androidx.preference.R.id.switchWidget);
|
||||
CompoundButton switchWidget = holder.itemView.findViewById(getSwitchResId());
|
||||
if (switchWidget != null) {
|
||||
// Consumes move events to ignore drag actions.
|
||||
switchWidget.setOnTouchListener((v, event) -> {
|
||||
@@ -101,18 +105,21 @@ public class ShortcutPreference extends Preference {
|
||||
switchWidget.setOnClickListener(view -> callOnToggleClicked());
|
||||
switchWidget.setClickable(mSettingsEditable);
|
||||
switchWidget.setFocusable(mSettingsEditable);
|
||||
switchWidget.setBackgroundResource(
|
||||
mSettingsEditable ? outValue.resourceId : /* Remove background */ 0);
|
||||
}
|
||||
|
||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||
final View divider = holder.itemView.findViewById(
|
||||
com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
|
||||
if (divider != null) {
|
||||
divider.setVisibility(mSettingsEditable ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(view -> callOnToggleClicked());
|
||||
holder.itemView.setClickable(!mSettingsEditable);
|
||||
holder.itemView.setFocusable(!mSettingsEditable);
|
||||
holder.itemView.setOnClickListener(view -> {
|
||||
if (mSettingsEditable) {
|
||||
callOnSettingsClicked();
|
||||
} else {
|
||||
callOnToggleClicked();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -37,13 +36,16 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settingslib.widget.ButtonPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -51,7 +53,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
@@ -71,20 +72,21 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
||||
private ContentResolver mContentResolver = mContext.getContentResolver();
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private Preference mPreference;
|
||||
private ButtonPreference mPreference;
|
||||
private FlashNotificationsPreviewPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference = new ButtonPreference(mContext);
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
final View rootView = View.inflate(mContext, mPreference.getLayoutResource(), null);
|
||||
mPreference.onBindViewHolder(PreferenceViewHolder.createInstanceForTests(rootView));
|
||||
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
||||
|
||||
mController = new FlashNotificationsPreviewPreferenceController(mContext, PREFERENCE_KEY);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -98,67 +100,58 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_torchPresent_cameraOff_screenOff_notVisible() {
|
||||
public void updateState_cameraOff_screenOff_notVisible() {
|
||||
setFlashNotificationsState(FlashNotificationsUtil.State.OFF);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_torchPresent_cameraOn_screenOff_isVisible() {
|
||||
public void updateState_cameraOn_screenOff_isVisible() {
|
||||
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_torchPresent_cameraOff_screenOn_isVisible() {
|
||||
public void updateState_cameraOff_screenOn_isVisible() {
|
||||
setFlashNotificationsState(FlashNotificationsUtil.State.SCREEN);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_torchPresent_cameraOn_screenOn_isVisible() {
|
||||
public void updateState_cameraOn_screenOn_isVisible() {
|
||||
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA_SCREEN);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_invalidPreference() {
|
||||
mController.handlePreferenceTreeClick(mock(Preference.class));
|
||||
|
||||
verify(mContext, never()).sendBroadcastAsUser(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_assertAction() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
public void clickOnButton_assertAction() {
|
||||
mPreference.getButton().callOnClick();
|
||||
|
||||
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).sendBroadcastAsUser(captor.capture(), any());
|
||||
Intent captured = captor.getValue();
|
||||
|
||||
assertThat(captured.getAction()).isEqualTo(ACTION_FLASH_NOTIFICATION_START_PREVIEW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_assertExtra() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
public void clickOnButton_assertExtra() {
|
||||
mPreference.getButton().callOnClick();
|
||||
|
||||
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).sendBroadcastAsUser(captor.capture(), any());
|
||||
Intent captured = captor.getValue();
|
||||
|
||||
assertThat(captured.getIntExtra(EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE, TYPE_LONG_PREVIEW))
|
||||
.isEqualTo(TYPE_SHORT_PREVIEW);
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.Shadows;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FlashNotificationsPreviewPreferenceTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private FlashNotificationsPreviewPreference mFlashNotificationsPreviewPreference;
|
||||
private PreferenceViewHolder mPreferenceViewHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(
|
||||
LayoutInflater.from(mContext).inflate(
|
||||
R.layout.flash_notification_preview_preference, null));
|
||||
mFlashNotificationsPreviewPreference = new FlashNotificationsPreviewPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setEnabled_true_verifyEnabledUi() {
|
||||
@ColorInt final int textColorEnabled = ((TextView) mPreferenceViewHolder.findViewById(
|
||||
android.R.id.title)).getCurrentTextColor();
|
||||
|
||||
mFlashNotificationsPreviewPreference.setEnabled(true);
|
||||
mFlashNotificationsPreviewPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final View frame = mPreferenceViewHolder.findViewById(R.id.frame);
|
||||
final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId();
|
||||
assertThat(backgroundResId).isEqualTo(
|
||||
com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
|
||||
final TextView title = (TextView) mPreferenceViewHolder.findViewById(android.R.id.title);
|
||||
assertThat(title.getAlpha()).isEqualTo(1f);
|
||||
assertThat(title.getCurrentTextColor()).isEqualTo(textColorEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setEnabled_false_verifyDisabledUi() {
|
||||
@ColorInt final int textColorDisabled = Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.textColorPrimary);
|
||||
|
||||
mFlashNotificationsPreviewPreference.setEnabled(false);
|
||||
mFlashNotificationsPreviewPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final View frame = mPreferenceViewHolder.findViewById(R.id.frame);
|
||||
final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId();
|
||||
assertThat(backgroundResId).isEqualTo(R.drawable.switch_bar_bg_disabled);
|
||||
final TextView title = (TextView) mPreferenceViewHolder.findViewById(android.R.id.title);
|
||||
assertThat(title.getAlpha()).isEqualTo(0.38f);
|
||||
assertThat(title.getCurrentTextColor()).isEqualTo(textColorDisabled);
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,13 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.SettingsThemeHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -40,10 +42,10 @@ public class ShortcutPreferenceTest {
|
||||
private static final String SETTINGS_CLICKED = "settings_clicked";
|
||||
|
||||
private ShortcutPreference mShortcutPreference;
|
||||
private PreferenceViewHolder mPreferenceViewHolder;
|
||||
private PreferenceViewHolder mViewHolder;
|
||||
private String mResult;
|
||||
|
||||
private ShortcutPreference.OnClickCallback mListener =
|
||||
private final ShortcutPreference.OnClickCallback mListener =
|
||||
new ShortcutPreference.OnClickCallback() {
|
||||
@Override
|
||||
public void onToggleClicked(ShortcutPreference preference) {
|
||||
@@ -61,30 +63,49 @@ public class ShortcutPreferenceTest {
|
||||
final Context context = ApplicationProvider.getApplicationContext();
|
||||
mShortcutPreference = new ShortcutPreference(context, null);
|
||||
|
||||
int resID = SettingsThemeHelper.isExpressiveTheme(context)
|
||||
? com.android.settingslib.widget.preference.twotarget.R.layout
|
||||
.settingslib_expressive_preference_two_target
|
||||
: com.android.settingslib.widget.preference.twotarget.R.layout
|
||||
.preference_two_target;
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
final View view =
|
||||
inflater.inflate(R.layout.accessibility_shortcut_secondary_action, null);
|
||||
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
final View view = inflater.inflate(resID, null);
|
||||
mViewHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
|
||||
final LinearLayout widget = mViewHolder.itemView.findViewById(android.R.id.widget_frame);
|
||||
inflater.inflate(mShortcutPreference.getSecondTargetResId(), widget, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickToggle_toggleClicked() {
|
||||
mShortcutPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
mShortcutPreference.onBindViewHolder(mViewHolder);
|
||||
mShortcutPreference.setOnClickCallback(mListener);
|
||||
|
||||
mPreferenceViewHolder.itemView.performClick();
|
||||
CompoundButton switchWidget = mViewHolder.itemView.findViewById(
|
||||
mShortcutPreference.getSwitchResId());
|
||||
assert switchWidget != null;
|
||||
switchWidget.performClick();
|
||||
|
||||
assertThat(mResult).isEqualTo(TOGGLE_CLICKED);
|
||||
assertThat(mShortcutPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickSettings_settingsClicked() {
|
||||
mShortcutPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
public void clickItem_settingsClicked() {
|
||||
mShortcutPreference.onBindViewHolder(mViewHolder);
|
||||
mShortcutPreference.setOnClickCallback(mListener);
|
||||
|
||||
final View settings = mPreferenceViewHolder.itemView.findViewById(R.id.main_frame);
|
||||
settings.performClick();
|
||||
mViewHolder.itemView.performClick();
|
||||
|
||||
assertThat(mResult).isEqualTo(SETTINGS_CLICKED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPreference_settingsClicked() {
|
||||
mShortcutPreference.onBindViewHolder(mViewHolder);
|
||||
mShortcutPreference.setOnClickCallback(mListener);
|
||||
|
||||
mShortcutPreference.performClick();
|
||||
|
||||
assertThat(mResult).isEqualTo(SETTINGS_CLICKED);
|
||||
}
|
||||
@@ -95,13 +116,4 @@ public class ShortcutPreferenceTest {
|
||||
|
||||
assertThat(mShortcutPreference.isChecked()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClickOnPreference_settingsClicked() {
|
||||
mShortcutPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
mShortcutPreference.setOnClickCallback(mListener);
|
||||
mShortcutPreference.performClick();
|
||||
|
||||
assertThat(mResult).isEqualTo(SETTINGS_CLICKED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user