问题描述:
“Actual Results: Volume options are missing on Sound & vibration menu if press volume button and three dots icon for the first time.
Expected Results: Volume options should show correctly on Sound & vibration menu after press volume button and three dots icon every time.
Reproduction Steps:
- Flash the latest image.
- Press any hardware volume button -> three dots (for the first time).
- Sound & vibration menu launched.
- Find volume options are missing. ==> Problem
- Press any hardware volume button -> three dots again.
- Find volume options can show correctly.
Reproducibility: The first time
”
解决方案是:在第一次点击时增加了一些延迟(1000ms).
packages/apps/Settings/src/com/android/settings/panel/PanelFragment.java
import static android.content.Context.MODE_PRIVATE;
import android.content.SharedPreferences;
//BSPA-222615 Determine whether it is the first click or not.
private boolean isHasOpened;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
mLayoutView = inflater.inflate(R.layout.panel_layout, container, false);
mLayoutView.getViewTreeObserver()
.addOnGlobalLayoutListener(mPanelLayoutListener);
mMaxHeight = getResources().getDimensionPixelSize(R.dimen.output_switcher_slice_max_height);
mPanelCreating = true;
//BSAP-222615 Determine whether it is the first click or not
SharedPreferences pref = getActivity().getSharedPreferences("paneldata",MODE_PRIVATE);
isHasOpened = pref.getBoolean("volumedata",false);
createPanelContent();
return mLayoutView;
}
private void loadAllSlices() {
mSliceLiveData.clear();
...
final SliceMetadata metadata = SliceMetadata.from(getActivity(), slice);
if (slice == null || metadata.isErrorSlice()) {
removeSliceLiveData(uri);
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
} else if (metadata.getLoadingState() == SliceMetadata.LOADED_ALL) {
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
} else {
Handler handler = new Handler();
handler.postDelayed(() -> {
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
loadPanelWhenReady();
}, isHasOpened ? DURATION_SLICE_BINDING_TIMEOUT_MS:1000);
}
loadPanelWhenReady();
...
}
private void removeSliceLiveData(Uri uri) {
final List<String> allowList = Arrays.asList(
getResources().getStringArray(
R.array.config_panel_keep_observe_uri));
if (!allowList.contains(uri.toString())) {
mSliceLiveData.remove(uri);
}
}
/**
* When all of the Slices have loaded for the first time, then we can setup the
* {@link RecyclerView}.
* <p>
* When the Recyclerview has been laid out, we can begin the animation with the
* {@link mOnGlobalLayoutListener}, which calls {@link #animateIn()}.
*/
private void loadPanelWhenReady() {
if (mPanelSlicesLoaderCountdownLatch.isPanelReadyToLoad()) {
mAdapter = new PanelSlicesAdapter(
this, mSliceLiveData, mPanel.getMetricsCategory());
mPanelSlices.setAdapter(mAdapter);
mPanelSlices.getViewTreeObserver()
.addOnGlobalLayoutListener(mOnGlobalLayoutListener);
mPanelSlices.setVisibility(View.VISIBLE);
final FragmentActivity activity = getActivity();
if (activity == null) {
return;
}
final DividerItemDecoration itemDecoration = new DividerItemDecoration(activity);
itemDecoration
.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
if (mPanelSlices.getItemDecorationCount() == 0) {
mPanelSlices.addItemDecoration(itemDecoration);
}
}
//BSPA-222615 Modify the attribute value after the first click.
SharedPreferences.Editor editor = getActivity().getSharedPreferences("paneldata",MODE_PRIVATE).edit();
editor.putBoolean("volumedata",true);
editor.apply();
}