Example usage for android.view View getX

List of usage examples for android.view View getX

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "drawing")
public float getX() 

Source Link

Document

The visual x position of this view, in pixels.

Usage

From source file:im.actor.sdk.view.emoji.keyboard.emoji.EmojiKeyboard.java

@Override
protected View createView() {
    final View emojiPagerView = LayoutInflater.from(activity).inflate(R.layout.emoji_smiles_pager, null);

    final ViewPager emojiPager = (ViewPager) emojiPagerView.findViewById(R.id.emoji_pager);

    final PagerSlidingTabStrip emojiPagerIndicator = (PagerSlidingTabStrip) emojiPagerView
            .findViewById(R.id.emoji_pager_indicator);
    View backspace = emojiPagerView.findViewById(R.id.backspace);
    final View backToSmiles = emojiPagerView.findViewById(R.id.back_to_smiles);
    final View indicatorContainer = emojiPagerView.findViewById(R.id.indicator_container);
    stickerIndicatorContainer = emojiPagerView.findViewById(R.id.sticker_indicator_container);
    stickerSwitchContainer = emojiPagerView.findViewById(R.id.sticker_switch_container);

    emojiPagerIndicator.setTabBackground(R.drawable.clickable_background);
    emojiPagerIndicator.setIndicatorColorResource(R.color.primary);
    emojiPagerIndicator.setIndicatorHeight(Screen.dp(2));
    emojiPagerIndicator.setDividerColor(0x00000000);
    emojiPagerIndicator.setUnderlineHeight(0);
    emojiPagerIndicator.setTabLayoutParams(new LinearLayout.LayoutParams(Screen.dp(48), Screen.dp(48)));

    backspace.setOnTouchListener(new RepeatListener(500, 100, new OnClickListener() {
        @Override//from   www .  ja  va  2s .c o m
        public void onClick(View v) {
            onBackspaceClick(v);
        }
    }));

    mEmojisAdapter = new SmilePagerAdapter(this);
    mEmojisAdapter.setTabs(emojiPagerIndicator);
    emojiPager.setAdapter(mEmojisAdapter);
    emojiPagerIndicator.setViewPager(emojiPager);

    backToSmiles.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            emojiPager.setCurrentItem(3, false);

            ObjectAnimator oa = ObjectAnimator.ofFloat(indicatorContainer, "translationX", 0, 0);
            oa.setDuration(0);
            oa.start();
            if (stickerIndicatorContainer.getVisibility() == View.INVISIBLE) {
                stickerIndicatorContainer.setVisibility(View.VISIBLE);
            }
            ObjectAnimator oas = ObjectAnimator.ofFloat(stickerIndicatorContainer, "translationX",
                    Screen.getWidth(), Screen.getWidth());
            oas.setDuration(0);
            oas.start();

            emojiPager.setCurrentItem(1, true);

        }
    });

    final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) stickerIndicatorContainer.getLayoutParams();

    emojiPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == 4) {

                ObjectAnimator oa = ObjectAnimator.ofFloat(indicatorContainer, "translationX",
                        indicatorContainer.getX(), -positionOffsetPixels);
                oa.setDuration(0);
                oa.start();
                if (stickerIndicatorContainer.getVisibility() == View.INVISIBLE) {
                    stickerIndicatorContainer.setVisibility(View.VISIBLE);
                }
                ObjectAnimator oas = ObjectAnimator.ofFloat(stickerIndicatorContainer, "translationX",
                        stickerIndicatorContainer.getX() + Screen.getWidth(),
                        -positionOffsetPixels + Screen.getWidth());
                oas.setDuration(0);
                oas.start();

            }
        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    //emojiPagerIndicator.setLayoutParams(new RelativeLayout.LayoutParams(Screen.dp(58 * mEmojisAdapter.getCount()), Screen.dp(48)));
    //        emojiPager.postDelayed(new Runnable() {
    //            @Override
    //            public void run() {
    //                emojiPager.setAlpha(0f);
    //                emojiPagerIndicator.setAlpha(0f);
    //                animateView(emojiPager);
    //                animateView(emojiPagerIndicator);
    //                emojiPager.setAdapter(mEmojisAdapter);
    //                emojiPagerIndicator.setViewPager(emojiPager);
    //            }
    //        }, BINDING_DELAY);

    if (SmilesPack.getRecent().size() == 0) {
        emojiPager.setCurrentItem(1);
    }

    return emojiPagerView;
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

/**
 * @return Whether we should intercept a gesture to open Quick Settings.
 *///ww w . j av a  2 s .c om
private boolean shouldQuickSettingsIntercept(float x, float y, float yDiff) {
    if ((!mQsExpansionEnabled || mCollapsedOnDown) && mQsExpansionEnabled) {
        return false;
    }
    View header = mKeyguardShowing ? mKeyguardStatusBar : mHeader;
    boolean onHeader = x >= header.getX() && x <= header.getX() + header.getWidth() && y >= header.getTop()
            && y <= header.getBottom();
    if (mQsExpanded) {
        return onHeader || (mScrollView.isScrolledToBottom() && yDiff < 0) && isInQsArea(x, y);
    } else {
        return onHeader;
    }
}

