Example usage for android.view View getY

List of usage examples for android.view View getY

Introduction

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

Prototype

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

Source Link

Document

The visual y position of this view, in pixels.

Usage

From source file:org.protocoderrunner.apprunner.api.PUI.java

public void draggable(View v) {
    v.setOnTouchListener(new OnTouchListener() {
        PointF downPT = new PointF(); // Record Mouse Position When Pressed
        // Down// w w w  .ja  v a  2s.  c o m
        PointF startPT = new PointF(); // Record Start Position of 'img'

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int eid = event.getAction();
            switch (eid) {
            case MotionEvent.ACTION_MOVE:
                PointF mv = new PointF(event.getX() - downPT.x, event.getY() - downPT.y);
                v.setX((int) (startPT.x + mv.x));
                v.setY((int) (startPT.y + mv.y));
                startPT = new PointF(v.getX(), v.getY());
                break;
            case MotionEvent.ACTION_DOWN:
                downPT.x = event.getX();
                downPT.y = event.getY();
                startPT = new PointF(v.getX(), v.getY());
                break;
            case MotionEvent.ACTION_UP:
                // Nothing have to do
                break;
            default:
                break;
            }
            return true;
        }
    });

}

From source file:com.android.launcher2.PagedView.java

public void setLayoutScale(float childrenScale) {
    mLayoutScale = childrenScale;/* w  w  w  .j ava 2s.  com*/
    invalidateCachedOffsets();

    // Now we need to do a re-layout, but preserving absolute X and Y coordinates
    int childCount = getChildCount();
    float childrenX[] = new float[childCount];
    float childrenY[] = new float[childCount];
    for (int i = 0; i < childCount; i++) {
        final View child = getPageAt(i);
        childrenX[i] = child.getX();
        childrenY[i] = child.getY();
    }
    // Trigger a full re-layout (never just call onLayout directly!)
    int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
    int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
    requestLayout();
    measure(widthSpec, heightSpec);
    layout(getLeft(), getTop(), getRight(), getBottom());
    for (int i = 0; i < childCount; i++) {
        final View child = getPageAt(i);
        child.setX(childrenX[i]);
        child.setY(childrenY[i]);
    }

    // Also, the page offset has changed  (since the pages are now smaller);
    // update the page offset, but again preserving absolute X and Y coordinates
    scrollToNewPageWithoutMovingPages(mCurrentPage);
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *//*from   w  w  w .j av  a 2  s.  co  m*/
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java

private void performAnimation() {
    if (!mViewCacheForAnim.isEmpty()) {
        isAnimating = true;// w ww.  j a  va  2 s . c o m
        int count = mViewCacheForAnim.size();
        final View view = mViewCacheForAnim.remove(0);
        Rect rect = new Rect();
        this.getGlobalVisibleRect(rect);
        int fly_distance = (int) (rect.height());
        float top = view.getY();
        float bottom = view.getY() + view.getMeasuredHeight();
        float startTop = top + fly_distance;
        float startBottom = bottom + fly_distance;
        int bufferDis = rect.height() / 4;

        if (startBottom < 0) {
            Log.d(TAG, "No animation as the view is passed!!");
            view.setVisibility(View.VISIBLE);
            performAnimation();
            return;
        } else if (startTop < rect.height()) {
            fly_distance += (rect.height() - startTop + bufferDis);
        }
        if (fly_distance > rect.height() * 2) {
            Log.d(TAG, "No animation as the fly distance is too long!");
            view.setVisibility(View.VISIBLE);
            performAnimation();
            return;
        } else if (fly_distance < rect.height()) {
            fly_distance = rect.height();
        }

        view.setTranslationY(fly_distance);
        long delay = FLY_IN_DELAY / count;
        long duration = delay > FLY_IN_DURATION ? FLY_IN_DURATION : delay;
        view.animate().setDuration(duration).setInterpolator(new DecelerateInterpolator())
                .setListener(new AnimatorListenerAdapter() {

                    public void onAnimationStart(Animator anim) {
                        view.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animator anim) {
                        view.clearAnimation();
                        view.setTranslationY(0f);
                        performAnimation();
                    }
                }).translationY(0);
    } else {
        isAnimating = false;
    }
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

private void startEditFragment(final View view, final int position) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);/*from   w  w  w .  ja  v  a  2 s.co m*/
    listAdapter.saveData();

    Source dataItem = listAdapter.getItem(position);
    final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment();
    sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable());
    Bundle arguments = new Bundle();
    arguments.putInt("position", position);
    arguments.putString("type", dataItem.getType());
    arguments.putString("title", dataItem.getTitle());
    arguments.putString("data", dataItem.getData());
    arguments.putInt("num", dataItem.getNum());
    arguments.putBoolean("use", dataItem.isUse());
    arguments.putBoolean("preview", dataItem.isPreview());
    String imageFileName = dataItem.getImageFile().getAbsolutePath();
    if (imageFileName != null && imageFileName.length() > 0) {
        arguments.putString("image", imageFileName);
    } else {
        arguments.putString("image", "");
    }

    arguments.putBoolean("use_time", dataItem.isUseTime());
    arguments.putString("time", dataItem.getTime());

    sourceInfoFragment.setArguments(arguments);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final CardView sourceCard = (CardView) view.findViewById(R.id.source_card);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float cardStartShadow = sourceCard.getPaddingLeft();
    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final int viewStartPadding = view.getPaddingLeft();
    final float textStartX = sourceTitle.getX();
    final float textStartY = sourceTitle.getY();
    final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension(
                                                            TypedValue.COMPLEX_UNIT_DIP,
                                                            8,
                                                            getResources().getDisplayMetrics());*/

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment")
                        .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime));
            int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime));
            sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0);
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding;
            view.setPadding(newPadding, 0, newPadding, 0);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            sourceTitle.setY(textStartY + interpolatedTime * textTranslationY);
            sourceTitle.setX(textStartX + viewStartPadding - newPadding);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE));
    titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setTextColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent));
    titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue());
        }
    });

    ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f);
    imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            imageOverlay.setAlpha((Float) animation.getAnimatedValue());
        }
    });

    int transitionTime = INFO_ANIMATION_TIME;

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(transitionTime);
    cardColorAnimation.setDuration(transitionTime);
    titleColorAnimation.setDuration(transitionTime);
    titleShadowAlphaAnimation.setDuration(transitionTime);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);
    titleColorAnimation.setInterpolator(decelerateInterpolator);
    titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator);

    if (imageOverlay.getAlpha() > 0) {
        imageOverlayAlphaAnimation.start();
    }

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }
    }, (long) (transitionTime * 1.1f));

    needsListReset = true;
    view.startAnimation(animation);
    cardColorAnimation.start();
    titleColorAnimation.start();
    titleShadowAlphaAnimation.start();
}

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

