Revert "[DataUsage] Adjusting the control of display sequence"

This reverts commit b8491032d7.

Bug: 277162513
Test: Manual
Test: Unit test
Change-Id: I5a84a9b1a99b1da4c18d786a6dff062b53cd46c6
This commit is contained in:
Chaohui Wang
2023-04-22 08:35:55 +08:00
parent 52b723beef
commit f46b33bbc4
4 changed files with 57 additions and 103 deletions

View File

@@ -48,8 +48,8 @@ public class ChartDataUsagePreference extends Preference {
// Set to half a meg for now. // Set to half a meg for now.
private static final long RESOLUTION = DataUnit.MEBIBYTES.toBytes(1) / 2; private static final long RESOLUTION = DataUnit.MEBIBYTES.toBytes(1) / 2;
private int mWarningColor; private final int mWarningColor;
private int mLimitColor; private final int mLimitColor;
private Resources mResources; private Resources mResources;
private NetworkPolicy mPolicy; private NetworkPolicy mPolicy;
@@ -58,25 +58,24 @@ public class ChartDataUsagePreference extends Preference {
private NetworkCycleChartData mNetworkCycleChartData; private NetworkCycleChartData mNetworkCycleChartData;
private int mSecondaryColor; private int mSecondaryColor;
private int mSeriesColor; private int mSeriesColor;
private UsageView mUsageView;
private boolean mSuspendUiUpdate; // Suppress UI updates to save some CPU time.
public ChartDataUsagePreference(Context context, AttributeSet attrs) { public ChartDataUsagePreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mResources = context.getResources();
setSelectable(false); 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 @Override
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
mUsageView = (UsageView) holder.findViewById(R.id.data_usage); final UsageView chart = (UsageView) holder.findViewById(R.id.data_usage);
} if (mNetworkCycleChartData == null) {
private void onUpdateView() {
UsageView chart = mUsageView;
if ((chart == null) || (mNetworkCycleChartData == null)) {
return; return;
} }
final int top = getTop(); final int top = getTop();
chart.clearPaths(); chart.clearPaths();
chart.configureGraph(toInt(mEnd - mStart), top); chart.configureGraph(toInt(mEnd - mStart), top);
@@ -292,16 +291,9 @@ public class ChartDataUsagePreference extends Preference {
return new SpannableStringBuilder().append(label, new ForegroundColorSpan(mLimitColor), 0); return new SpannableStringBuilder().append(label, new ForegroundColorSpan(mLimitColor), 0);
} }
public void onPreparingChartData() {
mSuspendUiUpdate = true;
}
public void setNetworkPolicy(NetworkPolicy policy) { public void setNetworkPolicy(NetworkPolicy policy) {
mPolicy = policy; mPolicy = policy;
if ((!mSuspendUiUpdate) && (mResources != null)) { notifyChanged();
onUpdateView();
notifyChanged();
}
} }
public long getInspectStart() { public long getInspectStart() {
@@ -313,31 +305,15 @@ public class ChartDataUsagePreference extends Preference {
} }
public void setNetworkCycleData(NetworkCycleChartData data) { public void setNetworkCycleData(NetworkCycleChartData data) {
if (data == null) {
return;
}
mNetworkCycleChartData = data; mNetworkCycleChartData = data;
mStart = data.getStartTime(); mStart = data.getStartTime();
mEnd = data.getEndTime(); 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(); notifyChanged();
mSuspendUiUpdate = false;
} }
public void setColors(int seriesColor, int secondaryColor) { public void setColors(int seriesColor, int secondaryColor) {
mSeriesColor = seriesColor; mSeriesColor = seriesColor;
mSecondaryColor = secondaryColor; mSecondaryColor = secondaryColor;
if ((!mSuspendUiUpdate) && (mResources != null)) { notifyChanged();
onUpdateView();
notifyChanged();
}
} }
} }

View File

@@ -172,20 +172,7 @@ public class DataUsageList extends DataUsageBaseFragment
public void onViewCreated(View v, Bundle savedInstanceState) { public void onViewCreated(View v, Bundle savedInstanceState) {
super.onViewCreated(v, 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); mHeader = setPinnedHeaderView(R.layout.apps_filter_spinner);
mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
mHeader.findViewById(R.id.filter_settings).setOnClickListener(btn -> { mHeader.findViewById(R.id.filter_settings).setOnClickListener(btn -> {
final Bundle args = new Bundle(); final Bundle args = new Bundle();
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate); args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
@@ -196,6 +183,8 @@ public class DataUsageList extends DataUsageBaseFragment
.setArguments(args) .setArguments(args)
.launch(); .launch();
}); });
mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
mCycleSpinner.setVisibility(View.GONE);
mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() { mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() {
@Override @Override
public void setAdapter(CycleAdapter cycleAdapter) { public void setAdapter(CycleAdapter cycleAdapter) {
@@ -227,6 +216,10 @@ public class DataUsageList extends DataUsageBaseFragment
super.sendAccessibilityEvent(host, eventType); super.sendAccessibilityEvent(host, eventType);
} }
}); });
mLoadingViewController = new LoadingViewController(
getView().findViewById(R.id.loading_container), getListView());
mLoadingViewController.showLoadingViewDelayed();
} }
@Override @Override
@@ -234,10 +227,6 @@ public class DataUsageList extends DataUsageBaseFragment
super.onResume(); super.onResume();
mDataStateListener.start(mSubId); mDataStateListener.start(mSubId);
if (mChart != null) {
mChart.onPreparingChartData();
}
// kick off loader for network history // kick off loader for network history
// TODO: consider chaining two loaders together instead of reloading // TODO: consider chaining two loaders together instead of reloading
// network history when showing app detail. // network history when showing app detail.
@@ -599,13 +588,11 @@ public class DataUsageList extends DataUsageBaseFragment
@Override @Override
public void onLoadFinished(Loader<List<NetworkCycleChartData>> loader, public void onLoadFinished(Loader<List<NetworkCycleChartData>> loader,
List<NetworkCycleChartData> data) { List<NetworkCycleChartData> data) {
onEndOfLoading(); mLoadingViewController.showContent(false /* animate */);
if (mLoadingViewController != null) {
mLoadingViewController.showContent(false /* animate */);
}
mCycleData = data; mCycleData = data;
// calculate policy cycles based on available data // calculate policy cycles based on available data
updatePolicy(); updatePolicy();
mCycleSpinner.setVisibility(View.VISIBLE);
} }
@Override @Override

