Clean up PreviewFragment and its child classes (Part 1)
- Delete v1 layout file
- Remove USE_NEW_UI and related code
- Delete unused code
More to come
Bug: 157620059
Test: Manual
Change-Id: Iffe14f2bddf7a4a0e351ffbe0df9714cda85fa93
diff --git a/res/layout/fragment_image_preview.xml b/res/layout/fragment_image_preview.xml
deleted file mode 100755
index a7273fb..0000000
--- a/res/layout/fragment_image_preview.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="false">
-
- <ImageView
- android:id="@+id/low_res_image"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerCrop"
- android:background="@android:color/black"/>
-
- <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
- android:id="@+id/full_res_image"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
-
- <androidx.core.widget.ContentLoadingProgressBar
- android:id="@+id/loading_indicator"
- style="@android:style/Widget.DeviceDefault.ProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:indeterminate="true"/>
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="true">
-
- <androidx.coordinatorlayout.widget.CoordinatorLayout
- android:id="@+id/coordinator_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom">
-
- <FrameLayout
- android:id="@+id/bottom_sheet"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/preview_bottom_sheet_background"
- android:theme="@style/WallpaperPicker.BottomPaneStyle"
- app:behavior_peekHeight="@dimen/preview_attribution_pane_collapsed_height"
- app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
- <include
- layout="@layout/preview_page_info"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
- </FrameLayout>
-
- </androidx.coordinatorlayout.widget.CoordinatorLayout>
-
- <View
- android:layout_width="match_parent"
- android:layout_height="@dimen/preview_gradient_background_height"
- android:layout_gravity="top"
- android:background="@drawable/gradient_background"/>
- <androidx.appcompat.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="top"
- style="@style/TranslucentToolbarStyle"/>
-
- </FrameLayout>
-
-</FrameLayout>
diff --git a/res/layout/fragment_live_preview.xml b/res/layout/fragment_live_preview.xml
deleted file mode 100755
index 0185272..0000000
--- a/res/layout/fragment_live_preview.xml
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <FrameLayout
- android:id="@+id/loading"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@android:color/black"
- android:forceHasOverlappingRendering="false">
-
- <androidx.core.widget.ContentLoadingProgressBar
- android:id="@+id/loading_indicator"
- style="@android:style/Widget.DeviceDefault.ProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:indeterminate="true"/>
-
- </FrameLayout>
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="true">
-
- <androidx.coordinatorlayout.widget.CoordinatorLayout
- android:id="@+id/coordinator_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom">
-
- <LinearLayout
- android:id="@+id/bottom_sheet"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:background="@drawable/preview_bottom_sheet_background"
- android:theme="@style/WallpaperPicker.BottomPaneStyle"
- app:behavior_peekHeight="@dimen/preview_attribution_pane_collapsed_height"
- app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
-
- <com.google.android.material.tabs.TabLayout
- android:id="@+id/tablayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- app:tabTextAppearance="@style/WallpaperPicker.Preview.TextAppearance.NoAllCaps"
- app:tabIndicatorColor="?android:attr/textColorPrimary"
- android:visibility="gone"/>
-
- <com.android.wallpaper.widget.ConstraintViewPager
- android:id="@+id/viewpager"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- </LinearLayout>
-
- </androidx.coordinatorlayout.widget.CoordinatorLayout>
-
- <View
- android:layout_width="match_parent"
- android:layout_height="@dimen/preview_gradient_background_height"
- android:layout_gravity="top"
- android:background="@drawable/gradient_background"/>
-
- <androidx.appcompat.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="top"
- style="@style/TranslucentToolbarStyle"/>
-
- </FrameLayout>
-
-</FrameLayout>
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index 9c2e244..ce7c430 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -105,7 +105,7 @@
@Override
protected int getLayoutResId() {
- return USE_NEW_UI ? R.layout.fragment_image_preview_v2 : R.layout.fragment_image_preview;
+ return R.layout.fragment_image_preview_v2;
}
@@ -127,49 +127,44 @@
mScreenSize = ScreenSizeCalculator.getInstance().getScreenSize(
activity.getWindowManager().getDefaultDisplay());
- if (USE_NEW_UI) {
- // TODO: Consider moving some part of this to the base class when live preview is ready.
- view.findViewById(R.id.low_res_image).setVisibility(View.GONE);
- view.findViewById(R.id.full_res_image).setVisibility(View.GONE);
- mLoadingProgressBar.hide();
- mContainer = view.findViewById(R.id.container);
- mTouchForwardingLayout = mContainer.findViewById(R.id.touch_forwarding_layout);
+ // TODO: Consider moving some part of this to the base class when live preview is ready.
+ view.findViewById(R.id.low_res_image).setVisibility(View.GONE);
+ view.findViewById(R.id.full_res_image).setVisibility(View.GONE);
+ mLoadingProgressBar.hide();
+ mContainer = view.findViewById(R.id.container);
+ mTouchForwardingLayout = mContainer.findViewById(R.id.touch_forwarding_layout);
- // Set aspect ratio on the preview card dynamically.
- ConstraintSet set = new ConstraintSet();
- set.clone(mContainer);
- String ratio = String.format("%d:%d", mScreenSize.x, mScreenSize.y);
- set.setDimensionRatio(mTouchForwardingLayout.getId(), ratio);
- set.applyTo(mContainer);
+ // Set aspect ratio on the preview card dynamically.
+ ConstraintSet set = new ConstraintSet();
+ set.clone(mContainer);
+ String ratio = String.format("%d:%d", mScreenSize.x, mScreenSize.y);
+ set.setDimensionRatio(mTouchForwardingLayout.getId(), ratio);
+ set.applyTo(mContainer);
- mWorkspaceSurface = mContainer.findViewById(R.id.workspace_surface);
- mWorkspaceSurfaceCallback = new WorkspaceSurfaceHolderCallback(mWorkspaceSurface,
- getContext());
- mWallpaperSurface = mContainer.findViewById(R.id.wallpaper_surface);
- mLockOverlay = mContainer.findViewById(R.id.lock_overlay);
- mLockScreenOverlayUpdater = new LockScreenOverlayUpdater(
- getContext(), mLockOverlay, getLifecycle());
- mLockScreenOverlayUpdater.adjustOverlayLayout(true);
+ mWorkspaceSurface = mContainer.findViewById(R.id.workspace_surface);
+ mWorkspaceSurfaceCallback = new WorkspaceSurfaceHolderCallback(mWorkspaceSurface,
+ getContext());
+ mWallpaperSurface = mContainer.findViewById(R.id.wallpaper_surface);
+ mLockOverlay = mContainer.findViewById(R.id.lock_overlay);
+ mLockScreenOverlayUpdater = new LockScreenOverlayUpdater(
+ getContext(), mLockOverlay, getLifecycle());
+ mLockScreenOverlayUpdater.adjustOverlayLayout(true);
- mTabs = view.findViewById(R.id.tabs_container);
- View lock = mTabs.findViewById(R.id.lock);
- View home = mTabs.findViewById(R.id.home);
- lock.setOnClickListener(v -> showLockscreenPreview());
- home.setOnClickListener(v -> showHomescreenPreview());
+ mTabs = view.findViewById(R.id.tabs_container);
+ View lock = mTabs.findViewById(R.id.lock);
+ View home = mTabs.findViewById(R.id.home);
+ lock.setOnClickListener(v -> showLockscreenPreview());
+ home.setOnClickListener(v -> showHomescreenPreview());
- onBottomActionBarReady(mBottomActionBar);
- view.measure(makeMeasureSpec(mScreenSize.x, EXACTLY),
- makeMeasureSpec(mScreenSize.y, EXACTLY));
+ onBottomActionBarReady(mBottomActionBar);
+ view.measure(makeMeasureSpec(mScreenSize.x, EXACTLY),
+ makeMeasureSpec(mScreenSize.y, EXACTLY));
- ((CardView) mWorkspaceSurface.getParent())
- .setRadius(SizeCalculator.getPreviewCornerRadius(
- activity, mContainer.getMeasuredWidth()));
- renderImageWallpaper();
- renderWorkspaceSurface();
- } else {
- mFullResImageView = view.findViewById(R.id.full_res_image);
- mLowResImageView = view.findViewById(R.id.low_res_image);
- }
+ ((CardView) mWorkspaceSurface.getParent())
+ .setRadius(SizeCalculator.getPreviewCornerRadius(
+ activity, mContainer.getMeasuredWidth()));
+ renderImageWallpaper();
+ renderWorkspaceSurface();
mInfoPageController = new InfoPageController(view.findViewById(R.id.page_info),
mPreviewMode);
@@ -183,16 +178,10 @@
// Load a low-res placeholder image if there's a thumbnail available from the asset that can
// be shown to the user more quickly than the full-sized image.
if (mWallpaperAsset.hasLowResDataSource()) {
- if (!USE_NEW_UI) {
- mWallpaperAsset.loadLowResDrawable(activity, mLowResImageView, Color.BLACK,
- new WallpaperPreviewBitmapTransformation(
- activity.getApplicationContext(), isRtl()));
- } else {
- mHandler.post(() ->
- mWallpaperAsset.loadLowResDrawable(activity, mLowResImageView, Color.BLACK,
- new WallpaperPreviewBitmapTransformation(
- activity.getApplicationContext(), isRtl())));
- }
+ mHandler.post(() ->
+ mWallpaperAsset.loadLowResDrawable(activity, mLowResImageView, Color.BLACK,
+ new WallpaperPreviewBitmapTransformation(
+ activity.getApplicationContext(), isRtl())));
}
mWallpaperAsset.decodeRawDimensions(getActivity(), dimensions -> {
@@ -209,11 +198,7 @@
mRawWallpaperSize = dimensions;
- if (USE_NEW_UI) {
- setUpExploreIntentAndLabel(ImagePreviewFragment.this::initFullResView);
- } else {
- setUpExploreIntent(ImagePreviewFragment.this::initFullResView);
- }
+ setUpExploreIntentAndLabel(ImagePreviewFragment.this::initFullResView);
});
setUpLoadingIndicator();
@@ -224,19 +209,13 @@
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- if (USE_NEW_UI) {
- WallpaperColorsLoader.getWallpaperColors(
- getContext(),
- mWallpaperAsset,
- mWallpaperSurface.getMeasuredWidth(),
- mWallpaperSurface.getMeasuredHeight(),
- mLockScreenOverlayUpdater::setColor);
- }
- }
- @Override
- protected void setUpBottomSheetView(ViewGroup bottomSheet) {
- // Nothing needed here.
+ WallpaperColorsLoader.getWallpaperColors(
+ getContext(),
+ mWallpaperAsset,
+ mWallpaperSurface.getMeasuredWidth(),
+ mWallpaperSurface.getMeasuredHeight(),
+ mLockScreenOverlayUpdater::setColor);
}
@Override
@@ -259,9 +238,8 @@
mLoadingProgressBar.hide();
}
mFullResImageView.recycle();
- if (USE_NEW_UI) {
- mWorkspaceSurfaceCallback.cleanUp();
- }
+
+ mWorkspaceSurfaceCallback.cleanUp();
}
@Override
@@ -274,27 +252,25 @@
@Override
protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
- if (USE_NEW_UI) {
- super.onBottomActionBarReady(bottomActionBar);
+ super.onBottomActionBarReady(bottomActionBar);
- mWallpaperInfoView = (WallpaperInfoView)
- LayoutInflater.from(getContext()).inflate(
- R.layout.wallpaper_info_view, /* root= */null);
- mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION);
- mBottomActionBar.showActionsOnly(INFORMATION, EDIT, APPLY);
- mBottomActionBar.bindBackButtonToSystemBackKey(getActivity());
- mBottomActionBar.setActionClickListener(EDIT, v ->
+ mWallpaperInfoView = (WallpaperInfoView)
+ LayoutInflater.from(getContext()).inflate(
+ 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))
- );
- mBottomActionBar.setActionSelectedListener(EDIT,
- selected -> {
- if (!selected) {
- setEditingEnabled(false);
- }
- });
- mBottomActionBar.setActionClickListener(APPLY, v -> onSetWallpaperClicked(v));
- mBottomActionBar.show();
- }
+ );
+ mBottomActionBar.setActionSelectedListener(EDIT,
+ selected -> {
+ if (!selected) {
+ setEditingEnabled(false);
+ }
+ });
+ mBottomActionBar.setActionClickListener(APPLY, v -> onSetWallpaperClicked(v));
+ mBottomActionBar.show();
}
@Override
@@ -312,14 +288,13 @@
* initializing a zoom-scroll observer and click listener.
*/
private void initFullResView() {
- setEditingEnabled(!USE_NEW_UI);
+ setEditingEnabled(false);
mFullResImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
// Set a solid black "page bitmap" so MosaicView draws a black background while waiting
// for the image to load or a transparent one if a thumbnail already loaded.
Bitmap backgroundBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
- int preColor = USE_NEW_UI ? ContextCompat.getColor(getContext(),
- R.color.fullscreen_preview_background) : Color.BLACK;
+ int preColor = ContextCompat.getColor(getContext(), R.color.fullscreen_preview_background);
int color = (mLowResImageView.getDrawable() == null) ? preColor : Color.TRANSPARENT;
backgroundBitmap.setPixel(0, 0, color);
mFullResImageView.setImage(ImageSource.bitmap(backgroundBitmap));
@@ -354,13 +329,9 @@
}
getActivity().invalidateOptionsMenu();
- if (USE_NEW_UI) {
- if (mWallpaperInfoView != null && mWallpaper != null) {
- mWallpaperInfoView.populateWallpaperInfo(mWallpaper, mActionLabel,
- mExploreIntent, this::onExploreClicked);
- }
- } else {
- populateInfoPage(mInfoPageController);
+ if (mWallpaperInfoView != null && mWallpaper != null) {
+ mWallpaperInfoView.populateWallpaperInfo(mWallpaper, mActionLabel,
+ mExploreIntent, this::onExploreClicked);
}
});
}
@@ -411,37 +382,23 @@
* and rendered to the layout.
*/
private void setDefaultWallpaperZoomAndScroll() {
- final float defaultWallpaperZoom;
- final float minWallpaperZoom;
- final PointF centerPosition;
+ // Determine minimum zoom to fit maximum visible area of wallpaper on crop surface.
+ int cropWidth = mWorkspaceSurface.getMeasuredWidth();
+ int cropHeight = mWorkspaceSurface.getMeasuredHeight();
+ Point crop = new Point(cropWidth, cropHeight);
+ Rect visibleRawWallpaperRect =
+ WallpaperCropUtils.calculateVisibleRect(mRawWallpaperSize, crop);
+ WallpaperCropUtils.adjustCurrentWallpaperCropRect(getContext(), mRawWallpaperSize,
+ visibleRawWallpaperRect);
+ Point visibleRawWallpaperSize = new Point(visibleRawWallpaperRect.width(),
+ visibleRawWallpaperRect.height());
- if (USE_NEW_UI) {
- // Determine minimum zoom to fit maximum visible area of wallpaper on crop surface.
- int cropWidth = mWorkspaceSurface.getMeasuredWidth();
- int cropHeight = mWorkspaceSurface.getMeasuredHeight();
- Point crop = new Point(cropWidth, cropHeight);
- Rect visibleRawWallpaperRect =
- WallpaperCropUtils.calculateVisibleRect(mRawWallpaperSize, crop);
- WallpaperCropUtils.adjustCurrentWallpaperCropRect(getContext(), mRawWallpaperSize,
- visibleRawWallpaperRect);
- Point visibleRawWallpaperSize = new Point(visibleRawWallpaperRect.width(),
- visibleRawWallpaperRect.height());
+ final float defaultWallpaperZoom = WallpaperCropUtils.calculateMinZoom(
+ visibleRawWallpaperSize, crop);
+ final float minWallpaperZoom = defaultWallpaperZoom;
- defaultWallpaperZoom = WallpaperCropUtils.calculateMinZoom(
- visibleRawWallpaperSize, crop);
- minWallpaperZoom = defaultWallpaperZoom;
-
- centerPosition = new PointF(visibleRawWallpaperRect.centerX(),
- visibleRawWallpaperRect.centerY());
- } else {
- // Determine minimum zoom to fit maximum visible area of wallpaper on crop surface.
- defaultWallpaperZoom = WallpaperCropUtils.calculateMinZoom(
- mRawWallpaperSize, mDefaultCropSurfaceSize);
- minWallpaperZoom =
- WallpaperCropUtils.calculateMinZoom(mRawWallpaperSize, mScreenSize);
-
- centerPosition = new PointF(mRawWallpaperSize.x / 2f, mRawWallpaperSize.y / 2f);
- }
+ final PointF centerPosition = new PointF(visibleRawWallpaperRect.centerX(),
+ visibleRawWallpaperRect.centerY());
// Set min wallpaper zoom and max zoom on MosaicView widget.
mFullResImageView.setMaxScale(Math.max(DEFAULT_WALLPAPER_MAX_ZOOM, defaultWallpaperZoom));
@@ -459,17 +416,13 @@
Rect visibleFileRect = new Rect();
mFullResImageView.visibleFileRect(visibleFileRect);
- if (USE_NEW_UI) {
- int cropWidth = mWorkspaceSurface.getMeasuredWidth();
- int cropHeight = mWorkspaceSurface.getMeasuredHeight();
- Point hostViewSize = new Point(cropWidth, cropHeight);
- Rect cropRect = WallpaperCropUtils.calculateCropRect(context, hostViewSize,
- hostViewSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom);
- WallpaperCropUtils.adjustCropRect(context, cropRect, false /* zoomIn */);
- return cropRect;
- }
- return WallpaperCropUtils.calculateCropRect(context, defaultDisplay, mRawWallpaperSize,
- visibleFileRect, wallpaperZoom);
+ int cropWidth = mWorkspaceSurface.getMeasuredWidth();
+ int cropHeight = mWorkspaceSurface.getMeasuredHeight();
+ Point hostViewSize = new Point(cropWidth, cropHeight);
+ Rect cropRect = WallpaperCropUtils.calculateCropRect(context, hostViewSize,
+ hostViewSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom);
+ WallpaperCropUtils.adjustCropRect(context, cropRect, false /* zoomIn */);
+ return cropRect;
}
@Override
@@ -537,19 +490,15 @@
};
private void setEditingEnabled(boolean enabled) {
- if (USE_NEW_UI) {
- mTouchForwardingLayout.setForwardingEnabled(enabled);
- }
+ mTouchForwardingLayout.setForwardingEnabled(enabled);
}
private void showHomescreenPreview() {
- // TODO (b/156129610): Update the behavior here.
mWorkspaceSurface.setVisibility(View.VISIBLE);
mLockOverlay.setVisibility(View.GONE);
}
private void showLockscreenPreview() {
- // TODO (b/156129610): Update the behavior here.
mWorkspaceSurface.setVisibility(View.GONE);
mLockOverlay.setVisibility(View.VISIBLE);
}
diff --git a/src/com/android/wallpaper/picker/LivePreviewFragment.java b/src/com/android/wallpaper/picker/LivePreviewFragment.java
index d4268da..0f5309c 100644
--- a/src/com/android/wallpaper/picker/LivePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/LivePreviewFragment.java
@@ -48,9 +48,6 @@
import android.util.Pair;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
@@ -59,14 +56,12 @@
import android.widget.ImageView;
import android.widget.TextView;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.lifecycle.LiveData;
import androidx.slice.Slice;
import androidx.slice.widget.SliceLiveData;
import androidx.slice.widget.SliceView;
-import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.android.wallpaper.R;
@@ -139,11 +134,7 @@
super.onCreate(savedInstanceState);
android.app.WallpaperInfo info = mWallpaper.getWallpaperComponent();
mWallpaperIntent = getWallpaperIntent(info);
- if (USE_NEW_UI) {
- setUpExploreIntentAndLabel(null);
- } else {
- setUpExploreIntent(null);
- }
+ setUpExploreIntentAndLabel(null);
String deleteAction = getDeleteAction(info);
if (!TextUtils.isEmpty(deleteAction)) {
@@ -193,48 +184,39 @@
mScreenSize = ScreenSizeCalculator.getInstance().getScreenSize(
activity.getWindowManager().getDefaultDisplay());
- if (USE_NEW_UI) {
- mViewGroup = view.findViewById(R.id.live_wallpaper_preview);
- mHomePreviewCard = mViewGroup.findViewById(R.id.wallpaper_full_preview_card);
- mTouchForwardingLayout = view.findViewById(R.id.touch_forwarding_layout);
- mHomePreview = mHomePreviewCard.findViewById(R.id.wallpaper_preview_image);
- mTouchForwardingLayout.setTargetView(mHomePreview);
- mTouchForwardingLayout.setForwardingEnabled(true);
- mLockScreenOverlay = mViewGroup.findViewById(R.id.lock_overlay);
- mLockScreenOverlayUpdater =
- new LockScreenOverlayUpdater(getContext(), mLockScreenOverlay, getLifecycle());
- mLockScreenOverlayUpdater.adjustOverlayLayout(/* isFullScreen= */ true);
- mTab = view.findViewById(R.id.tabs_container);
- mHomeTextView = mTab.findViewById(R.id.home);
- mHomeTextView.setTextColor(
- getResources().getColorStateList(R.color.bottom_action_button_color_tint,
- getContext().getTheme()));
- mLockTextView = mTab.findViewById(R.id.lock);
- mLockTextView.setTextColor(
- getResources().getColorStateList(R.color.bottom_action_button_color_tint,
- getContext().getTheme()));
- mWorkspaceSurface = mHomePreviewCard.findViewById(R.id.workspace_surface);
- mWorkspaceSurfaceCallback = new WorkspaceSurfaceHolderCallback(
- mWorkspaceSurface, getContext());
- updateScreenTab(/* isHomeSelected= */ true);
- view.addOnLayoutChangeListener((thisView, left, top, right, bottom,
- oldLeft, oldTop, oldRight, oldBottom) ->
- setupPreview()
- );
- setupCurrentWallpaperPreview(view);
- previewLiveWallpaper(container, mHomePreview);
- setupPreview();
- renderWorkspaceSurface();
- onBottomActionBarReady(mBottomActionBar);
- } else {
- mWallpaperConnection = new WallpaperConnection(mWallpaperIntent, activity,
- this, null);
- container.post(() -> {
- if (!mWallpaperConnection.connect()) {
- mWallpaperConnection = null;
- }
- });
- }
+
+ mViewGroup = view.findViewById(R.id.live_wallpaper_preview);
+ mHomePreviewCard = mViewGroup.findViewById(R.id.wallpaper_full_preview_card);
+ mTouchForwardingLayout = view.findViewById(R.id.touch_forwarding_layout);
+ mHomePreview = mHomePreviewCard.findViewById(R.id.wallpaper_preview_image);
+ mTouchForwardingLayout.setTargetView(mHomePreview);
+ mTouchForwardingLayout.setForwardingEnabled(true);
+ mLockScreenOverlay = mViewGroup.findViewById(R.id.lock_overlay);
+ mLockScreenOverlayUpdater =
+ new LockScreenOverlayUpdater(getContext(), mLockScreenOverlay, getLifecycle());
+ mLockScreenOverlayUpdater.adjustOverlayLayout(/* isFullScreen= */ true);
+ mTab = view.findViewById(R.id.tabs_container);
+ mHomeTextView = mTab.findViewById(R.id.home);
+ mHomeTextView.setTextColor(
+ getResources().getColorStateList(R.color.bottom_action_button_color_tint,
+ getContext().getTheme()));
+ mLockTextView = mTab.findViewById(R.id.lock);
+ mLockTextView.setTextColor(
+ getResources().getColorStateList(R.color.bottom_action_button_color_tint,
+ getContext().getTheme()));
+ mWorkspaceSurface = mHomePreviewCard.findViewById(R.id.workspace_surface);
+ mWorkspaceSurfaceCallback = new WorkspaceSurfaceHolderCallback(
+ mWorkspaceSurface, getContext());
+ updateScreenTab(/* isHomeSelected= */ true);
+ view.addOnLayoutChangeListener((thisView, left, top, right, bottom,
+ oldLeft, oldTop, oldRight, oldBottom) ->
+ setupPreview()
+ );
+ setupCurrentWallpaperPreview(view);
+ previewLiveWallpaper(container, mHomePreview);
+ setupPreview();
+ renderWorkspaceSurface();
+ onBottomActionBarReady(mBottomActionBar);
return view;
}
@@ -247,30 +229,28 @@
}
private void setupPreview() {
- if (USE_NEW_UI) {
- float screenAspectRatio = (float) mScreenSize.y / mScreenSize.x;
- int measuredViewHeight = mViewGroup.getMeasuredHeight();
- int measuredViewWidth = mViewGroup.getMeasuredWidth();
- int absoluteViewWidth = (int) ((measuredViewHeight - mViewGroup.getPaddingBottom()
- - mViewGroup.getPaddingTop()) / screenAspectRatio);
- int horizontalPadding = (measuredViewWidth - absoluteViewWidth) / 2;
- mViewGroup.setPaddingRelative(
- horizontalPadding,
- mViewGroup.getPaddingTop(),
- horizontalPadding,
- mViewGroup.getPaddingBottom());
- mHomeTextView.setOnClickListener(view ->
- updateScreenTab(/* isHomeSelected= */ true)
- );
- mLockTextView.setOnClickListener(view ->
- updateScreenTab(/* isHomeSelected= */ false)
- );
- repositionPreview(mHomePreview);
+ float screenAspectRatio = (float) mScreenSize.y / mScreenSize.x;
+ int measuredViewHeight = mViewGroup.getMeasuredHeight();
+ int measuredViewWidth = mViewGroup.getMeasuredWidth();
+ int absoluteViewWidth = (int) ((measuredViewHeight - mViewGroup.getPaddingBottom()
+ - mViewGroup.getPaddingTop()) / screenAspectRatio);
+ int horizontalPadding = (measuredViewWidth - absoluteViewWidth) / 2;
+ mViewGroup.setPaddingRelative(
+ horizontalPadding,
+ mViewGroup.getPaddingTop(),
+ horizontalPadding,
+ mViewGroup.getPaddingBottom());
+ mHomeTextView.setOnClickListener(view ->
+ updateScreenTab(/* isHomeSelected= */ true)
+ );
+ mLockTextView.setOnClickListener(view ->
+ updateScreenTab(/* isHomeSelected= */ false)
+ );
+ repositionPreview(mHomePreview);
- ((CardView) mHomePreview.getParent())
- .setRadius(SizeCalculator.getPreviewCornerRadius(
- getActivity(), mHomePreviewCard.getMeasuredWidth()));
- }
+ ((CardView) mHomePreview.getParent())
+ .setRadius(SizeCalculator.getPreviewCornerRadius(
+ getActivity(), mHomePreviewCard.getMeasuredWidth()));
}
private void repositionPreview(ImageView previewView) {
@@ -331,81 +311,12 @@
mWallpaperConnection.disconnect();
}
mWallpaperConnection = null;
- if (USE_NEW_UI) {
- mWorkspaceSurfaceCallback.cleanUp();
- }
+
+ mWorkspaceSurfaceCallback.cleanUp();
+
super.onDestroy();
}
- @Override
- protected void setUpBottomSheetView(ViewGroup bottomSheet) {
- if (USE_NEW_UI) {
- return;
- }
-
- initInfoPage();
- initSettingsPage();
-
- mViewPager = bottomSheet.findViewById(R.id.viewpager);
- mTabLayout = bottomSheet.findViewById(R.id.tablayout);
-
- // Create PagerAdapter
- final PagerAdapter pagerAdapter = new PagerAdapter() {
- @Override
- public Object instantiateItem(ViewGroup container, int position) {
- final View page = mPages.get(position).second;
- container.addView(page);
- return page;
- }
-
- @Override
- public void destroyItem(@NonNull ViewGroup container, int position,
- @NonNull Object object) {
- if (object instanceof View) {
- container.removeView((View) object);
- }
- }
-
- @Override
- public int getCount() {
- return mPages.size();
- }
-
- @Override
- public CharSequence getPageTitle(int position) {
- try {
- return mPages.get(position).first;
- } catch (IndexOutOfBoundsException e) {
- return null;
- }
- }
-
- @Override
- public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
- return (view == object);
- }
- };
-
- // Add OnPageChangeListener to re-measure ViewPager's height
- mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
- @Override
- public void onPageSelected(int position) {
- mViewPager.requestLayout();
- logLiveWallpaperPageSelected(position);
- }
- });
-
- // Set PagerAdapter
- mViewPager.setAdapter(pagerAdapter);
-
- // Make TabLayout visible if there are more than one page
- if (mPages.size() > 1) {
- mTabLayout.setVisibility(View.VISIBLE);
- mTabLayout.setupWithViewPager(mViewPager);
- }
- mViewPager.setCurrentItem(0);
- }
-
private void previewLiveWallpaper(ViewGroup container, ImageView thumbnailView) {
container.post(() -> {
mWallpaper.getThumbAsset(requireActivity().getApplicationContext()).loadPreviewImage(
@@ -495,43 +406,41 @@
}
protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
- if (USE_NEW_UI) {
- super.onBottomActionBarReady(bottomActionBar);
- mBottomActionBar.showActionsOnly(INFORMATION, DELETE, CUSTOMIZE, APPLY);
- mBottomActionBar.bindBackButtonToSystemBackKey(getActivity());
- mBottomActionBar.setActionClickListener(APPLY, unused ->
- this.onSetWallpaperClicked(null));
- mWallpaperInfoView = (WallpaperInfoView) LayoutInflater.from(getContext())
- .inflate(R.layout.wallpaper_info_view, /* root= */ null);
- mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION);
- final Uri uriSettingsSlice = getSettingsSliceUri(mWallpaper.getWallpaperComponent());
- if (uriSettingsSlice != null) {
- View previewPage = LayoutInflater.from(getContext())
- .inflate(R.layout.preview_customize_settings, null);
- mSettingsSliceView = previewPage.findViewById(R.id.settings_slice);
- mSettingsSliceView.setMode(SliceView.MODE_LARGE);
- mSettingsSliceView.setScrollable(false);
- mSettingsLiveData = SliceLiveData.fromUri(requireContext(), uriSettingsSlice);
- mSettingsLiveData.observeForever(mSettingsSliceView);
- mBottomActionBar.attachViewToBottomSheetAndBindAction(previewPage, CUSTOMIZE);
+ super.onBottomActionBarReady(bottomActionBar);
+ mBottomActionBar.showActionsOnly(INFORMATION, DELETE, CUSTOMIZE, APPLY);
+ mBottomActionBar.bindBackButtonToSystemBackKey(getActivity());
+ mBottomActionBar.setActionClickListener(APPLY, unused ->
+ this.onSetWallpaperClicked(null));
+ mWallpaperInfoView = (WallpaperInfoView) LayoutInflater.from(getContext())
+ .inflate(R.layout.wallpaper_info_view, /* root= */ null);
+ mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION);
+ final Uri uriSettingsSlice = getSettingsSliceUri(mWallpaper.getWallpaperComponent());
+ if (uriSettingsSlice != null) {
+ View previewPage = LayoutInflater.from(getContext())
+ .inflate(R.layout.preview_customize_settings, null);
+ mSettingsSliceView = previewPage.findViewById(R.id.settings_slice);
+ mSettingsSliceView.setMode(SliceView.MODE_LARGE);
+ mSettingsSliceView.setScrollable(false);
+ mSettingsLiveData = SliceLiveData.fromUri(requireContext(), uriSettingsSlice);
+ mSettingsLiveData.observeForever(mSettingsSliceView);
+ mBottomActionBar.attachViewToBottomSheetAndBindAction(previewPage, CUSTOMIZE);
+ } else {
+ if (mSettingsIntent != null) {
+ mBottomActionBar.setActionClickListener(CUSTOMIZE, listener ->
+ startActivity(mSettingsIntent));
} else {
- if (mSettingsIntent != null) {
- mBottomActionBar.setActionClickListener(CUSTOMIZE, listener ->
- startActivity(mSettingsIntent));
- } else {
- mBottomActionBar.hideActions(CUSTOMIZE);
- }
+ mBottomActionBar.hideActions(CUSTOMIZE);
}
-
- final String deleteAction = getDeleteAction(mWallpaper.getWallpaperComponent());
- if (TextUtils.isEmpty(deleteAction)) {
- mBottomActionBar.hideActions(DELETE);
- } else {
- mBottomActionBar.setActionClickListener(DELETE, listener ->
- showDeleteConfirmDialog());
- }
- mBottomActionBar.show();
}
+
+ final String deleteAction = getDeleteAction(mWallpaper.getWallpaperComponent());
+ if (TextUtils.isEmpty(deleteAction)) {
+ mBottomActionBar.hideActions(DELETE);
+ } else {
+ mBottomActionBar.setActionClickListener(DELETE, listener ->
+ showDeleteConfirmDialog());
+ }
+ mBottomActionBar.show();
}
private void logLiveWallpaperPageSelected(int position) {
@@ -617,7 +526,7 @@
@Override
protected int getLayoutResId() {
- return USE_NEW_UI ? R.layout.fragment_live_preview_v2 : R.layout.fragment_live_preview;
+ return R.layout.fragment_live_preview_v2;
}
@Override
@@ -691,34 +600,6 @@
}
}
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- if (USE_NEW_UI) {
- return;
- }
- menu.findItem(R.id.configure).setVisible(mSettingsIntent != null);
- menu.findItem(R.id.delete_wallpaper).setVisible(mDeleteIntent != null);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (USE_NEW_UI) {
- return false;
- }
- int id = item.getItemId();
- if (id == R.id.configure) {
- if (getActivity() != null) {
- startActivity(mSettingsIntent);
- return true;
- }
- } else if (id == R.id.delete_wallpaper) {
- showDeleteConfirmDialog();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
private void showDeleteConfirmDialog() {
final AlertDialog alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(getContext(), getDeviceDefaultTheme()))
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index 243c6cd..e03243d 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -26,19 +26,14 @@
import android.content.res.ColorStateList;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
-import android.graphics.Insets;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
-import android.view.WindowInsets;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
@@ -51,7 +46,6 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
-import androidx.core.view.ViewCompat;
import androidx.core.widget.ContentLoadingProgressBar;
import androidx.fragment.app.FragmentActivity;
@@ -106,8 +100,6 @@
public static final String ARG_PREVIEW_MODE = "preview_mode";
public static final String ARG_TESTING_MODE_ENABLED = "testing_mode_enabled";
- protected static final boolean USE_NEW_UI = ViewOnlyPreviewActivity.USE_NEW_UI;
-
/**
* Creates and returns new instance of {@link ImagePreviewFragment} with the provided wallpaper
* set as an argument.
@@ -208,12 +200,11 @@
// Set toolbar as the action bar.
Toolbar toolbar = view.findViewById(R.id.toolbar);
- if (USE_NEW_UI) {
- TextView titleTextView = toolbar.findViewById(R.id.custom_toolbar_title);
- if (titleTextView != null) {
- titleTextView.setText(R.string.preview);
- }
+ TextView titleTextView = toolbar.findViewById(R.id.custom_toolbar_title);
+ if (titleTextView != null) {
+ titleTextView.setText(R.string.preview);
}
+
AppCompatActivity activity = (AppCompatActivity) requireActivity();
activity.setSupportActionBar(toolbar);
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -221,25 +212,12 @@
toolbar.getNavigationIcon().setTint(getAttrColor(activity, android.R.attr.colorPrimary));
toolbar.getNavigationIcon().setAutoMirrored(true);
- if (!USE_NEW_UI) {
- ViewCompat.setPaddingRelative(toolbar,
- /* start */ getResources().getDimensionPixelSize(
- R.dimen.preview_toolbar_up_button_start_padding),
- /* top */ 0,
- /* end */ getResources().getDimensionPixelSize(
- R.dimen.preview_toolbar_set_wallpaper_button_end_padding),
- /* bottom */ 0);
- }
-
mLoadingProgressBar = view.findViewById(getLoadingIndicatorResId());
mLoadingProgressBar.show();
- if (USE_NEW_UI) {
- mBottomActionBar = view.findViewById(R.id.bottom_actionbar);
- }
+ mBottomActionBar = view.findViewById(R.id.bottom_actionbar);
mBottomSheet = view.findViewById(getBottomSheetResId());
- setUpBottomSheetView(mBottomSheet);
SizeCalculator.adjustBackgroundCornerRadius(mBottomSheet);
@@ -247,22 +225,6 @@
: savedInstanceState.getInt(KEY_BOTTOM_SHEET_STATE, STATE_EXPANDED);
setUpBottomSheetListeners();
- if (!USE_NEW_UI) {
- view.setOnApplyWindowInsetsListener((v, windowInsets) -> {
- toolbar.setPadding(toolbar.getPaddingLeft(),
- toolbar.getPaddingTop() + windowInsets.getSystemWindowInsetTop(),
- toolbar.getPaddingRight(), toolbar.getPaddingBottom());
- mBottomSheet.setPadding(mBottomSheet.getPaddingLeft(),
- mBottomSheet.getPaddingTop(), mBottomSheet.getPaddingRight(),
- mBottomSheet.getPaddingBottom()
- + windowInsets.getSystemWindowInsetBottom());
- WindowInsets.Builder builder = new WindowInsets.Builder(windowInsets);
- builder.setSystemWindowInsets(Insets.of(windowInsets.getSystemWindowInsetLeft(),
- 0, windowInsets.getStableInsetRight(), 0));
- return builder.build();
- });
- }
-
return view;
}
@@ -312,8 +274,6 @@
@LayoutRes
protected abstract int getLayoutResId();
- protected abstract void setUpBottomSheetView(ViewGroup bottomSheet);
-
@IdRes
protected abstract int getBottomSheetResId();
@@ -347,48 +307,6 @@
}
}
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- if (USE_NEW_UI) {
- return;
- }
- inflater.inflate(R.menu.preview_menu, menu);
- }
-
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- super.onPrepareOptionsMenu(menu);
- if (USE_NEW_UI) {
- return;
- }
- setupPreviewMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (USE_NEW_UI) {
- return false;
- }
- int id = item.getItemId();
- if (id == android.R.id.home) {
- // The Preview screen has multiple entry points. It could be opened from either
- // the IndividualPreviewActivity, the "My photos" selection (by way of
- // TopLevelPickerActivity), or from a system "crop and set wallpaper" intent.
- // Therefore, handle the Up button as a global Back.
- requireActivity().onBackPressed();
- return true;
- }
-
- return false;
- }
-
- private void setupPreviewMenu(Menu menu) {
- mPreview = (CheckBox) menu.findItem(R.id.preview).getActionView();
- mPreview.setChecked(mBottomSheetInitialState == STATE_COLLAPSED);
- mPreview.setOnClickListener(this::setPreviewBehavior);
- }
-
protected void setPreviewChecked(boolean checked) {
if (mPreview != null) {
mPreview.setChecked(checked);
@@ -398,17 +316,6 @@
}
}
- private void setPreviewBehavior(View v) {
- CheckBox checkbox = (CheckBox) v;
- BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(mBottomSheet);
-
- if (checkbox.isChecked()) {
- behavior.setState(STATE_COLLAPSED);
- } else {
- behavior.setState(STATE_EXPANDED);
- }
- }
-
protected void setUpExploreIntentAndLabel(@Nullable Runnable callback) {
Context context = getContext();
if (context == null) {
@@ -473,9 +380,7 @@
@Override
public void onDialogDismissed(boolean withItemSelected) {
- if (USE_NEW_UI) {
- mBottomActionBar.setActionSelected(APPLY, false /* selected */);
- }
+ mBottomActionBar.setActionSelected(APPLY, false /* selected */);
}
@Override
diff --git a/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java b/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
index 2846f5d..b4c4f5f 100755
--- a/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
+++ b/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
@@ -33,7 +33,6 @@
*/
public class ViewOnlyPreviewActivity extends BasePreviewActivity {
- public static boolean USE_NEW_UI = true;
/**
* Returns a new Intent with the provided WallpaperInfo instance put as an extra.
*/
@@ -45,10 +44,8 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (USE_NEW_UI) {
- setTheme(R.style.WallpaperTheme);
- getWindow().setFormat(PixelFormat.TRANSLUCENT);
- }
+ setTheme(R.style.WallpaperTheme);
+ getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.activity_preview);
}