Giter VIP home page Giter VIP logo

csci490-lab_04's Introduction

Lab04

  1. In Android Studio, create a basic Android project called CSCI490-Lab_04
  2. Add .idea/ to the .gitignore file
  3. Share the project to GitHub

Creating a Webview

  1. Create a branch called webview
    • git checkout -b webview
  2. In MainActivity.java add the following lines of code inside the onCreate() method:
WebView webview = new WebView(this);
setContentView(webview);
  1. Load any URL of your choice (that's appropriate) by calling webview.loadURL("yourURL.com")

  2. Run on your Android device or emulator. Challenge: How would you go to your Webview from MainActivity, i.e. Launch from a button click?

  3. Commit and push into Github

    • git add .
    • git commit -m "webview lab"
    • git push origin webview

Creating a URL Connection and retrieving content

  1. Once your webview branch is pushed up to Github, checkout branch master

    • git checkout master
  2. Create a branch called urlconnection

    • git checkout -b urlconnection
  3. In MainActivity.java create a method that passes in a String and returns a String

    • The parameter will (eventually) be the URL https://jsonplaceholder.typicode.com/users
    • The resulting String will be a JSON list of users
    • Inside the method, create a URL with the input string
    • Open a URLConnection with the call openConnection()
    • Create an InputStreamReader and channel through a BufferedReader as discussed in class
    • The output of the BufferedReader.readLine() will be a String. Put that in a variable
    • Print the String with Log.i() and check the contents
    • Compare that with typing the URL into a web browser Challenge: Use past JsonUtils and edit create a JSONObject
  4. Commit and push into Github

    • git add .
    • git commit -m "url connection lab"
    • git push origin urlconnection

AsyncTask

  1. Once your urlconnection branch is pushed to Github create a branch called asyncTask
    • git checkout -b asyncTask
  2. Create a new class that extends AsyncTask<String, Void, String> and @Override the doInBackground() and onPostExecute()
  3. Create a TextView element on your UI and pass that in the constructor to your AsyncTask class
  4. In MainActivity.java create an instance of your AsyncTask class
  5. Move your URL code from last lab to the doInBackground() task
  6. In the onPostExecute() set your TextView to a subString of the json that is returned. The subString should be from 10-23
  7. Commit and push into Gitub
    • git add .
    • git commit -m "async task"
    • git push origin async

csci490-lab_04's People

Contributors

kabriggs991 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.