List of usage examples for android.view View getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.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.//from w w w . j av a 2 s. c om * * @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 scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); 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 hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } transformPages(); mCalledSuper = true; }
From source file:com.android.launcher3.ViewPager.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 ww. j a v a 2s . 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. */ @CallSuper protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. mPosition = position; off = offset; if (mDecorChildCount > 0) { final int scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); 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 hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } dispatchOnPageScrolled(position, offset, offsetPixels); if (mPageTransformer != null) { final int scrollX = getScrollX(); 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.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:com.appunite.list.HorizontalListView.java
/** * Re-measure a child, and if its width changes, lay it out preserving its * top, and adjust the children below it appropriately. * @param child The child/*from ww w .jav a 2 s . co m*/ * @param childIndex The view group index of the child. * @param numChildren The number of children in the view group. */ private void measureAndAdjustRight(View child, int childIndex, int numChildren) { int oldWidth = child.getWidth(); measureItem(child); if (child.getMeasuredWidth() != oldWidth) { // lay out the view, preserving its top relayoutMeasuredItem(child); // adjust views below appropriately final int widthDelta = child.getMeasuredWidth() - oldWidth; for (int i = childIndex + 1; i < numChildren; i++) { getChildAt(i).offsetLeftAndRight(widthDelta); } } }
From source file:com.av.remusic.widget.RoundViewPager.java
/** * This method will be invoked when the currentPosition 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.//from ww w .ja v a2 s . c om * * @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. */ @CallSuper 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 scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); 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 hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } dispatchOnPageScrolled(position, offset, offsetPixels); if (mPageTransformer != null) { final int scrollX = getScrollX(); 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.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:com.bahrini.pager.pager.RtlSupportViewPager.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.//from w w w . j a v a 2 s .c om * * @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 scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); 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 hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mSlidingTabPageChangeListener != null) { mSlidingTabPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mPageTransformer != null) { final int scrollX = getScrollX(); 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.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:com.example.sky.test.view.ViewPager.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 . 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. */ @CallSuper 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 scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final ViewPager.LayoutParams lp = (ViewPager.LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } dispatchOnPageScrolled(position, offset, offsetPixels); if (mPageTransformer != null) { final int scrollX = getScrollX(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final ViewPager.LayoutParams lp = (ViewPager.LayoutParams) child.getLayoutParams(); if (lp.isDecor) continue; final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
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 w w.ja v a2s .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(); }
From source file:com.android.launcher2.Launcher.java
/** * Helper method for the cameraZoomIn/cameraZoomOut animations * @param view The view being animated/*from ww w. ja va2s .c o m*/ * @param scaleFactor The scale factor used for the zoom */ private void setPivotsForZoom(View view, float scaleFactor) { view.setPivotX(view.getWidth() / 2.0f); view.setPivotY(view.getHeight() / 2.0f); }
From source file:com.android.launcher2.Workspace.java
/** * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. * Responsibility for the bitmap is transferred to the caller. */// w w w .j a va 2s . c o m private Bitmap createDragOutline(View v, Canvas canvas, int padding) { final int outlineColor = getResources().getColor(android.R.color.holo_blue_light); final Bitmap b = Bitmap.createBitmap(v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); canvas.setBitmap(b); drawDragView(v, canvas, padding, true); mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor); canvas.setBitmap(null); return b; }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.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 a 2 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) { // TODO This is where I start getting tired. Refactor this better later. if (isOrientationHorizontal()) { final int scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); 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 hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } else { 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 (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mPageTransformer != null) { final boolean horizontal = isOrientationHorizontal(); final int scroll = horizontal ? getScrollX() : 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; float transformPos; if (horizontal) { transformPos = (float) (child.getLeft() - scroll) / getClientWidth(); } else { transformPos = (float) (child.getTop() - scroll) / getClientHeight(); } mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }