The document discusses Android's windowing system architecture and components. It describes the main components as SurfaceManager, WindowManager, and ActivityManager. SurfaceManager is responsible for compositing surfaces. WindowManager creates and lays out surfaces on behalf of clients and dispatches input events. ActivityManager manages activity lifecycles and stacking. The document also covers handling gestures, animations, custom view architecture, using the hierarchy viewer tool, and event propagation in Android views.
3. What is Android windowing system
In computing, a windowing
system (or window system) is a type
of graphical user interface (GUI) which
implements the WIMP (windows, icons,
menus, pointer) paradigm for a user
interface.
4. What is Android windowing system
Most popular windowing systems are X11
and Wayland
Most popular widget toolkits
are GTK+/Clutter and Qt
Most popular desktop environments
are GNOME and the KDE Software
Compilation
5. X Window
The X Window System (sometimes referred to
as "X" or as "XWindows") is an open, cross-
platform, client/server system for managing a
windowed graphical user interface in a
distributed network.
is a windowing system for bitmap displays,
common on UNIX-like computer operating
systems.
11. SurfaceManager
It is used for compositing window manager
with off-screen buffering.
Off-screen buffering means you cant directly
draw into the screen, but your drawings go to
the off-screen buffer.
There it is combined with other drawings and
form the final screen the user will see.
This off screen buffer is the reason behind the
transparency of windows.
13. WindowManager
The interface that apps use to talk to the
window manager.
Use Context.getSystemService(Context.WIND
OW_SERVICE) to get one of these.
14. WindowManager
Each window manager instance is bound to a
particular Display.
To obtain a WindowManager for a different
display, use createDisplayContext(Display) to
obtain a Context for that display, then
use Context.getSystemService(Context.WINDO
W_SERVICE) to get the WindowManager.
16. ActivityManager
Interact with the overall activities running in the
system.
Information you can retrieve about the available
memory
Information you can retrieve about any processes
that are in an error condition.
Information you can retrieve about a running
process.
ActivityManager.MemoryInfo,
ActivityManager.RunningAppProcessInfo
17. An activity has one or more windows (e.g.
dialogs)
A window has one or more surfaces (e.g.
surface views)
However, in window manager, a window is
called a session
A surface is called a window
18. How Android Draws Views?
• When an Activity receives focus, it will be
requested to draw its layout.
• The Android framework will handle the
procedure for drawing, but the Activity must
provide the root node of its layout hierarchy.
19. How Android Draws Views?
• When an Activity receives focus, it will be
requested to draw its layout.
• The Android framework will handle the
procedure for drawing, but the Activity must
provide the root node of its layout hierarchy.
• Drawing the layout is a two pass process: a
measure pass and a layout pass.
21. Handling Gestures
Some examples of common multi-touch gestures
and actions you might use include:
Pinch to zoom in, spread to zoom out.
Basic dragging in order to move, adjust, scroll,
and position.
Flick to jump to the next screen or scroll extra
fast.
Tap and hold to open an item or context menu.
Multi-finger drag often scrolls faster!
22. Handling Gestures
Handling multi touch gesture
Detecting common gesture
Managing touch event
Animating a scroll gesture
Tracking movement
Dragging & scalling
23. Handling Gestures
Android provides special types of touch screen
events such as pinch , double tap, scrolls , long
presses and flinch. These are all known as
gestures.
24. Handling Gestures
Android provides GestureDetector class to
receive motion events and tell us that these
events correspond to gestures or not.
25. Handling Gestures
To use it , you need to create an object of
GestureDetector and then extend another
class with
GestureDetector.SimpleOnGestureListener to
act as a listener and override some methods.
26. Handling Gestures
GestureDetector myG;
myG = new GestureDetector(this,new Gesture());
class Gesture extends GestureDetector.SimpleOnGestureListener{
public boolean onSingleTapUp(MotionEvent ev) {
}
public void onLongPress(MotionEvent ev) {
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
}
}
}
27. Handling Pinch Gesture
Android provides ScaleGestureDetector class
to handle gestures like pinch e.t.c. In order to
use it , you need to instantiate an object of
this class. Its syntax is as follow: -
ScaleGestureDetector SGD; SGD = new ScaleGestureDetector(this,new
ScaleListener());
28. Handling Pinch Gesture
We have to define the event listener and override a function OnTouchEvent to
make it working.
public boolean onTouchEvent(MotionEvent ev) {
SGD.onTouchEvent(ev);
return true;
}
private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
float scale = detector.getScaleFactor();
return true;
}
}
29. Handling Pinch Gesture
Apart from the pinch gestures , there are other
methods avaialible that notify more about touch
events. They are listed below:
1 getEventTime()
This method get the event time of the current event being processed..
2 getFocusX()
This method get the X coordinate of the current gesture's focal point.
3 getFocusY()
This method get the Y coordinate of the current gesture's focal point.
4 getTimeDelta()
This method return the time difference in milliseconds between the previous accepted scaling event and the
current scaling event.
5 isInProgress()
This method returns true if a scale gesture is in progress..
6 onTouchEvent(MotionEvent event)
This method accepts MotionEvents and dispatches events when appropriate.
30. Handling Pinch Gesture
Use of ScaleGestureDetector class.
It creates a basic application that allows you to
zoom in and out through pinch.
32. Animation in Android
• Animation in android is possible from many
ways.
• making animation called tweened animation.
33. Animation in Android
• Animation in android is possible from many
ways.
• making animation called tweened animation.
34. Tween Animation
• Tween Animation takes some parameters such
as start value , end value, size , time duration ,
rotation angle e.t.c and perform the required
animation on that object.
35. Tween Animation
• In order to perform animation in android , call
a static function loadAnimation() of the class
AnimationUtils.
Animation animation =
AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.myanimation);
second parameter, it is the name of the our animation xml file.
36. Sr.No Method & Description
1 start()
This method starts the animation.
2 setDuration(long duration)
This method sets the duration of an animation.
3 getDuration()
This method gets the duration which is set by above
method
4 end()
This method ends the animation.
5 cancel()
This method cancels the animation.
Tween Animation
38. Zoom in animation
• To perform a zoom in animation , create an
XML file under anim folder under res
directory, and put zoom xml code.
<set xmlns:android="http://schemas.android.com/apk/res/android"> <scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5" android:toXScale="3.0" android:fromYScale="0.5"
android:toYScale="3.0" android:duration="5000" android:pivotX="50%"
android:pivotY="50%" > </scale> </set>
39. Zoom in animation
• The
parameter fromXScale and fromYScale define
s the start point and the
parameters toXScale andtoYScale defines the
end point.
• The duration defines the time of animation
and the pivotX, pivotYdefines the center from
where the animation would start.
41. • Android offers a sophisticated and powerful
componentized model for building your UI, based
on the fundamental layout classes: View
and ViewGroup.
• A partial list of available widgets
includes Button, TextView,
EditText, ListView, CheckBox,
RadioButton, Gallery, Spinner, and the more
special-
purpose AutoCompleteTextView, ImageSwitcher,
and TextSwitcher.
• Among the layouts available
are LinearLayout, FrameLayout, RelativeLayout,
and others
42. • If none of the prebuilt widgets or layouts
meets your needs, you can create your own
View subclass.
43. View Hierarchy Design
• Sometimes your application's layout can slow
down your application. To help debug issues in
your layout, the Android SDK provides the
Hierarchy Viewer and lint tools.
44. View Hierarchy Design
• The Hierarchy Viewer application allows you
to debug and optimize your user interface
• It provides a visual representation of the
layout's View hierarchy
45. View Hierarchy Design
• Android lint is a static code scanning tool that
helps you optimize the layouts and layout
hierarchies of your applications, as well as
detect other common coding problems.
46. Using Hierarchy Viewer
• Connect your device or launch an emulator. To
preserve security, Hierarchy Viewer can only connect to
devices running a developer version of the Android
system.
• If you have not done so already, install the application
you want to work with.
• Run the application, and ensure that its UI is visible.
• From a terminal, launch hierarchyviewer from
the <sdk>/tools/ directory.
• Window will launched with device list
• Select apps name(packagename) and perform
operaion.
47.
48. Using Hierarchy Viewer
• The View Hierarchy window displays the View
objects that form the UI of the Activity that is
running on your device or emulator.
• You should see four panes:-
– Tree View:
– Tree Overview,
– Layout View,
– Properties View
49. Using Hierarchy Viewer
• When the UI of the current Activity changes,
the View Hierarchy window is not
automatically updated.
• To update it, click Load View Hierarchy at the
top of the window.
50.
51. Working with an individual View in
Tree View
• Each node in Tree View represents a single
View. Some information is always visible.
• Starting at the top of the node, you see the
following:
52. Working with an individual View in
Tree View
1. View class: The View object's class.
2. View object address: A pointer to View
object.
3. View object ID: The value of
the android:id attribute.
4. Performance indicators:
1. Green: Fastest, 50% faster than view object
2. Yellow : slower 50% of all the View objects
3. Red : slowest one in the tree
53. Working with an individual View in
Tree View
5. View index: The zero-based index of the View
in its parent View. If it is the only child, this is
0.
54. Using lint to Optimize Your UI
• The Android lint tool lets you analyze the XML
files that define your application's UI to find
inefficiencies in the view hierarchy.
• Note: The Android layoutopt tool has been
replaced by the lint tool beginning in ADT and
SDK Tools revision 16. The lint tool reports UI
layout performance issues in a similar way
as layoutopt, and detects additional problems.
55. Using lint to Optimize Your UI
• Improving Your Code with lint
• The Android SDK provides a code scanning
tool called lint that can help you to easily
identify and correct problems with the
structural quality of your code, without having
to execute the app or write any test cases.
56. Using lint to Optimize Your UI
• The lint tool checks your Android project
source files for potential bugs and
optimization improvements for correctness,
security, performance, usability, accessibility,
and internationalization.
• You can run lint from the command-line or
from the Eclipse environment.
57. Running lint from Eclipse
If the ADT Plugin is installed in your Eclipse
environment, the lint tool runs automatically
when you perform one of these actions:
Export an APK
Edit and save an XML source file in your
Android project (such as a manifest or layout
file)
Use the layout editor in Eclipse to make
changes
58. Running lint from the Command-Line
• To run lint against a list of files in a project
directory:
int [flags] <project directory>
lint --check MissingPrefix myproject
59. Configuring lint
You can configure lint checking at different
levels:
Globally, for all projects
Per project
Per file
Per Java class or method (by using
the @SuppressLint annotation), or per XML
element (by using the tools:ignoreattribute.
60. Configuring lint in Eclipse
You can configure global, project-specific, and
file-specific settings for lint from the Eclipse user
interface.
61. Global preferences
• Open Window > Preferences > Android > Lint
Error Checking.
• Specify your preferences and click OK.
62. Project and file-specific preferences
• Run the lint tool on your project by right-
clicking on your project folder in the Package
Explorer and selecting Android Tools > Run
Lint: Check for Common Errors.
• From the Lint Warnings view, use the toolbar
options to configure lint preferences for
individual projects and files in Eclipse.
63. Project and file-specific preferences
The options you can select include:
• Suppress this error with an annotation/attribute - If the
issue appears in a Java class, the lint tool adds
a@SuppressLint annotation to the method where the issue
was detected. If the issue appears in an .xml file, lintinserts
a tools:ignore attribute to disable checking for the lint issue
in this file.
• Ignore in this file - Disables checking for this lint issue in
this file.
• Ignore in this project - Disables checking for this lint issue
in this project.
• Always ignore - Disables checking for this lint issue globally
for all projects.
64. Configuring the lint file
You can specify your lint checking preferences
in the lint.xml file.
If you are creating this file manually, place it
in the root directory of your Android project.
If you are configuring lint preferences in
Eclipse, the lint.xml file is automatically
created and added to your Android project for
you.
65. Sample lint.xml file
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the given check in this project -->
<issue id="IconMissingDensityFolder" severity="ignore" />
<!-- Ignore the ObsoleteLayoutParam issue in the specified files -->
<issue id="ObsoleteLayoutParam">
<ignore path="res/layout/activation.xml" />
<ignore path="res/layout-xlarge/activation.xml" />
</issue>
<!-- Ignore the UselessLeaf issue in the specified file -->
<issue id="UselessLeaf">
<ignore path="res/layout/main.xml" />
</issue>
<!-- Change the severity of hardcoded strings to "error" -->
<issue id="HardcodedText" severity="error" />
</lint>
66. Event Propagation and Event Handling
in Views
For each application, a ViewRootImpl object is
created to handle communications with the
remote system WindowManagerService object.
The communication is through a Linux pipe which
is encapsulated in an InputChannel object
(mInputChannel field in class ViewRootImpl).
TheViewRootImpl object also registers an
instance of InputEventReceiver when the
first View object is registered with it.
67. Event Propagation and Event Handling
in Views
public void setView(View view, ...) {
...
mInputEventReceiver = new WindowInputEventReceiver(mInputChannel,
Looper.myLooper());
...
}
The constructor of
class WindowInputEventReceiver (class WindowManagerService extends
from classInputEventReceiver) calls a native methond nativeInit(...):
69. Event Propagation and Event Handling
in Views
Three parameters are passed to the native function nativeInit:
1) The receiver object itself;
2) TheInputChannel object passed from the ViewRootImpl object.
3) The main message queue (an object of class MessageQueue) of the
application.
71. Event Propagation and Event Handling
in Views
Included in the event listener interfaces are the
following callback methods:-
onClick()
onLongClick()
onFocusChange()
onKey()
onTouch()
onCreateContextMenu()
72. Event Propagation and Event Handling
in Views
Included in the event listener interfaces are the
following callback methods:-
onClick()
onLongClick()
onFocusChange()
onKey()
onTouch()
onCreateContextMenu()
76. • An android application can run on many
devices in many different regions.
• In order to make your application more
interactive, your application should handle
text,numbers,files e.t.c in ways appropriate to
the locales where your application will be
used.
77. Localizing Strings
• In order to localize the strings used in your
application , make a new folder under res with
name ofvalues-local where local would be the
replaced with the region.
• For example, in the case of italy, the values-
it folder would be made under res. It is shown
in the image below:
79. Localizing Strings
• Once that folder is made, copy
the strings.xmlfrom default folder to the
folder you have created. And change its
contents. For example, i have changed the
value of hello_world string.