Java Code Examples for com.nineoldandroids.view.ViewHelper

The following are top voted examples for showing how to use com.nineoldandroids.view.ViewHelper. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: Instrument.java   View source code 6 votes vote down vote up
public void slidingToY(View view ,float y){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setY(y);
    }else{
        ViewHelper.setY(view, y);
    }
}
 
Example 2
Project: OpenEyesReading-android   File: RotateDownPage.java   View source code 6 votes vote down vote up
@Override
public void transformPage(View page, float position) {
    if (position < -1) {
        ViewHelper.setRotation(page, 0);
    } else if (position <= 1) {
        if (position < 0) {
            mRot = (ROT_MAX * position);
            ViewHelper.setPivotX(page, page.getMeasuredWidth() * 0.5f);
            ViewHelper.setPivotY(page, page.getMeasuredHeight());
            ViewHelper.setRotation(page, mRot);
        } else {
            mRot = (ROT_MAX * position);
            ViewHelper.setPivotX(page, page.getMeasuredWidth() * 0.5f);
            ViewHelper.setPivotY(page, page.getMeasuredHeight());
            ViewHelper.setRotation(page, mRot);
        }
    } else {
        ViewHelper.setRotation(page, 0);
    }
}
 
Example 3
Project: GitHub   File: SlideLayout.java   View source code 6 votes vote down vote up
@Override
	public void computeScroll() {
		if (mScroller.computeScrollOffset()) {
			scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
			scrollX=mScroller.getCurrX();
//			这里是判断打开菜单时即向右滑动菜单向右滑动 实现视觉差滑动效果,scrollX就是监听startScroll开始滚动程X的值,因为getScrollX()只是监听手在屏幕上滑动的过程,手离开后就要在这里监听,0.7是可以根据需求改动
			if(scrollX<oldX){
//			Log.d("gaolei", "scrollX2--------------------------------|"+scrollX);
			ViewHelper.setTranslationX(getChildAt(0), (menuWidth+scrollX)* 0.7f);
			}
//			这里是判断点击菜单按钮关闭时,对菜单做处理,已达到视觉差效果,不然的话没有
			if(clickMenuToClose){
				ViewHelper.setTranslationX(getChildAt(0), (menuWidth+scrollX)* 0.7f);
			}
			oldX=scrollX;
			postInvalidate();
			
		}
	}
 
Example 4
Project: GitHub   File: SlidingMenu.java   View source code 6 votes vote down vote up
@Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        float scale = l * 1.0f / mMenuWidth;
        float leftScale = 1 - 0.3f * scale;
        float rightScale = 0.8f + scale * 0.2f;

//		ViewHelper.setScaleX(mMenu, leftScale);
//		ViewHelper.setScaleY(mMenu, leftScale);
//		ViewHelper.setAlpha(mMenu, 0.6f + 0.4f * (1 - scale));
//		Log.d("gaolei","mMenuWidth----------------"+mMenuWidth);
//		Log.d("gaolei","l---------------"+l);
//		Log.d("gaolei","scale----------------"+l * 1.0f / mMenuWidth);
//		Log.d("gaolei"," mMenuWidth * scale * 0.7f----------------"+ mMenuWidth * scale * 0.7f);
        ViewHelper.setTranslationX(mMenu, mMenuWidth * scale * 0.7f);

//		ViewHelper.setPivotX(mContent, 0);
//		ViewHelper.setPivotY(mContent, mContent.getHeight() / 2);
//		ViewHelper.setScaleX(mContent, rightScale);
//		ViewHelper.setScaleY(mContent, rightScale);

    }
 
