On the Network & internet page, we have a "Mobile network" pref that in single-SIM mode leads to a detail page for the current SIM. In multi-SIM mode it has more complicated behavior (leading either to details about the current subscription if there is only one, or a list of subscriptions if more than one). One of the things we wanted to add was a shortcut to add another eSIM subscription. So this CL adds a plus button control on the right of the preference which leads to a flow to add another mobile subscription via the eSIM manager. Bug: 116349402 Test: make RunSettingsRoboTests Change-Id: I38e0031e3bd603e93c45dcb4557750e7bc1b8b5a
86 lines
2.6 KiB
Java
86 lines
2.6 KiB
Java
/*
|
|
* 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.widget;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settingslib.RestrictedPreference;
|
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.preference.PreferenceViewHolder;
|
|
|
|
/**
|
|
* A preference with a plus button on the side representing an "add" action. The plus button will
|
|
* only be visible when a non-null click listener is registered.
|
|
*/
|
|
public class AddPreference extends RestrictedPreference implements View.OnClickListener {
|
|
|
|
private OnAddClickListener mListener;
|
|
private View mWidgetFrame;
|
|
|
|
public AddPreference(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
int getAddWidgetResId() {
|
|
return R.id.add_preference_widget;
|
|
}
|
|
|
|
/** Sets a listener for clicks on the plus button. Passing null will cause the button to be
|
|
* hidden. */
|
|
public void setOnAddClickListener(OnAddClickListener listener) {
|
|
mListener = listener;
|
|
if (mWidgetFrame != null) {
|
|
mWidgetFrame.setVisibility(shouldHideSecondTarget() ? View.GONE : View.VISIBLE);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected int getSecondTargetResId() {
|
|
return R.layout.preference_widget_add;
|
|
}
|
|
|
|
@Override
|
|
protected boolean shouldHideSecondTarget() {
|
|
return mListener == null;
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
|
super.onBindViewHolder(holder);
|
|
mWidgetFrame = holder.findViewById(android.R.id.widget_frame);
|
|
final View addWidget = holder.findViewById(getAddWidgetResId());
|
|
addWidget.setEnabled(true);
|
|
addWidget.setOnClickListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
if (view.getId() == getAddWidgetResId() && mListener != null) {
|
|
mListener.onAddClick(this);
|
|
}
|
|
}
|
|
|
|
public interface OnAddClickListener {
|
|
void onAddClick(AddPreference p);
|
|
}
|
|
}
|