Make views of preview fragment easier to be substituted
1. Add containers for views.
2. Extract tab setup logic.
3. Clean up for ag/14251265.
Bug: 185198554
Test: manual
Change-Id: I26f22abc9c539f2410c51540dc9819c1f94d2362
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index fb701bb..7e99797 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -25,6 +25,7 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
+import android.app.WallpaperColors;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -78,7 +79,7 @@
* Fragment which displays the UI for previewing an individual static wallpaper and its attribution
* information.
*/
-public class ImagePreviewFragment extends PreviewFragment {
+public class ImagePreviewFragment extends PreviewFragment implements WallpaperColorsLoader.Callback{
private static final float DEFAULT_WALLPAPER_MAX_ZOOM = 8f;
@@ -95,11 +96,10 @@
private SurfaceView mWorkspaceSurface;
private WorkspaceSurfaceHolderCallback mWorkspaceSurfaceCallback;
private SurfaceView mWallpaperSurface;
- private ViewGroup mLockPreviewContainer;
- private LockScreenPreviewer2 mLockScreenPreviewer;
private WallpaperInfoView mWallpaperInfoView;
- protected boolean mSkipPreviewRendering;
+ protected ViewGroup mLockPreviewContainer;
+ protected LockScreenPreviewer2 mLockScreenPreviewer;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -148,26 +148,7 @@
mLockScreenPreviewer = new LockScreenPreviewer2(getLifecycle(), getContext(),
mLockPreviewContainer);
- TabLayout tabs = view.findViewById(R.id.pill_tabs);
- tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.home_screen_message)));
- tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.lock_screen_message)));
- tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
- @Override
- public void onTabSelected(TabLayout.Tab tab) {
- updateScreenPreview(tab.getPosition() == 0);
- }
-
- @Override
- public void onTabUnselected(TabLayout.Tab tab) {}
-
- @Override
- public void onTabReselected(TabLayout.Tab tab) {}
- });
-
- // The TabLayout only contains below tabs
- // 0. Home tab
- // 1. Lock tab
- tabs.getTabAt(mViewAsHome ? 0 : 1).select();
+ setUpTabs(view.findViewById(R.id.pill_tabs));
updateScreenPreview(mViewAsHome);
view.measure(makeMeasureSpec(mScreenSize.x, EXACTLY),
@@ -176,10 +157,8 @@
.setRadius(SizeCalculator.getPreviewCornerRadius(
activity, mContainer.getMeasuredWidth()));
- if (!mSkipPreviewRendering) {
- renderImageWallpaper();
- renderWorkspaceSurface();
- }
+ renderImageWallpaper();
+ renderWorkspaceSurface();
// Trim some memory from Glide to make room for the full-size image in this fragment.
Glide.get(activity).setMemoryCategory(MemoryCategory.LOW);
@@ -190,11 +169,13 @@
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- if (!mSkipPreviewRendering) {
- WallpaperColorsLoader.getWallpaperColors(getContext(),
- mWallpaper.getThumbAsset(getContext()),
- mLockScreenPreviewer::setColor);
- }
+ WallpaperColorsLoader.getWallpaperColors(getContext(),
+ mWallpaper.getThumbAsset(getContext()), this);
+ }
+
+ @Override
+ public void onLoaded(@Nullable WallpaperColors colors) {
+ mLockScreenPreviewer.setColor(colors);
}
@Override
@@ -282,13 +263,33 @@
});
}
+ protected void setUpTabs(TabLayout tabs) {
+ tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.home_screen_message)));
+ tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.lock_screen_message)));
+ tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
+ @Override
+ public void onTabSelected(TabLayout.Tab tab) {
+ updateScreenPreview(tab.getPosition() == 0);
+ }
+
+ @Override
+ public void onTabUnselected(TabLayout.Tab tab) {}
+
+ @Override
+ public void onTabReselected(TabLayout.Tab tab) {}
+ });
+
+ // The TabLayout only contains below tabs
+ // 0. Home tab
+ // 1. Lock tab
+ tabs.getTabAt(mViewAsHome ? 0 : 1).select();
+ }
+
/**
* Initializes MosaicView by initializing tiling, setting a fallback page bitmap, and
* initializing a zoom-scroll observer and click listener.
*/
private void initFullResView() {
- if (getContext() == null || mSkipPreviewRendering) return;
-
// Minimum scale will only be respected under this scale type.
mFullResImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM);
// When we set a minimum scale bigger than the scale with which the full image is shown,