package com.gusfree.draw;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			Paint yellow=new Paint();
			yellow.setColor(Color.YELLOW);
			yellow.setAntiAlias(true);
			canvas.drawCircle(160, 50, 20, yellow);

			yellow.setStyle(Style.STROKE);
			canvas.drawCircle(160+100, 50, 20, yellow);


			yellow.setStrokeWidth(10);//선 두껍게
			canvas.drawLine(160+20,50+50,160+100-20,50+50,yellow);

		}
	}
}




package com.gusfree.draw;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			Paint yellow=new Paint();
			yellow.setColor(Color.YELLOW);
			yellow.setAntiAlias(true);
			canvas.drawCircle(160, 50, 20, yellow);

			yellow.setStyle(Style.STROKE);
			canvas.drawCircle(160+100, 50, 20, yellow);


			yellow.setStrokeWidth(10);//선 두껍게
			canvas.drawLine(160+20,50+50,160+100-20,50+50,yellow);

			/* mission: 동그라미 100개 random한 크기와 위치*/			
			Random random = new Random();

			Paint rPaint=new Paint();
			for(int i=0;i<100;i++){
				int x =random.nextInt(320);//0~320까지 랜덤
				int y = random.nextInt(400);
				int r = random.nextInt(160);
				int red =random.nextInt();
				int green =random.nextInt();
				int blue =random.nextInt();
				rPaint.setColor(Color.rgb(red, green, blue));
				canvas.drawCircle(x, y, r, rPaint);

			}

		}
	}
}




package com.gusfree.draw;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			Paint bluePaint=new Paint();
			bluePaint.setColor(Color.BLUE);
			
			canvas.drawRect(100, 200,100+200,200+50,bluePaint);
			
			RectF oval=new RectF(50,50,300,100);
			canvas.drawOval(oval, bluePaint);
			
			
		}
	}
}  



package com.gusfree.draw;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			Paint white=new Paint();
			white.setColor(Color.WHITE);
			white.setTextSize(30);
			canvas.drawText("안녕하세요", 75, 75, white);
		}
	}
}



package com.gusfree.draw;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			Paint bluePaint=new Paint();
			bluePaint.setColor(Color.BLUE);
			
			canvas.drawRect(100, 200,100+200,200+50,bluePaint);
			
			RectF oval=new RectF(50,50,300,100);
			canvas.drawOval(oval, bluePaint);
			
			Paint white=new Paint();
			white.setColor(Color.WHITE);
			white.setTextSize(30);
			canvas.drawText("안녕하세요", 75, 75, white);
			canvas.drawArc(oval,-150, 100, false, white);
		}
	}
}  



package com.gusfree.draw;

import java.io.InputStream;

import java.net.URL;
import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;

public class DrawActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MyView(this));

		//View  - TextView
	}
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			
			String addr="http://www.imaeil.com/news_img/2012/StarNews/20120504_170303000.jpg";
			try{
			URL url=new URL(addr);
			
			//단말기에서 WebServer로 데이터 요청	
			InputStream is=url.openStream();//요청+ 결과 받기
			
			//비트맵 공장에서 받은 데이터로 bitmap 생성
			Bitmap bitmap=BitmapFactory.decodeStream(is);
			
			BitmapFactory.decodeStream(is);
			
			
			canvas.drawBitmap(bitmap, 10, 10,null);
			}catch(Exception e){
				
			}
		}
	}
}  




'Android > 2012.04월 강좌' 카테고리의 다른 글

8일차 Draw 3 TouchEvent  (0) 2012.05.07
8일차 Draw 2 TouchEvent  (0) 2012.05.07
7일차 Thread 2  (0) 2012.05.04
7일차 Thread  (0) 2012.05.04
7일차 Notification  (0) 2012.05.04

+ Recent posts