Fix Wi-Fi Easy Connect buttons UI defects
1. Apply attr/colorAccent to button icons for theme UI control 2. Apply attr/selectableItemBackground for button tapping ripple effect 3. Use ConstraintLayout to separate ssid EditText and scan button 4. Remove ButtonPreference and add AddNetworkPreference. ButtonPreference's naming and design look like a general purpose UI component but it's not. This change refactors the code. 5. In AddNetworkPreference, use settingslib layout file 'preference_access_point' to fix UI alignment problems. Bug: 126964552 Bug: 125434239 Bug: 126762937 Test: manual test atest com.android.settings.wifi.WifiSettingsTest Change-Id: Ib899a1e10f96bb8427ff00d6b5dfca37a0642c44
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ButtonPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private View mRootView;
|
||||
private ButtonPreference mPref;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private boolean mClicked;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPref = new ButtonPreference(mContext);
|
||||
mRootView = View.inflate(mContext, R.layout.wifi_button_preference_widget, /* parent */
|
||||
null);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initButton_noIcon_shouldInvisible() {
|
||||
mPref.initButton(mHolder);
|
||||
assertThat(mRootView.findViewById(R.id.button_icon).getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initButton_withIcon_shouldVisible() {
|
||||
mPref.setButtonIcon(R.drawable.ic_qrcode_24dp);
|
||||
mPref.initButton(mHolder);
|
||||
assertThat(mRootView.findViewById(R.id.button_icon).getVisibility()).isEqualTo(
|
||||
View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initButton_whenClick_shouldCallback() {
|
||||
mClicked = false;
|
||||
mPref.setButtonIcon(R.drawable.ic_qrcode_24dp);
|
||||
mPref.setButtonOnClickListener((View v) -> {
|
||||
mClicked = true;
|
||||
});
|
||||
mPref.initButton(mHolder);
|
||||
ImageButton button = (ImageButton) mRootView.findViewById(R.id.button_icon);
|
||||
button.performClick();
|
||||
assertThat(mClicked).isTrue();
|
||||
}
|
||||
}
|
@@ -69,6 +69,7 @@ public class WifiSettingsTest {
|
||||
mWifiSettings = spy(new WifiSettings());
|
||||
doReturn(mContext).when(mWifiSettings).getContext();
|
||||
doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
|
||||
mWifiSettings.mAddWifiNetworkPreference = new AddWifiNetworkPreference(mContext);
|
||||
mWifiSettings.mSavedNetworksPreference = new Preference(mContext);
|
||||
mWifiSettings.mConfigureWifiSettingsPreference = new Preference(mContext);
|
||||
mWifiSettings.mWifiTracker = mWifiTracker;
|
||||
@@ -151,4 +152,11 @@ public class WifiSettingsTest {
|
||||
assertThat(mWifiSettings.mConfigureWifiSettingsPreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.wifi_configure_settings_preference_summary_wakeup_off));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkAddWifiNetworkPrefernce_preferenceVisible() {
|
||||
assertThat(mWifiSettings.mAddWifiNetworkPreference.isVisible()).isTrue();
|
||||
assertThat(mWifiSettings.mAddWifiNetworkPreference.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.wifi_add_network));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user