View File

@@ -17,10 +17,7 @@ package com.android.settings.datausage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -166,32 +163,23 @@ public class ChartDataUsagePreferenceTest {
@Test @Test
public void notifyChange_nonEmptyDataUsage_shouldHaveSingleContentDescription() { public void notifyChange_nonEmptyDataUsage_shouldHaveSingleContentDescription() {
final ArgumentCaptor<CharSequence> contentCaptor = final UsageView chart = (UsageView) mHolder.findViewById(R.id.data_usage);
ArgumentCaptor.forClass(CharSequence.class); final TextView labelTop = (TextView) mHolder.findViewById(R.id.label_top);
final UsageView chart = mock(UsageView.class); final TextView labelMiddle = (TextView) mHolder.findViewById(R.id.label_middle);
doReturn(chart).when(mHolder).findViewById(R.id.data_usage); final TextView labelBottom = (TextView) mHolder.findViewById(R.id.label_bottom);
final TextView labelTop = mock(TextView.class); final TextView labelStart = (TextView) mHolder.findViewById(R.id.label_start);
doReturn(labelTop).when(mHolder).findViewById(R.id.label_top); final TextView labelEnd = (TextView) mHolder.findViewById(R.id.label_end);
final TextView labelMiddle = mock(TextView.class);
doReturn(labelMiddle).when(mHolder).findViewById(R.id.label_middle);
final TextView labelBottom = mock(TextView.class);
doReturn(labelBottom).when(mHolder).findViewById(R.id.label_bottom);
final TextView labelStart = mock(TextView.class);
doReturn(labelStart).when(mHolder).findViewById(R.id.label_start);
final TextView labelEnd = mock(TextView.class);
doReturn(labelEnd).when(mHolder).findViewById(R.id.label_end);
createTestNetworkData(); createTestNetworkData();
mPreference.onBindViewHolder(mHolder);
mPreference.setNetworkCycleData(mNetworkCycleChartData); mPreference.setNetworkCycleData(mNetworkCycleChartData);
verify(chart).setContentDescription(contentCaptor.capture()); mPreference.onBindViewHolder(mHolder);
assertThat(contentCaptor.getValue()).isNotNull();
verify(labelTop, never()).setContentDescription(any()); assertThat(chart.getContentDescription()).isNotNull();
verify(labelMiddle, never()).setContentDescription(any()); assertThat(labelTop.getContentDescription()).isNull();
verify(labelBottom, never()).setContentDescription(any()); assertThat(labelMiddle.getContentDescription()).isNull();
verify(labelStart, never()).setContentDescription(any()); assertThat(labelBottom.getContentDescription()).isNull();
verify(labelEnd, never()).setContentDescription(any()); assertThat(labelStart.getContentDescription()).isNull();
assertThat(labelEnd.getContentDescription()).isNull();
} }
@Test @Test

View File

@@ -222,23 +222,32 @@ public class DataUsageListTest {
} }
@Test @Test
public void onViewCreated_shouldNotSetCycleSpinner() { public void onViewCreated_shouldHideCycleSpinner() {
View view = constructRootView(); final View view = new View(mActivity);
final View header = getHeader();
final Spinner spinner = getSpinner(header);
spinner.setVisibility(View.VISIBLE);
doReturn(header).when(mDataUsageList).setPinnedHeaderView(anyInt());
doReturn(view).when(mDataUsageList).getView();
mDataUsageList.onViewCreated(view, null); mDataUsageList.onViewCreated(view, null);
assertThat(getSpinner(view)).isNull(); assertThat(spinner.getVisibility()).isEqualTo(View.GONE);
} }
@Test @Test
public void onLoadFinished_networkCycleDataCallback_shouldSetCycleSpinner() { public void onLoadFinished_networkCycleDataCallback_shouldShowCycleSpinner() {
final View view = constructRootView(); final LoadingViewController loadingViewController = mock(LoadingViewController.class);
mDataUsageList.mLoadingViewController = loadingViewController;
final Spinner spinner = getSpinner(getHeader());
spinner.setVisibility(View.INVISIBLE);
mDataUsageList.mCycleSpinner = spinner;
assertThat(spinner.getVisibility()).isEqualTo(View.INVISIBLE);
doNothing().when(mDataUsageList).updatePolicy(); doNothing().when(mDataUsageList).updatePolicy();
doReturn(setupHeaderView(view)).when(mDataUsageList).setPinnedHeaderView(anyInt());
mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, null); mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, null);
assertThat(getSpinner(view)).isNotNull(); assertThat(spinner.getVisibility()).isEqualTo(View.VISIBLE);
} }
@Test @Test
@@ -249,25 +258,19 @@ public class DataUsageListTest {
verify(mLoaderManager).destroyLoader(DataUsageList.LOADER_SUMMARY); verify(mLoaderManager).destroyLoader(DataUsageList.LOADER_SUMMARY);
} }
private View constructRootView() { private View getHeader() {
View rootView = LayoutInflater.from(mActivity) final View rootView = LayoutInflater.from(mActivity)
.inflate(R.layout.preference_list_fragment, null, false); .inflate(R.layout.preference_list_fragment, null, false);
return rootView; final FrameLayout pinnedHeader = rootView.findViewById(R.id.pinned_header);
}
private View setupHeaderView(View rootView) {
final FrameLayout pinnedHeader = (FrameLayout) rootView.findViewById(R.id.pinned_header);
final View header = mActivity.getLayoutInflater() final View header = mActivity.getLayoutInflater()
.inflate(R.layout.apps_filter_spinner, pinnedHeader, true); .inflate(R.layout.apps_filter_spinner, pinnedHeader, false);
return header; return header;
} }
private Spinner getSpinner(View rootView) { private Spinner getSpinner(View header) {
final FrameLayout pinnedHeader = (FrameLayout) rootView.findViewById(R.id.pinned_header); final Spinner spinner = header.findViewById(R.id.filter_spinner);
if (pinnedHeader == null) { return spinner;
return null;
}
return pinnedHeader.findViewById(R.id.filter_spinner);
} }
@Implements(DataUsageBaseFragment.class) @Implements(DataUsageBaseFragment.class)