Example usage for android.view View getWidth

List of usage examples for android.view View getWidth

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getWidth() 

Source Link

Document

Return the width of your view.

Usage

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//  www  .j a  va 2 s.c om

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static String getMapStaticImageUri(final double lat, final double lng, final View v) {
    if (v == null)
        return null;
    final int wSpec = MeasureSpec.makeMeasureSpec(v.getWidth(), MeasureSpec.UNSPECIFIED);
    final int hSpec = MeasureSpec.makeMeasureSpec(v.getHeight(), MeasureSpec.UNSPECIFIED);
    v.measure(wSpec, hSpec);//from   ww  w.  j av  a 2  s  . c om
    return getMapStaticImageUri(lat, lng, 12, v.getMeasuredWidth(), v.getMeasuredHeight(),
            v.getResources().getConfiguration().locale);
}

From source file:com.android.leanlauncher.Workspace.java

public void beginDragShared(View child, DragSource source) {
    child.clearFocus();/*from   w w w .  java 2 s  .  c o m*/
    child.setPressed(false);

    // The outline is used to visualize where the item will land if dropped
    mDragOutline = createDragOutline(child, DRAG_BITMAP_PADDING);

    mLauncher.onDragStarted(child);
    // The drag bitmap follows the touch point around on the screen
    AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING);
    final Bitmap b = createDragBitmap(child, padding);

    final int bmpWidth = b.getWidth();
    final int bmpHeight = b.getHeight();

    float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
    int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
    int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - padding.get() / 2);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    Point dragVisualizeOffset = null;
    Rect dragRect = null;
    if (child instanceof BubbleTextView) {
        int iconSize = grid.iconSizePx;
        int top = child.getPaddingTop();
        int left = (bmpWidth - iconSize) / 2;
        int right = left + iconSize;
        int bottom = top + iconSize;
        dragLayerY += top;
        // Note: The drag region is used to calculate drag layer offsets, but the
        // dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
        dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2);
        dragRect = new Rect(left, top, right, bottom);
    }

    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }

    if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) {
        String msg = "Drag started with a view that has no tag set. This "
                + "will cause a crash (issue 11627249) down the line. " + "View: " + child + "  tag: "
                + child.getTag();
        throw new IllegalStateException(msg);
    }

    DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
            DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
    dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());

    b.recycle();
}

From source file:com.battlelancer.seriesguide.ui.ShowFragment.java

