Loading res/layout/preference_widget_add.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/add_preference_widget" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:paddingStart="?android:attr/listPreferredItemPaddingEnd" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/selectableItemBackground" android:scaleType="center" android:src="@drawable/ic_add_24dp" android:contentDescription="@string/add" /> res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -658,6 +658,8 @@ <string name="apply">Apply</string> <!-- Button label for generic share action [CHAR LIMIT=20] --> <string name="share">Share</string> <!-- Button label for generic add action [CHAR LIMIT=20] --> <string name="add">Add</string> <!-- Title of the Settings activity shown within the application itself. --> <string name="settings_label">Settings</string> Loading res/xml/mobile_network_list.xml +3 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ android:key="add_more" android:title="@string/mobile_network_list_add_more" android:icon="@drawable/ic_menu_add" android:order="100" /> android:order="100" > <intent android:action="android.telephony.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION" /> </Preference> </PreferenceScreen> res/xml/network_and_internet_v2.xml +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ android:targetClass="Settings$WifiSettingsActivity" /> </com.android.settings.widget.MasterSwitchPreference> <com.android.settingslib.RestrictedPreference <com.android.settings.widget.AddPreference android:key="mobile_network_list" android:title="@string/network_settings_title" android:summary="@string/summary_placeholder" Loading src/com/android/settings/network/MobileNetworkSummaryController.java +57 −27 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.network; import static android.telephony.TelephonyManager.MultiSimVariants.UNKNOWN; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; Loading @@ -23,19 +25,22 @@ import android.content.Context; import android.content.Intent; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccManager; import com.android.settings.R; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.widget.AddPreference; import com.android.settingslib.core.AbstractPreferenceController; import java.util.List; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; public class MobileNetworkSummaryController extends AbstractPreferenceController implements SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver { private static final String TAG = "MobileNetSummaryCtlr"; Loading @@ -44,7 +49,8 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController private SubscriptionManager mSubscriptionManager; private SubscriptionsChangeListener mChangeListener; private PreferenceScreen mScreen; private TelephonyManager mTelephonyMgr; private AddPreference mPreference; /** * This controls the summary text and click behavior of the "Mobile network" item on the Loading @@ -64,6 +70,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController public MobileNetworkSummaryController(Context context, Lifecycle lifecycle) { super(context); mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mTelephonyMgr = mContext.getSystemService(TelephonyManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); lifecycle.addObserver(this); } Loading @@ -82,7 +89,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mScreen = screen; mPreference = screen.findPreference(getPreferenceKey()); } @Override Loading @@ -100,29 +107,51 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController } } private void startAddSimFlow() { final Intent intent = new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION); mContext.startActivity(intent); } private boolean shouldEnableAddButton() { // The add button should only show up if the device is in multi-sim mode. return mTelephonyMgr.getMultiSimConfiguration() != UNKNOWN; } private void update() { if (mScreen != null) { final Preference preference = mScreen.findPreference(getPreferenceKey()); refreshSummary(preference); if (mPreference == null) { return; } final boolean enableAddButton = shouldEnableAddButton(); refreshSummary(mPreference); if (!enableAddButton) { mPreference.setOnAddClickListener(null); } else { mPreference.setOnAddClickListener(p -> { startAddSimFlow(); }); } final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions( mSubscriptionManager); preference.setOnPreferenceClickListener(null); preference.setFragment(null); if (subs.size() == 0) { preference.setOnPreferenceClickListener((Preference pref) -> { // TODO(asargent) - need to get correct intent to fire here mPreference.setOnPreferenceClickListener(null); mPreference.setFragment(null); mPreference.setEnabled(true); if (subs.isEmpty()) { if (enableAddButton) { mPreference.setEnabled(false); } else { mPreference.setOnPreferenceClickListener((Preference pref) -> { startAddSimFlow(); return true; }); } } else if (subs.size() == 1) { preference.setOnPreferenceClickListener((Preference pref) -> { mPreference.setOnPreferenceClickListener((Preference pref) -> { final Intent intent = new Intent(mContext, MobileNetworkActivity.class); mContext.startActivity(intent); return true; }); } else { preference.setFragment(MobileNetworkListFragment.class.getCanonicalName()); } mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName()); } } Loading @@ -142,6 +171,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController @Override public void onSubscriptionsChanged() { refreshSummary(mPreference); update(); } } Loading
res/layout/preference_widget_add.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/add_preference_widget" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:paddingStart="?android:attr/listPreferredItemPaddingEnd" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/selectableItemBackground" android:scaleType="center" android:src="@drawable/ic_add_24dp" android:contentDescription="@string/add" />
res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -658,6 +658,8 @@ <string name="apply">Apply</string> <!-- Button label for generic share action [CHAR LIMIT=20] --> <string name="share">Share</string> <!-- Button label for generic add action [CHAR LIMIT=20] --> <string name="add">Add</string> <!-- Title of the Settings activity shown within the application itself. --> <string name="settings_label">Settings</string> Loading
res/xml/mobile_network_list.xml +3 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ android:key="add_more" android:title="@string/mobile_network_list_add_more" android:icon="@drawable/ic_menu_add" android:order="100" /> android:order="100" > <intent android:action="android.telephony.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION" /> </Preference> </PreferenceScreen>
res/xml/network_and_internet_v2.xml +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ android:targetClass="Settings$WifiSettingsActivity" /> </com.android.settings.widget.MasterSwitchPreference> <com.android.settingslib.RestrictedPreference <com.android.settings.widget.AddPreference android:key="mobile_network_list" android:title="@string/network_settings_title" android:summary="@string/summary_placeholder" Loading
src/com/android/settings/network/MobileNetworkSummaryController.java +57 −27 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.network; import static android.telephony.TelephonyManager.MultiSimVariants.UNKNOWN; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; Loading @@ -23,19 +25,22 @@ import android.content.Context; import android.content.Intent; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccManager; import com.android.settings.R; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.widget.AddPreference; import com.android.settingslib.core.AbstractPreferenceController; import java.util.List; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; public class MobileNetworkSummaryController extends AbstractPreferenceController implements SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver { private static final String TAG = "MobileNetSummaryCtlr"; Loading @@ -44,7 +49,8 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController private SubscriptionManager mSubscriptionManager; private SubscriptionsChangeListener mChangeListener; private PreferenceScreen mScreen; private TelephonyManager mTelephonyMgr; private AddPreference mPreference; /** * This controls the summary text and click behavior of the "Mobile network" item on the Loading @@ -64,6 +70,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController public MobileNetworkSummaryController(Context context, Lifecycle lifecycle) { super(context); mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mTelephonyMgr = mContext.getSystemService(TelephonyManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); lifecycle.addObserver(this); } Loading @@ -82,7 +89,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mScreen = screen; mPreference = screen.findPreference(getPreferenceKey()); } @Override Loading @@ -100,29 +107,51 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController } } private void startAddSimFlow() { final Intent intent = new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION); mContext.startActivity(intent); } private boolean shouldEnableAddButton() { // The add button should only show up if the device is in multi-sim mode. return mTelephonyMgr.getMultiSimConfiguration() != UNKNOWN; } private void update() { if (mScreen != null) { final Preference preference = mScreen.findPreference(getPreferenceKey()); refreshSummary(preference); if (mPreference == null) { return; } final boolean enableAddButton = shouldEnableAddButton(); refreshSummary(mPreference); if (!enableAddButton) { mPreference.setOnAddClickListener(null); } else { mPreference.setOnAddClickListener(p -> { startAddSimFlow(); }); } final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions( mSubscriptionManager); preference.setOnPreferenceClickListener(null); preference.setFragment(null); if (subs.size() == 0) { preference.setOnPreferenceClickListener((Preference pref) -> { // TODO(asargent) - need to get correct intent to fire here mPreference.setOnPreferenceClickListener(null); mPreference.setFragment(null); mPreference.setEnabled(true); if (subs.isEmpty()) { if (enableAddButton) { mPreference.setEnabled(false); } else { mPreference.setOnPreferenceClickListener((Preference pref) -> { startAddSimFlow(); return true; }); } } else if (subs.size() == 1) { preference.setOnPreferenceClickListener((Preference pref) -> { mPreference.setOnPreferenceClickListener((Preference pref) -> { final Intent intent = new Intent(mContext, MobileNetworkActivity.class); mContext.startActivity(intent); return true; }); } else { preference.setFragment(MobileNetworkListFragment.class.getCanonicalName()); } mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName()); } } Loading @@ -142,6 +171,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController @Override public void onSubscriptionsChanged() { refreshSummary(mPreference); update(); } }