Merge "[Settings] Refactor Wifi Calling description text"
This commit is contained in:
@@ -29,16 +29,11 @@
|
|||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@android:id/tabcontent"
|
android:id="@android:id/tabcontent"
|
||||||
android:layout_width="0dip"
|
|
||||||
android:layout_height="0dip" />
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/prefs_container"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dip"
|
android:layout_height="0dip"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:clipChildren="false"
|
android:clipChildren="true"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="true"
|
||||||
android:smoothScrollbar="false" />
|
android:smoothScrollbar="false" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
|
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
|
||||||
android:key="wifi_calling_mode"
|
android:key="wifi_calling_mode"
|
||||||
|
isPreferenceVisible="false"
|
||||||
android:title="@string/wifi_calling_mode_title"
|
android:title="@string/wifi_calling_mode_title"
|
||||||
android:summary="@string/wifi_calling_mode_title"
|
android:summary="@string/wifi_calling_mode_title"
|
||||||
android:entries="@array/wifi_calling_mode_choices"
|
android:entries="@array/wifi_calling_mode_choices"
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
|
|
||||||
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
|
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
|
||||||
android:key="wifi_calling_roaming_mode"
|
android:key="wifi_calling_roaming_mode"
|
||||||
|
isPreferenceVisible="false"
|
||||||
android:title="@string/wifi_calling_roaming_mode_title"
|
android:title="@string/wifi_calling_roaming_mode_title"
|
||||||
android:summary="@string/wifi_calling_roaming_mode_summary"
|
android:summary="@string/wifi_calling_roaming_mode_summary"
|
||||||
android:entries="@array/wifi_calling_mode_choices_v2"
|
android:entries="@array/wifi_calling_mode_choices_v2"
|
||||||
@@ -39,7 +41,12 @@
|
|||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="emergency_address_key"
|
android:key="emergency_address_key"
|
||||||
|
isPreferenceVisible="false"
|
||||||
android:title="@string/emergency_address_title"
|
android:title="@string/emergency_address_title"
|
||||||
android:summary="@string/emergency_address_summary" />
|
android:summary="@string/emergency_address_summary" />
|
||||||
|
|
||||||
|
<com.android.settings.wifi.calling.LinkifyDescriptionPreference
|
||||||
|
android:key="no_options_description"
|
||||||
|
isPreferenceVisible="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.calling;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.style.ClickableSpan;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.core.text.util.LinkifyCompat;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/** A preference which supports linkify text as a description in the summary **/
|
||||||
|
public class LinkifyDescriptionPreference extends Preference {
|
||||||
|
|
||||||
|
public LinkifyDescriptionPreference(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkifyDescriptionPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
|
||||||
|
if (summaryView == null || summaryView.getVisibility() != View.VISIBLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CharSequence summary = getSummary();
|
||||||
|
if (TextUtils.isEmpty(summary)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
summaryView.setMaxLines(Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
final SpannableString spannableSummary = new SpannableString(summary);
|
||||||
|
if (spannableSummary.getSpans(0, spannableSummary.length(), ClickableSpan.class)
|
||||||
|
.length > 0) {
|
||||||
|
summaryView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
}
|
||||||
|
LinkifyCompat.addLinks(summaryView,
|
||||||
|
Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
|
||||||
|
}
|
||||||
|
}
|
@@ -35,9 +35,7 @@ import android.telephony.ims.ImsManager;
|
|||||||
import android.telephony.ims.ImsMmTelManager;
|
import android.telephony.ims.ImsMmTelManager;
|
||||||
import android.telephony.ims.ProvisioningManager;
|
import android.telephony.ims.ProvisioningManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.util.Linkify;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -59,8 +57,11 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||||
|
import com.android.settings.wifi.calling.LinkifyDescriptionPreference;
|
||||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the inner class of {@link WifiCallingSettings} fragment.
|
* This is the inner class of {@link WifiCallingSettings} fragment.
|
||||||
* The preference screen lets you enable/disable Wi-Fi Calling and change Wi-Fi Calling mode.
|
* The preference screen lets you enable/disable Wi-Fi Calling and change Wi-Fi Calling mode.
|
||||||
@@ -74,6 +75,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
|
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
|
||||||
private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
|
private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
|
||||||
private static final String PREFERENCE_EMERGENCY_ADDRESS = "emergency_address_key";
|
private static final String PREFERENCE_EMERGENCY_ADDRESS = "emergency_address_key";
|
||||||
|
private static final String PREFERENCE_NO_OPTIONS_DESC = "no_options_description";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
|
static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
|
||||||
@@ -93,7 +95,6 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
private ListWithEntrySummaryPreference mButtonWfcMode;
|
private ListWithEntrySummaryPreference mButtonWfcMode;
|
||||||
private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
|
private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
|
||||||
private Preference mUpdateAddress;
|
private Preference mUpdateAddress;
|
||||||
private TextView mEmptyView;
|
|
||||||
|
|
||||||
private boolean mValidListener = false;
|
private boolean mValidListener = false;
|
||||||
private boolean mEditableWfcMode = true;
|
private boolean mEditableWfcMode = true;
|
||||||
@@ -187,15 +188,6 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
mEmptyView = getView().findViewById(android.R.id.empty);
|
|
||||||
setEmptyView(mEmptyView);
|
|
||||||
mEmptyView.setAutoLinkMask(Linkify.WEB_URLS);
|
|
||||||
final Resources res = getResourcesForSubId();
|
|
||||||
final String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
|
|
||||||
res.getString(R.string.wifi_calling_off_explanation_2));
|
|
||||||
mEmptyView.setText(emptyViewText);
|
|
||||||
mEmptyView.setGravity(Gravity.TOP | Gravity.LEFT);
|
|
||||||
|
|
||||||
mSwitchBar = getView().findViewById(R.id.switch_bar);
|
mSwitchBar = getView().findViewById(R.id.switch_bar);
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
@@ -311,6 +303,9 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
mIntentFilter = new IntentFilter();
|
mIntentFilter = new IntentFilter();
|
||||||
mIntentFilter.addAction(ImsManager.ACTION_WFC_IMS_REGISTRATION_ERROR);
|
mIntentFilter.addAction(ImsManager.ACTION_WFC_IMS_REGISTRATION_ERROR);
|
||||||
|
|
||||||
|
updateDescriptionForOptions(
|
||||||
|
List.of(mButtonWfcMode, mButtonWfcRoamingMode, mUpdateAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -326,7 +321,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
final View view = inflater.inflate(
|
final View view = inflater.inflate(
|
||||||
R.layout.wifi_calling_settings_preferences, container, false);
|
R.layout.wifi_calling_settings_preferences, container, false);
|
||||||
|
|
||||||
final ViewGroup prefs_container = view.findViewById(R.id.prefs_container);
|
final ViewGroup prefs_container = view.findViewById(android.R.id.tabcontent);
|
||||||
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
||||||
final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
||||||
prefs_container.addView(prefs);
|
prefs_container.addView(prefs);
|
||||||
@@ -575,28 +570,35 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
|
final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
|
||||||
if (wfcEnabled) {
|
if (wfcEnabled) {
|
||||||
if (mEditableWfcMode) {
|
// Don't show WFC (home) preference if it's not editable.
|
||||||
preferenceScreen.addPreference(mButtonWfcMode);
|
mButtonWfcMode.setVisible(mEditableWfcMode);
|
||||||
} else {
|
// Don't show WFC roaming preference if it's not editable.
|
||||||
// Don't show WFC (home) preference if it's not editable.
|
mButtonWfcRoamingMode.setVisible(
|
||||||
preferenceScreen.removePreference(mButtonWfcMode);
|
mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming);
|
||||||
}
|
mUpdateAddress.setVisible(updateAddressEnabled);
|
||||||
if (mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming) {
|
|
||||||
preferenceScreen.addPreference(mButtonWfcRoamingMode);
|
|
||||||
} else {
|
|
||||||
// Don't show WFC roaming preference if it's not editable.
|
|
||||||
preferenceScreen.removePreference(mButtonWfcRoamingMode);
|
|
||||||
}
|
|
||||||
if (updateAddressEnabled) {
|
|
||||||
preferenceScreen.addPreference(mUpdateAddress);
|
|
||||||
} else {
|
|
||||||
preferenceScreen.removePreference(mUpdateAddress);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
preferenceScreen.removePreference(mButtonWfcMode);
|
mButtonWfcMode.setVisible(false);
|
||||||
preferenceScreen.removePreference(mButtonWfcRoamingMode);
|
mButtonWfcRoamingMode.setVisible(false);
|
||||||
preferenceScreen.removePreference(mUpdateAddress);
|
mUpdateAddress.setVisible(false);
|
||||||
}
|
}
|
||||||
|
updateDescriptionForOptions(
|
||||||
|
List.of(mButtonWfcMode, mButtonWfcRoamingMode, mUpdateAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDescriptionForOptions(List<Preference> visibleOptions) {
|
||||||
|
LinkifyDescriptionPreference pref = findPreference(PREFERENCE_NO_OPTIONS_DESC);
|
||||||
|
if (pref == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean optionsAvailable = visibleOptions.stream().anyMatch(Preference::isVisible);
|
||||||
|
if (!optionsAvailable) {
|
||||||
|
final Resources res = getResourcesForSubId();
|
||||||
|
String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
|
||||||
|
res.getString(R.string.wifi_calling_off_explanation_2));
|
||||||
|
pref.setSummary(emptyViewText);
|
||||||
|
}
|
||||||
|
pref.setVisible(!optionsAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user