0% found this document useful (0 votes)
133 views64 pages

Android Course: By: MR Adnane Ayman

The document provides an overview of an Android course outline that covers the following topics: 1. The course is divided into 3 chapters that cover Android basics, user interface, and advanced concepts over 22 hours total. 2. Chapter I focuses on Android fundamentals like the architecture, application components, and activities over 4 hours. 3. Chapter II covers the user interface, layouts, controls, and event handling for 2 hours. 4. Chapter III is 12 hours on practical work involving alerts, maps, preferences, databases and other advanced features.

Uploaded by

ramzi esprims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views64 pages

Android Course: By: MR Adnane Ayman

The document provides an overview of an Android course outline that covers the following topics: 1. The course is divided into 3 chapters that cover Android basics, user interface, and advanced concepts over 22 hours total. 2. Chapter I focuses on Android fundamentals like the architecture, application components, and activities over 4 hours. 3. Chapter II covers the user interface, layouts, controls, and event handling for 2 hours. 4. Chapter III is 12 hours on practical work involving alerts, maps, preferences, databases and other advanced features.

Uploaded by

ramzi esprims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 64

ANDROID

COURSE

By: Mr Adnane Ayman


Chapter I Chapter II Chapter
III
• Android • User • Advanced &
Basics Interfac Useful Concepts
e (Practical Work)

4 hours 2 hours 12 hours


Project 2 hours
Presentation

Final Exam 2 hours


Facts
Chapter I: Android Basics
4 hours

1. Overview [What is android ? / why android? /features]


2. Environment Setup ( IDEs ):
3. Architecture
4. Application Components
5. Running my first application
6. Resources 
7. Activities
8. Intents
Chapter II: User Interface
2 hours

