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

The following are Jave code examples for showing how to use getTranslationX() 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: GitHub   File: FloatLayoutHelper.java   Source Code and License Vote up 6 votes
private void doPullOverAnimation(final View v) {
    ObjectAnimator animator;
    if (v.getTranslationX() + v.getWidth() / 2 + v.getLeft() > parentViewWidth / 2) {
        animator = ObjectAnimator.ofFloat(v, "translationX",
                v.getTranslationX(), parentViewWidth - v.getWidth()
                        - v.getLeft() - rightMargin - mAdjuster.right);
        mTransitionX = parentViewWidth - v.getWidth() - v.getLeft() - rightMargin - mAdjuster.right;
    } else {
        animator = ObjectAnimator.ofFloat(v, "translationX",
                v.getTranslationX(), -v.getLeft() + leftMargin + mAdjuster.left);
        mTransitionX = -v.getLeft() + leftMargin + mAdjuster.left;
    }

    mTransitionY = (int) v.getTranslationY();
    animator.setDuration(200);
    animator.start();
}
 
Example 2
Project: genius-groupie   File: HeaderItemDecoration.java   Source Code and License Vote up 6 votes
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    for (int i = 0; i < parent.getChildCount(); i++) {
        View child = parent.getChildAt(i);
        if (!isHeader(child, parent)) continue;

        RecyclerView.LayoutManager lm = parent.getLayoutManager();

        float top = lm.getDecoratedTop(child) + child.getTranslationY();
        float bottom = lm.getDecoratedBottom(child) + child.getTranslationY();
        if (i == parent.getChildCount() - 1) {
            // Draw to bottom if last item
            bottom = Math.max(parent.getHeight(), bottom);
        }
        float right = lm.getDecoratedRight(child) + child.getTranslationX();
        float left = lm.getDecoratedLeft(child) + child.getTranslationX();
        c.drawRect(left, top, right, bottom, paint);
    }
}
 
Example 3
Project: boohee_v5.6   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 6 votes
private float getValue(int propertyConstant) {
    View v = (View) this.mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case 1:
                return v.getTranslationX();
            case 2:
                return v.getTranslationY();
            case 4:
                return v.getScaleX();
            case 8:
                return v.getScaleY();
            case 16:
                return v.getRotation();
            case 32:
                return v.getRotationX();
            case 64:
                return v.getRotationY();
            case 128:
                return v.getX();
            case 256:
                return v.getY();
            case 512:
                return v.getAlpha();
        }
    }
    return 0.0f;
}
 
Example 4
Project: BestPracticeApp   File: PointLayout.java   Source Code and License Vote up 6 votes
double getDistance() {
    View view = getChildAt(0);

    float left = view.getTranslationX();
    float top = view.getTranslationY();
    float width = view.getWidth();
    float height = view.getHeight();
    float w = width / 2;
    float h = height / 2;
    float x = left + w;
    float y = top + h;

    double sqrt = Math.sqrt((x - w) * (x - w) + (y - h) * (y - h));
    return sqrt;

}
 
Example 5
Project: file.io-app   File: MaterialIn.java   Source Code and License Vote up 6 votes
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 6
Project: Material-Motion   File: BaseFragment.java   Source Code and License Vote up 6 votes
protected Path createArcPath(View view, float endX, float endY, float radius){
    Path arcPath=new Path();
    float startX=view.getTranslationX();
    float startY=view.getTranslationY();
    float midX = startX + ((endX - startX) / 2);
    float midY = startY + ((endY - startY) / 2);
    float xDiff = midX - startX;
    float yDiff = midY - startY;

    double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
    double angleRadians = Math.toRadians(angle);

    float pointX = (float) (midX + radius * Math.cos(angleRadians));
    float pointY = (float) (midY + radius * Math.sin(angleRadians));

    arcPath.moveTo(startX, startY);
    arcPath.cubicTo(startX,startY,pointX,pointY, endX, endY);
    return arcPath;
}
 
Example 7
Project: vlayout   File: FloatLayoutHelper.java   Source Code and License Vote up 6 votes
private void doPullOverAnimation(final View v) {
    ObjectAnimator animator;
    if (v.getTranslationX() + v.getWidth() / 2 + v.getLeft() > parentViewWidth / 2) {
        animator = ObjectAnimator.ofFloat(v, "translationX",
                v.getTranslationX(), parentViewWidth - v.getWidth()
                        - v.getLeft() - rightMargin - mAdjuster.right);
        mTransitionX = parentViewWidth - v.getWidth() - v.getLeft() - rightMargin - mAdjuster.right;
    } else {
        animator = ObjectAnimator.ofFloat(v, "translationX",
                v.getTranslationX(), -v.getLeft() + leftMargin + mAdjuster.left);
        mTransitionX = -v.getLeft() + leftMargin + mAdjuster.left;
    }

    mTransitionY = (int) v.getTranslationY();
    animator.setDuration(200);
    animator.start();
}
 
