Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://vk.com/evgenykravchenko0
- ___ ___ ___
- / /\ ___ / /\ / /\
- / /:/_ /__/\ / /:/_ / /:/_
- / /:/ /\ \ \:\ / /:/ /\ / /:/ /\
- / /:/ /:/_ \ \:\ / /:/_/::\ / /:/ /:/_
- /__/:/ /:/ /\ ___ \__\:\ /__/:/__\/\:\ /__/:/ /:/ /\
- \ \:\/:/ /:/ /__/\ | |:| \ \:\ /~~/:/ \ \:\/:/ /:/
- \ \::/ /:/ \ \:\| |:| \ \:\ /:/ \ \::/ /:/
- \ \:\/:/ \ \:\__|:| \ \:\/:/ \ \:\/:/
- \ \::/ \__\::::/ \ \::/ \ \::/
- \__\/ ~~~~ \__\/ \__\/
- ___
- /__/\ ___ ___
- \ \:\ / /\ / /\
- \ \:\ / /:/ / /:/
- _____\__\:\ /__/::\ /__/::\
- /__/::::::::\ \__\/\:\__ \__\/\:\__
- \ \:\~~\~~\/ \ \:\/\ \ \:\/\
- \ \:\ ~~~ \__\::/ \__\::/
- \ \:\ /__/:/ /__/:/
- \ \:\ \__\/ \__\/
- \__\/
- package com.example.graphicbubble;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.os.Handler;
- import android.util.AttributeSet;
- import android.view.MotionEvent;
- import android.widget.ImageView;
- import android.view.View;
- import java.util.ArrayList;
- import java.util.Random;
- public class BubbleView extends ImageView implements View.OnTouchListener {
- private Random rand = new Random();
- private ArrayList<Bubble> bubbleList;
- private int size = 50;
- private int delay = 33;
- private Paint paint = new Paint();
- private Handler handler = new Handler();
- public BubbleView(Context context, AttributeSet attributeSet) {
- super(context, attributeSet);
- bubbleList = new ArrayList<Bubble>();
- //testBubbles();
- setOnTouchListener(this);
- }
- private Runnable runnable = new Runnable() {
- @Override
- public void run() {
- invalidate();
- }
- };
- protected void onDraw (Canvas canvas) {
- for (Bubble b: bubbleList) {
- b.draw(canvas);
- }
- handler.postDelayed(runnable, delay);
- }
- @Override
- public boolean onTouch(View v, MotionEvent motionEvent) {
- for (int i = 0; i < motionEvent.getPointerCount(); i++) {
- int x = (int) motionEvent.getX();
- int y = (int) motionEvent.getY();
- int s = 2 * size;
- bubbleList.add(new Bubble(x, y, s));
- }
- return true;
- }
- private class Bubble {
- private int x;
- private int y;
- private int size;
- private int color;
- public Bubble (int newX, int newY, int newSize) {
- x = newX;
- y = newY;
- size = newSize;
- color = Color.argb(rand.nextInt(256),
- rand.nextInt(256),
- rand.nextInt(256),
- rand.nextInt(256));
- }
- public void draw(Canvas canvas) {
- paint.setColor(color);
- canvas.drawOval(x - size / 2, y - size / 2,
- x + size / 2, y + size / 2, paint);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement