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

Commit f30dcd46 authored by John Pan's avatar John Pan
Browse files

Auto calculate grid card size

Before: https://screenshot.googleplex.com/APctde9RT2PKCQ4
After: https://screenshot.googleplex.com/5H8q3X3HXUmNkv5

Bug: 193374285
Test: Manual
Change-Id: I16359da61debce47f14f09a0886faf5541c5c19f
parent c823b183
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@

            <FrameLayout
                android:id="@+id/preview_card_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:clipToPadding="false"
                android:paddingTop="@dimen/preview_page_top_margin"
                android:paddingBottom="@dimen/preview_page_bottom_margin"
@@ -42,7 +42,8 @@
                app:layout_constraintBottom_toTopOf="@+id/options_container"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="@dimen/preview_card_vertical_bias">

                <include layout="@layout/grid_preview_card" />
            </FrameLayout>
+18 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.customization.picker.grid;
import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY_TEXT;

import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@@ -29,6 +30,8 @@ import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.widget.ContentLoadingProgressBar;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
@@ -49,11 +52,13 @@ import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.util.LaunchUtils;
import com.android.wallpaper.util.ScreenSizeCalculator;
import com.android.wallpaper.widget.BottomActionBar;

import com.bumptech.glide.Glide;

import java.util.List;
import java.util.Locale;

/**
 * Fragment that contains the UI for selecting and applying a GridOption.
@@ -67,7 +72,7 @@ public class GridFragment extends AppbarFragment {
    private OptionSelectorController<GridOption> mOptionsController;
    private GridOptionsManager mGridManager;
    private ContentLoadingProgressBar mLoading;
    private View mContent;
    private ConstraintLayout mContent;
    private View mError;
    private BottomActionBar mBottomActionBar;
    private ThemesUserEventLogger mEventLogger;
@@ -117,6 +122,18 @@ public class GridFragment extends AppbarFragment {
            // Make Talkback focus won't reset when notifyDataSetChange
            mOptionsContainer.setItemAnimator(null);
        }

        // Set aspect ratio on the preview card dynamically.
        Point mScreenSize;
        ScreenSizeCalculator screenSizeCalculator = ScreenSizeCalculator.getInstance();
        mScreenSize = screenSizeCalculator.getScreenSize(
                requireActivity().getWindowManager().getDefaultDisplay());
        ConstraintSet set = new ConstraintSet();
        set.clone(mContent);
        String ratio = String.format(Locale.US, "%d:%d", mScreenSize.x, mScreenSize.y);
        set.setDimensionRatio(R.id.preview_card_container, ratio);
        set.applyTo(mContent);

        mLoading = view.findViewById(R.id.loading_indicator);
        mError = view.findViewById(R.id.error_section);