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

Commit adb6f41e authored by chihhangchuang's avatar chihhangchuang
Browse files

Add full preview for Grid (part 1)

- Add new Activity and Fragment for full preview
- Add grid full preview page
- Screenshot: https://screenshot.googleplex.com/thKsXZgStcX.png

Test: Manually
Bug: 151287994
Change-Id: I5a88c9c60a616abf8a8a2a1dd82dbcbb7ef72139
parent cf95a0b6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@
        <activity android:name="com.android.customization.picker.theme.CustomThemeActivity"
                  android:resizeableActivity="false"
                  android:theme="@style/CustomizationTheme.NoActionBar"/>

        <activity android:name="com.android.customization.picker.ViewOnlyFullPreviewActivity"
            android:resizeableActivity="false"
            android:theme="@style/CustomizationTheme.NoActionBar"/>
    </application>

</manifest>
+28 −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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/preview_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/bottom_navbar_height" />

    <include layout="@layout/bottom_action_bar" />
</FrameLayout>
+52 −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:background="@color/fullscreen_preview_background">

        <androidx.cardview.widget.CardView
            style="@style/FullContentPreviewCard"
            android:id="@+id/grid_full_preview_card"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="32dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center">

            <ImageView
                android:id="@+id/grid_full_preview_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <SurfaceView
                android:id="@+id/grid_full_preview_surface"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </androidx.cardview.widget.CardView>
    </FrameLayout>
</LinearLayout>
+47 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.customization.model.grid;
import android.content.Context;
import android.graphics.PorterDuff.Mode;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import android.widget.ImageView;

@@ -29,10 +31,23 @@ import com.android.wallpaper.R;
/**
 * Represents a grid layout option available in the current launcher.
 */
public class GridOption implements CustomizationOption<GridOption> {
// TODO(chihhangchuang): Consider moving Parcelable into CustomizationOption.
public class GridOption implements CustomizationOption<GridOption>, Parcelable {
    public static final Creator<GridOption> CREATOR = new Creator<GridOption>() {
        @Override
        public GridOption createFromParcel(Parcel in) {
            return new GridOption(in);
        }

        @Override
        public GridOption[] newArray(int size) {
            return new GridOption[size];
        }
    };

    private final String mTitle;
    private final boolean mIsCurrent;
    private final String mIconShapePath;
    private final GridTileDrawable mTileDrawable;
    public final String name;
    public final int rows;
@@ -44,7 +59,8 @@ public class GridOption implements CustomizationOption<GridOption> {
            Uri previewImageUri, int previewPagesCount, String iconShapePath) {
        mTitle = title;
        mIsCurrent = isCurrent;
        mTileDrawable = new GridTileDrawable(rows, cols, iconShapePath);
        mIconShapePath = iconShapePath;
        mTileDrawable = new GridTileDrawable(rows, cols, mIconShapePath);
        this.name = name;
        this.rows = rows;
        this.cols = cols;
@@ -52,6 +68,18 @@ public class GridOption implements CustomizationOption<GridOption> {
        this.previewPagesCount = previewPagesCount;
    }

    protected GridOption(Parcel in) {
        mTitle = in.readString();
        mIsCurrent = in.readByte() != 0;
        mIconShapePath = in.readString();
        name = in.readString();
        rows = in.readInt();
        cols = in.readInt();
        previewImageUri = in.readParcelable(Uri.class.getClassLoader());
        previewPagesCount = in.readInt();
        mTileDrawable = new GridTileDrawable(rows, cols, mIconShapePath);
    }

    @Override
    public String getTitle() {
        return mTitle;
@@ -76,4 +104,21 @@ public class GridOption implements CustomizationOption<GridOption> {
    public int getLayoutResId() {
        return R.layout.grid_option;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(mTitle);
        parcel.writeByte((byte) (mIsCurrent ? 1 : 0));
        parcel.writeString(mIconShapePath);
        parcel.writeString(name);
        parcel.writeInt(rows);
        parcel.writeInt(cols);
        parcel.writeParcelable(previewImageUri, i);
        parcel.writeInt(previewPagesCount);
    }
}
+82 −0
Original line number Diff line number Diff line
/*
 * 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.
 */
package com.android.customization.picker;

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

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.android.customization.picker.grid.GridFullPreviewFragment;
import com.android.wallpaper.R;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.BottomActionBar.BottomActionBarHost;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/** Activity for full preview. */
public class ViewOnlyFullPreviewActivity extends FragmentActivity implements BottomActionBarHost {

    private static final String EXTRA_PREVIEW_SECTION = "preview_section";
    private static final String EXTRA_PREVIEW_BUNDLE = "preview_bundle";

    public static final int SECTION_STYLE = 0;
    public static final int SECTION_GRID = 1;
    public static final int SECTION_CLOCK = 2;

    @IntDef({SECTION_STYLE, SECTION_GRID, SECTION_CLOCK})
    @Retention(RetentionPolicy.SOURCE)
    private @interface Section {}

    /** Returns a new Intent with the provided data in the extra. */
    public static Intent newIntent(Context packageContext, @Section int section, Bundle bundle) {
        Intent intent = new Intent(packageContext, ViewOnlyFullPreviewActivity.class);
        intent.putExtra(EXTRA_PREVIEW_SECTION, section);
        intent.putExtra(EXTRA_PREVIEW_BUNDLE, bundle);
        return intent;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_preview);

        final Intent intent = getIntent();
        @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));
        }
    }

    @Override
    public BottomActionBar getBottomActionBar() {
        return findViewById(R.id.bottom_actionbar);
    }

    private void showFragment(Fragment fragment) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.preview_fragment_container, fragment)
                .commitNow();
    }
}
Loading