Ch3. 캔버스 활용 3-2 도형으로 안드로이드 캐릭터 만들기.

Slides:



Advertisements
Similar presentations
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Advertisements

My own View Android development Maarten Pennings 2011 oct 14.
Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing.
2D Graphics: Part 1. Android Graphics Libraries 2D Graphics –custom 2D graphics library in packages android.graphics android.graphics.drawable android.graphics.drawable.shapes.
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Data Storage: Part 1 (Preferences)
Basic Drawing Techniques
2D Graphics: Part 2.
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
Android Tutorial Team 3 Jerry Yu Mayank Mandava Mu Du Will Wangles.
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
로봇 모니터링 2/2 UNIT 21 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Broadcasting Service 2.
1 Mobile Computing Advanced Touching Copyright 2014 by Janson Industries Assg Part1Assg Part1 AssgPart2AssgPart2.
2012 내장형 시스템 설계  Full Color LED 디바이스 구성  Full Color LED 디바이스 드라이버  Full Color LED JNI 라이브러리 작성  Full Color LED 안드로이드 App 구현  JNI 라이브러리.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
망고 100 보드로 놀아보자 -18 Android 메뉴 생성 및 아이콘 생성 (SPDIF,WM8960)
Android - Broadcast Receivers
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Custom Widget 1 UNIT 26 로봇 SW 콘텐츠 교육원 조용수. 캔버스 public void drawColor(int color) 2 public class ControllerView extends View { public ControllerView(Context.
데이터 저장 & Fragment UNIT 28 로봇 SW 콘텐츠 교육원 조용수. 데이터 저장 & Fragment SharedPreference 로 데이터 저장 Fragment 의 이해 2.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
CHAP 8. 고급 그래픽과 O PEN GL. © 2012 생능출판사 All rights reserved C ANVAS 클래스와 P AINT 클래스.
CHAP 8. 그래픽.
Android Application Lifecycle and Menus
목차 한국기술교육대학교 강사: 김 영 준 ㈜헬로앱스 1일차 아두이노 제어 실습
Android and s Ken Nguyen Clayton state University 2012.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Google map v2.
© 2012 생능출판사 All rights reserved CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 2 차원 그래픽 사용 방법 1) XML 파일로 그래픽이나 애니메이션을 정의한다. 그리는 작업은 안드로이드 시스템이.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 그래픽 XML 파일로 그래픽이나 애니메이션을 정의한다. 그 리는 작업은 안드로이드 시스템이 담당한다. onDraw() 메소드 안에 draw...() 와 같은 메소드를 호.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Advanced.
2D Graphics: Part 1.
Android Introduction Hello World
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
CS499 – Mobile Application Development
Android Introduction Hello World.
2D Graphics: Part 2.
Android Widgets 1 7 August 2018
Android – Read/Write to External Storage
תכנות ב android אליהו חלסצ'י.
Picasso Revisted.
Android Programming Lecture 6
CIS 470 Mobile App Development
null, true, and false are also reserved.
Graphics with Canvas.
CMPE419 Mobile Application Development
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
CIS 470 Mobile App Development
Android Notifications
ארועים ומאזינים android.
CMPE419 Mobile Application Development
Activities, Fragments, and Intents
CIS 470 Mobile App Development
Presentation transcript:

Ch3. 캔버스 활용 3-2 도형으로 안드로이드 캐릭터 만들기

프로그램 구성 프로젝트 생성 사용자 뷰 클래스 생성

실행결과

소스 코드 ShapeAppActivity.java 001: package my.test.canvas; 002: 003: import android.app.Activity; 004: import android.os.Bundle; 005: 006: public class ShapeAppActivity extends Activity { 007: 008: @Override 009: public void onCreate(Bundle savedInstanceState) { 010: super.onCreate(savedInstanceState); 011: 012: setContentView(new ShapeView(this)); 013: } 014: }

소스 코드 ShapeView.java 001: package my.test.canvas; 002: 003: import android.content.Context; 004: import android.content.res.Configuration; 005: import android.graphics.Canvas; 006: import android.graphics.Color; 007: import android.graphics.LinearGradient; 008: import android.graphics.Paint; 009: import android.graphics.Path; 010: import android.graphics.Point; 011: import android.graphics.RadialGradient; 012: import android.graphics.RectF; 013: import android.graphics.Shader; 014: import android.view.View; 015: 016: public class ShapeView extends View { 017: private final float COMM_WIDTH = 250; 018: private final float HEAD_HEIGHT = COMM_WIDTH - (COMM_WIDTH / 4); 019: private final float EYE_RADIUS = HEAD_HEIGHT / 12; 020: private final float MARGINE = EYE_RADIUS / 2;

소스 코드 ShapeView.java 021: private final float BODY_HEIGHT = HEAD_HEIGHT - COMM_WIDTH / 10; 022: private final float ARM_WIDTH = EYE_RADIUS * 5; 023: 024: private Paint paint; 025: private Point center; 026: 027: private RectF head_rect; 028: private RectF body_rect; 029: private RectF arm_rect; 030: 031: private float x1, y1, x2, y2; 032: 033: public ShapeView(Context context) { 034: super(context); 035: 036: center = new Point(); 037: paint = new Paint(); 038: 039: paint.setAntiAlias(true); 040:

소스 코드 ShapeView.java 041: setBackgroundColor(Color.WHITE); 042: } 043: 042: } 043: 044: @Override 045: protected void onDraw(Canvas canvas) { 046: center.x = getWidth() / 2; 047: 048: Configuration config = getResources().getConfiguration(); 049: if(config.orientation == Configuration.ORIENTATION_LANDSCAPE) { 050: center.y = getHeight() / 2; 051: } 052: else { 053: center.y = getHeight() / 3; 054: } 055: 056: headDraw(canvas, paint); 057: bodyDraw(canvas, paint); 058: 059: super.onDraw(canvas); 060: }

소스 코드 ShapeView.java 061: 062: private void headDraw(Canvas canvas, Paint paint) { 063: x1 = center.x - COMM_WIDTH / 2; 064: y1 = center.y - HEAD_HEIGHT; 065: x2 = center.x + COMM_WIDTH / 2; 066: y2 = center.y; 067: head_rect = new RectF(x1, y1, x2, y2); 068: 069: x1 = head_rect.centerX(); 070: y1 = head_rect.centerY(); 071: RadialGradient grad = new RadialGradient(x1, y1, head_rect.width(), Color.GREEN, Color.BLACK, Shader.TileMode.CLAMP); 072: 073: paint.setAlpha(255); 074: paint.setStyle(Paint.Style.FILL); 075: paint.setShader(grad); 076: 077: canvas.drawArc(head_rect, 0, -180, false, paint); 078: paint.setShader(null); 079: paint.setColor(Color.WHITE); 080: canvas.drawCircle(x1 - EYE_RADIUS * 3, y1 - EYE_RADIUS * 3, EYE_RADIUS, paint);

소스 코드 ShapeView.java 081: canvas.drawCircle(x1 + EYE_RADIUS * 3, y1 - EYE_RADIUS * 3, EYE_RADIUS, paint); 082: 083: antennaDraw(canvas, paint); 084: } 085: 086: private void antennaDraw(Canvas canvas, Paint paint) { 087: x1 = head_rect.centerX(); 088: y1 = head_rect.top; 089: 090: paint.setStyle(Paint.Style.STROKE); 091: paint.setStrokeWidth(10); 092: paint.setColor(Color.rgb(0, 80, 0)); 093: 094: canvas.drawLine(x1 - 60, y1 - 20, x1 - 40, y1+ 7, paint); 095: canvas.drawLine(x1 + 60, y1 - 20, x1 + 40, y1 + 7, paint); 096: } 097: 098: 099: private void bodyDraw(Canvas canvas, Paint paint) { 100: x1 = head_rect.left;

소스 코드 ShapeView.java 101: y1 = head_rect.bottom - HEAD_HEIGHT / 2 + MARGINE; 102: x2 = head_rect.right; 103: y2 = head_rect.bottom + BODY_HEIGHT; 104: body_rect = new RectF(x1, y1, x2, y2); 105: 106: x1 = body_rect.centerX(); 107: y1 = body_rect.top; 108: x2 = body_rect.centerX(); 109: y2 = body_rect.bottom; 110: LinearGradient grad = new LinearGradient(x1, y1, x2, y2, Color.RED, Color.BLACK, Shader.TileMode.CLAMP); 111: 112: paint.setStyle(Paint.Style.FILL); 113: paint.setShader(grad); 114: canvas.drawRoundRect(body_rect, 10, 10, paint); 115: 116: armDraw(canvas, paint); 117: markDraw(canvas, paint); 118: } 119: 120: private void armDraw(Canvas canvas, Paint paint) {

소스 코드 ShapeView.java 121: arm_rect = new RectF(0, body_rect.top, 0, body_rect.bottom - MARGINE * 2); 122: 123: x1 = body_rect.left - ARM_WIDTH; 124: y1 = arm_rect.top; 125: x2 = body_rect.left - MARGINE; 126: y2 = arm_rect.bottom; 127: RectF rect_left = new RectF(x1, y1, x2, y2); 128: 129: x1 = body_rect.right + MARGINE; 130: y1 = arm_rect.top; 131: x2 = body_rect.right + ARM_WIDTH; 132: y2 = arm_rect.bottom; 133: RectF rect_right = new RectF(x1, y1, x2, y2); 134: 135: paint.setStrokeWidth(20); 136: canvas.drawRoundRect(rect_left, 30, 30, paint); 137: canvas.drawRoundRect(rect_right, 30, 30, paint); 138: paint.setShader(null); 139: } 140:

소스 코드 ShapeView.java 141: private void markDraw(Canvas canvas, Paint paint) { 142: Path path = new Path(); 143: 144: paint.setStyle(Paint.Style.STROKE); 145: paint.setStrokeWidth(EYE_RADIUS * 2); 146: paint.setColor(Color.YELLOW); 147: paint.setAlpha(50); 148: 149: path.moveTo(body_rect.left + 40, body_rect.top + 40); 150: path.lineTo(center.x, body_rect.bottom - 70); 151: path.lineTo(body_rect.right - 40, body_rect.top + 40); 152: 153: canvas.drawPath(path, paint); 154: } 155: }