Example usage for android.view View getTop

List of usage examples for android.view View getTop

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

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

@SuppressWarnings("deprecation")
public void displaydata(final AccountData result, boolean fromcache) {
    if (getActivity() == null) {
        return;/*from   ww w  . j  a v  a2  s.  c  om*/
    }
    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();
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Log.i(TAG, "drawChild()");
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();
    int clipTop = 0, clipBottom = getHeight();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                Log.i(TAG, "drawChild() -- 0");
                continue;
            }/*  ww w.  jav a2  s .  c  om*/
            switch (getDrawerViewAbsoluteGravity(v)) {
            case Gravity.LEFT:
                Log.i(TAG, "drawChild() -- 1");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                    final int vright = v.getRight();
                    if (vright > clipLeft)
                        clipLeft = vright;
                }
                break;
            case Gravity.RIGHT:
                Log.i(TAG, "drawChild() -- 2");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.RIGHT)) {
                    final int vleft = v.getLeft();
                    if (vleft < clipRight)
                        clipRight = vleft;
                }
                break;
            case Gravity.TOP:
                Log.i(TAG, "drawChild() -- 3");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                    final int vbottom = v.getBottom();
                    if (vbottom > clipTop) {
                        clipTop = vbottom;
                    }
                }
                break;
            case Gravity.BOTTOM:
                Log.i(TAG, "drawChild() -- 4");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.BOTTOM)) {
                    final int vtop = v.getTop();
                    if (vtop < clipBottom) {
                        clipBottom = vtop;
                    }
                }
                break;
            default:
                Log.i(TAG, "drawChild() -- 5");
                final int vtop = v.getTop();
                if (vtop < clipBottom) {
                    clipBottom = vtop;
                }
                break;
            }
        }
        canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        Log.i(TAG, "drawChild() -- drawingContent");
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);
        canvas.drawRect(clipLeft, clipTop, clipRight, clipBottom, mScrimPaint);
    } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
        Log.i(TAG, "drawChild() -- LEFT");
        final int shadowWidth = mShadowLeft.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeft.setAlpha((int) (0xff * alpha));
        mShadowLeft.draw(canvas);
    } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
        Log.i(TAG, "drawChild() -- Gravity.RIGHT");
        final int shadowWidth = mShadowRight.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
        Log.i(TAG, "drawChild() -- Gravity.TOP");
        final int shadowHeight = mShadowTop.getIntrinsicHeight();
        final int childBottom = child.getBottom();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight);
        mShadowTop.setAlpha((int) (0xff * alpha));
        mShadowTop.draw(canvas);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        Log.i(TAG, "drawChild() -- Gravity.BOTTOM");
        final int shadowHeight = mShadowBottom.getIntrinsicWidth();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    }
    return result;
}

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

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

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

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }/*from ww  w .  java 2 s  .  com*/
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToTop = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToTop);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getLeft();
        invalidate();
    }
    return scroll;
}

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

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectLeftWithinChild = rect.left;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectLeftWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }/*from w ww.  jav a2s  .  c om*/
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.right < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToLeft = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToLeft);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getTop();
        invalidate();
    }
    return scroll;
}

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

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int height = getHeight();
    int listUnfadedTop = getScrollY();
    int listUnfadedBottom = listUnfadedTop + height;
    final int fadingEdge = getVerticalFadingEdgeLength();

    if (showingTopFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedTop += fadingEdge;
        }//  w  ww.  j a va2  s.c  o  m
    }

    int childCount = getChildCount();
    int bottomOfBottomChild = getChildAt(childCount - 1).getBottom();

    if (showingBottomFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (bottomOfBottomChild - fadingEdge))) {
            listUnfadedBottom -= fadingEdge;
        }
    }

    int scrollYDelta = 0;

    if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.height() > height) {
            // just enough to get screen size chunk on
            scrollYDelta += (rect.top - listUnfadedTop);
        } else {
            // get entire rect at bottom of screen
            scrollYDelta += (rect.bottom - listUnfadedBottom);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToBottom = bottomOfBottomChild - listUnfadedBottom;
        scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
    } else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.height() > height) {
            // screen size chunk
            scrollYDelta -= (listUnfadedBottom - rect.bottom);
        } else {
            // entire rect at top
            scrollYDelta -= (listUnfadedTop - rect.top);
        }

        // make sure we aren't scrolling any further than the top our children
        int top = getChildAt(0).getTop();
        int deltaToTop = top - listUnfadedTop;
        scrollYDelta = Math.max(scrollYDelta, deltaToTop);
    }

    final boolean scroll = scrollYDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollYDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedTop = child.getTop();
        invalidate();
    }
    return scroll;
}

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