Example 8
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 9
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 5 votes
public static float getTranslationX(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getTranslationX();
    } else {
        return view.getTranslationX();
    }
}
 
Example 10
Project: ultrasonic   File: DraggableDrawer.java   Source Code and License Vote up 5 votes
private int supportGetTranslationX(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return (int) v.getTranslationX();
    }

    return 0;
}
 
Example 11
Project: ultrasonic   File: ViewHelper.java   Source Code and License Vote up 5 votes
public static int getLeft(View v) {
    if (MenuDrawer.USE_TRANSLATIONS) {
        return (int) (v.getLeft() + v.getTranslationX());
    }

    return v.getLeft();
}
 
Example 12
Project: BestPracticeApp   File: PointLayout.java   Source Code and License Vote up 5 votes
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        View view = getChildAt(0);
        float width = view.getWidth();
        float height = view.getHeight();
        int left1 = view.getLeft();
        int top1 = view.getTop();
        float w = left1+width / 2;
        float h = top1+height / 2;
        float x = left1 +view.getTranslationX()+ width / 2;
        float y = top1 +view.getTranslationY()+ height / 2;
        path.reset();


        //移动点
        canvas.drawCircle(x, y, RADIUS_MOVE, paint);


        double sqrt = Math.sqrt((x - w) * (x - w) + (y - h) * (y - h));


        if (sqrt >= DISTANCE || isLeave) {
            doLeave();
            return;
        }
        float p = (float) ((OUTLENGTH - sqrt) / OUTLENGTH);


        float radius = ORGINLENGTH * p;
        canvas.drawCircle(w, h, radius, paint);
//        Log.i(TAG, "draw: " + sqrt);
        double cose = (x - w) / sqrt;
        double sine = (y - h) / sqrt;


        double dy = RADIUS_MOVE * cose;
        double dx = RADIUS_MOVE * sine;
        double dy1 = radius * cose;
        double dx1 = radius * sine;


        float x1 = (float) (w - dx1);
        float y1 = (float) (h + dy1);

        float x4 = (float) (w + dx1);
        float y4 = (float) (h - dy1);


        float x2 = (float) (x - dx);
        float y2 = (float) (y + dy);

        float x3 = (float) (x + dx);
        float y3 = (float) (y - dy);


        float xx = w + (x - w) / 2;
        float yy = h + (y - h) / 2;

        path.moveTo(x1, y1);
        path.quadTo(xx, yy, x2, y2);

        path.lineTo(x3, y3);
        path.quadTo(xx, yy, x4, y4);
        path.close();

        canvas.drawPath(path, paint);

//        canvas.drawCircle(x1, y1, 15, paint1);
//        canvas.drawCircle(x2, y2, 15, paint1);
//        canvas.drawCircle(x3, y3, 15, paint2);
//        canvas.drawCircle(x4, y4, 15, paint2);
//        canvas.drawCircle(xx, yy, 15, paint2);
    }
 
Example 13
Project: airgram   File: ViewProxy.java   Source Code and License Vote up 5 votes
public static float getTranslationX(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getTranslationX();
    } else {
        return view.getTranslationX();
    }
}
 
Example 14
Project: MyLife   File: ElasticDrawer.java   Source Code and License Vote up 5 votes
private int supportGetTranslationX(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return (int) v.getTranslationX();
    }

    return 0;
}
 
Example 15
Project: Cybernet-VPN   File: ElasticDrawer.java   Source Code and License Vote up 5 votes
private int supportGetTranslationX(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return (int) v.getTranslationX();
    }

    return 0;
}
 
Example 16
Project: SnakeViewMaker   File: SnakeViewMaker.java   Source Code and License Vote up 5 votes
private void updateChildrenPosition() {
    updateTargetViewLocation();
    for (View child : mChildren) {
        if (mTargetLocation[0] == child.getTranslationX()
                && mTargetLocation[1] == child.getTranslationY())
            break;
        child.setTranslationX(mTargetLocation[0]);
        child.setTranslationY(mTargetLocation[1]);
        child.requestLayout();
    }
}
 
Example 17
Project: Cybernet-VPN   File: ViewHelper.java   Source Code and License Vote up 4 votes
@SuppressLint("NewApi")
static int getRight(View v) {
    return (int) (v.getRight() + v.getTranslationX());
}
 
Example 18
Project: boohee_v5.6   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
public static float getTranslationX(View view) {
    return view.getTranslationX();
}
 
Example 19
Project: MyLife   File: ViewHelper.java   Source Code and License Vote up 4 votes
@SuppressLint("NewApi")
static int getLeft(View v) {
    return (int) (v.getLeft() + v.getTranslationX());
}
 
Example 20
Project: MyLife   File: ViewHelper.java   Source Code and License Vote up 4 votes
@SuppressLint("NewApi")
static int getRight(View v) {
    return (int) (v.getRight() + v.getTranslationX());
}