CS260 Intro to Java & Android 09.AndroidAdvUI (Part I)

Similar documents
Mobile Application (Design and) Development

ANDROID (4) 2D Graphics and Animation, Handling Screen Rotation. Marek Piasecki

INTRODUCTION TO ANDROID

CS260 Intro to Java & Android 05.Android UI(Part I)

CS260 Intro to Java & Android 05.Android UI(Part I)

Mobile App Design Project Doodle App. Description:

Custom Views in Android Tutorial

Exercise 1: First Android App

Orientation & Localization

A Crash Course to Android Mobile Platform

Programming of Mobile Services, Spring 2012

Mastering Android Drawables

Chapter 6: Inheritance

Assistant Professor Computer Science. Introduction to Human-Computer Interaction

TWO-DIMENSIONAL FIGURES

Lab 1 - Setting up the User s Profile UI

package import import import import import import import public class extends public void super new this class extends public super public void new

O X X X O O X O X. Tic-Tac-Toe. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 2: The Ultimate Tic-Tac-Toe Game

Graphics and Painting

This lecture. The BrowserIntent Example (cont d)

Our First Android Application

Introduction to Android Development

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CISC 1600 Lecture 3.1 Introduction to Processing

Chapter 2 Welcome App

Lab 3. Accessing GSM Functions on an Android Smartphone

Chapter 7 Applets. Answers

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL II)

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Spring Lecture 7 Lecturer: Omid Jafarinezhad

Appendix F: Java Graphics

Game Programming with. presented by Nathan Baur

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android. Emmanuel Agu

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

Java Programming Lecture 6

Computer Games 2014 Selected Game Engines

ACS-1805 Introduction to Programming (with App Inventor)

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

COMP4521 EMBEDDED SYSTEMS SOFTWARE

SQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite

CS371m - Mobile Computing. 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries

CS378 -Mobile Computing. User Interface Basics

Appendix F: Java Graphics

Android Apps Development for Mobile Game Lesson Create a simple paint brush that allows user to draw something (Page 11 13)

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

CS 4330/5390: Mobile Application Development Exam 1

Reviewing OO Concepts

Android Application Development 101. Jason Chen Google I/O 2008

Assignment 2. Application Development

Mobile Computing LECTURE # 2

Android/Java Lightning Tutorial JULY 30, 2018

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Graphics. Lecture 16

CS 160: Lecture 10. Professor John Canny Spring 2004 Feb 25 2/25/2004 1

SEVEN ADVANCED ACADEMY

Mobile Systeme Grundlagen und Anwendungen standortbezogener Dienste. Location Based Services in the Context of Web 2.0

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Expressions, Statements, and Control Structures

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

AplusBug dude = new AplusBug(); A+ Computer Science -

Android HelloWorld - Example. Tushar B. Kute,

Mobile User Interfaces

COMP-202: Foundations of Programming. Lecture 26: Image Manipulation; Wrap-Up Jackie Cheung, Winter 2015

Programming Fundamentals

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Lifecycle Callbacks and Intents

CSE 331 Software Design & Implementation

Introduction to Computer Science I

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

Classes. Integer Division. Thursday, October 23, March 13, 2008

OPTIMIZING ANDROID UI PRO TIPS FOR CREATING SMOOTH AND RESPONSIVE APPS

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

Embedded Systems Programming - PA8001

Android Application Development

Testing Android Games on a Real Device

The Suggest Example layout (cont ed)

EECS 1001 and EECS 1030M, lab 01 conflict

Project Report Group 4

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

CS Programming Exercise:

Polymorphism: Interfaces and Iteration. Fundamentals of Computer Science

Garfield AP CS. Graphics

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

ListView (link) An ordered collection of selectable choices. key attributes in XML:

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Activity Logging Lecture 16

Android AND-401. Android Application Development. Download Full Version :

BCA 6. Question Bank

App Development for Smart Devices. Lec #18: Advanced Topics

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSE115 Lab 4 Fall 2016

Transcription:

CS260 Intro to Java & Android 09.AndroidAdvUI (Part I) Winter 2015 Winter 2015 CS260 - Intro to Java & Android 1

Creating TicTacToe for Android We are going to begin to use everything we ve learned thus far to produce the shell of an Android TicTacToe game Winter 2015 CS260 - Intro to Java & Android 2

TicTacToe for Android Step #1 Create Initial App Create TicTacToeAndroid using the default settings for an Android project Delete the Hello World textview widget Copy over the UI from your Game Skeleton application which should look like the following screen Winter 2015 CS260 - Intro to Java & Android 3

TicTacToe for Android Step #1 Create Initial App Winter 2015 CS260 - Intro to Java & Android 4

TicTacToe for Android Step #2 Add an Array Resource Create a string array in strings.xml where the string-array name is gamedifficulty and the items are: Easy Medium Hard Winter 2015 CS260 - Intro to Java & Android 5

