+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingStart="8dp"
- android:orientation="horizontal">
-
- <Button
- android:id="@+id/button1"
- style="@style/SettingsActionButton"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-
- <Button
- android:id="@+id/button2"
- style="@style/SettingsActionButton"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-
- <Button
- android:id="@+id/button3"
- style="@style/SettingsActionButton"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-
- <Button
- android:id="@+id/button4"
- style="@style/SettingsActionButton"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-</LinearLayout>
\ No newline at end of file
<style name="ActionSecondaryButton" parent="android:Widget.DeviceDefault.Button"/>
- <style name="SettingsActionButton"
- parent="android:Widget.DeviceDefault.Button.Borderless.Colored">
- <item name="android:drawablePadding">4dp</item>
- <item name="android:drawableTint">@*android:color/btn_colored_borderless_text_material
- </item>
- <item name="android:layout_marginEnd">8dp</item>
- <item name="android:paddingTop">20dp</item>
- <item name="android:paddingBottom">20dp</item>
- </style>
-
<style name="LockPatternContainerStyle">
<item name="android:maxHeight">400dp</item>
<item name="android:maxWidth">420dp</item>
settings:allowDividerAbove="true"
settings:allowDividerBelow="true"/>
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons"
android:order="-9998" />
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/storage_label">
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="header_view" />
<com.android.settings.applications.SpacePreference
android:selectable="false"
settings:allowDividerBelow="true"/>
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons" />
<PreferenceCategory
android:order="-10000"
settings:allowDividerBelow="true"/>
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons"
android:order="-9999"/>
android:defaultValue="100"
android:max="400"/>
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons" />
</PreferenceCategory>
settings:allowDividerBelow="true"/>
<!-- Buttons -->
- <com.android.settings.widget.ActionButtonPreference
+ <com.android.settingslib.widget.ActionButtonsPreference
android:key="buttons"
android:selectable="false" />
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.deviceinfo.StorageWizardMoveConfirm;
-import com.android.settings.widget.ActionButtonPreference;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.applications.ApplicationsState.Callbacks;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import com.android.settingslib.widget.ActionButtonsPreference;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Collections;
// Views related to cache info
@VisibleForTesting
- ActionButtonPreference mButtonsPref;
+ ActionButtonsPreference mButtonsPref;
private Preference mStorageUsed;
private Button mChangeStorageButton;
.setComputingString(R.string.computing_size)
.setErrorString(R.string.invalid_size_value)
.build();
- mButtonsPref = ((ActionButtonPreference) findPreference(KEY_HEADER_BUTTONS));
+ mButtonsPref = ((ActionButtonsPreference) findPreference(KEY_HEADER_BUTTONS));
mStorageUsed = findPreference(KEY_STORAGE_USED);
mChangeStorageButton = (Button) ((LayoutPreference) findPreference(KEY_CHANGE_STORAGE))
.findViewById(R.id.button);
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.ActionButtonPreference;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.widget.ActionButtonsPreference;
import java.util.ArrayList;
import java.util.HashSet;
@VisibleForTesting
boolean mDisableAfterUninstall = false;
@VisibleForTesting
- ActionButtonPreference mButtonsPref;
+ ActionButtonsPreference mButtonsPref;
private final int mRequestUninstall;
private final int mRequestRemoveDeviceAdmin;
public int getAvailabilityStatus() {
// TODO(b/37313605): Re-enable once this controller supports instant apps
return mAppEntry != null && !AppUtils.isInstant(mAppEntry.info)
- ? AVAILABLE : DISABLED_FOR_USER ;
+ ? AVAILABLE : DISABLED_FOR_USER;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
- mButtonsPref = ((ActionButtonPreference) screen.findPreference(KEY_ACTION_BUTTONS))
+ mButtonsPref = ((ActionButtonsPreference) screen.findPreference(
+ KEY_ACTION_BUTTONS))
.setButton1Text(R.string.uninstall_text)
.setButton1Icon(R.drawable.ic_settings_delete)
.setButton2Text(R.string.force_stop)
} else {
Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART,
Uri.fromParts("package", mAppEntry.info.packageName, null));
- intent.putExtra(Intent.EXTRA_PACKAGES, new String[] {mAppEntry.info.packageName});
+ intent.putExtra(Intent.EXTRA_PACKAGES, new String[]{mAppEntry.info.packageName});
intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(mAppEntry.info.uid));
Log.d(TAG, "Sending broadcast to query restart status for "
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.widget.ActionButtonPreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.ActionButtonsPreference;
/**
* This class adds two buttons: one to connect/disconnect from a device (depending on the current
private boolean mIsConnected;
private boolean mConnectButtonInitialized;
- private ActionButtonPreference mActionButtons;
+ private ActionButtonsPreference mActionButtons;
public BluetoothDetailsButtonsController(Context context, PreferenceFragmentCompat fragment,
CachedBluetoothDevice device, Lifecycle lifecycle) {
@Override
protected void init(PreferenceScreen screen) {
- mActionButtons = ((ActionButtonPreference) screen.findPreference(getPreferenceKey()))
+ mActionButtons = ((ActionButtonsPreference) screen.findPreference(
+ getPreferenceKey()))
.setButton1Text(R.string.forget)
.setButton1Icon(R.drawable.ic_settings_delete)
.setButton1OnClickListener((view) -> onForgetButtonPressed())
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
-import com.android.settings.widget.ActionButtonPreference;
import com.android.settings.widget.GearPreference;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.widget.ActionButtonsPreference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
private SeekBarPreference mDefaultPitchPref;
private SeekBarPreference mDefaultRatePref;
- private ActionButtonPreference mActionButtons;
+ private ActionButtonsPreference mActionButtons;
private int mDefaultPitch = TextToSpeech.Engine.DEFAULT_PITCH;
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
mDefaultPitchPref = (SeekBarPreference) findPreference(KEY_DEFAULT_PITCH);
mDefaultRatePref = (SeekBarPreference) findPreference(KEY_DEFAULT_RATE);
- mActionButtons = ((ActionButtonPreference) findPreference(KEY_ACTION_BUTTONS))
+ mActionButtons = ((ActionButtonsPreference) findPreference(KEY_ACTION_BUTTONS))
.setButton1Text(R.string.tts_play)
.setButton1OnClickListener(v -> speakSampleText())
.setButton1Enabled(false)
+++ /dev/null
-/*
- * 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.widget;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-
-import androidx.annotation.DrawableRes;
-import androidx.annotation.StringRes;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.settings.R;
-
-/**
- * This preference provides a four buttons layout with Settings style.
- * It looks like below
- *
- * --------------------------------------------------
- * button1 | button2 | button3 | button4 |
- * --------------------------------------------------
- *
- * User can set title / icon / click listener for each button.
- *
- * By default, four buttons are visible.
- * However, there are two cases which button should be invisible(View.GONE).
- *
- * 1. User sets invisible for button. ex: ActionButtonPreference.setButton1Visible(false)
- * 2. User doesn't set any title or icon for button.
- *
- */
-public class ActionButtonPreference extends Preference {
-
- private final String TAG = "ActionButtonPreference";
- private final ButtonInfo mButton1Info = new ButtonInfo();
- private final ButtonInfo mButton2Info = new ButtonInfo();
- private final ButtonInfo mButton3Info = new ButtonInfo();
- private final ButtonInfo mButton4Info = new ButtonInfo();
-
- public ActionButtonPreference(Context context, AttributeSet attrs,
- int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- init();
- }
-
- public ActionButtonPreference(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- init();
- }
-
- public ActionButtonPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- init();
- }
-
- public ActionButtonPreference(Context context) {
- super(context);
- init();
- }
-
- private void init() {
- setLayoutResource(R.layout.settings_action_buttons);
- setSelectable(false);
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder holder) {
- super.onBindViewHolder(holder);
- holder.setDividerAllowedAbove(true);
- holder.setDividerAllowedBelow(true);
-
- mButton1Info.mButton = (Button) holder.findViewById(R.id.button1);
- mButton2Info.mButton = (Button) holder.findViewById(R.id.button2);
- mButton3Info.mButton = (Button) holder.findViewById(R.id.button3);
- mButton4Info.mButton = (Button) holder.findViewById(R.id.button4);
-
- mButton1Info.setUpButton();
- mButton2Info.setUpButton();
- mButton3Info.setUpButton();
- mButton4Info.setUpButton();
- }
-
- public ActionButtonPreference setButton1Visible(boolean isVisible) {
- if (isVisible != mButton1Info.mIsVisible) {
- mButton1Info.mIsVisible = isVisible;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton1Text(@StringRes int textResId) {
- final String newText = getContext().getString(textResId);
- if (!TextUtils.equals(newText, mButton1Info.mText)) {
- mButton1Info.mText = newText;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton1Icon(@DrawableRes int iconResId) {
- if (iconResId == 0) {
- return this;
- }
-
- final Drawable icon;
- try {
- icon = getContext().getDrawable(iconResId);
- mButton1Info.mIcon = icon;
- notifyChanged();
- } catch (Resources.NotFoundException exception) {
- Log.e(TAG, "Resource does not exist: " + iconResId);
- }
- return this;
- }
-
- public ActionButtonPreference setButton1Enabled(boolean isEnabled) {
- if (isEnabled != mButton1Info.mIsEnabled) {
- mButton1Info.mIsEnabled = isEnabled;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton1OnClickListener(View.OnClickListener listener) {
- if (listener != mButton1Info.mListener) {
- mButton1Info.mListener = listener;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton2Visible(boolean isVisible) {
- if (isVisible != mButton2Info.mIsVisible) {
- mButton2Info.mIsVisible = isVisible;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton2Text(@StringRes int textResId) {
- final String newText = getContext().getString(textResId);
- if (!TextUtils.equals(newText, mButton2Info.mText)) {
- mButton2Info.mText = newText;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton2Icon(@DrawableRes int iconResId) {
- if (iconResId == 0) {
- return this;
- }
-
- final Drawable icon;
- try {
- icon = getContext().getDrawable(iconResId);
- mButton2Info.mIcon = icon;
- notifyChanged();
- } catch (Resources.NotFoundException exception) {
- Log.e(TAG, "Resource does not exist: " + iconResId);
- }
- return this;
- }
-
- public ActionButtonPreference setButton2Enabled(boolean isEnabled) {
- if (isEnabled != mButton2Info.mIsEnabled) {
- mButton2Info.mIsEnabled = isEnabled;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton2OnClickListener(View.OnClickListener listener) {
- if (listener != mButton2Info.mListener) {
- mButton2Info.mListener = listener;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton3Visible(boolean isVisible) {
- if (isVisible != mButton3Info.mIsVisible) {
- mButton3Info.mIsVisible = isVisible;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton3Text(@StringRes int textResId) {
- final String newText = getContext().getString(textResId);
- if (!TextUtils.equals(newText, mButton3Info.mText)) {
- mButton3Info.mText = newText;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton3Icon(@DrawableRes int iconResId) {
- if (iconResId == 0) {
- return this;
- }
-
- final Drawable icon;
- try {
- icon = getContext().getDrawable(iconResId);
- mButton3Info.mIcon = icon;
- notifyChanged();
- } catch (Resources.NotFoundException exception) {
- Log.e(TAG, "Resource does not exist: " + iconResId);
- }
- return this;
- }
-
- public ActionButtonPreference setButton3Enabled(boolean isEnabled) {
- if (isEnabled != mButton3Info.mIsEnabled) {
- mButton3Info.mIsEnabled = isEnabled;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton3OnClickListener(View.OnClickListener listener) {
- if (listener != mButton3Info.mListener) {
- mButton3Info.mListener = listener;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton4Visible(boolean isVisible) {
- if (isVisible != mButton4Info.mIsVisible) {
- mButton4Info.mIsVisible = isVisible;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton4Text(@StringRes int textResId) {
- final String newText = getContext().getString(textResId);
- if (!TextUtils.equals(newText, mButton4Info.mText)) {
- mButton4Info.mText = newText;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton4Icon(@DrawableRes int iconResId) {
- if (iconResId == 0) {
- return this;
- }
-
- final Drawable icon;
- try {
- icon = getContext().getDrawable(iconResId);
- mButton4Info.mIcon = icon;
- notifyChanged();
- } catch (Resources.NotFoundException exception) {
- Log.e(TAG, "Resource does not exist: " + iconResId);
- }
- return this;
- }
-
- public ActionButtonPreference setButton4Enabled(boolean isEnabled) {
- if (isEnabled != mButton4Info.mIsEnabled) {
- mButton4Info.mIsEnabled = isEnabled;
- notifyChanged();
- }
- return this;
- }
-
- public ActionButtonPreference setButton4OnClickListener(View.OnClickListener listener) {
- if (listener != mButton4Info.mListener) {
- mButton4Info.mListener = listener;
- notifyChanged();
- }
- return this;
- }
-
- static class ButtonInfo {
- private Button mButton;
- private CharSequence mText;
- private Drawable mIcon;
- private View.OnClickListener mListener;
- private boolean mIsEnabled = true;
- private boolean mIsVisible = true;
-
- void setUpButton() {
- mButton.setText(mText);
- mButton.setOnClickListener(mListener);
- mButton.setEnabled(mIsEnabled);
- mButton.setCompoundDrawablesWithIntrinsicBounds(
- null /* left */, mIcon /* top */, null /* right */, null /* bottom */);
-
- if (shouldBeVisible()) {
- mButton.setVisibility(View.VISIBLE);
- } else {
- mButton.setVisibility(View.GONE);
- }
- }
-
- /**
- * By default, four buttons are visible.
- * However, there are two cases which button should be invisible.
- *
- * 1. User set invisible for this button. ex: mIsVisible = false.
- * 2. User didn't set any title or icon.
- *
- */
- private boolean shouldBeVisible() {
- return mIsVisible && (!TextUtils.isEmpty(mText) || mIcon != null);
- }
- }
-}
\ No newline at end of file
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.widget.ActionButtonPreference;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDialog;
import com.android.settings.wifi.WifiDialog.WifiDialogListener;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.widget.ActionButtonsPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.wifi.AccessPoint;
private final MetricsFeatureProvider mMetricsFeatureProvider;
// UI elements - in order of appearance
- private ActionButtonPreference mButtonsPref;
+ private ActionButtonsPreference mButtonsPref;
private EntityHeaderController mEntityHeaderController;
private Preference mSignalStrengthPref;
private Preference mLinkSpeedPref;
setupEntityHeader(screen);
- mButtonsPref = ((ActionButtonPreference) screen.findPreference(KEY_BUTTONS_PREF))
+ mButtonsPref = ((ActionButtonsPreference) screen.findPreference(KEY_BUTTONS_PREF))
.setButton1Text(R.string.forget)
.setButton1Icon(R.drawable.ic_settings_delete)
.setButton1OnClickListener(view -> forgetNetwork())
package com.android.settings.applications;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import android.widget.Button;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.widget.ActionButtonPreference;
-import com.android.settings.widget.ActionButtonPreferenceTest;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import com.android.settingslib.widget.ActionButtonsPreference;
import org.junit.Before;
import org.junit.Test;
@Mock
private AppStorageSizesController mSizesController;
- private ActionButtonPreference mButtonsPref;
+ private ActionButtonsPreference mButtonsPref;
private AppStorageSettings mSettings;
private Button mLeftButton;
private Button mRightButton;
mRightButton = new Button(RuntimeEnvironment.application);
mSettings = spy(new AppStorageSettings());
mSettings.mSizeController = mSizesController;
- mButtonsPref = ActionButtonPreferenceTest.createMock();
+ mButtonsPref = createMock();
mSettings.mButtonsPref = mButtonsPref;
when(mButtonsPref.setButton1OnClickListener(any(View.OnClickListener.class)))
verify(mSettings).handleClearDataClick();
verify(mSettings).handleClearCacheClick();
}
+
+ private ActionButtonsPreference createMock() {
+ final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
+ when(pref.setButton1Text(anyInt())).thenReturn(pref);
+ when(pref.setButton1Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ when(pref.setButton2Text(anyInt())).thenReturn(pref);
+ when(pref.setButton2Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ return pref;
+ }
}
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.UserManager;
+import android.view.View;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.widget.ActionButtonPreference;
-import com.android.settings.widget.ActionButtonPreferenceTest;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.ActionButtonsPreference;
import org.junit.Before;
import org.junit.Test;
@Mock
private PackageInfo mPackageInfo;
- private ActionButtonPreference mButtonPrefs;
+ private ActionButtonsPreference mButtonPrefs;
private Intent mUninstallIntent;
private AppButtonsPreferenceController mController;
mPackageInfo.packageName = PACKAGE_NAME;
mPackageInfo.applicationInfo = mAppInfo;
- mButtonPrefs = ActionButtonPreferenceTest.createMock();
+ mButtonPrefs = createMock();
mController.mButtonsPref = mButtonPrefs;
mController.mPackageInfo = mPackageInfo;
return SettingsEnums.PAGE_UNKNOWN;
}
}
+
+ private ActionButtonsPreference createMock() {
+ final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
+ when(pref.setButton1Text(anyInt())).thenReturn(pref);
+ when(pref.setButton1Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ return pref;
+ }
}
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
-import com.android.settings.widget.ActionButtonPreference;
-import com.android.settings.widget.ActionButtonPreferenceTest;
+import com.android.settingslib.widget.ActionButtonsPreference;
import org.junit.Test;
import org.junit.runner.RunWith;
@Config(shadows = SettingsShadowBluetoothDevice.class)
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
private BluetoothDetailsButtonsController mController;
- private ActionButtonPreference mButtonsPref;
+ private ActionButtonsPreference mButtonsPref;
private Button mConnectButton;
private Button mForgetButton;
mConnectButton = buttons.findViewById(R.id.button2);
mForgetButton = buttons.findViewById(R.id.button1);
mController =
- new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice, mLifecycle);
- mButtonsPref = ActionButtonPreferenceTest.createMock();
+ new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
+ mLifecycle);
+ mButtonsPref = createMock();
when(mButtonsPref.getKey()).thenReturn(mController.getPreferenceKey());
when(mButtonsPref.setButton2OnClickListener(any(View.OnClickListener.class)))
.thenAnswer(invocation -> {
verify(mButtonsPref).setButton2Enabled(false);
}
+
+ private ActionButtonsPreference createMock() {
+ final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
+ when(pref.setButton1Text(anyInt())).thenReturn(pref);
+ when(pref.setButton1Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ when(pref.setButton2Text(anyInt())).thenReturn(pref);
+ when(pref.setButton2Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ return pref;
+ }
}
paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/SearchWidget/res/")), null));
paths.add(new ResourcePath(null,
+ Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/ActionButtonsPreference/res")), null));
+ paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/SettingsLayoutPreference/res")), null));
paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/core/res/res")), null));
+++ /dev/null
-/*
- * 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.widget;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.view.View;
-import android.widget.Button;
-
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-public class ActionButtonPreferenceTest {
-
- private Context mContext;
- private View mRootView;
- private ActionButtonPreference mPref;
- private PreferenceViewHolder mHolder;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mRootView = View.inflate(mContext, R.layout.settings_action_buttons, null /* parent */);
- mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
- mPref = new ActionButtonPreference(mContext);
- }
-
- @Test
- public void onBindViewHolder_setTitle_shouldShowButtonByDefault() {
- mPref.setButton1Text(R.string.settings_label);
- mPref.setButton2Text(R.string.settings_label);
- mPref.setButton3Text(R.string.settings_label);
- mPref.setButton4Text(R.string.settings_label);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void onBindViewHolder_setIcon_shouldShowButtonByDefault() {
- mPref.setButton1Icon(R.drawable.ic_settings);
- mPref.setButton2Icon(R.drawable.ic_settings);
- mPref.setButton3Icon(R.drawable.ic_settings);
- mPref.setButton4Icon(R.drawable.ic_settings);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void onBindViewHolder_notSetTitleOrIcon_shouldNotShowButtonByDefault() {
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.GONE);
- }
-
- @Test
- public void onBindViewHolder_setVisibleIsGoneAndSetTitle_shouldNotShowButton() {
- mPref.setButton1Text(R.string.settings_label).setButton1Visible(false);
- mPref.setButton2Text(R.string.settings_label).setButton2Visible(false);
- mPref.setButton3Text(R.string.settings_label).setButton3Visible(false);
- mPref.setButton4Text(R.string.settings_label).setButton4Visible(false);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.GONE);
- }
-
- @Test
- public void onBindViewHolder_setVisibleIsGoneAndSetIcon_shouldNotShowButton() {
- mPref.setButton1Icon(R.drawable.ic_settings).setButton1Visible(false);
- mPref.setButton2Icon(R.drawable.ic_settings).setButton2Visible(false);
- mPref.setButton3Icon(R.drawable.ic_settings).setButton3Visible(false);
- mPref.setButton4Icon(R.drawable.ic_settings).setButton4Visible(false);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.GONE);
- }
-
- @Test
- public void onBindViewHolder_setVisibility_shouldUpdateButtonVisibility() {
- mPref.setButton1Text(R.string.settings_label).setButton1Visible(false);
- mPref.setButton2Text(R.string.settings_label).setButton2Visible(false);
- mPref.setButton3Text(R.string.settings_label).setButton3Visible(false);
- mPref.setButton4Text(R.string.settings_label).setButton4Visible(false);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.GONE);
-
- mPref.setButton1Visible(true);
- mPref.setButton2Visible(true);
- mPref.setButton3Visible(true);
- mPref.setButton4Visible(true);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button2).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button3).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mRootView.findViewById(R.id.button4).getVisibility())
- .isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void onBindViewHolder_setEnabled_shouldEnableButton() {
- mPref.setButton1Enabled(true);
- mPref.setButton2Enabled(false);
- mPref.setButton3Enabled(true);
- mPref.setButton4Enabled(false);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(mRootView.findViewById(R.id.button1).isEnabled()).isTrue();
- assertThat(mRootView.findViewById(R.id.button2).isEnabled()).isFalse();
- assertThat(mRootView.findViewById(R.id.button3).isEnabled()).isTrue();
- assertThat(mRootView.findViewById(R.id.button4).isEnabled()).isFalse();
- }
-
- @Test
- public void onBindViewHolder_setText_shouldShowSameText() {
- mPref.setButton1Text(R.string.settings_label);
- mPref.setButton2Text(R.string.settings_label);
- mPref.setButton3Text(R.string.settings_label);
- mPref.setButton4Text(R.string.settings_label);
-
- mPref.onBindViewHolder(mHolder);
-
- assertThat(((Button) mRootView.findViewById(R.id.button1)).getText())
- .isEqualTo(mContext.getText(R.string.settings_label));
- assertThat(((Button) mRootView.findViewById(R.id.button2)).getText())
- .isEqualTo(mContext.getText(R.string.settings_label));
- assertThat(((Button) mRootView.findViewById(R.id.button3)).getText())
- .isEqualTo(mContext.getText(R.string.settings_label));
- assertThat(((Button) mRootView.findViewById(R.id.button4)).getText())
- .isEqualTo(mContext.getText(R.string.settings_label));
- }
-
- @Test
- public void onBindViewHolder_setButtonIcon_iconMustDisplayAboveText() {
- mPref.setButton1Text(R.string.settings_label);
- mPref.setButton1Icon(R.drawable.ic_settings);
-
- mPref.onBindViewHolder(mHolder);
- final Drawable[] drawablesAroundText =
- ((Button) mRootView.findViewById(R.id.button1))
- .getCompoundDrawables();
-
- assertThat(drawablesAroundText[1 /* top */]).isNotNull();
- }
-
- @Test
- public void setButtonIcon_iconResourceIdIsZero_shouldNotDisplayIcon() {
- mPref.setButton1Text(R.string.settings_label);
- mPref.setButton1Icon(0);
-
- mPref.onBindViewHolder(mHolder);
- final Drawable[] drawablesAroundText =
- ((Button) mRootView.findViewById(R.id.button1))
- .getCompoundDrawables();
-
- assertThat(drawablesAroundText[1 /* top */]).isNull();
- }
-
- @Test
- public void setButtonIcon_iconResourceIdNotExisting_shouldNotDisplayIconAndCrash() {
- mPref.setButton1Text(R.string.settings_label);
- mPref.setButton1Icon(999999999 /* not existing id */);
- // Should not crash here
- mPref.onBindViewHolder(mHolder);
- final Drawable[] drawablesAroundText =
- ((Button) mRootView.findViewById(R.id.button1))
- .getCompoundDrawables();
-
- assertThat(drawablesAroundText[1 /* top */]).isNull();
- }
-
- public static ActionButtonPreference createMock() {
- final ActionButtonPreference pref = mock(ActionButtonPreference.class);
- when(pref.setButton1Text(anyInt())).thenReturn(pref);
- when(pref.setButton1Icon(anyInt())).thenReturn(pref);
- when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
- when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
- when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
-
- when(pref.setButton2Text(anyInt())).thenReturn(pref);
- when(pref.setButton2Icon(anyInt())).thenReturn(pref);
- when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
- when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
- when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
-
- when(pref.setButton3Text(anyInt())).thenReturn(pref);
- when(pref.setButton3Icon(anyInt())).thenReturn(pref);
- when(pref.setButton3Enabled(anyBoolean())).thenReturn(pref);
- when(pref.setButton3Visible(anyBoolean())).thenReturn(pref);
- when(pref.setButton3OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
-
- when(pref.setButton4Text(anyInt())).thenReturn(pref);
- when(pref.setButton4Icon(anyInt())).thenReturn(pref);
- when(pref.setButton4Enabled(anyBoolean())).thenReturn(pref);
- when(pref.setButton4Visible(anyBoolean())).thenReturn(pref);
- when(pref.setButton4OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
- return pref;
- }
-}
\ No newline at end of file
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import com.android.settings.testutils.shadow.ShadowBidiFormatter;
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
-import com.android.settings.widget.ActionButtonPreference;
-import com.android.settings.widget.ActionButtonPreferenceTest;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.ActionButtonsPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.wifi.AccessPoint;
private ImageView mockHeaderIcon;
@Mock
- private ActionButtonPreference mockButtonsPref;
+ private ActionButtonsPreference mockButtonsPref;
@Mock
private Preference mockSignalStrengthPref;
@Mock
.thenReturn(mockNetworkInfo);
doNothing().when(mockConnectivityManager).registerNetworkCallback(
nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
- mockButtonsPref = ActionButtonPreferenceTest.createMock();
+ mockButtonsPref = createMock();
when(mockButtonsPref.setButton1OnClickListener(mForgetClickListener.capture()))
.thenReturn(mockButtonsPref);
verify(mockAccessPoint, times(2)).getLevel();
verify(mockIconInjector, times(2)).getIcon(anyInt());
}
+
+ private ActionButtonsPreference createMock() {
+ final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
+ when(pref.setButton1Text(anyInt())).thenReturn(pref);
+ when(pref.setButton1Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ when(pref.setButton2Text(anyInt())).thenReturn(pref);
+ when(pref.setButton2Icon(anyInt())).thenReturn(pref);
+ when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
+ when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
+
+ return pref;
+ }
}