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.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
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.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
More Java: Encapsulation, Getters, Setters, Anonymous Class 1 CS300.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android: Hello World Frank Xu Gannon University. Steps Configuration ▫Android SDK ▫Android Development Tools (ADT)  Eclipse plug-in ▫Android SDK and.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Android Application Development 2013 PClassic Chris Murphy 1.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
1 Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources, Listener 10/9/2012 Y. Richard Yang.
Better reference the original webpage :
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Introducing the Sudoku Example
Basic Drawing Techniques
2D Graphics: Part 2.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Intro to Android Development Ben Lafreniere. Getting up and running Don’t use the VM! ials/hello-world.html.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Eclipse Tutorial Barrett Summer Scholars 2011 Sustainable Engineering: Learning to Engineer Truly Green Products.
Presented By: Muhammad Tariq Software Engineer Android Training course.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Mobile Computing Lecture#12 Graphics & Animation.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
Lab7 – Appendix.
Introduction to android
Android Programming - Features
Android Application 2D Graphics cs.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Application Development 1 6 May 2018
Android N Amanquah.
Adapting to Display Orientation
GUI Programming Fundamentals
CS499 – Mobile Application Development
Android Introduction Hello World.
Mobile Computing With Android ACST Intro to Android, Part 2
2D Graphics: Part 2.
Development-Introduction
ITEC535 – Mobile Programming
תכנות ב android אליהו חלסצ'י.
Mobile Device Development
CIS 470 Mobile App Development
Graphics with Canvas.
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
Android Sensor Programming
Presentation transcript:

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 be available tomorrow 3-4pm

Projects I will you with your group & project assignment tomorrow if I haven’t done so already Please fill out the When2Meets for arranging meetings Kickoff (“release planning”) meetings start next week

Schedule Previously: Basics of building software Software development processes Configuration Management Continuous Integration Requirements Today: Intro to Android Tuesday: More Android programming

What is Android?

An open source Linux-based operating system intended for mobile computing platforms Includes a Java API for developing applications It is not a device or product

“Hello, Android”

Creating Your First(?) Android App 1. Set up your development environment 2. Create a new Android project in Eclipse 3. Run it in the emulator 4. Hilarity ensues

1. Set Up Your Android Environment Install Eclipse Install Android SDK (Android libraries) Install ADT plugin (Android development tools) Create AVD (Android virtual device) Moore 207 and Moore 100B machines should have the environment already set up

2. Create an Android Project in Eclipse File → New → Project Select “Android Project” Fill in Project details...

Name that appears on device Directory name Class to automatically create Java package Android version

3. Run the Android Application Run → Run (or click the “Run” button) Select “Android Application” The emulator may take a few minutes (or sometimes longer!) to start, so be patient! You don't need to restart the emulator when you have a new version of your application

Source code Auto-generated code UI layout String constants Configuration

1 public class HelloAndroid extends Activity { 2 /** Called when the activity is first created. */ 4 public void onCreate(Bundle savedInstanceState) 5 { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.main); 8 } 9 } HelloAndroid.java

1 2 <LinearLayout 3 xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 <TextView 9 android:layout_width="fill_parent" 10 android:layout_height="wrap_content" 11 " 12 /> 13 main.xml

1 2 3 Hello World, HelloAndroid! 4 5 Hello, Android 6 strings.xml

1 2 <manifest 3 xmlns:android=" 4 package="edu.upenn.cis350" 5 android:versionCode="1" 6 android:versionName="1.0"> 7 <application 8 9 <activity android:name=".HelloAndroid" <action 13 android:name="android.intent.action.MAIN" /> 14 <category 15 android:name="android.intent.category.LAUNCHER"/> AndroidManifest.xml

Review: Android Components Application: consists of one or more Activities Activity: A “screen” in an Android app Java class that contains UI code Has a ContentView that consists of Layouts and Views Layout: specifies how Views are arranged; may be declared in xml file AndroidManifest.xml: main configuration file

Android User Interfaces

Basic 2D Graphics in Android

Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic Many of them require a lot of knowledge of the underlying graphics libraries We will look at the very simplest form of 2D graphics

Drawing on a Canvas Visible elements in an Android UI are called Views Each View has an associated Canvas When the View is shown, its onDraw method is automatically called by Android It uses the Canvas to render the different things it wants to display You can create your own View with your own onDraw method to display basic objects using the Canvas