TicTacToe for Android Step #3 Create Ask Difficulty Dialog Winter 2015 CS260 - Intro to Java & Android 6

Start the game In the private method startgame that accepts the difficulty level, use the Log.d method to display the difficulty level in the logcat window based on the difficulty level the user selected. Hook up the New Game button so that when the button is pressed: the Game Difficulty dialogue appears allowing the user to enter Easy (0), Medium (1), or Hard (2) after the user enters their selection, the difficulty value shows up in the logcat window Winter 2015 CS260 - Intro to Java & Android 7

Graphics We will explore still graphics and then graphic animation Android provides libraries to perform 2D and 3D graphics android.graphics provides low-level graphics drawing tools such as canvases color filters points rectangles Winter 2015 CS260 - Intro to Java & Android 8

Android colors Represented with four 8-bit numbers (ARGB) alpha - measures transparency where 0 is completely transparent and 255 is completely opaque red green blue int color = Color.BLACK; int color = Color.argb (127, 0, 255, 255); Winter 2015 CS260 - Intro to Java & Android 9

Accessing Color Information It is best to define your colors in an xml file <?xml version="1.0" encoding="utf-8"?> <resources> <color name="steelblue">#4682b4</color> <color name="navy">#000080</color> </resources> Note: Four values is ARGB while three values is RGB where A is fully opaque Colors can be accessed by int color = getresources ().getcolor (R.color.navy); Winter 2015 CS260 - Intro to Java & Android 10

Paint The Paint class holds information about style and color how to draw geometries, text, and bitmaps Before drawing a color, it is common to set the color with the method setcolor (Color.BLUE); which is part of the Paint class Winter 2015 CS260 - Intro to Java & Android 11

Canvas The canvas is a surface to draw on Android framework APIs provide 2D drawing APIs to: a) render your own graphics on a canvas - need to call ondraw () method passing a Canvas b) modify (customizing) existing Views - draw graphics or animations into an existing View a) is best for simple graphics with no animation b) is best for video games with complex animation and frequent redraws Winter 2015 CS260 - Intro to Java & Android 12

Basic Display An Activity provides the UI for the display screen An Activity hosts a View A View hosts a Canvas The ondraw () method can be overridden to perform custom drawing on the Canvas Winter 2015 CS260 - Intro to Java & Android 13

Custom View public class CustomDrawableView extends View { private ShapeDrawable mdrawable; public CustomDrawableView (Context context) { super (context); int x = 10, y = 10, width = 300, height = 50; } mdrawable = new ShapeDrawable (new OvalShape()); mdrawable.getpaint ().setcolor (0xff74AC23); mdrawable.setbounds (x, y, x + width, y + height); protected void ondraw (Canvas canvas) { } mdrawable.draw (canvas); } // http://developer.android.com/guide/topics/graphics/2d-graphics.html Winter 2015 CS260 - Intro to Java & Android 14

Drawing Custom View CustomDrawableView mcustomdrawableview; protected void oncreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); mcustomdrawableview = new CustomDrawableView (this); setcontentview (mcustomdrawableview); } // http://developer.android.com/guide/topics/graphics/2d-graphics.html Winter 2015 CS260 - Intro to Java & Android 15

TicTacToe for Android Step #4 Let s draw a simple graphic in our Android game before getting into more complicated graphics. Create a new class called CustomDrawableView in your tictactoeandroid package. Place the previous CustomDrawableView code in this class. For now, comment out displaying the TicTacToe main activity and simply write the code necessary to display a new CustomDrawableView instead. You should end up with the UI on the following slide. If you get this, check your updated TicTacToe into subversion. Winter 2015 CS260 - Intro to Java & Android 16

TicTacToe for Android Step #4 Winter 2015 CS260 - Intro to Java & Android 17

CustomView Modifications You can do any kind of drawing in the ondraw of a custom view. The following slides allow you to draw the lines of a TicTacToe board See if you can get this to work Winter 2015 CS260 - Intro to Java & Android 18

Add Instance Variables private Paint mbackground = new Paint (); private Paint mdarklines = new Paint (); private float mnumber_of_rectangles = 3f; private int mrectangleheight, mrectanglewidth; Winter 2015 CS260 - Intro to Java & Android 19

Add ondraw Logic mbackground.setcolor (getresources ().getcolor (R.color.teal)); canvas.drawrect (0, 0, getwidth (), getheight (), mbackground); // Compute mrectangleheight and mrectanglewidth here mdarklines.setcolor (Color.BLACK); for (int i = 0; i < (int) mnumber_of_rectangles; i++) { canvas.drawline (0, i * mrectangleheight, getwidth(), i * mrectangleheight, mdarklines); canvas.drawline (i * mrectanglewidth, 0, i * mrectanglewidth, getheight(), mdarklines); } Winter 2015 CS260 - Intro to Java & Android 20

Result Winter 2015 CS260 - Intro to Java & Android 21