/**
 * Make sure views are touching the top or bottom edge, as appropriate for
 * our gravity//from  w  ww .j  a  v  a 2 s.c om
 */
private void adjustViewsUpOrDown() {
    final int childCount = getChildCount();
    int delta;

    if (childCount > 0) {
        View child;

        if (!mStackFromBottom) {
            // Uh-oh -- we came up short. Slide all views up to make them
            // align with the top
            child = getChildAt(0);
            delta = child.getTop() - mListPadding.top;
            if (mFirstPosition != 0) {
                // It's OK to have some space above the first item if it is
                // part of the vertical spacing
                delta -= mDividerHeight;
            }
            if (delta < 0) {
                // We only are looking to see if we are too low, not too high
                delta = 0;
            }
        } else {
            // we are too high, slide all views down to align with bottom
            child = getChildAt(childCount - 1);
            delta = child.getBottom() - (getHeight() - mListPadding.bottom);

            if (mFirstPosition + childCount < mItemCount) {
                // It's OK to have some space below the last item if it is
                // part of the vertical spacing
                delta += mDividerHeight;
            }

            if (delta > 0) {
                delta = 0;
            }
        }

        if (delta != 0) {
            offsetChildrenTopAndBottomUnhide(-delta);
        }
    }
}

From source file:com.dian.diabetes.widget.VerticalViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns.//  ww  w.j  a  va2 s .c o m
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollY = getScrollY();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        final int height = getHeight();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            int childTop = 0;
            switch (height) {
            default:
                childTop = paddingTop;
                break;
            case Gravity.TOP:
                childTop = paddingTop;
                paddingTop += child.getHeight();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                break;
            case Gravity.RIGHT:
                childTop = height - paddingBottom - child.getMeasuredHeight();
                paddingBottom += child.getMeasuredHeight();
                break;
            }
            childTop += scrollY;

            final int childOffset = childTop - child.getTop();
            if (childOffset != 0) {
                child.offsetTopAndBottom(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollY = getScrollY();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getTop() - scrollY) / getClientHeight();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

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

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.mBehavior != null) {
        final float scrimAlpha = lp.mBehavior.getScrimOpacity(this, child);
        if (scrimAlpha > 0f) {
            if (mScrimPaint == null) {
                mScrimPaint = new Paint();
            }/*www. j  a  v  a2s  .  c o  m*/
            mScrimPaint.setColor(lp.mBehavior.getScrimColor(this, child));
            mScrimPaint.setAlpha(MathUtils.constrain(Math.round(255 * scrimAlpha), 0, 255));

            final int saved = canvas.save();
            if (child.isOpaque()) {
                // If the child is opaque, there is no need to draw behind it so we'll inverse
                // clip the canvas
                canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(),
                        Region.Op.DIFFERENCE);
            }
            // Now draw the rectangle for the scrim
            canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                    getHeight() - getPaddingBottom(), mScrimPaint);
            canvas.restoreToCount(saved);
        }
    }
    return super.drawChild(canvas, child, drawingTime);
}

From source file:com.candykk.calculator.viewpager.VerticalViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*  w w w  .jav  a2  s .co m*/
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollY = getScrollY();

        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();

        final int height = getHeight();

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            int childTop = 0;

            switch (vgrav) {
            default:
                childTop = paddingTop;
                break;
            case Gravity.TOP:
                childTop = paddingTop;
                paddingTop += child.getHeight();
                break;
            case Gravity.CENTER_VERTICAL:
                childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                break;
            case Gravity.BOTTOM:
                childTop = height - paddingBottom - child.getMeasuredHeight();
                paddingBottom += child.getMeasuredHeight();
                break;
            }
            childTop += scrollY;

            final int childOffset = childTop - child.getTop();
            if (childOffset != 0) {
                child.offsetTopAndBottom(childOffset);
            }
        }
    }

    if (mSeenPositionMin < 0 || position < mSeenPositionMin) {
        mSeenPositionMin = position;
    }
    if (mSeenPositionMax < 0 || Math.ceil(position + offset) > mSeenPositionMax) {
        mSeenPositionMax = position + 1;
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollY = getScrollY();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getTop() - scrollY) / getHeight();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}