Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72c3debb authored by Weng Su's avatar Weng Su Committed by Android (Google) Code Review
Browse files

Merge "[Provider Model] Add progress bar to internet panel" into sc-dev

parents 48535ffd c407a2d9
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -83,7 +83,19 @@
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="20sp"/>

        <include layout="@layout/horizontal_divider"/>
        <ProgressBar
            android:id="@+id/progress_bar"
            android:indeterminate="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="1dp"
            android:maxHeight="1dp"
            android:visibility="gone"
            style="@style/TrimmedHorizontalProgressBar"/>

        <include
            android:id="@+id/header_divider"
            layout="@layout/horizontal_divider"/>

        <!-- Note: There is a landscape version of panel_slice_list which supports scrolling. -->
        <include layout="@layout/panel_slice_list"/>
+1 −1
Original line number Diff line number Diff line
@@ -2118,7 +2118,7 @@
    <!-- Wi-Fi settings. text displayed when Wi-Fi is off and network list is empty [CHAR LIMIT=50]-->
    <string name="wifi_empty_list_wifi_off">To see available networks, turn Wi\u2011Fi on.</string>
    <!-- Wi-Fi settings. text displayed when Wi-Fi is on and network list is empty [CHAR LIMIT=50]-->
    <string name="wifi_empty_list_wifi_on">Searching for Wi\u2011Fi networks\u2026</string>
    <string name="wifi_empty_list_wifi_on">Searching for networks\u2026</string>
    <!-- Wifi Settings. text displayed when user has restriction DISALLOW_CONFIG_WIFI [CHAR LIMIT=NONE]-->
    <string name="wifi_empty_list_user_restricted">You don\u2019t have permission to change the Wi\u2011Fi network.</string>
    <!-- Wi-Fi settings. content description for more button [CHAR LIMIT=50]-->
+55 −3
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
    private static final String TAG = "InternetConnectivityPanel";
    private static final int SUBTITLE_TEXT_NONE = -1;
    private static final int SUBTITLE_TEXT_WIFI_IS_TURNED_ON = R.string.wifi_is_turned_on_subtitle;
    private static final int SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS =
            R.string.wifi_empty_list_wifi_on;
    private static final int SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE =
            R.string.non_carrier_network_unavailable;
    private static final int SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE =
@@ -80,9 +82,14 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
            if (intent == null) {
                return;
            }
            if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)
                    || TextUtils.equals(intent.getAction(),
                    WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {

            if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
                showProgressBar();
                updatePanelTitle();
                return;
            }

            if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                updatePanelTitle();
            }
        }
@@ -102,6 +109,12 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
    private DataConnectivityListener mConnectivityListener;
    private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    // Wi-Fi scanning progress bar
    protected boolean mIsProgressBarVisible;
    protected final Runnable mHideProgressBarRunnable = () -> {
        setProgressBarVisible(false);
    };

    private InternetConnectivityPanel(Context context) {
        mContext = context.getApplicationContext();
        mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
@@ -137,6 +150,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        mTelephonyManager.registerTelephonyCallback(
                new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
        mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
        showProgressBar();
        updatePanelTitle();
    }

@@ -151,6 +165,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        mConnectivityListener.stop();
        mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
        mContext.unregisterReceiver(mWifiStateReceiver);
        mContext.getMainThreadHandler().removeCallbacks(mHideProgressBarRunnable);
    }

    /**
@@ -215,6 +230,11 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        mContext.startActivity(getSeeMoreIntent());
    }

    @Override
    public boolean isProgressBarVisible() {
        return mIsProgressBarVisible;
    }

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.PANEL_INTERNET_CONNECTIVITY;
@@ -302,6 +322,11 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve

        final List<ScanResult> wifiList = mWifiManager.getScanResults();
        if (wifiList != null && wifiList.size() != 0) {
            if (mIsProgressBarVisible) {
                // When the Wi-Fi scan result callback is received
                //   Sub-Title: Searching for networks...
                mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
            }
            return;
        }

@@ -334,6 +359,33 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
    }

    protected void showProgressBar() {
        if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
            setProgressBarVisible(false);
            return;
        }

        setProgressBarVisible(true);
        List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
        if (wifiScanResults != null && wifiScanResults.size() > 0) {
            mContext.getMainThreadHandler().postDelayed(mHideProgressBarRunnable,
                    2000 /* delay millis */);
        }
    }

    protected void setProgressBarVisible(boolean visible) {
        if (mIsProgressBarVisible == visible) {
            return;
        }
        mIsProgressBarVisible = visible;

        if (mCallback == null) {
            return;
        }
        mCallback.onProgressBarVisibleChanged();
        updatePanelTitle();
    }

    private class NetworkProviderTelephonyCallback extends TelephonyCallback implements
            TelephonyCallback.DataConnectionStateListener,
            TelephonyCallback.ServiceStateListener {
+7 −0
Original line number Diff line number Diff line
@@ -110,4 +110,11 @@ public interface PanelContent extends Instrumentable {
    default int getViewType() {
        return 0;
    }

    /**
     * @return {@code true} to enable progress bar visibility, {@code false} otherwise.
     */
    default boolean isProgressBarVisible() {
        return false;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -42,4 +42,9 @@ public interface PanelContentCallback {
     * It will be called when panel requests to change the title.
     */
    void onTitleChanged();

    /**
     * It will be called when panel requests to change the progress bar visibility.
     */
    void onProgressBarVisibleChanged();
}
Loading