private void populateShow() {
    if (mShowCursor == null) {
        return;/*from w  w w  . j a va  2  s  . com*/
    }

    // title
    mShowTitle = mShowCursor.getString(ShowQuery.TITLE);
    mShowPoster = mShowCursor.getString(ShowQuery.POSTER);

    // status
    if (mShowCursor.getInt(ShowQuery.STATUS) == 1) {
        mTextViewStatus.setTextColor(getResources().getColor(
                Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.textColorSgGreen)));
        mTextViewStatus.setText(getString(R.string.show_isalive));
    } else {
        mTextViewStatus.setTextColor(Color.GRAY);
        mTextViewStatus.setText(getString(R.string.show_isnotalive));
    }

    // release time
    String releaseDay = mShowCursor.getString(ShowQuery.RELEASE_DAY);
    long releaseTime = mShowCursor.getLong(ShowQuery.RELEASE_TIME_MS);
    String releaseCountry = mShowCursor.getString(ShowQuery.RELEASE_COUNTRY);
    if (!TextUtils.isEmpty(releaseDay)) {
        String[] values = TimeTools.formatToShowReleaseTimeAndDay(getActivity(), releaseTime, releaseCountry,
                releaseDay);
        mTextViewReleaseTime.setText(values[1] + " " + values[0]);
    } else {
        mTextViewReleaseTime.setText(null);
    }

    // runtime
    mTextViewRuntime.setText(getString(R.string.runtime_minutes, mShowCursor.getInt(ShowQuery.RUNTIME)));

    // network
    mTextViewNetwork.setText(mShowCursor.getString(ShowQuery.NETWORK));

    // favorite button
    final boolean isFavorite = mShowCursor.getInt(ShowQuery.IS_FAVORITE) == 1;
    mButtonFavorite.setEnabled(true);
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(mButtonFavorite, 0,
            Utils.resolveAttributeToResourceId(getActivity().getTheme(),
                    isFavorite ? R.attr.drawableStar : R.attr.drawableStar0),
            0, 0);
    mButtonFavorite.setText(isFavorite ? R.string.context_unfavorite : R.string.context_favorite);
    CheatSheet.setup(mButtonFavorite, isFavorite ? R.string.context_unfavorite : R.string.context_favorite);
    mButtonFavorite.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // disable until action is complete
            v.setEnabled(false);
            ShowTools.get(v.getContext()).storeIsFavorite(getShowTvdbId(), !isFavorite);
        }
    });

    // overview
    mTextViewOverview.setText(mShowCursor.getString(ShowQuery.OVERVIEW));

    // country for release time calculation
    // show "unknown" if country is not supported
    mTextViewReleaseCountry.setText(
            TimeTools.isUnsupportedCountry(releaseCountry) ? getString(R.string.unknown) : releaseCountry);

    // original release
    String firstRelease = mShowCursor.getString(ShowQuery.FIRST_RELEASE);
    Utils.setValueOrPlaceholder(mTextViewFirstRelease,
            TimeTools.getShowReleaseYear(firstRelease, releaseTime, releaseCountry));

    // content rating
    Utils.setValueOrPlaceholder(mTextViewContentRating, mShowCursor.getString(ShowQuery.CONTENT_RATING));
    // genres
    Utils.setValueOrPlaceholder(mTextViewGenres,
            Utils.splitAndKitTVDBStrings(mShowCursor.getString(ShowQuery.GENRES)));

    // TVDb rating
    String tvdbRating = mShowCursor.getString(ShowQuery.TVDB_RATING);
    if (!TextUtils.isEmpty(tvdbRating)) {
        mTextViewTvdbRating.setText(tvdbRating);
    }

    // last edit
    long lastEditRaw = mShowCursor.getLong(ShowQuery.LAST_EDIT_MS);
    if (lastEditRaw > 0) {
        mTextViewLastEdit.setText(DateUtils.formatDateTime(getActivity(), lastEditRaw * 1000,
                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME));
    } else {
        mTextViewLastEdit.setText(R.string.unknown);
    }

    // IMDb button
    String imdbId = mShowCursor.getString(ShowQuery.IMDBID);
    ServiceUtils.setUpImdbButton(imdbId, mButtonImdb, TAG, getActivity());

    // TVDb button
    ServiceUtils.setUpTvdbButton(getShowTvdbId(), mButtonTvdb, TAG);

    // trakt button
    ServiceUtils.setUpTraktButton(getShowTvdbId(), mButtonTrakt, TAG);

    // web search button
    ServiceUtils.setUpWebSearchButton(mShowTitle, mButtonWebSearch, TAG);

    // shout button
    mButtonComments.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), TraktShoutsActivity.class);
            i.putExtras(TraktShoutsActivity.createInitBundleShow(mShowTitle, getShowTvdbId()));
            ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat
                    .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle());
            fireTrackerEvent("Shouts");
        }
    });

    // poster, full screen poster button
    final View posterContainer = getView().findViewById(R.id.containerShowPoster);
    final ImageView posterView = (ImageView) posterContainer.findViewById(R.id.imageViewShowPoster);
    Utils.loadPoster(getActivity(), posterView, mShowPoster);
    posterContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent fullscreen = new Intent(getActivity(), FullscreenImageActivity.class);
            fullscreen.putExtra(FullscreenImageActivity.InitBundle.IMAGE_PATH,
                    TheTVDB.buildScreenshotUrl(mShowPoster));
            ActivityCompat.startActivity(getActivity(), fullscreen, ActivityOptionsCompat
                    .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle());
        }
    });

    // background
    ImageView background = (ImageView) getView().findViewById(R.id.imageViewShowPosterBackground);
    Utils.loadPosterBackground(getActivity(), background, mShowPoster);

    onLoadTraktRatings(true);
}

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.j  ava 2 s  .c o m
    }

    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.aliyun.homeshell.Folder.java

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    View parent = mLauncher.getDragLayer();
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    int contentWidth = mContentWidth;
    int contentHeight = mContentHeight;
    int width = getPaddingLeft() + getPaddingRight() + contentWidth;
    int height = getPaddingTop() + getPaddingBottom() + contentHeight + mFolderNameHeight
            + mFolderNameContentGap + mPageIndicatorHeight;
    lp.width = width;/*w  w w  .j a  v a  2s  .  c o  m*/
    lp.height = height;
    lp.x = (parent.getWidth() - width) / 2;
    lp.y = (parent.getHeight() - height) / 2 - mFolderNameContentGap;

    int contentWidthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY);
    int contentHeightSpec = MeasureSpec.makeMeasureSpec(contentHeight, MeasureSpec.EXACTLY);
    mFolderViewPager.measure(contentWidthSpec, contentHeightSpec);

    contentWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
    contentHeightSpec = MeasureSpec.makeMeasureSpec(mPageIndicatorHeight, MeasureSpec.AT_MOST);
    mPageIndicator.measure(contentWidthSpec, contentHeightSpec);
    int titleWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
    int titleHeightSpec = MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY);
    mFolderName.measure(titleWidthSpec, titleHeightSpec);
    setMeasuredDimension(width, height);
}

