Implement the renderers for conditional header and footer
Bug: 119593268 Bug: 113451905 Test: visual Change-Id: I43d6ca8508f0ba49796004d679d6cbe37ddf4455
This commit is contained in:
@@ -33,13 +33,16 @@ public class ContextualCard {
|
||||
/**
|
||||
* Flags indicating the type of the ContextualCard.
|
||||
*/
|
||||
@IntDef({CardType.DEFAULT, CardType.SLICE, CardType.LEGACY_SUGGESTION, CardType.CONDITIONAL})
|
||||
@IntDef({CardType.DEFAULT, CardType.SLICE, CardType.LEGACY_SUGGESTION, CardType.CONDITIONAL,
|
||||
CardType.CONDITIONAL_HEADER, CardType.CONDITIONAL_FOOTER})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface CardType {
|
||||
int DEFAULT = 0;
|
||||
int SLICE = 1;
|
||||
int LEGACY_SUGGESTION = 2;
|
||||
int CONDITIONAL = 3;
|
||||
int CONDITIONAL_HEADER = 4;
|
||||
int CONDITIONAL_FOOTER = 5;
|
||||
}
|
||||
|
||||
private final Builder mBuilder;
|
||||
|
@@ -42,6 +42,7 @@ public class ConditionContextualCardController implements ContextualCardControll
|
||||
private final ConditionManager mConditionManager;
|
||||
|
||||
private ContextualCardUpdateListener mListener;
|
||||
private boolean mIsExpanded;
|
||||
|
||||
public ConditionContextualCardController(Context context) {
|
||||
mContext = context;
|
||||
@@ -49,6 +50,10 @@ public class ConditionContextualCardController implements ContextualCardControll
|
||||
mConditionManager.startMonitoringStateChange();
|
||||
}
|
||||
|
||||
public void setIsExpanded(boolean isExpanded) {
|
||||
mIsExpanded = isExpanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCardUpdateListener(ContextualCardUpdateListener listener) {
|
||||
mListener = listener;
|
||||
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.homepage.contextualcards.conditional;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
|
||||
/**
|
||||
* Data class representing a condition footer {@link ContextualCard}.
|
||||
*
|
||||
* Use this class for {@link ConditionFooterContextualCardRenderer} and
|
||||
* {@link ConditionContextualCardController}.
|
||||
*/
|
||||
public class ConditionFooterContextualCard extends ContextualCard {
|
||||
|
||||
private ConditionFooterContextualCard(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardType() {
|
||||
return CardType.CONDITIONAL_FOOTER;
|
||||
}
|
||||
|
||||
public static class Builder extends ContextualCard.Builder {
|
||||
|
||||
@Override
|
||||
public Builder setCardType(int cardType) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot change card type for " + getClass().getName());
|
||||
}
|
||||
|
||||
public ConditionFooterContextualCard build() {
|
||||
return new ConditionFooterContextualCard(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.homepage.contextualcards.conditional;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCardRenderer;
|
||||
import com.android.settings.homepage.contextualcards.ControllerRendererPool;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
public class ConditionFooterContextualCardRenderer implements ContextualCardRenderer {
|
||||
public static final int VIEW_TYPE = R.layout.homepage_condition_footer;
|
||||
private static final String TAG = "ConditionFooterRenderer";
|
||||
|
||||
private final Context mContext;
|
||||
private final ControllerRendererPool mControllerRendererPool;
|
||||
|
||||
public ConditionFooterContextualCardRenderer(Context context,
|
||||
ControllerRendererPool controllerRendererPool) {
|
||||
mContext = context;
|
||||
mControllerRendererPool = controllerRendererPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType(boolean isHalfWidth) {
|
||||
return VIEW_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder createViewHolder(View view) {
|
||||
return new ConditionFooterCardHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(RecyclerView.ViewHolder holder, ContextualCard card) {
|
||||
final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(
|
||||
mContext).getMetricsFeatureProvider();
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
|
||||
MetricsProto.MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
SettingsEnums.SETTINGS_HOMEPAGE,
|
||||
null /* key */,
|
||||
0 /* false */);
|
||||
final ConditionContextualCardController controller =
|
||||
mControllerRendererPool.getController(mContext,
|
||||
ContextualCard.CardType.CONDITIONAL_FOOTER);
|
||||
controller.setIsExpanded(false);
|
||||
controller.onConditionsChanged();
|
||||
});
|
||||
}
|
||||
|
||||
public static class ConditionFooterCardHolder extends RecyclerView.ViewHolder {
|
||||
public ConditionFooterCardHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.homepage.contextualcards.conditional;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Data class representing a condition header {@link ContextualCard}.
|
||||
*
|
||||
* Use this class to store additional attributes on top of {@link ContextualCard} for
|
||||
* {@link ConditionHeaderContextualCardRenderer} and {@link ConditionContextualCardController}.
|
||||
*/
|
||||
public class ConditionHeaderContextualCard extends ContextualCard {
|
||||
|
||||
private final List<ContextualCard> mConditionalCards;
|
||||
|
||||
private ConditionHeaderContextualCard(Builder builder) {
|
||||
super(builder);
|
||||
mConditionalCards = builder.mConditionalCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardType() {
|
||||
return CardType.CONDITIONAL_HEADER;
|
||||
}
|
||||
|
||||
public List<ContextualCard> getConditionalCards() {
|
||||
return mConditionalCards;
|
||||
}
|
||||
|
||||
public static class Builder extends ContextualCard.Builder {
|
||||
|
||||
private List<ContextualCard> mConditionalCards;
|
||||
|
||||
public Builder setConditionalCards(List<ContextualCard> conditionalCards) {
|
||||
mConditionalCards = conditionalCards;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setCardType(int cardType) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot change card type for " + getClass().getName());
|
||||
}
|
||||
|
||||
public ConditionHeaderContextualCard build() {
|
||||
return new ConditionHeaderContextualCard(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.homepage.contextualcards.conditional;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCardRenderer;
|
||||
import com.android.settings.homepage.contextualcards.ControllerRendererPool;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
public class ConditionHeaderContextualCardRenderer implements ContextualCardRenderer {
|
||||
public static final int VIEW_TYPE = R.layout.homepage_condition_header;
|
||||
private static final String TAG = "ConditionHeaderRenderer";
|
||||
|
||||
private final Context mContext;
|
||||
private final ControllerRendererPool mControllerRendererPool;
|
||||
|
||||
public ConditionHeaderContextualCardRenderer(Context context,
|
||||
ControllerRendererPool controllerRendererPool) {
|
||||
mContext = context;
|
||||
mControllerRendererPool = controllerRendererPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType(boolean isHalfWidth) {
|
||||
return VIEW_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder createViewHolder(View view) {
|
||||
return new ConditionHeaderCardHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(RecyclerView.ViewHolder holder, ContextualCard contextualCard) {
|
||||
final ConditionHeaderContextualCard headerCard =
|
||||
(ConditionHeaderContextualCard) contextualCard;
|
||||
final ConditionHeaderCardHolder view = (ConditionHeaderCardHolder) holder;
|
||||
final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(
|
||||
mContext).getMetricsFeatureProvider();
|
||||
view.icons.removeAllViews();
|
||||
headerCard.getConditionalCards().stream().forEach(card -> {
|
||||
final ImageView icon = (ImageView) LayoutInflater.from(mContext).inflate(
|
||||
R.layout.homepage_condition_header_icon, view.icons, false);
|
||||
icon.setImageDrawable(card.getIconDrawable());
|
||||
view.icons.addView(icon);
|
||||
});
|
||||
view.itemView.setOnClickListener(v -> {
|
||||
metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
|
||||
MetricsProto.MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
SettingsEnums.SETTINGS_HOMEPAGE,
|
||||
null /* key */,
|
||||
1 /* true */);
|
||||
final ConditionContextualCardController controller =
|
||||
mControllerRendererPool.getController(mContext,
|
||||
ContextualCard.CardType.CONDITIONAL_HEADER);
|
||||
controller.setIsExpanded(true);
|
||||
controller.onConditionsChanged();
|
||||
});
|
||||
}
|
||||
|
||||
public static class ConditionHeaderCardHolder extends RecyclerView.ViewHolder {
|
||||
public final LinearLayout icons;
|
||||
public final ImageView expandIndicator;
|
||||
|
||||
public ConditionHeaderCardHolder(View itemView) {
|
||||
super(itemView);
|
||||
icons = itemView.findViewById(R.id.header_icons_container);
|
||||
expandIndicator = itemView.findViewById(R.id.expand_indicator);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user