Example 5
Project: JazzyViewPager   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateRotate(View left, View right, float positionOffset, boolean up) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = (up ? 1 : -1) * (ROT_MAX * positionOffset);
			mTrans = (up ? -1 : 1) * (float) (getMeasuredHeight() - getMeasuredHeight()*Math.cos(mRot*Math.PI/180.0f));
			ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(left, up ? 0 : left.getMeasuredHeight());
			ViewHelper.setTranslationY(left, mTrans);
			ViewHelper.setRotation(left, mRot);
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = (up ? 1 : -1) * (-ROT_MAX + ROT_MAX*positionOffset);
			mTrans = (up ? -1 : 1) * (float) (getMeasuredHeight() - getMeasuredHeight()*Math.cos(mRot*Math.PI/180.0f));
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, up ? 0 : right.getMeasuredHeight());
			ViewHelper.setTranslationY(right, mTrans);
			ViewHelper.setRotation(right, mRot);
		}
	}
}
 
Example 6
Project: DMAudioStreamer   File: Slider.java   View source code 6 votes vote down vote up
public void setValue(final int value) {
    if (placedBall == false)
        post(new Runnable() {

            @Override
            public void run() {
                setValue(value);
            }
        });
    else {
        this.value = value;
        float division = (ball.xFin - ball.xIni) / max;
        ViewHelper.setX(ball, value * division + getHeight() / 2 - ball.getWidth() / 2);
        ball.changeBackground();
    }

}
 
Example 7
Project: DMAudioStreamer   File: Slider.java   View source code 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (!placedBall) {
        placeBall();
    }

    Paint paint = new Paint();
    paint.setColor(backgroundColorLine);
    paint.setStrokeWidth(dpToPx(3, getResources()));
    canvas.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint);
    paint.setColor(backgroundColor);
    float division = (ball.xFin - ball.xIni) / (max - min);
    int value = this.value - min;
    canvas.drawLine(getHeight() / 2, getHeight() / 2, value * division + getHeight() / 2, getHeight() / 2, paint);

    if (press) {
        paint.setColor(backgroundColor);
        paint.setAntiAlias(true);
        canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, getHeight() / 2, getHeight() / 4, paint);
    }
    invalidate();
}
 
Example 8
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
protected void animateTablet(View left, View right, float positionOffset) {		
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 30.0f * positionOffset;
			mTrans = getOffsetXForRotation(mRot, left.getMeasuredWidth(),
					left.getMeasuredHeight());
			ViewHelper.setPivotX(left, left.getMeasuredWidth()/2);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()/2);
			ViewHelper.setTranslationX(left, mTrans);
			ViewHelper.setRotationY(left, mRot);
			logState(left, "Left");
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -30.0f * (1-positionOffset);
			mTrans = getOffsetXForRotation(mRot, right.getMeasuredWidth(), 
					right.getMeasuredHeight());
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setTranslationX(right, mTrans);
			ViewHelper.setRotationY(right, mRot);
			logState(right, "Right");
		}
	}
}
 
Example 9
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateCube(View left, View right, float positionOffset, boolean in) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = (in ? 90.0f : -90.0f) * positionOffset;
			ViewHelper.setPivotX(left, left.getMeasuredWidth());
			ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
			ViewHelper.setRotationY(left, mRot);
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -(in ? 90.0f : -90.0f) * (1-positionOffset);
			ViewHelper.setPivotX(right, 0);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setRotationY(right, mRot);
		}
	}
}
 
Example 10
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateAccordion(View left, View right, float positionOffset) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			ViewHelper.setPivotX(left, left.getMeasuredWidth());
			ViewHelper.setPivotY(left, 0);
			ViewHelper.setScaleX(left, 1-positionOffset);
		}
		if (right != null) {
			manageLayer(right, true);
			ViewHelper.setPivotX(right, 0);
			ViewHelper.setPivotY(right, 0);
			ViewHelper.setScaleX(right, positionOffset);
		}
	}
}
 
Example 11
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateZoom(View left, View right, float positionOffset, boolean in) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mScale = in ? ZOOM_MAX + (1-ZOOM_MAX)*(1-positionOffset) :
				1+ZOOM_MAX - ZOOM_MAX*(1-positionOffset);
			ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
			ViewHelper.setScaleX(left, mScale);
			ViewHelper.setScaleY(left, mScale);
		}
		if (right != null) {
			manageLayer(right, true);
			mScale = in ? ZOOM_MAX + (1-ZOOM_MAX)*positionOffset :
				1+ZOOM_MAX - ZOOM_MAX*positionOffset;
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
		}
	}
}
 
