diff options
17 files changed, 52 insertions, 457 deletions
diff --git a/res/layout-land/fragment_theme_picker.xml b/res/layout-land/fragment_theme_picker.xml index f2083f32..dc302325 100644 --- a/res/layout-land/fragment_theme_picker.xml +++ b/res/layout-land/fragment_theme_picker.xml @@ -55,30 +55,14 @@ android:layout_height="0dp" android:layout_weight="1"/> - <RelativeLayout - android:layout_width="match_parent" + <Button + android:id="@+id/apply_button" + style="@style/ActionPrimaryButton" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@null" - android:paddingHorizontal="10dp"> - <CheckBox - android:id="@+id/use_my_wallpaper" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentStart="true" - android:layout_centerVertical="true" - android:layout_toStartOf="@+id/apply_button" - android:ellipsize="end" - android:paddingLeft="4dp" - android:minHeight="@dimen/min_taptarget_height" - android:text="@string/keep_my_wallpaper"/> - <Button - android:id="@+id/apply_button" - style="@style/ActionPrimaryButton" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:text="@string/apply_theme_btn"/> - </RelativeLayout> + android:layout_gravity="end" + android:paddingHorizontal="10dp" + android:text="@string/apply_theme_btn"/> </LinearLayout> </LinearLayout> diff --git a/res/layout/fragment_theme_picker.xml b/res/layout/fragment_theme_picker.xml index 1de5a3c9..d15d93fd 100644 --- a/res/layout/fragment_theme_picker.xml +++ b/res/layout/fragment_theme_picker.xml @@ -53,29 +53,11 @@ android:layout_gravity="bottom|center_horizontal" android:layout_marginTop="10dp" android:layout_weight="1" - app:layout_constraintBottom_toTopOf="@id/use_my_wallpaper" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/theme_preview_pager" app:layout_constraintVertical_bias="1.0"/> - <CheckBox - android:id="@+id/use_my_wallpaper" - android:layout_width="wrap_content" - android:layout_height="@dimen/min_taptarget_height" - android:layout_marginStart="10dp" - android:ellipsize="end" - android:gravity="start|center_vertical" - android:paddingLeft="4dp" - android:text="@string/keep_my_wallpaper" - app:layout_constraintBottom_toTopOf="@id/apply_button" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHeight_min="@dimen/min_taptarget_height" - app:layout_constraintHorizontal_bias="0.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/options_container" - app:layout_constraintVertical_bias="1.0"/> - <Button android:id="@+id/apply_button" style="@style/ActionPrimaryButton" diff --git a/res/layout/fragment_theme_scalable_picker.xml b/res/layout/fragment_theme_scalable_picker.xml index e03df3e7..ae147c28 100644 --- a/res/layout/fragment_theme_scalable_picker.xml +++ b/res/layout/fragment_theme_scalable_picker.xml @@ -55,29 +55,11 @@ android:layout_gravity="bottom|center_horizontal" android:layout_marginTop="10dp" android:layout_weight="1" - app:layout_constraintBottom_toTopOf="@id/use_my_wallpaper" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" /> - <CheckBox - android:id="@+id/use_my_wallpaper" - android:layout_width="wrap_content" - android:layout_height="@dimen/min_taptarget_height" - android:layout_marginStart="10dp" - android:ellipsize="end" - android:gravity="start|center_vertical" - android:paddingLeft="4dp" - android:text="@string/keep_my_wallpaper" - app:layout_constraintBottom_toTopOf="@id/apply_button" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHeight_min="@dimen/min_taptarget_height" - app:layout_constraintHorizontal_bias="0.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/options_container" - app:layout_constraintVertical_bias="1.0" /> - <Button android:id="@+id/apply_button" style="@style/ActionPrimaryButton" diff --git a/res/layout/preview_card_wallpaper_content.xml b/res/layout/preview_card_wallpaper_content.xml deleted file mode 100644 index 0b43c2f4..00000000 --- a/res/layout/preview_card_wallpaper_content.xml +++ /dev/null @@ -1,31 +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:tools="http://schemas.android.com/tools" - android:id="@+id/preview_static_image" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="bottom" - tools:showIn="@layout/theme_preview_card"> - <TextView - style="@style/CardTitleTextAppearance" - android:id="@+id/wallpaper_description" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:gravity="center_horizontal|bottom"/> -</FrameLayout>
\ No newline at end of file diff --git a/robolectric_tests/src/com/android/customization/model/theme/ThemeManagerTest.java b/robolectric_tests/src/com/android/customization/model/theme/ThemeManagerTest.java index 6f1f95e3..cfb8a33f 100644 --- a/robolectric_tests/src/com/android/customization/model/theme/ThemeManagerTest.java +++ b/robolectric_tests/src/com/android/customization/model/theme/ThemeManagerTest.java @@ -40,12 +40,11 @@ import android.provider.Settings; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; -import com.android.customization.model.CustomizationManager.OptionsFetchedListener; import com.android.customization.model.CustomizationManager.Callback; +import com.android.customization.model.CustomizationManager.OptionsFetchedListener; import com.android.customization.model.theme.custom.CustomTheme; import com.android.customization.module.ThemesUserEventLogger; import com.android.customization.testutils.OverlayManagerMocks; -import com.android.wallpaper.module.WallpaperSetter; import org.json.JSONObject; import org.junit.After; @@ -61,7 +60,6 @@ import org.robolectric.RobolectricTestRunner; public class ThemeManagerTest { @Mock OverlayManagerCompat mMockOm; - @Mock WallpaperSetter mMockWallpaperSetter; @Mock ThemesUserEventLogger mThemesUserEventLogger; @Mock ThemeBundleProvider mThemeBundleProvider; private OverlayManagerMocks mMockOmHelper; @@ -75,7 +73,7 @@ public class ThemeManagerTest { mActivity = spy(activity); mMockOmHelper = new OverlayManagerMocks(); mMockOmHelper.setUpMock(mMockOm); - mThemeManager = new ThemeManager(mThemeBundleProvider, activity, mMockWallpaperSetter, + mThemeManager = new ThemeManager(mThemeBundleProvider, activity, mMockOm, mThemesUserEventLogger); } diff --git a/src/com/android/customization/model/theme/DefaultThemeProvider.java b/src/com/android/customization/model/theme/DefaultThemeProvider.java index ce12d351..7c99f9cd 100644 --- a/src/com/android/customization/model/theme/DefaultThemeProvider.java +++ b/src/com/android/customization/model/theme/DefaultThemeProvider.java @@ -15,8 +15,6 @@ */ package com.android.customization.model.theme; -import static android.content.res.Resources.ID_NULL; - import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE; import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW; import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR; @@ -29,14 +27,9 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE; import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.content.pm.ResolveInfo; import android.content.res.Resources.NotFoundException; -import android.service.wallpaper.WallpaperService; import android.text.TextUtils; import android.util.Log; @@ -49,7 +42,6 @@ import com.android.customization.model.theme.custom.CustomTheme; import com.android.customization.module.CustomizationPreferences; import com.android.wallpaper.R; import com.android.wallpaper.asset.ResourceAsset; -import com.android.wallpaper.model.LiveWallpaperInfo; import com.bumptech.glide.request.RequestOptions; import com.google.android.apps.wallpaper.asset.ThemeBundleThumbAsset; @@ -57,9 +49,7 @@ import com.google.android.apps.wallpaper.asset.ThemeBundleThumbAsset; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.xmlpull.v1.XmlPullParserException; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -83,12 +73,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB private static final String ICON_THEMEPICKER_PREFIX = "theme_overlay_icon_themepicker_"; private static final String ICON_SETTINGS_PREFIX = "theme_overlay_icon_settings_"; private static final String ICON_SYSUI_PREFIX = "theme_overlay_icon_sysui_"; - private static final String WALLPAPER_PREFIX = "theme_wallpaper_"; - private static final String WALLPAPER_TITLE_PREFIX = "theme_wallpaper_title_"; - private static final String WALLPAPER_ATTRIBUTION_PREFIX = "theme_wallpaper_attribution_"; - private static final String WALLPAPER_THUMB_PREFIX = "theme_wallpaper_thumbnail_"; - private static final String WALLPAPER_ACTION_PREFIX = "theme_wallpaper_action_"; - private static final String WALLPAPER_OPTIONS_PREFIX = "theme_wallpaper_options_"; private static final String DEFAULT_THEME_NAME= "default"; private static final String THEME_TITLE_FIELD = "_theme_title"; @@ -172,8 +156,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB mOverlayProvider.addNoPreviewIconOverlay(builder, iconSettingsOverlayPackage); - addWallpaper(themeName, builder); - mThemes.add(builder.build(mContext)); } catch (NameNotFoundException | NotFoundException e) { Log.w(TAG, String.format("Couldn't load part of theme %s, will skip it", themeName), @@ -184,70 +166,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB addCustomThemes(); } - private void addWallpaper(String themeName, Builder builder) { - try { - String wallpaperResName = WALLPAPER_PREFIX + themeName; - int wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName, - "drawable", mStubPackageName); - // Check in case the theme has a separate thumbnail for the wallpaper - String wallpaperThumbnailResName = WALLPAPER_THUMB_PREFIX + themeName; - int wallpaperThumbnailResId = mStubApkResources.getIdentifier(wallpaperThumbnailResName, - "drawable", mStubPackageName); - if (wallpaperResId != ID_NULL) { - builder.setWallpaperInfo(mStubPackageName, wallpaperResName, - themeName, wallpaperResId, - mStubApkResources.getIdentifier(WALLPAPER_TITLE_PREFIX + themeName, - "string", mStubPackageName), - mStubApkResources.getIdentifier( - WALLPAPER_ATTRIBUTION_PREFIX + themeName, "string", - mStubPackageName), - mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName, - "string", mStubPackageName)) - .setWallpaperAsset(wallpaperThumbnailResId != ID_NULL ? - getThumbAsset(WALLPAPER_THUMB_PREFIX, themeName) - : getDrawableResourceAsset(WALLPAPER_PREFIX, themeName)); - } else { - // Try to see if it's a live wallpaper reference - wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName, - "string", mStubPackageName); - if (wallpaperResId != ID_NULL) { - String wpComponent = mStubApkResources.getString(wallpaperResId); - - int wallpaperOptionsResId = mStubApkResources.getIdentifier( - WALLPAPER_OPTIONS_PREFIX + themeName, "string", mStubPackageName); - String wallpaperOptions = wallpaperOptionsResId != ID_NULL - ? mStubApkResources.getString(wallpaperOptionsResId) : null; - - String[] componentParts = wpComponent.split("/"); - Intent liveWpIntent = new Intent(WallpaperService.SERVICE_INTERFACE); - liveWpIntent.setComponent( - new ComponentName(componentParts[0], componentParts[1])); - - Context appContext = mContext.getApplicationContext(); - PackageManager pm = appContext.getPackageManager(); - ResolveInfo resolveInfo = - pm.resolveService(liveWpIntent, PackageManager.GET_META_DATA); - if (resolveInfo != null) { - android.app.WallpaperInfo wallpaperInfo; - try { - wallpaperInfo = new android.app.WallpaperInfo(appContext, resolveInfo); - LiveWallpaperInfo liveInfo = new LiveWallpaperInfo(wallpaperInfo); - builder.setLiveWallpaperInfo(liveInfo).setWallpaperAsset( - wallpaperThumbnailResId != ID_NULL ? - getThumbAsset(WALLPAPER_THUMB_PREFIX, themeName) - : liveInfo.getThumbAsset(mContext)) - .setWallpaperOptions(wallpaperOptions); - } catch (XmlPullParserException | IOException e) { - Log.w(TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); - } - } - } - } - } catch (NotFoundException e) { - // Nothing to do here, if there's no wallpaper we'll just omit wallpaper - } - } - /** * Default theme requires different treatment: if there are overlay packages specified in the * stub apk, we'll use those, otherwise we'll get the System default values. But we cannot skip @@ -318,8 +236,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB mOverlayProvider.addSystemDefaultIcons(builder, SYSUI_PACKAGE, ICONS_FOR_PREVIEW); } - addWallpaper(DEFAULT_THEME_NAME, builder); - mThemes.add(builder.build(mContext)); } diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java index e83e8520..14b2dcdc 100644 --- a/src/com/android/customization/model/theme/ThemeBundle.java +++ b/src/com/android/customization/model/theme/ThemeBundle.java @@ -31,7 +31,6 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.PathShape; -import android.icu.text.SimpleDateFormat; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -40,9 +39,7 @@ import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.Dimension; -import androidx.annotation.DrawableRes; import androidx.annotation.Nullable; -import androidx.annotation.StringRes; import androidx.core.graphics.PathParser; import com.android.customization.model.CustomizationManager; @@ -51,7 +48,6 @@ import com.android.customization.widget.DynamicAdaptiveIconDrawable; import com.android.wallpaper.R; import com.android.wallpaper.asset.Asset; import com.android.wallpaper.asset.BitmapCachingAsset; -import com.android.wallpaper.model.LiveWallpaperInfo; import com.android.wallpaper.model.WallpaperInfo; import org.json.JSONException; @@ -59,12 +55,10 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; @@ -83,20 +77,15 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { private final PreviewInfo mPreviewInfo; private final boolean mIsDefault; protected final Map<String, String> mPackagesByCategory; - @Nullable private final WallpaperInfo mWallpaperInfo; - @Nullable private final String mWallpaperOptions; private WallpaperInfo mOverrideWallpaper; private Asset mOverrideWallpaperAsset; private CharSequence mContentDescription; protected ThemeBundle(String title, Map<String, String> overlayPackages, - boolean isDefault, @Nullable WallpaperInfo wallpaperInfo, - @Nullable String wallpaperOptions, PreviewInfo previewInfo) { + boolean isDefault, PreviewInfo previewInfo) { mTitle = title; mIsDefault = isDefault; mPreviewInfo = previewInfo; - mWallpaperInfo = wallpaperInfo; - mWallpaperOptions = wallpaperOptions; mPackagesByCategory = Collections.unmodifiableMap(overlayPackages); } @@ -169,16 +158,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { mOverrideWallpaperAsset = null; } - public boolean shouldUseThemeWallpaper() { - return mOverrideWallpaper == null && mWallpaperInfo != null; - } - - public Asset getWallpaperPreviewAsset(Context context) { - return mOverrideWallpaper != null ? - getOverrideWallpaperAsset(context) : - getPreviewInfo().wallpaperAsset; - } - private Asset getOverrideWallpaperAsset(Context context) { if (mOverrideWallpaperAsset == null) { mOverrideWallpaperAsset = new BitmapCachingAsset(context, @@ -187,15 +166,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { return mOverrideWallpaperAsset; } - public WallpaperInfo getWallpaperInfo() { - return mWallpaperInfo; - } - - @Nullable - public String getWallpaperOptions() { - return mWallpaperOptions; - } - boolean isDefault() { return mIsDefault; } @@ -280,14 +250,13 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { @ColorInt public final int colorAccentDark; public final List<Drawable> icons; public final Drawable shapeDrawable; - @Nullable public final Asset wallpaperAsset; public final List<Drawable> shapeAppIcons; @Dimension public final int bottomSheeetCornerRadius; private PreviewInfo(Context context, Typeface bodyFontFamily, Typeface headlineFontFamily, int colorAccentLight, int colorAccentDark, List<Drawable> icons, Drawable shapeDrawable, @Dimension int cornerRadius, - @Nullable Asset wallpaperAsset, List<Drawable> shapeAppIcons) { + List<Drawable> shapeAppIcons) { this.bodyFontFamily = bodyFontFamily; this.headlineFontFamily = headlineFontFamily; this.colorAccentLight = colorAccentLight; @@ -295,8 +264,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { this.icons = icons; this.shapeDrawable = shapeDrawable; this.bottomSheeetCornerRadius = cornerRadius; - this.wallpaperAsset = wallpaperAsset == null - ? null : new BitmapCachingAsset(context, wallpaperAsset); this.shapeAppIcons = shapeAppIcons; } @@ -323,15 +290,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { private Path mShapePath; private boolean mIsDefault; @Dimension private int mCornerRadius; - private Asset mWallpaperAsset; - private WallpaperInfo mWallpaperInfo; - private String mWallpaperOptions; protected Map<String, String> mPackages = new HashMap<>(); private List<Drawable> mAppIcons = new ArrayList<>(); public ThemeBundle build(Context context) { - return new ThemeBundle(mTitle, mPackages, mIsDefault, mWallpaperInfo, mWallpaperOptions, - createPreviewInfo(context)); + return new ThemeBundle(mTitle, mPackages, mIsDefault, createPreviewInfo(context)); } public PreviewInfo createPreviewInfo(Context context) { @@ -359,8 +322,7 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { } } return new PreviewInfo(context, mBodyFontFamily, mHeadlineFontFamily, mColorAccentLight, - mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, - mWallpaperAsset, shapeIcons); + mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons); } public Map<String, String> getPackages() { @@ -416,30 +378,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> { return this; } - public Builder setWallpaperInfo(String wallpaperPackageName, String wallpaperResName, - String themeId, @DrawableRes int wallpaperResId, @StringRes int titleResId, - @StringRes int attributionResId, @StringRes int actionUrlResId) { - mWallpaperInfo = new ThemeBundledWallpaperInfo(wallpaperPackageName, wallpaperResName, - themeId, wallpaperResId, titleResId, attributionResId, actionUrlResId); - return this; - } - - public Builder setLiveWallpaperInfo(LiveWallpaperInfo info) { - mWallpaperInfo = info; - return this; - } - - - public Builder setWallpaperAsset(Asset wallpaperAsset) { - mWallpaperAsset = wallpaperAsset; - return this; - } - - public Builder setWallpaperOptions(String wallpaperOptions) { - mWallpaperOptions = wallpaperOptions; - return this; - } - public Builder asDefault() { mIsDefault = true; return this; diff --git a/src/com/android/customization/model/theme/ThemeManager.java b/src/com/android/customization/model/theme/ThemeManager.java index 79b45fd3..533fbd0f 100644 --- a/src/com/android/customization/model/theme/ThemeManager.java +++ b/src/com/android/customization/model/theme/ThemeManager.java @@ -24,7 +24,6 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_THEMEPICKER; import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE; -import android.graphics.Point; import android.provider.Settings; import android.text.TextUtils; @@ -35,13 +34,6 @@ import com.android.customization.model.CustomizationManager; import com.android.customization.model.ResourceConstants; import com.android.customization.model.theme.custom.CustomTheme; import com.android.customization.module.ThemesUserEventLogger; -import com.android.wallpaper.R; -import com.android.wallpaper.asset.Asset; -import com.android.wallpaper.model.LiveWallpaperInfo; -import com.android.wallpaper.model.WallpaperInfo; -import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback; -import com.android.wallpaper.module.WallpaperSetter; -import com.android.wallpaper.util.WallpaperCropUtils; import org.json.JSONObject; @@ -61,25 +53,22 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> { THEME_CATEGORIES.add(OVERLAY_CATEGORY_ICON_SYSUI); THEME_CATEGORIES.add(OVERLAY_CATEGORY_ICON_LAUNCHER); THEME_CATEGORIES.add(OVERLAY_CATEGORY_ICON_THEMEPICKER); - }; - + } private final ThemeBundleProvider mProvider; private final OverlayManagerCompat mOverlayManagerCompat; - private final WallpaperSetter mWallpaperSetter; protected final FragmentActivity mActivity; private final ThemesUserEventLogger mEventLogger; private Map<String, String> mCurrentOverlays; public ThemeManager(ThemeBundleProvider provider, FragmentActivity activity, - WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, + OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { mProvider = provider; mActivity = activity; mOverlayManagerCompat = overlayManagerCompat; - mWallpaperSetter = wallpaperSetter; mEventLogger = logger; } @@ -90,67 +79,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> { @Override public void apply(ThemeBundle theme, Callback callback) { - // Set wallpaper - if (theme.shouldUseThemeWallpaper()) { - mWallpaperSetter.requestDestination(mActivity, mActivity.getSupportFragmentManager(), - R.string.set_theme_wallpaper_dialog_message, - destination -> applyWallpaper( - theme, - destination, - createSetWallpaperCallback(theme, callback)), - theme.getWallpaperInfo() instanceof LiveWallpaperInfo); - - } else { - applyOverlays(theme, callback); - } - } - - private SetWallpaperCallback createSetWallpaperCallback(ThemeBundle theme, Callback callback) { - return new SetWallpaperCallback() { - @Override - public void onSuccess(WallpaperInfo wallpaperInfo) { - applyWallpaperOptions(theme); - applyOverlays(theme, callback); - } - - @Override - public void onError(@Nullable Throwable throwable) { - callback.onError(throwable); - } - }; - } - - protected void applyWallpaperOptions(ThemeBundle theme) { - //Do nothing. - } - - private void applyWallpaper(ThemeBundle theme, int destination, - SetWallpaperCallback callback) { - Point defaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize( - mActivity.getResources(), - mActivity.getWindowManager().getDefaultDisplay()); - Asset wallpaperAsset = theme.getWallpaperInfo().getAsset(mActivity); - if (wallpaperAsset != null) { - wallpaperAsset.decodeRawDimensions(mActivity, - dimensions -> { - float scale = 1f; - // Calculate scale to fit the screen height - if (dimensions != null && dimensions.y > 0) { - scale = (float) defaultCropSurfaceSize.y / dimensions.y; - } - mWallpaperSetter.setCurrentWallpaper(mActivity, - theme.getWallpaperInfo(), - wallpaperAsset, - destination, - scale, null, callback); - }); - } else { - mWallpaperSetter.setCurrentWallpaper(mActivity, - theme.getWallpaperInfo(), - null, - destination, - 1f, null, callback); - } + applyOverlays(theme, callback); } private void applyOverlays(ThemeBundle theme, Callback callback) { diff --git a/src/com/android/customization/model/theme/custom/CustomTheme.java b/src/com/android/customization/model/theme/custom/CustomTheme.java index 8a7ca054..9c14f01b 100644 --- a/src/com/android/customization/model/theme/custom/CustomTheme.java +++ b/src/com/android/customization/model/theme/custom/CustomTheme.java @@ -41,7 +41,7 @@ public class CustomTheme extends ThemeBundle { public CustomTheme(@NonNull String id, String title, Map<String, String> overlayPackages, @Nullable PreviewInfo previewInfo) { - super(title, overlayPackages, false, null, null, previewInfo); + super(title, overlayPackages, false, previewInfo); mId = id; } @@ -76,11 +76,6 @@ public class CustomTheme extends ThemeBundle { } @Override - public boolean shouldUseThemeWallpaper() { - return false; - } - - @Override public boolean isActive(CustomizationManager<ThemeBundle> manager) { return isDefined() && super.isActive(manager); } diff --git a/src/com/android/customization/module/CustomizationInjector.java b/src/com/android/customization/module/CustomizationInjector.java index d25f9259..85853deb 100644 --- a/src/com/android/customization/module/CustomizationInjector.java +++ b/src/com/android/customization/module/CustomizationInjector.java @@ -23,13 +23,11 @@ import com.android.customization.model.theme.OverlayManagerCompat; import com.android.customization.model.theme.ThemeBundleProvider; import com.android.customization.model.theme.ThemeManager; import com.android.wallpaper.module.Injector; -import com.android.wallpaper.module.WallpaperSetter; public interface CustomizationInjector extends Injector { CustomizationPreferences getCustomizationPreferences(Context context); ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, - WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, - ThemesUserEventLogger logger); + OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger); } diff --git a/src/com/android/customization/module/DefaultCustomizationInjector.java b/src/com/android/customization/module/DefaultCustomizationInjector.java index a0d435b1..7358d8f0 100644 --- a/src/com/android/customization/module/DefaultCustomizationInjector.java +++ b/src/com/android/customization/module/DefaultCustomizationInjector.java @@ -30,7 +30,6 @@ import com.android.wallpaper.module.DefaultCategoryProvider; import com.android.wallpaper.module.LoggingOptInStatusProvider; import com.android.wallpaper.module.WallpaperPreferences; import com.android.wallpaper.module.WallpaperRotationRefresher; -import com.android.wallpaper.module.WallpaperSetter; import com.android.wallpaper.monitor.PerformanceMonitor; import com.android.wallpaper.picker.PreviewFragment; @@ -50,7 +49,6 @@ public class DefaultCustomizationInjector extends BaseWallpaperInjector return mPrefs; } - @Override public CustomizationPreferences getCustomizationPreferences(Context context) { return (CustomizationPreferences) getPreferences(context); @@ -115,9 +113,8 @@ public class DefaultCustomizationInjector extends BaseWallpaperInjector @Override public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, - WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, - ThemesUserEventLogger logger) { - return new ThemeManager(provider, activity, wallpaperSetter, overlayManagerCompat, logger); + OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { + return new ThemeManager(provider, activity, overlayManagerCompat, logger); } } diff --git a/src/com/android/customization/picker/CustomizationPickerActivity.java b/src/com/android/customization/picker/CustomizationPickerActivity.java index 86a0bf62..d4f8095a 100644 --- a/src/com/android/customization/picker/CustomizationPickerActivity.java +++ b/src/com/android/customization/picker/CustomizationPickerActivity.java @@ -65,7 +65,6 @@ import com.android.wallpaper.module.FormFactorChecker; import com.android.wallpaper.module.Injector; import com.android.wallpaper.module.InjectorProvider; import com.android.wallpaper.module.UserEventLogger; -import com.android.wallpaper.module.WallpaperSetter; import com.android.wallpaper.picker.CategoryFragment; import com.android.wallpaper.picker.CategoryFragment.CategoryFragmentHost; import com.android.wallpaper.picker.MyPhotosStarter; @@ -98,7 +97,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal private static final Map<Integer, CustomizationSection> mSections = new HashMap<>(); private CategoryFragment mWallpaperCategoryFragment; - private WallpaperSetter mWallpaperSetter; private boolean mWallpaperCategoryInitialized; @@ -194,14 +192,11 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } //Theme CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector(); - mWallpaperSetter = new WallpaperSetter(injector.getWallpaperPersister(this), - injector.getPreferences(this), mUserEventLogger, false); ThemesUserEventLogger eventLogger = (ThemesUserEventLogger) injector.getUserEventLogger( this); ThemeManager themeManager = injector.getThemeManager( new DefaultThemeProvider(this, injector.getCustomizationPreferences(this)), - this, - mWallpaperSetter, new OverlayManagerCompat(this), eventLogger); + this, new OverlayManagerCompat(this), eventLogger); if (themeManager.isAvailable()) { mSections.put(R.id.nav_theme, new ThemeSection(R.id.nav_theme, themeManager)); } else { @@ -391,14 +386,6 @@ public class CustomizationPickerActivity extends FragmentActivity implements Wal } @Override - protected void onDestroy() { - super.onDestroy(); - if (mWallpaperSetter != null) { - mWallpaperSetter.cleanUp(); - } - } - - @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (mDelegate.handleActivityResult(requestCode, resultCode, data)) { diff --git a/src/com/android/customization/picker/theme/CustomThemeActivity.java b/src/com/android/customization/picker/theme/CustomThemeActivity.java index fe537ba3..6173b3d6 100644 --- a/src/com/android/customization/picker/theme/CustomThemeActivity.java +++ b/src/com/android/customization/picker/theme/CustomThemeActivity.java @@ -53,7 +53,6 @@ import com.android.customization.module.ThemesUserEventLogger; import com.android.customization.picker.theme.CustomThemeStepFragment.CustomThemeComponentStepHost; import com.android.wallpaper.R; import com.android.wallpaper.module.InjectorProvider; -import com.android.wallpaper.module.WallpaperSetter; import org.json.JSONException; @@ -106,8 +105,6 @@ public class CustomThemeActivity extends FragmentActivity implements mThemeManager = injector.getThemeManager( new DefaultThemeProvider(this, injector.getCustomizationPreferences(this)), this, - new WallpaperSetter(injector.getWallpaperPersister(this), - injector.getPreferences(this), mUserEventLogger, false), new OverlayManagerCompat(this), mUserEventLogger); mThemeManager.fetchOptions(null, false); diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java index b5c68e53..c3f2a8dc 100644 --- a/src/com/android/customization/picker/theme/ThemeFragment.java +++ b/src/com/android/customization/picker/theme/ThemeFragment.java @@ -35,7 +35,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLayoutChangeListener; import android.view.ViewGroup; -import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.SeekBar; @@ -63,6 +62,7 @@ import com.android.customization.widget.OptionSelectorController; import com.android.wallpaper.R; import com.android.wallpaper.asset.Asset; import com.android.wallpaper.asset.Asset.CenterCropBitmapTask; +import com.android.wallpaper.asset.BitmapCachingAsset; import com.android.wallpaper.model.WallpaperInfo; import com.android.wallpaper.module.CurrentWallpaperInfoFactory; import com.android.wallpaper.module.InjectorProvider; @@ -92,7 +92,6 @@ public class ThemeFragment extends ToolbarFragment { } private RecyclerView mOptionsContainer; - private CheckBox mUseMyWallpaperButton; private OptionSelectorController<ThemeBundle> mOptionsController; private ThemeManager mThemeManager; private ThemesUserEventLogger mEventLogger; @@ -102,8 +101,9 @@ public class ThemeFragment extends ToolbarFragment { private ContentLoadingProgressBar mLoading; private View mContent; private View mError; - private boolean mUseMyWallpaper; + private boolean mUseMyWallpaper = true; private WallpaperInfo mCurrentHomeWallpaper; + private Asset mCurrentWallpaperThumbAsset; private CurrentWallpaperInfoFactory mCurrentWallpaperFactory; private TimeTicker mTicker; @@ -145,8 +145,6 @@ public class ThemeFragment extends ToolbarFragment { view.findViewById(R.id.apply_button).setOnClickListener(v -> { applyTheme(); }); - mUseMyWallpaperButton = view.findViewById(R.id.use_my_wallpaper); - mUseMyWallpaperButton.setOnCheckedChangeListener(this::onUseMyWallpaperCheckChanged); setUpOptions(savedInstanceState); return view; @@ -220,32 +218,23 @@ public class ThemeFragment extends ToolbarFragment { super.onActivityResult(requestCode, resultCode, data); } - private void onUseMyWallpaperCheckChanged(CompoundButton checkbox, boolean checked) { - mUseMyWallpaper = checked; - reloadWallpaper(); - } - private void reloadWallpaper() { mCurrentWallpaperFactory.createCurrentWallpaperInfos( (homeWallpaper, lockWallpaper, presentationMode) -> { mCurrentHomeWallpaper = homeWallpaper; - if (mSelectedTheme != null) { - if (mUseMyWallpaper || (mSelectedTheme instanceof CustomTheme)) { - mSelectedTheme.setOverrideThemeWallpaper(homeWallpaper); - } else { - mSelectedTheme.setOverrideThemeWallpaper(null); - } - if (mAdapter != null) { - mAdapter.rebindWallpaperIfAvailable(); - } + mCurrentWallpaperThumbAsset = new BitmapCachingAsset(getContext(), + mCurrentHomeWallpaper.getThumbAsset(getContext())); + if (mSelectedTheme != null && mAdapter != null) { + mAdapter.setWallpaperAsset(mCurrentWallpaperThumbAsset); + mAdapter.rebindWallpaperIfAvailable(); } }, false); } private void createAdapter(List<ThemeBundle> options) { mAdapter = new ThemePreviewAdapter(getActivity(), mSelectedTheme, - mSelectedTheme instanceof CustomTheme ? this::onEditClicked : null, - new PreloadWallpapersLayoutListener(options)); + mCurrentWallpaperThumbAsset, + mSelectedTheme instanceof CustomTheme ? this::onEditClicked : null); mPreviewPager.setAdapter(mAdapter); } @@ -255,11 +244,6 @@ public class ThemeFragment extends ToolbarFragment { } } - private void updateButtonsVisibility() { - mUseMyWallpaperButton.setVisibility(mSelectedTheme instanceof CustomTheme - ? View.INVISIBLE : View.VISIBLE); - } - private void hideError() { mContent.setVisibility(View.VISIBLE); mError.setVisibility(View.GONE); @@ -292,7 +276,6 @@ public class ThemeFragment extends ToolbarFragment { mEventLogger.logThemeSelected(mSelectedTheme, selected instanceof CustomTheme); createAdapter(options); - updateButtonsVisibility(); } }); mOptionsController.initOptions(mThemeManager); @@ -384,11 +367,12 @@ public class ThemeFragment extends ToolbarFragment { R.id.shape_preview_icon_0, R.id.shape_preview_icon_1, R.id.shape_preview_icon_2, R.id.shape_preview_icon_3, R.id.shape_preview_icon_4, R.id.shape_preview_icon_5 }; + private Asset mWallpaperAsset; - ThemePreviewAdapter(Activity activity, ThemeBundle theme, - @Nullable OnClickListener editClickListener, - @Nullable OnLayoutChangeListener coverCardLayoutListener) { + ThemePreviewAdapter(Activity activity, ThemeBundle theme, @Nullable Asset wallpaperAsset, + @Nullable OnClickListener editClickListener) { super(activity, R.layout.theme_preview_card); + mWallpaperAsset = wallpaperAsset; final Resources res = activity.getResources(); final PreviewInfo previewInfo = theme.getPreviewInfo(); @@ -397,14 +381,14 @@ public class ThemeFragment extends ToolbarFragment { : null; WallpaperPreviewLayoutListener wallpaperListener = new WallpaperPreviewLayoutListener( - theme, previewInfo, coverScrim, true); + () -> mWallpaperAsset, previewInfo, coverScrim, true); addPage(new ThemeCoverPage(activity, theme.getTitle(), previewInfo.resolveAccentColor(res), previewInfo.icons, previewInfo.headlineFontFamily, previewInfo.bottomSheeetCornerRadius, previewInfo.shapeDrawable, previewInfo.shapeAppIcons, editClickListener, mColorButtonIds, mColorTileIds, mColorTileIconIds, mShapeIconIds, - wallpaperListener, coverCardLayoutListener)); + wallpaperListener)); addPage(new ThemePreviewPage(activity, R.string.preview_name_font, R.drawable.ic_font, R.layout.preview_card_font_content, previewInfo.resolveAccentColor(res)) { @@ -501,31 +485,6 @@ public class ThemeFragment extends ToolbarFragment { } }); } - if (previewInfo.wallpaperAsset != null) { - addPage(new ThemePreviewPage(activity, R.string.preview_name_wallpaper, - R.drawable.ic_nav_wallpaper, R.layout.preview_card_wallpaper_content, - previewInfo.resolveAccentColor(res)) { - - private final WallpaperPreviewLayoutListener mListener = - new WallpaperPreviewLayoutListener(theme, previewInfo, null, false); - - @Override - protected boolean containsWallpaper() { - return true; - } - - @Override - protected void bindBody(boolean forceRebind) { - if (card == null) { - return; - } - card.addOnLayoutChangeListener(mListener); - if (forceRebind) { - card.requestLayout(); - } - } - }); - } } public void rebindWallpaperIfAvailable() { @@ -544,15 +503,23 @@ public class ThemeFragment extends ToolbarFragment { } } + public void setWallpaperAsset(Asset wallpaperAsset) { + mWallpaperAsset = wallpaperAsset; + } + private static class WallpaperPreviewLayoutListener implements OnLayoutChangeListener { - private final ThemeBundle mTheme; + interface WallpaperPreviewAssetProvider { + Asset getAsset(); + } + private final WallpaperPreviewAssetProvider mWallpaperPreviewAssetProvider; private final PreviewInfo mPreviewInfo; private final Drawable mScrim; private final boolean mIsTranslucent; - public WallpaperPreviewLayoutListener(ThemeBundle theme, PreviewInfo previewInfo, - Drawable scrim, boolean translucent) { - mTheme = theme; + WallpaperPreviewLayoutListener( + WallpaperPreviewAssetProvider wallpaperPreviewAssetProvider, + PreviewInfo previewInfo, Drawable scrim, boolean translucent) { + mWallpaperPreviewAssetProvider = wallpaperPreviewAssetProvider; mPreviewInfo = previewInfo; mScrim = scrim; mIsTranslucent = translucent; @@ -564,8 +531,7 @@ public class ThemeFragment extends ToolbarFragment { int targetWidth = right - left; int targetHeight = bottom - top; if (targetWidth > 0 && targetHeight > 0) { - Asset wallpaperPreviewAsset = mTheme.getWallpaperPreviewAsset( - view.getContext()); + Asset wallpaperPreviewAsset = mWallpaperPreviewAssetProvider.getAsset(); if (wallpaperPreviewAsset != null) { wallpaperPreviewAsset.decodeBitmap( targetWidth, targetHeight, @@ -611,41 +577,4 @@ public class ThemeFragment extends ToolbarFragment { } } } - - /** - * Runs only once after the card size is known, and requests decoding wallpaper bitmaps - * for all the options, to warm-up the bitmap cache. - */ - private static class PreloadWallpapersLayoutListener implements OnLayoutChangeListener { - private static boolean alreadyRunOnce; - private final List<ThemeBundle> mOptions; - - public PreloadWallpapersLayoutListener(List<ThemeBundle> options) { - mOptions = options; - } - - @Override - public void onLayoutChange(View view, int left, int top, int right, - int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - if (alreadyRunOnce) { - view.removeOnLayoutChangeListener(this); - return; - } - int targetWidth = right - left; - int targetHeight = bottom - top; - if (targetWidth > 0 && targetHeight > 0) { - for (ThemeBundle theme : mOptions) { - if (theme instanceof CustomTheme && !((CustomTheme) theme).isDefined()) { - continue; - } - Asset wallpaperAsset = theme.getWallpaperPreviewAsset(view.getContext()); - if (wallpaperAsset != null) { - wallpaperAsset.decodeBitmap(targetWidth, targetHeight, bitmap -> {}); - } - } - view.removeOnLayoutChangeListener(this); - alreadyRunOnce = true; - } - } - } } diff --git a/src/com/android/customization/picker/theme/ThemePreviewPage.java b/src/com/android/customization/picker/theme/ThemePreviewPage.java index c3af91cd..cbcbc785 100644 --- a/src/com/android/customization/picker/theme/ThemePreviewPage.java +++ b/src/com/android/customization/picker/theme/ThemePreviewPage.java @@ -179,7 +179,6 @@ abstract class ThemePreviewPage extends PreviewPage { } // Shape preview icons: - for (int i = 0; i < 3 && i < mShapeAppIcons.size(); i++) { ImageView iconView = card.findViewById(mShapeIconIds[i]); iconView.setBackground(mShapeAppIcons.get(i)); diff --git a/tests/src/com/android/customization/testing/TestCustomizationInjector.java b/tests/src/com/android/customization/testing/TestCustomizationInjector.java index 10b59343..dbbdb74b 100644 --- a/tests/src/com/android/customization/testing/TestCustomizationInjector.java +++ b/tests/src/com/android/customization/testing/TestCustomizationInjector.java @@ -13,7 +13,6 @@ import com.android.customization.module.ThemesUserEventLogger; import com.android.wallpaper.module.DrawableLayerResolver; import com.android.wallpaper.module.PackageStatusNotifier; import com.android.wallpaper.module.UserEventLogger; -import com.android.wallpaper.module.WallpaperSetter; import com.android.wallpaper.testing.TestInjector; /** @@ -38,12 +37,10 @@ public class TestCustomizationInjector extends TestInjector implements Customiza public ThemeManager getThemeManager( ThemeBundleProvider provider, FragmentActivity activity, - WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { if (mThemeManager == null) { - mThemeManager = new TestThemeManager(provider, activity, wallpaperSetter, - overlayManagerCompat, logger); + mThemeManager = new TestThemeManager(provider, activity, overlayManagerCompat, logger); } return mThemeManager; } diff --git a/tests/src/com/android/customization/testing/TestThemeManager.java b/tests/src/com/android/customization/testing/TestThemeManager.java index cc8567f1..c4d25fba 100644 --- a/tests/src/com/android/customization/testing/TestThemeManager.java +++ b/tests/src/com/android/customization/testing/TestThemeManager.java @@ -6,7 +6,6 @@ import com.android.customization.model.theme.OverlayManagerCompat; import com.android.customization.model.theme.ThemeBundleProvider; import com.android.customization.model.theme.ThemeManager; import com.android.customization.module.ThemesUserEventLogger; -import com.android.wallpaper.module.WallpaperSetter; /** * Test implementation of {@link ThemeManager}. @@ -18,10 +17,9 @@ public class TestThemeManager extends ThemeManager { public TestThemeManager( ThemeBundleProvider provider, FragmentActivity activity, - WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { - super(provider, activity, wallpaperSetter, overlayManagerCompat, logger); + super(provider, activity, overlayManagerCompat, logger); } @Override |