Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit baf002d6 authored by Arc Wang's avatar Arc Wang
Browse files

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
parent 3d5ef5ec
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    android:viewportHeight="24"
    android:tint="?android:attr/colorAccent">
  <path
      android:fillColor="#FF000000"
      android:pathData="M7,4v3H4V4H7M9,2H2v7h7V2L9,2z"/>
+2 −1
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    android:viewportHeight="24"
    android:tint="?android:attr/colorAccent">
  <path
      android:fillColor="#FF000000"
      android:pathData="M9,2l-7,0l0,2l7,0l0,-2z"/>
+1 −2
Original line number Diff line number Diff line
@@ -22,5 +22,4 @@
           android:minWidth="@dimen/min_tap_target_size"
           android:minHeight="@dimen/min_tap_target_size"
           android:layout_gravity="center"
           android:background="@null"
           android:visibility="gone"/>
           android:background="?android:attr/selectableItemBackground"/>
+21 −18
Original line number Diff line number Diff line
@@ -50,29 +50,31 @@
                        android:text="@string/wifi_ssid"
                        android:textDirection="locale" />

                <RelativeLayout
                <androidx.constraintlayout.widget.ConstraintLayout
                        xmlns:app="http://schemas.android.com/apk/res-auto"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                    <EditText android:id="@+id/ssid"
                            android:layout_width="match_parent"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_alignParentStart="true"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintEnd_toStartOf="@+id/ssid_scanner_button"
                            style="@style/wifi_item_edit_content"
                            android:hint="@string/wifi_ssid_hint"
                            android:singleLine="true"
                            android:inputType="textNoSuggestions"/>

                    <ImageButton
                        android:id="@+id/ssid_scanner_button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minWidth="@dimen/min_tap_target_size"
                        android:minHeight="@dimen/min_tap_target_size"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        android:background="@null"
                        app:layout_constraintEnd_toEndOf="parent"
                        android:background="?android:attr/selectableItemBackground"
                        android:src="@drawable/ic_scan_24dp"
                        android:contentDescription="@string/wifi_dpp_scan_qr_code"/>
                </RelativeLayout>
                </androidx.constraintlayout.widget.ConstraintLayout>

                <LinearLayout android:id="@+id/ssid_too_long_warning"
                              android:layout_width="match_parent"
@@ -286,13 +288,15 @@
                        style="@style/wifi_item_label"
                        android:text="@string/wifi_password" />

                <RelativeLayout
                <androidx.constraintlayout.widget.ConstraintLayout
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <EditText android:id="@+id/password"
                              android:layout_width="match_parent"
                              android:layout_width="0dp"
                              android:layout_height="wrap_content"
                              android:layout_alignParentStart="true"
                              app:layout_constraintStart_toStartOf="parent"
                              app:layout_constraintEnd_toStartOf="@+id/password_scanner_button"
                              style="@style/wifi_item_edit_content"
                              android:singleLine="true"
                              android:password="true"/>
@@ -303,12 +307,11 @@
                        android:layout_height="wrap_content"
                        android:minWidth="@dimen/min_tap_target_size"
                        android:minHeight="@dimen/min_tap_target_size"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        android:background="@null"
                        app:layout_constraintEnd_toEndOf="parent"
                        android:background="?android:attr/selectableItemBackground"
                        android:src="@drawable/ic_scan_24dp"
                        android:contentDescription="@string/wifi_dpp_scan_qr_code"/>
                </RelativeLayout>
                </androidx.constraintlayout.widget.ConstraintLayout>
            </LinearLayout>

            <LinearLayout android:id="@+id/show_password_layout"
+83 −0
Original line number Diff line number Diff line
/*
 * 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.wifi;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

import androidx.annotation.DrawableRes;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settings.wifi.dpp.WifiDppUtils;

/**
 * The Preference for users to add Wi-Fi networks in WifiSettings
 */
public class AddWifiNetworkPreference extends Preference {

    private static final String TAG = "AddWifiNetworkPreference";

    private boolean mInitialized;

    public AddWifiNetworkPreference(Context context) {
        super(context);

        setLayoutResource(com.android.settingslib.R.layout.preference_access_point);
        setWidgetLayoutResource(R.layout.wifi_button_preference_widget);
        setIcon(R.drawable.ic_menu_add);
        setTitle(R.string.wifi_add_network);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        if (!mInitialized) {
            mInitialized = true;

            final ImageButton imageButton = (ImageButton) holder.findViewById(R.id.button_icon);
            imageButton.setImageDrawable(getDrawable(R.drawable.ic_scan_24dp));
            imageButton.setContentDescription(
                    getContext().getString(R.string.wifi_dpp_scan_qr_code));
            imageButton.setOnClickListener(view -> {
                getContext().startActivity(
                    WifiDppUtils.getEnrolleeQrCodeScannerIntent(/* ssid */ null));
            });

            final View divider = (View) holder.findViewById(
                    com.android.settingslib.R.id.two_target_divider);
            divider.setVisibility(View.INVISIBLE);
        }
    }

    private Drawable getDrawable(@DrawableRes int iconResId) {
        Drawable buttonIcon = null;

        try {
            buttonIcon = getContext().getDrawable(iconResId);
        } catch (Resources.NotFoundException exception) {
            Log.e(TAG, "Resource does not exist: " + iconResId);
        }
        return buttonIcon;
    }
}
Loading