Merge "Move Dream OOBE activity to SettingsGoogle"
This commit is contained in:
@@ -2942,24 +2942,6 @@
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name=".dream.DreamSetupActivity"
|
||||
android:exported="true"
|
||||
android:immersive="true"
|
||||
android:theme="@style/SudThemeGlif.DayNight"
|
||||
android:icon="@drawable/ic_settings_display">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="com.android.settings.suggested.category.SCREEN_SAVER"/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.is_supported"
|
||||
android:resource="@bool/dream_setup_supported"/>
|
||||
<meta-data android:name="com.android.settings.title"
|
||||
android:resource="@string/dream_setup_title"/>
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/dream_setup_description"/>
|
||||
<meta-data android:name="com.android.settings.icon_tintable" android:value="true"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="Settings$UserSettingsActivity"
|
||||
android:label="@string/user_settings_title"
|
||||
|
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.setupdesign.GlifLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/setup_wizard_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:icon="@drawable/ic_settings_display"
|
||||
app:sucHeaderText="@string/dream_setup_title"
|
||||
app:sudDescriptionText="@string/dream_setup_description">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/dream_container"
|
||||
style="@style/SudContentFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/dream_setup_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</com.google.android.setupdesign.GlifLayout>
|
@@ -24,10 +24,10 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
|
||||
/** Grid layout manager that calculates the number of columns for the screen size. */
|
||||
final class AutoFitGridLayoutManager extends GridLayoutManager {
|
||||
public final class AutoFitGridLayoutManager extends GridLayoutManager {
|
||||
private final float mColumnWidth;
|
||||
|
||||
AutoFitGridLayoutManager(Context context) {
|
||||
public AutoFitGridLayoutManager(Context context) {
|
||||
super(context, /* spanCount= */ 1);
|
||||
this.mColumnWidth = context
|
||||
.getResources()
|
||||
|
@@ -37,7 +37,7 @@ import java.util.List;
|
||||
/**
|
||||
* RecyclerView adapter which displays list of items for the user to select.
|
||||
*/
|
||||
class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private final List<IDreamItem> mItemList;
|
||||
private int mLastSelectedPos = -1;
|
||||
|
||||
@@ -103,7 +103,7 @@ class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
DreamAdapter(List<IDreamItem> itemList) {
|
||||
public DreamAdapter(List<IDreamItem> itemList) {
|
||||
mItemList = itemList;
|
||||
}
|
||||
|
||||
|
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupcompat.template.FooterButton;
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
import com.google.android.setupdesign.GlifLayout;
|
||||
import com.google.android.setupdesign.util.ThemeHelper;
|
||||
import com.google.android.setupdesign.util.ThemeResolver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The setup activity for dreams which is displayed during setup wizard.
|
||||
*/
|
||||
public class DreamSetupActivity extends SettingsActivity {
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
Intent modIntent = new Intent(super.getIntent());
|
||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DreamSetupFragment.class.getName());
|
||||
return modIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return DreamSetupFragment.class.getName().equals(fragmentName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstance) {
|
||||
setTheme(ThemeResolver.getDefault().resolve(getIntent()));
|
||||
ThemeHelper.trySetDynamicColor(this);
|
||||
super.onCreate(savedInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isToolbarEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment used to control the active dream.
|
||||
*/
|
||||
public static class DreamSetupFragment extends SettingsPreferenceFragment {
|
||||
private DreamBackend mBackend;
|
||||
private DreamBackend.DreamInfo mActiveDream;
|
||||
private FooterButton mFooterButton;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.dream_setup_layout, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mBackend = DreamBackend.getInstance(getContext());
|
||||
final List<DreamBackend.DreamInfo> dreamInfos = mBackend.getDreamInfos();
|
||||
mActiveDream = dreamInfos.stream().filter(d -> d.isActive).findFirst().orElse(null);
|
||||
DreamAdapter dreamAdapter = new DreamAdapter(dreamInfos.stream()
|
||||
.map(DreamItem::new)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
final RecyclerView recyclerView = view.findViewById(R.id.dream_setup_list);
|
||||
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(getContext()));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setAdapter(dreamAdapter);
|
||||
|
||||
final GlifLayout layout = view.findViewById(R.id.setup_wizard_layout);
|
||||
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
|
||||
mFooterButton = new FooterButton.Builder(getContext())
|
||||
.setListener(this::onPrimaryButtonClicked)
|
||||
.setButtonType(FooterButton.ButtonType.NEXT)
|
||||
.setTheme(R.style.SudGlifButton_Primary)
|
||||
.build();
|
||||
updateFooterButtonText();
|
||||
mixin.setPrimaryButton(mFooterButton);
|
||||
}
|
||||
|
||||
private void updateFooterButtonText() {
|
||||
final int res = canCustomizeDream() ? R.string.wizard_next : R.string.wizard_finish;
|
||||
mFooterButton.setText(getContext().getString(res));
|
||||
}
|
||||
|
||||
private boolean canCustomizeDream() {
|
||||
return mActiveDream != null && mActiveDream.settingsComponentName != null;
|
||||
}
|
||||
|
||||
private void onPrimaryButtonClicked(View view) {
|
||||
if (canCustomizeDream()) {
|
||||
final Intent intent = new Intent().setComponent(mActiveDream.settingsComponentName);
|
||||
WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
// Use RESULT_CANCELED here so that the user may go back and change this if they wish.
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
private class DreamItem implements IDreamItem {
|
||||
private final DreamBackend.DreamInfo mDreamInfo;
|
||||
|
||||
private DreamItem(DreamBackend.DreamInfo dreamInfo) {
|
||||
mDreamInfo = dreamInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mDreamInfo.caption;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mDreamInfo.icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked() {
|
||||
mActiveDream = mDreamInfo;
|
||||
mBackend.setActiveDream(mDreamInfo.componentName);
|
||||
updateFooterButtonText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getPreviewImage() {
|
||||
return mDreamInfo.previewImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
if (mActiveDream == null) {
|
||||
return false;
|
||||
}
|
||||
return mDreamInfo.componentName.equals(mActiveDream.componentName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,7 +18,10 @@ package com.android.settings.dream;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
interface IDreamItem {
|
||||
/**
|
||||
* Interface representing a dream item to be displayed.
|
||||
*/
|
||||
public interface IDreamItem {
|
||||
CharSequence getTitle();
|
||||
|
||||
Drawable getIcon();
|
||||
|
Reference in New Issue
Block a user