Java Code Examples for android.view.View.getX()

The following are Jave code examples for showing how to use getX() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ArcLayout-master   File: DemoLikeTumblrActivity.java   Source Code and License Vote up 7 votes
private Animator createShowItemAnimator(View item) {
  float dx = centerItem.getX() - item.getX();
  float dy = centerItem.getY() - item.getY();

  item.setScaleX(0f);
  item.setScaleY(0f);
  item.setTranslationX(dx);
  item.setTranslationY(dy);

  Animator anim = ObjectAnimator.ofPropertyValuesHolder(
      item,
      AnimatorUtils.scaleX(0f, 1f),
      AnimatorUtils.scaleY(0f, 1f),
      AnimatorUtils.translationX(dx, 0f),
      AnimatorUtils.translationY(dy, 0f)
  );

  anim.setInterpolator(new DecelerateInterpolator());
  anim.setDuration(50);
  return anim;
}
 
Example 2
Project: ArcLayout-master   File: DemoLikeTumblrActivity.java   Source Code and License Vote up 7 votes
private Animator createHideItemAnimator(final View item) {
  final float dx = centerItem.getX() - item.getX();
  final float dy = centerItem.getY() - item.getY();

  Animator anim = ObjectAnimator.ofPropertyValuesHolder(
      item,
      AnimatorUtils.scaleX(1f, 0f),
      AnimatorUtils.scaleY(1f, 0f),
      AnimatorUtils.translationX(0f, dx),
      AnimatorUtils.translationY(0f, dy)
  );

  anim.setInterpolator(new DecelerateInterpolator());
  anim.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
      super.onAnimationEnd(animation);
      item.setTranslationX(0f);
      item.setTranslationY(0f);
    }
  });
  anim.setDuration(50);
  return anim;
}
 
Example 3
Project: StackCardsView   File: SwipeTouchHelper.java   Source Code and License Vote up 7 votes
private ScrollInfo calcScrollInfo(View movingView) {
    ScrollInfo result = new ScrollInfo();
    float dx = movingView.getX() - mChildInitX;
    float dy = movingView.getY() - mChildInitY;
    int direction;
    if (Float.compare(dx, 0) == 0 && Float.compare(dy, 0) == 0) {
        direction = StackCardsView.SWIPE_NONE;
    } else {
        if (Math.abs(dx) * SLOPE > Math.abs(dy)) {
            direction = dx > 0 ? StackCardsView.SWIPE_RIGHT : StackCardsView.SWIPE_LEFT;
        } else {
            direction = dy > 0 ? StackCardsView.SWIPE_DOWN : StackCardsView.SWIPE_UP;
        }
    }
    log(TAG, "calcScrollInfo,direction=" + direction + ",dx=" + dx + ",dy=" + dy);
    result.direction = direction;
    double distance = Math.sqrt(dx * dx + dy * dy);
    float dismiss_distance = mSwipeView.getDismissDistance();
    if (distance >= dismiss_distance) {
        result.progress = 1;
    } else {
        result.progress = (float) distance / dismiss_distance;
    }
    return result;
}
 
Example 4
Project: RNLearn_Project1   File: LayoutUpdateAnimation.java   Source Code and License Vote up 7 votes
@Override
@Nullable Animation createAnimationImpl(View view, int x, int y, int width, int height) {
  boolean animateLocation = view.getX() != x || view.getY() != y;
  boolean animateSize = view.getWidth() != width || view.getHeight() != height;
  if (!animateLocation && !animateSize) {
    return null;
  } else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) {
    // Use GPU-accelerated animation, however we loose the ability to resume interrupted
    // animation where it was left off. We may be able to listen to animation interruption
    // and set the layout manually in this case, so that next animation kicks off smoothly.
    return new TranslateAnimation(view.getX() - x, 0, view.getY() - y, 0);
  } else {
    // Animation is sub-optimal for perf, but scale transformation can't be use in this case.
    return new PositionAndSizeAnimation(view, x, y, width, height);
  }
}
 
Example 5
Project: ArcLayout-master   File: MainActivity.java   Source Code and License Vote up 7 votes
private Animator createHideItemAnimator(final View item) {
        float dx = fab.getX() - item.getX();
        float dy = fab.getY() - item.getY();

        Animator anim = ObjectAnimator.ofPropertyValuesHolder(
                item,
//                AnimatorUtils.rotation(720f, 0f),
                AnimatorUtils.translationX(0f, dx),
                AnimatorUtils.translationY(0f, dy)
        );

        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                item.setTranslationX(0f);
                item.setTranslationY(0f);
            }
        });

        return anim;
    }
 
Example 6
Project: NeoTerm   File: RecyclerTabLayout.java   Source Code and License Vote up 7 votes
protected void startAnimation(final int position) {

        float distance = 1;

        View view = mLinearLayoutManager.findViewByPosition(position);
        if (view != null) {
            float currentX = view.getX() + view.getMeasuredWidth() / 2.f;
            float centerX = getMeasuredWidth() / 2.f;
            distance = Math.abs(centerX - currentX) / view.getMeasuredWidth();
        }

        ValueAnimator animator;
        if (position < mIndicatorPosition) {
            animator = ValueAnimator.ofFloat(distance, 0);
        } else {
            animator = ValueAnimator.ofFloat(-distance, 0);
        }
        animator.setDuration(DEFAULT_SCROLL_DURATION);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                scrollToTab(position, (float) animation.getAnimatedValue(), true);
            }
        });
        animator.start();
    }
 
Example 7
Project: sflauncher   File: SuperRecyclerView.java   Source Code and License Vote up 7 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if(PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("widgetScroll", false)) {
        if (ev.getAction() == MotionEvent.ACTION_MOVE || ev.getAction() == MotionEvent.ACTION_SCROLL) {
            if(Math.abs(ev.getX()-lastX)<Math.abs(ev.getY()-lastY)) {
                for (int i = 0; i < getChildCount(); i++) {
                    View v = getChildAt(i);
                    if (v.getTag() instanceof Card.Apps) {
                        Card.Apps c = (Card.Apps) v.getTag();
                        float x = v.getX() + c.getCardContainer().getX();
                        float y = v.getY() + c.getCardContainer().getY();
                        float w = c.getCardContainer().getWidth();
                        float h = c.getCardContainer().getHeight();
                        if (ev.getX() >= x && ev.getX() < x + w && ev.getY() >= y && ev.getY() < y + h) {
                            return true;
                        } else break;
                    }
                }
            }
        }
    }
    lastX = ev.getX();
    lastY = ev.getY();
    return super.onInterceptTouchEvent(ev);
}
 
Example 8
Project: GitHub   File: SimpleViewBehavior.java   Source Code and License Vote up 6 votes
public void updateView(View child, View dependency) {
    float percent = 0;
    float start = 0;
    float current = 0;
    float end = UNSPECIFIED_INT;
    switch (mDependType) {
        case DEPEND_TYPE_WIDTH:
            start = mDependStartWidth;
            current = dependency.getWidth();
            end = mDependTargetWidth;
            break;
        case DEPEND_TYPE_HEIGHT:
            start = mDependStartHeight;
            current = dependency.getHeight();
            end = mDependTargetHeight;
            break;
        case DEPEND_TYPE_X:
            start = mDependStartX;
            current = dependency.getX();
            end = mDependTargetX;
            break;
        case DEPEND_TYPE_Y:
            start = mDependStartY;
            current = dependency.getY();
            end = mDependTargetY;
            break;
    }
    if (end != UNSPECIFIED_INT) {
        percent = Math.abs(current - start) / Math.abs(end - start);
    }
    updateViewWithPercent(child, percent > 1 ? 1 : percent);
}
 
Example 9
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 6 votes
public static float getX(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getX();
    } else {
        return view.getX();
    }
}
 
Example 10
Project: exciting-app   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 6 votes
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
Example 11
Project: OpenWithX   File: ResolverDrawerLayout.java   Source Code and License Vote up 6 votes
private static boolean isChildUnder(View child, float x, float y) {
    final float left = child.getX();
    final float top = child.getY();
    final float right = left + child.getWidth();
    final float bottom = top + child.getHeight();
    return x >= left && y >= top && x < right && y < bottom;
}
 
Example 12
Project: Bridge   File: ResolverDrawerLayout.java   Source Code and License Vote up 6 votes
private View findListChildUnder(float x, float y) {
    View v = findChildUnder(x, y);
    while (v != null) {
        x -= v.getX();
        y -= v.getY();
        if (v instanceof RecyclerView/*AbsListView*/) {
            // One more after this.
            return findChildUnder((ViewGroup) v, x, y);
        }
        v = v instanceof ViewGroup ? findChildUnder((ViewGroup) v, x, y) : null;
    }
    return null;
}
 
Example 13
Project: ChimpCheck   File: FingerGestures.java   Source Code and License Vote up 6 votes
public static void swipeOnView(AppEventOuterClass.UIID uiid, ViewInteraction vi, AppEventOuterClass.Orientation ori){
    switch(ori.getOrientType()){
        case UP: vi.perform(swipeUp()); break;
        case DOWN: vi.perform(swipeDown()); break;
        case LEFT: vi.perform(swipeLeft()); break;
        case RIGHT: vi.perform(swipeRight()); break;
        case XY_TYPE:
            ActivityManager activityManager = new ActivityManager();
            View v = new View(activityManager.getActivityInstance().getApplicationContext());
            switch(uiid.getIdType()){
                case R_ID:
                    v = activityManager.getDecorView().findViewById(uiid.getRid());
                    break;
                case NAME_ID:
                    View decorView = activityManager.getDecorView();
                    int resId = decorView.getResources().getIdentifier(uiid.getNameid(), "id", activityManager.getActivityInstance().getPackageName() );
                    v = decorView.findViewById(resId);
                    break;
            }

            if(v == null) {
                return;
            }

            float x = v.getX();
            float y = v.getY();
            float centerX = x + v.getWidth() / 2;
            float centerY = y + v.getHeight() / 2;
            AppEventOuterClass.XYCoordin desXY = ori.getXy();
            vi.perform(swipeOnCoord(centerX, centerY, desXY.getX(), desXY.getY()));
            
            break;
    }
}
 
