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

Commit 689e1a9a authored by Goven Liu's avatar Goven Liu Committed by Automerger Merge Worker
Browse files

Merge "[Wi-Fi] Add button in WifiEntryPreference for launching OpenRoaming...

Merge "[Wi-Fi] Add button in WifiEntryPreference for launching OpenRoaming help page" into rvc-dev am: 7c8dde0f

Change-Id: I3755d51f07c87f380cc802abf6b41637204f0ed7
parents df1e7814 7c8dde0f
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2020 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M11,18h2v-2h-2V18zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5C16,7.79 14.21,6 12,6z"/>
</vector>
+10 −0
Original line number Diff line number Diff line
@@ -93,4 +93,14 @@
        android:gravity="center"
        android:orientation="vertical" />

    <ImageButton
        android:id="@+id/icon_button"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="64dp"
        android:minHeight="@dimen/min_tap_target_size"
        android:layout_gravity="center"
        android:background="?android:attr/selectableItemBackground"
        android:visibility="gone">
    </ImageButton>
</LinearLayout>
+2 −0
Original line number Diff line number Diff line
@@ -92,4 +92,6 @@
    <!-- Size of nearby icon -->
    <dimen name="bt_nearby_icon_size">24dp</dimen>

    <!-- Define minimal size of the tap area -->
    <dimen name="min_tap_target_size">48dp</dimen>
</resources>
+69 −4
Original line number Diff line number Diff line
@@ -23,8 +23,10 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -37,7 +39,8 @@ import com.android.wifitrackerlib.WifiEntry;
/**
 * Preference to display a WifiEntry in a wifi picker.
 */
public class WifiEntryPreference extends Preference implements WifiEntry.WifiEntryCallback {
public class WifiEntryPreference extends Preference implements WifiEntry.WifiEntryCallback,
        View.OnClickListener {

    private static final int[] STATE_SECURED = {
            R.attr.state_encrypted
@@ -62,6 +65,7 @@ public class WifiEntryPreference extends Preference implements WifiEntry.WifiEnt
    private WifiEntry mWifiEntry;
    private int mLevel = -1;
    private CharSequence mContentDescription;
    private OnButtonClickListener mOnButtonClickListener;

    public WifiEntryPreference(@NonNull Context context, @NonNull WifiEntry wifiEntry) {
        this(context, wifiEntry, new IconInjector(context));
@@ -95,11 +99,32 @@ public class WifiEntryPreference extends Preference implements WifiEntry.WifiEnt

        view.itemView.setContentDescription(mContentDescription);

        final ImageView frictionImageView = (ImageView) view.findViewById(R.id.friction_icon);
        bindFrictionImage(frictionImageView);

        // Turn off divider
        view.findViewById(R.id.two_target_divider).setVisibility(View.INVISIBLE);

        // Enable the icon button when this Entry is a canManageSubscription entry.
        final ImageButton imageButton = (ImageButton) view.findViewById(R.id.icon_button);
        final ImageView frictionImageView = (ImageView) view.findViewById(
                R.id.friction_icon);
        if (mWifiEntry.canManageSubscription() && !mWifiEntry.isSaved()
                && mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_DISCONNECTED) {
            final Drawable drawablehelp = getDrawable(R.drawable.ic_help);
            drawablehelp.setTintList(
                    Utils.getColorAttr(getContext(), android.R.attr.colorControlNormal));
            ((ImageView) imageButton).setImageDrawable(drawablehelp);
            imageButton.setVisibility(View.VISIBLE);
            imageButton.setOnClickListener(this);
            if (frictionImageView != null) {
                frictionImageView.setVisibility(View.GONE);
            }
        } else {
            imageButton.setVisibility(View.GONE);

            if (frictionImageView != null) {
                frictionImageView.setVisibility(View.VISIBLE);
                bindFrictionImage(frictionImageView);
            }
        }
    }

    /**
@@ -236,4 +261,44 @@ public class WifiEntryPreference extends Preference implements WifiEntry.WifiEnt
            return mContext.getDrawable(Utils.getWifiIconResource(level));
        }
    }

    /**
     * Set listeners, who want to listen the button client event.
     */
    public void setOnButtonClickListener(OnButtonClickListener listener) {
        mOnButtonClickListener = listener;
        notifyChanged();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.icon_button) {
            if (mOnButtonClickListener != null) {
                mOnButtonClickListener.onButtonClick(this);
            }
        }
    }

    /**
     * Callback to inform the caller that the icon button is clicked.
     */
    public interface OnButtonClickListener {

        /**
         * Register to listen the button click event.
         */
        void onButtonClick(WifiEntryPreference preference);
    }

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

        try {
            buttonIcon = getContext().getDrawable(iconResId);
        } catch (Resources.NotFoundException exception) {
            // Do nothing
        }
        return buttonIcon;
    }

}
+20 −0
Original line number Diff line number Diff line
@@ -21,7 +21,13 @@ import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.R;
import com.android.wifitrackerlib.WifiEntry;

import org.junit.Before;
@@ -147,4 +153,18 @@ public class WifiEntryPreferenceTest {
        assertThat(iconList).containsExactly(mMockDrawable0, mMockDrawable1,
                mMockDrawable2, mMockDrawable3, mMockDrawable4, null);
    }

    @Test
    public void canManageSubscription_shouldSetImageButtonVisible() {
        when(mMockWifiEntry.canManageSubscription()).thenReturn(true);
        final WifiEntryPreference pref =
                new WifiEntryPreference(mContext, mMockWifiEntry, mMockIconInjector);
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        final View view = inflater.inflate(pref.getLayoutResource(), new LinearLayout(mContext),
                false);
        final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
        pref.onBindViewHolder(holder);

        assertThat(view.findViewById(R.id.icon_button).getVisibility()).isEqualTo(View.VISIBLE);
    }
}