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

Commit 22cf6044 authored by chihhangchuang's avatar chihhangchuang
Browse files

Add full preview for theme picker

Video: https://drive.google.com/file/d/1UoAZxxjJEKwq9ZYJ3MWca8ygEX97vhBz/view?usp=sharing

Test: Manually
Bug: 151286773
Change-Id: Ib94425fa716a58f0cf3b43ca3d2c05cccf4a52ec
parent cb6d3c38
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
<?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.
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/section_header"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:paddingTop="@dimen/full_preview_page_default_padding_top"
        android:paddingBottom="@dimen/full_preview_page_default_padding_bottom"
        android:clipToPadding="false"
        android:background="@color/fullscreen_preview_background">

        <include layout="@layout/theme_preview_card_v2"/>
    </FrameLayout>
</LinearLayout>
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -324,6 +324,13 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
        }
    }

    @Nullable
    @Override
    public ThemeBundle.Builder parseThemeBundle(String serializedTheme) throws JSONException {
        return parseCustomTheme(serializedTheme);
    }

    @Nullable
    @Override
    public CustomTheme.Builder parseCustomTheme(String serializedTheme) throws JSONException {
        JSONObject theme = new JSONObject(serializedTheme);
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ public interface ThemeBundleProvider {

    void removeCustomTheme(CustomTheme theme);

    @Nullable ThemeBundle.Builder parseThemeBundle(String serializedTheme) throws JSONException;

    @Nullable CustomTheme.Builder parseCustomTheme(String serializedTheme) throws JSONException;

    ThemeBundle findEquivalent(ThemeBundle other);
+13 −2
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@
 */
package com.android.customization.picker;

import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_THEME_OPTION_TITLE;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
@@ -25,6 +28,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.android.customization.picker.grid.GridFullPreviewFragment;
import com.android.customization.picker.theme.ThemeFullPreviewFragment;
import com.android.wallpaper.R;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.BottomActionBar.BottomActionBarHost;
@@ -63,8 +67,15 @@ public class ViewOnlyFullPreviewActivity extends FragmentActivity implements Bot
        @Section final int section = intent.getIntExtra(EXTRA_PREVIEW_SECTION, 0);
        final Bundle bundle = intent.getBundleExtra(EXTRA_PREVIEW_BUNDLE);
        if (section == SECTION_GRID) {
            showFragment(
                    GridFullPreviewFragment.newInstance(getString(R.string.grid_title), bundle));
            showFragment(GridFullPreviewFragment.newInstance(
                    getString(R.string.grid_title), bundle));
        } else if (section == SECTION_STYLE) {
            final String themeTitle = bundle.getString(EXTRA_THEME_OPTION_TITLE);
            showFragment(ThemeFullPreviewFragment.newInstance(
                    TextUtils.isEmpty(themeTitle)
                            ? getString(R.string.theme_title)
                            : themeTitle,
                    bundle));
        }
    }

+40 −14
Original line number Diff line number Diff line
@@ -15,6 +15,12 @@
 */
package com.android.customization.picker.theme;

import static android.app.Activity.RESULT_OK;

import static com.android.customization.picker.ViewOnlyFullPreviewActivity.SECTION_STYLE;
import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_THEME_OPTION;
import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_THEME_OPTION_TITLE;
import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_WALLPAPER_INFO;
import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;

import android.app.Activity;
@@ -56,6 +62,7 @@ import com.android.customization.model.theme.custom.CustomTheme;
import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.TimeTicker;
import com.android.customization.picker.ViewOnlyFullPreviewActivity;
import com.android.customization.picker.WallpaperPreviewer;
import com.android.customization.picker.theme.ThemePreviewPage.ThemeCoverPage;
import com.android.customization.picker.theme.ThemePreviewPage.TimeContainer;
@@ -80,6 +87,7 @@ public class ThemeFragment extends AppbarFragment {

    private static final String TAG = "ThemeFragment";
    private static final String KEY_SELECTED_THEME = "ThemeFragment.SelectedThemeBundle";
    private static final int FULL_PREVIEW_REQUEST_CODE = 1000;

    private static final boolean USE_NEW_PREVIEW = false;

@@ -141,11 +149,17 @@ public class ThemeFragment extends AppbarFragment {
        if (USE_NEW_PREVIEW) {
            mPreviewPager.setVisibility(View.GONE);
            view.findViewById(R.id.preview_card_container).setVisibility(View.VISIBLE);
            // Set Wallpaper background.
            mWallpaperPreviewer = new WallpaperPreviewer(
                    getLifecycle(),
                    getActivity(),
                    view.findViewById(R.id.wallpaper_preview_image),
                    view.findViewById(R.id.wallpaper_preview_surface));
            mCurrentWallpaperFactory.createCurrentWallpaperInfos(
                    (homeWallpaper, lockWallpaper, presentationMode) -> {
                        mCurrentHomeWallpaper = homeWallpaper;
                        mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper);
                    }, false);
            view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom,
@@ -154,10 +168,13 @@ public class ThemeFragment extends AppbarFragment {
                    view.removeOnLayoutChangeListener(this);
                }
            });

            ViewGroup previewContainer = view.findViewById(R.id.theme_preview_container);
            previewContainer.setOnClickListener(v -> showFullPreview());
            mThemeOptionPreviewer = new ThemeOptionPreviewer(
                    getLifecycle(),
                    getContext(),
                    view.findViewById(R.id.theme_preview_container));
                    previewContainer);
        }
        return view;
    }
@@ -206,10 +223,12 @@ public class ThemeFragment extends AppbarFragment {
    @Override
    public void onResume() {
        super.onResume();
        if (!USE_NEW_PREVIEW) {
            mTicker = TimeTicker.registerNewReceiver(getContext(), this::updateTime);
            reloadWallpaper();
            updateTime();
        }
    }

    private void updateTime() {
        if (mAdapter != null) {
@@ -220,7 +239,7 @@ public class ThemeFragment extends AppbarFragment {
    @Override
    public void onPause() {
        super.onPause();
        if (getContext() != null) {
        if (getContext() != null && !USE_NEW_PREVIEW) {
            getContext().unregisterReceiver(mTicker);
        }
    }
@@ -251,6 +270,8 @@ public class ThemeFragment extends AppbarFragment {
                    reloadOptions();
                }
            }
        } else if (requestCode == FULL_PREVIEW_REQUEST_CODE && resultCode == RESULT_OK) {
            applyTheme();
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
@@ -259,16 +280,12 @@ public class ThemeFragment extends AppbarFragment {
        mCurrentWallpaperFactory.createCurrentWallpaperInfos(
                (homeWallpaper, lockWallpaper, presentationMode) -> {
                    mCurrentHomeWallpaper = homeWallpaper;
                    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);
    }

@@ -401,6 +418,15 @@ public class ThemeFragment extends AppbarFragment {
        startActivityForResult(intent, CustomThemeActivity.REQUEST_CODE_CUSTOM_THEME);
    }

    private void showFullPreview() {
        Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_WALLPAPER_INFO, mCurrentHomeWallpaper);
        bundle.putString(EXTRA_THEME_OPTION, mSelectedTheme.getSerializedPackages());
        bundle.putString(EXTRA_THEME_OPTION_TITLE, mSelectedTheme.getTitle());
        Intent intent = ViewOnlyFullPreviewActivity.newIntent(getContext(), SECTION_STYLE, bundle);
        startActivityForResult(intent, FULL_PREVIEW_REQUEST_CODE);
    }

    /**
     * Adapter class for mPreviewPager.
     * This is a ViewPager as it allows for a nice pagination effect (ie, pages snap on swipe,
Loading