Professional Documents
Culture Documents
Final Project: Whatsappinventormit For App Inventor
Final Project: Whatsappinventormit For App Inventor
FINAL PROJECT
WHATSAPPINVENTORMIT FOR APP INVENTOR
CONTENT
Overview .............................................................................................................................................. 2
Links ................................................................................................................................................... 22
References ......................................................................................................................................... 23
Summary ............................................................................................................................................ 23
Customizations ................................................................................................................ 23
OVERVIEW
In this tutorial, we are going to study how to use the experimental Firebase component. We are going to
develop an app that allows users to chat with each other using persistent data.
WHAT IS FIREBASE?
Firebase provides a way to use data stored online. The data can be used for different apps that share
them in real-time. In addition, the service provides application developers with an API that allows
application data to be synchronized across clients and stored on Firebase's cloud. It is an amazing new
component in App Inventor!
This tutorial assumes that you are familiar with the basics of App Inventor, including using the
Component Designer to build a user interface, and the Blocks Editor to specify the app's behavior. If you
are not familiar with the basics, try going through some of the basic tutorials before continuing.
LEARNING OBJECTIVES
STEP-BY-STEP INSTRUCTIONS
We can develop an app with several screens using App Inventor. In this sense, WhatsAppInventorMIT
will be able to manage three different screens in order to do the following tasks:
All the screens will use the information stored in the same Firebase database. This tutorial presents
Firebase as a way to work with real-time cloud data service.
You start building a multiscreen app by creating a new project, just as with any other app. As usual, App
Inventor automatically creates the main screen and names it Screen1 and you can add components.
Here is the Designer and the Components panel when all the components for Screen1 have been added:
The main objective of Screen1 is to display all the buttons needed to access different screens of the app.
We can choose to:
AlignVertical: Center
AppName:
WhatsAppInventorMIT
Background color:
None
Icon: iconoapp.png
Title:""
TitleVisible: False
ShowStatusBar: False
Image:
background.png
Text:""
Text:""
To add a new screen to your app, click the Add Screen button in the top toolbar of the Designer window.
A dialog window will appear, in which you provide a name for the new screen. Our app needs three new
screens: scrCreateUsers, scrViewUsers and scrChat. To create a new one you can use the Add Screen ...
button:
This screen allows users to create two new nicknames or usernames in the database. We will be able to
chat using these usernames, so it is very important to create them at the start.
To save data on the Internet, we need to click on a button that connects our app with the Firebase
service. To return to Screen1, we click on another button that closes the screen. We use a notifier
component for displaying messages on the screen.
AlignVertical: Center
BackgroundColor:
None
Background Image:
background.png
Scrollable: False
Title:""
TitleVisible: False
ShowStatusBar: False
Background color:
None
Fontsize: 18
Text: "Create
users..."
Fontsize: 18
Text: ""
Fontsize: 18
Text: ""
Background color:
None
Image:btnSave.png
Image:btnBack.png
10
This screen displays the current users saved on the Firebase database. It is assumed that this screen will
be opened to check the usernames previously created.
It is similar in appearance to scrCreateUsers but the textboxes are disabled and there is only one button
to return to the main screen.
11
AlignVertical: Center
BackgroundColor:
None
Background Image:
background.png
Scrollable: False
Title:""
TitleVisible: False
ShowStatusBar: False
Background color:
None
Text: "Current
users..."
12
Fontsize: 18
Text:""
Fontsize: 18
Text:""
13
Background color:
None
Image:btnBack.png
14
The most important screen is scrChat, which allows us to choose a user, send and receive messages in
real-time using the Firebase component and view them on the screen.
We can test our app using the same device and changing the user or we can use the app in different
devices. To keep the app working correctly, it is very important to use the same developer account
and the project bucket related to the Firebase component.
15
AlignVertical: Center
BackgroundColor:
None
Background Image:
background.png
Scrollable: False
Title:""
TitleVisible: False
ShowStatusBar: False
Background color:
None
Image:
btnChooseUser.png
Text: ""
16
Fontsize: 18
Text: "Message:"
Text: ""
17
BackgroundColor:
None
Image: none
Text: "U1-->U2"
TextColor: Orange
Text: "U2-->U1"
TextColor: Yellow
Background color:
None
Image:btnBack.png
18
Clock
Notifier
These blocks essentially manage the click events and open new windows.
Because other apps may use the Firebase component, you should add a call to procedure
Unauthenticate in order to clear the internal Firebase cache.
19
Firebase uses a tag-value pair to save/read data on the cloud, so our app will use the usernames as tags.
When a user clicks on the save button, the app ensures that both fields are filled to avoid having saved
data without a tag.
If an error should occur, the FirebaseError event would be triggered and our app would notify us.
Note that we use a notifier component to show certain messages according to the events described.
20
This screen gets the values previously saved in scrCreateUsers. The Initialize event is used for calling the
GetValue procedure of the Firebase component and the GotValue event fills the textboxes.
The first thing this screen needs is the usernames that will be used to store data related to them. The
initialize event gets these values reading tags "User1" and "User2". Next, using GetValue, the app reads
messages previously sent between the users. It uses the "real usernames" previously read as tags. When
the screen opens, it uses a clock sensor with a timer to prevent reading from an empty tag.
Our app is able to send messages between two different users; however, it is also possible to simulate
two users by using the choose button. To choose the username sending the message, click on the
button and select it from the list.
When a user writes a message and clicks on the Send button, the app will test which index of the
previous list has been selected. The procedure StoreValue relates to each user with its message and the
DataChanged event is the procedure that deals with the updated data.
Our app implements a procedure called checkTagValueAndWriteText to check which tag is being
changed in our database in a specific moment. The main mission of the procedure is to receive and deal
with data from the Internet. Depending on the tag, the procedure will set a pair of global variables that
it will use later or it will show the messages on the screen.
21
LINKS
WhatsAppInventorMIT in Gallery:
http://ai2.appinventor.mit.edu/?galleryId=6176442605371392
https://drive.google.com/folderview?id=0B0k5c5YtPa8ETUs2NzExVmtDWGc&usp=sharing
22
REFERENCES
SUMMARY
DISCUSSION QUESTIONS
CUSTOMIZATIONS
1. Let users delete all messages sent between them. Hint: use a new button component to store
blank data in the convenient tag.
2. Add a new functionality to the app that allows users to send date and time to their messages
and develop the needed changes to show this new information on the screen.
23