diff --git a/src/com/android/customization/picker/WallpaperPreviewer.java b/src/com/android/customization/picker/WallpaperPreviewer.java index 9e56cec1ff325c1bafc2aadbca0a3a12dac32077..ba750c940b1e2337aca38fd6c9aa57c2d65990dc 100644 --- a/src/com/android/customization/picker/WallpaperPreviewer.java +++ b/src/com/android/customization/picker/WallpaperPreviewer.java @@ -28,6 +28,7 @@ import android.view.Surface; import android.view.SurfaceControlViewHost; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -84,6 +85,16 @@ public class WallpaperPreviewer implements LifecycleObserver { mWallpaperSurface = wallpaperSurface; mWallpaperSurface.setZOrderMediaOverlay(false); mWallpaperSurface.getHolder().addCallback(mWallpaperSurfaceCallback); + + View rootView = homePreview.getRootView(); + rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom) { + updatePreviewCardRadius(); + rootView.removeOnLayoutChangeListener(this); + } + }); } @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) @@ -128,18 +139,6 @@ public class WallpaperPreviewer implements LifecycleObserver { } } - /** Updates the preview card view radius to match the device radius. */ - public void updatePreviewCardRadius() { - final float screenAspectRatio = - ScreenSizeCalculator.getInstance().getScreenAspectRatio(mActivity); - CardView cardView = (CardView) mHomePreview.getParent(); - final int cardWidth = (int) (cardView.getMeasuredHeight() / screenAspectRatio); - ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); - layoutParams.width = cardWidth; - cardView.setLayoutParams(layoutParams); - cardView.setRadius(SizeCalculator.getPreviewCornerRadius(mActivity, cardWidth)); - } - /** * Sets a wallpaper to be shown on preview screen. * @@ -148,7 +147,7 @@ public class WallpaperPreviewer implements LifecycleObserver { */ public void setWallpaper(WallpaperInfo wallpaperInfo, @Nullable WallpaperColorsListener listener) { - mWallpaper = wallpaperInfo; + mWallpaper = wallpaperInfo; mWallpaperColorsListener = listener; setUpWallpaperPreview(); } @@ -224,6 +223,23 @@ public class WallpaperPreviewer implements LifecycleObserver { }); } + /** Updates the preview card view corner radius to match the device corner radius. */ + private void updatePreviewCardRadius() { + final float screenAspectRatio = + ScreenSizeCalculator.getInstance().getScreenAspectRatio(mActivity); + CardView cardView = (CardView) mHomePreview.getParent(); + final int cardWidth = (int) (cardView.getMeasuredHeight() / screenAspectRatio); + ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); + layoutParams.width = cardWidth; + cardView.setLayoutParams(layoutParams); + cardView.setRadius(SizeCalculator.getPreviewCornerRadius(mActivity, cardWidth)); + } + + private static Intent getWallpaperIntent(android.app.WallpaperInfo info) { + return new Intent(WallpaperService.SERVICE_INTERFACE) + .setClassName(info.getPackageName(), info.getServiceName()); + } + private class WallpaperSurfaceCallback implements SurfaceHolder.Callback { private Surface mLastSurface; @@ -262,10 +278,5 @@ public class WallpaperPreviewer implements LifecycleObserver { mHost = null; } } - }; - - private static Intent getWallpaperIntent(android.app.WallpaperInfo info) { - return new Intent(WallpaperService.SERVICE_INTERFACE) - .setClassName(info.getPackageName(), info.getServiceName()); } } diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java index 98c7515416329f86a2fd63373575585650534ba4..ad37fbfae724a1528496211ab1e39b7d6ad82c4e 100644 --- a/src/com/android/customization/picker/grid/GridFragment.java +++ b/src/com/android/customization/picker/grid/GridFragment.java @@ -150,15 +150,6 @@ public class GridFragment extends AppbarFragment { mGridOptionPreviewer = new GridOptionPreviewer(mGridManager, view.findViewById(R.id.grid_preview_container)); - view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - wallpaperPreviewer.updatePreviewCardRadius(); - view.removeOnLayoutChangeListener(this); - } - }); - view.findViewById(R.id.grid_preview_card).setOnClickListener(v -> showFullPreview()); return view; } diff --git a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java index ae3370c48aaa1357dd8c7302da5f8fe887d95498..69105dfb555bd7917954b64cc67cc09e4b316abf 100644 --- a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java +++ b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java @@ -104,15 +104,6 @@ public class GridFullPreviewFragment extends AppbarFragment { mGridOptionPreviewer = new GridOptionPreviewer(gridManager, view.findViewById(R.id.grid_preview_container)); - - view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - mWallpaperPreviewer.updatePreviewCardRadius(); - view.removeOnLayoutChangeListener(this); - } - }); return view; } diff --git a/src/com/android/customization/picker/theme/CustomThemeNameFragment.java b/src/com/android/customization/picker/theme/CustomThemeNameFragment.java index 750c4055864354a22cb4d7b357564352e5931501..f36c80b0bc6a7a565803abba7760b08cf8a17d28 100644 --- a/src/com/android/customization/picker/theme/CustomThemeNameFragment.java +++ b/src/com/android/customization/picker/theme/CustomThemeNameFragment.java @@ -106,15 +106,6 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment { // Set theme default name. mNameEditor = view.findViewById(R.id.custom_theme_name); mNameEditor.setText(getOriginalThemeName()); - - view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - wallpaperPreviewer.updatePreviewCardRadius(); - view.removeOnLayoutChangeListener(this); - } - }); return view; } diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java index 4b77214cc93a40781bb254447002c9898a66eb95..de8aa69b9c62ac0a5a6df47499b9f39681b2712f 100644 --- a/src/com/android/customization/picker/theme/ThemeFragment.java +++ b/src/com/android/customization/picker/theme/ThemeFragment.java @@ -143,15 +143,6 @@ public class ThemeFragment extends AppbarFragment { mThemeOptionPreviewer::updateColorForLauncherWidgets); }, false); - view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - mWallpaperPreviewer.updatePreviewCardRadius(); - view.removeOnLayoutChangeListener(this); - } - }); - view.findViewById(R.id.theme_preview_card).setOnClickListener(v -> showFullPreview()); return view; } diff --git a/src/com/android/customization/picker/theme/ThemeFullPreviewFragment.java b/src/com/android/customization/picker/theme/ThemeFullPreviewFragment.java index c96c3acc155756b63f67a72774d243ab6f11706d..7cbeab927f92d3d6c5e7509e2a3694fa38e7b669 100644 --- a/src/com/android/customization/picker/theme/ThemeFullPreviewFragment.java +++ b/src/com/android/customization/picker/theme/ThemeFullPreviewFragment.java @@ -120,15 +120,6 @@ public class ThemeFullPreviewFragment extends AppbarFragment { view.findViewById(R.id.wallpaper_preview_surface)); wallpaperPreviewer.setWallpaper(mWallpaper, themeOptionPreviewer::updateColorForLauncherWidgets); - - view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - wallpaperPreviewer.updatePreviewCardRadius(); - view.removeOnLayoutChangeListener(this); - } - }); return view; }