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:de.tobiasbielefeld.solitaire.ui.GameManager.java

public boolean onTouch(View v, MotionEvent event) {
    /*/*ww w  .j  av  a 2 s  .  c om*/
     * handle input like touching cards and stacks and moving cards around
     */

    //if something important happens don't accept input
    if (stopConditions())
        return true;

    //also don't do anything with a second touch point
    if (event.getPointerId(0) != 0) {
        if (movingCards.hasCards())
            movingCards.returnToPos();

        return true;
    }

    float X = event.getX() + v.getX(), Y = event.getY() + v.getY();

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (currentGame.hasMainStack() && currentGame.testIfMainStackTouched(X, Y)) {

            if (currentGame.hasLimitedRedeals() && currentGame.dealFromStack().isEmpty()) {
                if (currentGame.getRemainingNumberOfRedeals() == 0)
                    return true;
                else
                    currentGame.incrementRedealCounter(this);
            }

            currentGame.onMainStackTouch();
        } else if (cards[v.getId()].isUp()) {//&& currentGame.addCardToMovementTest(cards[v.getId()])) {

            if (getSharedBoolean("pref_key_double_tap_enable", true)) {
                if (tappedStack != null && tappedStack == cards[v.getId()].getStack()
                        && System.currentTimeMillis() - firstTapTime < doubleTapSpeed) {

                    CardAndStack cardAndStack = null;

                    if (getSharedBoolean("pref_key_double_tap_all_cards", true)
                            && cards[v.getId()].getStack().getID() <= currentGame.getLastTableauID()) {
                        cardAndStack = currentGame.doubleTap(cards[v.getId()].getStack());
                    } else if (currentGame.addCardToMovementTest(cards[v.getId()])) {
                        cardAndStack = currentGame.doubleTap(cards[v.getId()]);
                    }

                    if (cardAndStack != null) {
                        movingCards.add(cardAndStack.getCard(), event.getX(), event.getY());
                        movingCards.moveToDestination(cardAndStack.getStack());
                        tappedStack = null;
                        return true;
                    }

                } else {
                    tappedStack = cards[v.getId()].getStack();
                    firstTapTime = System.currentTimeMillis();
                }
            }

            if (currentGame.addCardToMovementTest(cards[v.getId()])) {
                movingCards.add(cards[v.getId()], event.getX(), event.getY());
            }
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE && movingCards.hasCards()) {
        movingCards.move(X, Y);
    } else if (event.getAction() == MotionEvent.ACTION_UP && movingCards.hasCards()) {
        for (Stack stack : stacks) {
            if (stack.isOnLocation(X, Y) && movingCards.first().getStack() != stack
                    && movingCards.first().test(stack)) {
                movingCards.moveToDestination(stack);
                return true;
            }
        }

        //if they aren't placed, return them to their old places
        movingCards.returnToPos();
    }
    return true;
}

From source file:com.bottomsheetbehavior.MergedAppBarLayoutBehavior.java

private void init(@NonNull CoordinatorLayout parent, @NonNull View child) {

    AppBarLayout appBarLayout = (AppBarLayout) child;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        appBarLayout.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
    }//from   ww  w. ja  v  a2 s  .c o  m

    if (mToolbar == null || mBackground == null) {
        return;
    }

    mBackGroundLayoutParams = (FrameLayout.LayoutParams) mBackground.getLayoutParams();
    getBottomSheetBehavior(parent);

    mTitleTextView = findTitleTextView(mToolbar);
    if (mTitleTextView == null)
        return;

    mInitialY = child.getY();

    child.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);

    setFullBackGroundColor(
            mVisible && mCurrentTitleAlpha == 1 ? mBackgroundColor : android.R.color.transparent);
    setPartialBackGroundHeight(0);
    mTitleTextView.setAlpha(mCurrentTitleAlpha);
    mInit = true;
    setToolbarVisible(false, child);
}

From source file:com.androidinspain.deskclock.timer.TimerFragment.java

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed/*w w w. j  a  v  a2  s.c  o  m*/
 * @param animateDown {@code true} if the views should animate upwards, otherwise downwards
 */