From source file:cc.flydev.launcher.Page.java

public int getLayoutTransitionOffsetForPage(int index) {
    if (mPageScrolls == null || index >= mPageScrolls.length || index < 0) {
        return 0;
    } else {/*  w ww.  j a v a  2s . c o m*/
        View child = getChildAt(index);
        int scrollOffset = (getViewportWidth() - child.getMeasuredWidth()) / 2;
        int baselineX = mPageScrolls[index] + scrollOffset + getViewportOffsetX();
        return (int) (child.getX() - baselineX);
    }
}

From source file:com.minoon.stackviewpagersample.StackViewPager.java

/**
 * ??Overlap?View????/*from   www.j  av  a  2s . co m*/
 *
 * @return
 */
private int getOverlapScrollX() {
    View v = getOverlapView();
    return v == null ? 0 : (int) (getClientWidth() - v.getX());
}

From source file:com.minoon.stackviewpagersample.StackViewPager.java

private void scrollDeltaOverlap(float dx) {
    View v = getOverlapView();
    if (v != null) {
        float positionX = v.getX() - dx;
        // 0 ~ ? ??OverlapView
        positionX = getXInRange(positionX, v);
        v.setX(positionX);//  w ww . ja v  a2s  .  co  m
    }
}

From source file:com.aliyun.homeshell.Folder.java

private void autoMoveIconByScroll(int srcPageIndex, int desPageIndex) {
    mScrolling = true;//  w  ww  .  ja v  a 2  s . co  m
    cancelMoveAnimation();
    final CellLayout srcPage = mContentList.get(srcPageIndex);
    final CellLayout desPage = mContentList.get(desPageIndex);
    View movedView = null;
    // scroll left
    if (srcPageIndex > desPageIndex) {
        for (int j = desPage.getCountY() - 1; j >= 0; j--) {
            for (int i = desPage.getCountX() - 1; i >= 0; i--) {
                if ((movedView = desPage.getChildAt(i, j)) != null) {
                    moveAnim = ObjectAnimator.ofFloat(movedView, TRANSLATION_X,
                            LauncherApplication.getScreenWidth() - movedView.getX() + 100);
                    break;
                }
            }
            if (movedView != null) {
                break;
            }
        }
    } else {
        // scroll right
        for (int j = 0; j < desPage.getCountY(); j++) {
            for (int i = 0; i < desPage.getCountX(); i++) {
                if ((movedView = desPage.getChildAt(i, j)) != null) {
                    moveAnim = ObjectAnimator.ofFloat(movedView, TRANSLATION_X, -300);
                    break;
                }
            }
            if (movedView != null) {
                break;
            }
        }
    }
    if (movedView == null)
        return;
    final ItemInfo movedInfo = (ItemInfo) movedView.getTag();
    final View view = movedView;
    mReorderAlarm.cancelAlarm();
    moveAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            view.setTranslationX(0);
            desPage.removeView(view);
            ViewParent parent = (view.getParent());
            if (parent != null) {
                String title = "";
                if (movedInfo != null) {
                    title = movedInfo.title.toString();
                }
                Log.e(HOR_LOG_TAG, "The icon:" + title + ",has the parent when end on autoScroll,remove");
                return;
            }
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
            int movedFromX = movedInfo.cellX;
            int movedFromY = movedInfo.cellY;
            lp.cellX = movedInfo.cellX = mEmptyCell[0];
            lp.cellY = movedInfo.cellY = mEmptyCell[1];
            mEmptyCell[0] = movedFromX;
            mEmptyCell[1] = movedFromY;
            boolean insert = false;
            srcPage.addViewToCellLayout(view, insert ? 0 : -1, (int) movedInfo.id, lp, true);
            // force to reorder
            // mReorderAlarm.cancelAlarm();
            // mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
            // mReorderAlarm.setAlarm(150);
        }
    });
    moveAnim.setDuration(300);
    moveAnim.start();
}

From source file:com.android.systemui.qs.QSDragPanel.java

