Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.

Slides:



Advertisements
Similar presentations
UNIT 10 GPIO Test 로봇 SW 교육원 조용수.
Advertisements

Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
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.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
How Inflation Works!. Examine the following code public class MainActivity extends Activity public void onCreate(Bundle savedInstanceState)
Basic Drawing Techniques
I2C UNIT 23 로봇 SW 교육원 조용수. 학습 목표 I2C I2C Protocol 구조 N051 I2C 동작 I2C Register 2.
2D Graphics: Part 2.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
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.
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.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
전광판 만들기 UNIT 04 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Layout XML 이란 ? 기본 XML 속성 Text View 2.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Import import android.graphics.Bitmap; import android.widget.ImageView;
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
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.
Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2.
Custom Widget 1 UNIT 26 로봇 SW 콘텐츠 교육원 조용수. 캔버스 public void drawColor(int color) 2 public class ControllerView extends View { public ControllerView(Context.
Ch3. 캔버스 활용 3-2 도형으로 안드로이드 캐릭터 만들기.
UNIT 30 네트워크 전송 2 로봇 SW 콘텐츠 교육원 조용수.
데이터 저장 & 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 View Stuff. TextViews Display text Display images???
CHAP 8. 고급 그래픽과 O PEN GL. © 2012 생능출판사 All rights reserved C ANVAS 클래스와 P AINT 클래스.
네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.
Android vs. JavaScript 建國科技大學資管系 饒瑞佶 2013/5. JavaScript call Java By JavascriptInterface 將 native code 寫在 JavascriptInterface 內,例 如取得方位的程式 透過 WebView.
Android Application Lifecycle and Menus
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
CHAP 6. 이벤트 처리. © 2012 생능출판사 All rights reserved 폴링과 이벤트 구동 방식.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 그래픽 XML 파일로 그래픽이나 애니메이션을 정의한다. 그 리는 작업은 안드로이드 시스템이 담당한다. onDraw() 메소드 안에 draw...() 와 같은 메소드를 호.
Concurrency in Android
TUTORIAL ON MULTITOUCH AND SWIPE GESTURES
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
CS499 – Mobile Application Development
Android – Event Handling
2D Graphics: Part 2.
Android Widgets 1 7 August 2018
Android Programming Lecture 6
null, true, and false are also reserved.
Graphics with Canvas.
CMPE419 Mobile Application Development
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
JavaScript Reserved Words
滑動 建國科技大學 資管系 饒瑞佶 2013/4 V1 2015/5 V2.
Programming Mobile Applications with Android
滑動 建國科技大學 資管系 饒瑞佶.
Mobile Programming Gestures in Android.
Activities, Fragments, and Intents
CIS 470 Mobile App Development
User Interface Development
User Interface Development
Presentation transcript:

Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수

학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2

Custom View 의 기본 구조 : 생성자 3 public class ControllerView extends View { // 소스에서 직접 생성한 경우 호출되는 생성자 public ControllerView(Context context) { super(context); // TODO Auto-generated constructor stub } // 리소스 XML 에서 생성하게 될 경우 호출되는 생성자 public ControllerView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } // 리소스 XML 에서 생성하게 될 경우 호출되는 생성자, Default Style 파라메타 추가 public ControllerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub }

Custom View 의 기본 구조 : 크기설정 4 int heightSize = 0; int widthSize = protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub int heightMode = MeasureSpec.getMode(heightMeasureSpec); switch(heightMode) { case MeasureSpec.UNSPECIFIED: // mode 가 셋팅되지 않은 크기가 넘어올때 or Fixed Size heightSize = heightMeasureSpec; break; case MeasureSpec.AT_MOST: // wrap_content ( 뷰 내부의 크기에 따라 크기가 달라짐 ) heightSize = 300; break; case MeasureSpec.EXACTLY: // fill_parent, match_parent ( 외부에서 이미 크기가 지정 ) heightSize = MeasureSpec.getSize(heightMeasureSpec); break; } int widthMode = MeasureSpec.getMode(widthMeasureSpec); switch(widthMode) { case MeasureSpec.UNSPECIFIED: // mode 가 셋팅되지 않은 크기가 넘어올때 widthSize = widthMeasureSpec; break; case MeasureSpec.AT_MOST widthSize = 300; break; case MeasureSpec.EXACTLY: widthSize = MeasureSpec.getSize(widthMeasureSpec); break; } setMeasuredDimension(widthSize, heightSize); }

Custom View 의 기본 구조 : 터치 public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()) { case MotionEvent.ACTION_UP: invalidate(); break; case MotionEvent.ACTION_DOWN: invalidate(); break; case MotionEvent.ACTION_MOVE: invalidate(); break; } return true; }

onDraw 6 PointF pTouchPoint ; PointF pOldTouchPoint protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub final Paint pCenter = new Paint(); pCenter.setColor(Color.YELLOW); canvas.drawColor(Color.BLACK); canvas.drawLine(0, heightSize/2, widthSize, heightSize/2, pCenter); canvas.drawLine(widthSize/2, 0, widthSize/2, heightSize, pCenter); if(pTouchPoint.x > 0 && pTouchPoint.y > 0) { canvas.drawCircle(pTouchPoint.x, pTouchPoint.y, 200, pCenter); }

좌표 처리 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { … pTouchPoint = new PointF(widthSize/2, heightSize/2); pOldTouchPoint = new PointF(widthSize/2, heightSize/2); setMeasuredDimension(widthSize, heightSize); } private final int TOUCH_OFFSET = public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()) { case MotionEvent.ACTION_UP: pOldTouchPoint.x = pTouchPoint.x = widthSize/2; pOldTouchPoint.y = pTouchPoint.y = heightSize/2; invalidate(); break;

좌표 처리 8 case MotionEvent.ACTION_DOWN: pTouchPoint.x = event.getX(); pTouchPoint.y = event.getY(); pOldTouchPoint.x = pTouchPoint.x; pOldTouchPoint.y = pTouchPoint.y; invalidate(); break; case MotionEvent.ACTION_MOVE: pTouchPoint.x = event.getX(); pTouchPoint.y = event.getY(); if(Math.abs(pTouchPoint.x - pOldTouchPoint.x) > TOUCH_OFFSET || Math.abs(pTouchPoint.y - pOldTouchPoint.y) > TOUCH_OFFSET ) { pOldTouchPoint.x = pTouchPoint.x; pOldTouchPoint.y = pTouchPoint.y; } invalidate(); break; } return true; }