private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) {
    if (mCurrentView == toView) {
        return;
    }

    final boolean toTimers = toView == mTimersView;
    if (toTimers) {
        mTimersView.setVisibility(VISIBLE);
    } else {
        mCreateTimerView.setVisibility(VISIBLE);
    }
    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    updateFab(BUTTONS_DISABLE);

    final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration();

    final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver();
    viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.removeOnPreDrawListener(this);
            }

            final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time);
            final float distanceY = view != null ? view.getHeight() + view.getY() : 0;
            final float translationDistance = animateDown ? distanceY : -distanceY;

            toView.setTranslationY(-translationDistance);
            mCurrentView.setTranslationY(0f);
            toView.setAlpha(0f);
            mCurrentView.setAlpha(1f);

            final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y,
                    translationDistance);
            final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f);
            final AnimatorSet translationAnimatorSet = new AnimatorSet();
            translationAnimatorSet.playTogether(translateCurrent, translateNew);
            translationAnimatorSet.setDuration(animationDuration);
            translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

            final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f);
            fadeOutAnimator.setDuration(animationDuration / 2);
            fadeOutAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);

                    // The fade-out animation and fab-shrinking animation should run together.
                    updateFab(FAB_AND_BUTTONS_SHRINK);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    if (toTimers) {
                        showTimersView(FAB_AND_BUTTONS_EXPAND);

                        // Reset the state of the create view.
                        mCreateTimerView.reset();
                    } else {
                        showCreateTimerView(FAB_AND_BUTTONS_EXPAND);
                    }

                    if (timerToRemove != null) {
                        DataModel.getDataModel().removeTimer(timerToRemove);
                        Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete,
                                com.androidinspain.deskclock.R.string.label_deskclock);
                    }

                    // Update the fab and button states now that the correct view is visible and
                    // before the animation to expand the fab and buttons starts.
                    updateFab(FAB_AND_BUTTONS_IMMEDIATE);
                }
            });

            final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f);
            fadeInAnimator.setDuration(animationDuration / 2);
            fadeInAnimator.setStartDelay(animationDuration / 2);

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet);
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mTimersView.setTranslationY(0f);
                    mCreateTimerView.setTranslationY(0f);
                    mTimersView.setAlpha(1f);
                    mCreateTimerView.setAlpha(1f);
                }
            });
            animatorSet.start();

            return true;
        }
    });
}

From source file:uk.org.downiesoft.slideshow.GridViewFragment.java

/**
 * {@inheritDoc}/*  w  w w.  j ava 2  s.  co  m*/
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_slideshow:
        View thumbView = mGridView.getChildAt(0);
        ActivityOptions options = ActivityOptions.makeScaleUpAnimation(mGridView, (int) thumbView.getX(),
                (int) thumbView.getY(), thumbView.getWidth(), thumbView.getHeight());
        startSlideshow(mCurrentFile, 0, true, options);
        return true;
    case R.id.action_show_favourites:
        showFavourites();
        return true;
    case R.id.action_save_favourites:
        FavouritesManager.saveFavouritesDialog(getActivity(), mFavourites, this);
        return true;
    case R.id.action_open_favourites:
        FavouritesManager.loadFavouritesDialog(getActivity(), this);
        return true;
    case R.id.action_refresh_gridthumbs:
        mThumbnailAdapter.refreshThumbs();
        return true;
    case R.id.action_browse:
        Intent intent = new Intent(getActivity(), BrowserActivity.class);
        intent.putExtra(BrowserDialog.ARG_ZFILE, mCurrentFile.toArgs());
        startActivityForResult(intent, SlideShowActivity.REQUEST_BROWSER);
        return true;
    default:
        return false;
    }
}

From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.MergedAppBarLayoutBehavior.java