Example 14
Project: PaoMovie   File: MyRelativeLayout.java   Source Code and License Vote up 6 votes
/**
 * 该方法用于回一个View的终点坐标 如果该View不存在则返回(0,0)
 *
 * @param view
 * @return
 */
private Point getViewMidPoint(View view) {
	Point point = new Point();
	if (view != null) {
		float xx = view.getX();
		float yy = view.getY();
		int center_x = (int) (xx + view.getWidth() / 2);
		int center_y = (int) (yy + view.getHeight() / 2);
		point.set(center_x, center_y);
	} else {
		point.set(0, 0);
	}
	return point;
}
 
Example 15
Project: Rx2Animations   File: RxAnimations.java   Source Code and License Vote up 6 votes
public static Completable enter(final View view, final int xOffset, final int yOffset) {
    final float startingX = view.getX();
    final float startingY = view.getY();
    return animate(view, new DecelerateInterpolator())
            .fadeIn()
            .translateBy(xOffset, yOffset)
            .onAnimationCancel(aView -> set(aView, startingX, startingY, OPAQUE))
            .schedule();
}
 
Example 16
Project: Rx2Animations   File: RxAnimations.java   Source Code and License Vote up 6 votes
public static Completable enter(final View view, final int delay, final int xOffset, final int yOffset) {
    final float startingX = view.getX();
    final float startingY = view.getY();
    return animate(view, new DecelerateInterpolator())
            .delay(delay)
            .fadeIn()
            .translateBy(xOffset, yOffset)
            .onAnimationCancel(aView -> set(aView, startingX, startingY, OPAQUE))
            .schedule();
}
 
Example 17
Project: boohee_v5.6   File: ViewCompatHC.java   Source Code and License Vote up 5 votes
public static float getX(View view) {
    return view.getX();
}
 
Example 18
Project: letv   File: ViewCompatHC.java   Source Code and License Vote up 5 votes
public static float getX(View view) {
    return view.getX();
}
 
Example 19
Project: FriskyImage   File: FriskyBounce.java   Source Code and License Vote up 3 votes
public void StartCrazyBounce1(final int TimeForCover) {


        int a[] = new int[2];
        Rootview.getLocationOnScreen(a);

        final float PosX = View.getX();
        final float PosY = View.getY();


        runnable5 = new Runnable() {
            @Override
            public void run() {

                View.animate().x(0).y(PosY / 2).withEndAction(runnable2).setDuration(TimeForCover).withEndAction(runnable2).setDuration(TimeForCover).setInterpolator(new LinearInterpolator()).start();

            }
        };


        runnable4 = new Runnable() {
            @Override
            public void run() {
                View.animate().x(PosX).y(PosY).withEndAction(runnable5).setDuration(TimeForCover).setInterpolator(new LinearInterpolator()).start();

            }
        };

        runnable3 = new Runnable() {
            @Override
            public void run() {

                View.animate().translationXBy(PosX).y(PosY / 2).setDuration(TimeForCover).withEndAction(runnable4).setInterpolator(new LinearInterpolator()).start();


            }
        };

        runnable2 = new Runnable() {
            @Override
            public void run() {


                int a = RootLayoutRect.right + RootLayoutRect.left / 2;
                View.animate().y(0).x(PosX).withEndAction(runnable3).setDuration(TimeForCover).setInterpolator(new LinearInterpolator()).start();
            }
        };
        View.animate().x(0).y(PosY / 2).withEndAction(runnable2).setDuration(TimeForCover).setInterpolator(new LinearInterpolator()).start();

    }
 
Example 20
Project: phonk   File: WidgetHelper.java   Source Code and License Vote up 3 votes
public static void setMovable(View viewHandler, final View viewContainer, final ReturnInterface callback) {
    View.OnTouchListener onMoveListener = new View.OnTouchListener() {

        public int x_init;
        public int y_init;

        @Override
        public boolean onTouch(View v, MotionEvent e) {
            int action = e.getActionMasked();

            switch (action) {

                case MotionEvent.ACTION_DOWN:
                    x_init = (int) e.getRawX() - (int) viewContainer.getX();
                    //MLog.network(getContext(), TAG, "" + x_init + " " + (int) e.getRawX() + " " + (int) mWindow.getX() + " " + (int) mWindow.getLeft());
                    y_init = (int) e.getRawY() - (int) viewContainer.getY();

                    break;

                case MotionEvent.ACTION_MOVE:

                    int x_cord = (int) e.getRawX();
                    int y_cord = (int) e.getRawY();

                    int posX = x_cord - x_init;
                    int posY = y_cord - y_init;

                    viewContainer.setX(posX);
                    viewContainer.setY(posY);

                    ReturnObject r = new ReturnObject();
                    r.put("x", posX);
                    r.put("y", posY);

                    if (callback != null) callback.event(r);

                    break;
            }

            return true;
        }

    };

    viewHandler.setOnTouchListener(onMoveListener);
}