private void restoreDraggingTilePosition(View v, final Runnable onAnimationFinishedRunnable) {
    if (mRestored) {
        return;//  w  w w.  j a v a2s.  c  om
    }
    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.
 *///from   ww  w  .j ava 2s .com
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));
        }
    }
}

From source file:com.wb.launcher3.Page.java

@Override
protected void dispatchDraw(Canvas canvas) {
    int halfScreenSize = getViewportWidth() / 2;
    // mOverScrollX is equal to getScrollX() when we're within the normal scroll range.
    // Otherwise it is equal to the scaled overscroll position.
    int screenCenter = mOverScrollX + halfScreenSize;

    if (screenCenter != mLastScreenCenter || mForceScreenScrolled) {
        // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can
        // set it for the next frame
        mForceScreenScrolled = false;/*from ww  w . jav a  2  s . c o  m*/
        screenScrolled(screenCenter);
        mLastScreenCenter = screenCenter;
    }

    // Find out which screens are visible; as an optimization we only call draw on them
    final int pageCount = getChildCount();
    if (pageCount > 0) {
        //*/Modified by tyd Greg 2014-03-20,for transition effect
        boolean allowed = true;
        Workspace workspace = null;
        if (this instanceof Workspace) {
            workspace = (Workspace) this;
            allowed = !workspace.isSmall();
        }
        if (TydtechConfig.TYDTECH_DEBUG_FLAG) {
            Log.d("Greg", "allowed: " + allowed);
        }
        /*/
        if(!allowed || !TydtechConfig.TRANSITION_EFFECT_ENABLED){
        getVisiblePages(mTempVisiblePagesRange);
        }else{
        getVisiblePagesExt(mTempVisiblePagesRange);
        }
        //*/
        getVisiblePages(mTempVisiblePagesRange);
        //*/
        final int leftScreen = mTempVisiblePagesRange[0];
        final int rightScreen = mTempVisiblePagesRange[1];
        if (leftScreen != -1 && rightScreen != -1) {
            final long drawingTime = getDrawingTime();
            // Clip to the bounds
            canvas.save();
            canvas.clipRect(getScrollX(), getScrollY(), getScrollX() + getRight() - getLeft(),
                    getScrollY() + getBottom() - getTop());

            // Draw all the children, leaving the drag view for last
            for (int i = pageCount - 1; i >= 0; i--) {
                final View v = getPageAt(i);
                if (v == mDragView)
                    continue;
                if (mForceDrawAllChildrenNextFrame
                        || (leftScreen <= i && i <= rightScreen && shouldDrawChild(v))) {
                    drawChild(canvas, v, drawingTime);
                }
            }
            // Draw the drag view on top (if there is one)
            if (mDragView != null) {
                drawChild(canvas, mDragView, drawingTime);
            }

            mForceDrawAllChildrenNextFrame = false;
            canvas.restore();
        }

        //*/Added by TYD Theobald_Wu on 20130223 [begin] for cycle rolling pages
        if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED && allowed) {
            canvas.save();
            int width = 0;
            final int pageW = getViewportWidth();
            View v = null;
            int scrollOffset = (pageW - getChildWidth(0)) / 2;
            if (mOverScrollX < 0) {
                int index = pageCount - 1;
                v = getPageAt(index);
                width = getViewportOffsetX() - scrollOffset - v.getWidth();
            } else if (mOverScrollX > mMaxScrollX) {
                v = getPageAt(0);
                width = getViewportOffsetX() + pageW * pageCount + scrollOffset;
            }
            if (TydtechConfig.TYDTECH_DEBUG_FLAG) {
                Log.d("Greg", "width: " + width);
                Log.d("Greg", "mOverScrollX: " + mOverScrollX);
            }
            if (v != null) {
                canvas.translate(width, v.getY());
                canvas.concat(v.getMatrix());
                final int w = v.getWidth();
                final int h = v.getHeight();
                final int sx = v.getScrollX();
                final int sy = v.getScrollY();
                Rect rect = new Rect(sx, sy, sx + w, sy + h);
                ///* zhangwuba mark this, user verison lead to screen flash 2014-5-12
                //canvas.saveLayerAlpha(sx, sy, sx + w, sy + h, (int) (v.getAlpha() * 255),
                //  Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
                //*/
                v.draw(canvas);
            }
            canvas.restore();
        }
        //*/
    }
}

