Example usage for android.view View getLeft

List of usage examples for android.view View getLeft

Introduction

In this page you can find the example usage for android.view View getLeft.

Prototype

@ViewDebug.CapturedViewProperty
public final int getLeft() 

Source Link

Document

Left position of this view relative to its parent.

Usage

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Fills the list from pos up to the top of the list view.
 * /*from  ww w  .  j  av  a 2 s. c  o m*/
 * @param pos
 *           The first position to put in the list
 * 
 * @param nextRight
 *           The location where the right of the item associated with pos should be drawn
 * 
 * @return The view that is currently selected
 */
private View fillLeft(int pos, int nextRight) {
    View selectedView = null;

    int end = 0;
    // if ( ( mGroupFlags & CLIP_TO_PADDING_MASK ) == CLIP_TO_PADDING_MASK ) {
    // end = mListPadding.top;
    // }

    while (nextRight > end && pos >= 0) {
        // is this the selected item?
        boolean selected = pos == mSelectedPosition;
        View child = makeAndAddView(pos, nextRight, false, mListPadding.top, selected);
        nextRight = child.getLeft() - mDividerWidth;
        if (selected) {
            selectedView = child;
        }
        pos--;
    }

    mFirstPosition = pos + 1;
    setVisibleRangeHint(mFirstPosition, mFirstPosition + getChildCount() - 1);
    return selectedView;
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * Layout a child that has been measured, preserving its top position.
 * TODO: unify with setUpChild./*from  w  ww.j  a v  a2  s.  c om*/
 * @param child The child.
 */
private void relayoutMeasuredItem(View child) {
    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childLeft = child.getLeft();
    final int childRight = childLeft + w;
    final int childTop = mListPadding.top;
    final int childBottom = childTop + h;
    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * Once the selected view as been placed, fill up the visible area above and
 * below it.//from   w  ww.j  a v  a  2s. c  o m
 *
 * @param sel The selected view
 * @param position The position corresponding to sel
 */
private void fillToLeftAndRight(View sel, int position) {
    final int dividerWidth = mDividerWidth;
    if (!mStackFromRight) {
        fillLeft(position - 1, sel.getLeft() - dividerWidth);
        adjustViewsLeftOrRight();
        fillRight(position + 1, sel.getRight() + dividerWidth);
    } else {
        fillRight(position + 1, sel.getRight() + dividerWidth);
        adjustViewsLeftOrRight();
        fillLeft(position - 1, sel.getLeft() - dividerWidth);
    }
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * Check if we have dragged the bottom of the list too low (we have pushed the
 * bottom element off the bottom of the screen when we did not need to). Correct by sliding
 * everything back up.//from  ww  w  .  j  a va2 s. co  m
 *
 * @param childCount Number of children
 */
private void correctTooLow(int childCount) {
    // First see if the first item is visible. If it is not, it is OK for the
    // bottom of the list to be pushed down.
    if (mFirstPosition == 0 && childCount > 0) {

        // Get the first child ...
        final View firstChild = getChildAt(0);

        // ... and its top edge
        final int firstLeft = firstChild.getLeft();

        // This is top of our drawable area
        final int start = mListPadding.left;

        // This is bottom of our drawable area
        final int end = (getRight() - getLeft()) - mListPadding.right;

        // This is how far the top edge of the first view is from the top of the
        // drawable area
        int leftOffset = firstLeft - start;
        View lastChild = getChildAt(childCount - 1);
        final int lastRight = lastChild.getRight();
        int lastPosition = mFirstPosition + childCount - 1;

        // Make sure we are 1) Too low, and 2) Either there are more rows below the
        // last row or the last row is scrolled off the bottom of the drawable area
        if (leftOffset > 0) {
            if (lastPosition < mItemCount - 1 || lastRight > end) {
                if (lastPosition == mItemCount - 1) {
                    // Don't pull the bottom too far up
                    leftOffset = Math.min(leftOffset, lastRight - end);
                }
                // Move everything up
                offsetChildrenLeftAndRightUnhide(-leftOffset);
                if (lastPosition < mItemCount - 1) {
                    // Fill the gap that was opened below the last position with more rows, if
                    // possible
                    fillRight(lastPosition + 1, lastChild.getRight() + mDividerWidth);
                    // Close up the remaining gap
                    adjustViewsLeftOrRight();
                }
            } else if (lastPosition == mItemCount - 1) {
                adjustViewsLeftOrRight();
            }
        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) {
    if (!ViewCompat.isLaidOut(child)) {
        // The view has not been laid out yet, so we can't obtain its bounds.
        return;//from  w  w  w  .  ja  va  2  s . c om
    }

    if (child.getWidth() <= 0 || child.getHeight() <= 0) {
        // Bounds are empty so there is nothing to dodge against, skip...
        return;
    }

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final Behavior behavior = lp.getBehavior();
    final Rect dodgeRect = acquireTempRect();
    final Rect bounds = acquireTempRect();
    bounds.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());

    if (behavior != null && behavior.getInsetDodgeRect(this, child, dodgeRect)) {
        // Make sure that the rect is within the view's bounds
        if (!bounds.contains(dodgeRect)) {
            throw new IllegalArgumentException("Rect should be within the child's bounds." + " Rect:"
                    + dodgeRect.toShortString() + " | Bounds:" + bounds.toShortString());
        }
    } else {
        dodgeRect.set(bounds);
    }

    // We can release the bounds rect now
    releaseTempRect(bounds);

    if (dodgeRect.isEmpty()) {
        // Rect is empty so there is nothing to dodge against, skip...
        releaseTempRect(dodgeRect);
        return;
    }

    final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection);

    boolean offsetY = false;
    if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) {
        int distance = dodgeRect.top - lp.topMargin - lp.mInsetOffsetY;
        if (distance < inset.top) {
            setInsetOffsetY(child, inset.top - distance);
            offsetY = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) {
        int distance = getHeight() - dodgeRect.bottom - lp.bottomMargin + lp.mInsetOffsetY;
        if (distance < inset.bottom) {
            setInsetOffsetY(child, distance - inset.bottom);
            offsetY = true;
        }
    }
    if (!offsetY) {
        setInsetOffsetY(child, 0);
    }

    boolean offsetX = false;
    if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) {
        int distance = dodgeRect.left - lp.leftMargin - lp.mInsetOffsetX;
        if (distance < inset.left) {
            setInsetOffsetX(child, inset.left - distance);
            offsetX = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) {
        int distance = getWidth() - dodgeRect.right - lp.rightMargin + lp.mInsetOffsetX;
        if (distance < inset.right) {
            setInsetOffsetX(child, distance - inset.right);
            offsetX = true;
        }
    }
    if (!offsetX) {
        setInsetOffsetX(child, 0);
    }

    releaseTempRect(dodgeRect);
}

From source file:com.appunite.list.HorizontalListView.java

private View addViewToLeft(View theView, int position) {
    int abovePosition = position - 1;
    View view = obtainView(abovePosition, mIsScrap);
    int edgeOfNewChild = theView.getLeft() - mDividerWidth;
    setupChild(view, abovePosition, edgeOfNewChild, false, mListPadding.top, false, mIsScrap[0]);
    return view;//  w w  w  .  j  a va 2s  . c o m
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Once the selected view as been placed, fill up the visible area above and below it.
 * /*  w  w  w . j  a v  a  2s. co m*/
 * @param sel
 *           The selected view
 * @param position
 *           The position corresponding to sel
 */
private void fillBeforeAndAfter(View sel, int position) {
    final int dividerWidth = mDividerWidth;
    if (!mStackFromRight) {
        fillLeft(position - 1, sel.getLeft() - dividerWidth);
        adjustViewsLeftOrRight();
        fillRight(position + 1, sel.getRight() + dividerWidth);
    } else {
        fillRight(position + 1, sel.getRight() + dividerWidth);
        adjustViewsLeftOrRight();
        fillLeft(position - 1, sel.getLeft() - dividerWidth);
    }
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Check if we have dragged the right of the list too low (we have pushed the right element off the right of the screen when
 * we did not need to). Correct by sliding everything back up.
 * /* w w  w  . j  av a  2 s .com*/
 * @param childCount
 *           Number of children
 */
private void correctTooSmall(int childCount) {
    // First see if the first item is visible. If it is not, it is OK for the
    // bottom of the list to be pushed down.
    if (mFirstPosition == 0 && childCount > 0) {

        // Get the first child ...
        final View firstChild = getChildAt(0);

        // ... and its top edge
        final int firstLeft = firstChild.getLeft();

        // This is top of our drawable area
        final int start = mListPadding.left;

        // This is bottom of our drawable area
        final int end = (getRight() - getLeft()) - mListPadding.right;

        // This is how far the top edge of the first view is from the top of the
        // drawable area
        int leftOffset = firstLeft - start;
        View lastChild = getChildAt(childCount - 1);
        final int lastRight = lastChild.getRight();
        int lastPosition = mFirstPosition + childCount - 1;

        // Make sure we are 1) Too low, and 2) Either there are more rows below the
        // last row or the last row is scrolled off the bottom of the drawable area
        if (leftOffset > 0) {
            if (lastPosition < mItemCount - 1 || lastRight > end) {
                if (lastPosition == mItemCount - 1) {
                    // Don't pull the bottom too far up
                    leftOffset = Math.min(leftOffset, lastRight - end);
                }
                // Move everything up
                offsetChildrenLeftAndRight(-leftOffset);
                if (lastPosition < mItemCount - 1) {
                    // Fill the gap that was opened below the last position with more rows, if
                    // possible
                    fillRight(lastPosition + 1, lastChild.getRight() + mDividerWidth);
                    // Close up the remaining gap
                    adjustViewsLeftOrRight();
                }
            } else if (lastPosition == mItemCount - 1) {
                adjustViewsLeftOrRight();
            }
        }
    }
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

private View addViewBefore(View theView, int position) {
    int abovePosition = position - 1;
    View view = obtainView(abovePosition, mIsScrap);
    int edgeOfNewChild = theView.getLeft() - mDividerWidth;
    setupChild(view, abovePosition, edgeOfNewChild, false, mListPadding.top, false, mIsScrap[0]);
    return view;/*w  w w . j  a  v a2  s. com*/
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

@SuppressWarnings("deprecation")
public void displaydata(final AccountData result, boolean fromcache) {
    if (getActivity() == null) {
        return;//from   w  ww  . jav  a 2  s.c o m
    }
    svAccount.setVisibility(View.VISIBLE);
    llLoading.setVisibility(View.GONE);
    unsupportedErrorView.setVisibility(View.GONE);
    answerErrorView.setVisibility(View.GONE);
    errorView.removeAllViews();

    this.fromcache = fromcache;

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext());
    final int tolerance = Integer.parseInt(sp.getString("notification_warning", "3"));

    tvAccLabel.setText(account.getLabel());
    tvAccUser.setText(account.getName());
    Library lib;
    try {
        lib = app.getLibrary(account.getLibrary());
        tvAccCity.setText(lib.getDisplayName());
    } catch (IOException e) {
        ErrorReporter.handleException(e);
        e.printStackTrace();
    } catch (JSONException e) {
        ErrorReporter.handleException(e);
    }

    /*
    Lent items
     */

    llLent.removeAllViews();

    final boolean notification_on = sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false);
    boolean notification_problems = false;

    if (tvWarning != null) {
        if (result.getWarning() != null && result.getWarning().length() > 1) {
            tvWarning.setVisibility(View.VISIBLE);
            tvWarning.setText(result.getWarning());
        } else {
            tvWarning.setVisibility(View.GONE);
        }
    }

    if (result.getLent().size() == 0) {
        TextView t1 = new TextView(getActivity());
        t1.setText(R.string.entl_none);
        llLent.addView(t1);
        tvLentHeader.setText(getActivity().getString(R.string.lent_head) + " (0)");
    } else {
        tvLentHeader
                .setText(getActivity().getString(R.string.lent_head) + " (" + result.getLent().size() + ")");

        lentManager = new ExpandingCardListManager(getActivity(), llLent) {
            @Override
            public View getView(final int position, ViewGroup container) {
                final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_lent, container,
                        false);
                LentViewHolder holder = new LentViewHolder();
                holder.findViews(v);

                final LentItem item = result.getLent().get(position);

                // Expanding and closing details
                v.setClickable(true);
                v.setFocusable(true);
                v.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (getExpandedPosition() != position) {
                            expand(position);
                        } else {
                            collapse();
                        }
                    }
                });

                if (item.getId() != null) {
                    // Connection to detail view
                    holder.ivDetails.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View clicked) {
                            Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
                            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId());
                            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v,
                                    v.getLeft(), v.getTop(), v.getWidth(), v.getHeight());
                            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
                        }
                    });
                    holder.hasDetailLink = true;
                }

                // Overview (Title/Author, Status/Deadline)
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle());
                } else {
                    setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor);
                }

                DateTimeFormatter fmt = DateTimeFormat.shortDate();

                if (item.getDeadline() != null && item.getStatus() != null) {
                    holder.tvStatus.setText(
                            fmt.print(item.getDeadline()) + " (" + Html.fromHtml(item.getStatus()) + ")");
                } else if (item.getDeadline() != null) {
                    holder.tvStatus.setText(fmt.print(new LocalDate(item.getDeadline())));
                } else {
                    setHtmlTextOrHide(item.getStatus(), holder.tvStatus);
                }

                // Detail
                setTextOrHide(item.getAuthor(), holder.tvAuthorDetail);
                setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail);
                if (item.getLendingBranch() != null && item.getHomeBranch() != null) {
                    holder.tvBranchDetail
                            .setText(Html.fromHtml(item.getLendingBranch() + " / " + item.getHomeBranch()));
                } else if (item.getLendingBranch() != null) {
                    holder.tvBranchDetail.setText(Html.fromHtml(item.getLendingBranch()));
                } else {
                    setHtmlTextOrHide(item.getHomeBranch(), holder.tvBranchDetail);
                }

                // Color codes for return dates
                if (item.getDeadline() != null) {
                    if (item.getDeadline().equals(LocalDate.now())
                            || item.getDeadline().isBefore(LocalDate.now())) {
                        holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_overdue));
                    } else if (Days.daysBetween(LocalDate.now(), item.getDeadline()).getDays() <= tolerance) {
                        holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_warning));
                    } else if (item.getDownloadData() != null) {
                        holder.vStatusColor
                                .setBackgroundColor(getResources().getColor(R.color.account_downloadable));
                    }
                } else if (item.getDownloadData() != null) {
                    holder.vStatusColor
                            .setBackgroundColor(getResources().getColor(R.color.account_downloadable));
                }

                if (item.getProlongData() != null) {
                    holder.ivProlong.setTag(item.getProlongData());
                    holder.ivProlong.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            prolong((String) arg0.getTag());
                        }
                    });
                    holder.ivProlong.setVisibility(View.VISIBLE);
                    holder.ivProlong.setAlpha(item.isRenewable() ? 255 : 100);
                } else if (item.getDownloadData() != null && app.getApi() instanceof EbookServiceApi) {
                    holder.ivDownload.setTag(item.getDownloadData());
                    holder.ivDownload.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            download((String) arg0.getTag());
                        }
                    });
                    holder.ivProlong.setVisibility(View.GONE);
                    holder.ivDownload.setVisibility(View.VISIBLE);
                } else {
                    holder.ivProlong.setVisibility(View.INVISIBLE);
                }
                v.setTag(holder);
                return v;
            }

            @Override
            public void expandView(int position, View view) {
                LentViewHolder holder = (LentViewHolder) view.getTag();
                LentItem item = result.getLent().get(position);

                holder.llDetails.setVisibility(View.VISIBLE);
                setHtmlTextOrHide(item.getTitle(), holder.tvTitleAndAuthor);
                if (holder.hasDetailLink)
                    holder.ivDetails.setVisibility(View.VISIBLE);
            }

            @Override
            public void collapseView(int position, View view) {
                LentViewHolder holder = (LentViewHolder) view.getTag();
                LentItem item = result.getLent().get(position);

                holder.llDetails.setVisibility(View.GONE);
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getAuthor());
                    holder.tvTitleAndAuthor.setVisibility(View.VISIBLE);
                }
                holder.ivDetails.setVisibility(View.GONE);
            }

            @Override
            public int getCount() {
                return result.getLent().size();
            }
        };
        lentManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() {
            private float llDataY;
            private float llDataTranslationY = 0;

            @Override
            public void beforeExpand(View unexpandedView) {
                LentViewHolder holder = (LentViewHolder) unexpandedView.getTag();
                llDataY = ViewHelper.getY(holder.llData);
            }

            @Override
            public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) {
                LentViewHolder holder = (LentViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(-heightDifference, 0);
                // Animate buttons to the side
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0));
                // Animate llData to the bottom if required
                if (ViewHelper.getY(holder.llData) != llDataY) {
                    ViewHelper.setY(holder.llData, llDataY);
                    llDataTranslationY = ViewHelper.getTranslationY(holder.llData);
                    anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0));
                } else {
                    llDataTranslationY = 0;
                }
                return anims;
            }

            @Override
            public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) {
                LentViewHolder holder = (LentViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(0, heightDifference);
                // Animate buttons back
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference));
                // Animate llData back
                anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY));
                return anims;
            }

            @Override
            public void onCollapseAnimationEnd() {
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0);
                } else {
                    // phone
                    ViewHelper.setTranslationY(tvResHeader, 0);
                    ViewHelper.setTranslationY(llRes, 0);
                    ViewHelper.setTranslationY(tvAge, 0);
                    ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0);
                }
            }

            private Collection<Animator> getAnimations(float from, float to) {
                List<Animator> animators = new ArrayList<>();
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    if (result.getLent().size() >= result.getReservations().size()) {
                        animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY",
                                from, to));
                    }
                } else {
                    // phone
                    animators.add(ObjectAnimator.ofFloat(tvResHeader, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(llRes, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY",
                            from, to));
                }
                return animators;
            }
        });

        for (final LentItem item : result.getLent()) {
            try {
                if (notification_on && item.getDeadline() == null && !item.isEbook()) {
                    notification_problems = true;
                }
            } catch (Exception e) {
                notification_problems = true;
            }
        }
    }

    if (notification_problems) {
        if (tvError != null) {
            tvError.setVisibility(View.VISIBLE);
            tvError.setText(R.string.notification_problems);
        }
    }

    /*
    Reservations
     */
    llRes.removeAllViews();
    if (result.getReservations().size() == 0) {
        TextView t1 = new TextView(getActivity());
        t1.setText(R.string.reservations_none);
        llRes.addView(t1);
        tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (0)");
    } else {
        tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " ("
                + result.getReservations().size() + ")");
        resManager = new ExpandingCardListManager(getActivity(), llRes) {
            @Override
            public View getView(final int position, ViewGroup container) {
                final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_reservation, llRes,
                        false);
                ReservationViewHolder holder = new ReservationViewHolder();
                holder.findViews(v);

                final ReservedItem item = result.getReservations().get(position);

                // Expanding and closing details
                v.setClickable(true);
                v.setFocusable(true);
                v.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (getExpandedPosition() != position) {
                            expand(position);
                        } else {
                            collapse();
                        }
                    }
                });

                if (item.getId() != null) {
                    // Connection to detail view
                    holder.ivDetails.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View clicked) {
                            Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
                            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId());
                            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v,
                                    v.getLeft(), v.getTop(), v.getWidth(), v.getHeight());
                            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
                        }
                    });
                    holder.hasDetailLink = true;
                }

                // Overview (Title/Author, Ready/Expire)
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle());
                } else {
                    setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor);
                }

                DateTimeFormatter fmt = DateTimeFormat.shortDate();

                StringBuilder status = new StringBuilder();
                if (item.getStatus() != null)
                    status.append(item.getStatus());
                boolean needsBraces = item.getStatus() != null
                        && (item.getReadyDate() != null || item.getExpirationDate() != null);
                if (needsBraces)
                    status.append(" (");
                if (item.getReadyDate() != null) {
                    status.append(getString(R.string.reservation_expire_until)).append(" ")
                            .append(fmt.print(item.getReadyDate()));
                }
                if (item.getExpirationDate() != null) {
                    if (item.getReadyDate() != null)
                        status.append(", ");
                    status.append(fmt.print(item.getExpirationDate()));
                }
                if (needsBraces)
                    status.append(")");
                if (status.length() > 0) {
                    holder.tvStatus.setText(Html.fromHtml(status.toString()));
                } else {
                    holder.tvStatus.setVisibility(View.GONE);
                }

                // Detail
                setTextOrHide(item.getAuthor(), holder.tvAuthorDetail);
                setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail);
                setHtmlTextOrHide(item.getBranch(), holder.tvBranchDetail);

                if (item.getBookingData() != null) {
                    holder.ivBooking.setTag(item.getBookingData());
                    holder.ivBooking.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            bookingStart((String) arg0.getTag());
                        }
                    });
                    holder.ivBooking.setVisibility(View.VISIBLE);
                    holder.ivCancel.setVisibility(View.GONE);
                } else if (item.getCancelData() != null) {
                    holder.ivCancel.setTag(item.getCancelData());
                    holder.ivCancel.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            cancel((String) arg0.getTag());
                        }
                    });
                    holder.ivCancel.setVisibility(View.VISIBLE);
                    holder.ivBooking.setVisibility(View.GONE);
                } else {
                    holder.ivCancel.setVisibility(View.INVISIBLE);
                    holder.ivBooking.setVisibility(View.GONE);
                }
                v.setTag(holder);
                return v;
            }

            @Override
            public void expandView(int position, View view) {
                ReservationViewHolder holder = (ReservationViewHolder) view.getTag();
                ReservedItem item = result.getReservations().get(position);

                holder.llDetails.setVisibility(View.VISIBLE);
                setTextOrHide(item.getTitle(), holder.tvTitleAndAuthor);
                if (holder.hasDetailLink)
                    holder.ivDetails.setVisibility(View.VISIBLE);
            }

            @Override
            public void collapseView(int position, View view) {
                ReservationViewHolder holder = (ReservationViewHolder) view.getTag();
                ReservedItem item = result.getReservations().get(position);

                holder.llDetails.setVisibility(View.GONE);
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getAuthor());
                    holder.tvTitleAndAuthor.setVisibility(View.VISIBLE);
                }
                holder.ivDetails.setVisibility(View.GONE);
            }

            @Override
            public int getCount() {
                return result.getReservations().size();
            }
        };
        resManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() {
            private float llDataY;
            private float llDataTranslationY = 0;

            @Override
            public void beforeExpand(View unexpandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) unexpandedView.getTag();
                llDataY = ViewHelper.getY(holder.llData);
            }

            @Override
            public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(-heightDifference, 0);
                // Animate buttons to the side
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0));
                // Animate llData to the bottom if required
                if (ViewHelper.getY(holder.llData) != llDataY) {
                    ViewHelper.setY(holder.llData, llDataY);
                    llDataTranslationY = ViewHelper.getTranslationY(holder.llData);
                    anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0));
                } else {
                    llDataTranslationY = 0;
                }
                return anims;
            }

            @Override
            public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(0, heightDifference);
                // Animate buttons back
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference));
                // Animate llData back
                anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY));
                return anims;
            }

            @Override
            public void onCollapseAnimationEnd() {
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0);
                } else {
                    // phone
                    ViewHelper.setTranslationY(tvAge, 0);
                    ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0);
                }
            }

            private Collection<Animator> getAnimations(float from, float to) {
                List<Animator> animators = new ArrayList<>();
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    if (result.getReservations().size() >= result.getLent().size()) {
                        animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY",
                                from, to));
                    }
                } else {
                    // phone
                    animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY",
                            from, to));
                }
                return animators;
            }
        });
    }

    if (result.getPendingFees() != null) {
        tvPendingFeesLabel.setVisibility(View.VISIBLE);
        tvPendingFees.setVisibility(View.VISIBLE);
        tvPendingFees.setText(result.getPendingFees());
    } else {
        tvPendingFeesLabel.setVisibility(View.GONE);
        tvPendingFees.setVisibility(View.GONE);
    }
    if (result.getValidUntil() != null) {
        tvValidUntilLabel.setVisibility(View.VISIBLE);
        tvValidUntil.setVisibility(View.VISIBLE);
        tvValidUntil.setText(result.getValidUntil());
    } else {
        tvValidUntilLabel.setVisibility(View.GONE);
        tvValidUntil.setVisibility(View.GONE);
    }
    refreshage();
}