좌표 처리 9 case MotionEvent.ACTION_DOWN: pTouchPoint.x = event.getX(); pTouchPoint.y = event.getY(); pOldTouchPoint.x = pTouchPoint.x; pOldTouchPoint.y = pTouchPoint.y; invalidate(); break; case MotionEvent.ACTION_MOVE: pTouchPoint.x = event.getX(); pTouchPoint.y = event.getY(); if(Math.abs(pTouchPoint.x - pOldTouchPoint.x) > TOUCH_OFFSET || Math.abs(pTouchPoint.y - pOldTouchPoint.y) > TOUCH_OFFSET ) { pOldTouchPoint.x = pTouchPoint.x; pOldTouchPoint.y = pTouchPoint.y; } invalidate(); break; } return true; }

onDraw 에 반영 10 PointF pTouchPoint ; PointF pOldTouchPoint protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub final Paint pCenter = new Paint(); pCenter.setColor(Color.YELLOW); canvas.drawColor(Color.BLACK); canvas.drawLine(0, heightSize/2, widthSize, heightSize/2, pCenter); canvas.drawLine(widthSize/2, 0, widthSize/2, heightSize, pCenter); if(pTouchPoint.x > 0 && pTouchPoint.y > 0) { canvas.drawCircle(pTouchPoint.x, pTouchPoint.y, 200, pCenter); }

좌표 데이터 전송 11 public interface ControllerCallBack { public void ChangeControllerPosition(int xOffset, int yOffset); } public class MainActivity extends RobotActivity implements ControllerCallBack{ ControllerView protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); controllerView = (ControllerView)findViewById(R.id.conroller); controllerView.setCallback(this); }

좌표 데이터 전송 12 public class ControllerView extends View { ControllerCallBack callback = null; … public ControllerCallBack getCallback() { return callback; } public void setCallback(ControllerCallBack callback) { this.callback = callback; }

좌표 데이터 전송 public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()) { case MotionEvent.ACTION_UP: … callback.ChangeControllerPosition(0, 0); invalidate(); break; case MotionEvent.ACTION_DOWN: … invalidate(); break; case MotionEvent.ACTION_MOVE: … int xOffset = (int)(widthSize/2 - pTouchPoint.x); int yOffset = (int)(heightSize/2 - pTouchPoint.y); callback.ChangeControllerPosition(xOffset, yOffset); } invalidate(); break; } return true; }

좌표 데이터 처리 public void ChangeControllerPosition(int xOffset, int yOffset) { // TODO Auto-generated method stub Log.d("MainActivity", "ChangeControlerPosition x:" + xOffset + " y:" + yOffset); int rSpeed = 0; int fSpeed = 0; if(Math.abs(xOffset/10) > 10) { rSpeed = (int)(xOffset/10); } // Front Speed if(Math.abs(yOffset/10) > 10) { fSpeed = (int)(yOffset/10); } leftWheel.write(fSpeed + rSpeed); rightWheel.write(fSpeed - rSpeed); }

테스트 15