From source file:com.android.internal.widget.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  . j av 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.
 */
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 (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) / getPaddedWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final boolean isLayoutRtl = isLayoutRtlSupport();
    if (isLayoutRtl) {
        mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    } else {/*from w w w. j ava  2 s  .c om*/
        mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    }
    final int width = r - l;
    final int paddingStart = isLayoutRtl ? getPaddingRight() : getPaddingLeft();
    final int paddingEnd = isLayoutRtl ? getPaddingLeft() : getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingStart;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, width - paddingEnd - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            final int lpMargin = isLayoutRtl ? lp.rightMargin : lp.leftMargin;
            lp.dimWhenOffset = xStart + lpMargin + range + childWidth / 2 > width - paddingEnd;
            final int pos = (int) (range * mSlideOffset);
            xStart += pos + lpMargin;
            mSlideOffset = (float) pos / mSlideRange;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childRight;
        final int childLeft;
        if (isLayoutRtl) {
            childRight = width - xStart + offset;
            childLeft = childRight - childWidth;
        } else {
            childLeft = xStart - offset;
            childRight = childLeft + childWidth;
        }

        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when
            // nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void showMenuItemToast(final View v, final CharSequence text, final boolean isBottomBar) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    v.getLocationOnScreen(screenPos);/*from  www.j  ava  2 s  .  c  o  m*/
    v.getWindowVisibleDisplayFrame(displayFrame);
    final int width = v.getWidth();
    final int height = v.getHeight();
    final int screenWidth = v.getResources().getDisplayMetrics().widthPixels;
    final Toast cheatSheet = Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT);
    if (isBottomBar) {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    } else {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
    }
    cheatSheet.show();
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

private void startAppShortcutOrInfoActivity(View v) {
    Object tag = v.getTag();/*from   w w w  .java 2  s .  c  o  m*/
    final ShortcutInfo shortcut;
    final Intent intent;
    if (tag instanceof ShortcutInfo) {
        shortcut = (ShortcutInfo) tag;
        intent = shortcut.intent;
        int[] pos = new int[2];
        v.getLocationOnScreen(pos);
        intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()));

    } else if (tag instanceof AppInfo) {
        shortcut = null;
        intent = ((AppInfo) tag).intent;
    } else {
        throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
    }

    boolean success = startActivitySafely(v, intent, tag);

    if (success && v instanceof BubbleTextView) {
        mWaitingForResume = (BubbleTextView) v;
        mWaitingForResume.setStayPressed(true);
    }
}