1. UI layouts
2. UI Controls
3. Event handlings
Chapter III: Advanced &
Useful Concepts: Practical Work
12 hours
1. Alert Dialogs
2. Auto Complete
3. Sending SMS
4. Sending Emails
5. Google maps (TP markers)
6. Progress Bars
7. Shared Preferences
8. SQLite / ORMs (Sugar)
9. Text to speech
10.Firebase(FirebaseAuthenticationManager + FirebaseData
baseManager
INTRODUCTION
TO ANDROID
AND ANDROID
STUDIO
{ Mr Adnane Ayman
What Will We Learn Today
Android Basics:

 Overview [What is android ? / why android? /features]


 Environment Setup ( IDEs ):

 Architecture

 Application Components

 Running my first application

 Resources 

 Activities

 Intents
What is android ?

Android is the world’s most popular and dominant


mobile operating system. It’s based on Linux and is
open-source. It runs on a wide variety of hardware,
including smartphones, smart watches, cars, televisions,
digital cameras, game consoles and more. It was founded
by Andy Rubin and three others in October 2003 and got
acquired by Google in August 2005.
Distribution
dashboard

2011

2018
Worlwide Market Share

With Over 2.5 Billion monthly active users


Why Android?
Open Source

Distribute your
app anywhere Larger Developer
(Playstore, and community
Amazon,Appstor reach
e …)

Android

Rich
Free SDK ,IDE
development
and emulator
Environment
Feature & Description
Features Feature & Description
Beautiful UI Multi-touch
Android OS basic screen provides a Android has native support for multi-
beautiful and intuitive user interface. touch which was initially made available
Connectivity in handsets.
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS,
Bluetooth, Wi-Fi, LTE, NFC and WiMAX. Multi-tasking
Storage User can jump from one task to another
SQLite, a lightweight relational database, and same time various application can run
is used for data storage purposes. simultaneously.

Media support GCM


MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, Google Cloud Messaging (GCM) is a
GIF, SVG … service that lets developers send short
Messaging message data to their users on Android
SMS and MMS devices, without needing a proprietary
sync solution.
Web browser
Based on the open-source WebKit layout
engine, coupled with Chrome's V8 Android Beam
JavaScript engine supporting HTML5 and A popular NFC-based technology that lets
CSS3. users instantly share, just by touching two
NFC-enabled phones together.
Android Plateform Overview
Android Plateform Overview

Android is actually a system of the Linux family, for once


without the GNU tools. The OS is based on:
 A Linux kernel (and its drivers)

 a virtual machine: Dalvik Virtual Machine

 applications (browser, contact management, telephony

application ...)

[Dalvik] is the name of the open-source virtual machine used on


Android systems. This virtual machine is running .dex files and
is not compatible with a JVM of the type Java SE or even Java
ME
What Do I Need To Build An
Android App?

• Java Programming Language & XML


• Android SDK & SDK Tools
• Android Studio
• The desire to learn
Environment Setup ( IDEs ):
You can start the development of your Android application on
one of the following operating systems:

• Microsoft Windows XP or later.

• Mac OS X 10.5.8 or later with Intel chip.

• Linux, including GNU C Library 2.7 or later.

Second, all the tools needed to develop Android apps are


available for free and can be downloaded from the web. Below is
a list of the software you will need before you start programming
your Android application.

• Java JDK5 or later

• Android Studio
Environment Setup ( IDEs ):
You can download the latest version of Java JDK from Oracle's
Java site
− Java SE Downloads. You will find instructions for installing
JDK in downloaded files, follow the given instructions to install
and configure the setup. Finally set PATH and JAVA_HOME
environment variables to refer to the directory that
contains java and javac, typically java_install_dir/bin and
java_install_dir respectively.

Android IDEs
There are so many sophisticated Technologies are available to
develop android applications, the familiar technologies, which
are predominantly using tools as follows
• Android Studio
• Eclipse IDE(Deprecated)
Architecture
• Java: Java class files containing app logic
• Res: Different resource files
• Anim: Animation resource files
• Drawable: Images
• Drawable-Xdpi: Images depending on
screen density
• Layout: App layout files
• Menu: Layout menu files
• Values: Value files (strings, colors,
arrays, etc)
• Values-vX: Value files depending on API
level
• Values-Xdp: Value files depending on
screen density
• XML: XML files
• AndroidManifest.xml: App metadata file
• build.gradle: Build related settings
Application Components

Application components are the essential building


blocks of an Android application. These components
are loosely coupled by the application manifest
file AndroidManifest.xml that describes each
component of the application and how they interact.
There are following four main components that can be
used within an Android application :
Activities

 They dictate the UI and handle the


user interaction to the smart phone
screen
 Every app has at least one activity

 Activities can be full-screen, floating

or embedded inside another activity


Services
 A service is a long running
operation in the background
 There are two types of services
in Android – Bounded (which
runs as long as components
which bind to it run) and
Unbounded (which runs
indefinitely)
 Services run on the main
thread of the application by
default
BroadcastReceiver
 A broadcast is a system or app
event that can be “broadcasted”
so other apps/services can listen
for it
 Broadcasts are handled by a
BroadcastReceiver, which is a
component that allows you to
listen for broadcasts
 A BroadcastReceiver can be
implemented in
AndroidManifest.xml, or
dynamically by calling
registerReceiver(), or both
Content Providers/Resolvers
 A content provider allows you to
store data in your app in a
Update
structured way, similar to a
relational database like SQL, for
the purpose of providing it to
other apps. Example usage:
App
Contacts app, SMS app, etc
Insert Delete
Database  A content resolver allows you to
get data from a content provider
or manipulate its data (modify,
delete, update, etc)
 You cannot request to read data
Fetch
from a content provider at
runtime, it has to be declared in
AndroidManifest.xml
Additional Components
Intents
• An intent is an abstract description of
an operation to be performed. Think
of it as an “intention” to do
something
• Intents can be used to start activities,
services or send a broadcast
• Intents are of two types – Explicit
(when you know what exactly you
want to do), and Implicit (when
you’re not sure what you want to do)
AndroidManifest.XML
• Is the file which describes the
fundamental characteristics
of the app and defines each
of its components.
Layouts
• A layout defines the visual structure for a user
interface, such as the UI for an activity or app widget
• Layouts can be defined both in XML or
programmatically using View and ViewGroup objects
• There are 5 different types of Layouts in Android:
LinearLayout, RelativeLayout, FrameLayout,
TableLayout and AbsoluteLayout
Life cycle of Android application
Workflow
Running my first application

The first step is to


create a simple
Android Application
using Android studio.
When you click on
Android studio icon, it
will show screen as
shown here:
Running my first application

The next level of


installation should
contain selecting the
activity to mobile, it
specifies the default
layout for Applications.
Running my first application
A new installation frame
should ask Application
name, package
information and location
of the project. You need
to specify Minimum
SDK, and declare as
API:17 Android 4.2(Jelly
Bean)
At the final stage it going to be open development tool to write the application code.
Anatomy of Android Application
1. Java => Contains the .java source
files for your project.

2. res/drawable => A directory for


drawable objects

3. res/layout => A directory for files


that define your app's UI

4. res/values => A directory for other


various XML files that contain a
collection of strings and colours
definitions…

5. AndroidManifest.xml

6. Build.gradle => contains


compileSdkVersion,
buildToolsVersion, applicationId,
minSdkVersion, targetSdkVersion,
versionCode and versionName
The Main Activity File
The main activity code is a Java file MainActivity.java. This is the actual application
file which ultimately gets converted to a Dalvik executable and runs your application.
Following is the default code generated by the application wizard for 
Hello World! application

Here, R.layout.activity_main refers to the activity_main.xml file located in


the res/layout folder. The onCreate() method is one of many methods that are figured
when an activity is loaded.
The Manifest File
Following is the list of tags which you will use in your manifest file to specify different
Android application components :
<activity>elements for activities; <service> elements for services ;<receiver> elements for
broadcast receivers ;<provider> elements for content providers
The Strings File
The strings.xml file is located in the res/values folder and it
contains all the text that your application uses. For example,
the names of buttons, labels, default text, and similar types of
strings go into this file.
The Layout File
The activity_main.xml is a layout file available in res/layout directory, that is referenced
by your application when building its interface
Running the application
Congratulations!!! you have
developed your first Android
Application
Friendly
reminder
Accessing Resources in Code
When your Android application is compiled, a R class gets generated, which contains
resource IDs for all the resources available in your res/ directory. You can use R class to
access that resource using sub-directory and resource name or directly resource ID
Example 1 :
To access res/drawable/myimage.png and set an ImageView you will use following code:

ImageView imageView = (ImageView) findViewById(R.id.myimageview);


imageView.setImageResource(R.drawable.myimage);

Example 2:
Consider next example where res/values/strings.xml has following definition 

Now you can set the text on a TextView object with ID msg using a resource ID as
follows :
TextView msgTextView = (TextView) findViewById(R.id.msg);
msgTextView.setText(R.string.hello);
Accessing Resources in Code

Example 3 :
Consider the following resource XML res/values/strings.xml file that includes a color
resource and a string resource:

Now you can use these resources in the following layout file to set the text color and
text string as follows :
The Application
life cycle

LIFECYCLE.txt
Click here
Layouts
Layouts
 When the content for your layout is dynamic or not pre-determined, you
can use a layout that subclasses AdapterView to populate the layout
with views at runtime.
UI Controls
 Input controls are the interactive components in your app's
user interface. Android provides a wide variety of controls
you can use in your UI, such as buttons, text fields, seek bars,
check box, zoom buttons, toggle buttons, and many more.

test.txt
UI Controls
 Input controls are the interactive components in your app's user interface.
Android provides a wide variety of controls you can use in your UI, such as
buttons, text fields, seek bars, check box, zoom buttons, toggle buttons, and
many more.

Example 1: Button with id = myButton


 Step 1:

Public class MainActivity extends AppCompatActivity implements


View.OnClickListener
 Step 2:

Private Button button;


(inside on create)=>
button = (Button) findViewById(R.id.myButton);
button.setOnClickListener(this);
UI Controls
Example 1: Button with id = myButton
 Step 3:

@override
Public void onClick(View view) {
if(view == myButton){
//traitement+ toast
Toast.makeText(getApplicationContext(),“click!!",Toast.LENGTH_SHOR
T).show();
}
}
UI Controls
Example 2: Button style
https://angrytools.com/android/button/
 Step 1: paste the xml generated code in layout.xml

 Step 2: paste the buttonShape.xml generated code in the drawable

folder

Example 3 : changing case of textview


TP ; help (getText,setText , toLowerCase, toUpperCase)
UI Controls

num1 OP num2

+
Example 4 : Basic calculator
Result -
: XX

/
Intents
An Android Intent is an abstract description of an operation to be performed.
Example 1 :
// Explicit Intent by specifying its class name
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
// Starts TargetActivity
startActivity(i);

These intents (explicit) designate the


target component by its name and they
are typically used for application-
internal messages - such as an activity
starting a subordinate service or
launching a sister activity.
Intents
Example 1 : Implicit Intent
String q = “Tesla";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);
Login Page Login

**********
Case user
unknown
Connect

Login
Example 4 :
Main Screen **********

Connect
Case user New
known Activity
+
greetings
Notifications
Android Toast class provides a handy way to show users alerts but problem
is that these alerts are not persistent which means alert flashes on the screen
for a few seconds and then disappears.

Example :
 Step 1:  Create Notification Builder

NotificationCompat.BuildermBuilder=new NotificationCompat.Builder(this);

 Step 2: Once you have Builder object, you can set its Notification properties using
Builder object as per your requirement. But this is mandatory to set at least following −
 A small icon, set by setSmallIcon()
 A title, set by setContentTitle()
 Detail text, set by setContentText()
=>
mBuilder.setSmallIcon(R.drawable.notification_icon);
mBuilder.setContentTitle("Notification Alert, Click Me!"); mBuilder.setContentText("Hi,
This is Android Notification Detail!");
Notifications
Example :
 Step 3: Attach Actions

 This is an optional part and required if you want to attach an action with
the notification. An action allows users to go directly from the
notification to an Activity in your application
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURREN
T); mBuilder.setContentIntent(resultPendingIntent);
Notifications

Example :
 Step 4: Issue the notification

 Finally, you pass the Notification object to the


system by calling NotificationManager.notify() to
send your notification.
NotificationManager mNotificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification
later on.
mNotificationManager.notify(notificationID,
mBuilder.build());
Sugar ORM (SQLite)

Step 1: Download via Gradle :


 implementation 'com.github.satyan:sugar:1.5‘

Step 2: Manifest File inside Application :


 android:name="com.orm.SugarApp“

 outside <Application>

<meta-data android:name="DATABASE" android:value=“Vehicles.db" />


<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME"
android:value="com.example.myapplication.vehiclesModel" />
Sugar ORM (SQLite)

Step 3: Create the Model :


Step 4: Create the Layout / Activity:
Sending a Mail
Example .
// You will use ACTION_SEND action to launch an email client installed on your
Android device
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
startActivity(Intent.createChooser(email, "Choose an email client from..."));
Tests
Example 1 : Robolectric
http://robolectric.org/

Example 2 : Espresso
https://developer.android.com/training/testing/espresso
Any Questions?

AS
YO K ME

Is coding an instrument?

You might also like