Example 12
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateRotate(View left, View right, float positionOffset, boolean up) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = (up ? 1 : -1) * (ROT_MAX * positionOffset);
			mTrans = (up ? -1 : 1) * (float) (getMeasuredHeight() - getMeasuredHeight()*Math.cos(mRot*Math.PI/180.0f));
			ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(left, up ? 0 : left.getMeasuredHeight());
			ViewHelper.setTranslationY(left, mTrans);
			ViewHelper.setRotation(left, mRot);
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = (up ? 1 : -1) * (-ROT_MAX + ROT_MAX*positionOffset);
			mTrans = (up ? -1 : 1) * (float) (getMeasuredHeight() - getMeasuredHeight()*Math.cos(mRot*Math.PI/180.0f));
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, up ? 0 : right.getMeasuredHeight());
			ViewHelper.setTranslationY(right, mTrans);
			ViewHelper.setRotation(right, mRot);
		}
	}
}
 
Example 13
Project: JewelryUI   File: JazzyViewPager.java   View source code 6 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {		
	if (mState != State.IDLE) {
		if (right != null) {
			manageLayer(right, true);
			mScale = (1-SCALE_MAX) * positionOffset + SCALE_MAX;
			mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
			ViewHelper.setTranslationX(right, mTrans);
		}
		if (left != null) {
			left.bringToFront();
		}
	}
}
 
Example 14
Project: JewelryUI   File: ViewAnimationUtils.java   View source code 6 votes vote down vote up
/**
 * Lifting view
 *
 * @param view         The animation target
 * @param baseRotation initial Rotation X in 3D space
 * @param fromY        initial Y position of view
 * @param duration     aniamtion duration
 * @param startDelay   start delay before animation begin
 */
@Deprecated
public static void liftingFromBottom(View view, float baseRotation, float fromY, int duration, int startDelay) {
    ViewHelper.setRotationX(view, baseRotation);
    ViewHelper.setTranslationY(view, fromY);

    ViewPropertyAnimator
            .animate(view)
            .setInterpolator(new AccelerateDecelerateInterpolator())
            .setDuration(duration)
            .setStartDelay(startDelay)
            .rotationX(0)
            .translationY(0)
            .start();

}
 
Example 15
Project: JewelryUI   File: ViewAnimationUtils.java   View source code 6 votes vote down vote up
/**
 * Lifting view
 *
 * @param view         The animation target
 * @param baseRotation initial Rotation X in 3D space
 * @param duration     aniamtion duration
 * @param startDelay   start delay before animation begin
 */
@Deprecated
public static void liftingFromBottom(View view, float baseRotation, int duration, int startDelay) {
    ViewHelper.setRotationX(view, baseRotation);
    ViewHelper.setTranslationY(view, view.getHeight() / 3);

    ViewPropertyAnimator
            .animate(view)
            .setInterpolator(new AccelerateDecelerateInterpolator())
            .setDuration(duration)
            .setStartDelay(startDelay)
            .rotationX(0)
            .translationY(0)
            .start();

}
 
Example 16
Project: Sega   File: FadeTransformer.java   View source code 6 votes vote down vote up
@Override
protected void onTransform(View view, float position) {

    // Page is not an immediate sibling, just make transparent
    if(position < -1 || position > 1) {
        ViewHelper.setAlpha(view,0.6f);
    }
    // Page is sibling to left or right
    else if (position <= 0 || position <= 1) {

        // Calculate alpha.  Position is decimal in [-1,0] or [0,1]
        float alpha = (position <= 0) ? position + 1 : 1 - position;
        ViewHelper.setAlpha(view,alpha);

    }
    // Page is active, make fully visible
    else if (position == 0) {
        ViewHelper.setAlpha(view,1);
    }
}
 
