Merge "[Provider Model] Add progress bar to internet panel" into sc-dev
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -101,6 +102,8 @@ public class PanelFragment extends Fragment {
|
||||
private int mMaxHeight;
|
||||
private View mFooterDivider;
|
||||
private boolean mPanelCreating;
|
||||
private ProgressBar mProgressBar;
|
||||
private View mHeaderDivider;
|
||||
|
||||
private final Map<Uri, LiveData<Slice>> mSliceLiveData = new LinkedHashMap<>();
|
||||
|
||||
@@ -208,6 +211,8 @@ public class PanelFragment extends Fragment {
|
||||
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
||||
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
||||
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
|
||||
mProgressBar = mLayoutView.findViewById(R.id.progress_bar);
|
||||
mHeaderDivider = mLayoutView.findViewById(R.id.header_divider);
|
||||
|
||||
// Make the panel layout gone here, to avoid janky animation when updating from old panel.
|
||||
// We will make it visible once the panel is ready to load.
|
||||
@@ -233,6 +238,8 @@ public class PanelFragment extends Fragment {
|
||||
|
||||
mMetricsProvider = FeatureFactory.getFactory(activity).getMetricsFeatureProvider();
|
||||
|
||||
updateProgressBar();
|
||||
|
||||
mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
|
||||
// Add predraw listener to remove the animation and while we wait for Slices to load.
|
||||
mLayoutView.getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
|
||||
@@ -314,6 +321,16 @@ public class PanelFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgressBar() {
|
||||
if (mPanel.isProgressBarVisible()) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mHeaderDivider.setVisibility(View.GONE);
|
||||
} else {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
mHeaderDivider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAllSlices() {
|
||||
mSliceLiveData.clear();
|
||||
final List<Uri> sliceUris = mPanel.getSlices();
|
||||
@@ -531,6 +548,13 @@ public class PanelFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressBarVisibleChanged() {
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
updateProgressBar();
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
FragmentActivity getFragmentActivity() {
|
||||
return getActivity();
|
||||
|
Reference in New Issue
Block a user