CS499 – Mobile Application Development

Slides:



Advertisements
Similar presentations
Graphics.  2D Graphics using  ImageView  Canvas  ViewAnimation.
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.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
2D Graphics: Part 1. Android Graphics Libraries 2D Graphics –custom 2D graphics library in packages android.graphics android.graphics.drawable android.graphics.drawable.shapes.
Graphics in Android 1 Fall 2012 CS2302: Programming Principles.
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Basic Drawing Techniques
2D Graphics: Part 2.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Android Tutorial Team 3 Jerry Yu Mayank Mandava Mu Du Will Wangles.
Flag Quiz App 1 CS7030: Mobile App Development. assets Folder 2 CS7030: Mobile App Development  drawable folder – Image contents at the root level 
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Animation.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Animations 1 Fall 2012 CS2302: Programming Principles.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
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 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.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
Android and s Ken Nguyen Clayton state University 2012.
Graphics in Android 1 CS7030: Mobile App Development.
Mobile Computing Lecture#12 Graphics & Animation.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
Android View Stuff. TextViews Display text Display images???
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
CHAPTER 5 Graphics Drawing Audio. Chapter objectives: Learn to draw to a canvas Examine the process of adding drawn elements and UI controls to a layout.
Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Feb 2, 2016.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
Graphics & Animation Radan Ganchev Astea Solutions.
2D Graphics: Part 1.
Android Application 2D Graphics cs.
Lecture 3: Animation & Graphics
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
GUI Programming Fundamentals
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
Android Introduction Hello World.
2D Graphics: Part 2.
S.RENUKADEVI/AP/SCD/ANDROID - Notifications
Android Introduction Hello Views Part 1.
תכנות ב android אליהו חלסצ'י.
Mobile Computing With Android ACST 4550 Android Animation
CIS 470 Mobile App Development
Android Programming Lecture 6
CIS 470 Mobile App Development
Graphics in Android Fall 2012 CS2302: Programming Principles.
Graphics with Canvas.
滑動 建國科技大學 資管系 饒瑞佶 2013/4 V1 2015/5 V2.
滑動 建國科技大學 資管系 饒瑞佶.
Lecture 3: Animation & Graphics
CIS 470 Mobile App Development
Lecture 8: Graphics By: Eliav Menachi.
Adding Components to Activity
CIS 470 Mobile App Development
User Interface Development
Android Sensor Programming
User Interface Development
Presentation transcript:

CS499 – Mobile Application Development Fall 2013 Animation & Graphics

2D Graphics With a View With a Canvas Simple graphic, no updating Java and/or XML With a Canvas More complex graphics with regular updating

Drawable Represents something that can be drawn, such as a bitmap, color, shape, etc. BitmapDrawable ColorDrawable ShapeDrawable – primitive shapes such as circles, oval, rectangles, … TransitionDrawable – 2-layer graphics – fades between layer 1 and 2

