Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cce99074 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge "Move Dream OOBE activity to SettingsGoogle"

parents 9377681a 3eb4cb41
Loading
Loading
Loading
Loading
+0 −18
Original line number Original line Diff line number Diff line
@@ -2942,24 +2942,6 @@
                android:value="true" />
                android:value="true" />
        </activity>
        </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
        <activity
            android:name="Settings$UserSettingsActivity"
            android:name="Settings$UserSettingsActivity"
            android:label="@string/user_settings_title"
            android:label="@string/user_settings_title"

res/layout/dream_setup_layout.xml

deleted100644 → 0
+0 −39
Original line number Original line Diff line number Diff line
<?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>
 No newline at end of file
+2 −2
Original line number Original line Diff line number Diff line
@@ -24,10 +24,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.R;


/** Grid layout manager that calculates the number of columns for the screen size. */
/** 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;
    private final float mColumnWidth;


    AutoFitGridLayoutManager(Context context) {
    public AutoFitGridLayoutManager(Context context) {
        super(context, /* spanCount= */ 1);
        super(context, /* spanCount= */ 1);
        this.mColumnWidth = context
        this.mColumnWidth = context
                .getResources()
                .getResources()
+2 −2
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@ import java.util.List;
/**
/**
 * RecyclerView adapter which displays list of items for the user to select.
 * 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 final List<IDreamItem> mItemList;
    private int mLastSelectedPos = -1;
    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;
        mItemList = itemList;
    }
    }


+0 −177
Original line number Original line Diff line number Diff line
/*
 * 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);
            }
        }
    }
}
Loading