Android Course: By: MR Adnane Ayman
Android Course: By: MR Adnane Ayman
COURSE
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:
Architecture
Application Components
Resources
Activities
Intents
What is android ?
2011
2018
Worlwide Market Share
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.
application ...)
• 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
5. AndroidManifest.xml
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.
@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
folder
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);
**********
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
outside <Application>
Example 2 : Espresso
https://developer.android.com/training/testing/espresso
Any Questions?
AS
YO K ME
Is coding an instrument?