From source file:com.android.launcher3.Launcher.java

@Override
public boolean onLongClick(View v) {
    if (!isDraggingEnabled())
        return false;
    if (isWorkspaceLocked())
        return false;
    if (mState != State.WORKSPACE)
        return false;

    if (creation != null)
        creation.clearAllLayout();/* ww w .j  a v  a 2s.  co m*/

    if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator)
            || (v == mAllAppsButton && mAllAppsButton != null)) {
        onLongClickAllAppsButton(v);
        return true;
    }

    if (v instanceof Workspace) {
        if (!mWorkspace.isInOverviewMode()) {
            if (!mWorkspace.isTouchActive()) {
                showOverviewMode(true);
                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    CellLayout.CellInfo longClickCellInfo = null;
    View itemUnderLongClick = null;
    if (v.getTag() instanceof ItemInfo) {
        ItemInfo info = (ItemInfo) v.getTag();
        longClickCellInfo = new CellLayout.CellInfo(v, info);
        itemUnderLongClick = longClickCellInfo.cell;
        mPendingRequestArgs = null;
    }

    // The hotseat touch handling does not go through Workspace, and we always allow long press
    // on hotseat items.
    if (!mDragController.isDragging()) {
        if (itemUnderLongClick == null) {
            // User long pressed on empty space
            mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
            if (mWorkspace.isInOverviewMode()) {
                mWorkspace.startReordering(v);
            } else {
                showOverviewMode(true);
            }
        } else {
            final boolean isAllAppsButton = !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v)
                    && mDeviceProfile.inv.isAllAppsButtonRank(
                            mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY));
            if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
                // User long pressed on an item
                DragOptions dragOptions = new DragOptions();
                if (itemUnderLongClick instanceof BubbleTextView) {
                    BubbleTextView icon = (BubbleTextView) itemUnderLongClick;
                    if (icon.hasDeepShortcuts()) {
                        DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
                        if (dsc != null) {
                            dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
                        }
                    }
                }

                int positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                        longClickCellInfo.cellY);

                List<Shortcuts> shortcutses = new ArrayList<Shortcuts>();

                if (creation != null)
                    creation.clearAllLayout();

                mWorkspace.startDrag(longClickCellInfo, dragOptions);

                //Get selected app info
                final Object tag = v.getTag();
                final ShortcutInfo shortcut;
                try {
                    shortcut = (ShortcutInfo) tag;
                    Drawable icon;
                    if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                            shortcut.getTargetComponent().getPackageName()) != null) {
                        icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity,
                                shortcut.getTargetComponent().getPackageName()));
                    } else {
                        icon = new BitmapDrawable(activity.getResources(),
                                shortcut.getIcon(new IconCache(Launcher.this, getDeviceProfile().inv)));
                    }

                    shortcutses = ShortcutsManager.getShortcutsBasedOnTag(Launcher.this.getApplicationContext(),
                            Launcher.this, shortcut, icon);
                    ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                            .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                    Hotseat.isHotseatTouched,
                                    Utilities.getDockSizeDefaultValue(getApplicationContext()))
                            .setOptionLayoutStyle(StyleOption.NONE).setPackageImage(icon)
                            .setShortcutsList(shortcutses).build();

                    creation = new ShortcutsCreation(builder);

                    creation.init();

                    Hotseat.isHotseatTouched = false;

                } catch (ClassCastException e) {
                    Log.e(TAG, "Clicked on Folder/Widget!");
                    positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                            longClickCellInfo.cellY);
                    try {
                        //Get selected folder info
                        final View f = v;
                        final Object tagF = v.getTag();
                        final FolderInfo folder;
                        folder = (FolderInfo) tagF;

                        shortcutses = new ArrayList<Shortcuts>();
                        shortcutses.add(new Shortcuts(R.drawable.ic_folder_open_black_24dp,
                                getString(R.string.folder_open), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            onClickFolderIcon(f);
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));
                        shortcutses.add(new Shortcuts(R.drawable.ic_title_black_24dp,
                                getString(R.string.folder_rename), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            AlertDialog.Builder alert = new AlertDialog.Builder(
                                                    new ContextThemeWrapper(Launcher.this,
                                                            R.style.AlertDialogCustom));
                                            LinearLayout layout = new LinearLayout(getApplicationContext());
                                            layout.setOrientation(LinearLayout.VERTICAL);
                                            layout.setPadding(100, 50, 100, 100);

                                            final EditText titleBox = new EditText(Launcher.this);

                                            titleBox.getBackground().mutate()
                                                    .setColorFilter(
                                                            ContextCompat.getColor(getApplicationContext(),
                                                                    R.color.colorPrimary),
                                                            PorterDuff.Mode.SRC_ATOP);
                                            alert.setMessage(getString(R.string.folder_title));
                                            alert.setTitle(getString(R.string.folder_enter_title));

                                            layout.addView(titleBox);
                                            alert.setView(layout);

                                            alert.setPositiveButton(getString(R.string.ok),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            folder.setTitle(titleBox.getText().toString());
                                                            LauncherModel.updateItemInDatabase(
                                                                    Launcher.getLauncherActivity(), folder);
                                                        }
                                                    });

                                            alert.setNegativeButton(getString(R.string.cancel),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            creation.clearAllLayout();
                                                        }
                                                    });
                                            alert.show();
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));

                        ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                                .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                        Hotseat.isHotseatTouched,
                                        Utilities.getDockSizeDefaultValue(getApplicationContext()))
                                .setOptionLayoutStyle(0)
                                .setPackageImage(
                                        ContextCompat.getDrawable(Launcher.this, R.mipmap.ic_launcher_home))
                                .setShortcutsList(shortcutses).build();

                        creation = new ShortcutsCreation(builder);

                        creation.init();
                    } catch (ClassCastException ee) {
                    }
                }
            }
        }
    }
    return true;
}