Implemented Better Canteen Meals (Custom CardView)
BIN
app/src/main/ic_bio-web.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
app/src/main/ic_msc-web.png
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
app/src/main/ic_vegan-web.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
app/src/main/ic_vegetarian-web.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
@@ -7,6 +7,8 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.Day;
|
import de.sebse.fuplanner.services.Canteen.types.Day;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.Meal;
|
import de.sebse.fuplanner.services.Canteen.types.Meal;
|
||||||
@@ -33,6 +35,7 @@ class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull MealViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull MealViewHolder viewHolder, int i) {
|
||||||
|
viewHolder.reset();
|
||||||
Meal meal = getItem(i);
|
Meal meal = getItem(i);
|
||||||
viewHolder.mTitle.setText(meal.getName());
|
viewHolder.mTitle.setText(meal.getName());
|
||||||
String value;
|
String value;
|
||||||
@@ -50,6 +53,20 @@ class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
|
|||||||
value = mContext.getString(R.string.prices, meal.getPriceStdnt(), meal.getPriceEmply(), meal.getPriceOther());
|
value = mContext.getString(R.string.prices, meal.getPriceStdnt(), meal.getPriceEmply(), meal.getPriceOther());
|
||||||
}
|
}
|
||||||
viewHolder.mSubTitle.setText(value);
|
viewHolder.mSubTitle.setText(value);
|
||||||
|
StringBuilder string = new StringBuilder();
|
||||||
|
List<String> notes = meal.getNotes();
|
||||||
|
for (int i1 = 0, notesSize = notes.size(); i1 < notesSize; i1++) {
|
||||||
|
if (i1 != 0)
|
||||||
|
string.append("\n");
|
||||||
|
String s = notes.get(i1);
|
||||||
|
string.append(" - ").append(s);
|
||||||
|
}
|
||||||
|
viewHolder.mNotes.setText(string.toString());
|
||||||
|
viewHolder.mCategory.setText(meal.getCategory());
|
||||||
|
viewHolder.mIconVegan.setVisibility(meal.getVegan() == Meal.VEGAN_VEGAN ? View.VISIBLE : View.GONE);
|
||||||
|
viewHolder.mIconVegetarian.setVisibility(meal.getVegan() == Meal.VEGAN_VEGETERIAN ? View.VISIBLE : View.GONE);
|
||||||
|
viewHolder.mIconBio.setVisibility((meal.getCertificates() & Meal.CERT_BIO) != 0 ? View.VISIBLE : View.GONE);
|
||||||
|
viewHolder.mIconMsc.setVisibility((meal.getCertificates() & Meal.CERT_MSC) != 0 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Meal getItem(int groupPosition) {
|
public Meal getItem(int groupPosition) {
|
||||||
@@ -67,107 +84,6 @@ class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public String getChild(int groupPosition, int childPosititon) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("\n\n");
|
|
||||||
for (String s : this.getGroup(groupPosition).getNotes())
|
|
||||||
{
|
|
||||||
sb.append(s);
|
|
||||||
sb.append("\n\n");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getChildId(int groupPosition, int childPosition) {
|
|
||||||
return childPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getChildView(int groupPosition, final int childPosition,
|
|
||||||
boolean isLastChild, View convertView, ViewGroup parent) {
|
|
||||||
|
|
||||||
final String childText = getChild(groupPosition, childPosition);
|
|
||||||
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.list_all_string, parent, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringViewHolder itemHolder = new StringViewHolder(convertView);
|
|
||||||
itemHolder.mString.setText(childText);
|
|
||||||
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getChildrenCount(int groupPosition) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Meal getGroup(int groupPosition) {
|
|
||||||
if (this.mDay != null)
|
|
||||||
return this.mDay.get(groupPosition);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getGroupCount() {
|
|
||||||
if (this.mDay != null)
|
|
||||||
return this.mDay.size();
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getGroupId(int groupPosition) {
|
|
||||||
return groupPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getGroupView(int groupPosition, boolean isExpanded,
|
|
||||||
View convertView, ViewGroup parent) {
|
|
||||||
Meal meal = getGroup(groupPosition);
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.list_canteen_items, parent, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemViewHolder itemHolder = new ItemViewHolder(convertView);
|
|
||||||
//itemHolder.mTitle.setText(meal.getName());
|
|
||||||
//itemHolder.mSubLeft.setText(meal.getCategory());
|
|
||||||
String value;
|
|
||||||
switch (Preferences.getString(mContext, R.array.pref_price_group)) {
|
|
||||||
case "student":
|
|
||||||
value = mContext.getString(R.string.price, meal.getPriceStdnt());
|
|
||||||
break;
|
|
||||||
case "employee":
|
|
||||||
value = mContext.getString(R.string.price, meal.getPriceEmply());
|
|
||||||
break;
|
|
||||||
case "other":
|
|
||||||
value = mContext.getString(R.string.price, meal.getPriceOther());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
value = mContext.getString(R.string.prices, meal.getPriceStdnt(), meal.getPriceEmply(), meal.getPriceOther());
|
|
||||||
}
|
|
||||||
//itemHolder.mSubRight.setText(value);
|
|
||||||
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasStableIds() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void setDay(Day day) {
|
public void setDay(Day day) {
|
||||||
this.mDay = day;
|
this.mDay = day;
|
||||||
this.setDay();
|
this.setDay();
|
||||||
|
|||||||
@@ -10,10 +10,14 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Logger(Object object) {
|
public Logger(Object object) {
|
||||||
|
this.tag = getClassName(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClassName(Object object) {
|
||||||
if (object instanceof String)
|
if (object instanceof String)
|
||||||
this.tag = (String) object;
|
return (String) object;
|
||||||
else
|
else
|
||||||
this.tag = object.getClass().getSimpleName();
|
return object.getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void d(Object... msg) {
|
public void d(Object... msg) {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.sebse.fuplanner.tools.ui;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.tools.ui.cardview.ExpandableCardView;
|
||||||
|
|
||||||
|
public class ExpandableCardViewHolder extends CustomViewHolder {
|
||||||
|
ExpandableCardViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
getView().reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpandableCardView getView() {
|
||||||
|
return (ExpandableCardView) mView;
|
||||||
|
}
|
||||||
|
|
||||||
|
View getOuterView() {
|
||||||
|
return getView().getOuterView();
|
||||||
|
}
|
||||||
|
|
||||||
|
View getInnerView() {
|
||||||
|
return getView().getInnerView();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,40 @@
|
|||||||
package de.sebse.fuplanner.tools.ui;
|
package de.sebse.fuplanner.tools.ui;
|
||||||
|
|
||||||
|
import android.media.Image;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
public class MealViewHolder extends CustomViewHolder {
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
import de.sebse.fuplanner.tools.ui.cardview.ExpandableCardView;
|
||||||
|
|
||||||
|
public class MealViewHolder extends ExpandableCardViewHolder {
|
||||||
public final TextView mTitle;
|
public final TextView mTitle;
|
||||||
public final TextView mSubTitle;
|
public final TextView mSubTitle;
|
||||||
|
public final TextView mCategory;
|
||||||
|
public final TextView mNotes;
|
||||||
|
|
||||||
|
public final ImageView mIconVegan;
|
||||||
|
public final ImageView mIconVegetarian;
|
||||||
|
public final ImageView mIconBio;
|
||||||
|
public final ImageView mIconMsc;
|
||||||
|
|
||||||
|
|
||||||
public MealViewHolder(View view) {
|
public MealViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
mTitle = view.findViewById(R.id.title);
|
View outerView = getOuterView();
|
||||||
mSubTitle = view.findViewById(R.id.sub_title);
|
View innerView = getInnerView();
|
||||||
|
mTitle = outerView.findViewById(R.id.title);
|
||||||
|
mSubTitle = outerView.findViewById(R.id.sub_title);
|
||||||
|
mNotes = innerView.findViewById(R.id.notes);
|
||||||
|
mCategory = innerView.findViewById(R.id.category);
|
||||||
|
mIconVegan = innerView.findViewById(R.id.icon_vegan);
|
||||||
|
mIconVegetarian = innerView.findViewById(R.id.icon_vegetarian);
|
||||||
|
mIconBio = innerView.findViewById(R.id.icon_bio);
|
||||||
|
mIconMsc = innerView.findViewById(R.id.icon_msc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,27 +3,22 @@ package de.sebse.fuplanner.tools.ui.cardview;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.ViewStub;
|
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.RotateAnimation;
|
import android.view.animation.RotateAnimation;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.tools.UtilsUi;
|
import de.sebse.fuplanner.tools.UtilsUi;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -46,21 +41,13 @@ import de.sebse.fuplanner.tools.UtilsUi;
|
|||||||
* @author Alessandro Sperotti
|
* @author Alessandro Sperotti
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ExpandableCardView extends LinearLayout {
|
public class ExpandableCardView extends CardView {
|
||||||
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
private ViewGroup containerView;
|
|
||||||
|
|
||||||
private ImageButton arrowBtn;
|
|
||||||
//private ImageButton headerIcon;
|
|
||||||
//private TextView textViewTitle;
|
|
||||||
|
|
||||||
private int innerViewRes;
|
private int innerViewRes;
|
||||||
private int outerViewRes;
|
private int outerViewRes;
|
||||||
//private Drawable iconDrawable;
|
|
||||||
|
|
||||||
private CardView card;
|
private View innerView;
|
||||||
|
private View outerView;
|
||||||
|
private ImageButton imageButton;
|
||||||
|
|
||||||
public static final int DEFAULT_ANIM_DURATION = 350;
|
public static final int DEFAULT_ANIM_DURATION = 350;
|
||||||
private long animDuration = DEFAULT_ANIM_DURATION;
|
private long animDuration = DEFAULT_ANIM_DURATION;
|
||||||
@@ -71,10 +58,10 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
private boolean isExpanded = false;
|
private boolean isExpanded = false;
|
||||||
private boolean isExpanding = false;
|
private boolean isExpanding = false;
|
||||||
private boolean isCollapsing = false;
|
private boolean isCollapsing = false;
|
||||||
private boolean expandOnClick = false;
|
|
||||||
private boolean startExpanded = false;
|
private boolean startExpanded = false;
|
||||||
|
|
||||||
private int previousHeight = 0;
|
private int collapsedHeight = 0;
|
||||||
|
private int expandedHeight = 0;
|
||||||
|
|
||||||
private OnExpandedListener listener;
|
private OnExpandedListener listener;
|
||||||
|
|
||||||
@@ -82,9 +69,11 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
if(isExpanded()) collapse();
|
if(isExpanded()) collapse();
|
||||||
else expand();
|
else expand();
|
||||||
};
|
};
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
|
||||||
public ExpandableCardView(Context context) {
|
public ExpandableCardView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
initView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpandableCardView(Context context, AttributeSet attrs) {
|
public ExpandableCardView(Context context, AttributeSet attrs) {
|
||||||
@@ -103,19 +92,27 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
|
|
||||||
private void initView(Context context){
|
private void initView(Context context){
|
||||||
//Inflating View
|
//Inflating View
|
||||||
LayoutInflater inflater = (LayoutInflater) context
|
imageButton = new ImageButton(context);
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
imageButton.setImageDrawable(getResources().getDrawable(R.drawable.arrow_down));
|
||||||
if (inflater == null) throw new AssertionError();
|
imageButton.setPadding(
|
||||||
inflater.inflate(R.layout.expandable_cardview, this);
|
(int) UtilsUi.convertDpToPixels(getContext(), 10),
|
||||||
|
(int) UtilsUi.convertDpToPixels(getContext(), 10),
|
||||||
|
(int) UtilsUi.convertDpToPixels(getContext(), 10),
|
||||||
|
(int) UtilsUi.convertDpToPixels(getContext(), 10)
|
||||||
|
);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
TypedValue outValue = new TypedValue();
|
||||||
|
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
||||||
|
imageButton.setBackgroundResource(outValue.resourceId);
|
||||||
|
}
|
||||||
|
isExpanded = startExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAttributes(Context context, AttributeSet attrs){
|
private void initAttributes(Context context, AttributeSet attrs){
|
||||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableCardView);
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableCardView);
|
||||||
title = typedArray.getString(R.styleable.ExpandableCardView_title);
|
|
||||||
//iconDrawable = typedArray.getDrawable(R.styleable.ExpandableCardView_icon);
|
|
||||||
innerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_inner_view, View.NO_ID);
|
innerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_inner_view, View.NO_ID);
|
||||||
outerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_outer_view, View.NO_ID);
|
outerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_outer_view, View.NO_ID);
|
||||||
expandOnClick = typedArray.getBoolean(R.styleable.ExpandableCardView_expandOnClick, false);
|
|
||||||
animDuration = typedArray.getInteger(R.styleable.ExpandableCardView_animationDuration, DEFAULT_ANIM_DURATION);
|
animDuration = typedArray.getInteger(R.styleable.ExpandableCardView_animationDuration, DEFAULT_ANIM_DURATION);
|
||||||
startExpanded = typedArray.getBoolean(R.styleable.ExpandableCardView_startExpanded, false);
|
startExpanded = typedArray.getBoolean(R.styleable.ExpandableCardView_startExpanded, false);
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
@@ -125,69 +122,91 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
|
|
||||||
arrowBtn = findViewById(R.id.arrow);
|
innerView = inflateChild(innerViewRes);
|
||||||
//textViewTitle = findViewById(R.id.title);
|
outerView = inflateChild(outerViewRes);
|
||||||
//headerIcon = findViewById(R.id.icon);
|
|
||||||
|
|
||||||
//Setting attributes
|
|
||||||
/*if(!TextUtils.isEmpty(title)) textViewTitle.setText(title);
|
|
||||||
|
|
||||||
if(iconDrawable != null){
|
|
||||||
headerIcon.setVisibility(VISIBLE);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
headerIcon.setBackground(iconDrawable);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
card = findViewById(R.id.card);
|
|
||||||
|
|
||||||
setInnerView(innerViewRes);
|
|
||||||
setOuterView(outerViewRes);
|
|
||||||
|
|
||||||
containerView = findViewById(R.id.viewContainer);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
setElevation(UtilsUi.convertDpToPixels(getContext(), 4));
|
setElevation(UtilsUi.convertDpToPixels(getContext(), 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startExpanded){
|
setOnClickListener(defaultClickListener);
|
||||||
setAnimDuration(0);
|
|
||||||
expand();
|
|
||||||
setAnimDuration(animDuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expandOnClick){
|
@Override
|
||||||
card.setOnClickListener(defaultClickListener);
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
arrowBtn.setOnClickListener(defaultClickListener);
|
removeAllViews();
|
||||||
|
int x = getPaddingLeft();
|
||||||
|
int y = getPaddingTop();
|
||||||
|
addView(outerView);
|
||||||
|
outerView.layout(x, y, x+outerView.getMeasuredWidth(), y+outerView.getMeasuredHeight());
|
||||||
|
addView(imageButton);
|
||||||
|
imageButton.layout(
|
||||||
|
getMeasuredWidth() - getPaddingRight() - imageButton.getMeasuredWidth(),
|
||||||
|
y,
|
||||||
|
getMeasuredWidth() - getPaddingRight(),
|
||||||
|
y+imageButton.getMeasuredHeight()
|
||||||
|
);
|
||||||
|
addView(innerView);
|
||||||
|
innerView.layout(x, y+outerView.getMeasuredHeight(), x+innerView.getMeasuredWidth(), y+outerView.getMeasuredHeight()+innerView.getMeasuredHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
//log.d("w", MeasureSpec.toString(widthMeasureSpec));
|
||||||
|
//log.d("h", MeasureSpec.toString(heightMeasureSpec));
|
||||||
|
if (MeasureSpec.getSize(widthMeasureSpec) == 0 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED || MeasureSpec.getSize(heightMeasureSpec) == 0 && MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.UNSPECIFIED) {
|
||||||
|
log.w("This should not happen! Invalid dimension size");
|
||||||
|
setMeasuredDimension(reconcileSize(10, widthMeasureSpec), reconcileSize(10, heightMeasureSpec));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int desiredWidth;
|
||||||
|
int desiredHeight;
|
||||||
|
|
||||||
|
int widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
|
||||||
|
int heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
|
||||||
|
imageButton.measure(widthMeasure, heightMeasure);
|
||||||
|
|
||||||
|
widthMeasure = atMostExactlySpec(Math.max(0, MeasureSpec.getSize(widthMeasureSpec)-imageButton.getMeasuredWidth()), widthMeasureSpec);
|
||||||
|
heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
|
||||||
|
outerView.measure(widthMeasure, heightMeasure);
|
||||||
|
desiredWidth = imageButton.getMeasuredWidth() + outerView.getMeasuredWidth();
|
||||||
|
desiredHeight = Math.max(imageButton.getMeasuredHeight(), outerView.getMeasuredHeight());
|
||||||
|
|
||||||
|
widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
|
||||||
|
heightMeasure = atMostSpec(Math.max(0, MeasureSpec.getSize(heightMeasureSpec)-desiredHeight), heightMeasureSpec);
|
||||||
|
innerView.measure(widthMeasure, heightMeasure);
|
||||||
|
desiredWidth = Math.max(desiredWidth, innerView.getMeasuredWidth());
|
||||||
|
desiredHeight += innerView.getMeasuredHeight();
|
||||||
|
|
||||||
|
desiredWidth += getPaddingLeft() + getPaddingRight();
|
||||||
|
desiredHeight += getPaddingTop() + getPaddingBottom();
|
||||||
|
|
||||||
|
if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
|
||||||
|
expandedHeight = desiredHeight;
|
||||||
|
collapsedHeight = desiredHeight - innerView.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
setMeasuredDimension(reconcileSize(desiredWidth, widthMeasureSpec), reconcileSize(isExpanded ? expandedHeight : collapsedHeight, heightMeasureSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expand() {
|
public void expand() {
|
||||||
|
final int initialHeight = this.getHeight();
|
||||||
final int initialHeight = card.getHeight();
|
int targetHeight = expandedHeight;
|
||||||
|
//innerView.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||||
if(!isMoving()) {
|
//log.d(targetHeight, outerView.getHeight(), innerView.getHeight(), innerView.getMeasuredHeight());
|
||||||
previousHeight = initialHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
card.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
int targetHeight = card.getMeasuredHeight();
|
|
||||||
|
|
||||||
if(targetHeight - initialHeight != 0) {
|
if(targetHeight - initialHeight != 0) {
|
||||||
animateViews(initialHeight,
|
animateViews(initialHeight, targetHeight - initialHeight, EXPANDING);
|
||||||
targetHeight - initialHeight,
|
|
||||||
EXPANDING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collapse() {
|
public void collapse() {
|
||||||
int initialHeight = card.getMeasuredHeight();
|
final int initialHeight = this.getHeight();
|
||||||
|
int targetHeight = collapsedHeight;
|
||||||
|
|
||||||
if(initialHeight - previousHeight != 0) {
|
if(initialHeight - targetHeight != 0) {
|
||||||
animateViews(initialHeight,
|
animateViews(initialHeight, initialHeight - targetHeight, COLLAPSING);
|
||||||
initialHeight - previousHeight,
|
|
||||||
COLLAPSING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -207,21 +226,17 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
isCollapsing = false;
|
isCollapsing = false;
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
if(animationType == EXPANDING){
|
if (animationType == EXPANDING)
|
||||||
listener.onExpandChanged(card,true);
|
listener.onExpandChanged(ExpandableCardView.this, true);
|
||||||
}
|
else
|
||||||
else{
|
listener.onExpandChanged(ExpandableCardView.this, false);
|
||||||
listener.onExpandChanged(card,false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
card.getLayoutParams().height = animationType == EXPANDING ? (int) (initialHeight + (distance * interpolatedTime)) :
|
ExpandableCardView.this.getLayoutParams().height = animationType == EXPANDING
|
||||||
(int) (initialHeight - (distance * interpolatedTime));
|
? (int) (initialHeight + (distance * interpolatedTime))
|
||||||
card.findViewById(R.id.viewContainer).requestLayout();
|
: (int) (initialHeight - (distance * interpolatedTime));
|
||||||
|
ExpandableCardView.this.requestLayout();
|
||||||
containerView.getLayoutParams().height = animationType == EXPANDING ? (int) (initialHeight + (distance * interpolatedTime)) :
|
|
||||||
(int) (initialHeight - (distance * interpolatedTime));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,8 +262,7 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
isCollapsing = animationType == COLLAPSING;
|
isCollapsing = animationType == COLLAPSING;
|
||||||
|
|
||||||
startAnimation(expandAnimation);
|
startAnimation(expandAnimation);
|
||||||
//Log.d("SO","Started animation: "+ (animationType == EXPANDING ? "Expanding" : "Collapsing"));
|
imageButton.startAnimation(arrowAnimation);
|
||||||
arrowBtn.startAnimation(arrowAnimation);
|
|
||||||
isExpanded = animationType == EXPANDING;
|
isExpanded = animationType == EXPANDING;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -273,48 +287,21 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
this.listener = null;
|
this.listener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void setTitle(String title){
|
private View inflateChild(@LayoutRes int resId) {
|
||||||
if(textViewTitle != null) textViewTitle.setText(title);
|
return inflate(getContext(), resId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(int resId){
|
public View getOuterView() {
|
||||||
if(textViewTitle != null) textViewTitle.setText(resId);
|
return outerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(Drawable drawable){
|
public View getInnerView() {
|
||||||
if(headerIcon != null){
|
return innerView;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
headerIcon.setBackground(drawable);
|
|
||||||
}
|
}
|
||||||
iconDrawable = drawable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIcon(int resId){
|
|
||||||
if(headerIcon != null){
|
|
||||||
iconDrawable = ContextCompat.getDrawable(getContext(), resId);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
headerIcon.setBackground(iconDrawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void setInnerView(int resId){
|
|
||||||
ViewStub stub = findViewById(R.id.viewStub);
|
|
||||||
stub.setLayoutResource(resId);
|
|
||||||
stub.inflate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setOuterView(int resId){
|
|
||||||
ViewStub stub = findViewById(R.id.headerStub);
|
|
||||||
stub.setLayoutResource(resId);
|
|
||||||
View view = stub.inflate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOnClickListener(@Nullable OnClickListener l) {
|
public void setOnClickListener(@Nullable OnClickListener l) {
|
||||||
if(arrowBtn != null) arrowBtn.setOnClickListener(l);
|
if(imageButton != null) imageButton.setOnClickListener(l);
|
||||||
super.setOnClickListener(l);
|
super.setOnClickListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +313,50 @@ public class ExpandableCardView extends LinearLayout {
|
|||||||
this.animDuration = animDuration;
|
this.animDuration = animDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int reconcileSize(int contentSize, int measureSpec) {
|
||||||
|
final int mode = MeasureSpec.getMode(measureSpec);
|
||||||
|
final int specSize = MeasureSpec.getSize(measureSpec);
|
||||||
|
switch(mode) {
|
||||||
|
case MeasureSpec.EXACTLY:
|
||||||
|
return specSize;
|
||||||
|
case MeasureSpec.AT_MOST:
|
||||||
|
if (contentSize < specSize) {
|
||||||
|
return contentSize;
|
||||||
|
} else {
|
||||||
|
log.w("Your content may be cropped!");
|
||||||
|
return specSize;
|
||||||
|
}
|
||||||
|
case MeasureSpec.UNSPECIFIED:
|
||||||
|
default:
|
||||||
|
return contentSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int atMostSpec(int atMostSpace, int measureSpec) {
|
||||||
|
if (MeasureSpec.getMode(measureSpec) == MeasureSpec.UNSPECIFIED)
|
||||||
|
return measureSpec;
|
||||||
|
else
|
||||||
|
return MeasureSpec.makeMeasureSpec(atMostSpace, MeasureSpec.AT_MOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int atMostExactlySpec(int atMostExactlySpace, int measureSpec) {
|
||||||
|
if (MeasureSpec.getMode(measureSpec) == MeasureSpec.UNSPECIFIED)
|
||||||
|
return measureSpec;
|
||||||
|
else
|
||||||
|
return MeasureSpec.makeMeasureSpec(atMostExactlySpace, MeasureSpec.getMode(measureSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
long anim = getAnimDuration();
|
||||||
|
this.setAnimDuration(0);
|
||||||
|
if (startExpanded) {
|
||||||
|
this.expand();
|
||||||
|
} else {
|
||||||
|
this.collapse();
|
||||||
|
}
|
||||||
|
this.setAnimDuration(anim);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interfaces
|
* Interfaces
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<android.support.v7.widget.CardView android:id="@+id/card"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingTop="@dimen/default_vertical_padding"
|
|
||||||
android:paddingBottom="@dimen/default_vertical_padding"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:layout_marginBottom="5dp"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/viewContainer"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/default_card_height"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/default_card_height"
|
|
||||||
android:id="@+id/header"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<!--<ImageButton
|
|
||||||
android:id="@+id/icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
style="@style/FUTheme.itemTitle"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:maxLength="39"
|
|
||||||
android:layout_toEndOf="@+id/icon"
|
|
||||||
android:layout_toRightOf="@+id/icon" />
|
|
||||||
<!-
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textColor="@android:color/primary_text_light"
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ViewStub
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:layout_marginStart="15dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/headerStub"
|
|
||||||
android:inflatedId="@+id/outerView"
|
|
||||||
android:layout_toLeftOf="@id/arrow"
|
|
||||||
android:layout_toStartOf="@id/arrow"/>
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/arrow"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="20dp"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:background="?selectableItemBackgroundBorderless"
|
|
||||||
android:src="@drawable/arrow_down"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:layout_alignParentEnd="true" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<ViewStub
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/viewStub"
|
|
||||||
android:inflatedId="@+id/innerView"/>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
|
||||||
52
app/src/main/res/layout/list_canteen_body.xml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp">
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/FUTheme.itemValue"
|
||||||
|
android:id="@+id/category"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/category"
|
||||||
|
style="@style/FUTheme.itemValue"
|
||||||
|
android:id="@+id/notes"/>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:src="@mipmap/ic_vegan"
|
||||||
|
android:id="@+id/icon_vegan"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:src="@mipmap/ic_vegetarian"
|
||||||
|
android:id="@+id/icon_vegetarian"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:src="@mipmap/ic_msc"
|
||||||
|
android:id="@+id/icon_msc"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:src="@mipmap/ic_bio"
|
||||||
|
android:id="@+id/icon_bio"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="5dp">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/profile"
|
android:id="@+id/profile"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
app:title="Passengers"
|
app:title="Passengers"
|
||||||
app:outer_view="@layout/list_canteen_header"
|
app:outer_view="@layout/list_canteen_header"
|
||||||
app:inner_view="@layout/list_all_show_more"
|
app:inner_view="@layout/list_canteen_body"
|
||||||
app:expandOnClick="true"
|
|
||||||
app:animationDuration="300"
|
app:animationDuration="300"
|
||||||
app:startExpanded="false" />
|
app:startExpanded="true" />
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
app:icon="@drawable/ic_event"
|
app:icon="@drawable/ic_event"
|
||||||
|
|||||||
BIN
app/src/main/res/mipmap-hdpi/ic_bio.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_msc.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_vegan.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_vegetarian.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_bio.png
Normal file
|
After Width: | Height: | Size: 850 B |
BIN
app/src/main/res/mipmap-mdpi/ic_msc.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_vegan.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_vegetarian.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_bio.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_msc.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_vegan.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_vegetarian.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_bio.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_msc.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_vegan.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_vegetarian.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_bio.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_msc.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_vegan.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_vegetarian.png
Normal file
|
After Width: | Height: | Size: 14 KiB |