Merge "Use saved state for preview checkbox if available" into ub-launcher3-qt-r1-dev
am: aca0cbcc08
Change-Id: I919dabf9931ff1d9ab94d30e689b9a9c8bb9e303
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index dc05fa5..eba645c 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -15,6 +15,9 @@
*/
package com.android.wallpaper.picker;
+import static com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED;
+import static com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED;
+
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
@@ -343,8 +346,8 @@
});
// Configure loading indicator with a MaterialProgressDrawable.
- mProgressDrawable =
- new MaterialProgressDrawable(getActivity().getApplicationContext(), mLoadingIndicator);
+ mProgressDrawable = new MaterialProgressDrawable(getActivity().getApplicationContext(),
+ mLoadingIndicator);
mProgressDrawable.setAlpha(255);
mProgressDrawable.setBackgroundColor(getResources().getColor(R.color.material_white_100,
getContext().getTheme()));
@@ -369,34 +372,29 @@
mBottomSheetInitialState = (savedInstanceState == null)
- ? BottomSheetBehavior.STATE_EXPANDED
+ ? STATE_EXPANDED
: savedInstanceState.getInt(KEY_BOTTOM_SHEET_STATE,
- BottomSheetBehavior.STATE_EXPANDED);
+ STATE_EXPANDED);
setUpBottomSheetListeners();
return view;
}
protected int getDeviceDefaultTheme() {
- return BuildCompat.isAtLeastQ() ? getDayNightDeviceDefault()
- : android.R.style.Theme_DeviceDefault;
- }
-
- @TargetApi(29)
- private int getDayNightDeviceDefault() {
- return R.style.Theme_AppCompat_DayNight;
+ return android.R.style.Theme_DeviceDefault;
}
@Override
public void onResume() {
super.onResume();
- WallpaperPreferences preferences = InjectorProvider.getInjector().getPreferences(getActivity());
+ WallpaperPreferences preferences =
+ InjectorProvider.getInjector().getPreferences(getActivity());
preferences.setLastAppActiveTimestamp(new Date().getTime());
- // Show the staged 'load wallpaper' or 'set wallpaper' error dialog fragments if there is one
- // that was unable to be shown earlier when this fragment's hosting activity didn't allow
- // committing fragment transactions.
+ // Show the staged 'load wallpaper' or 'set wallpaper' error dialog fragments if there is
+ // one that was unable to be shown earlier when this fragment's hosting activity didn't
+ // allow committing fragment transactions.
if (mStagedLoadWallpaperErrorDialogFragment != null) {
mStagedLoadWallpaperErrorDialogFragment.show(
getFragmentManager(), TAG_LOAD_WALLPAPER_ERROR_DIALOG_FRAGMENT);
@@ -413,6 +411,11 @@
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.preview_menu, menu);
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
setupPreviewMenu(menu);
}
@@ -433,6 +436,7 @@
protected void setupPreviewMenu(Menu menu) {
mPreview = (CheckBox) menu.findItem(R.id.preview).getActionView();
+ mPreview.setChecked(mBottomSheetInitialState == STATE_COLLAPSED);
mPreview.setOnClickListener(this::setPreviewBehavior);
}
@@ -450,9 +454,9 @@
BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(mBottomSheet);
if (checkbox.isChecked()) {
- behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+ behavior.setState(STATE_COLLAPSED);
} else {
- behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ behavior.setState(STATE_EXPANDED);
}
}
@@ -553,10 +557,10 @@
return;
}
switch (newState) {
- case BottomSheetBehavior.STATE_COLLAPSED:
+ case STATE_COLLAPSED:
setPreviewChecked(true /* checked */);
break;
- case BottomSheetBehavior.STATE_EXPANDED:
+ case STATE_EXPANDED:
setPreviewChecked(false /* checked */);
break;
}
@@ -639,7 +643,13 @@
// Initialize the state of the BottomSheet based on the current state because if the initial
// and current state are the same, the state change listener won't fire and set the correct
// arrow asset and text alpha.
- if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
+ if (bottomSheetBehavior.getState() == STATE_EXPANDED) {
+ setPreviewChecked(false);
+ mAttributionTitle.setAlpha(1f);
+ mAttributionSubtitle1.setAlpha(1f);
+ mAttributionSubtitle2.setAlpha(1f);
+ } else {
+ setPreviewChecked(true);
mAttributionTitle.setAlpha(0f);
mAttributionSubtitle1.setAlpha(0f);
mAttributionSubtitle2.setAlpha(0f);