Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CViewN extends View {
- int width;
- int height;
- int gapV;
- int x;
- int y;
- Paint vaweP;
- Paint cPaint1;
- Paint cPaint2;
- Paint cPaint3;
- Paint cPaint4;
- int alpha = 0;
- RectF rectCircle;
- float initialRadius;
- float radiusOffset;
- ValueAnimator anim = ValueAnimator.ofFloat(0, 35);
- int mActivePointerId = MotionEvent.INVALID_POINTER_ID;
- float mLastTouchX;
- float mLastTouchY;
- float mPosX = 0f;
- float mPosY = 0f;
- @Override
- public boolean onTouchEvent(MotionEvent ev){
- final int action = ev.getActionMasked();
- switch (action){
- case MotionEvent.ACTION_DOWN:
- {
- final int pointerIndex = ev.getActionIndex();
- final float x = ev.getX(pointerIndex);
- final float y = ev.getY(pointerIndex);
- // Remember where we started (for dragging)
- mLastTouchX = x;
- mLastTouchY = y;
- mActivePointerId = ev.getPointerId(pointerIndex);
- break;
- }
- case MotionEvent.ACTION_MOVE:
- {
- // Find the index of the active pointer and fetch its position
- final int pointerIndex = ev.findPointerIndex(mActivePointerId);
- final float x = ev.getX(pointerIndex);
- final float y = ev.getY(pointerIndex);
- // Calculate the distance moved
- final float dx = x - mLastTouchX;
- final float dy = y - mLastTouchY;
- mPosX += dx;
- mPosY += dy;
- // Remember this touch position for the next move event
- mLastTouchX = x;
- mLastTouchY = y;
- invalidate();
- break;
- }
- case MotionEvent.ACTION_UP:
- {
- mActivePointerId = MotionEvent.INVALID_POINTER_ID;
- break;
- }
- case MotionEvent.ACTION_CANCEL:
- {
- mActivePointerId = MotionEvent.INVALID_POINTER_ID;
- break;
- }
- case MotionEvent.ACTION_POINTER_UP:
- {
- final int pointerIndex = ev.getActionIndex();
- final int pointerId = ev.getPointerId(pointerIndex);
- if(pointerId == mActivePointerId){
- // This was our active pointer going up. Choose a new
- // active pointer and adjust accordingly.
- final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
- mLastTouchX = ev.getX(newPointerIndex);
- mLastTouchY = ev.getY(newPointerIndex);
- mActivePointerId = ev.getPointerId(newPointerIndex);
- }
- break;
- }
- }
- return true;
- }
- public CViewN(Context context){
- //this(context, null, 0);
- super(context);
- }
- public CViewN(Context context, AttributeSet attrs){
- //this(context, attrs, 0);
- super(context, attrs);
- init(context, attrs);
- }
- public CViewN(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- init(context, attrs);
- }
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- public CViewN(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes){
- super(context, attrs, defStyleAttr, defStyleRes);
- init(context, attrs);
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int heightSize = MeasureSpec.getSize(heightMeasureSpec);
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int desiredWidth = 1000;
- int desiredHeight = 1500;
- int width;
- int height;
- //width
- if(widthMode == MeasureSpec.EXACTLY){
- //Must be this size
- width = widthSize;
- }else if(widthMode == MeasureSpec.AT_MOST){
- //Can't be bigger than...
- width = Math.min(widthSize, desiredWidth);
- }else{
- //Be whatever you want
- width = desiredWidth;
- }
- //height
- if(heightMode == MeasureSpec.EXACTLY){
- //Must be this size
- height = heightSize;
- }else if
- (heightMode == MeasureSpec.AT_MOST){
- //Can't be bigger than...
- height = Math.min(heightSize, desiredHeight);
- }else{
- //Be whatever you want
- height = desiredHeight;
- }
- //MUST CALL THIS
- setMeasuredDimension(width, height);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- width = w;
- height = h;
- x = width/2;
- y = height/2;
- }
- protected void init(Context context, @Nullable AttributeSet attrs) {
- vaweP = new Paint(Paint.ANTI_ALIAS_FLAG);
- vaweP.setStyle(Paint.Style.STROKE);
- vaweP.setColor(Color.RED);
- vaweP.setStrokeWidth(5);
- gapV = 30;
- }
- @Override
- protected void onAttachedToWindow(){
- super.onAttachedToWindow();
- anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator valueAnimator) {
- radiusOffset = (float) valueAnimator.getAnimatedValue();
- alpha = (int) ((float) valueAnimator.getAnimatedValue());
- invalidate();
- }
- });
- anim.setDuration(1000);
- anim.setInterpolator(new LinearInterpolator());
- anim.setRepeatMode(ValueAnimator.RESTART);
- anim.setRepeatCount(ValueAnimator.INFINITE);
- anim.start();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- /* float currentRadius;
- currentRadius = initialRadius;
- while (currentRadius < (width/2)) {
- canvas.drawCircle(x, y, currentRadius, vaweP);
- currentRadius += gapV;
- }*/
- float radius = initialRadius + radiusOffset + mPosY;
- for(int i = 0; i < 10;i++ ){
- canvas.drawCircle(x, y, radius, vaweP);
- radius = radius + 35;
- }
- rectCircle = new RectF(0,0, width, height);
- cPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
- cPaint1.setColor(Color.GREEN);
- cPaint1.setAlpha(30);
- cPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
- cPaint2.setColor(Color.RED);
- cPaint2.setAlpha(30);
- cPaint3 = new Paint(Paint.ANTI_ALIAS_FLAG);
- cPaint3.setColor(Color.BLUE);
- cPaint3.setAlpha(30);
- cPaint4 = new Paint(Paint.ANTI_ALIAS_FLAG);
- cPaint4.setColor(Color.YELLOW);
- cPaint4.setAlpha(30);
- //canvas.drawRoundRect(rectCircle, 10, 10, cPaint);
- canvas.drawArc(rectCircle, alpha, 90, true, cPaint1);
- canvas.drawArc(rectCircle, alpha + 90, 90, true, cPaint2);
- canvas.drawArc(rectCircle, alpha + 180, 90, true, cPaint3);
- canvas.drawArc(rectCircle, alpha + 270, 90, true, cPaint4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement