CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
HTTP and Threads. Download some code I’ve created an Android Project which gives examples of everything covered in this lecture. Download code here.here.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
UI Design Patterns & Best Practices Mike Wolfson July 22, 2010.
CS378 - Mobile Computing Web - WebView and Web Services.
CS378 - Mobile Computing App Project Overview. App Project Teams of 2 or 3 students Develop an Android application of your choosing subject to instructor.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Welcome to CIS 083 ! Events CIS 068.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
CS378 - Mobile Computing Web - WebView and Web Services.
Visual Basic .NET BASICS
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
Concurrent Programming and Threads Threads Blocking a User Interface.
Android networking 1. Network programming with Android If your Android is connected to a WIFI, you can connect to servers using the usual Java API, like.
ALAA M. ALSALEHI SOFTWARE ENGINEER AT IUG Multithreading in 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.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Project Information Abstract Project Objectives The objective of this project is to: Create a visual designer that will allow inexperienced end- users.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Developing Android Services. Objectives Creating a service that runs in background Performing long-running tasks in a separate thread Performing repeated.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Android Application 2D Graphics cs.
Asynchronous Task (AsyncTask) in Android
Instructor: Mazhar Hussain
Event loops 16-Jun-18.
Click the mouse button or press the Space Bar to display the answers.
CS240: Advanced Programming Concepts
Development-Introduction
Lecture 28 Concurrent, Responsive GUIs
Understand Windows Forms Applications and Console-based Applications
Android Programming Lecture 8
Event loops.
CS371m - Mobile Computing Responsiveness.
Android Topics UI Thread and Limited processing resources
Android Topics Asynchronous Callsbacks
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Android Topics Threads and the MessageQueue
Android Developer Fundamentals V2
Events, Event Handlers, and Threads
Event loops 8-Apr-19.
Threads, Handlers, and AsyncTasks
Using threads for long running tasks.
Event loops.
Mobile Computing Dr. Mohsin Ali Memon.
Event loops.
Event loops 19-Aug-19.
Android Threads Dimitar Ivanov Mobile Applications with Android
Presentation transcript:

CS378 - Mobile Computing Responsiveness

An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the equation have the following property: Given an input between -1 and 1 the output is also between -1 and 1 sin and cos scaled to pi / 2, multiply, add, average, remainder (except for 0)

Random Art The color at any given point is based on the x and y coordinates of that point scaled to between -1 and 1 Feed the x and y coordinates into the equation Pick equations at random, keep the good pictures, throws away the boring ones

Random Art Color of this pixel? Assume large frame is 400 by 300. Assume this pixel is at 100, 20 x = 100 / 400 = > scaled to -1 to 1 = -0.5 y = 30 / 300 = 0.1 -> scaled to -1 to 1 = -0.2 Plug these values into random equation: Assume equation is yxASCSySSxCyCACMMSCSSCC postfix, A = Average, S = Sin, C = Cos, M = Multiply Assume answer is Scale to number of colors. Assume 256 shades of gray. Color at that pixel is 224 th shade of gray (224, 224, 224) X+X+ Y+Y+ 0, 0

Result yxASCSySSxCyCACMMSCSSCC

Result xxACSSxCAyCyxASASCAyCCAyyyAAxMS xCxCAxSySMMCMCSMSCS

Result yCCSxxMSSAS

Results

RandomArt Application Create a subclass of View that does the computation and draws the graphics More on 2d graphics later in term – but we simply override the onDraw(Canvas) method and draw want we want – colors via Paint objects – Canvas.drawPoint(x, y, Paint) method add click listener to the View so click results in new expression and a redraw – invalidate() -> leads to onDraw(Canvas)

The Problem Neat idea but computationally expensive 480 by 800 screen on Galaxy Nexus 384,00 pixels depending on the expressions, tens of millions of computations, plus the rendering

Responsiveness user's threshold of pain? 1 second? 2? – Android dev documents claim 100 to 200 milliseconds (0.1 to 0.2 seconds) The Android Systems has its own threshold of pain – if the systems determines an application has become unresponsive it displays the Application Not Responding dialog ANR occurs if app not responsive to user input

Android System The Activity Manager and Window Manager system services monitor applications for responsiveness ANR dialog displayed if: – No response to an input event such as a key press or screen touch in 5 seconds – A BroadcastRecevier doesn't finish executing in 10 seconds

Typical Blocking Operations complex calculations or rendering looking at data set of unknown size parsing a data set processing multimedia files accessing network resources accessing location based services access a content provider accessing a local database accessing a file

The UI Thread For application that consist of Activity (or Activities) it is vital to not block the UI thread (main thread of execution) AND on API level 11 and later certain operations must be moved off the main UI thread – code that accesses resources over a network – for example, HTTPrequests on the main UI thread result in a NetworkOnMainThreadException – discover StrictMode

Enabling Responsiveness move time consuming operations to child threads – Android AsyncTask – Java Thread – Service? provide progress bar for worker threads big setups -> use a splash screen or render main view as quickly as possible and filling in information asynchronously assume the network is SLOW don't access the Android UI toolkit from outside the UI thread

Asking for Trouble Loading image from network may be slow and block the main (UI) thread of the application

AsyncTask Android class to handle simple threading for operations that take a few seconds Removes some of the complexities of Java Thread class and Android Handler class Result published to the UI thread

AsyncTask Three Generic Parameters – data type of Parameter to task – data type of Progress – data type of Result four steps in carrying out task – onPreExecute() – doInBackground(Param… params) – onProgressUpdate(Progress values) – onPostExecute(Result result)

Methods onPreExecute() runs on UI thread before background processing begins doInBackground(Param… params) runs on a background thread and won't block UI thread publishProgress(Progress… values) method invoked by doInBackground and results in call to onProgressUpdate() method on UI thread onPostExecute(Result result) runs on UI thread once doInBackground is done

Downloading with AsyncTask

Random Art with AsyncTask Add progress bar and button for new art create a Bitmap and draw to that

Just One More

Loaders Loader classes introduced in API 11 Help asynchronously load data from content provider or network for Activity or Fragment monitor data source and deliver new results when content changes multiple classes to work with