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

Commit cf3af285 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a controller and renderer for Slices."

parents aaa79085 0757e492
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2018 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.
-->

<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/homepage_card_top_margin"
    android:layout_marginBottom="@dimen/homepage_card_bottom_margin"
    android:layout_marginStart="@dimen/homepage_card_side_margin"
    android:layout_marginEnd="@dimen/homepage_card_side_margin"
    app:cardCornerRadius="@dimen/homepage_card_corner_radius"
    app:cardElevation="@dimen/homepage_card_elevation">

    <androidx.slice.widget.SliceView
        android:id="@+id/slice_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="@dimen/homepage_card_padding_start"
        android:paddingEnd="@dimen/homepage_card_padding_end"
        android:paddingTop="@dimen/homepage_card_padding_top"
        android:paddingBottom="@dimen/homepage_card_padding_bottom"/>

</androidx.cardview.widget.CardView>
+11 −0
Original line number Diff line number Diff line
@@ -340,4 +340,15 @@
    <dimen name="homepage_bottombar_top_margin">34dp</dimen>
    <dimen name="homepage_bottombar_fab_cradle">68dp</dimen>

    <!-- Homepage cards size and padding -->
    <dimen name="homepage_card_corner_radius">8dp</dimen>
    <dimen name="homepage_card_elevation">2dp</dimen>
    <dimen name="homepage_card_top_margin">6dp</dimen>
    <dimen name="homepage_card_bottom_margin">6dp</dimen>
    <dimen name="homepage_card_side_margin">16dp</dimen>
    <dimen name="homepage_card_padding_start">16dp</dimen>
    <dimen name="homepage_card_padding_end">16dp</dimen>
    <dimen name="homepage_card_padding_top">6dp</dimen>
    <dimen name="homepage_card_padding_bottom">6dp</dimen>

</resources>
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.settings.homepage;
import com.android.settings.homepage.ContextualCard.CardType;
import com.android.settings.homepage.conditional.ConditionContextualCardController;
import com.android.settings.homepage.conditional.ConditionContextualCardRenderer;
import com.android.settings.homepage.slices.SliceContextualCardController;
import com.android.settings.homepage.slices.SliceContextualCardRenderer;

import java.util.Set;
import java.util.TreeSet;
@@ -50,6 +52,9 @@ public class ContextualCardLookupTable {
                add(new ControllerRendererMapping(CardType.CONDITIONAL,
                        ConditionContextualCardController.class,
                        ConditionContextualCardRenderer.class));
                add(new ControllerRendererMapping(CardType.SLICE,
                        SliceContextualCardController.class,
                        SliceContextualCardRenderer.class));
            }};

    public static Class<? extends ContextualCardController> getCardControllerClass(
+7 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.lifecycle.LifecycleOwner;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

@@ -39,11 +40,14 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
    private final Context mContext;
    private final ControllerRendererPool mControllerRendererPool;
    private final List<ContextualCard> mContextualCards;
    private final LifecycleOwner mLifecycleOwner;

    public ContextualCardsAdapter(Context context, ContextualCardManager manager) {
    public ContextualCardsAdapter(Context context, LifecycleOwner lifecycleOwner,
            ContextualCardManager manager) {
        mContext = context;
        mContextualCards = new ArrayList<>();
        mControllerRendererPool = manager.getControllerRendererPool();
        mLifecycleOwner = lifecycleOwner;
        setHasStableIds(true);
    }

@@ -60,7 +64,7 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int cardType) {
        final ContextualCardRenderer renderer = mControllerRendererPool.getRenderer(mContext,
                cardType);
                mLifecycleOwner, cardType);
        final int viewType = renderer.getViewType();
        final View view = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);

@@ -71,7 +75,7 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final int cardType = mContextualCards.get(position).getCardType();
        final ContextualCardRenderer renderer = mControllerRendererPool.getRenderer(mContext,
                cardType);
                mLifecycleOwner, cardType);

        renderer.bindView(holder, mContextualCards.get(position));
    }
+12 −4
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ import android.content.Context;
import android.util.Log;

import androidx.collection.ArraySet;
import androidx.lifecycle.LifecycleOwner;

import com.android.settings.homepage.conditional.ConditionContextualCardController;
import com.android.settings.homepage.conditional.ConditionContextualCardRenderer;
import com.android.settings.homepage.slices.SliceContextualCardController;
import com.android.settings.homepage.slices.SliceContextualCardRenderer;

import java.util.Set;

@@ -64,7 +67,8 @@ public class ControllerRendererPool {
        return mControllers;
    }

    public ContextualCardRenderer getRenderer(Context context, @ContextualCard.CardType int cardType) {
    public ContextualCardRenderer getRenderer(Context context, LifecycleOwner lifecycleOwner,
            @ContextualCard.CardType int cardType) {
        final Class<? extends ContextualCardRenderer> clz =
                ContextualCardLookupTable.getCardRendererClasses(cardType);
        for (ContextualCardRenderer renderer : mRenderers) {
@@ -74,7 +78,7 @@ public class ControllerRendererPool {
            }
        }

        final ContextualCardRenderer renderer = createCardRenderer(context, clz);
        final ContextualCardRenderer renderer = createCardRenderer(context, lifecycleOwner, clz);
        if (renderer != null) {
            mRenderers.add(renderer);
        }
@@ -85,15 +89,19 @@ public class ControllerRendererPool {
            Class<? extends ContextualCardController> clz) {
        if (ConditionContextualCardController.class == clz) {
            return new ConditionContextualCardController(context);
        } else if (SliceContextualCardController.class == clz) {
            return new SliceContextualCardController();
        }
        return null;
    }

    private ContextualCardRenderer createCardRenderer(Context context, Class<?> clz) {
    private ContextualCardRenderer createCardRenderer(Context context,
            LifecycleOwner lifecycleOwner, Class<?> clz) {
        if (ConditionContextualCardRenderer.class == clz) {
            return new ConditionContextualCardRenderer(context, this /*controllerRendererPool*/);
        } else if (SliceContextualCardRenderer.class == clz) {
            return new SliceContextualCardRenderer(context, lifecycleOwner);
        }
        return null;
    }

}
Loading