Drawing in Android - Java public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SimpleView(this)); } private static class SimpleView extends View{ private ShapeDrawable mDrawable = new ShapeDrawable(); public SimpleView(Context context) { super(context); setFocusable(true); this.mDrawable = new ShapeDrawable(new RectShape()); this.mDrawable.getPaint().setColor(0xFFFF0000); @Override protected void onDraw(Canvas canvas) { int x = 10; int y = 10; int width = 300; int height = 50; this.mDrawable.setBounds(x,y,x + width, y + height); this.mDrawable.draw(canvas); y += height + 5; Drawing in Android - Java OvalShape(), PathShape(), RoundRectShape,Shape, …

Drawing in Android - XML /res/drawable/simplerectangle.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FF0000FF" /> </shape> /res/layout/xmldrawable.xml <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_height="wrap_content" > <ImageView android:layout_width="fill_parent" android:layout_height="50dip" android:src="@drawable/simplerectangle" /> </LinearLayout> </ScrollView> Drawing in Android - XML

ARGB color values ARGB – Alpha, Red, Green, Blue – common method for defining color values Each color (RGB) defined as a percentage level from 0 to 255 Alpha specifies a level of transparency

TransitionDrawable /res/drawable/shape_transition.xml <?xml version="1.0" encoding="utf-8"?> <transition xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/cyan_shape" android:right="50px"/> android:drawable="@drawable/magenta_shape" android:left="50px"/> </transition>   /res/layout/main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main_window" android:gravity="center"> </RelativeLayout>

TransitionDrawable public class AnimationTransitionActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); RelativeLayout rl = (RelativeLayout) findViewById(R.id.main_window); ImageView iv = new ImageView(this); Resources res = getResources(); TransitionDrawable trans = (TransitionDrawable) res .getDrawable(R.drawable.shape_transition); iv.setImageDrawable(trans); rl.addView(iv); trans.setCrossFadeEnabled(true); trans.startTransition(5000); }

Animation Class Animates the contents of a View Animation – a series of timed changes to View properties such as size, position, etc. Manipulate times to give effect of sequential or simultaneous changes

Animation Class /res/anim/icon_animation.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="3000" android:interpolator="@android:anim/linear_interpolator" /> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" android:startOffset="3000" android:interpolator="@android:anim/accelerate_interpolator" /> <translate android:fromXDelta="0" android:toXDelta="50" android:fromYDelta="0" android:toYDelta="50" android:startOffset="6000" android:interpolator="@android:anim/overshoot_interpolator" android:duration="2000" /> <scale android:fromXScale="1" android:toXScale="2" android:fromYScale="1" android:toYScale="2" android:duration="2000" android:pivotX="50%" android:pivotY="50%" android:startOffset="8000" android:interpolator="@android:anim/anticipate_overshoot_interpolator" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" android:startOffset="10000" android:interpolator="@android:anim/decelerate_interpolator" /> </set>

Animation Class public class AnimationTweenActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView iv = (ImageView) findViewById(R.id.icon); Animation anim = AnimationUtils.loadAnimation(this,R.anim.icon_animation); iv.startAnimation(anim); } /res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/frame"> <ImageView android:id="@+id/icon" android:visibility="invisible" android:src="@drawable/b128" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

Canvas Helper class for drawing Bitmaps Bitmap represents a matrix of Pixels Drawing operations additionally require Something to draw (e.g. Rect, Path, Text, Bitmap A paint object (for setting drawing colors & styles) Multiple drawing styles drawText(), drawPoints(), drawColor(), drawOval(), drawBitmap()

Using a Canvas will cause a onDraw() public class BounceAnimationActivity extends Activity { protected static final int GUIUPDATEIDENTIFIER = 0x101; // unique identifier Thread myRefreshThread = null; BounceView myBounceView = null; Handler myGUIUpdateHandler = new Handler () { public void handleMessage(Message msg) { switch (msg.what) { case BounceAnimationActivity.GUIUPDATEIDENTIFIER: myBounceView.invalidate(); break; } super.handleMessage(msg); }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.myBounceView = new BounceView(this); this.setContentView(this.myBounceView); new Thread(new RefreshRunner()).start(); … Thread class here will cause a onDraw()

More Advanced Animation class RefreshRunner implements Runnable { public void run() { while (!Thread.currentThread().isInterrupted()) { Message message = new Message(); message.what = BounceAnimationActivity.GUIUPDATEIDENTIFIER; BounceAnimationActivity.this.myGUIUpdateHandler.sendMessage(message); try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }

public class BounceView extends View { protected Drawable mySprite; protected Point mySpritePos = new Point(0,0); protected enum HorizontalDirection{LEFT, RIGHT}; protected enum VerticalDirection {UP, DOWN} ; protected HorizontalDirection myXDirection = HorizontalDirection.RIGHT; protected VerticalDirection myYDirection = VerticalDirection.UP; public BounceView(Context context) { super(context); this.mySprite = this.getResources().getDrawable(R.drawable.b64); } @Override protected void onDraw(Canvas canvas) { this.mySprite.setBounds(this.mySpritePos.x, this.mySpritePos.y,this.mySpritePos.x+50, this.mySpritePos.y+50); if (mySpritePos.x >= this.getWidth() - mySprite.getBounds().width()) this.myXDirection = HorizontalDirection.LEFT; else if (mySpritePos.x <= 0) this.myXDirection = HorizontalDirection.RIGHT; if (mySpritePos.y >= this.getHeight() - mySprite.getBounds().height()) this.myYDirection = VerticalDirection.UP; else if (mySpritePos.y <= 0) this.myYDirection = VerticalDirection.DOWN; if (this.myXDirection == HorizontalDirection.RIGHT) this.mySpritePos.x += 10; else this.mySpritePos.x -= 10; if (this.myYDirection == VerticalDirection.DOWN) this.mySpritePos.y += 10; else this.mySpritePos.y -= 10; this.mySprite.draw(canvas); BounceView