All posts by edwardm

MIT App Inventor Source Code

This is for advanced software developers only: MIT App Inventor Sources. That’s the actual source code that makes App Inventor work behind the scenes – from the browser based editor to the server side support to the AI Companion. It’s all there.

MIT has made the source code for App Inventor publicly available. At a minimum, you need to be proficient in Java, Javascript, and have familiarity with various web techniques, such as JSON. Exploring this source code is not for the neophyte.

With access to the source code it is possible to host App Inventor on your own server and it is possible to develop your own App Inventor components (this also requires making a custom version of AI Companion).

Again, this is for advanced software developers.

How to create a bouncing ball animation in App Inventor 2

App Inventor 2 provides easy to use features for creating games. These features have proven popular for introducing programming concepts to students in K-12, especially at the elementary and middle school level. While our focus is oriented towards practical applications rather than games, we can have a little fun too!

The purpose of the sample app in this blog post is to illustrate the basic programming concepts of a bouncing ball animation.

The “Game”

Well, its not much of a game! To keep the programming simple, all this does is enable a ball to bounce around on the screen, to change its heading or trajectory, and to make it travel faster or slower. When the ball hits the edge of the screen, it rebounds in an appropriate direction. Here’s the user interface as seen on the smart phone:

Screenshot_2014-10-13-11-40-46

Press the Start button to make the ball start moving; press Stop to end the movement.

To change the speed of movement press the Faster or Slower buttons. Pretty easy?

To change the trajectory, you may enter a heading value in degrees, in the field next to the Set heading button, and then press the Set heading button.

Continue reading How to create a bouncing ball animation in App Inventor 2

Using ListPicker for displaying and selecting from on screen lists

What is ListPicker?

ListPicker is a user interface component that makes it easy to display a list of items and have the user make a selection from the list. For example, let’s say we’d like to display six things on the screen and then have the user select an item from the list.

For simplicity, here is a sample ListPicker list showing six items labeled “A”, “B”, “C”, “D”, “E” and “F”.  Those items are arbitrary – your list could contain “Oranges”, “Bananas”, “Apples”, “Grapes” or whatever other text descriptions you would like to have. (The default color is white text on black but the color properties, as well as the text size, may be changed in the App Inventor Designer.)

Screenshot_2014-10-10-12-03-13

 

When this screen is displayed the user may touch an item in the list to select it.

Use ListPicker whenever you have a set of items from which the user is expected to make a selection. Example applications could include selecting a product from a list of inventory items, select a food item from a menu, select a name from a display of names and addresses and many more.

Learning how to use ListPicker is helpful for new App Inventor programmers as many online tutorials and example programs use ListPicker – but without explaining what it is or how to use it!  Becoming familiar with ListPicker will make those other tutorials easier to understand!

Example

When an item is selected an event is created, and your event handler can then identify which item was selected in this list.  To illustrate, let’s start with a simple app that displays a list of items when the “Click me to display a short list” is pressed:

Screenshot_2014-10-10-12-03-24

ListPicker does all the hard work for us – display the items on screen (as shown in the previous screen snap shot) and processing the selected element.

In the example above, “C” was selected.

How to Build the ListPicker Demonstration Application

Step 1 is to drag a ListPicker component from the Palette to the Viewer. Rename the control if you wish and change the text of the ListPicker control button to something useful 🙂 Here is the app after dragging the ListPicker component and changing the text (in the ListPicker properties) to “Click me to display a short list”:

LP-Designer

Step 2 is to place some items into the list. We do that by typing a comma separated list in the ElementsFromString property of ListPicker, as shown here:

LP-Properties

 

We have now added six items – A, B, C, D, E and F. We could enter longer text descriptions if we wished – for example “Oranges, Bananas,Apples” and so on:

LP-Properties2

Step 3 is to add an event handler for the list to process the list selection – this turns out to be really super hard – not! It is actually super easy! Click on the ListPicker component in the Blocks Editor and then drag the .AfterPicking event into your program:

LP-EventBlockListPicker handles all the details of the on screen selection. All that is needed is to fetch the item that was selected, store that in a variable, or, as in this example, display the selection in a label field on the app’s screen.

That’s it for the basic operation of the ListPicker. If you have many elements – too many to fit on one screen – the list automatically handles scrolling. Just use your finger to drag up or down the list. You can also change ListPicker properties such as the color of the list and more.

Of course there are many ListPicker features, but this is intended as a brief introduction.

But one feature we wish to mention is that you can add items to the list to display from within your program by putting your items in a list and assigning them as shown here:

LP-BlocksAddingThe ListPicker1.Elements property contains a programmatic list of items.  If you are not familiar with lists, please see Chapter 8 “Introduction to Lists” in my e-book “Guide to App Inventor 2:Tutorial – The fast and easy way to create Android apps”.

Using the WebViewer Control in App Inventor

Would it be neat if you could display pages from the web in your Android app? Well, you can!

And it is very easy to do in App Inventor.

In the Designer, drop a WebViewer control on to your app’s screen design area. The WebViewer control is located at the bottom of the user interface section of the Palette:

WebViewerControl

After dropping the control on to your user interface, select the control and set the Properties. In particular, set a default or initial web URL to display on the screen. Here, I have set the default URL to http://appinventor.pevest.com. Be sure to include the leading http://

WebViewerProperties

 

When your app runs, the WebViewer will automatically load the page at the HomeURL.

You can change this page, programmatically. Here, for example, in response to a button press, the URL is changed to my 3D blog.

WebChangeURL

Once this runs, the new page is read in to the viewer. Just like this!

Screenshot_2014-09-08-16-39-22