Add new preview for theme picker (Part1)
- Uses a flag to hide the new preview until it's ready.
- Uses the apply button of bottom action bar.
Screenshot:
flag is false: https://screenshot.googleplex.com/nDyDnt708tL.png
flag is ture: https://screenshot.googleplex.com/R76eoVL0rNy.png
Test: Manually
Bug: 146475648
Change-Id: I49e33e011da106e7773a66a1238cc462a873c1cc
diff --git a/res/layout/fragment_theme_picker.xml b/res/layout/fragment_theme_picker.xml
index d15d93f..93606ea 100644
--- a/res/layout/fragment_theme_picker.xml
+++ b/res/layout/fragment_theme_picker.xml
@@ -16,7 +16,6 @@
-->
<LinearLayout
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:orientation="vertical"
@@ -27,49 +26,40 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <androidx.constraintlayout.widget.ConstraintLayout
+ <LinearLayout
android:id="@+id/content_section"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <!-- The V2 preview card. -->
+ <FrameLayout
+ android:id="@+id/preview_card_container"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/preview_content_height"
+ android:paddingTop="@dimen/preview_content_padding_top"
+ android:paddingBottom="@dimen/preview_content_padding_bottom"
+ android:clipToPadding="false"
+ android:background="@color/fullscreen_preview_background"
+ android:visibility="gone">
+ <include layout="@layout/theme_preview_card_v2"/>
+ </FrameLayout>
+
+ <!-- Will remove it later. -->
<com.android.wallpaper.widget.PreviewPager
android:id="@+id/theme_preview_pager"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/preview_pager_background"
- app:layout_constrainedHeight="true"
- app:layout_constraintBottom_toTopOf="@id/options_container"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHeight_max="@dimen/preview_pager_max_height"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.0"
- app:layout_constraintVertical_chainStyle="spread_inside"/>
+ android:layout_height="@dimen/preview_content_height"
+ android:background="@color/preview_pager_background"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/options_container"
android:layout_width="match_parent"
- android:layout_height="@dimen/options_container_height"
+ android:layout_height="0dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginTop="10dp"
- android:layout_weight="1"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/theme_preview_pager"
- app:layout_constraintVertical_bias="1.0"/>
-
- <Button
- android:id="@+id/apply_button"
- style="@style/ActionPrimaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="end"
- android:layout_marginEnd="10dp"
- android:layout_marginBottom="10dp"
- android:text="@string/apply_theme_btn"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"/>
- </androidx.constraintlayout.widget.ConstraintLayout>
+ android:layout_weight="1"/>
+ </LinearLayout>
<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/loading_indicator"
diff --git a/res/layout/theme_preview_card_v2.xml b/res/layout/theme_preview_card_v2.xml
new file mode 100644
index 0000000..b6e8d49
--- /dev/null
+++ b/res/layout/theme_preview_card_v2.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 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.
+-->
+<androidx.cardview.widget.CardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/FullContentPreviewCard"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center">
+
+ <ImageView
+ android:id="@+id/wallpaper_preview_image"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/primary_color" />
+
+ <SurfaceView
+ android:id="@+id/wallpaper_preview_surface"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+</androidx.cardview.widget.CardView>
\ No newline at end of file
diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java
index e04d8d2..d73214c 100644
--- a/src/com/android/customization/picker/theme/ThemeFragment.java
+++ b/src/com/android/customization/picker/theme/ThemeFragment.java
@@ -15,6 +15,8 @@
*/
package com.android.customization.picker.theme;
+import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;
+
import android.app.Activity;
import android.app.WallpaperColors;
import android.content.Context;
@@ -54,6 +56,7 @@
import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.TimeTicker;
+import com.android.customization.picker.WallpaperPreviewer;
import com.android.customization.picker.theme.ThemePreviewPage.ThemeCoverPage;
import com.android.customization.picker.theme.ThemePreviewPage.TimeContainer;
import com.android.customization.widget.OptionSelectorController;
@@ -65,6 +68,7 @@
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
+import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.PreviewPager;
import java.util.List;
@@ -77,6 +81,8 @@
private static final String TAG = "ThemeFragment";
private static final String KEY_SELECTED_THEME = "ThemeFragment.SelectedThemeBundle";
+ private static final boolean USE_NEW_PREVIEW = false;
+
/**
* Interface to be implemented by an Activity hosting a {@link ThemeFragment}
*/
@@ -104,6 +110,8 @@
private Asset mCurrentWallpaperThumbAsset;
private CurrentWallpaperInfoFactory mCurrentWallpaperFactory;
private TimeTicker mTicker;
+ private BottomActionBar mBottomActionBar;
+ private WallpaperPreviewer mWallpaperPreviewer;
@Override
public void onAttach(Context context) {
@@ -128,14 +136,43 @@
.getCurrentWallpaperFactory(getActivity().getApplicationContext());
mPreviewPager = view.findViewById(R.id.theme_preview_pager);
mOptionsContainer = view.findViewById(R.id.options_container);
- view.findViewById(R.id.apply_button).setOnClickListener(v -> {
- applyTheme();
- });
- setUpOptions(savedInstanceState);
+ if (USE_NEW_PREVIEW) {
+ mPreviewPager.setVisibility(View.GONE);
+ view.findViewById(R.id.preview_card_container).setVisibility(View.VISIBLE);
+ mWallpaperPreviewer = new WallpaperPreviewer(
+ getLifecycle(),
+ getActivity(),
+ view.findViewById(R.id.wallpaper_preview_image),
+ view.findViewById(R.id.wallpaper_preview_surface));
+ 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;
}
+ @Override
+ protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
+ mBottomActionBar = bottomActionBar;
+ mBottomActionBar.bindBackButtonToSystemBackKey(getActivity());
+ mBottomActionBar.showActionsOnly(APPLY);
+ mBottomActionBar.setActionClickListener(APPLY, v -> applyTheme());
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ // Setup options here when all views are ready(including BottomActionBar), since we need to
+ // update views after options are loaded.
+ setUpOptions(savedInstanceState);
+ }
+
private void applyTheme() {
mThemeManager.apply(mSelectedTheme, new Callback() {
@Override
@@ -208,11 +245,15 @@
mCurrentWallpaperFactory.createCurrentWallpaperInfos(
(homeWallpaper, lockWallpaper, presentationMode) -> {
mCurrentHomeWallpaper = homeWallpaper;
- mCurrentWallpaperThumbAsset = new BitmapCachingAsset(getContext(),
- mCurrentHomeWallpaper.getThumbAsset(getContext()));
- if (mSelectedTheme != null && mAdapter != null) {
- mAdapter.setWallpaperAsset(mCurrentWallpaperThumbAsset);
- mAdapter.rebindWallpaperIfAvailable();
+ if (USE_NEW_PREVIEW) {
+ mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper);
+ } else {
+ mCurrentWallpaperThumbAsset = new BitmapCachingAsset(getContext(),
+ mCurrentHomeWallpaper.getThumbAsset(getContext()));
+ if (mSelectedTheme != null && mAdapter != null) {
+ mAdapter.setWallpaperAsset(mCurrentWallpaperThumbAsset);
+ mAdapter.rebindWallpaperIfAvailable();
+ }
}
}, false);
}
@@ -261,7 +302,10 @@
}
mEventLogger.logThemeSelected(mSelectedTheme,
selected instanceof CustomTheme);
- createAdapter(options);
+ if (!USE_NEW_PREVIEW) {
+ createAdapter(options);
+ }
+ mBottomActionBar.show();
}
});
mOptionsController.initOptions(mThemeManager);
@@ -285,6 +329,9 @@
mOptionsController.setAppliedOption(mSelectedTheme);
}
mOptionsController.setSelectedOption(mSelectedTheme);
+ // Set selected option above will show BottomActionBar when entering the tab. But
+ // it should not show when entering the tab.
+ mBottomActionBar.hide();
}
@Override
public void onError(@Nullable Throwable throwable) {