private void init(@NonNull CoordinatorLayout parent, @NonNull View child) {

    AppBarLayout appBarLayout = (AppBarLayout) child;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        appBarLayout.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
    }/* w  w w  .j  a v  a 2s.com*/

    mToolbar = (Toolbar) appBarLayout.findViewById(R.id.expanded_toolbar);
    mBackground = appBarLayout.findViewById(R.id.background);
    mBackGroundLayoutParams = (FrameLayout.LayoutParams) mBackground.getLayoutParams();
    getBottomSheetBehavior(parent);

    mTitleTextView = findTitleTextView(mToolbar);
    if (mTitleTextView == null)
        return;

    mInitialY = child.getY();

    child.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);
    //        setStatusBarBackgroundVisible(mVisible);

    setFullBackGroundColor(
            mVisible && mCurrentTitleAlpha == 1 ? R.color.colorPrimary : android.R.color.transparent);
    setPartialBackGroundHeight(0);
    mTitleTextView.setText(mToolbarTitle);
    mTitleTextView.setAlpha(mCurrentTitleAlpha);
    mInit = true;
    setToolbarVisible(false, child);
}

From source file:uk.org.downiesoft.slideshow.GridViewFragment.java

/**
 * {@inheritDoc}// w w w  .  j a  v  a 2  s. c o m
  * In this case we select the given slide in the grid view.
 * @see PreviewFragment.PreviewFragmentListener
 */
@Override
public void onPreviewStartSlideshow() {
    View previewView = mPreview.getView();
    if (previewView != null) {
        ActivityOptions options = ActivityOptions.makeScaleUpAnimation(mGridView, (int) previewView.getX(),
                (int) previewView.getY(), previewView.getWidth(), previewView.getHeight());
        startSlideshow(mCurrentFile, mCurrentImage, false, options);
    }
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private void applyTumblrOpenAniamtion() {
    final View firstItem = mMenuItemViews.get(0);

    //make start position at center
    for (MenuItemView itemView : mMenuItemViews) {
        itemView.disableAlphaAnimation();
        itemView.setX(firstItem.getLeft());
        itemView.setY(firstItem.getY());
        itemView.setScaleX(0);/*  ww w  .  j a  v a2 s.  c o m*/
        itemView.setScaleY(0);
    }
    final SpringSystem springSystem = SpringSystem.create();

    final Spring springScaleX = springSystem.createSpring();
    final Spring springScaleY = springSystem.createSpring();

    springScaleX.addListener(new MapPerformer(firstItem, View.SCALE_X, 0, 1));
    springScaleY.addListener(new MapPerformer(firstItem, View.SCALE_Y, 0, 1));
    final DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(this,
            mContainerView, true);
    springScaleX.addListener(destroySelfSpringListener);
    springScaleY.addListener(destroySelfSpringListener);
    springScaleX.setEndValue(1);
    springScaleY.setEndValue(1);

    for (int i = 1; i < mMenuItemCount; i++) {
        final View menuItemView = mMenuItemViews.get(i);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                final Spring springScaleX = springSystem.createSpring();
                final Spring springScaleY = springSystem.createSpring();

                springScaleX.addListener(new MapPerformer(menuItemView, View.SCALE_X, 0, 1));
                springScaleY.addListener(new MapPerformer(menuItemView, View.SCALE_Y, 0, 1));
                final DestroySelfSpringListener destroySelfSpringListener = new DestroySelfSpringListener(
                        SpringFloatingActionMenu.this, mContainerView, true);
                springScaleX.addListener(destroySelfSpringListener);
                springScaleY.addListener(destroySelfSpringListener);
                springScaleX.setEndValue(1);
                springScaleY.setEndValue(1);

                final Spring springX = springSystem.createSpring();
                final Spring springY = springSystem.createSpring();

                springX.addListener(
                        new MapPerformer(menuItemView, View.X, firstItem.getLeft(), menuItemView.getLeft()));
                springY.addListener(
                        new MapPerformer(menuItemView, View.Y, firstItem.getTop(), menuItemView.getTop()));
                springX.addListener(destroySelfSpringListener);
                springY.addListener(destroySelfSpringListener);
                springX.setEndValue(1);
                springY.setEndValue(1);
            }
        }, mTumblrTimeInterval * (i - 1));
    }
}

From source file:com.placefinder.placedetailspanel.MergedAppBarLayoutBehavior.java

