Files
app_Settings/src/com/android/settings/widget/AddPreference.java
Antony Sargent 475dde51b6 Fix some problems with the "Mobile network" preference
This fixes a few issues with the "Mobile network" preference that shows
on the Network & internet page:

-The pref should not be available at all if the device is wifi-only.

-The pref should be disabled in airplane mode.

-If eSIM support is disabled, we need to disable entry points for adding
 a new eSIM subscription (the summary and click handler in single-SIM
 mode with no physical SIM, and the 'add' button in dual-SIM mode).

Bug: 116349402
Test: make RunSettingsRoboTests
Change-Id: Ic6fe426e9f890d80b399d48a2c9984d4d8b02a10
2019-02-11 09:50:38 -08:00

93 lines
2.8 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;
private View mAddWidget;
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);
}
}
public void setAddWidgetEnabled(boolean enabled) {
if (mAddWidget != null) {
mAddWidget.setEnabled(enabled);
}
}
@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);
mAddWidget = holder.findViewById(getAddWidgetResId());
mAddWidget.setEnabled(true);
mAddWidget.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == getAddWidgetResId() && mListener != null) {
mListener.onAddClick(this);
}
}
public interface OnAddClickListener {
void onAddClick(AddPreference p);
}
}