update app inventor in your phone · fusion table app • ^this app lets people enter food orders...

57

Upload: others

Post on 31-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 2: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Update App Inventor in your phone

• Go to android play store in your phone:

• Update “MIT App Inventor 2”

Page 3: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• Agenda

– Learn how to manipulate lists

– Learn how conditional statements work

• (“if”, “else”, “for each”)

– Learn how to create and use a function

– Working with Google API (i.e. sharing data)

– Troubleshoot issues

Page 4: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Create a List

• App Inventor uses “lists” to store data.• Lists can be used to store your mock/example data

• Lists can be used to compare data (i.e. “I have a list of addresses but the data does not include postal code. I want my app to automatically add the postal code for certain addresses”)

• Example of how to create & manipulate lists:

– http://www.imagnity.com/tutorials/app-inventor/list-blocks-on-app-inventor/

Page 5: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Modifying MapIt Tutorial

• Orginal MapIt does not have a pre-populated list of addresses

• “We want to create a pre-populated pick list”. How can we do this?

Page 6: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• What do we want to do?

– Let us enable the “select location” button when the app is first opened

– Create a pre-populated list of addresses

– Add postal code for known addresses

Page 7: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Original MapIt Code(initialize)

Page 8: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 9: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Modified Code

Create a New List

Enable Button

Pre-populate List

Uppercase/Lowercase

Page 10: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Modified Code

Create a New List

Enable Button

Pre-populate List

Uppercase/Lowercase

Page 11: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Modified Code

Create a New List

Enable Button

Pre-populate List

Uppercase/Lowercase

Page 12: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Modified Code

Create a New List

Enable Button

Pre-populate List

Uppercase/Lowercase

Page 13: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 14: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 15: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Code for appending postal code

We know the postal codes for 3255 and 1000 Riverside Dive. We don’t know the postal code for any other address.

Sample Data:

List1 (Original List)Index Data

1 – 3255 RIVERSIDE DRIVE, OTTAWA2 – 1000 RIVERSIDE DRIVE, OTTAWA3 – 3333 riverside drive, ottawa4 – 55 riverside drive, ottawa

List1(After running appendPostalAddressCheck):Index Data

1 – 3255 RIVERSIDE DRIVE, OTTAWA, K2D 8R92 – 1000 RIVERSIDE DRIVE, OTTAWA, L2K 2K23 – 3333 riverside drive, ottawa, Postal Unknown4 – 55 riverside drive, ottawa, Postal Unknown

Page 16: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Updated to Append Postal Code

Created New Function(this “Call” can be doneanywhere in code)

Convert Text to Uppercase

Convert Text to Lowercase

Page 17: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”

Replace old text in list with appended postal code

Function Name

Page 18: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”

Replace old text in list with appended postal code

Function Name

Page 19: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”

Replace old text in list with appended postal code

Function Name

Page 20: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), then append “unknown”

Replace old text in list with appended postal code

Function Name

elementInList1=“foo bar 1”

IF “foo” is in elementInList1 THENmake elementInList1 = elementInList1 join “, K2D 8R9”(elementInList1=“foo bar 1, K2D 8R9”)

Page 21: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”Replace old text in list with

appended postal codeInc Counter

Function Name

Page 22: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”

Replace old text in list with appended postal code

Function Name

Page 23: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Initialize Counter

“for each” will walk through each element one by one

Compare Text

If Found, update with postal code

If not found(“else”), the append “unknown”

Replace old text in list with appended postal code

Inc Counter

Function Name

Page 24: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 25: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

RIVERSIDE is not the same as Riverside or riverside

Page 26: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• How can we reuse the appendPostalAddressCheckcode when the user enters a new address?

Page 27: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• What is missing?

– Check if the postal code has already been appended. If it has been, then don’t append a postal code

Page 28: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Using Google API

• MIT App Inventor may not have all the features/components you are looking for

• An API (application programming interface) is a set of third party routines, procedures, that MIT App Inventor can access/call to provide you with additional features/functions that you may need

• You might get lucky if an API exists for the feature you are looking for. Some APIs can be difficult to use

• TIP: Search in Google or Youtube for the following terms:“App Inventor Google API <calendar, fusion, ext..>”

Page 29: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

MIT App Inventor Components

Third Party API

Your Application

API Access

Google APIFusion Table

TABLE_IDTABLE_URLAPI_KEY

Page 30: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Using Google API

• Creating A Calendar:– https://groups.google.com/forum/#!topic/app-inventor-

developers-library/x4GBw8wVI0I

• Working with Google Fusion(tables)– http://appinventor.mit.edu/explore/ai2/pizzaparty.html

• Other Interesting Links(might not use Google API)– code snippets - https://puravidaapps.com/snippets.php– Stock Quote Example -

http://beta.appinventor.mit.edu/learn/tutorials/stockquotes/stockquotes.html

– GPS/Coordinates: http://puravidaapps.com/coordinates.php, https://groups.google.com/forum/#!topic/ai4a/6BjEKN70j9U

Page 31: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Fusion Table App

• “This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access place for the data. By reading from the table, the app can easily display the orders that have been entered.”

• “A Fusion Table is a Google service to support the gathering, managing, sharing, and visualizing of data.”

http://appinventor.mit.edu/explore/ai2/pizzaparty.html

Page 32: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Working With Fusion Tables

• http://appinventor.mit.edu/explore/ai2/pizzaparty.html

Page 33: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• https://www.google.com/drive/

Page 34: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 35: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 36: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 37: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 38: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• Edit > Change Columns.

• You'll rename the four default columns to Date(type=Date), Name (type=Text), Pizza (type=Text), Drink(type=Text).

• Click save and then add a fifth column by going to the Edit > Add Column. Name this fifth column Comment(type=Text).

Page 39: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 40: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 41: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• “In order to use the FusiontablesControl Component you need to acquire a Google Applications Programming Interface (API) key, an API Key. To get an API key, follow these instructions:”

– https://code.google.com/apis/console/

Page 42: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 43: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 44: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 45: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 46: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 47: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• API_KEY: AIzaSyD0i8nHcMe_jKxTUg

Page 48: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Go Back To Fusion Table Page

Page 49: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 50: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• After “save”. Then click on blue “done” button

Page 51: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 52: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

• TABLE_URL: https://www.google.com/fusiontables/embedviz?viz=GVIZ&t=TABLE&q=select+col0%2C+col1%2C+col2%2C+col3%2C+col4+from+1BZQ3LfP6jFwn

Page 53: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

TABLE_ID: 1BZQ3LfP6jFwn3PxuQAv3Ol5bGA4

Page 54: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access
Page 55: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Add a single space

This constructs a “SQL” statement: you can learn more about SQL at

http://www.w3schools.com/sql/

INSERT INTO 1BZQ3LfP6jFwn3PxuQAv3Ol5bGA4tN31xxxxxxxx (Date, Name, Pizza, Drink, Comment) VALUES ('Mar 1, 2015 12:11:39 PM', ‘MyName', ‘Cheese', ‘Coke', ‘This is a comment')

Page 56: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access

Other Resources for Help

• https://groups.google.com/forum/#!searchin/mitappinventortest/

• Post questions in the forum. Be detailed. Take screen captures of your code blocks. Mention you are new to programming.

Page 57: Update App Inventor in your phone · Fusion Table App • ^This App lets people enter food orders for a pizza party. Orders are stored in a Fusion Table, providing one easy to access