Implement floating dream preview button.

Bug: 217556080
Test: locally on device
Change-Id: If76dce6a250fc5fc37d26fc3d7a31775333055d7
This commit is contained in:
Lucas Silva
2022-02-08 20:50:00 +00:00
parent a03b66952e
commit 12945af711
6 changed files with 81 additions and 44 deletions

View File

@@ -0,0 +1,24 @@
<!--
~ Copyright (C) 2022 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="@android:color/white"
android:pathData="M12,16Q13.875,16 15.188,14.688Q16.5,13.375 16.5,11.5Q16.5,9.625 15.188,8.312Q13.875,7 12,7Q10.125,7 8.812,8.312Q7.5,9.625 7.5,11.5Q7.5,13.375 8.812,14.688Q10.125,16 12,16ZM12,14.2Q10.875,14.2 10.088,13.412Q9.3,12.625 9.3,11.5Q9.3,10.375 10.088,9.587Q10.875,8.8 12,8.8Q13.125,8.8 13.913,9.587Q14.7,10.375 14.7,11.5Q14.7,12.625 13.913,13.412Q13.125,14.2 12,14.2ZM12,19Q8.35,19 5.35,16.962Q2.35,14.925 1,11.5Q2.35,8.075 5.35,6.037Q8.35,4 12,4Q15.65,4 18.65,6.037Q21.65,8.075 23,11.5Q21.65,14.925 18.65,16.962Q15.65,19 12,19ZM12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5ZM12,17Q14.825,17 17.188,15.512Q19.55,14.025 20.8,11.5Q19.55,8.975 17.188,7.487Q14.825,6 12,6Q9.175,6 6.812,7.487Q4.45,8.975 3.2,11.5Q4.45,14.025 6.812,15.512Q9.175,17 12,17Z"/>
</vector>

View File

@@ -40,17 +40,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<Button
android:id="@+id/preview_button"
style="@style/ActionPrimaryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="@string/dream_preview_button_title"
app:layout_constraintTop_toBottomOf="@+id/dream_list"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

View File

@@ -0,0 +1,33 @@
<!--
~ Copyright (C) 2022 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.
-->
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dream_preview_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dream_preview_button_title"
android:textAllCaps="false"
android:textColor="?androidprv:attr/textColorOnAccent"
android:theme="@style/Theme.CollapsingToolbar.Settings"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|center"
app:backgroundTint="?androidprv:attr/colorAccentPrimaryVariant"
app:iconTint="?androidprv:attr/textColorOnAccent"
app:icon="@drawable/dream_preview_icon"/>

View File

@@ -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<DreamInfo> 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,

View File

@@ -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) {

View File

@@ -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);
}
}