diff --git a/res/drawable/dream_preview_icon.xml b/res/drawable/dream_preview_icon.xml
new file mode 100644
index 00000000000..c4bd73936a1
--- /dev/null
+++ b/res/drawable/dream_preview_icon.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/dream_picker_layout.xml b/res/layout/dream_picker_layout.xml
index 6530ea20bbf..6de7ff6fec9 100644
--- a/res/layout/dream_picker_layout.xml
+++ b/res/layout/dream_picker_layout.xml
@@ -40,17 +40,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
-
-
diff --git a/res/layout/dream_preview_button.xml b/res/layout/dream_preview_button.xml
new file mode 100644
index 00000000000..b34786312f3
--- /dev/null
+++ b/res/layout/dream_preview_button.xml
@@ -0,0 +1,33 @@
+
+
+
+
diff --git a/src/com/android/settings/dream/DreamPickerController.java b/src/com/android/settings/dream/DreamPickerController.java
index e4081ac6647..6d5463c1d6c 100644
--- a/src/com/android/settings/dream/DreamPickerController.java
+++ b/src/com/android/settings/dream/DreamPickerController.java
@@ -19,8 +19,6 @@ package com.android.settings.dream;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.graphics.drawable.Drawable;
-import android.view.View;
-import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
@@ -46,7 +44,6 @@ public class DreamPickerController extends BasePreferenceController {
private final DreamBackend mBackend;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final List mDreamInfos;
- private Button mPreviewButton;
@Nullable
private DreamInfo mActiveDream;
private DreamAdapter mAdapter;
@@ -86,17 +83,6 @@ public class DreamPickerController extends BasePreferenceController {
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(mAdapter);
-
- mPreviewButton = ((LayoutPreference) preference).findViewById(R.id.preview_button);
- mPreviewButton.setVisibility(View.VISIBLE);
- mPreviewButton.setOnClickListener(v -> mBackend.preview(mActiveDream));
- updatePreviewButtonState();
- }
-
- private void updatePreviewButtonState() {
- final boolean hasDream = mActiveDream != null;
- mPreviewButton.setClickable(hasDream);
- mPreviewButton.setEnabled(hasDream);
}
@Nullable
@@ -129,7 +115,6 @@ public class DreamPickerController extends BasePreferenceController {
public void onItemClicked() {
mActiveDream = mDreamInfo;
mBackend.setActiveDream(mDreamInfo.componentName);
- updatePreviewButtonState();
mMetricsFeatureProvider.action(
mContext,
SettingsEnums.ACTION_DREAM_SELECT_TYPE,
diff --git a/src/com/android/settings/dream/DreamSettings.java b/src/com/android/settings/dream/DreamSettings.java
index 7ae364e50ab..2acce07828e 100644
--- a/src/com/android/settings/dream/DreamSettings.java
+++ b/src/com/android/settings/dream/DreamSettings.java
@@ -23,8 +23,13 @@ import static com.android.settingslib.dream.DreamBackend.WHILE_DOCKED;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.widget.Button;
import androidx.annotation.VisibleForTesting;
+import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -144,6 +149,25 @@ public class DreamSettings extends DashboardFragment {
return controllers;
}
+ @Override
+ public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
+ Bundle bundle) {
+
+ final ViewGroup root = getActivity().findViewById(android.R.id.content);
+ final Button previewButton = (Button) getActivity().getLayoutInflater().inflate(
+ R.layout.dream_preview_button, root, false);
+ root.addView(previewButton);
+
+ final DreamBackend dreamBackend = DreamBackend.getInstance(getContext());
+ previewButton.setOnClickListener(v -> dreamBackend.preview(dreamBackend.getActiveDream()));
+
+ final RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, bundle);
+ previewButton.post(() -> {
+ recyclerView.setPadding(0, 0, 0, previewButton.getMeasuredHeight());
+ });
+ return recyclerView;
+ }
+
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER
= new BaseSearchIndexProvider(R.xml.dream_fragment_overview) {
diff --git a/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java b/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
index 043fc55a6c0..401ffe0700f 100644
--- a/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
@@ -19,12 +19,9 @@ package com.android.settings.dream;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.content.ComponentName;
import android.content.Context;
-import android.widget.Button;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
@@ -93,19 +90,4 @@ public class DreamPickerControllerTest {
RecyclerView view = mPreference.findViewById(R.id.dream_list);
assertThat(view.getAdapter().getItemCount()).isEqualTo(1);
}
-
- @Test
- public void testPreviewButton() {
- final DreamInfo mockDreamInfo = new DreamInfo();
- mockDreamInfo.componentName = new ComponentName("package", "class");
- mockDreamInfo.isActive = true;
-
- when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mockDreamInfo));
- final DreamPickerController controller = buildController();
- controller.updateState(mPreference);
-
- Button view = mPreference.findViewById(R.id.preview_button);
- view.performClick();
- verify(mBackend).preview(mockDreamInfo);
- }
}