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

The following are Jave code examples for showing how to use setX() of the com.nineoldandroids.view.ViewHelper class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DMAudioStreamer   File: Slider.java   View Source Code Vote up 6 votes
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
Project: XERUNG   File: Switch.java   View Source Code Vote up 5 votes
@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 3
Project: XERUNG   File: Switch.java   View Source Code Vote up 5 votes
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 4
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
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 5
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
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 6
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
@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 7
Project: XERUNG   File: Switch.java   View Source Code Vote up 5 votes
@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 8
Project: XERUNG   File: Switch.java   View Source Code Vote up 5 votes
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 9
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
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 10
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
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 11
Project: XERUNG   File: Slider.java   View Source Code Vote up 5 votes
@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
Project: DMAudioStreamer   File: Slider.java   View Source Code Vote up 5 votes
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
Project: XERUNG   File: Slider.java   View Source Code Vote up 4 votes
@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 14
Project: XERUNG   File: Slider.java   View Source Code Vote up 4 votes
@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 15
Project: DMAudioStreamer   File: Slider.java   View Source Code Vote up 4 votes
@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;
}