Example 17
Project: HutHelper   File: DragLayout.java   View source code 6 votes vote down vote up
private void animateView(float percent) {
    float f1 = 1 - percent * 0.3f;
    ViewHelper.setScaleX(vg_main, f1);   //主布局逐渐变大
    ViewHelper.setScaleY(vg_main, f1);
    ViewHelper.setTranslationX(vg_left, -vg_left.getWidth() / 2.3f
            + vg_left.getWidth() / 2.3f * percent);
    ViewHelper.setScaleX(vg_left, 0.5f + 0.5f * percent);//左边的布局逐渐变小
    ViewHelper.setScaleY(vg_left, 0.5f + 0.5f * percent);
    ViewHelper.setAlpha(vg_left, percent);
    if (isShowShadow) {
        ViewHelper.setScaleX(iv_shadow, f1 * 1.4f * (1 - percent * 0.12f));
        ViewHelper.setScaleY(iv_shadow, f1 * 1.85f * (1 - percent * 0.12f));
    }
    getBackground().setColorFilter(
            evaluate(percent, Color.BLACK, Color.TRANSPARENT),
            Mode.SRC_OVER);
}
 
Example 18
Project: NeteaseCloudMusic   File: ScanMusicActivity.java   View source code 6 votes vote down vote up
private void initAnimations() {
    searchAnimation = ValueAnimator.ofFloat(0f, 1f);
    searchAnimation.setDuration(50000);
    searchAnimation.setRepeatCount(ValueAnimator.INFINITE);
    searchAnimation.setRepeatMode(ValueAnimator.RESTART);
    searchAnimation.setInterpolator(new LinearInterpolator());
    searchAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float angle = (valueAnimator.getAnimatedFraction() * 360);
            ViewHelper.setTranslationX(ivSearch, (float) Math.sin(angle) * radius);
            ViewHelper.setTranslationY(ivSearch, (float) Math.cos(angle) * radius);
        }
    });


    scanAnimation = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.61f);
    scanAnimation.setDuration(2000);
    scanAnimation.setRepeatCount(TranslateAnimation.INFINITE);
    scanAnimation.setRepeatMode(TranslateAnimation.RESTART);
}
 
Example 19
Project: JazzyViewPager   File: JazzyViewPager.java   View source code 6 votes vote down vote up
protected void animateTablet(View left, View right, float positionOffset) {		
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 30.0f * positionOffset;
			mTrans = getOffsetXForRotation(mRot, left.getMeasuredWidth(),
					left.getMeasuredHeight());
			ViewHelper.setPivotX(left, left.getMeasuredWidth()/2);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()/2);
			ViewHelper.setTranslationX(left, mTrans);
			ViewHelper.setRotationY(left, mRot);
			logState(left, "Left");
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -30.0f * (1-positionOffset);
			mTrans = getOffsetXForRotation(mRot, right.getMeasuredWidth(), 
					right.getMeasuredHeight());
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setTranslationX(right, mTrans);
			ViewHelper.setRotationY(right, mRot);
			logState(right, "Right");
		}
	}
}
 
Example 20
Project: JazzyViewPager   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateCube(View left, View right, float positionOffset, boolean in) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = (in ? 90.0f : -90.0f) * positionOffset;
			ViewHelper.setPivotX(left, left.getMeasuredWidth());
			ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
			ViewHelper.setRotationY(left, mRot);
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -(in ? 90.0f : -90.0f) * (1-positionOffset);
			ViewHelper.setPivotX(right, 0);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setRotationY(right, mRot);
		}
	}
}
 
Example 21
Project: JazzyViewPager   File: JazzyViewPager.java   View source code 6 votes vote down vote up
private void animateAccordion(View left, View right, float positionOffset) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			ViewHelper.setPivotX(left, left.getMeasuredWidth());
			ViewHelper.setPivotY(left, 0);
			ViewHelper.setScaleX(left, 1-positionOffset);
		}
		if (right != null) {
			manageLayer(right, true);
			ViewHelper.setPivotX(right, 0);
			ViewHelper.setPivotY(right, 0);
			ViewHelper.setScaleX(right, positionOffset);
		}
	}
}
 
Example 22
Project: ClouldReader   File: Instrument.java   View source code 5 votes vote down vote up
public float getTranslationY(View view){
    if(view == null){
        return 0;
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        return view.getTranslationY();
    }else{
        return ViewHelper.getTranslationY(view);
    }
}
 
Example 23
Project: ClouldReader   File: Instrument.java   View source code 5 votes vote down vote up
public void slidingByDelta(View view ,float delta){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setTranslationY(delta);
    }else{
        ViewHelper.setTranslationY(view, delta);
    }
}
 
Example 24
Project: ClouldReader   File: Instrument.java   View source code 5 votes vote down vote up
public void slidingToY(View view ,float y){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setY(y);
    }else{
        ViewHelper.setY(view, y);
    }
}
 
Example 25
Project: GitHub   File: Instrument.java   View source code 5 votes vote down vote up
public float getTranslationY(View view){
    if(view == null){
        return 0;
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        return view.getTranslationY();
    }else{
        return ViewHelper.getTranslationY(view);
    }
}
 
Example 26
Project: GitHub   File: Instrument.java   View source code 5 votes vote down vote up
public void slidingByDelta(View view ,float delta){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setTranslationY(delta);
    }else{
        ViewHelper.setTranslationY(view, delta);
    }
}
 
Example 27
Project: pius1   File: SlideBottomPanel.java   View source code 5 votes vote down vote up
private void handleActionUp(MotionEvent event) {
    if (!isPanelOnTouch) {
        return;
    }
    long pressDuration = System.currentTimeMillis() - mPressStartTime;
    computeVelocity();
    if (!isPanelShowing && ((event.getY() - firstDownY) < 0 && (Math.abs(event.getY() - firstDownY) > mMoveDistanceToTrigger))
                || (yVelocity < 0 && Math.abs(yVelocity) > Math.abs(xVelocity) && Math.abs(yVelocity) > mMinVelocity)) {
        displayPanel();
    } else if (!isPanelShowing && pressDuration < MAX_CLICK_TIME &&
            distance(firstDownX, firstDownY, event.getX(), event.getY()) < MAX_CLICK_DISTANCE) {
        displayPanel();
    } else if (!isPanelShowing && isDragging && ((event.getY() - firstDownY > 0) ||
            Math.abs(event.getY() - firstDownY) < mMoveDistanceToTrigger)){
        hidePanel();
    }

    if (isPanelShowing) {
        View mPanel = findViewWithTag(TAG_PANEL);
        float currentY = ViewHelper.getY(mPanel);
        if (currentY < (mMeasureHeight - mPanelHeight) ||
                currentY < (mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger)) {
            ObjectAnimator.ofFloat(mPanel, "y", currentY, mMeasureHeight - mPanelHeight)
                    .setDuration(mAnimationDuration).start();
        } else if (currentY > mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger){
            hidePanel();
        }
    }

    isPanelOnTouch = false;
    isDragging = false;
    deltaY = 0;
}
 
Example 28
Project: JazzyViewPager   File: JazzyViewPager.java   View source code 5 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {		
	if (mState != State.IDLE) {
		if (right != null) {
			manageLayer(right, true);
			mScale = (1-SCALE_MAX) * positionOffset + SCALE_MAX;
			mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
			ViewHelper.setTranslationX(right, mTrans);
		}
		if (left != null) {
			left.bringToFront();
		}
	}
}
 
Example 29
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (isEnabled()) {
		isLastTouch = true;
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			press = true;
		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			requestDisallowInterceptTouchEvent(true);
			float x = event.getX();
			x = (x < ball.xIni) ? ball.xIni : x;
			x = (x > ball.xFin) ? ball.xFin : x;
			if (x > ball.xCen) {
				iSchecked = true;
			} else {
				iSchecked = false;
			}
			ViewHelper.setX(ball, x);
			ball.changeBackground();
			if (event.getX() <= getWidth() && event.getX() >= 0) {
				isLastTouch = false;
				press = false;
			}
		} else if (event.getAction() == MotionEvent.ACTION_UP 
				|| event.getAction() == MotionEvent.ACTION_CANCEL) {
			requestDisallowInterceptTouchEvent(false);
			press = false;
			isLastTouch = false;
			if (eventCheck != iSchecked) {
				eventCheck = iSchecked;
				if (onCheckListener != null)
					onCheckListener.onCheck(iSchecked);
			}
			if (event.getX() <= getWidth() && event.getX() >= 0) {
				ball.animateCheck();
			} 
		}
	}
	return true;
}
 
Example 30
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (!placedBall)
		placeBall();

	// Crop line to transparent effect
	Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(),
			canvas.getHeight(), Bitmap.Config.ARGB_8888);
	Canvas temp = new Canvas(bitmap);
	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setColor((iSchecked) ? backgroundColor : Color.parseColor("#B0B0B0"));
	paint.setStrokeWidth(Utils.dpToPx(2, getResources()));
	temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint);
	Paint transparentPaint = new Paint();
	transparentPaint.setAntiAlias(true);
	transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
	transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
	temp.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2,
			ViewHelper.getY(ball) + ball.getHeight() / 2, ball.getWidth() / 2, transparentPaint);
	canvas.drawBitmap(bitmap, 0, 0, new Paint());

	if (press) {
		paint.setColor((iSchecked) ? makePressColor(70) : Color.parseColor("#446D6D6D"));
		canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, getHeight() / 2, getHeight() / 2, paint);
	}
	invalidate();
}
 
Example 31
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
private void placeBall() {
	ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2);
	ball.xIni = ViewHelper.getX(ball);
	ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2;
	ball.xCen = getWidth() / 2 - ball.getWidth() / 2;
	placedBall = true;
	ball.animateCheck();
}
 
Example 32
Project: XERUNG   File: Slider.java   View source code 5 votes vote down vote up
private void placeBall() {
	ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2);
	ball.xIni = ViewHelper.getX(ball);
	ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2;
	ball.xCen = getWidth() / 2 - ball.getWidth() / 2;
	placedBall = true;
}
 
Example 33
Project: XERUNG   File: Slider.java   View source code 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (numberIndicatorResize == false) {
		RelativeLayout.LayoutParams params = (LayoutParams) numberIndicator.
				numberIndicator.getLayoutParams();
		params.height = (int) finalSize * 2;
		params.width = (int) finalSize * 2;
		numberIndicator.numberIndicator.setLayoutParams(params);
	}

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setColor(backgroundColor);
	if (animate) {
		if (y == 0)
			y = finalY + finalSize * 2;
		y -= Utils.dpToPx(6, getResources());
		size += Utils.dpToPx(2, getResources());
	}
	canvas.drawCircle(
			ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent())
					+ ball.getWidth() / 2, y, size, paint);
	if (animate && size >= finalSize)
		animate = false;
	if (animate == false) {
		ViewHelper.setX(numberIndicator.numberIndicator, 
				(ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent()) + ball.getWidth() / 2) - size);
		ViewHelper.setY(numberIndicator.numberIndicator, y - size);
		numberIndicator.numberIndicator.setText(value + "");
	}
	invalidate();
}
 
Example 34
Project: XERUNG   File: ButtonFloat.java   View source code 5 votes vote down vote up
/**
 * float的动画 
 */
private void playAnimation() {
	post(new Runnable() {
		@Override
		public void run() {
			float originalY = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources());
			ViewHelper.setY(ButtonFloat.this, 
					ViewHelper.getY(ButtonFloat.this) + getHeight() * 3);
			ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", originalY);
			animator.setInterpolator(new BounceInterpolator());
			animator.setDuration(1500);// 动画持续时间
			animator.start();
		}
	});
}
 
Example 35
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (isEnabled()) {
		isLastTouch = true;
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			press = true;
		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			requestDisallowInterceptTouchEvent(true);
			float x = event.getX();
			x = (x < ball.xIni) ? ball.xIni : x;
			x = (x > ball.xFin) ? ball.xFin : x;
			if (x > ball.xCen) {
				iSchecked = true;
			} else {
				iSchecked = false;
			}
			ViewHelper.setX(ball, x);
			ball.changeBackground();
			if (event.getX() <= getWidth() && event.getX() >= 0) {
				isLastTouch = false;
				press = false;
			}
		} else if (event.getAction() == MotionEvent.ACTION_UP 
				|| event.getAction() == MotionEvent.ACTION_CANCEL) {
			requestDisallowInterceptTouchEvent(false);
			press = false;
			isLastTouch = false;
			if (eventCheck != iSchecked) {
				eventCheck = iSchecked;
				if (onCheckListener != null)
					onCheckListener.onCheck(iSchecked);
			}
			if (event.getX() <= getWidth() && event.getX() >= 0) {
				ball.animateCheck();
			} 
		}
	}
	return true;
}
 
Example 36
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (!placedBall)
		placeBall();

	// Crop line to transparent effect
	Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(),
			canvas.getHeight(), Bitmap.Config.ARGB_8888);
	Canvas temp = new Canvas(bitmap);
	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setColor((iSchecked) ? backgroundColor : Color.parseColor("#B0B0B0"));
	paint.setStrokeWidth(Utils.dpToPx(2, getResources()));
	temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint);
	Paint transparentPaint = new Paint();
	transparentPaint.setAntiAlias(true);
	transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
	transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
	temp.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2,
			ViewHelper.getY(ball) + ball.getHeight() / 2, ball.getWidth() / 2, transparentPaint);
	canvas.drawBitmap(bitmap, 0, 0, new Paint());

	if (press) {
		paint.setColor((iSchecked) ? makePressColor(70) : Color.parseColor("#446D6D6D"));
		canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, getHeight() / 2, getHeight() / 2, paint);
	}
	invalidate();
}
 
Example 37
Project: XERUNG   File: Switch.java   View source code 5 votes vote down vote up
private void placeBall() {
	ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2);
	ball.xIni = ViewHelper.getX(ball);
	ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2;
	ball.xCen = getWidth() / 2 - ball.getWidth() / 2;
	placedBall = true;
	ball.animateCheck();
}
 
Example 38
Project: XERUNG   File: Slider.java   View source code 5 votes vote down vote up
private void placeBall() {
	ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2);
	ball.xIni = ViewHelper.getX(ball);
	ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2;
	ball.xCen = getWidth() / 2 - ball.getWidth() / 2;
	placedBall = true;
}
 
Example 39
Project: XERUNG   File: Slider.java   View source code 5 votes vote down vote up
private void setValueInRunnable(final int value,final boolean inRunnable) {
	if(placedBall == false && inRunnable == true)
		post(new Runnable() {
			@Override
			public void run() {
				setValue(value,inRunnable);
			}
		});
	else{
		this.value = value;
		float division = (ball.xFin - ball.xIni) / max;
		ViewHelper.setX(ball,value*division + getHeight()/2 - ball.getWidth()/2);
		ball.changeBackground();
	}
}
 
Example 40
Project: XERUNG   File: Slider.java   View source code 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (numberIndicatorResize == false) {
		RelativeLayout.LayoutParams params = (LayoutParams) numberIndicator.
				numberIndicator.getLayoutParams();
		params.height = (int) finalSize * 2;
		params.width = (int) finalSize * 2;
		numberIndicator.numberIndicator.setLayoutParams(params);
	}

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setColor(backgroundColor);
	if (animate) {
		if (y == 0)
			y = finalY + finalSize * 2;
		y -= Utils.dpToPx(6, getResources());
		size += Utils.dpToPx(2, getResources());
	}
	canvas.drawCircle(
			ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent())
					+ ball.getWidth() / 2, y, size, paint);
	if (animate && size >= finalSize)
		animate = false;
	if (animate == false) {
		ViewHelper.setX(numberIndicator.numberIndicator, 
				(ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent()) + ball.getWidth() / 2) - size);
		ViewHelper.setY(numberIndicator.numberIndicator, y - size);
		numberIndicator.numberIndicator.setText(value + "");
	}
	invalidate();
}