private void restoreDraggingTilePosition(View v, final Runnable onAnimationFinishedRunnable) {
    if (mRestored) {
        return;//from  ww  w.j a  va 2 s.c  o  m
    }
    mRestored = true;
    mRestoring = true;
    mCurrentlyAnimating.add(mDraggingRecord);

    if (DEBUG_DRAG) {
        Log.i(TAG, "restoreDraggingTilePosition() called with " + "v = ["
                + (v.getTag() != null ? v.getTag() : v) + "]");
    }
    final boolean dragRecordDetached = mRecords.indexOf(mDraggingRecord) == -1;

    if (DEBUG_DRAG) {
        Log.v(TAG, "mLastLeftShift: " + mLastLeftShift + ", detached: " + dragRecordDetached + ", drag record: "
                + mDraggingRecord);
    }

    final QSPage originalPage = getPage(mDraggingRecord.page);
    originalPage.removeView(mDraggingRecord.tileView);
    addTransientView(mDraggingRecord.tileView, 0);
    mDraggingRecord.tileView.setTransitionVisibility(View.VISIBLE);

    // need to move center of the dragging view to the coords of the event.
    final float touchEventBoxLeft = v.getX()
            + (mLastTouchLocationX - (mDraggingRecord.tileView.getWidth() / 2));
    final float touchEventBoxTop = v.getY()
            + (mLastTouchLocationY - (mDraggingRecord.tileView.getHeight() / 2));

    mDraggingRecord.tileView.setX(touchEventBoxLeft);
    mDraggingRecord.tileView.setY(touchEventBoxTop);

    if (dragRecordDetached) {
        setToLastDestination(mDraggingRecord);
        if (DEBUG_DRAG) {
            Log.d(TAG,
                    "setting drag record view to coords: x:" + touchEventBoxLeft + ", y:" + touchEventBoxTop);
            Log.d(TAG,
                    "animating drag record to: " + mDraggingRecord + ", loc: " + mDraggingRecord.destination);
        }
    } else {
        mDraggingRecord.destination.x = getLeft(mDraggingRecord.destinationPage, mDraggingRecord.row,
                mDraggingRecord.col, getColumnCount(mDraggingRecord.destinationPage, mDraggingRecord.row));

        mDraggingRecord.destination.y = getRowTop(mDraggingRecord.row);
    }

    // setup x destination to animate to
    float destinationX = mDraggingRecord.destination.x;

    // see if we should animate this to the left or right off the page
    // the +1's are to account for the edit page
    if (mDraggingRecord.destinationPage > mViewPager.getCurrentItem() - 1) {
        if (DEBUG_DRAG) {
            Log.d(TAG, "adding width to animate out >>>>>");
        }
        destinationX += getWidth();
    } else if (mDraggingRecord.destinationPage < mViewPager.getCurrentItem() - 1) {
        if (DEBUG_DRAG) {
            Log.d(TAG, "removing width to animate out <<<<<");
        }
        destinationX -= getWidth();
    }

    // setup y
    float destinationY = mDraggingRecord.destination.y + mViewPager.getTop();

    mDraggingRecord.tileView.animate().withLayer().x(destinationX).y(destinationY) // part of the viewpager now
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    mDraggingRecord.tileView.setAlpha(1);
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    mViewPager.requestDisallowInterceptTouchEvent(false);
                    removeTransientView(mDraggingRecord.tileView);
                    mCurrentlyAnimating.remove(mDraggingRecord);
                    mRestoring = false;
                    mPagerAdapter.notifyDataSetChanged();
                    onStopDrag();

                    if (onAnimationFinishedRunnable != null) {
                        postOnAnimation(onAnimationFinishedRunnable);
                    }
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mViewPager.requestDisallowInterceptTouchEvent(false);

                    removeTransientView(mDraggingRecord.tileView);

                    final QSPage targetP = getPage(mDraggingRecord.destinationPage);

                    if (DEBUG_DRAG) {
                        if (dragRecordDetached) {
                            Log.i(TAG, "drag record was detached");
                        } else {
                            Log.i(TAG, "drag record was attached");
                        }
                    }
                    targetP.addView(mDraggingRecord.tileView);
                    mDraggingRecord.page = mDraggingRecord.destinationPage;

                    mDraggingRecord.tileView.setX(mDraggingRecord.destination.x);
                    // reset this to be in the coords of the page, not viewpager anymore
                    mDraggingRecord.tileView.setY(mDraggingRecord.destination.y);

                    mCurrentlyAnimating.remove(mDraggingRecord);

                    mRestoring = false;

                    if (dragRecordDetached) {
                        mRecords.add(mDraggingRecord);
                        mPagerAdapter.notifyDataSetChanged();
                    }
                    onStopDrag();

                    if (onAnimationFinishedRunnable != null) {
                        postOnAnimation(onAnimationFinishedRunnable);
                    } else {
                        requestLayout();
                    }
                }
            });
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Before doing an animation, map the item IDs for the currently visible children to the
 * {@link Rect} that defines their position on the screen so a translation animation
 * can be applied to their new layout positions.
 *///w  w  w.jav  a  2s. co m
private void cacheChildRects() {
    final int childCount = getChildCount();
    mChildRectsForAnimation.clear();

    long originalDraggedChildId = -1;
    if (isDragReorderingSupported()) {
        originalDraggedChildId = mReorderHelper.getDraggedChildId();
        if (mCachedDragViewRect != null && originalDraggedChildId != -1) {
            // This child was dragged in a reordering operation.  Use the cached position
            // of where the drag event was released as the cached location.
            mChildRectsForAnimation.put(originalDraggedChildId,
                    new ViewRectPair(mDragView, mCachedDragViewRect));
            mCachedDragViewRect = null;
        }
    }

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

        Rect rect;
        if (lp.id != originalDraggedChildId) {
            final int childTop = (int) child.getY();
            final int childBottom = childTop + child.getHeight();
            final int childLeft = (int) child.getX();
            final int childRight = childLeft + child.getWidth();
            rect = new Rect(childLeft, childTop, childRight, childBottom);
            mChildRectsForAnimation.put(lp.id /* item id */, new ViewRectPair(child, rect));
        }
    }
}