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

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