Multimedia Programming and Mobile Devices (Teaching Material)
Multimedia Programming and Mobile Devices (Teaching Material)
online
Module 8
Multimedia programming
and mobile devices
on updatePhotoDescipiomO\
(desctptionsNength >
(page • document
.getlemenWByiK
elemented
= fc
elementld
Module 8: Multimedia programming and mobile devices
Page 88
Module 8: Multimedia programming and mobile devices
Page 88
Module 8: Multimedia programming and mobile devices
This first topic will analyze the different technologies used in applications for mobile
devices, their limitations, integrated work environments, modules for developing
them, emulators, configurations, profiles, their life cycle and modifications of
existing applications.
When developing a mobile application, there are some requirements that need to
be taken into account. Each platform poses a series of requirements that are
necessary when running an application correctly.
Page 88
Module 8: Multimedia programming and mobile devices
Page 88
Module 8: Multimedia programming and mobile devices
Today, there are various Android app development platforms, which provide
developers with all the tools necessary to create applications for mobile devices.
These platforms are called IDE (Integrated Development Environment). Two of the
most notable and frequently used are Eclipse and Android Studio.
The choice of IDE is a subjective matter, which in most cases is determined by the
application developer himself.
• Eclipse:
- It is a very powerful platform with a lot of debugging tools.
- It is part of a Java distribution, whose language is the basis of Android.
- It has a large number of plugins (ADT Plugin) with the Android application
development tools.
- Full integration with the SDK manager from the IDE with everything
needed to install all versions of Android.
$ eclipse
• Android Studio:
- It is the platform recommended by most developers.
- It is purely Android, since it is created to develop applications in this
language.
- Allows for easier plugin installation and integration than Eclipse.
- Compiling and exporting .apk files is easier.
Page 88
Module 8: Multimedia programming and mobile devices
Once the advantages and disadvantages of each have been assessed, the IDE used for
application development will be Android Studio. This offers greater guarantees for the
future in the development of mobile applications.
Android is an established language that has been in continuous development over the
last few years. It has spread throughout the world, being the most used operating
system on mobile devices. Prior to this growth, during the development of the first
versions, the language began to be documented, thus facilitating the creation of
applications for developers.
Before you start developing, you need to install the appropriate IDE. In this case,
Android Studio requires some previous features before starting its installation:
Once installed, the next step is to install Android Studio. During installation it will be
necessary to include a fundamental module for development. This is the SDK
Page 88
Module 8: Multimedia programming and mobile devices
Manager, which will allow you to download all the packages needed to compile
applications within the IDE. Another module that will need to be installed is the Java
Virtual Machine (JVM). This will be able to interpret the compiled Java language. In
addition, it will be responsible for executing all the instructions to be emulated.
1.4. Emulators
1.5. Settings
- Battery: Enabling this feature allows you to see how the phone behaves when
the battery is low, or when warning windows are displayed.
- GPS: activate or deactivate GPS using specific coordinates.
- Camera: Use the front or rear camera on your device.
- System Files: Access the device's file system.
- Remote control: control the emulator's behavior from another physical device.
- Identifiers: You can view and modify the Android and device identifier.
- Network: Control whether the device's data network is enabled or remains
offline.
- Calls: Emulate the behavior of the device when making a phone call or writing a
Page 88
Module 8: Multimedia programming and mobile devices
text message.
• Supported devices:
These emulators allow you to simulate different devices, such as: Google 4, Google
Nexus 5, Google Nexus 7, Samsung Galaxy S3, etc. They give you the possibility of
emulating a fully customized device, configuring the number of processors, memory
size, screen resolution, Internet connection, navigation bar interface and Android
version.
In the case of Genymotion, its installation and configuration is very simple; just
follow the steps provided in its documentation. Its versatility allows it to be
integrated with the main development IDEs such as Android Studio and Eclipse
through the plugin that exists for each of them.
1.6. Profiles
Characteristics
Emulators have pre-defined hardware profiles. This way, if a device that has already
been created matches the characteristics of the device you want to emulate, it would
not be necessary to customize a new profile. These profiles cannot be modified, as
they are included within the AVD.
Page 88
Module 8: Multimedia programming and mobile devices
It should be noted that any type of memory chosen for our emulator will be taken
from the physical machine, that is, from our own computer.
Architecture and requirements
In order to be able to use these already defined profiles, it is important to take into
account some requirements. These are already defined in the Android
documentation. The fundamental requirement is that the equipment allows, due to its
hardware characteristics, device emulation and virtualization. For more details,
please consult the documentation provided by Android on its official website.
You can visit the official Android website at the following link:
www.android.com
Supported devices
All types of devices are supported and have a profile within the Android AVD. It is
possible to use, as already indicated, tablets, Android Wear, mobile phones or
Android TV.
The activities are divided into two parts: the logical layer and the graphical part. The
logical layer is responsible for establishing the operation of the application, and is
located in the project's .java files. The graphical layer is made up of the xml files that
Page 88
Module 8: Multimedia programming and mobile devices
form the different layouts of the application. It is responsible for specifying the
elements that make up the different activities.
Therefore, each activity in an application needs to have a java file and an xml file. The
java file will be responsible for calling the xml file to load its content into the
application.
Activities have three states: resumed, paused and stopped, which will change
depending on the events that are launched.
Page 88
Module 8: Multimedia programming and mobile devices
As can be seen in the image, there are a series of events or occurrences that take
place to make state changes in the activity.
Page 88
Module 8: Multimedia programming and mobile devices
• onCreate: is the event produced when the application is created. Its function is
establish the corresponding layout of the activity and its important resources.
• onRestart: is the event that is triggered when an activity is stopped, before
being restarted.
• onStart: is the event that occurs before displaying the activity.
• onResume: is the event executed before the user interacts with the activity.
• The onCreate event reserves resources, while the onDestroy event releases
them.
• With the onStart event the activity is visible, while with the onStop event it
loses its visibility.
• With the onResume event the activity gains focus, while with the onPause
event it loses focus.
When you create a new project, the Android Studio IDE offers the ability to create a
starter activity for the project. But how do you create a new activity? Here are the
steps to follow:
Step 1
An activity is created within the project. As you can see, it will inherit from the
Activity class with its corresponding java file and xml. If it is created as an activity, it
will come related. If not, you need to specify the corresponding layout in the onCreate
event.
CODE:
super, encrest(savedInstanceState) ;
setContentView (R . layout. activity main);
Step 2
The activity is declared in the AndroidManifest.xml.
CODE:
application
Page13 88
Module 8: Multimedia programming and mobile devices
android :allowBackup="true"
android: icon=" @mipmap/ic Launcher"
android :label="@string/app name"
android: supportsRtl="true"
android: themes "style/ AppTheme" >
activity android :name=" . MainActivity " >
< intent-filter
action android: name=" android. intent. action. MAIN" />
Once the new activity has been created, it can be launched. To do this, you must
create an Intent object.
There are two methods to launch the activity, which depend on whether you are
interested in receiving results or not from the new activity:
• startActivity(intent).
• startActivityForResult(intent, code): This method expects a result
associated with the established code.
Page14 88
Module 8: Multimedia programming and mobile devices
method.
CODE:
In the MainActivity
In the Main2Activity
Page15 88
Module 8: Multimedia programming and mobile devices
In the same way that it is possible to emulate already defined devices, this section
extends it to applications that are already developed. Android allows you to
download and modify a large number of example applications from its official
website. These applications can serve as a guide for the development of a new
application. You can reuse functions that already work correctly in these examples
and add them to the project you are developing.
These types of applications can be found in the samples section of the official
Android developers page.
Page16 88
Module 8: Multimedia programming and mobile devices
Page17 88
Module 8: Multimedia programming and mobile devices
In this second topic, we will cover programming for mobile devices, its main tools
and construction phases, user interfaces, its graphic context, events, animation
techniques, services, databases, and persistence. The thread model will be studied,
as well as the management of wireless communication. The sending and receiving of
text messages and multimedia messaging will also be studied, as well as the handling
of HTTP and HTTPS connections.
Phase 1: Configuration
First of all, it is necessary to install all the required elements, both the programming
elements and the emulation environments, AVD in the case of Android.
The items that need to be installed are: Android SDK, Android Development Tools,
and Android Platforms.
Once these are installed, the ADV device emulator will be installed last.
Phase 2: Development
In this phase, the entire programming part of the application will be developed. This
must include the source code, any files or resources used, and the project's Android
manifest file.
Every application requires a process that ensures that the result obtained is correct
Page18 88
Module 8: Multimedia programming and mobile devices
Phase 4: Publication
It is the last phase of the application building process. At this point the application
executable file is generated.
The minimum and recommended SDK version, languages, graphic resolutions and
resources required must be defined for the correct execution of the application on
all devices. If you have any type of restriction, you have to review the
AndroidManifest.xml file. The package name must also be identified within the
AndroidManifest.xml file.
A digital certificate is then created and the application is signed. This will allow the
application to be installed on the devices. This signature will also allow the author to
be identified and prevent the application from being manipulated. A key associated
with the application will be generated and, finally, the already signed executable will
be obtained.
Once the executable has been obtained, it can be transferred to a physical device or
published on Google Play. In order to publish a publication on Google Play, you must
identify this application and accept the terms that Google requires. For more details,
please visit the official website.
The official Google Play page can be visited at the following link:
https://play.google.com/store
X___________________________________________________________________/
Page19 88
Module 8: Multimedia programming and mobile devices
(-------------------------------------------------------------------------------------------- \
Layouts are non-visible elements whose function is to establish the position
of the graphic components (widgets) of the application.
\/
• FrameLayout: Arranges all elements in the top right corner of the frame, i.e.
overlaps them. The usefulness of this layout is to make different elements
visible in the same activity in the same position.
• LinearLayout: Lays out all elements one after the other. This layout has
a property called Orientation, which can be horizontal or vertical. This indicates
whether the elements will be forming columns, or forming rows, respectively.
• RelativeLayout: Arranges elements anywhere in the layout. To do this, it is
usually placed based on the parent component or other components already
placed.
You can learn about the different properties of this type of Layout in
the following link:
https://developer.android.com/reference/android/widget/RelativeLayout.
LayoutParams.html
Within a layout you can find another layout or widgets, which include all the
elements that inherit from the Widget class. The most popular ones are: Button,
TextView, EditText, ListView, RadioButton, CheckBox and ToggleBar, among others.
Page20 88
Module 8: Multimedia programming and mobile devices
All these elements have a series of properties. First of all, the size properties, both
for width (width) and height (height), are mandatory in all activity components, that
is, both in layouts and widgets. Additionally, they can have different properties for
the margin, padding, text, font, or background, among others. Another of the most
important properties is the identifier, to be able to refer to this component.
Margin is the distance between two components, while padding is the space
between the component and its own content.
You can find out about the different widgets at the following
link:
https://developer.android.com/reference/android/widget/package-summary
.html
Units of measurement
The most common units of measurement that Android uses are match_parent (uses
all the allocated space, as big as its parent is) and wrap_content (fits the content to
its size). To express fixed sizes:
Page21 88
Module 8: Multimedia programming and mobile devices
• px. It corresponds to the current screen resolution. This is the worst measure to
use, since for similar sizes, the resolution can vary, so the appearance will vary
in the same way.
• mm, in. Based on the physical size of the screen expressed in millimeters or
inches.
Menus
(--------------------------------------------
A menu is a component that contains a set of options to
navigate the application more quickly.
\/
There are different ways to create menus in an application: taskbar menus, context
menus, and side drop-down menus.
CODE:
Page22 88
Module 8: Multimedia programming and mobile devices
To interact with this menu, callbacks that respond to these events must be created:
For the side drop-down menus, there is a predefined template, in which the menu
and its interaction with the user are already established. To do this, you need to
modify the menu content to customize the application and set its operation based
on the item you have selected.
Notifications
Page23 88
Module 8: Multimedia programming and mobile devices
has seen it. The programmer only needs to indicate the message he wants to
display and its duration.
• Status bar notifications: Status bar notifications consist of an interface and
the element that will be launched when tapped, typically the main activity of
the app.
Important: These notifications must have an icon, a title and a message defined in
their
interface. Their removal when pressed must be specified by code
, since otherwise they will remain fixed
in the status bar.
In the following code you can see how to create the notification, to which you have
to add the element that will be launched when pressed.
Page24 88
Module 8: Multimedia programming and mobile devices
2.4. Events
Android applications are designed for touch devices, so many of their events are
related to this feature, that is, they are events of the View class.
Listeners are the View class interfaces that are responsible for capturing events, that
is, detecting user interaction and executing the corresponding instructions.
CODE:
} 1);
This is one way to program the event when a button is pressed, but there are other
ways that are just as valid.
The most popular events that are implemented are: onClick, onLongClick,
onFocusChange, onKey, onTouch, and onCreateContextMenu.
Page25 88
Module 8: Multimedia programming and mobile devices
/------------------------------------------------------------------------\
An animation is the change of one of the properties of an object
that allows it to be seen over time with a different appearance.
Yo____________________________________________)
Frame-by-frame animation
It is one of the possibilities of the Drawable class. To create an image transition you
need to create an xml file in the res/drawable folder.
CODE:
Once you have the xml file and the images you want to display in this directory, it is
possible to create different types of items, one for each of the images. These items
will have two attributes:
Page26 88
Module 8: Multimedia programming and mobile devices
Then, in the activity in which you want to show it, you need to create the animation,
indicating the xml file, and start the animation.
Finally, the start() and stop() methods are used to perform the animation
operations.
CODE:
AnimationDrawable animation;
Imageview myView;
Override
protected void onCreate(Bundle savedlnstanceState) { super. onCreate (savedlnstanceState) ;
setContentView(R.layout.activity main) ;
animation, start () ;
}
View animation
With this animation system you can transform some characteristics of some Views.
For example, if you have a TextView, you can move, rotate, grow, or shrink the text.
In the res/anim directory you have to create an xml document, which will contain
Page27 88
Module 8: Multimedia programming and mobile devices
the different animations for the object in the order in which you want to act.
The tags used for this are:<translade> ,<rotate> ,<scale> ,<alpha> . In addition, it is
possible to group several of these labels into groups, so that they are executed
simultaneously, and to do this, the label is used<set> .
Page28 88
Module 8: Multimedia programming and mobile devices
CODE:
<scale
android:duration="2000"
android: fromscale="2.0"
android:fromYScale="2.0"
android: toXScale="1.0"
android: toYScale="1.0" />
<rotate
android:startOffset="2000"
android: duration="2000"
android: fromDegrees="0"
android:toDegrees=”360"
android: pi vo tx=” 50 % "
android: pivotY=" 50% "/>
<translate
android:startOffset="4000"
android:duration=”2000"
android: fromXDelta="0"
android: fromYDe 1 ta = " 0 "
android: toXDelta="50"
android: to YDelta=" 100" />
<alpha
android:startOffset="4000"
android:duration="2000"
android: fromAlpha= " 1"
android:toAlpha="0" />
</set>
Once you have the xml, it is possible to create the animation, with the Animation class
and the created xml.
CODE:
Override
protected void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState);
setcontentview (R. layout. activity main);
Page29 88
Module 8: Multimedia programming and mobile devices
text.startAnimation(animation);
More information about this type of work can be found in the following link.
animation:
https://developer.android.com/guide/topics/graphics/view-animation
We create a raw folder inside the res directory. We will include our audio files there.
We look for the raw folder in the directory<nombre app> \app\src\main\res\raw. In
the example, an mp3 with the sound of a cat has been used.
For this practice, the MediaPlayer class will be used. The code in the java file so that
the sound repeats indefinitely at the time the main activity is created will be:
CODE:
Override
protected void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState);
setContentView(R.layout.activity main) ;
Page30 88
Module 8: Multimedia programming and mobile devices
If you need to stop the audio, you would use the stop() method.
(-------------------------------------------------------------------------------------------- \
A service is a process executed invisibly to the user. There are
two types of services: initiated and linking.
YO)
Service started
A component starts a service using the startService() method. In this way, the service
remains started in the background until its process ends. Even if the component that
launched it ends, this service will continue to run.
Page31 88
Module 8: Multimedia programming and mobile devices
Linked service
Unlike started services, bound services are created to link a component to a service. To
do this, it is necessary to do it using the bindService() method. These types of services
create a client-server interface that allows communication between the components
and the service. Different components can be bound to the same link, but when all
components remove communication with the service, the service ends.
All services must be declared in the AndroidManifest.xml file, using the tag<Service> .
All these types of services cannot communicate directly with the user, since they do
not have a graphical interface. To do this, they must use a communication mechanism,
such as Toasts or Notifications.
Page32 88
Module 8: Multimedia programming and mobile devices
https://developer.android.com/guide/components/services.html?hl=es-419
• Internal databases: using the SQLite API, databases can be created in the
application.
• External databases: using web services, you can create connections to
databases on the Internet (for example, thanks to the platform provided by
Google, FireBase).
• Preferences: Allows you to store user settings in the
application.
• Content providers: These are components that allow data management
with other applications.
• Files: allow you to create files, both in the device memory
such as on an SD card, and use them as resources.
• XML: through different libraries, such as SAX and DOM, they allow data to
be manipulated in an XML.
SQLite Databases
SQLite databases are based on the SQL language, meaning SQL statements are
executed in the Android application.
Page33 88
Module 8: Multimedia programming and mobile devices
To do this, you must use the SQLiteOpenHelper class. Its use is normally based on
creating a class that inherits from this one and implements its two mandatory
methods: onCreate() and onUpgrade(). This class has a default constructor.
CODE:
public DataBase (Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context,
name, factory, version);
CODE:
verride
public void onCreate(SQLiteDat abase sqLite Database) {
String query = "CREATE TABLE users (_id INTEGER PRIMARY KEY AUTOINCREMENT, first name TEXT, last name TEXT, phone INTEGER) sqLiteDatabase.execSQL
(query);
1
@Ovecride
public void onUpgrade { SQLite Database sqLite Dat abase, int i, int il) {
Furthermore, the programmer will be able to implement all the methods needed for
database management.
Page34 88
Module 8: Multimedia programming and mobile devices
In addition, this class has two methods that allow you to open the database connection
in a read or write manner, depending on the type of operation you want to perform.
The methods are respectively getReadableDatabase() and getWritableDatabase().
CODE:
SQLiteDatabase bd = getWritableDatabase () ;
bd.close();
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery ("SELECT name, surname, phone FROM users order BY name", null);
https://developer.android.com/reference/android/database/sqlite/SQLite
Database.html
2.8. Persistence
Preferences
Page35 88
Module 8: Multimedia programming and mobile devices
Page36 88
Module 8: Multimedia programming and mobile devices
The transaction indicates that it should call a class that inherits from
PreferenceFragment() and load it on the current view.
Page37 88
Module 8: Multimedia programming and mobile devices
The fragment class will indicate which xml file should be displayed.
In the case of using a layout: in the Java code of the activity you will only have to load
the corresponding layout. In order for the values indicated in the application to be
stored, it is necessary, as indicated above, to work with the SharedPreferences class.
CODE:
A file is created, in this case called file, and the second parameter corresponds to the
access mode.
There are different modes of access:
• MODE_PRIVATE: Only this application can access the file. Its value is 0.
• MODE_WORLD_READABLE: All applications on the device can
read this file, but it can only be modified by this. Its value is 1. It is not
recommended for use due to security flaws and has been deprecated since
version 17.
Page38 88
Module 8: Multimedia programming and mobile devices
Next, there are the different methods of the Editor class to write to the file, which are:
putString(key, value), putBoolean(key, value) or putInt(key, value), among others.
You can consult all the methods of the class in the following link:
https://developer.android.com/reference/android/content/SharedPreference
s.Editor.html
Finally, the editor must be closed for all changes to take effect.
CODE:
editor, commit ()
Page39 88
Module 8: Multimedia programming and mobile devices
In addition to the getSharedPreferences (String file, int mode) method, you can use
the getPreferences (int mode) function, in which the file is created by default, and you
can only have one in the application.
Files
There are different ways to store files on an Android device. Files can be found in the
device's internal memory, external memory, or resources. Files found in resources are
read-only, so information cannot be stored in them, only read operations can be
performed.
Internal storage
All applications contain a folder to store files when installed on a device. This folder has
the path data/data/packageName/files. This folder is also uninstalled
automatically when you uninstall the app.
The package used for reading and writing files is java.io, which has already been
studied in Programming.
More information about this package can be found at the following link:
https://developer.android.com/reference/java/io/package-summary.html
External storage
Since device memory is limited, Android allows the option of using external storage,
usually an SD card, to store these files.
Page40 88
Module 8: Multimedia programming and mobile devices
Since these storage systems are not fixed, before starting to use them it is necessary to
check that they exist and are ready for use.
CODE:
Also, if the operation is writing, it is necessary to give permissions to the application for
this. As previously done, the WRITE_EXTERNAL_STORAGE permission must be
declared in the AndroidManifest.xml file, with the tag<uses-permission> .
Resource files
The /res folder of the Android project contains the application's resources, which are
read-only. These are the folders that contain the images (res/drawable or res/assets)
or the music (res/raw).
From the project it is possible to load any of these resources to make use of reading
them. Additionally, in the res/raw folder it is also possible to store files with the .txt
extension.
Music and image files usually take up quite a bit of space, and that is a disadvantage if
it is part of the app, as it would be a large app to download. Therefore, SD cards have
the possibility of storing these resources that belong to the application. The path to
these files is /Android/data/PackageName/files.
FILE CONSTANT
Music DIRECTORY_MUSIC
Page41 88
Module 8: Multimedia programming and mobile devices
Download DIRECTORY_DOWNLOADS
Pictures DIRECTORY_PICTURES
DCIM DIRECTORY_DCIM
All these folders also belong to the application, so they will be automatically deleted
when you uninstall it.
Page42 88
Module 8: Multimedia programming and mobile devices
All processes in an application run within the same thread and the choice of process
execution follows a priority order. This order corresponds from lowest to highest
with the following:
• Processes empty.
• Processes in second flat.
• Services.
• Processes visible.
• Processes in the first place flat.
When you start the application, a thread called main will be created. This is the
thread that has been worked with until now.
Page43 88
Module 8: Multimedia programming and mobile devices
(--------------------------------------------------------•
---------------------------------------------------------TO
A thread is a subprocess or thread of execution, that is, it is a set
of tasks that are executed.
• It is the only one capable of interacting with the user and is responsible
for collecting events.
• He is the only one who can modify the graphical interface, since he is the
one who can access its components.
If the main thread is busy with some operation, it will not be able to pick up user
interactions, and thus will give the appearance of a hung application. If this
continues for several seconds, the Operating System will throw a message that the
application is not responding.
The first solution to this problem is the creation of new threads using the
Java Thread class:
https://developer.android.com/reference/java/lang/Thread.html
(--------------------------------------------.
An asynchronous task is the execution of instructions in the background.
These objects inherit from the AsynxTask class.
\)
The AsyncTask class is responsible for executing background tasks, with the
characteristic of allowing these tasks to modify the graphical interface. This is
possible through two mandatory methods:
Page44 88
Module 8: Multimedia programming and mobile devices
Operation
When creating an Asynctask, it is first necessary to prepare the data, although this is
not mandatory. This is done on the main thread, but you need to put the code inside
the asynchronous task's onPreExecute() method. For example, it is common to find
that this method indicates the mechanism by which the user will know the status of
the activity, and it is initialized.
Then, in the doInBackground() method, all those instructions that could stop the
application if they were running in the foreground are executed, such as web
requests.
During the execution of the asynchronous task, the publishProgress() method can be
called, which will execute the code in the onProgressUpdate() method on the main
thread. For example, to update the status of the waiting bar.
Additionally, it is possible to end this thread, to do so, the onCancelled() event must
be implemented using the cancel() method.
Page45 88
Module 8: Multimedia programming and mobile devices
In this model, clients are responsible for making requests to the servers, and they
respond with the necessary information.
Currently, there are various applications that use this model, such as: email, instant
messaging and Internet service. That is, it is used whenever a web page is accessed.
It should be noted that in this model, roles are not exchanged between clients and
servers.
Page46 88
Module 8: Multimedia programming and mobile devices
Since this is a service that requires an Internet connection for communication, you
need to have the Internet permission defined.
Page47 88
Module 8: Multimedia programming and mobile devices
(-------------------------------------------------------------------------------------\
A broadcast receiver is an application component that is responsible for
receiving messages sent by the Operating System and by
other applications.
\______________________________._____________________________________J
To avoid this, it is possible to declare the broadcast receiver for specific times, using
Context.registerReceiver() and Context.unregisterReceiver(), which are usually
found in the onResume() and onPause() methods, respectively.
One of the uses of this concept will be seen in the reception of messages.
Page48 88
Module 8: Multimedia programming and mobile devices
Text messaging can be done in two ways: from another activity or directly.
To send a text message from another activity, you must create a communication
element that indicates the phone number to which this message will be sent. This
intent will also have the message content and type vnd.android- dir/mms-sms. The
message will then be sent as a new activity.
CODE:
Intent send = new Intent (Intent. ACTION^^IEW, Uri.fromParts("sms", number, null)) send.
putExtra("sms_body", "Message content");
send. setType("vnd. android-dir /mms-sms");
startActivity(submit);
It is also possible to send messages directly and for this you need the SMSManager
class. This class has the sendTextMessage method which is the one that will send the
text message.
In this method, the fields that need to be filled out are: destinationAddress, with the
phone number to which you want to send the message, the text you want to send,
and the sending element, which contains the relevant information about the
message.
/------------------------------------------------------ ---------------------------------------------------->
A PendingIntent is a communication with the Operating System that
is not known when it will take place.
Yo__________________________________________________________________J
CODE:
Pendingintent send = Pendingintent, ge tAc ti vity(MainActi vi ty. this, G, new Intent (MainActivity. this, Main2Activity. class), 0);
SmsManager manager = SmsManager.getDefault{);
manager. sendTextMessage(number, null, 'message1', send, null);
It is also interesting that after sending the message, its delivery is confirmed. To do
Page49 88
Module 8: Multimedia programming and mobile devices
this, the SMSManager class allows you to know the status of the message, using the
deleveryIntent field.
CODE:
To send multimedia messages, you only need to change the content and type of
message.
Page50 88
Module 8: Multimedia programming and mobile devices
(---------------------------------------
---------------------------------------TO
The HTTP protocol is a client-server protocol that is responsible for
exchanging information between web browsers and their servers.
1)
The HTTPS protocol is an application layer protocol, based on the HTTP protocol,
that is, it adds security to said protocol. Uses SSL/TLS based encryption. While the
HTTP protocol uses port 80, HTTPS uses 443.
If you want to create an application with Internet access, you must take into account
the necessary permission.
CODE:
Android has two packages that allow the development of this type of applications:
java.net and Android.net.
CODE:
Page51 88
Module 8: Multimedia programming and mobile devices
(------------ ----
-------------h
PHP is a server-side programming language used
for dynamic web content development.
.J
• Create the different files with the .php extension, which are responsible
for communication between the application and the database. These
files contain the various queries to the database.
• Make a web request to the server: http://localhost http://127.0.0.1,
indicating the path to the files.
http://localhost/archivosPHP/mostrarUsuarios.php
Page52 88
Module 8: Multimedia programming and mobile devices
This topic will study the concept of multimedia applications, the architecture used,
multimedia data sources, multimedia object processing and their playback.
Almost all of the apps currently on the Android market are considered multimedia
apps, since they all contain some of these elements.
All of these applications must manage all of the information. The treatment of audio
is not the same as that of an image, since each of these types of information has
classes and methods that allow its functionality.
In this chapter we will study these classes and their most popular methods.
Page53 88
Module 8: Multimedia programming and mobile devices
The Android architecture is divided into different layers, always keeping in mind that
the core is Linux (we can say that Android is a version of Linux). This is the
composition of the Android OS, defined by the following layer diagram:
System Apps
Content Providers
Activity Location Package Notification
Linux Kernel
Drivers
Power Management
• Linux Kernel is the lowest layer. It is responsible for managing all the
compatibility between the hardware, that is, it is where we will have all the
drivers for Wifi, USB, screens... This layer has those small softwares that are
responsible for compatibility.
Page54 88
Module 8: Multimedia programming and mobile devices
• Libraries, They are not at the hardware level like the previous layer, but at
the software level. They are responsible for the compatibility of 2D and 3D
animations, font types, data managers, web browsers…
• ART (Android Routine) is the layer where all the magic of our apps with the
Android OS is handled.
ART → It is the virtual machine, which makes the apps run on the OS
(without this, you would never be able to run your applications). It
makes your apps weigh a little more, but consume new resources.
Google has created a development API for Android applications, in which some of
the products such as Maps, Firebase or PUSH Notifications have been successful in
recent times.
Cloud Platform
Get your apps ready for the latest Everything you need to build and
version of Android. scale your enterprise, securely.
The tools and infrastructure you need The official IDE for building apps on
to build better mobile apps. every type of Android device.
3 Web TensorFlow
Page55 88
Module 8: Multimedia programming and mobile devices
It is important to note that in order to use this information, the user must accept
access to it. Therefore, in the application it is necessary to specify the permission of
the information with which it is going to work, in the AndroidManifest.xml, as
already mentioned above. For example, READ_CALENDAR, READ_CALL_LOG,
READ_CONTACTS or READ_SMS.
In this link you can check all the permissions that can be
set in an application:
https://developer.android.com/reference/android/Manifest.permission.html
Page56 88
Module 8: Multimedia programming and mobile devices
Create a project
By default, your Analytics data will power other features in Firebase and
other Google products. You can control how your Analytics data is shared at
any time from your settings. More information
Add Firebase to
your
Android app
Page57 88
Module 8: Multimedia programming and mobile devices
Now you need to enter the application package name and SHA-1. It is necessary to
take into account whether the application being developed has a testing purpose or
a more professional one (for example, with the intention of uploading it to
GooglePlay), since it must be configured in debug mode for the first option and
without debug mode for the second.
com.example.online.ilernaFirebase
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
Required for Dynamic Links, Invites, and support with a phone number or Google Sign-in in Auth. You can edit the SHA-1s
key in Settings.
This will generate a file with a .json extension that will have to be downloaded and
installed in the project branch → Project/<nombre del proyecto> /app. Once this
file is introduced into the directory, it will be introduced into Gradle Scripts:
dependencies { // ...
compile 'com.google.firebase:firebase-core:15.0.0'
The wizard will show the changes that need to be made to the application. After
doing this, communication between the project and the database will already exist.
Once Firebase is implemented in our project, it will be possible to create nodes in
the database. The following image shows the creation of the first node.
CODE:
Page58 88
Module 8: Multimedia programming and mobile devices
CODE:
Override
public void onCancelled(DatabaseError databaseError) {
}
};
db.addValueEventListener(event);
To send new data to the Firebase server, it is also necessary to send it parsed, that
is, the complete object.
CODE:
Maps
As mentioned above, the Google Console allows you to create a Google Maps API
project. Once created, instead of being assigned to an Android project as in Firebase,
it provides a key that can be pasted into all projects that use the map.
Android Studio offers the possibility to create an activity using a map template,
which will make it easier to create the layout from scratch. Once the map is created,
it is possible to indicate the key obtained in the Google Maps API in the
google_maps_api.xml file located in the res/values folder.
Page59 88
Module 8: Multimedia programming and mobile devices
CODE:
• CameraUpdate
• GoogleMap
• LocationManager
Sensors
Sensors are devices that collect information from the outside environment. All
Android devices contain a series of sensors that allow better use of it.
The classes used for sensor use are found in the android.hardware package and are:
Sensor, SensorEvent, SensorManager and
SensorEventListener.
r----------------------------------------------------
--------------TO
Sensors on Android devices are not always available, so it is
always necessary to check before using them.
IJ
• Accelerometer.
• Gravity.
• Gyroscope.
• Linear accelerator.
• Rotation.
• Proximity sensor.
• Brightness.
• Pressure.
• Temperature.
Page60 88
Module 8: Multimedia programming and mobile devices
• Humidity.
Page61 88
Module 8: Multimedia programming and mobile devices
There are a large number of Android classes that allow you to use different
multimedia resources. These are some of them.
For audio:
For video:
• Camera: Allows you to use the camera for photos and videos.
• FaceDetector: Detect faces from the camera.
Once the classes that allow working with multimedia objects have been learned, the
unit focuses on MediaPlayer and Camera. A schematic of MediaPlayer is shown on
the next page.
MediaPlayer
As you can see in the image, an audio goes through many states, from when the
resource is called until it finishes playing.
Page62 88
Module 8: Multimedia programming and mobile devices
Whenever you want to play a music file, you must first specify the path to the file.
Then it is necessary to prepare the audio for later execution. All this has already
been explained in more depth (with code included) in point 2.5 of UF1.
Please note that audio preparation can take some time, so it is necessary to do it in
the background.
Camera
Page63 88
Module 8: Multimedia programming and mobile devices
If the first option is carried out, it is necessary to give CAMERA permission to the
application (in the AndroidManifest.xml file) in order to use it. If the second option is
used, it is not mandatory to have access to the camera.
Let's not forget to request all the necessary permissions associated with our
application, such as access to external storage, Internet access, etc.
Once the camera has been opened in the application itself, it is necessary to detect
the camera, and if so, access it using the Camera.open() method. Once the camera
is finished being used, the resources need to be released with the release() method.
Page64 88
Module 8: Multimedia programming and mobile devices
This first topic provides an in-depth analysis of game engines, studying the concepts
of animation, game architecture and its components, types of game engines and
their uses, areas of specialization, main components of the game engine and
libraries. In addition, a study of existing games is carried out, as well as the
application of possible modifications to them.
Nowadays, mobile devices are part of people's daily lives, grouping all user needs
within a single device. This fact makes mobile devices used both for work or
communication purposes, as well as for leisure. This is where the development of
animated applications for devices comes in.
/
-----------------------------
TO
An animation is the change of one of the properties of an object
that allows it to be seen over time with a different appearance.
1)
The basis for creating these animations lies in programming. Android offers a
number of mechanisms dedicated to creating animations for both 2D and 3D
objects.
Page65 88
Module 8: Multimedia programming and mobile devices
• Canvas: is the template or canvas that allows you to define a control at the
user interface level in applications. Canvas can represent any object such as
ovals, lines, rectangles, triangles, etc.
• Animators: is the property that allows you to add a specific animation to any
object through the use of properties or programming styles.
• Drawable Animation: Allows you to load a series of Drawable resources to
create an animation. It uses traditional animations, such as placing one
image after another in order as if it were a movie.
• OpenGL: is one of the most important libraries for high-performance 2D and
3D graphics. Android includes support for its use.
• Resources used: within the logic of the game it is also necessary to control all
the sound effects and images.
This block is the fundamental part for the developer. All functions have to be
Page66 88
Module 8: Multimedia programming and mobile devices
• Output: These are the succession of scenes that are updated in the user
interface.
These frames are processed one after the other, giving the user a sensation of
continuous movement and animation. All these blocks of frames result in the game
scene at different moments in time.
The main task of an engine is to provide the game with a rendering engine for 2D
and 3D graphics, physics engine or collision detector, sounds, programming scripts,
animations, artificial intelligence, memory management and a graphical scene.
Nowadays there are a wide variety of graphic engines, such as: Ogre (which is open
source), Doom Engine, Quake Engine, Unity, cryengine, source engine, Unreal
engine, Game Maker, etc.
Page67 88
Module 8: Multimedia programming and mobile devices
Page68 88
Module 8: Multimedia programming and mobile devices
Page69 88
Module 8: Multimedia programming and mobile devices
most widely used libraries today. It is free and open source software. It
allows the use of basic elements such as lines, points, polygons, etc., as well
as other more complex elements, such as: textures, transformations, lighting,
etc.
• Direct3D: set of multimedia libraries. It is OpenGL's biggest competitor in the
gaming world. It allows the use of elements such as lines, points or polygons,
as well as management of textures or geometric transformations. Property of
Microsoft.
1.5. Components of a game engine
A game engine is a fundamental part of a game's programming code. This graphics
engine is responsible for most of the graphical aspects of a game.
One of its tasks is to establish communication and take advantage of all the
resources that a graphics card offers.
The main components of a game engine are:
• Libraries: all those libraries used for the development of figures, polygons, lights
and shadows, etc.
• Physics engine: responsible for managing collisions, animations, programming
scripts, sounds, physics, etc.
• Rendering engine: It is responsible for rendering all the textures of a map, all the
reliefs, object smoothing, gravity, stripe drawing, etc.
These components globally collect all the elements that appear within a game. Each
of these elements is part of a set of resources that can be found in every graphics
engine:
• Assets: all 3D models, textures, materials, animations, sounds, etc.
This group represents all the elements that will be part of the game.
• Rendering: All textures and materials in this part make use of the
resources designed for the graphics engine. This will show the visual aspect and
potential of a graphics engine.
• Sounds: It is necessary to configure within the engine how the audio tracks will
be. The sound of the video game will depend on the processing capacity of
these sounds. Some of the configurable options are: tone modification, looping
of sounds, etc.
• Artificial intelligence: This is one of the most important features that a graphics
engine can develop. This adds incentives to the game, allowing the
development of the game to occur based on decision-making defined by a set of
rules. In addition, it defines the behavior of all elements that are not controlled
by the user player, but are part of the game elements.
• Visual scripts: Not only is it possible to execute portions of code defined in the
Page70 88
Module 8: Multimedia programming and mobile devices
game, but they can also be executed in real time within the graphical aspect of
the game.
• Shading and lighting: the graphics engine provides colors and shadows to each
of the vertices that form part of the scene.
As has been seen, the tasks that make up a graphics engine require the use of a large
number of resources within the computer. Hence, the higher the processing power
and speed of a graphics card, the better the result of a game scene. To reduce the
cost of this, some engines employ a number of techniques that allow terrain or
materials to be rendered without consuming resources, but instead appearing within
the visual space, which is known as culling.
Graphics engines are a key aspect within a game. They have been created exclusively
for the development of video games, and today they are the fundamental tool for
creating video games. The evolution of games and entertainment is linked to the
evolution of game engines.
As already mentioned in some of the previous sections, libraries are a key section in
the game development process. To give an object or element a more realistic
appearance, graphics engines need to process a series of functions, which draw
these objects in 2D or 3D. Since the design of an object requires a great deal of
programming work, and it will be represented on many occasions in a game, the
creation of these objects is covered by a series of functions that are provided by the
libraries.
These libraries allow the programmer to abstract from the more complex aspects of
representing visual elements; it is only necessary to call the function of the library in
charge of this and collect the returned object for representation in the scene.
The basic functions used by graphics engines are those that allow working with
visual elements, such as points, lines, planes or polygons. They provide the
fundamental resources in a game such as sounds and music. The character modeling
section should include the use of sprites for 2D, and the use of models (assets) for
the development of 3D game platforms.
Page71 88
Module 8: Multimedia programming and mobile devices
The goal of these APIs is to provide the developer with a document where they can
find all the resources, and, in this way, reduce the complexity in communicating with
the graphics cards.
The operation of this type of library consists of trying to accept as input a series of
primitives, which are: lines, points and polygons, and convert them into pixels.
OpenGL is currently at version 4. Each of these versions has been developing an
evolution in terms of textures, shapes and transformations of the objects. It is
possible to use any of them, using the documentation provided on their official
website. This documentation offers numerous example codes, books or video
tutorials to make use of the desired library.
Starting with version 3, OpenGL developed its own rendering language called GLSL.
This allows the development of a scene to be carried out through programming.
Another API that offers this same type of 3D graphics is Direct 3D. It offers a low-
level 3D API, in which you can find basic elements such as: coordinate systems,
transformations, polygons, points and lines.
It is a library with graphic resources that require a level of programming experienced
in this type of resources. One of the strong points of this API is that it is independent
of the type of device to be used, which allows for more versatile development.
1.8. Study of existing games
Nowadays, the gaming market for devices is very large. There are already a huge
number of games for all possible types of genres. This often makes it difficult for
some of them to succeed. For this reason, it is advisable to carry out a market study
before its development, focusing on those games of a similar nature to the game to
be created.
Page72 88
Module 8: Multimedia programming and mobile devices
In many cases, the development of a type of video game genre is related to the
success of one of them. When downloads of a particular game increase significantly,
it means that that type of game is a good draw for users. This fact can be exploited
by game developers with fewer resources to enter the market.
Both 2D and 3D games are accepted in the mobile gaming industry, so the range of
possibilities is unlimited.
Page73 88
Module 8: Multimedia programming and mobile devices
Android games account for almost the largest percentage of downloads of leisure-
related applications, so it is possible to find examples of games that have already
been tested and whose success has been measured. The process of creating a new
game is not easy, and often this requires that this development be carried out by a
large number of people from different specialties, who work together within the
project. However, the pace of life in society forces these devices to be continually
updated, so it is very necessary to make this game adapt to the new times, adding
new features and optimizing its performance on the devices.
Unlike apps, games are generally not open source, so it is not possible to legally add
new modifications to the game if you are not part of the development team or the
author of one of them.
Page74 88
Module 8: Multimedia programming and mobile devices
This topic will study the development of 2D and 3D games, their main development
environments, the integration of the game engine into said environment, 3D
programming concepts, their development phases and the properties of objects.
The different applications of both the graphics engine functions and the scene graph
will also be shown, as well as the execution analysis and optimization of the code.
There are different types of environments that are geared towards a type of game,
either 2D or 3D. It is also possible to find different environments depending on the
complexity of the game to be created.
If the goal is to make simple games with an interface that is not very demanding for
2D platforms, it is possible to use environments such as:
• Stencyl: is a platform that allows the creation of 2D games through the use
of code blocks, which help to understand basic programming structures, so it
is not necessary to develop lines of code. Allows you to add images for
characters, which are added to a scene by simply dragging them. It is a
simple and easy-to-use platform.
• Pygame: game development environment using the Python language. It
allows the creation of 2D games. It is based on the use of sprites for
characters and libraries of sound and multimedia resources. Programming is
a bit more complex, since it is necessary to create control structures and
variables through code.
When the game to be developed requires greater graphical power, as is the case
with 3D, it is necessary that the development environments be, in turn, more
complete. Some of the most important ones are:
Page75 88
Module 8: Multimedia programming and mobile devices
• Unity 3D: Today, Unity is one of the most widely used tools in the gaming
world, as well as one of the most highly rated. Unity allows you to export a
game created on any of the different devices. Unity is based on the C#
language. It has its own engine for developing the graphic part, which allows
for a very complete development of all the scenes in a game. It is possible to
configure all the necessary elements, such as: lighting, textures, materials,
characters, terrain, sounds, physics, etc.
• Unreal Engine: Along with Unity 3D, it is one of the best-known and most
valued environments in the world of game development. Allows
configuration and design of advanced graphical resources in the same way as
Unity.
To do this, the first step is, once the project is selected, go to the editing menu and
select preferences. This will display the Unity preferences window, and within it, in
the external tools section, you will be able to view the different compiler
configuration parameters. You can choose the editor for programming the lines of
code, as well as the path where the Android SDK is installed on your computer.
Once this path is selected, Unity will be able to compile an Android project. To
perform the compilation, select the compilation configuration menu. In this window
you can choose which will be the compilation platform, in this case Android. This will
perform the entire graphics rendering process as well as programming for that
platform. At this point the desired scenes will be added to compile. And once the
platform is chosen, the compile option must be selected.
Android does not allow compiling without a bundle identifier, so you will need to
Page76 88
Module 8: Multimedia programming and mobile devices
define such an identifier which will then be used by Google Play for publishing.
Within the project settings section, all the sections of the package will be specified.
Finally, once all these sections have been completed, an .apk (extension for Android
applications) will be generated on the computer, which will be the executable file
that will be installed on the desired device.
Page77 88
Module 8: Multimedia programming and mobile devices
This class is called a character controller, and it allows you to apply physics and
collisions to characters in a capsule form. Provides a simple collider. This causes the
character to walk on the ground and not climb walls.
Finally, another of the concepts, and probably the most complex, is Artificial
Intelligence (AI). This allows Unity to create characters that are capable of
interacting in the scene, even avoiding collisions between its elements. This tool in
Unity is called NavMesh.
Page78 88
Module 8: Multimedia programming and mobile devices
For them, through the agent creation inspector, the properties that will characterize
it are defined, such as:
• Radius: radius that the character will have when moving to avoid
collisions.
• Height: Defines the maximum height of obstacles that the character will be
able to access by passing under them.
• Speed: Maximum speed in units per second that the character will have.
• Acceleration: Acceleration of the character's movement and actions.
• Area: will define the path the character will take and which ones he will not
be able to choose.
Creating a new game requires a large number of tasks that can be grouped into
different phases:
1st) Design phase: this is the step prior to programming. At this stage it is necessary
to determine which will be the relevant aspects of the game, choose the theme and
the development of the story. It is also important to establish what the rules of the
game will be.
Once the story is documented, it is necessary to separate the game into parts. Each
of these parts will make up the game screens. You also have to define what the
menu will look like within the screens, as well as the placement of the objects within
it.
2nd) Code design: in this phase all the layers that make up the game are specified.
It's about separating all the basic aspects of the game from its functionality. This is
what is known as Framework.
The Framework will define how the game windows will be handled. Allows you to
ensure that objects occupy the correct space within the corresponding window. It
will also be responsible for handling user input events. These will, in most cases, be
collected from the computer's keyboard or mouse.
Page79 88
Module 8: Multimedia programming and mobile devices
Another task of the Framework is file management, where reading and writing tasks
will be carried out, such as, for example, saving game preferences and scores.
It will also determine the handling of graphics, which establishes the pixels mapped
to the different screens. It is necessary to determine the position through the
coordinates of each of the pixels, as well as the color. Audio handling, to be able to
play, for example, background music in the game, will also be determined by the
Framework.
3rd) Asset Design: This is one of the most complicated phases and has the greatest
impact on a game. These are the creations of the different elements or models that
can be used within the game, such as: characters, logos, sounds, buttons, fonts, etc.
4th) Game logic design: this is the phase where you define how the game will
behave. The rules already designed will be applied, as well as the programming of
the behavior of each of the game events.
5th) Testing: one of the most important phases. This is when the entire application is
checked to assess the game's performance and the correct implementation of the
rest of the phases.
6th) Game distribution: once all the development phases have been completed, the
objective is for the product to be distributed. To do this, you need to export this
game in the same way as an application.
Each of the objects represented within a scene has certain properties, which are:
• Light: is what allows us to observe points of illumination within the scene. This
will bring the game to life. Light or a point of light on a particular part of a scene
leads to focusing your attention on it. It will indicate the projection of the
camera within the game. It is possible to add different light points in a scene, as
well as configure the color of a light.
• Textures: reflect the quality with which all the objects that appear within the
game environment can be appreciated. They are part of the textures, for
example, the materials. Within the materials, some can be distinguished such
as: water, metal, wood, fabrics, etc. To achieve a real effect in a texture,
mathematical algorithms called shaders are applied to these materials, which
allow defining what the color of each of the pixels that make up an object will
Page80 88
Module 8: Multimedia programming and mobile devices
be.
• Reflections and shadows: These add a more realistic representation to objects.
To achieve this effect, what is done is to add a kind of outline to the graphic
components. The color of this shadow is defined and what the distance applied
to each object will be. Shadows usually match the projection of light, so that the
shadow appears as an effect of said lighting. With reflections and shadows it is
possible to establish the position that an object occupies within the scene.
These are some of the basic properties of objects. These will be configured
individually for each object depending on the possible interaction within a scene.
Page81 88
Module 8: Multimedia programming and mobile devices
One of the most complex tasks that a graphics engine has is the rendering of the
objects that make up a given scene. The processing of each of them requires a
certain amount of graphic resources that, in most cases, are offered by graphic
cards.
Page82 88
Module 8: Multimedia programming and mobile devices
Unity offers a simple tool for organizing and managing animations called Animator
Controller. This allows you to create a graph of actions within Unity, which allows
you to control all the animations of a character or object. It is possible to establish
an order of execution of the same depending on some of the rules or conditions of
the game.
This, for example, allows you to define the behavior of a character who normally
walks in one direction and who, when you press the space bar, will jump.
Each of these nodes will be the representation of a character action. These will
reflect the transitions between the most basic states.
Its use usually occurs during the use of directional movements of the character,
which are repeated periodically until the occurrence of another of the events. These
movements usually involve walking forward, backward, or diagonally. Other nodes
will define states such as character death, falls or collisions with other objects in the
scene, etc.
Page83 88
Module 8: Multimedia programming and mobile devices
During the development of a game it will be necessary to compile and debug the
code many times. Unity offers an integrated IDE (Mono Develop). This will be the
default editor for programming the game code.
When you are editing a file within the project it will appear as a tab. The text editor
allows you to add breakpoints in the margins next to each of the lines of code you
want. Once these breakpoints are selected, debugging of the code begins through
the debug button. This will execute the code, stopping at the first breakpoint found
in the code. This allows you to see the values that all the variables have taken up to
that point.
It is also possible to navigate between the different stopping points to check the
correct behavior of the application.
In case of errors during compilation, Unity contains a log file called Debug.log, where
all messages displayed in the console will be stored. The most common thing is that
if there are errors in the code, Unity itself, when compiling, does not allow the game
to run, and displays a message at the bottom referencing the error or errors found.
Another tool that is useful within the Unity IDE is the Unity Test Runner. This tool
checks programming code for errors before compiling. This can be useful for
correcting syntax errors, for example.
In addition to having all these debugging tools, it is advisable for the developer to
have acquired a series of good programming and code structuring practices.
The code has to be as clean as possible, which will help in the later correction and
improvement of some functions. In projects with extensive code development, this
can pose a very large optimization problem.
Declared functions must be well defined and there should not be multiple functions
whose behavior is the same.
Page84 88
Module 8: Multimedia programming and mobile devices
Literature
Multimedia programming and mobile devices. Caesar Saint John Pastor. Egret.
Webgraphy
https://developer.android.com/index.html
http://www.sgoliver.net/blog/android-programming-course/index-of-contents/
Page85 88
already
' I LERNA,
Online j
■function updatePhotoDesciptiont ■ if
(descrptions Nength > (page • 1 \ document
.getElementByK
Item)
■function updateAllmagesg {
var i = 1;
■ while ( < 10) {
\ var elements = photo' + i,
i var elementidBig = big m age + i;
Yes if (page *9+i-1< photos length) (
® \ I document.getElementByldelemertd) Ic-m
W \ \
document.getElementByidele
mentdig) *
} else {