Add conditionals to Settings
Also add Airplane Mode and Hotspot conditionals (more to come soon) Change-Id: I11f206db59f7c715f416fb5852b8f0fcb857a247
This commit is contained in:
@@ -18,7 +18,6 @@ package com.android.settings.dashboard;
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -26,40 +25,52 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.DashboardTile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder> {
|
||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder> implements View.OnClickListener {
|
||||
public static final String TAG = "DashboardAdapter";
|
||||
|
||||
private final List<Object> mItems = new ArrayList<>();
|
||||
private final List<Integer> mTypes = new ArrayList<>();
|
||||
private final List<Integer> mIds = new ArrayList<>();
|
||||
|
||||
private final List<DashboardCategory> mCategories;
|
||||
private final Context mContext;
|
||||
|
||||
private List<DashboardCategory> mCategories;
|
||||
private List<Condition> mConditions;
|
||||
|
||||
private boolean mIsShowingAll;
|
||||
// Used for counting items;
|
||||
private int mId;
|
||||
|
||||
public DashboardAdapter(Context context, List<DashboardCategory> categories) {
|
||||
private Condition mExpandedCondition = null;
|
||||
|
||||
public DashboardAdapter(Context context) {
|
||||
mContext = context;
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public void setCategories(List<DashboardCategory> categories) {
|
||||
mCategories = categories;
|
||||
|
||||
// TODO: Better place for tinting?
|
||||
TypedValue tintColor = new TypedValue();
|
||||
context.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent,
|
||||
mContext.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent,
|
||||
tintColor, true);
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
for (int j = 0; j < categories.get(i).tiles.size(); j++) {
|
||||
DashboardTile tile = categories.get(i).tiles.get(j);
|
||||
|
||||
if (!context.getPackageName().equals(
|
||||
if (!mContext.getPackageName().equals(
|
||||
tile.intent.getComponent().getPackageName())) {
|
||||
// If this drawable is coming from outside Settings, tint it to match the
|
||||
// color.
|
||||
@@ -67,9 +78,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
}
|
||||
}
|
||||
setShowingAll(mIsShowingAll);
|
||||
}
|
||||
|
||||
setShowingAll(false);
|
||||
setHasStableIds(true);
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
mConditions = conditions;
|
||||
setShowingAll(mIsShowingAll);
|
||||
}
|
||||
|
||||
public boolean isShowingAll() {
|
||||
@@ -88,19 +102,21 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
public void setShowingAll(boolean showingAll) {
|
||||
mIsShowingAll = showingAll;
|
||||
reset();
|
||||
countItem(null, com.android.settings.R.layout.dashboard_spacer, true);
|
||||
for (int i = 0; i < mCategories.size(); i++) {
|
||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||
countItem(mConditions.get(i), R.layout.condition_card, mConditions.get(i).shouldShow());
|
||||
}
|
||||
countItem(null, R.layout.dashboard_spacer, true);
|
||||
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
||||
DashboardCategory category = mCategories.get(i);
|
||||
countItem(category, com.android.settings.R.layout.dashboard_category, mIsShowingAll);
|
||||
countItem(category, R.layout.dashboard_category, mIsShowingAll);
|
||||
for (int j = 0; j < category.tiles.size(); j++) {
|
||||
DashboardTile tile = category.tiles.get(j);
|
||||
Log.d(TAG, "Maybe adding " + tile.intent.getComponent().getClassName());
|
||||
countItem(tile, com.android.settings.R.layout.dashboard_tile, mIsShowingAll
|
||||
countItem(tile, R.layout.dashboard_tile, mIsShowingAll
|
||||
|| ArrayUtils.contains(DashboardSummary.INITIAL_ITEMS,
|
||||
tile.intent.getComponent().getClassName()));
|
||||
}
|
||||
}
|
||||
countItem(null, com.android.settings.R.layout.see_all, true);
|
||||
countItem(null, R.layout.see_all, true);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -129,10 +145,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
switch (mTypes.get(position)) {
|
||||
case com.android.settings.R.layout.dashboard_category:
|
||||
case R.layout.dashboard_category:
|
||||
onBindCategory(holder, (DashboardCategory) mItems.get(position));
|
||||
break;
|
||||
case com.android.settings.R.layout.dashboard_tile:
|
||||
case R.layout.dashboard_tile:
|
||||
final DashboardTile tile = (DashboardTile) mItems.get(position);
|
||||
onBindTile(holder, tile);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -142,7 +158,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
});
|
||||
break;
|
||||
case com.android.settings.R.layout.see_all:
|
||||
case R.layout.see_all:
|
||||
onBindSeeAll(holder);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -151,6 +167,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.layout.condition_card:
|
||||
ConditionAdapterUtils.bindViews((Condition) mItems.get(position), holder,
|
||||
mItems.get(position) == mExpandedCondition, this,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onExpandClick(v);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +196,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
|
||||
private void onBindSeeAll(DashboardItemHolder holder) {
|
||||
holder.title.setText(mIsShowingAll ? com.android.settings.R.string.see_less
|
||||
: com.android.settings.R.string.see_all);
|
||||
holder.title.setText(mIsShowingAll ? R.string.see_less
|
||||
: R.string.see_all);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,10 +215,38 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mIds.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getTag() == mExpandedCondition) {
|
||||
mExpandedCondition.onPrimaryClick();
|
||||
} else {
|
||||
mExpandedCondition = (Condition) v.getTag();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void onExpandClick(View v) {
|
||||
if (v.getTag() == mExpandedCondition) {
|
||||
mExpandedCondition = null;
|
||||
} else {
|
||||
mExpandedCondition = (Condition) v.getTag();
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public Object getItem(long itemId) {
|
||||
for (int i = 0; i < mIds.size(); i++) {
|
||||
if (mIds.get(i) == itemId) {
|
||||
return mItems.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class DashboardItemHolder extends RecyclerView.ViewHolder {
|
||||
private final ImageView icon;
|
||||
private final TextView title;
|
||||
private final TextView summary;
|
||||
public final ImageView icon;
|
||||
public final TextView title;
|
||||
public final TextView summary;
|
||||
|
||||
public DashboardItemHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
Reference in New Issue
Block a user