Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Snippets Groups Projects
Commit f7afbf6b authored by chihhangchuang's avatar chihhangchuang Committed by Automerger Merge Worker
Browse files

Cleanup WallpaperPreviewer am: c33c041b

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ThemePicker/+/11984358

Change-Id: Ie91b9fcfa428e1f27919f16207b6669e7d1f8469
parents 67875c4e c33c041b
Branches
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ import android.view.Surface; ...@@ -28,6 +28,7 @@ import android.view.Surface;
import android.view.SurfaceControlViewHost; import android.view.SurfaceControlViewHost;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -84,6 +85,16 @@ public class WallpaperPreviewer implements LifecycleObserver { ...@@ -84,6 +85,16 @@ public class WallpaperPreviewer implements LifecycleObserver {
mWallpaperSurface = wallpaperSurface; mWallpaperSurface = wallpaperSurface;
mWallpaperSurface.setZOrderMediaOverlay(false); mWallpaperSurface.setZOrderMediaOverlay(false);
mWallpaperSurface.getHolder().addCallback(mWallpaperSurfaceCallback); 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) @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
...@@ -128,18 +139,6 @@ public class WallpaperPreviewer implements LifecycleObserver { ...@@ -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. * Sets a wallpaper to be shown on preview screen.
* *
...@@ -148,7 +147,7 @@ public class WallpaperPreviewer implements LifecycleObserver { ...@@ -148,7 +147,7 @@ public class WallpaperPreviewer implements LifecycleObserver {
*/ */
public void setWallpaper(WallpaperInfo wallpaperInfo, public void setWallpaper(WallpaperInfo wallpaperInfo,
@Nullable WallpaperColorsListener listener) { @Nullable WallpaperColorsListener listener) {
mWallpaper = wallpaperInfo; mWallpaper = wallpaperInfo;
mWallpaperColorsListener = listener; mWallpaperColorsListener = listener;
setUpWallpaperPreview(); setUpWallpaperPreview();
} }
...@@ -224,6 +223,23 @@ public class WallpaperPreviewer implements LifecycleObserver { ...@@ -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 class WallpaperSurfaceCallback implements SurfaceHolder.Callback {
private Surface mLastSurface; private Surface mLastSurface;
...@@ -262,10 +278,5 @@ public class WallpaperPreviewer implements LifecycleObserver { ...@@ -262,10 +278,5 @@ public class WallpaperPreviewer implements LifecycleObserver {
mHost = null; mHost = null;
} }
} }
};
private static Intent getWallpaperIntent(android.app.WallpaperInfo info) {
return new Intent(WallpaperService.SERVICE_INTERFACE)
.setClassName(info.getPackageName(), info.getServiceName());
} }
} }
...@@ -150,15 +150,6 @@ public class GridFragment extends AppbarFragment { ...@@ -150,15 +150,6 @@ public class GridFragment extends AppbarFragment {
mGridOptionPreviewer = new GridOptionPreviewer(mGridManager, mGridOptionPreviewer = new GridOptionPreviewer(mGridManager,
view.findViewById(R.id.grid_preview_container)); 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()); view.findViewById(R.id.grid_preview_card).setOnClickListener(v -> showFullPreview());
return view; return view;
} }
......
...@@ -104,15 +104,6 @@ public class GridFullPreviewFragment extends AppbarFragment { ...@@ -104,15 +104,6 @@ public class GridFullPreviewFragment extends AppbarFragment {
mGridOptionPreviewer = new GridOptionPreviewer(gridManager, mGridOptionPreviewer = new GridOptionPreviewer(gridManager,
view.findViewById(R.id.grid_preview_container)); 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; return view;
} }
......
...@@ -106,15 +106,6 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment { ...@@ -106,15 +106,6 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
// Set theme default name. // Set theme default name.
mNameEditor = view.findViewById(R.id.custom_theme_name); mNameEditor = view.findViewById(R.id.custom_theme_name);
mNameEditor.setText(getOriginalThemeName()); 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; return view;
} }
......
...@@ -143,15 +143,6 @@ public class ThemeFragment extends AppbarFragment { ...@@ -143,15 +143,6 @@ public class ThemeFragment extends AppbarFragment {
mThemeOptionPreviewer::updateColorForLauncherWidgets); mThemeOptionPreviewer::updateColorForLauncherWidgets);
}, false); }, 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()); view.findViewById(R.id.theme_preview_card).setOnClickListener(v -> showFullPreview());
return view; return view;
} }
......
...@@ -120,15 +120,6 @@ public class ThemeFullPreviewFragment extends AppbarFragment { ...@@ -120,15 +120,6 @@ public class ThemeFullPreviewFragment extends AppbarFragment {
view.findViewById(R.id.wallpaper_preview_surface)); view.findViewById(R.id.wallpaper_preview_surface));
wallpaperPreviewer.setWallpaper(mWallpaper, wallpaperPreviewer.setWallpaper(mWallpaper,
themeOptionPreviewer::updateColorForLauncherWidgets); 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; return view;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment