Java Code Examples for com.nineoldandroids.view.ViewHelper#setX()

The following examples show how to use com.nineoldandroids.view.ViewHelper#setX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Slider.java    From MoeGallery with GNU General Public License v3.0 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 2
Source File: Slider.java    From meiShi with Apache License 2.0 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 3
Source File: Slider.java    From DMAudioStreamer with Apache License 2.0 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 4
Source File: Slider.java    From XERUNG with Apache License 2.0 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 5
Source File: Switch.java    From Social with Apache License 2.0 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 6
Source File: Switch.java    From Social with Apache License 2.0 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) {
            float x = event.getX();
            x = (x < ball.xIni) ? ball.xIni : x;
            x = (x > ball.xFin) ? ball.xFin : x;
            if (x > ball.xCen) {
                eventCheck = true;
            } else {
                eventCheck = 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) {
            press = false;
            isLastTouch = false;
            if (eventCheck != check) {
                check = eventCheck;
                if (onCheckListener != null)
                    onCheckListener.onCheck(Switch.this,check);
            }
            if ((event.getX() <= getWidth() && event.getX() >= 0)) {
                ball.animateCheck();
            }
        }
    }
    return true;
}
 
Example 7
Source File: Slider.java    From meiShi with Apache License 2.0 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 8
Source File: ArcAnimator.java    From MousePaint with MIT License 5 votes vote down vote up
void setDegree(float degree){
    mValue = degree;
    View clipView = mTarget.get();
    float x = mArcMetric.getAxisPoint().x + mArcMetric.mRadius
            * Utils.cos(degree);
    float y = mArcMetric.getAxisPoint().y - mArcMetric.mRadius
            * Utils.sin(degree);
    ViewHelper.setX(clipView,x - clipView.getWidth() / 2);
    ViewHelper.setY(clipView,y - clipView.getHeight() / 2);
}
 
Example 9
Source File: Switch.java    From XERUNG with Apache License 2.0 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 10
Source File: Switch.java    From XERUNG with Apache License 2.0 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 11
Source File: Slider.java    From XERUNG with Apache License 2.0 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 12
Source File: Slider.java    From MaterialDesignLibrary with Apache License 2.0 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 13
Source File: Slider.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (numberIndicatorResize == false) {
        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 14
Source File: Switch.java    From XERUNG with Apache License 2.0 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 15
Source File: Slider.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	isLastTouch = true;
	if (isEnabled()) {
		if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
			if (numberIndicator != null && numberIndicator.isShowing() == false)
				numberIndicator.show();// 只要一按下就会冒出指示器
			if ((event.getX() <= getWidth() && event.getX() >= 0)) {
				press = true;
				// calculate value
				int newValue = 0;
				float division = (ball.xFin - ball.xIni) / (max - min);
				if (event.getX() > ball.xFin) {
					newValue = max;
				} else if (event.getX() < ball.xIni) {
					newValue = min;
				} else {
					newValue = min + (int) ((event.getX() - ball.xIni) / division);
				}
				if (value != newValue) {
					value = newValue;
					if (onValueChangedListener != null)
						onValueChangedListener.onValueChanged(newValue);
				}
				// move ball indicator
				float x = event.getX();
				x = (x < ball.xIni) ? ball.xIni : x;
				x = (x > ball.xFin) ? ball.xFin : x;
				ViewHelper.setX(ball, x);
				ball.changeBackground();

				// If slider has number indicator
				if (numberIndicator != null) {
					// move number indicator
					numberIndicator.indicator.x = x;
					// 指示器起始的y坐标是当前控件的顶部Y坐标-当前控件高度的一半,就等于从空间的垂直中心开始。
					numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() ;
					numberIndicator.indicator.finalSize = getHeight() / 2;
					numberIndicator.numberIndicator.setText("");
				}

			} else {
				press = false;
				isLastTouch = false;
				if (numberIndicator != null)
					numberIndicator.dismiss();

			}

		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (numberIndicator != null)
				numberIndicator.dismiss();
			isLastTouch = false;
			press = false;
			if ((event.getX() <= getWidth() && event.getX() >= 0)) {

			}
		}
	}
	return true;
}
 
Example 16
Source File: Slider.java    From MaterialDesignLibrary with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    isLastTouch = true;
    if (isEnabled()) {
        if (event.getAction() == MotionEvent.ACTION_DOWN
                || event.getAction() == MotionEvent.ACTION_MOVE) {
            if (numberIndicator != null
                    && numberIndicator.isShowing() == false)
                numberIndicator.show();
            if ((event.getX() <= getWidth() && event.getX() >= 0)) {
                press = true;
                // calculate value
                int newValue = 0;
                float division = (ball.xFin - ball.xIni) / (max - min);
                if (event.getX() > ball.xFin) {
                    newValue = max;
                } else if (event.getX() < ball.xIni) {
                    newValue = min;
                } else {
                    newValue = min + (int) ((event.getX() - ball.xIni) / division);
                }
                if (value != newValue) {
                    value = newValue;
                    if (onValueChangedListener != null)
                        onValueChangedListener.onValueChanged(newValue);
                }
                // move ball indicator
                float x = event.getX();
                x = (x < ball.xIni) ? ball.xIni : x;
                x = (x > ball.xFin) ? ball.xFin : x;
                ViewHelper.setX(ball, x);
                ball.changeBackground();

                // If slider has number indicator
                if (numberIndicator != null) {
                    // move number indicator
                    numberIndicator.indicator.x = x;
                    numberIndicator.indicator.finalY = Utils
                            .getRelativeTop(this) - getHeight() / 2;
                    numberIndicator.indicator.finalSize = getHeight() / 2;
                    numberIndicator.numberIndicator.setText("");
                }

            } else {
                press = false;
                isLastTouch = false;
                if (numberIndicator != null)
                    numberIndicator.dismiss();

            }

        } else if (event.getAction() == MotionEvent.ACTION_UP ||
                event.getAction() == MotionEvent.ACTION_CANCEL) {
            if (numberIndicator != null)
                numberIndicator.dismiss();
            isLastTouch = false;
            press = false;
        }
    }
    return true;
}
 
Example 17
Source File: Slider.java    From DMAudioStreamer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    isLastTouch = true;
    if (isEnabled()) {
        if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {

            if ((event.getX() <= getWidth() && event.getX() >= 0)) {
                press = true;
                // calculate value
                int newValue = 0;
                float division = (ball.xFin - ball.xIni) / (max - min);
                if (event.getX() > ball.xFin) {
                    newValue = max;
                } else if (event.getX() < ball.xIni) {
                    newValue = min;
                } else {
                    newValue = min + (int) ((event.getX() - ball.xIni) / division);
                }
                if (value != newValue) {
                    value = newValue;
                    if (onValueChangedListener != null)
                        onValueChangedListener.onValueChanged(newValue);
                }
                // move ball indicator
                float x = event.getX();
                x = (x < ball.xIni) ? ball.xIni : x;
                x = (x > ball.xFin) ? ball.xFin : x;
                ViewHelper.setX(ball, x);
                ball.changeBackground();

            } else {
                press = false;
                isLastTouch = false;
            }

        } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
            press = false;
        }
    }
    return true;
}
 
Example 18
Source File: ProgressBarIndeterminateDeterminate.java    From meiShi with Apache License 2.0 4 votes vote down vote up
/**
 * Stop indeterminate animation to convert view in determinate progress bar
 */
private void stopIndeterminate(){
	animation.cancel();
	ViewHelper.setX(progressView,0);
	runAnimation = false;
}
 
Example 19
Source File: TutorialActivity.java    From PhoneTutorial with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
	if(fromViewPosition == -1){
		fromViewPosition = ViewHelper.getX(imageContainer);
		fromViewTitlePosition = ViewHelper.getX(titleContainer);
	}
	switch (arg1.getAction()) {
	case MotionEvent.ACTION_DOWN:
		fromTouchPosition = arg1.getX();
		break;
	case MotionEvent.ACTION_MOVE:
		newPosition = fromViewPosition-(fromTouchPosition-arg1.getX());
		newPosition = (newPosition>0)? 0 : newPosition;
		newPosition = (newPosition< -width*(images.length-1))? -width*(images.length-1) : newPosition;
		ViewHelper.setX(imageContainer,newPosition);
		ViewHelper.setX(titleContainer,fromViewTitlePosition+(newPosition-fromViewPosition)*(widthTitle/width));
		
		break;
	case MotionEvent.ACTION_UP:
		if(newPosition<=(fromViewPosition-width/3)){
			setSmallBackground(positionIndicator.getChildAt(position));
			position++;
			animate();
			fromViewPosition = -position * width;
			fromViewTitlePosition = -position * widthTitle;
			setBigBackground(positionIndicator.getChildAt(position));
		}else if(newPosition>=(fromViewPosition+width/3)){
			setSmallBackground(positionIndicator.getChildAt(position));
			position--;
			animate();
			fromViewPosition = -position * width;
			fromViewTitlePosition = -position * widthTitle;
			setBigBackground(positionIndicator.getChildAt(position));
		}else{
			animate();
			fromViewPosition = -position * width;
			fromViewTitlePosition = -position * widthTitle;
		}
		
		if(position == images.length-1 && !nextButton.isShow)
			nextButton.show();
		else if(nextButton.isShow && position != images.length-1)
			nextButton.hide();
		
		break;

	}
	return true;
}
 
Example 20
Source File: Slider.java    From XERUNG with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	isLastTouch = true;
	if (isEnabled()) {
		if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
			if (numberIndicator != null && numberIndicator.isShowing() == false)
				numberIndicator.show();// 只要一按下就会冒出指示器
			if ((event.getX() <= getWidth() && event.getX() >= 0)) {
				press = true;
				// calculate value
				int newValue = 0;
				float division = (ball.xFin - ball.xIni) / (max - min);
				if (event.getX() > ball.xFin) {
					newValue = max;
				} else if (event.getX() < ball.xIni) {
					newValue = min;
				} else {
					newValue = min + (int) ((event.getX() - ball.xIni) / division);
				}
				if (value != newValue) {
					value = newValue;
					if (onValueChangedListener != null)
						onValueChangedListener.onValueChanged(newValue);
				}
				// move ball indicator
				float x = event.getX();
				x = (x < ball.xIni) ? ball.xIni : x;
				x = (x > ball.xFin) ? ball.xFin : x;
				ViewHelper.setX(ball, x);
				ball.changeBackground();

				// If slider has number indicator
				if (numberIndicator != null) {
					// move number indicator
					numberIndicator.indicator.x = x;
					// 指示器起始的y坐标是当前控件的顶部Y坐标-当前控件高度的一半,就等于从空间的垂直中心开始。
					numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() ;
					numberIndicator.indicator.finalSize = getHeight() / 2;
					numberIndicator.numberIndicator.setText("");
				}

			} else {
				press = false;
				isLastTouch = false;
				if (numberIndicator != null)
					numberIndicator.dismiss();

			}

		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (numberIndicator != null)
				numberIndicator.dismiss();
			isLastTouch = false;
			press = false;
			if ((event.getX() <= getWidth() && event.getX() >= 0)) {

			}
		}
	}
	return true;
}