Plan for today Open-Closed and Quizmaster

Slides:



Advertisements
Similar presentations
Using Evernote and Google Docs in your web or mobile application (and potentially Dropbox and Skydrive) By Peter Messenger Senior Developer – Triple Point.
Advertisements

Prepared by: Prepared by: Jameela Rabaya Jameela Rabaya Fatima Darawsha Fatima Darawsha.
Location based social networking on Android phones – integrated with Facebook. Simple and easy to use.
Getting a Web Page (And what to do once you’ve got it)
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
DSpace XML UI Project Texas A&M University Digital Initiatives, Research and Technology Scott Phillips, Cody Green, Alexey Maslov, Adam Mikeal, Brian Surratt,
Presented by…. Group 2 1. Programming language 2Introduction.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
JavaScript & jQuery the missing manual Chapter 11
CS378 - Mobile Computing Web - WebView and Web Services.
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
CS378 - Mobile Computing Web - WebView and Web Services.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Cross Site Integration “mashups” cross site scripting.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
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.
Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,
Server - Client Communication Getting data from server.
API Crash Course CWU Startup Club. OUTLINE What is an API? Why are API’s useful? What is HTTP? JSON? XML? What is a RESTful API? How do we consume an.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Scheduled Silence Application Midterm Presentation David Koritsanszky and Frederick Evans.
Unit 13 –JQuery Basics Instructor: Brent Presley.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
Copyright Office Material Copyright Request System.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Introduction to Android Programming
Intro To Android Programming
A little more App Inventor and Mind the GAP!
Mobile Device Development
Compsci 290.3, Spring 2017 Software Design and Implementation: Mobile Landon Cox Owen Astrachan See.
12/29/2017 2:33 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
XML-RPC Web Services in WinCC OA An Application: online PARA JCOP FWWG Meeting Lorenzo Masetti.
How to think about interaction
Android Application Web 1.
Conventions … learning
Physics validation database
Business Directory REST API
Asynchronous Task (AsyncTask) in Android
The Client-Server Model
Data Virtualization Demoette… Custom Java Procedures
Node.js Express Web Applications
Introduction to Redux Header Eric W. Greene Microsoft Virtual Academy
Outline SOAP and Web Services in relation to Distributed Objects
MAD.
Development Changes in Dynamics 365 for Finance and Operations
Visual Studio Tools for Office 2005
Development-Introduction
Plan for today Refactoring and Design Patterns
Outline SOAP and Web Services in relation to Distributed Objects
Automated Automation of REST APIs
Android SDK & App Development
WEB API.
Zlatko Stamatov JavaSkop 13 December 2015
CSE 154 Lecture 22: AJAX.
Geo 318 – Introduction to GIS Programming
CS323 Android Topics Network Basics for an Android App
Google Plus Hangouts Skills: Start a Hangout on Air, invite participants, conduct Hangout Concepts: none We will begin with some examples of Google Hangouts.
MIS JavaScript and API Workshop (Part 3)
Introduction to AJAX and JSON
Engineering Secure Software
Mobile Programming Dr. Mohsin Ali Memon.
Introduction to AJAX and JSON
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Consuming Web Services with 2E Generated Objects
THE ANDROID TEXTBOOK APP
Blazor A new framework for browser-based .NET apps Ryan Nowak
Presentation transcript:

Plan for today Open-Closed and Quizmaster Review of open-closed principle Hopes, dreams, aspirations, reality What is refactoring for? Design first, code second? Repeat until done Third-party APIs v Stock Android How to navigate the online space of options

Quizmaster Review and Preview Where are quizzes found? Hard-wired/coded in QuizGenerator.java Stored in XML files as part of assets, read and parsed by custom XMLxyz.java classes What's missing here? Web-based quizzes How could these alternatives co-exist? Design for complete/some flexibility, then implement Get quiz from web, then increase flexibility

Toward Internet/Web connections Services and permissions on Android must be dealt with intentionally To open a connection to Internet? Must supply app permission Permission levels for Android Applications Android 6.0 change in model Runtime permission vs. Install permission https://developer.android.com/training/articles/user-data-permissions.html We'll see more on best practices later

Adding Permissions for Applications Use AndroidManifest.xml for permissions Open Internet socket/connection --- aside: what is a socket? Also access network state (not needed here) <uses-permission android:name= "android.permission.INTERNET" /> <uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE" />

How to access Internet? Step one: Google, StackOverflow, Android book Open HTTPConnection, similar to how this is done in Java See code in JSONQuizGenerator.java and method getJSONRaw() Examine code in gitlab: https://gitlab.oit.duke.edu/ola/quizmaster/blob/master/app/src/main/java/edu/duke/compsci290/quizmaster/JSONQuizGenerator.java

Concepts in this version of code Create URL (see constructor), what is a URL? Store URL as instance variable for use in method to make connection Alternative from Java/design perspective? What to do with Exceptions? In general, throwing exceptions to top level is a good idea What is alternative? What about application specific exceptions?

Concepts in HttpURLConnection Create the connection Options required or available: type of connection, duration of "try and try again" Get response code for connection, verify Open stream for connection Read stream for connection Notice stream reading code Decorator design pattern (more later). Create readers from streams and readers from readers Dissect code in .readStream()

How to test the connection? Deploy to phone, offer user choice of creating quiz from online/Internet Get ready to debug Android.os.NetworkOnMainThreadException Say what? E/InputEventReceiver: Exception dispatching input event. 02-13 22:46:45.566 20555-20555/edu.duke.compsci290.quizmaster E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 02-13 22:46:45.568 20555-20555/edu.duke.compsci290.quizmaster E/MessageQueue-JNI: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303) at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86) at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)

Is Google/Search your friend? https://developer.android.com/reference/android/os/AsyncTask.html AsyncTask enables proper and easy use of the UI thread. This class allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. Who will be happy with this approach?

Third Party APIs You will often see these on StackOverflow How do you know which are "good"? Good judgment comes from experience, experience comes from bad judgment Good design comes from experience, experience comes from bad design Side note: attributing quotes is problematic In our case if it's referenced in Android documentation …

Let's use the Volley library/APIs Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster.  https://developer.android.com/training/volley/index.html How to add GitHub or other library to project? Differences: Android Studio and other Java projects – managing dependencies Maven, Gradle, others Trust or investigate fully or …

Let's use the Volley library/API Choose the right Build.gradle file compile 'com.android.volley:volley:1.0.0' Magic happens (ok, that's relative)

What does Volley get us? Handle network requests simply and appropriately on the right non-UI thread Call back to main UI thread you manage See code in new getJSON() method StringRequest request = new StringRequest(Request.Method.GET,mURLString, new Response.Listener<String>(){ // override method here }, new Response.ErrorListener(){ // override method here });

What is JSON and why not XML? Given that we have XMLQuizParser what might be appropriate for testing Internet? Copy XML file to Internet, get it, parse it, … Why use JSON instead? JavaScript Object Notation What does Google say it is? Why is it popular on the web? Why is it used in Android applications?

JSON Example http://www.cs.duke.edu/csed/quizzes/oscars.json What is format for JSON file? This example is NOT created to play nicely with our Quiz and Question classes However, Compare JSONParser class to XMLQuizParser class Better alternative: Gson library Parse directly to Java class/object: reflection