[DataUsage] Adjusting the control of display sequence
Showing a usage graph before end of statistic would lead to incorrect height of usage graph, and another update would lead to layout moved a little bit. This change tries to improve it through: 1. Start the loading animation earlier, and stop animation when statistics loaded. (Only effective when UI re-create.) 2. Update the UI only when statistics are ready. Bug: 187019210 Test: robotest ChartDataUsagePreferenceTest DataUsageListTest Change-Id: Ic83f2422b6c6d55948110d652ee24234f43b6445
This commit is contained in:
@@ -48,8 +48,8 @@ public class ChartDataUsagePreference extends Preference {
|
||||
// Set to half a meg for now.
|
||||
private static final long RESOLUTION = DataUnit.MEBIBYTES.toBytes(1) / 2;
|
||||
|
||||
private final int mWarningColor;
|
||||
private final int mLimitColor;
|
||||
private int mWarningColor;
|
||||
private int mLimitColor;
|
||||
|
||||
private Resources mResources;
|
||||
private NetworkPolicy mPolicy;
|
||||
@@ -58,24 +58,25 @@ public class ChartDataUsagePreference extends Preference {
|
||||
private NetworkCycleChartData mNetworkCycleChartData;
|
||||
private int mSecondaryColor;
|
||||
private int mSeriesColor;
|
||||
private UsageView mUsageView;
|
||||
private boolean mSuspendUiUpdate; // Suppress UI updates to save some CPU time.
|
||||
|
||||
public ChartDataUsagePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mResources = context.getResources();
|
||||
setSelectable(false);
|
||||
mLimitColor = Utils.getColorAttrDefaultColor(context, android.R.attr.colorError);
|
||||
mWarningColor = Utils.getColorAttrDefaultColor(context, android.R.attr.textColorSecondary);
|
||||
setLayoutResource(R.layout.data_usage_graph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
final UsageView chart = (UsageView) holder.findViewById(R.id.data_usage);
|
||||
if (mNetworkCycleChartData == null) {
|
||||
mUsageView = (UsageView) holder.findViewById(R.id.data_usage);
|
||||
}
|
||||
|
||||
private void onUpdateView() {
|
||||
UsageView chart = mUsageView;
|
||||
if ((chart == null) || (mNetworkCycleChartData == null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int top = getTop();
|
||||
chart.clearPaths();
|
||||
chart.configureGraph(toInt(mEnd - mStart), top);
|
||||
@@ -291,9 +292,16 @@ public class ChartDataUsagePreference extends Preference {
|
||||
return new SpannableStringBuilder().append(label, new ForegroundColorSpan(mLimitColor), 0);
|
||||
}
|
||||
|
||||
public void onPreparingChartData() {
|
||||
mSuspendUiUpdate = true;
|
||||
}
|
||||
|
||||
public void setNetworkPolicy(NetworkPolicy policy) {
|
||||
mPolicy = policy;
|
||||
notifyChanged();
|
||||
if ((!mSuspendUiUpdate) && (mResources != null)) {
|
||||
onUpdateView();
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public long getInspectStart() {
|
||||
@@ -305,15 +313,31 @@ public class ChartDataUsagePreference extends Preference {
|
||||
}
|
||||
|
||||
public void setNetworkCycleData(NetworkCycleChartData data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
mNetworkCycleChartData = data;
|
||||
mStart = data.getStartTime();
|
||||
mEnd = data.getEndTime();
|
||||
if (mResources == null) {
|
||||
Context context = getContext();
|
||||
mResources = context.getResources();
|
||||
mLimitColor = Utils.getColorAttrDefaultColor(context, android.R.attr.colorError);
|
||||
mWarningColor = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorSecondary);
|
||||
setLayoutResource(R.layout.data_usage_graph);
|
||||
}
|
||||
onUpdateView();
|
||||
notifyChanged();
|
||||
mSuspendUiUpdate = false;
|
||||
}
|
||||
|
||||
public void setColors(int seriesColor, int secondaryColor) {
|
||||
mSeriesColor = seriesColor;
|
||||
mSecondaryColor = secondaryColor;
|
||||
notifyChanged();
|
||||
if ((!mSuspendUiUpdate) && (mResources != null)) {
|
||||
onUpdateView();
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -151,7 +151,20 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
public void onViewCreated(View v, Bundle savedInstanceState) {
|
||||
super.onViewCreated(v, savedInstanceState);
|
||||
|
||||
// Show loading
|
||||
mLoadingViewController = new LoadingViewController(
|
||||
v.findViewById(R.id.loading_container), getListView());
|
||||
mLoadingViewController.showLoadingViewDelayed();
|
||||
}
|
||||
|
||||
private void onEndOfLoading() {
|
||||
if (mHeader != null) {
|
||||
return;
|
||||
}
|
||||
mHeader = setPinnedHeaderView(R.layout.apps_filter_spinner);
|
||||
|
||||
mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
|
||||
|
||||
mHeader.findViewById(R.id.filter_settings).setOnClickListener(btn -> {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
|
||||
@@ -162,8 +175,6 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
.setArguments(args)
|
||||
.launch();
|
||||
});
|
||||
mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
|
||||
mCycleSpinner.setVisibility(View.GONE);
|
||||
mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() {
|
||||
@Override
|
||||
public void setAdapter(CycleAdapter cycleAdapter) {
|
||||
@@ -195,10 +206,6 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
super.sendAccessibilityEvent(host, eventType);
|
||||
}
|
||||
});
|
||||
|
||||
mLoadingViewController = new LoadingViewController(
|
||||
getView().findViewById(R.id.loading_container), getListView());
|
||||
mLoadingViewController.showLoadingViewDelayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,6 +213,10 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
super.onResume();
|
||||
mDataStateListener.start(mSubId);
|
||||
|
||||
if (mChart != null) {
|
||||
mChart.onPreparingChartData();
|
||||
}
|
||||
|
||||
// kick off loader for network history
|
||||
// TODO: consider chaining two loaders together instead of reloading
|
||||
// network history when showing app detail.
|
||||
@@ -526,11 +537,13 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<NetworkCycleChartData>> loader,
|
||||
List<NetworkCycleChartData> data) {
|
||||
mLoadingViewController.showContent(false /* animate */);
|
||||
onEndOfLoading();
|
||||
if (mLoadingViewController != null) {
|
||||
mLoadingViewController.showContent(false /* animate */);
|
||||
}
|
||||
mCycleData = data;
|
||||
// calculate policy cycles based on available data
|
||||
updatePolicy();
|
||||
mCycleSpinner.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user