diff --git a/packages/SettingsLib/res/drawable/ic_help.xml b/packages/SettingsLib/res/drawable/ic_help.xml
new file mode 100644
index 0000000000000..73681d379e183
--- /dev/null
+++ b/packages/SettingsLib/res/drawable/ic_help.xml
@@ -0,0 +1,25 @@
+
+
+
+
diff --git a/packages/SettingsLib/res/layout/preference_access_point.xml b/packages/SettingsLib/res/layout/preference_access_point.xml
index 472a6e3d0dd4d..fecafa89aeb01 100644
--- a/packages/SettingsLib/res/layout/preference_access_point.xml
+++ b/packages/SettingsLib/res/layout/preference_access_point.xml
@@ -93,4 +93,14 @@
android:gravity="center"
android:orientation="vertical" />
+
+
diff --git a/packages/SettingsLib/res/values/dimens.xml b/packages/SettingsLib/res/values/dimens.xml
index d10e034157db3..a5ec5e66f242e 100644
--- a/packages/SettingsLib/res/values/dimens.xml
+++ b/packages/SettingsLib/res/values/dimens.xml
@@ -92,4 +92,6 @@
24dp
+
+ 48dp
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiEntryPreference.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiEntryPreference.java
index 6a7000eb92c81..c63c34c1b6d1b 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiEntryPreference.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiEntryPreference.java
@@ -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;
+ }
+
}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEntryPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEntryPreferenceTest.java
index 0f1e0ff60e37c..47836c022d384 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEntryPreferenceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEntryPreferenceTest.java
@@ -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);
+ }
}