1 public class MyShapeView extends View { 2 3 // You must implement these constructors!! 4 public MyShapeView(Context c) { 5 super(c); 6 init(); // more on this in a second! 7 } 8 public MyShapeView(Context c, AttributeSet a) { 9 super(c, a); 10 init(); 11 }... to be continued! Create a custom View class

Shapes and ShapeDrawables Android has built-in Shape classes to represent 2D shapes, e.g. RectShape, OvalShape, etc. From a Shape, you can create a ShapeDrawable object, which has methods for drawing itself A ShapeDrawable has a Paint object that is the “paintbrush”: color, transparency, stroke, etc. ShapeDrawables have a “bounding area” using an x-y coordinate system with (0,0) in top left corner

Still in the MyShapeView class protected ShapeDrawable square; 13 protected ShapeDrawable circle; protected void init() { // blue 60x60 square at 80, square = new ShapeDrawable(new RectShape()); 19 // set the color 20 square.getPaint().setColor(Color.BLUE); 21 // position it 22 square.setBounds(80, 120, 80+60, ); // greenish circle at 230, circle = new ShapeDrawable(new OvalShape()); 26 // set the color using opacity + RGB 27 circle.getPaint().setColor(0xff74AC23); 28 // give it a white shadow 29 // arguments are blur radius, x-offset, y-offset 30 circle.getPaint().setShadowLayer(10, 15, 15, Color.WHITE); 31 // position it 32 circle.setBounds(230, 220, , ); } // end of init method

Still in the MyShapeView class // this is automatically called by Android 36 // EVERY time this View is rendered 37 protected void onDraw(Canvas canvas) { // draw the square 40 square.draw(canvas); // draw the circle 43 circle.draw(canvas); } // end of onDraw method

Placing the View in the Activity If you want the entire Activity to be filled with your custom View, pass an instance to setContentView In your Activity class: 1 public void onCreate(Bundle savedInstanceState) { 2 3 // always do this first! 4 super.onCreate(savedInstanceState); 5 6 // set the View in the Activity (not using XML here) 7 setContentView(new MyShapeView(this)); 8 9 } // end of onCreate method

Placing the View in the Activity Alternatively, you can put it in the XML file 1 2 <LinearLayout 3 xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 <TextView 9 android:layout_width="fill_parent" 10 android:layout_height="wrap_content" 11 " 12 /> <edu.upenn.cis542.MyShapeView 15 android:layout_width="fill_parent" 16 android:layout_height="wrap_content" 17 /> 18

rectangle oval shadow layer MyShapeView 1. Create a View class 2. Create ShapeDrawables 3. Override onDraw 4. Add View to Activity

Drawing Lines In the onDraw method, you can create a Paint object and draw right on the Canvas The Canvas has a drawLine method that you can use to draw a line segment between two points In your View's onDraw method: 1 // create a Paint object 2 Paint p = new Paint(); 3 // set its color 4 p.setColor(Color.RED); 5 // set the stroke width 6 p.setStrokeWidth(10); 7 8 // draw a line from (40, 20) to (60, 50) 9 canvas.drawLine(40, 20, 60, 50, p);

Drawing Text The Canvas also has a drawText method that will make text appear on the screen In your View's onDraw method: 1 // create a Paint object 2 Paint p = new Paint(); 3 // set its color 4 p.setColor(Color.WHITE); 5 // set the alignment 6 p.setTextAlign(Paint.Align.LEFT); 7 // set the typeface (font) 8 p.setTypeface(Typeface.SANS_SERIF); 9 // set the size 10 p.setTextSize(20); // draw the text at (180, 120) 13 canvas.drawText(“Hello”, 180, 120, p);

Handling User Interaction When the user interacts with the View, Android invokes its onTouchEvent method Android passes a MotionEvent object, which includes: – the type of Action (down, up/release, move) – the location (x-y coordinate) – the time at which it occurred To force the View to redraw, call invalidate( )

This is the revised MyShapeView class... 1 protected ShapeDrawable square; 2 protected int squareColor = Color.BLUE; 3 4 protected void init() { 5 square = new ShapeDrawable(new RectShape()); 6 square.setBounds(80, 120, 80+60, ); 7 } 8 9 protected void onDraw(Canvas canvas) { 10 square.getPaint().setColor(squareColor); // use variable 11 square.draw(canvas); 12 } public boolean onTouchEvent(MotionEvent e) { 15 if (e.getAction() == MotionEvent.ACTION_DOWN) { 16 int x = (int)e.getX(); int y = (int)e.getY(); 17 if (x > 80 && x 120 && y < 180) { 18 squareColor = Color.RED; 19 invalidate(); // force redraw 20 return true; 21 } 22 } 23 return false; 24 }

Review: Android Graphics View: base class to extend for UI component onDraw: method that is called when View is displayed in the UI Paint: object that is used to draw basic elements on the screen onTouchEvent: callback method that is invoked when user interacts with View