Merging from ub-launcher3-master @ build 6476761
Bug:154410862
Test: manual, presubmit on the source branch
x20/teams/android-launcher/merge/ub-launcher3-master_rvc-d1-dev_6476761.html
Change-Id: Idbde25a62efd946b98057b4bac2d3dc5f0128bbc
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c0b2e8d..619d745 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -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>
diff --git a/res/layout/activity_full_preview.xml b/res/layout/activity_full_preview.xml
new file mode 100644
index 0000000..b1e0584
--- /dev/null
+++ b/res/layout/activity_full_preview.xml
@@ -0,0 +1,28 @@
+<?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>
diff --git a/res/layout/fragment_clock_scalable_picker.xml b/res/layout/fragment_clock_scalable_picker.xml
deleted file mode 100644
index db31dc5..0000000
--- a/res/layout/fragment_clock_scalable_picker.xml
+++ /dev/null
@@ -1,119 +0,0 @@
-<?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.coordinatorlayout.widget.CoordinatorLayout
- 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:background="?android:colorPrimary"
- android:orientation="vertical">
-
- <include layout="@layout/section_header" />
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:layout_behavior="@string/scalable_container_behavior">
-
- <com.android.wallpaper.widget.PreviewPager
- android:id="@+id/clock_preview_pager"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/preview_pager_background" />
- </FrameLayout>
-
- <FrameLayout
- android:id="@+id/scalable_content_container"
- android:layout_width="wrap_content"
- android:layout_height="@dimen/content_container_maximum_height"
- app:behavior_peekHeight="@dimen/content_container_minimum_height"
- app:layout_behavior="@string/bottom_sheet_behavior">
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/content_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/options_container"
- android:layout_width="match_parent"
- android:layout_height="@dimen/options_container_height"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="10dp"
- app:layout_constraintBottom_toTopOf="@id/placeholder"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="1.0" />
-
- <Space
- android:id="@+id/placeholder"
- android:layout_width="match_parent"
- android:layout_height="@dimen/min_taptarget_height"
- 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"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="end"
- android:layout_marginVertical="10dp"
- android:layout_marginEnd="10dp"
- android:layout_weight="1"
- android:text="@string/apply_theme_btn"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent" />
- </androidx.constraintlayout.widget.ConstraintLayout>
- </FrameLayout>
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.core.widget.ContentLoadingProgressBar
- android:id="@+id/loading_indicator"
- style="@android:style/Widget.DeviceDefault.ProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:layout_marginTop="200dp"
- android:indeterminate="true" />
-
- <FrameLayout
- android:id="@+id/error_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone">
-
- <TextView
- android:id="@+id/error_message"
- style="@style/TitleTextAppearance"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:text="@string/something_went_wrong" />
- </FrameLayout>
- </FrameLayout>
-</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/res/layout/fragment_grid_full_preview.xml b/res/layout/fragment_grid_full_preview.xml
new file mode 100644
index 0000000..1c01743
--- /dev/null
+++ b/res/layout/fragment_grid_full_preview.xml
@@ -0,0 +1,58 @@
+<?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"
+ android:background="@color/primary_color"/>
+
+ <SurfaceView
+ android:id="@+id/grid_full_preview_option_surface"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <SurfaceView
+ android:id="@+id/grid_full_preview_wallpaper_surface"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ </androidx.cardview.widget.CardView>
+ </FrameLayout>
+</LinearLayout>
diff --git a/res/layout/fragment_grid_scalable_picker.xml b/res/layout/fragment_grid_scalable_picker.xml
deleted file mode 100644
index 6a3a77a..0000000
--- a/res/layout/fragment_grid_scalable_picker.xml
+++ /dev/null
@@ -1,101 +0,0 @@
-<?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.coordinatorlayout.widget.CoordinatorLayout
- 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:background="?android:colorPrimary"
- android:orientation="vertical">
-
- <include layout="@layout/section_header" />
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:layout_behavior="@string/scalable_container_behavior">
-
- <com.android.wallpaper.widget.PreviewPager
- android:id="@+id/grid_preview_pager"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/preview_pager_background"
- app:card_style="screen_aspect_ratio" />
- </FrameLayout>
-
- <FrameLayout
- android:id="@+id/scalable_content_container"
- android:layout_width="wrap_content"
- android:layout_height="@dimen/content_container_maximum_height"
- app:behavior_peekHeight="@dimen/content_container_minimum_height"
- app:layout_behavior="@string/bottom_sheet_behavior">
-
- <LinearLayout
- android:id="@+id/content_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/options_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:paddingVertical="18dp"
- android:lineHeight="24dp"
- android:singleLine="true"
- android:text="@string/grid_options_title"
- android:textAppearance="@style/TitleTextAppearance"/>
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/options_container"
- android:layout_width="match_parent"
- android:layout_height="@dimen/options_container_height"
- android:layout_gravity="center_horizontal"/>
- </LinearLayout>
- </FrameLayout>
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.core.widget.ContentLoadingProgressBar
- android:id="@+id/loading_indicator"
- style="@android:style/Widget.DeviceDefault.ProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:layout_marginTop="200dp"
- android:indeterminate="true" />
-
- <FrameLayout
- android:id="@+id/error_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone">
-
- <TextView
- android:id="@+id/error_message"
- style="@style/TitleTextAppearance"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:text="@string/something_went_wrong" />
- </FrameLayout>
- </FrameLayout>
-</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/res/layout/fragment_theme_scalable_picker.xml b/res/layout/fragment_theme_scalable_picker.xml
deleted file mode 100644
index ae147c2..0000000
--- a/res/layout/fragment_theme_scalable_picker.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<?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.coordinatorlayout.widget.CoordinatorLayout
- 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:background="?android:colorPrimary"
- android:orientation="vertical">
-
- <include layout="@layout/section_header" />
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:layout_behavior="@string/scalable_container_behavior">
-
- <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" />
- </FrameLayout>
-
- <FrameLayout
- android:id="@+id/scalable_content_container"
- android:layout_width="wrap_content"
- android:layout_height="@dimen/content_container_maximum_height"
- app:behavior_peekHeight="@dimen/content_container_minimum_height"
- app:layout_behavior="@string/bottom_sheet_behavior">
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/content_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/options_container"
- android:layout_width="match_parent"
- android:layout_height="@dimen/options_container_height"
- 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_toTopOf="parent"
- 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>
- </FrameLayout>
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.core.widget.ContentLoadingProgressBar
- android:id="@+id/loading_indicator"
- style="@android:style/Widget.DeviceDefault.ProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:layout_marginTop="200dp"
- android:indeterminate="true" />
-
- <FrameLayout
- android:id="@+id/error_section"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone">
-
- <TextView
- android:id="@+id/error_message"
- style="@style/TitleTextAppearance"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:text="@string/something_went_wrong" />
- </FrameLayout>
- </FrameLayout>
-</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/src/com/android/customization/model/grid/GridOption.java b/src/com/android/customization/model/grid/GridOption.java
index e3b90f4..2f32ce1 100644
--- a/src/com/android/customization/model/grid/GridOption.java
+++ b/src/com/android/customization/model/grid/GridOption.java
@@ -18,6 +18,8 @@
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 @@
/**
* 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 @@
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 @@
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 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);
+ }
}
diff --git a/src/com/android/customization/picker/BasePreviewAdapter.java b/src/com/android/customization/picker/BasePreviewAdapter.java
index dab923a..c3ddc1d 100644
--- a/src/com/android/customization/picker/BasePreviewAdapter.java
+++ b/src/com/android/customization/picker/BasePreviewAdapter.java
@@ -17,6 +17,7 @@
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_RTL;
+import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@@ -29,6 +30,7 @@
import androidx.viewpager.widget.PagerAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
+import com.android.wallpaper.util.SizeCalculator;
import com.android.wallpaper.widget.PreviewPager;
import java.util.ArrayList;
@@ -103,11 +105,24 @@
protected final String title;
protected CardView card;
- protected PreviewPage(String title) {
+ private Activity mActivity;
+
+ protected PreviewPage(String title, Activity activity) {
this.title = title;
+ mActivity = activity;
}
public void setCard(CardView card) {
+ card.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) {
+ card.setRadius(SizeCalculator.getPreviewCornerRadius(
+ mActivity, card.getMeasuredWidth()));
+ card.removeOnLayoutChangeListener(this);
+ }
+ });
this.card = card;
}
diff --git a/src/com/android/customization/picker/CustomizationPickerActivity.java b/src/com/android/customization/picker/CustomizationPickerActivity.java
index f1e9a47..ac456be 100644
--- a/src/com/android/customization/picker/CustomizationPickerActivity.java
+++ b/src/com/android/customization/picker/CustomizationPickerActivity.java
@@ -120,24 +120,25 @@
if (!supportsCustomization()) {
Log.w(TAG, "Themes not supported, reverting to Wallpaper Picker");
skipToWallpaperPicker();
- } else {
- setContentView(R.layout.activity_customization_picker_main);
- setUpBottomNavView();
+ return;
+ }
- FragmentManager fm = getSupportFragmentManager();
- Fragment fragment = fm.findFragmentById(R.id.fragment_container);
+ setContentView(R.layout.activity_customization_picker_main);
+ setUpBottomNavView();
- if (fragment == null) {
- // App launch specific logic: log the "app launched" event and set up daily logging.
- mUserEventLogger.logAppLaunched();
- DailyLoggingAlarmScheduler.setAlarm(getApplicationContext());
+ FragmentManager fm = getSupportFragmentManager();
+ Fragment fragment = fm.findFragmentById(R.id.fragment_container);
- // Navigate to the Wallpaper tab if we started directly from launcher, otherwise
- // start at the Styles tab
- navigateToSection(
- WALLPAPER_FOCUS.equals(getIntent().getStringExtra(WALLPAPER_FLAVOR_EXTRA))
- ? R.id.nav_wallpaper : R.id.nav_theme);
- }
+ if (fragment == null) {
+ // App launch specific logic: log the "app launched" event and set up daily logging.
+ mUserEventLogger.logAppLaunched();
+ DailyLoggingAlarmScheduler.setAlarm(getApplicationContext());
+
+ // Navigate to the Wallpaper tab if we started directly from launcher, otherwise
+ // start at the Styles tab
+ navigateToSection(
+ WALLPAPER_FOCUS.equals(getIntent().getStringExtra(WALLPAPER_FLAVOR_EXTRA))
+ ? R.id.nav_wallpaper : R.id.nav_theme);
}
mBottomActionBar = findViewById(R.id.bottom_actionbar);
diff --git a/src/com/android/customization/picker/ViewOnlyFullPreviewActivity.java b/src/com/android/customization/picker/ViewOnlyFullPreviewActivity.java
new file mode 100644
index 0000000..19324da
--- /dev/null
+++ b/src/com/android/customization/picker/ViewOnlyFullPreviewActivity.java
@@ -0,0 +1,82 @@
+/*
+ * 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();
+ }
+}
diff --git a/src/com/android/customization/picker/clock/ClockFragment.java b/src/com/android/customization/picker/clock/ClockFragment.java
index 47fad5f..bc02ae3 100644
--- a/src/com/android/customization/picker/clock/ClockFragment.java
+++ b/src/com/android/customization/picker/clock/ClockFragment.java
@@ -15,8 +15,7 @@
*/
package com.android.customization.picker.clock;
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
-
+import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
@@ -90,20 +89,8 @@
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
- View view;
- if (ADD_SCALABLE_HEADER) {
- // TODO(b/147780560): Once the temporary flag (ADD_SCALABLE_HEADER) is removed,
- // we should have a layout with the same name for portrait and landscape.
- int orientation = getResources().getConfiguration().orientation;
- view = inflater.inflate(
- orientation == ORIENTATION_LANDSCAPE
- ? R.layout.fragment_clock_picker
- : R.layout.fragment_clock_scalable_picker,
- container, /* attachToRoot */ false);
- } else {
- view = inflater.inflate(
- R.layout.fragment_clock_picker, container, /* attachToRoot */ false);
- }
+ View view = inflater.inflate(
+ R.layout.fragment_clock_picker, container, /* attachToRoot */ false);
setUpToolbar(view);
mContent = view.findViewById(R.id.content_section);
mPreviewPager = view.findViewById(R.id.clock_preview_pager);
@@ -134,7 +121,7 @@
}
private void createAdapter() {
- mPreviewPager.setAdapter(new ClockPreviewAdapter(getContext(), mSelectedOption));
+ mPreviewPager.setAdapter(new ClockPreviewAdapter(getActivity(), mSelectedOption));
}
private void setUpOptions() {
@@ -188,8 +175,8 @@
private final Asset mPreviewAsset;
- public ClockfacePreviewPage(String title, Asset previewAsset) {
- super(title);
+ public ClockfacePreviewPage(String title, Activity activity, Asset previewAsset) {
+ super(title, activity);
mPreviewAsset = previewAsset;
}
@@ -213,9 +200,10 @@
* we don't want to just scroll)
*/
private static class ClockPreviewAdapter extends BasePreviewAdapter<ClockfacePreviewPage> {
- ClockPreviewAdapter(Context context, Clockface clockface) {
- super(context, R.layout.clock_preview_card);
- addPage(new ClockfacePreviewPage(clockface.getTitle(), clockface.getPreviewAsset()));
+ ClockPreviewAdapter(Activity activity, Clockface clockface) {
+ super(activity, R.layout.clock_preview_card);
+ addPage(new ClockfacePreviewPage(
+ clockface.getTitle(), activity , clockface.getPreviewAsset()));
}
}
}
diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java
index 43eb82f..c9af437 100644
--- a/src/com/android/customization/picker/grid/GridFragment.java
+++ b/src/com/android/customization/picker/grid/GridFragment.java
@@ -15,12 +15,17 @@
*/
package com.android.customization.picker.grid;
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.app.Activity.RESULT_OK;
+import static com.android.customization.picker.ViewOnlyFullPreviewActivity.SECTION_GRID;
+import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_GRID_OPTION;
+import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_GRID_USES_SURFACE_VIEW;
+import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_WALLPAPER_INFO;
import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
@@ -30,6 +35,7 @@
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
@@ -51,6 +57,7 @@
import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
+import com.android.customization.picker.ViewOnlyFullPreviewActivity;
import com.android.customization.widget.OptionSelectorController;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
@@ -73,7 +80,9 @@
*/
public class GridFragment extends AppbarFragment {
- private static final int PREVIEW_FADE_DURATION_MS = 100;
+ static final int PREVIEW_FADE_DURATION_MS = 100;
+
+ private static final int FULL_PREVIEW_REQUEST_CODE = 1000;
private static final String TAG = "GridFragment";
@@ -154,20 +163,8 @@
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
- View view;
- if (ADD_SCALABLE_HEADER) {
- // TODO(b/147780560): Once the temporary flag (ADD_SCALABLE_HEADER) is removed,
- // we should have a layout with the same name for portrait and landscape.
- int orientation = getResources().getConfiguration().orientation;
- view = inflater.inflate(
- orientation == ORIENTATION_LANDSCAPE
- ? R.layout.fragment_grid_picker
- : R.layout.fragment_grid_scalable_picker,
- container, /* attachToRoot */ false);
- } else {
- view = inflater.inflate(
- R.layout.fragment_grid_picker, container, /* attachToRoot */ false);
- }
+ View view = inflater.inflate(
+ R.layout.fragment_grid_picker, container, /* attachToRoot */ false);
setUpToolbar(view);
mContent = view.findViewById(R.id.content_section);
mPreviewPager = view.findViewById(R.id.grid_preview_pager);
@@ -205,13 +202,24 @@
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == FULL_PREVIEW_REQUEST_CODE && resultCode == RESULT_OK) {
+ applyGridOption(data.getParcelableExtra(EXTRA_GRID_OPTION));
+ }
+ }
+
+
+ @Override
protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
mBottomActionBar = bottomActionBar;
mBottomActionBar.showActionsOnly(APPLY);
- mBottomActionBar.setActionClickListener(APPLY, unused -> {
- mBottomActionBar.disableActions();
- mGridManager.apply(mSelectedOption, mApplyGridCallback);
- });
+ mBottomActionBar.setActionClickListener(APPLY, unused -> applyGridOption(mSelectedOption));
+ }
+
+ private void applyGridOption(GridOption gridOption) {
+ mBottomActionBar.disableActions();
+ mGridManager.apply(gridOption, mApplyGridCallback);
}
private void loadWallpaperBackground() {
@@ -286,6 +294,15 @@
mError.setVisibility(View.VISIBLE);
}
+ private void showFullPreview() {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(EXTRA_WALLPAPER_INFO, mHomeWallpaper);
+ bundle.putParcelable(EXTRA_GRID_OPTION, mSelectedOption);
+ bundle.putBoolean(EXTRA_GRID_USES_SURFACE_VIEW, mGridManager.usesSurfaceView());
+ Intent intent = ViewOnlyFullPreviewActivity.newIntent(getContext(), SECTION_GRID, bundle);
+ startActivityForResult(intent, FULL_PREVIEW_REQUEST_CODE);
+ }
+
private class GridPreviewPage extends PreviewPage {
private final int mPageId;
private final Asset mPreviewAsset;
@@ -298,9 +315,46 @@
private ImageView mPreview;
private SurfaceView mPreviewSurface;
+ private final SurfaceHolder.Callback mSurfaceCallback = new SurfaceHolder.Callback() {
+
+ private Surface mLastSurface;
+ private Message mCallback;
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mLastSurface != holder.getSurface()) {
+ mLastSurface = holder.getSurface();
+ Bundle result = mGridManager.renderPreview(
+ SurfaceViewUtils.createSurfaceViewRequest(mPreviewSurface), mName);
+ if (result != null) {
+ mPreviewSurface.setChildSurfacePackage(
+ SurfaceViewUtils.getSurfacePackage(result));
+ mCallback = SurfaceViewUtils.getCallback(result);
+ }
+ }
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width,
+ int height) {}
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (mCallback != null) {
+ try {
+ mCallback.replyTo.send(mCallback);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } finally {
+ mCallback = null;
+ }
+ }
+ }
+ };
+
private GridPreviewPage(Activity activity, int id, Uri previewUri, String name, int rows,
int cols) {
- super(null);
+ super(null, activity);
mPageId = id;
mPreviewAsset = new ContentUriAsset(activity, previewUri,
RequestOptions.fitCenterTransform());
@@ -315,6 +369,8 @@
super.setCard(card);
mPreview = card.findViewById(R.id.grid_preview_image);
mPreviewSurface = card.findViewById(R.id.grid_preview_surface);
+ // PreviewSurface is the top of its window(card view), due to #setZOrderOnTop(true).
+ mPreviewSurface.setOnClickListener(view -> showFullPreview());
}
public void bindPreviewContent() {
@@ -325,38 +381,7 @@
mPreviewSurface.setVisibility(usesSurfaceViewForPreview ? View.VISIBLE : View.GONE);
if (usesSurfaceViewForPreview) {
mPreviewSurface.setZOrderOnTop(true);
- mPreviewSurface.getHolder().addCallback(new SurfaceHolder.Callback() {
-
- private Message mCallback;
-
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- Bundle result = mGridManager.renderPreview(
- SurfaceViewUtils.createSurfaceViewRequest(mPreviewSurface), mName);
- if (result != null) {
- mPreviewSurface.setChildSurfacePackage(
- SurfaceViewUtils.getSurfacePackage(result));
- mCallback = SurfaceViewUtils.getCallback(result);
- }
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {}
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- if (mCallback != null) {
- try {
- mCallback.replyTo.send(mCallback);
- } catch (RemoteException e) {
- e.printStackTrace();
- } finally {
- mCallback = null;
- }
- }
- }
- });
+ mPreviewSurface.getHolder().addCallback(mSurfaceCallback);
} else {
mPreviewAsset.loadDrawableWithTransition(mActivity,
mPreview /* imageView */,
diff --git a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java
new file mode 100644
index 0000000..29d74de
--- /dev/null
+++ b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java
@@ -0,0 +1,360 @@
+/*
+ * 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.grid;
+
+import static android.app.Activity.RESULT_OK;
+import static android.view.View.MeasureSpec.EXACTLY;
+import static android.view.View.MeasureSpec.makeMeasureSpec;
+
+import static com.android.customization.picker.grid.GridFragment.PREVIEW_FADE_DURATION_MS;
+import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.os.Bundle;
+import android.os.Message;
+import android.os.RemoteException;
+import android.service.wallpaper.WallpaperService;
+import android.util.DisplayMetrics;
+import android.view.LayoutInflater;
+import android.view.Surface;
+import android.view.SurfaceControlViewHost;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.cardview.widget.CardView;
+import androidx.core.content.ContextCompat;
+
+import com.android.customization.model.grid.GridOption;
+import com.android.customization.model.grid.GridOptionsManager;
+import com.android.customization.model.grid.LauncherGridOptionsProvider;
+import com.android.customization.module.CustomizationInjector;
+import com.android.customization.module.ThemesUserEventLogger;
+import com.android.wallpaper.R;
+import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.asset.ContentUriAsset;
+import com.android.wallpaper.model.LiveWallpaperInfo;
+import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.module.InjectorProvider;
+import com.android.wallpaper.picker.AppbarFragment;
+import com.android.wallpaper.util.SizeCalculator;
+import com.android.wallpaper.util.SurfaceViewUtils;
+import com.android.wallpaper.util.WallpaperConnection;
+import com.android.wallpaper.widget.BottomActionBar;
+import com.android.wallpaper.widget.LiveTileOverlay;
+
+import com.bumptech.glide.request.RequestOptions;
+
+/** A Fragment for grid full preview page. */
+public class GridFullPreviewFragment extends AppbarFragment {
+
+ static final String EXTRA_WALLPAPER_INFO = "wallpaper_info";
+ static final String EXTRA_GRID_OPTION = "grid_option";
+ static final String EXTRA_GRID_USES_SURFACE_VIEW = "uses_surface_view";
+
+ private final Rect mPreviewLocalRect = new Rect();
+ private final Rect mPreviewGlobalRect = new Rect();
+ private final int[] mLivePreviewLocation = new int[2];
+
+ private GridOptionsManager mGridManager;
+ private WallpaperInfo mWallpaper;
+ private GridOption mGridOption;
+ private boolean mUsesSurfaceView;
+
+ private CardView mCardView;
+ private ImageView mHomePreview;
+ private SurfaceView mGridOptionSurface;
+ private SurfaceView mWallpaperSurface;
+ private WallpaperConnection mWallpaperConnection;
+
+ // Home workspace surface is behind the app window, and so must the home image wallpaper like
+ // the live wallpaper. This view is rendered on mWallpaperSurface for home image wallpaper.
+ private ImageView mHomeImageWallpaper;
+
+ /**
+ * Returns a new {@link GridFullPreviewFragment} with the provided title and bundle arguments
+ * set.
+ */
+ public static GridFullPreviewFragment newInstance(CharSequence title, Bundle intentBundle) {
+ GridFullPreviewFragment fragment = new GridFullPreviewFragment();
+ Bundle bundle = new Bundle();
+ bundle.putAll(AppbarFragment.createArguments(title));
+ bundle.putAll(intentBundle);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mWallpaper = getArguments().getParcelable(EXTRA_WALLPAPER_INFO);
+ mGridOption = getArguments().getParcelable(EXTRA_GRID_OPTION);
+ mUsesSurfaceView = getArguments().getBoolean(EXTRA_GRID_USES_SURFACE_VIEW);
+
+ CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector();
+ ThemesUserEventLogger eventLogger = (ThemesUserEventLogger) injector.getUserEventLogger(
+ getContext());
+
+ mGridManager = new GridOptionsManager(new LauncherGridOptionsProvider(getContext(),
+ getString(R.string.grid_control_metadata_name)),
+ eventLogger);
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(
+ R.layout.fragment_grid_full_preview, container, /* attachToRoot */ false);
+ setUpToolbar(view);
+
+ mCardView = view.findViewById(R.id.grid_full_preview_card);
+ mHomePreview = view.findViewById(R.id.grid_full_preview_image);
+ mGridOptionSurface = view.findViewById(R.id.grid_full_preview_option_surface);
+ mWallpaperSurface = view.findViewById(R.id.grid_full_preview_wallpaper_surface);
+ mGridOptionSurface.setVisibility(View.GONE);
+
+ final DisplayMetrics dm = getResources().getDisplayMetrics();
+ float screenAspectRatio = (float) dm.heightPixels / dm.widthPixels;
+
+ 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) {
+ int cardWidth = (int) (mCardView.getMeasuredHeight() / screenAspectRatio);
+ ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams();
+ layoutParams.width = cardWidth;
+ mCardView.setLayoutParams(layoutParams);
+ mCardView.setRadius(SizeCalculator.getPreviewCornerRadius(
+ getActivity(), mCardView.getMeasuredWidth()));
+ view.removeOnLayoutChangeListener(this);
+ }
+ });
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ updateWallpaperSurface();
+ updateWorkspaceSurface();
+ }
+
+ @Override
+ protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
+ bottomActionBar.bindBackButtonToSystemBackKey(getActivity());
+ bottomActionBar.showActionsOnly(APPLY);
+ bottomActionBar.setActionClickListener(APPLY, v -> finishActivityWithResultOk());
+ bottomActionBar.show();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.setVisibility(true);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.setVisibility(false);
+ }
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ LiveTileOverlay.INSTANCE.detach(mHomePreview.getOverlay());
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.disconnect();
+ mWallpaperConnection = null;
+ }
+ }
+
+ private void finishActivityWithResultOk() {
+ Activity activity = requireActivity();
+ activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
+ Intent intent = new Intent();
+ intent.putExtra(EXTRA_GRID_OPTION, mGridOption);
+ activity.setResult(RESULT_OK, intent);
+ activity.finish();
+ }
+
+ private void updateWallpaperSurface() {
+ mWallpaperSurface.setZOrderMediaOverlay(false);
+ mWallpaperSurface.getHolder().addCallback(mWallpaperSurfaceCallback);
+ }
+
+ private void updateWorkspaceSurface() {
+ if (mUsesSurfaceView) {
+ mGridOptionSurface.setZOrderOnTop(true);
+ mGridOptionSurface.getHolder().addCallback(mGridOptionSurfaceCallback);
+ mGridOptionSurface.setVisibility(View.VISIBLE);
+ } else {
+ final Asset previewAsset = new ContentUriAsset(
+ getContext(),
+ mGridOption.previewImageUri,
+ RequestOptions.fitCenterTransform());
+ previewAsset.loadDrawableWithTransition(getContext(),
+ mHomePreview /* imageView */,
+ PREVIEW_FADE_DURATION_MS /* duration */,
+ null /* drawableLoadedListener */,
+ getResources().getColor(android.R.color.transparent,
+ null) /* placeHolderColorJ */);
+ }
+ }
+
+ private void setUpWallpaperPreview() {
+ if (mWallpaper != null && mHomeImageWallpaper != null) {
+ boolean renderInImageWallpaperSurface = !(mWallpaper instanceof LiveWallpaperInfo);
+ mWallpaper.getThumbAsset(getContext())
+ .loadPreviewImage(getActivity(),
+ renderInImageWallpaperSurface ? mHomeImageWallpaper : mHomePreview,
+ getResources().getColor(R.color.secondary_color));
+ LiveTileOverlay.INSTANCE.detach(mHomePreview.getOverlay());
+ if (mWallpaper instanceof LiveWallpaperInfo) {
+ mWallpaper.getThumbAsset(getContext().getApplicationContext())
+ .loadPreviewImage(
+ getActivity(),
+ mHomeImageWallpaper,
+ getContext().getColor(R.color.secondary_color));
+ setUpLiveWallpaperPreview(mWallpaper);
+ } else {
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.disconnect();
+ mWallpaperConnection = null;
+ }
+ }
+ }
+ }
+
+ private void setUpLiveWallpaperPreview(WallpaperInfo homeWallpaper) {
+ Activity activity = getActivity();
+ if (activity == null) {
+ return;
+ }
+
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.disconnect();
+ }
+
+ mHomePreview.getLocationOnScreen(mLivePreviewLocation);
+ mPreviewGlobalRect.set(0, 0, mHomePreview.getMeasuredWidth(),
+ mHomePreview.getMeasuredHeight());
+ mPreviewLocalRect.set(mPreviewGlobalRect);
+ mPreviewGlobalRect.offset(mLivePreviewLocation[0], mLivePreviewLocation[1]);
+
+ mWallpaperConnection = new WallpaperConnection(
+ getWallpaperIntent(homeWallpaper.getWallpaperComponent()), activity,
+ new WallpaperConnection.WallpaperConnectionListener() {
+ @Override
+ public void onEngineShown() {}
+ }, mPreviewGlobalRect);
+
+ LiveTileOverlay.INSTANCE.update(new RectF(mPreviewLocalRect), mCardView.getRadius());
+
+ mWallpaperConnection.setVisibility(true);
+ mHomePreview.post(() -> {
+ if (!mWallpaperConnection.connect()) {
+ mWallpaperConnection = null;
+ LiveTileOverlay.INSTANCE.detach(mHomePreview.getOverlay());
+ }
+ });
+ }
+
+ private Intent getWallpaperIntent(android.app.WallpaperInfo info) {
+ return new Intent(WallpaperService.SERVICE_INTERFACE)
+ .setClassName(info.getPackageName(), info.getServiceName());
+ }
+
+ private final SurfaceHolder.Callback mGridOptionSurfaceCallback = new SurfaceHolder.Callback() {
+
+ private Surface mLastSurface;
+ private Message mCallback;
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mLastSurface != holder.getSurface()) {
+ mLastSurface = holder.getSurface();
+ Bundle result = mGridManager.renderPreview(
+ SurfaceViewUtils.createSurfaceViewRequest(mGridOptionSurface),
+ mGridOption.name);
+ if (result != null) {
+ mGridOptionSurface.setChildSurfacePackage(
+ SurfaceViewUtils.getSurfacePackage(result));
+ mCallback = SurfaceViewUtils.getCallback(result);
+ }
+ }
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (mCallback != null) {
+ try {
+ mCallback.replyTo.send(mCallback);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } finally {
+ mCallback = null;
+ }
+ }
+ }
+ };
+
+ private final SurfaceHolder.Callback mWallpaperSurfaceCallback = new SurfaceHolder.Callback() {
+
+ private Surface mLastSurface;
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mLastSurface != holder.getSurface()) {
+ mLastSurface = holder.getSurface();
+ mHomeImageWallpaper = new ImageView(getContext());
+ mHomeImageWallpaper.setBackgroundColor(
+ ContextCompat.getColor(getContext(), R.color.primary_color));
+ mHomeImageWallpaper.measure(makeMeasureSpec(mHomePreview.getWidth(), EXACTLY),
+ makeMeasureSpec(mHomePreview.getHeight(), EXACTLY));
+ mHomeImageWallpaper.layout(0, 0, mHomePreview.getWidth(), mHomePreview.getHeight());
+
+ SurfaceControlViewHost host = new SurfaceControlViewHost(getContext(),
+ getContext().getDisplay(), mWallpaperSurface.getHostToken());
+ host.setView(mHomeImageWallpaper, mHomeImageWallpaper.getWidth(),
+ mHomeImageWallpaper.getHeight());
+ mWallpaperSurface.setChildSurfacePackage(host.getSurfacePackage());
+ }
+ setUpWallpaperPreview();
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {}
+ };
+}
diff --git a/src/com/android/customization/picker/theme/CustomThemeNameFragment.java b/src/com/android/customization/picker/theme/CustomThemeNameFragment.java
index ed59eb1..45e4324 100644
--- a/src/com/android/customization/picker/theme/CustomThemeNameFragment.java
+++ b/src/com/android/customization/picker/theme/CustomThemeNameFragment.java
@@ -131,7 +131,7 @@
private void bindCover(CardView card) {
Context context = getContext();
PreviewInfo previewInfo = mCustomThemeManager.buildCustomThemePreviewInfo(context);
- mCoverPage = new ThemeCoverPage(context, getThemeName(),
+ mCoverPage = new ThemeCoverPage(getActivity(), getThemeName(),
previewInfo.resolveAccentColor(getResources()), previewInfo.icons,
previewInfo.headlineFontFamily, previewInfo.bottomSheeetCornerRadius,
previewInfo.shapeDrawable, previewInfo.shapeAppIcons, null,
diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java
index b56c402..e04d8d2 100644
--- a/src/com/android/customization/picker/theme/ThemeFragment.java
+++ b/src/com/android/customization/picker/theme/ThemeFragment.java
@@ -15,8 +15,6 @@
*/
package com.android.customization.picker.theme;
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
-
import android.app.Activity;
import android.app.WallpaperColors;
import android.content.Context;
@@ -119,20 +117,8 @@
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
- View view;
- if (ADD_SCALABLE_HEADER) {
- // TODO(b/147780560): Once the temporary flag (ADD_SCALABLE_HEADER) is removed,
- // we should have a layout with the same name for portrait and landscape.
- int orientation = getResources().getConfiguration().orientation;
- view = inflater.inflate(
- orientation == ORIENTATION_LANDSCAPE
- ? R.layout.fragment_theme_picker
- : R.layout.fragment_theme_scalable_picker,
- container, /* attachToRoot */ false);
- } else {
- view = inflater.inflate(
- R.layout.fragment_theme_picker, container, /* attachToRoot */ false);
- }
+ View view = inflater.inflate(
+ R.layout.fragment_theme_picker, container, /* attachToRoot */ false);
setUpToolbar(view);
mContent = view.findViewById(R.id.content_section);
diff --git a/src/com/android/customization/picker/theme/ThemePreviewPage.java b/src/com/android/customization/picker/theme/ThemePreviewPage.java
index cbcbc78..b8152d9 100644
--- a/src/com/android/customization/picker/theme/ThemePreviewPage.java
+++ b/src/com/android/customization/picker/theme/ThemePreviewPage.java
@@ -1,6 +1,6 @@
package com.android.customization.picker.theme;
-import android.content.Context;
+import android.app.Activity;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Typeface;
@@ -45,21 +45,20 @@
final int accentColor;
protected final LayoutInflater inflater;
- public ThemePreviewPage(Context context, @StringRes int titleResId,
- @DrawableRes int iconSrc, @LayoutRes int contentLayoutRes,
- @ColorInt int accentColor) {
- super(null);
+ public ThemePreviewPage(Activity activity, @StringRes int titleResId,
+ @DrawableRes int iconSrc, @LayoutRes int contentLayoutRes, @ColorInt int accentColor) {
+ super(null, activity);
this.nameResId = titleResId;
if (iconSrc != Resources.ID_NULL) {
- this.icon = context.getResources().getDrawable(iconSrc, context.getTheme());
- int size = context.getResources().getDimensionPixelSize(R.dimen.card_header_icon_size);
+ this.icon = activity.getResources().getDrawable(iconSrc, activity.getTheme());
+ int size = activity.getResources().getDimensionPixelSize(R.dimen.card_header_icon_size);
icon.setBounds(0, 0, size, size);
} else {
this.icon = null;
}
this.contentLayoutRes = contentLayoutRes;
this.accentColor = accentColor;
- this.inflater = LayoutInflater.from(context);
+ this.inflater = LayoutInflater.from(activity);
}
@Override
@@ -106,15 +105,17 @@
private final int mCornerRadius;
private final ColorStateList mTintList;
- public ThemeCoverPage(Context context, String title, int accentColor, List<Drawable> icons,
+ public ThemeCoverPage(Activity activity, String title, int accentColor,
+ List<Drawable> icons,
Typeface headlineFont, int cornerRadius,
Drawable shapeDrawable,
List<Drawable> shapeAppIcons,
OnClickListener editClickListener,
int[] colorButtonIds, int[] colorTileIds, int[][] colorTileIconIds,
int[] shapeIconIds, OnLayoutChangeListener... wallpaperListeners) {
- super(context, 0, 0, R.layout.preview_card_cover_content, accentColor);
- mRes = context.getResources();
+ super(activity, 0, 0, R.layout.preview_card_cover_content,
+ accentColor);
+ mRes = activity.getResources();
mTitle = title;
mHeadlineFont = headlineFont;
mIcons = icons;