private void init(@NonNull CoordinatorLayout parent, @NonNull View child) {

    AppBarLayout appBarLayout = (AppBarLayout) child;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        appBarLayout.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
    }/*from www .j a  v a 2 s.  com*/

    mToolbar = (Toolbar) appBarLayout.findViewById(R.id.expanded_toolbar);
    mBackground = appBarLayout.findViewById(R.id.background);
    mBackGroundLayoutParams = (FrameLayout.LayoutParams) mBackground.getLayoutParams();
    mStatusBarReplacer = appBarLayout.findViewById(R.id.status_bar_replacer);
    getBottomSheetBehavior(parent);

    mTitleTextView = findTitleTextView(mToolbar);
    if (mTitleTextView == null)
        return;

    mInitialY = child.getY();

    child.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);
    //        setStatusBarBackgroundVisible(mVisible);

    setFullBackGroundColor(
            mVisible && mCurrentTitleAlpha == 1 ? R.color.colorPrimary : android.R.color.transparent);
    setPartialBackGroundHeight(0);
    mTitleTextView.setText(mToolbarTitle);
    mTitleTextView.setAlpha(mCurrentTitleAlpha);
    mInit = true;
    setToolbarVisible(false, child);
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private HashMap<Integer, String> processStickerAnnotations(ViewGroup viewGroup) {
    HashMap<Integer, String> allStickerAnnotations = new HashMap<>();
    if (viewGroup != null) {
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof StickerAnnotationImageView) {
                StickerAnnotationImageView stickerAnnotationImageView = (StickerAnnotationImageView) child;

                int annotationImageResource = stickerAnnotationImageView.getImageResourceId();
                float getX = child.getX();
                float getY = child.getY();
                int width = child.getWidth();
                int height = child.getHeight();
                float rotation = child.getRotation();
                String value = annotationImageResource + Utils.SEPARATOR + getX + Utils.SEPARATOR + getY
                        + Utils.SEPARATOR + width + Utils.SEPARATOR + height + Utils.SEPARATOR + rotation;
                allStickerAnnotations.put(i, value);
            }//from  w  w  w  .j  a va2s  .  c  o  m
        }
    }

    return allStickerAnnotations;
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void removeOutOfBoundsAnnotations() {
    RelativeLayout relativeLayout = (RelativeLayout) findViewById(
            R.id.supersede_feedbacklibrary_annotate_image_layout);
    if (relativeLayout != null) {
        List<View> toRemove = new ArrayList<>();
        int newBitmapWidth = annotateImageView.getBitmapWidth();
        int newBitmapHeight = annotateImageView.getBitmapHeight();
        float fraction = 0.5f;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof StickerAnnotationView || child instanceof TextAnnotationView) {
                // A fraction the sticker should be visible, if not the sticker will be removed
                float deleteThresholdX = child.getWidth() * fraction;
                float deleteThresholdY = child.getHeight() * fraction;
                float x = child.getX();
                float y = child.getY();

                boolean xOk = true;
                boolean yOk = true;
                if (x < 0) {
                    xOk = Math.abs(x) < deleteThresholdX;
                } else if (x > 0 && !(x < 0)) {
                    xOk = x + deleteThresholdX < newBitmapWidth;
                }/*w  w w .  java  2s  .co m*/
                if (y < 0) {
                    yOk = Math.abs(y) < deleteThresholdY;
                } else if (y > 0 && !(y < 0)) {
                    yOk = y + deleteThresholdY < newBitmapHeight;
                }

                if (!(xOk && yOk)) {
                    toRemove.add(child);
                }
            }
        }

        for (int i = 0; i < toRemove.size(); ++i) {
            relativeLayout.removeView(toRemove.get(i));
        }
        toRemove.clear();

        textAnnotationCounter = 1;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof TextAnnotationView) {
                String newAnnotationNumber = Integer.toString(textAnnotationCounter);
                ((TextAnnotationImageView) child).getAnnotationNumberView().setText(newAnnotationNumber);
                textAnnotationCounter++;
            }
            if (textAnnotationCounter > textAnnotationCounterMaximum) {
                break;
            }
        }
    }
}