Cleanup the AppbarFragment usage in PreviewFragment
Cleanup only, no business logic change
- AppbarFragment had a good pattern to set title on toolbar. PreviewFragment won't do it throught accessing activity tool bar.
- AppbarFragment had a good pattern to set bottom action bar, which is widely used within the app, PreviewFragment won't do it by itself.
Test: Manually
Fixes: 160211359
Fixes: 160206877
Change-Id: I5cc4c05f1b885adbbe0f66afac3fb1ea6183ba0b
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index ee04541..8e5c6bb 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -32,7 +32,6 @@
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Bundle;
-import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.SurfaceControlViewHost;
@@ -77,13 +76,11 @@
private static final float DEFAULT_WALLPAPER_MAX_ZOOM = 8f;
- private final Handler mHandler = new Handler();
private final WallpaperSurfaceCallback mWallpaperSurfaceCallback =
new WallpaperSurfaceCallback();
private SubsamplingScaleImageView mFullResImageView;
private Asset mWallpaperAsset;
- private Point mDefaultCropSurfaceSize;
private Point mScreenSize;
private Point mRawWallpaperSize; // Native size of wallpaper image.
private ImageView mLowResImageView;
@@ -152,7 +149,6 @@
mLock.setOnClickListener(v -> updateScreenPreview(/* isHomeSelected= */ false));
mHome.setOnClickListener(v -> updateScreenPreview(/* isHomeSelected= */ true));
- onBottomActionBarReady(mBottomActionBar);
view.measure(makeMeasureSpec(mScreenSize.x, EXACTLY),
makeMeasureSpec(mScreenSize.y, EXACTLY));
@@ -165,34 +161,7 @@
// Trim some memory from Glide to make room for the full-size image in this fragment.
Glide.get(activity).setMemoryCategory(MemoryCategory.LOW);
-
- mDefaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize(
- getResources(), activity.getWindowManager().getDefaultDisplay());
-
- mBottomActionBar.disableActions();
- mWallpaperAsset.decodeRawDimensions(getActivity(), dimensions -> {
- if (mBottomActionBar != null) {
- mBottomActionBar.enableActions();
- }
-
- // Don't continue loading the wallpaper if the Fragment is detached.
- if (getActivity() == null) {
- return;
- }
-
- // Return early and show a dialog if dimensions are null (signaling a decoding error).
- if (dimensions == null) {
- showLoadWallpaperErrorDialog();
- return;
- }
-
- mRawWallpaperSize = dimensions;
-
- setUpExploreIntentAndLabel(ImagePreviewFragment.this::initFullResView);
- });
-
setUpLoadingIndicator();
-
return view;
}
@@ -238,7 +207,6 @@
R.layout.wallpaper_info_view, /* root= */null);
mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION);
mBottomActionBar.showActionsOnly(INFORMATION, EDIT, APPLY);
- mBottomActionBar.bindBackButtonToSystemBackKey(getActivity());
mBottomActionBar.setActionClickListener(EDIT, v ->
setEditingEnabled(mBottomActionBar.isActionSelected(EDIT))
);
@@ -263,11 +231,28 @@
// Will trigger onActionSelected callback to update the editing state.
mBottomActionBar.setDefaultSelectedButton(EDIT);
mBottomActionBar.show();
- }
- @Override
- protected CharSequence getExploreButtonLabel(Context context) {
- return context.getString(mWallpaper.getActionLabelRes(context));
+ mBottomActionBar.disableActions();
+ mWallpaperAsset.decodeRawDimensions(getActivity(), dimensions -> {
+ if (mBottomActionBar != null) {
+ mBottomActionBar.enableActions();
+ }
+
+ // Don't continue loading the wallpaper if the Fragment is detached.
+ if (getActivity() == null) {
+ return;
+ }
+
+ // Return early and show a dialog if dimensions are null (signaling a decoding error).
+ if (dimensions == null) {
+ showLoadWallpaperErrorDialog();
+ return;
+ }
+
+ mRawWallpaperSize = dimensions;
+
+ setUpExploreIntentAndLabel(ImagePreviewFragment.this::initFullResView);
+ });
}
/**