Android-BluetoothImagePro

advertisement
Blutooth Image Pro – Android Application
UNIVERSITY NAME
Project Title:
Blutooth Image Pro – Android Application
Prepared by:
Student ID:
Supervisor Name:
Course:
1
Blutooth Image Pro – Android Application
INDIVIDUAL PROJECT DECLARATION
I hereby declare that, the following project and prepared report on
“Android – Bluetooth Image Pro Application” which is being handed
as part of completion of <Specify Course> has been thought out,
designed and implemented by me. The technological innovation that
the application brings in is innovative and any material used has been
referenced.
I am also aware that cheating and plagiarism is a breach of University
regulations and will be dealt with accordingly.
Signed: ...............................
Date: 14 / 01 / 2011
2
Blutooth Image Pro – Android Application
ACKNOWLEDGMENT
To begin with I would like to thank Allah, it was due to his divine help
that this project has been completed successfully.
Furthermore, I express my gratitude towards my project tutor <Give
Name of Tutor>, who has in every way helped me to succeed and mentored
me where ever I was lacking.
Finally; I am grateful to my friends who have always shared a helping
hand to me whenever I needed it most.
<Student Name>
3
Blutooth Image Pro – Android Application
A BSTRACT
Android is a new technology which consists of a software stack
encompassing a Linux kernel based operating system and other
utility applications.[2]
The open source nature of the system invites more and more
application developers to create innovative applications for the
device. The “Bluetooth Image Pro“ application is focused to
provide a complete Bluetooth Image Sharing solution on
Android devices. Leverage the Device hardware like Camera to
view preview, take images and share it with other devices.
Allow user to share images with not only other “Android”
powered devices but will any operating system that is running
on a device with Bluetooth capabilities. Provide user with a
easy and user friendly navigation system in the form of a
Tabbed User Interface. Provide a easy to view image gallery to
the user, which can facilitate the user to scroll through the
available images and send them to other Bluetooth powered
devices. The application Tabbed user interface would
encapsulates three primary modules - Home Page: The home
page displays the splash screen of the application. Camera
Page: This page facilitates the user to preview the camera view
of the device in landscape mode and allows the user to take a
snapshot of the camera preview. The user also has the option to
view the last clicked image and to send it to other device.
Gallery Page: The image gallery page shows a gallery view of
the application, which allows the user to scroll through the
available images and then send them via Bluetooth to other
Bluetooth enabled devices.
4
Blutooth Image Pro – Android Application
INDEX
ABS TR AC T ........................................................................................................................................... 4
C HA PT ER 1 – IN TR O DU CTI ON .................................................................................................... 7
1.1
A N D R O I D ................................................................................................................................. 7
C HA PT ER 2 – L I TE R A T UR E R EV IE W ...................................................................................... 10
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
A N D R O I D S O F T W A R E D E V E L O P M E N T ................................................................................ 10
A N D R O I D A P P L I C A T I O N F U N D A M E N T A L S : ....................................................................... 12
A P P L I C A T I O N C O M P O N E N T S .............................................................................................. 13
P R O C E S S E S A N D T H R E A D S .................................................................................................. 18
P R O C E S S E S A N D L I F E C Y C L E S .................................................................................................. 29
U S E R I N T E R F A C E ...................................................................................................................... 33
U S I N G T H E C A M E R A ................................................................................................................. 36
U S I N G T H E B L U E T O O T H .......................................................................................................... 38
U S E R I N T E R F A C E C O N T R O L S U S E D ....................................................................................... 38
C HA PT ER 3 – A P PL ICA TI ON DE SI GN A N D I MP L EMEN TA TI ON ................................... 43
3.1
F EAT UR E S .............................................................................................................................. 43
3.2
SO F T W AR E DE SI GN ............................................................................................................ 43
3.2 .1
USA BIL I T Y F L O W S .......................................................................................................... 44
3.2 .1 .1
M O DUL E L A Y OU T H IER AR CH Y .............................................................................. 44
3.2 .1 .2
CAM ER A PR O M O DUL E .............................................................................................. 45
3.2 .1 .3
VIE W C AM ER A I M AG E MO DUL E ............................................................................ 46
3.2 .1 .4
SEN D C AM ER A IM AG E MO DUL E ............................................................................ 47
3.2 .1 .5
IM AGE G AL L ER Y M OD U L E ....................................................................................... 48
3.3
COD E DE SIG N ........................................................................................................................ 49
3.3 .1
M O DUL E L A Y OU T H IER AR CH Y .................................................................................. 49
3.3 .2
CAM ER A PR O M O DUL E .................................................................................................. 49
3.3 .3
VIE W C AM ER A I M AG E M O DUL E ................................................................................ 50
3.3 .4
SEN D C AM ER A IM AG E M O DUL E ................................................................................ 50
3.4
USA GE S TE PS ........................................................................................................................ 51
CH AP T E R 4 – C ON C LUSI ON AN D FUT U R E W OR K ...................................................... 56
REF ER E NC ES .................................................................................................................................... 59
5
Blutooth Image Pro – Android Application
AP PE N D IX : ........................................................................................................................................ 60
SOU RC E C O D E .................................................................................................................................. 60
Index of Figures
Figure
No.
1
2
3
4
5
6
7
8
Figure Summary
Android Service Model
Activity Lifecycle
View Group
Module Layout Hierarchy
Camera Pro Module
Activity Lifecycle
Send Camera Module
Image Gallery Module
Page
Number
22
28
34
44
45
46
47
48
6
Blutooth Image Pro – Android Application
C HAPTER 1 – I NTRODUCTION
1.1
A NDROID
Android in its core sense is a versatile set of software components for
mobile computing devices. It primarily consists of the below software
stack:

Core mobile applications

Middleware featured software components

The primary Android Operation System.
Android systems and softwares were bought by Google in the year of
2005. In its core, the operating system is built upon the Linux kernel. In
the java programming language android application are written. The
java code is compiled- along with any resource file that is required by
any application- that is grouped by the apt tool into a package of
android, where the file of archive is marked by .apk suffix. The
installation is done on the mobile where the file is on the vehicle used
for distribution of the application, where the files are downloaded to
the devices. One of the applications is consider that is in a single .apk
file where all codes are single. [1]
Why Android:
To begin with when Android was launched, the budding relevancies
for the Android proposal had a blend of different feedbacks. The
alluded issues were having the points referring to the lack of records,
inadequate communication, problem of virus and no relevance for
public. Though there were many statements given against the viability
of the functionality of the Android system, the applications aiming at
the use of this platform had started to spread its roots after the very
first week of its declaration. The Snake Game was the first piece of
7
Blutooth Image Pro – Android Application
application for the general public. Another device was developed for
the advanced users such as Android Dev Phone, which was a SIM and
hardware, unlocked. Some developer’s desired unlocked devices or
the users of the advanced applications instead of the retail priced
regular customer devices to try and apply their relevance. [3]
Android development tools
The Android development tools is the android software development
kit that includes enhancement tools those is comprehensive. Debugger
is included, libraries, emulator for handsets, documentation, tutorials
as well as sample codes. At the present development platforms have
computers running LUNIX (Linux distribution is on any modern
desktop), Mac OS X 10.4.9 either later, Windows XP either alter. The
IDE which is acronym of supported integration development
environment is Eclipse that is 3.4 or 3.5 that is used by the Android
development tools (ADT) plug in, the edit of java is done by any text
editor through developers as well as XML files can use command line
techniques (java development kit as well as apache Ant those are
required) for the creation, built as well as android application are
debug in addition with the android devices those are controlled (for
instance reboot is triggered , software packages are installed remotely).
[3]
Proposed Application Software:
The “Bluetooth Image Pro“ application is focused to provide a
complete Bluetooth Image Sharing solution on Android
devices. Leverage the Device hardware like Camera to view
preview, take images and share it with other devices. Allow
8
Blutooth Image Pro – Android Application
user to share images with not only other “Android” powered
devices but will any operating system that is running on a
device with Bluetooth capabilities. Provide user with a easy
and user friendly navigation system in the form of a Tabbed
User Interface. Provide a easy to view image gallery to the user,
which can facilitate the user to scroll through the available
images and send them to other Bluetooth powered devices.
The application Tabbed user interface would encapsulates three
primary modules - Home Page: The home page displays the
splash screen of the application. Camera Page: This page
facilitates the user to preview the camera view of the device in
landscape mode and allows the user to take a snapshot of the
camera preview.
The user will also have the option to view the last clicked image
and to send it to other device. Gallery Page: The image gallery
page shows a gallery view of the application, which allows the
user to scroll through the available images and then send them
via Bluetooth to other Bluetooth enabled devices.
9
Blutooth Image Pro – Android Application
C HAPTER 2 – L ITERATURE REVIEW
2.1 A NDROID S OFTWARE DEVELOPMENT
The budding relevancies for the Android proposal earlier had a
blend of different feedbacks. The alluded issues were having the
points referring to the lack of records, inadequate
communication, problem of virus and no relevance for public.
Though there were many statements given against the viability
of the functionality of the Android system, the applications
aiming at the use of this platform had started to spread its roots
after the very first week of its declaration. The Snake Game was
the first piece of application for the general public. Another
device was developed for the advanced users such as Android
Dev Phone, which was a SIM and hardware, unlocked. Some
developer’s desired unlocked devices or the users of the
advanced applications instead of the retail priced regular
customer devices to try and apply their relevance.[1]
Software development kit
SDK is the android software development kit that includes
enhancement tools those is comprehensive. Debugger is
included, libraries, emulator for handsets (QEMU based),
documentation, tutorials as well as sample codes. At the present
development platforms have computers running LUNIX (Linux
distribution is on any modern desktop), Mac OS X 10.4.9 either
later, Windows XP either alter. The IDE which is acronym of
supported integration development environment is Eclipse that
is 3.4 or 3.5 that is used by the Android development tools
(ADT) plug in, the edit of java is done by any text editor through
developers as well as XML files can use command line
10
Blutooth Image Pro – Android Application
techniques (java development kit as well as apache Ant those
are required) for the creation, built as well as android
application are debug in addition with the android devices
those are controlled (for instance reboot is triggered , software
packages are installed remotely).[1]
12th November 2007 the preview release of android SDK have
taken place. The android developer challenged announced that
there would be new release of SDK that is available in private in
download area as through email that was sent accidentally by
the android developer challenge team on 15th July 2008. The
email was focused towards the winners of the android
developer challengers in first round. The exposure of Google
was for supplying new SDK that had released to few developers
as well as not others (where this arrangement was kept
privately) that have led to wide reported frustrations at the time
by the android developer community. [6]
The released of android 0.9 SDK beta took lace on 18th august
2008. The API was extended as well as extended when the
release was provided; the home screen was designed as well as
developed. The availability of detailed instruction is there for
those who are already working with the earlier releases.
Android 1.0 was released on 23 September 2008 SDK. Many bug
fixes were released at the time of release although the addition
of certain similar features has taken place. API changes have
also taken from the place 0.9 versions, since there was a release
for many multiple versions.
The android SDK goes hand in hand with the overall android
platform enhancement of Android SDK. Androids older version
is also supported by SDK if the developers wish to make a target
to the applications those are based on the older versions.
Downloadable components are development tools, for
11
Blutooth Image Pro – Android Application
compatibility testing older versions can also be downloaded if
the user has downloaded the newer version also. [6]
In .apk format the android applications are packaged as well as
stored under/data/app folder that is in android OS (for security
reasons only the folder is accessible to root) .dex files are
consisted in APK package (that is compiled byte code files that
is called as Dalvik executable), other resource files are also
available. [6]
2.2 A NDROID A PPLICATION F UNDAMENTALS :
In the java programming language android application are
written. The java code is compiled- along with any resource file
that is required by any application- that is grouped by the apt
tool into a package of android, where the file of archive is
marked by .apk suffix. The installation is done on the mobile
where the file is on the vehicle used for distribution of the
application, where the files are downloaded to the devices. One
of the applications is consider that is in a single .apk file where
all codes are single. [9]
The android application lives in its own world by many ways such as:

Linux process runs its own application by default. When the
applications code needs to be executed the process gets started
automatically by android, as well as its shut down when it is not
needed for so long where the requirement of system is needed by other
applications.

Virtual machine is consisted by each process, from the code of all other
applications code runs in isolation that is free from code.
12
Blutooth Image Pro – Android Application

A unique Linux user Id is assigned by each application. The
applications file are set visible permissions of all set users are set
whereby only to the single applications. Although there are many
ways to export to other applications.
The sharing of same two users ID is it possible to arrange, that’s is the
case where they will be able to see at each other’s file. For the
conservation of system resources, that is with the application of same
ID that can be used to run same LINUX process where same VM is
shared. [9]
2.3 A PPLICATION C OMPONENTS
Here we are talking about the essential aspect of Android. This is the
one such single application, which can make use of fundamental of
some other applications (provided those applications permit it). To
understand it in a better way, we take up an illustration, if your
application wants to exhibit a scrolling list of images and some other
application has already developed appropriate scroller and had made
accessible to others then one can make use of that scroller to do the job,
instead of creating for your self. Your application does not include the
rules and regulations of the other application and the other things,
which are related to it. When there is a necessity, the part of the other
application just starts up.[7]
For this to work, the system should be required to begin an application
procedure when any part of it is wanted and instantiate the Java
objects for that part. Different applications on many of the other system
have single entry, Android application do not have a particular entry
point for everything in the application (no main () function, for
example). The system has all the vital elements that the system can
instantiate and run as required. There are four types of components.
13
Blutooth Image Pro – Android Application
Activities
With the help of an activity a visual client can be presented with
interface for the one single effort, which the user had undertaken. For
example, an activity which demonstrate the current list of menu items
the client can choose anything from it or if one wants to exhibit
photographs by the side of their captions. There is an other activity in
this applications which is known as text messaging application, which
displays the record of associates which is require to send the message,
next activity to write the note to the selected contact and the additional
activities to figure out previous messages or to alter the settings. All
these activity work jointly to form a consistent user interface, every
activity is self-sufficient of the other. Activity act as a foundation class
and each one is implemented as the sub class of the activity.
An application may be having only single activity or may be it include
quite a lot of number of activities which are mentioned un the text
messaging application. But to know what are the activities and how
many there is it depends upon the applications and its blueprint. On
an average the activities, which have been clearly marked as first,
should be the first one to be offered to the client when the application
first come into existence. Moving from individual activity to another
is consummate by having the existing activity begins the next one.[7]
Each and every activity is given a window to illustrate by default.
Usually the window fills the monitor, however it may be lesser than
the screen and hang on the top of the additional window. This can be
better understand with the help of this illustration-when a pop –up
dialog box appears in the middle of the activity demanding a user
reaction or a window that presents the client with the essential
information when they opt for particular entry on screen.
14
Blutooth Image Pro – Android Application
The visual substance of the window is made available by the chain of
commands objects derived from the base View class. A particular
rectangular space within the window is examined. Parent view
includes and manages the plan of their children. Leaf views (those at
the base of the ladder) copy in the rectangles they manage and wants
the user to take the action needed to be taken at that time. Therefore we
can say views are there where the activity dealings take place with the
clients.
For example, a sight may be exhibit a tiny icon and may commence a
deed as soon as the user taps that particular image. Android had many
number of handy views, which one can use. This includes buttons, text
fields, scroll bars, menu items, check boxes, and more.
A view hierarchy is positioned inside an activity window by the
Activity. setContent View() method. The content outlook is the View
object at the base of the hierarchy.(See the separate User Interface
document for more information on views and the hierarchy.) [7]
Services
In the case of services, it doesn’t have a image to interact with the user,
however it runs in the backdrop for an imprecise phase of time .For
better understanding we had an example a service may play
background music when the client is busy in attending the
supplementary matters or it may obtain statistics over the system or to
evaluate something and to make available the result to the activities
that require it. Each service extends the Service base class. [10]
A media player playing songs from a play list is one of the key
example .The media player has the facilities that allow the user to
select the songs and start playing them. On the other hand, the music
playback itself would not be handled by an activity for the reason that
15
Blutooth Image Pro – Android Application
the user will be looking forward that the music should be continues
even after the user had left the media player and start doing something
else. In order to keep the music in a continuous mode, the media player
activity might begin a service to run in the backdrop. After this, the
system will be in a position to keep the music playback operational
even after the activity is going on it leaves the screen.
It is likely to be possible to attach to an continuing service (and to begin
the service if it is not in the running mode previously) One can also
converse with the service through an interaction that the services
exposé, at the same time you are linked to it. This interaction permits
the user to use music services such as pause, rewind, forward, stop and
again the playback.
Services run in the major line of the application procedure, resembling
the actions and the additional components, so that they won’t obstruct
the any other components for the user interaction, they frequently
produce an extra line of prolonged everyday jobs. (Like music
playback) See Processes and Threads, later. [10]
Broadcast receivers.
As the term suggests, broadcast receiver is such a component that has
nothing to do but only to obtain and respond to broadcasts
announcement. Numerous number of broadcasts start off in the system
code –for example announcements that the battery is low, that there is
a change in the time zone, language has been altered according to the
user choice, and the image has been taken. With the help of the
applications we can also commence the broadcasts- for instance let the
further applications come to know that the various facts has been
download to the device and is accessible to others to use.[10]
16
Blutooth Image Pro – Android Application
An application is capable of having much number of broadcasts
receiver and to react to that announcement which it considers to be the
most important. All receivers extend the Broadcasts Receiver base
class.
Broadcasts receivers do not exhibit a user interaction. On the other
hand they may begin an activity in response to information, which
they obtain, or they might use the Notification Manager to aware the
user. Notifications can get the user awareness in various conducts such
as blinking the backlight, playing the sound, vibrating the device. In
general they place constant symbol in the status bar, which the client
can unlock to get the message. [10]
Content providers
With the help of the content provider a certain set of application facts is
made accessible to further new applications. The facts can be stored in
the file system, in an SQLite database, or in any other way that makes a
logic .The content provider extends the Content Provider base class to
put into practice a regular set of methods that facilitates the other
applications to regain and store data of the type it controls. These
methods are not openly called by the applications. Instead of this they
make use of Content Resolver object and identify its methods. With the
help of the Content Resolver one can communicate to the content
provider, with its help the provider is able to supervise any course of
action and communication that is involved. [11]
See the separate Content Providers document for more
information on using content providers.
17
Blutooth Image Pro – Android Application
See the separate Content Providers document for more information on
using content providers. [11]
2.4 P ROCESSES AND T HREADS
At the initial stage when relevance constituent have to be process,
Android initiate a Linux method which is meant for this to run by the
means of particular line of implementation. But by error, each and
every module of the appliance run in that method and line.
On the other hand, one is also able to organize the module to run in
some further procedure and you can generate supplementary thread
for any process.[3]
Processes
Wherever a noticeable file restricts a module run is known as process.
The
component
ingredients
of
this
process
are
<activity>,
<service>,<receiver> and <provider>- every element of the method
have some characteristic which can identify a process and anywhere
that part should be run. The quality are to be positioned in such a
manner that each part runs in its very particular process, therefore a
few section contribute to the process whereas the other do not. The
parts are located in such a way that the elements of dissimilar
application run in the similar process- apart from that the application
share the similar Linux user ID and are marked by the similar power
.A default value is pertained by all the parts as the <application aspect
too has a procedure trait.[3]
Each and every one part is situated in the major line of definite
method, and the structure describes the element and sends out from
that thread. Threads are not split up for every illustration. As a result
18
Blutooth Image Pro – Android Application
procedures that take actions according to the label process like
View.onKeyDown() that gives you the user information and action
and the cycle of life notice are talk about afterwards in the Component
Lifecycles section- which constantly run in the key thread of the
procedure. This imply that no section is supposed to be execute
extended or create hurdles in the procedure (like system operations or
calculation loops) whenever identify by the system, because this will
also obstruct the several parts in the process. You can also produce
unlike threads for lengthy maneuver and this has been talked later
under Threads. [4]
Android makes a decision when to close down a process at any point.
This is mainly done when there is short memory and is in need by
some further process that is right away
helping the client. Function
section that are running in the course of action thus devastated. A
method has to resume for the section at that time when the work comes
again.
Android consider several times when it comes to the conclusion of the
process and its virtual significance to the client .For instance, it will
eagerly close the procedure along with the movement and that they are
not able see them on the monitor than a procedure with noticeable
action .As a result, the termination of the process is based on the
condition of the modules running in that process. Those circumstances
are the matter of the later segment, Component Lifecycles. [4]
Threads
However one might bind the procedure to a particular process but
probably there may be situation arises when one would like to produce
additional thread to do several backdrop efforts. The client interaction
should be rapid to react to the user procedures. The threads are
permitted to undertake an action so it is not allowed to carry out
19
Blutooth Image Pro – Android Application
actions that consumed more time such as operations like network
downloads. Separate threads are allocated to complete the pending
tasks as early as possible.
Threads are generally generated in a certain set of laws using typical
Java Thread objects. A number of ease lessons are granted by Android
for organizing the threads. Looper is used to process a communication
loop inside a thread; Handler is responsible for dispensation messages,
and the Handler Thread for creating a thread by the side of message
loop. [4]
Remote procedure calls
Android designed a trivial system for remote procedure calls (RPCs).
This process is identifying as near by, but this is accomplished
distantly (in some other procedure), and any outcome is come back to
the caller. This require decomposed the system call and its entire aide
facts to the point where the working structure can able to recognize,
broadcast it from the confined process and make available space to the
distant process and address space and reconstruct and renovate the call
there. Android make available the rules and regulations to execute that
work, as a result one is able to focus on crucial and put into practice the
RPC interaction itself.
Just procedures are incorporated by RPC interaction. By error the
entire process are implemented simultaneously (unless and until the
distant procedure ends, it obstructs the narrow procedures), yet there
is no return worth.[12]
In concise, the system performs its task as follow: you commence by
announce the RPC interaction you need to execute with the help of the
uncomplicated IDL (interface definition language). As soon as the
announcement was made the helping instrument produce a Java
20
Blutooth Image Pro – Android Application
interface definition in such a manner that it should be accessible to
both process: -nearly and distantly. It consists of two central classes, as
shown in the following diagram:
The central course consist of each and every policy that is required to
manage the distant process calls for the purpose of interaction which
the one you announced with the IDL. Together central program
execute the IBinder interaction. This can be utilized locally and inside
by the system one cannot overlook the inscribed rules and regulations.
The further known as Stub widen the Binder class. In count to inner
rules and regulations for effectuate the RPC interaction you
announced. You may be in need to subclass Stub to execute that
process, as shown in the diagram.
Normally, the distant procedure would be organized by a service (as a
service can update the scheme regarding the procedure and its link ups
to further methods) This would be having together the interaction file
produced by the helping instrument and the associate class executing
the RPC system. The interaction file, which is produced through
helping instrument, is available to the customers of the service.
This is how the link is established among the service and the customer:
Service
customer
on
the
local
side
would
execute
on
ServiceConnected() and onServiceDisconnected()procedures as a result
they can be informed as soon as a link to the distant service is
successfully recognized ,as well as when it go off. This is then followed
by the call to bindService()to locate up the connection.
The facilities which are provided by onBind() technique is that it would
either acknowledge or refuse the connection which is based on the
objective it receives (the intent exceed to bindService()).If the
21
Blutooth Image Pro – Android Application
correlation is established ,it
will go back to the case of the Stub
associate class. [5]
Figure 1: Android Service Model
If the service acknowledge the correlation, Android express the
customer onServiceConnected() procedure and bypass it an IBinder
objective, a substitute designed for the Stub subclass control by the
service. With the help of the alternative customer is able formulate the
calls on the distant service.
This short explanation does not include all the aspect of the RPC
machinery. For further details see designing a Remote Interface Using
AIDL and the IBinder class description. [5]
Thread-safe methods
In hardly any background, the procedure you execute might be called
from more threads and hence it must be printed to be thread –safe.
22
Blutooth Image Pro – Android Application
This is first and foremost exact for the procedures, which is known to
be remotely when we have talk about the RPC machinery in the earlier
part. Once a call on a procedure is executed in an IBinder thing creates
in a similar method as the IBinder, the procedure is accomplished in
the caller’s thread. On the other hand when the call begin in some
different system, the procedure is implemented in a thread selected
from a group of threads that Android preserve in the similar course as
the IBinder; it is not carry out in the major thread of the procedure .For
instance a service provided on Bind() technique would be originated
from the major thread of the service system, procedures executed in
that article onBind() returns(for instance ,a Stub subclass that executes
RPC system) will be generated from the group of threads. The services
is capable of having more than one user, more than one group thread
that can connect the similar IBinder process at similar time. Hence,
IBinder technique should be executed to be threading safe.
In a same way, a content source is capable of accepting the facts
requirements that initiated in further processes. Even though the
Content Resolver and ContentProvider classes conceal the facts of how
the inter process contact is handled. ContentProvider technique reply
to the following call:-query(),insert(),delete(),update(),and getType()are called from a group of threads in the substance contributor
system,not the major thread of the procedure. As these procedures
might be bring into being from several threads at the similar time ,
moreover they should be executed to be thread-safe. [9]
COMPONENT LIFECYCLE
Every component of the process like the activity, the service or the
broadcast receiver has a life cycle with a starting point to an end
destination or from the stage of its activation to the stage where it
becomes inactive.
23
Blutooth Image Pro – Android Application
Activity lifecycle
Android is designed around the unique requirements of mobile
applications. In particular, Android recognizes that resources (memory
and battery, for example) are limited on most mobile devices, and
provides mechanisms to conserve those resources. The mechanisms are
evident in the Android Activity Lifecycle, which defines the states or
events that an activity goes through from the time it is created until it
finishes running. The lifecycle is shown diagrammatically in the
following Figure [9]
Your activity monitors and reacts to these events by instantiating
methods that override the Activity class methods for each event:
On Create—it is the state when your activity is first created. This is the
place you normally create your views, open any persistent data files
your activity needs to use, and in general initialize your activity. When
calling on Create, the Android framework is passed a Bundle object
that contains any activity state saved from when the activity ran before.
On Start—this is just before your activity becomes visible on the
screen. Once on Start completes, if your activity can become the
foreground activity on the screen, control will transfer to on Resume. If
the activity cannot become the foreground activity for some reason,
control transfers to the on Stop method.
On Resume – it is right after on Start if your activity is the foreground
activity on the screen. At this point your activity is running and
interacting with the user. You are receiving keyboard and touch inputs,
and the screen is displaying your user interface. On Resume is also
called if your activity loses the foreground to another activity, and that
activity eventually exits, popping your activity back to the foreground.
This is where your activity would start (or resume) doing things that
24
Blutooth Image Pro – Android Application
are needed to update the user interface (receiving location updates or
running an animation, for example).
On Pause-- Called when Android is just about to resume a different
activity, giving that activity the foreground. At this point your activity
will no longer have access to the screen, so you should stop doing
things that consume battery and CPU cycles unnecessarily. If you are
running an animation, no one is going to be able to see it, so you might
as well suspend it until you get the screen back. Your activity needs to
take advantage of this method to store any state that you will need in
case your activity gains the foreground again—and it is not guaranteed
that your activity will resume. If the mobile device you are running on
runs out of memory, there is no virtual memory on disk to use for
expansion, so your activity may have to make way for a system process
that needs memory. Once you exit this method, Android may kill your
activity at any time without returning control to you.
On Stop—it is when your activity is no longer visible, either because
another activity has taken the foreground or because your activity is
being destroyed.
On Destroy-- The last chance for your activity to do any processing
before it is destroyed. Normally you'd get to this point because the
activity is done and the framework called its finish method. But as
mentioned earlier, the method might be called because Android has
decided it needs the resources your activity is consuming.
It is important to take advantage of these methods to provide the best
user experience possible. This is the first place in this book we've
discussed how programming for mobile devices is different from
programming for desktop devices, and there will be many more such
25
Blutooth Image Pro – Android Application
places as you go through later chapters. Your users will appreciate it if
you write your activities with the activity lifecycle in mind, and you
will ultimately benefit.
void
onCreate(Bundle
savedInstanceState)
void
onStart()
void
onRestart()
void
onResume()
void
onPause()
void
onStop()
void onDestroy()
When the sate changes appropriate work can be done with all the methods
those are hooked where user can override. oncreate must implement all
activities for the initial setup when the insatiate of first setup is done. on
pause will also do implementations where data changes take place as well
as interaction will be stopped with the users.
Calling into the Super class
Super class version should be first call for any implementation of activity
lifecycle technique, for instance
Protected void onPause() {
super.onPause();
...
}
These seven methods will describe the lifecycle of an entire activity. By
implementation of them three nested loops can be easily monitored
26
Blutooth Image Pro – Android Application
When the first call to oncreate() all the way through to a single final cal to s
destroy is the entire lifetime of an activity that actually happens. state in
oncreate is conducted by activity at its initial setup of “global” and on
destroy holds all the released remaining of resources. For instance when
the data has to be downloaded from the network the thread is running in
the background, the creation of thread oncreate() may take place as well as
it may stop the thread in onDestry().
27
Blutooth Image Pro – Android Application
Figure 2: Activity Lifecycle
The visibility of lifetime is based on the activity that actually takes pace
among a call to onstart() until and unless it is communicated call to
onStop(). The user can see the activity on screen during this time. Two
resources between those two methods can maintain the activity to the
users, as that is required to be shown to the users. For instance in order to
28
Blutooth Image Pro – Android Application
monitor for changes that can impact your UI registration of Broadcast
receiver in OnStart(), when the displaying cannot be seen unregistration
by the users() can take place, as the activity is entirely abed on the
visisbility as well as hidden of the users. [11]
As the forefront lifeteime of an movement takes place among the call to
onResume() until and unless a communicate is done to a call onPause(). The
interaction with the users takes place during this time as the functioning is in
front of so many activities. Between the resumed as well as paused state an
activity can make a transition- for instance, onpause() is known as when the
device gets sleep either when the start of new activity takes place. When the
new intent is delivered as well as activity when have a result of on Resume ().
The lightweight of the codes in these two methods should take place.
The paths an activity may take place among states, which can be explained by
the following diagram that has been illustrated below: the activity can be in is
in the oval colored shapes states. The callback method is represented by the
square rectangles where the implementation of performance activity
transition among states takes place.
Whenever any particular components handle a request, the component is
running properly is insured by android, if it is necessary it needs to be started
as well as with an appropriate component is available of an instance, if it is
necessary instance is created. [11].
2.5 P ROCESSES
AND LIFECYC LES
For as long as possible android system tries to maintain an procedure of
application, when memory runs low it need to remove all the old
procedures. In order to determine which processes to kill and which to
keep, into an “importance hierarchy” each process is kept by android
29
Blutooth Image Pro – Android Application
based on the sate of a component and what they are based. Elimination of
first takes place with processes of low importance, and after that the
lowest ones and keeps on moving so on. Hierarchy has five levels. In order
of importance following list will present them in an order. [2]
1. What is the user is currently doing is required by foreground
processes. If any of the following conditions hold process is need to be
considered to be the foreground:

The user is interacting with the service the hosts are bound with
them.

The execution of On Recieve() method is on the broadcast
receivers.

The user is interacting is the running of the activity (on resume
() is the activity of the object technique has been called)

On its lifecycle callbacks the service objects are executed
(oncreate(), onstart() either ondestroy())
At any given time only few foreground procedure will exists. Only as a
last resort they are killed – they cannot all continue to run if the memory is
so low. Generally, at the given point, memory-paging state is through
which the device has reached, in order to keep the user interface
responsive there is a requirement of killing the foreground processes. [1]
2. Any foreground component cannot ne found in a visible process, what
the users sees on the screen can still be affected. If either of the
following conditions is holding a procedure is said to controlled:

The activity that is not in the foreground is hosted, the users can
still have the visibility of it (the method has been called as
onpause() ). For instance this may occur is the activity of
foreground is a dialogue if the previous activity is been seen
behind.
30
Blutooth Image Pro – Android Application

A bound to a visible activity is when the service is hosted.
The visible process will not be killed and is considered to be the extremely
important unless all the foreground is need to be runner by the
foreground process.
3. When the service is not fall into any of the two higher categorizes they
are the service processes those are run by a service those have been
started with the start service () technique. Anything the users see are
not directly tied with the service processes, they generally carries
things about which the users cares about (in the background mp3 is
played either through downloading data on the network), the running
takes place in the system until and unless there is not enough memory
for the retaining of that is along with either foreground along with the
visibility of processes.
4. The activity that is not currently visible to the user is a background
process ( onstop() method is the activity objects that has been called ).
On the user experience these processes have no direct impact, to
reclaim memory for a foreground they can be killed at any point of
time, services or visible processes. There are many process related to
background are running, in a LRU so that they can be kept (recently
used least) it is the list of process to ensure that the last is to be killed
by the users of the activity that has been recently seen. If the correctly
lifecycles methods activity are implemented as well as capturing of
current state is done, on the user experience killing of process will
never have a harmful effect. [12]
31
Blutooth Image Pro – Android Application
Any active application is not hold in any empty process. The basic reason
to keep such a procedure around is to have a cache in order to improve the
startup time the next time where a run will take place next time. In order
to balance overall system the system can kill the processes the resources
are among procedures caches as well as the underlying caches of kernel.
It can rank the android at the most highest level, on the currently active
process they are based upon. For instance when a process hosts a visibility
activity and a service, the rank will be given as a visible process not a
service process.
As the other process is dependent so the process ranking have the
possibility to get increased rank. Never ranking can be done of a process
that is served by another process low than the ranked that is been served.
For instance a process B client is served by process of Service A of a
content provider, or if the component of a process of B is bound by process
A, it will be always given less importance as compared with Process B.
Background activity is ranked lower as compared with the process running
service, an activity that can initiate a long run operations have the tendency to
do well for that operation service can be started, spawn of thread is not
allowed – the outlast of the activity is particularly takes place. For instance
playing background music as well as uploading of images captured from the
camera to a particular web site. Usage of the services those will have a
guarantee about the operations that will have at least priority of service
providing, irrespective of the fact that what all happens to the activity. As
lifecycle receiver section that has taken place earlier, time consuming
operations should not be used rather they should make use of broadcast of
receiver where services can be employed. [12]
32
Blutooth Image Pro – Android Application
2.6 U SER I NTERFACE
With the usage of view and view object group user interface is built in
an android application. There are many categories of view as well as
view groups such as each are descendants of the view class.
On the android platform view objects are the basic units of interfaces
expressions. Widgets are served to the base of subclasses of view class;
UI objects are fully implemented on them. Layouts are the view groups
those serve the bases of subclasses that makes offering of distinctive
categories of layout architecture, like linear as well as relative and
tabular. [15]
For a particular area of the screen a view object of the data structure
whose properties are carried in the layout parameters as well as
content are carried. Its own measurement are handled by view object,
layout, drawings, focuses changes as well as scrolling in addition to the
key interactions with the gestures where the residing of rectangular
area of screen takes place. In the user interface they are the objects, it is
also a point of interaction for the receiver as well as for the viewer of
the purpose of event interactions.
View Hierarchy
The hierarchy of view of UI is defined as an activity on the android
platform, nodes of View Group, diagram below can make it very clear.
The complexity and simplicity of hierarchy tree according to the need
of the users, where the users can build it with the usage of Androids
set of widgets those are predefined as well as layouts either through
the customs view that can be created by the user itself.
33
Blutooth Image Pro – Android Application
Figure 3: View Group
To the screen for rendering when the hierarchy tree is attached,
setcontentview() is the activity that is called as the method as well as
the root node object is referred. Invalidate is used by the android
system that easily receives the references, measure as well as it can
draw the tree. The child nodes are drawn it is the root node hierarchy
requests – for calling each node of the hierarchy is responsible in order
to draw themselves. Within the parent children can make a request
about the size and the location. The parents easily decide how big each
child can be. Android parse in layout in order of the elements (from the
beginning or the top of the hierarchy tree), instantiating the view by
adding them with their parents. Drawn in order are these, overlapping
of the position can take place by these orders; the top of others will be
lied by the last one that has to be drawn. [15]
Layout
For defining the layout and the most common way to express the view
hierarchy is with an XML layout file. XML makes an offering of the
human readable structure for the layout, which is very much like
HTML. A view is each element in XML either a viewgroup object (or
descendants thereof). Trees haves leaves viewobjects are like that,
34
Blutooth Image Pro – Android Application
where objects can be termed as the branches of the tree (it will be more
clear with the hierarchy mentioned above)
The java class is that to reprsent is the name of an XML elemnet that is
respective. So a <Text View> element can easily create a text View in
UI, where a <Linear layout>can easily create view group. When a
layout resource is loaded, the run time object is initialized by the
android system that can correspond to the layout of the element.
For instance a vertical simple layout may look like this that is the text
view as well as button.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
textview as well as the button is consisted in the linear layout element.
Another linear layout can be nested by user (either another category of
35
Blutooth Image Pro – Android Application
view group) that is inside, where the view hierarchy can be lengthen as
well as ca be created a more complicated layout.
Layout of view can be done in numerous ways. Where more and
distinctive view groups are used, where structuring of child views can
be done as well as in an infinite number of ways groups can be viewed.
Linear layouts are included in the view groups those are offered by
android, table layout, relative layout, grid layout even others. Layout
parameters are set where the position of child view is defined with the
layout structure. [14]
Widgets
For interaction with the user a widget view object is used that ca serve
as an interface. Fully implemented widgets are provided by android,
like buttons, checkboxes as well as entry text filed, UI can be build
quickly., Android provides more complex widgets such as clock, date
picker, zoom as well as controls. The android platform does not have
the limit to the availability of widgets. If there is a need to create own
actionable element as well as creation of customization own view
object can be defined either by extension as well as combination of
already existing widgets. [16]
2.7 U SING
THE
C AMERA
As the shrunk in the size of digital cameras have simultaneously
reduced the prices as well particularly in the mobile phone handsets of
the users. [13]
There is a need to add the camera in order to access camera hardware
in the manifest of the applications, that is shown below:
36
Blutooth Image Pro – Android Application
<Uses-permission android:name=”android.permission.CAMERA”/>
To the camera service grants access can be done. Camera class, while
taking pictures as well as manipulation of streaming camera previews,
can adjust camera settings.
Use of static open method is done to use the camera service. When the
camera finishes the applications, by calling the release the service
needs to be relinquished.
The preview size as well as image can use the camera parameters
through image formatting as well as preview from the rate.
Using the Camera Preview
Incorporation of live videos can be done in the applications this is
known as access to the streamline of camera. For the basis of
augmenting reality some of the android applications have been used
by the functionality. Onto real time surface the camera preview can be
displayed. [13]
Preview call back can also be assigned that can be fired for each
preview frame, where display or manipulation of each preview frame
will be done individually.
Taking a Picture:
On a camera object take picture is passed by the shutter callback as
well as picture callback for the RAW implementation as well as JPEG
images will be encoded. Byte array will be received by each picture
callback that will represent the image in the format, which is
appropriate, triggered immediately is done by shutter callback when
its shutter gets closed down. [13]
37
Blutooth Image Pro – Android Application
2.8 U SING
THE
B LU ETOOTH
Intent class is used by the developers who use the facility of operating
system for the broadcasting of the messages with the usage of device
Bluetooth. [16]
An operation to be performed Internet is the prescribed description. To
launch an activity it can be started with a start activity, broadcast
receivers areas end comments as well as start service either are bind
service in order to communicate with the services available in
background.
In different applications when the code are run the binding among
these are facilitated to perform alter runtime that has an intent to
provide a facility.
Action -- The general action to be completed, such as ACTION_VIEW,
ACTION_EDIT, ACTION_MAIN, etc.
Data -- The data to operate on, such as a person record in the contacts
database, expressed as an Uri.
2.9 U SER I NTERFACE C ONTROLS U SED
1) Image View Class:
Arbitrary image is displayed by image view, which is called as an icon.
Various images can be loaded with the help of image viewer (they can
include resources or content providers), it can be used in any layout
manager with the help of good care of computing, scaling and tinting
is been provided as the numerous display options. [8]
38
Blutooth Image Pro – Android Application
2) Gallery Class:
The gallery class can be viewed as the categories are displayed either
through centre locked or horizontally scrolling list.
There is need to adjust some properties of gallery such as spacing if the
author is not doing the default values for the assumption of the gallery
where theme gallery item background will be used for the single
gallery with the usage of adopter.
Gallery layout pattern need to be used for the view given to the
gallery, which will define the layout parameters categories. [8]
3) Linear Layout Class:
It is the layout in which the single Colum as well as single rows the
layout is been arranged. As the direction have been set by using set
orientation (). Gravity can be also specified, that is the arrangement can
be set by calling it as a set gravity, as the horizontal is of the default
orientation.
4) Tab Host Class:
It is the window view of a container for a tabbed. In this two children’s
are hold: when the user select for any specific tab that is a tab label,
another is the frame layout that will highlight about the displays on the
payer carrying content. With the usage of this container image the
individual element can be typically controlled. Without setting the
values on the child categorizes themselves. [8]
Tab Spec
Tab indicator can be found in tab content, where the track of all tags
can be kept has also a tab. among these options builders can be used.
For the indicator of lab choices are as follows:
39
Blutooth Image Pro – Android Application
Label is set
For the tab content label and an icon is set
The view of ID
The activity is launched.[8]
5) Tab Widget:
In the parent tab collection the display of a list of all tab labels are
easily represented. Tab host is the container object for the widgets. The
message is send to the parent container when the user selects the tab,
tab hot, which is to tell for switching off to displayed page. The adding
of label is done when the container tab host is used. Callback handler
needs to be added as well as managed to callbacks. The list of tabs
might be used to iterate it might to be called object. Tweaking of the
layout of the tab list is done; tab host is the most of the techniques that
can be used.[8]
6) Toast:
It is the view that contains quick little messages for the users. Creation
and show those can be done by toast class.
The appearing on the floating view on the application is done when the
view is displayed to the user. Focus will never be received. Typing of
something else will be in the middle where the user probably will be.
The idea behind is to be un obstacles much as possible, while shoeing
the information which users tends to se, volume control is one of the
example along with that brief message about the settings that have
been saved is the another example. [7]
40
Blutooth Image Pro – Android Application
7) Table View:
When rows and columns arrangement for children is done in a layout.
Table ray objects is included in table layout, row is also defined by
each (that means other children one can have, that explanation will be
done below). For their rows borderlines is not displayed by the table
layout, columns or cells. Each row consist of either zero or more cells,
one view object can be hold by each cell. With most cells table have
many columns for rows. Table can leave empty cells. Cells can do
spanning of column, as in HTML it can be done.
The widest cell in the Colum can help in defining the width of a
column. A table layout is the one that can make certain specification
about columns those are either stretchable or either shrinkable they are
called as set column shrinkable either set column stretchable ().
Shrinkable is if marked, the shrunk of column width can be done
where the table can be fit into the parent object. Stretchable is if
marked, the expansion can be done easily for the fit in any extra space.
Parent container helps in defining the width of the table. Shrinkable
and stretchable can be the important characteristics of any container.
The availability of space can be easily occupied by column. But it wont
is stretched. Set Colum collapsed can help in hiding the column.
Children of a table layout attribute cannot explain layout width.
MATCH_PARENT consists of width. Child can define the attribute of
layout_height attribute; WRAP_CONTENT is the default value table
row is a child, at that time height is always considered as
WRAP_CONTENT
In increasing Column order cells must be added to a row, in code as
well as Code. Zero based is the column numbers. For a child cell if the
specification of Column number is not there, that can auto increment to
the next available column. If the column number is skipped, in that
41
Blutooth Image Pro – Android Application
row it is considered to be the empty cell. Apidemos will make the
Tablelayot set for an example that is about the creation of tables in
XML.[8]
42
Blutooth Image Pro – Android Application
C HAPTER 3 – A PPLICATION D ESIGN A ND
I MPLEMENTATION
3.1
F EATURES
The “Bluetooth Image Pro“ application is focused to achieve the below
primary functionalities:
 Provide a complete Bluetooth Image Sharing solution on
Android devices.
 Leverage the Device hardware like Camera to view preview,
take images and share it with other devices.
 Allow user to share images with not only other “Android”
powered devices but will any operating system that is
running on a device with Bluetooth capabilities.
 Provide user with a easy and user friendly navigation
system in the form of a Tabbed User Interface.
 Provide a easy to view image gallery to the user, which can
facilitate the user to scroll through the available images and
send them to other Bluetooth powered devices.
3.2
S OFTWARE D ESIGN
The “Bluetooth Image Pro“ application has been developed in JAVA, using
Android API version 7. The development environment that has been used is
Eclipse powered with Android plug-in.
The application is a Tabbed user interface which has been designed to
provide enhanced user friendly experience and to modularize the various
feature components.
43
Blutooth Image Pro – Android Application
3.2.1 U SABILIT Y F LOWS
3.2.1.1 M ODULE L AYOUT H IERARCHY
Tab User Interface Manager
Home Page
Camera Page
Gallery Page
(Displays the splash
screen)
(Facilitates the user
to preview camera,
take picture and
share it.)
(Provides a image
gallery view to the
user and allows to
share pictures.
Figure 4: MODULE LAYOUT HIERARCHY
The application Tabbed user interface encapsulates three
primary modules as depicted in the above figure:

Home Page: The home page displays the
splash screen of the application.

Camera Page: This page facilitates the user
to preview the camera view of the device in
landscape mode and allows the user to take
a snapshot of the camera preview. The user
also has the option to view the last clicked
image and to send it to other device.
44
Blutooth Image Pro – Android Application

Gallery Page: The image gallery page shows
a gallery view of the application, which
allows the user to scroll through the
available images and then send them via
Bluetooth to other Bluetooth enabled
devices.
3.2.1.2
C AMERA P RO M ODU LE
Camera TabPage Manager
Start
Camera Pro
Activity
Initialize and register to Camera Hardware
Initialize Camera Preview and Camera Events
Take Picture
(Event Fired)
Save
Storage Card
Figure 5: CAMERA PRO MODULE
The Camera Pro Module is responsible for initializing the
Camera Hardware and registering for its events. It also shows
45
Blutooth Image Pro – Android Application
the user a live preview of the camera video and allows taking a
snapshot of the current view. The image is then saved into the
storage card temporarily and the user can share it using
Bluetooth.
3.2.1.3 V IEW C AMERA I MAGE M ODU LE
Camera TabPage Manager
Show Last
Clicked
Image
Retrieve
Show
Image Preview Area
Storage Card
Figure 6: VIEW CAMERA IMAGE MODULE
This feature allows the user to view the last clicked image. The
module loads the last clicked image from the storage card and
then sends it to the preview view area where the user can view
it and send it to other Bluetooth enabled devices.
46
Blutooth Image Pro – Android Application
3.2.1.4
S END C AMERA I MAGE M ODU LE
Camera TabPage Manager
1) Search for Bluetooth
devices.
Use the Intent class to
communicate with the
available device sender
activities and user selects
Bluetooth activity.
Send Last
clicked
Image
Figure 7:
2) Select Bluetooth device
(user operation)
3) Send Image (optional
authentication
procedure as set by the
receiver).
SEND CAMERA IMAGE MODULE
To broadcast messages using the device’s Bluetooth capabilities
to Generic devices (not only Android devices), the Android
operating system facilitates the developers to use the “Intent”
class.
The Intent Send loads the JPG stream from the storage card and
then sends it via Bluetooth activity and further performs the
below steps internally:
Search for Bluetooth devices.
Select Bluetooth device (user operation)
Send Image (optional authentication procedure as set by the
receiver).
47
Blutooth Image Pro – Android Application
3.2.1.5 I MAGE G ALLERY M ODULE
Initialize Image Gallery Scroller with the available images.
On user selection, load the image in Preview area.
User
Selects
Send Image
1) Search for Bluetooth
devices.
Use the Intent class to
communicate with the
available device sender
activities and select
Bluetooth activity.
2) Select Bluetooth device
3) Send Image (optional
authentication
procedure as set by the
receiver).
Figure 8: Image Gallery Module
The image gallery page shows a gallery view of the application,
which allows the user to scroll through the available images and
then send them via Bluetooth to other Bluetooth enabled
devices. For doing this, The Intent Send loads the JPG stream
from the storage card and then sends it via Bluetooth activity
48
Blutooth Image Pro – Android Application
and further search for Bluetooth devices. After this step, the user
can select Bluetooth device and send the image to it.
3.3
C ODE D ESIGN
3.3.1
M ODULE L AYOUT H IERARCHY
The “Bluetooth Image Pro” application uses Android 7.0
TabHost widget control to render the user interface as a tabbed
UI.
Each TabHost contains various TabSpecs which denotes a page
of the Tab.
Code Snippet:
TabSpec homeAppSect = applicationSects.newTabSpec("1");
TabSpec cameraAppSect = applicationSects.newTabSpec("1");
TabSpec imageAppSect = applicationSects.newTabSpec("1");
Each of the three activities are then loaded into the three
TabSpec’s:
homeAppSect.setContent(new Intent(thisAct, HomeLayout.class));
cameraAppSect.setContent(new Intent(thisAct, CameraImageLoader.class));
imageAppSect.setContent(new Intent(thisAct, ImageRenderer.class));
3.3.2
C AMERA P RO M ODU LE
The camera Pro module opens the Camera preview activity by
using the intent’s loader feature as under:
Intent cameraPro = new Intent(Intent.ACTION_MAIN);
cameraPro.setClassName("com.android.CameraPro", "com.android.CameraPro.CameraPro");
startActivity(cameraPro);
The camera pro activity opens the camera port and sets the
preview on the preview widget area display area as under:
hardwareCamHandle = Camera.open();
hardwareCamHandle.setPreviewDisplay(subScreenHandler);
49
Blutooth Image Pro – Android Application
3.3.3
V IEW C AMERA I MAGE M ODU LE
After the camera pro activity opens the camera port and sets the
preview on the preview widget area display area, the preview
class registers the below events of the camera activity:
1) public void surfaceCreated(SurfaceHolder subScreenHandler)
2) public void surfaceDestroyed(SurfaceHolder subScreenHandler)
3) public void surfaceChanged(SurfaceHolder subScrHandler, int structure, int c, int l)
The camera button is also reregisters as the below event listener:
public void onClick(View v)
{preview.hardwareCamHandle.takePicture(shutterCallback, rawCallback,
jpegCallback); }
3.3.4
S END C AMERA I MAGE M ODU LE
The camera button click loads the JPG stream into memory and
saves it onto the hard drive as:
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] streamLoader, Camera hardwareCam) {
FileOutputStream sdCardHandler = null;
sdCardHandler = new FileOutputStream("/sdcard/bluetoothpro/camerapic.jpg", false);
sdCardHandler.write(streamLoader);
sdCardHandler.close();
The camera button click loads the JPG stream into memory and
saves it onto the hard drive as:
File f = new File( Environment.getExternalStorageDirectory() +
"\\bluetoothpro\\camerapic.jpg");
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
startActivity(intent);
50
Blutooth Image Pro – Android Application
3.4 U SAGE S TEPS
Step 1: Copy the Extracted folder and files directly in the SDCard.
The path should be like this:
1) sdcard \ bluetoothpro\
2) sdcard \ CameraPro.apk
3) sdcard \ BluetoothPro.apk
After copying the files please Install the CameraPro application first and then the
BluetoothPro application.
Please make sure that you do not run individual applications from the installation
competition wizard itself. After both the applications have been installed use
“Step2” to run the application
Step 2: After the installation you should see the below applications in your All
Applications Menu:
Run the “Bluetooth Image Pro” application which will bring up the below “Step3”
screen.
51
Blutooth Image Pro – Android Application
Step 3: You should see the below screen
Home Page
Camera Section
Image Gallery
52
Blutooth Image Pro – Android Application
Step 4: Camera Section: In this section, you should see the
below screen:
53
Blutooth Image Pro – Android Application
1) Press “Start Camera Activity” to take a picture as below:
2) Press “View Last Clicked Image” to see the image in the
preview section
3) Press “Send Last Clicked Image” to send the last clicked
image. On selecting the “Bluetooth Send button the user will
be prompted with the below
Click On Bluetooth
User can select this option to use
Bluetooth always. In this case from
the second run of the application,
this menu will not pop up, and user
will be directly taken to the
Bluetooth device selection.
54
Blutooth Image Pro – Android Application
Step 5: Image Gallery:
This section will use the Android’s gallery widget to display
utility images and will facilitate the user to send these images
via Bluetooth to other devices:
Press the Send Image Button to send the file.
55
Blutooth Image Pro – Android Application
C HAPTER 4 – C ONCLUSION AND F UTURE W ORK
Conclusion:
At the beginning of the project an application was visualized which would
provide a complete Bluetooth Image Sharing solution for Android devices.
At the final stage, such an application has been developed which can take
advantage of the latest Android technology and provides a complete
Bluetooth Image Sharing solution on Android devices.
The application successfully leverages the Device hardware like Camera to
view preview, take images and share it with other devices. The initial vision
of a complete image sharing solution has been completed by the fact that, the
application allows the user to share images with not only other Android
powered devices but with any operating system that is running on a device
with Bluetooth capabilities.
Additionally the application has been able to provide user with an easy and
user friendly navigation system in the form of a Tabbed User Interface. Which
also provides an easy to view image gallery to the user, that facilitate the user
to scroll through the available images and send them to other Bluetooth
powered devices.
As a brief summary of the application user interface, the application provides
a tabbed user interface which encapsulates three primary modules - Home
Page which displays the splash screen of the application. Camera Page
facilitates the user to preview the camera view of the device in landscape
mode and allows the user to take a snapshot of the camera preview. The user
also has the option to view the last clicked image and to send it to other
device. The Gallery Page shows a gallery view of the application, which
56
Blutooth Image Pro – Android Application
allows the user to scroll through the available images and then send them via
Bluetooth to other Bluetooth enabled devices.
The application focuses upon various user sects and supports many usability
domains. For instance, the application can be used as a short distance mms
tool, as a navigation map sharing tool, as a fun application where user takes
quick images and shares to friends in close vicinity etc. The application is
truly in the right direction for being as a complete image sharing solution.
Future Work:
The application “Bluetooth Image Pro” was visualised as a complete image
sharing solution. Although it has stood to its direction, however there are
various areas of improvement which can be bridged for this application to
stand out of all the available applications. As a future work the below can be
suggested:

Adding GPRS connectivity for the application to receive
imagery from the internet.

Adding an image editor as an added functionality, so
that the user can modify the image taken from the
camera before sending it to other users.

Enhancing camera preview features. The below features
can be added to the camera preview:

Zoom functionality

Changing the contrast / colour options of
the live preview

Option to store the image in SD/main
memory

Changing the picture mode
(Colour/Greyscale,
Landscape/Portrait)
57
Blutooth Image Pro – Android Application

Adding multiple short images feature.

Controlling the camera’s flash and auto
focus capabilities, depending on the
devices hardware.

Add video functionality as an added
feature to plain images. This will
facilitate the users to share video
files also.

Making this application available on the android
market so that it can be used world wide and feature
request can be received from all sects of users.

Application portability to other operating systems, so
that the application can be used by users of all
devices.
58
Blutooth Image Pro – Android Application
REFERENCES
1) Professional Android 2 Application Development (Wrox Programmer to Programmer) by
Reto Meier (Mar 1, 2010)
2) Hello, Android: Introducing Google's Mobile Development Platform (Pragmatic
Programmers) by Ed Burnette (Jul 20, 2010)
3) The Android Developer's Cookbook: Building Applications with the Android SDK
(Developer's Library) by James Steele and Nelson To (Oct 27, 2010)
4) Beginning Android 2 by Mark Murphy (Mar 19, 2010)
5) Pro Android 2 by Sayed Hashimi, Satya Komatineni, Dave MacLean, and Dave MacLean
(Mar 15, 2010)
6) Android Application Development For Dummies (For Dummies (Computer/Tech)) by Steve
Holzner (Dec 7, 2010)
7) Android Wireless Application Development (2nd Edition) (Developer's Library) by Shane
Conder and Lauren Darcey (Dec 25, 2010)
8) Sams Teach Yourself Android Application Development in 24 Hours (Sams Teach Yourself -Hours) by Lauren Darcey and Shane Conder (Jun 20, 2010)
9) Beginning Android by Mark Murphy (Jun 26, 2009)
10) Unlocking Android: A Developer's Guide by Frank Ableson, Charlie Collins, and Robi Sen
(Apr 21, 2009)
11) Android OS: The Unofficial Handbook by Minute Help Guides (Jul 2, 2010)
12) Android Application Development: Programming with the Google SDK by Rick Rogers, John
Lombardo, Zigurd Mednieks, and G. Blake Meike (May 13, 2009)
Web References:
13) www.android.com/
Visited 17/11/2010
14) developer.android.com/ Visited 21/10/2010
15) code.google.com/android/ Visited 11/11/2010
16) androidcommunity.com/ & androidforums.com/ Visited 11/11/2010
59
Blutooth Image Pro – Android Application
17)
A PPENDIX :
S OURCE C ODE
1) Application Tabs
public class ApplicationTabs {
public static void makeTabs ( TabHost aplicationSects , Contxt thisAct ) {
Log . e ( “ Logger “ , “ Started the tab setter mechanism “ ) ;
TabSpec homeAppSect = aplicationSects . newTabSpec ( “ 1 “ ) ;
TabSpec cameraAppSect = aplicationSects . newTabSpec ( “ 1 “ ) ;
TabSpec imageAppSect = aplicationSects . newTabSpec ( “ 1 “ ) ;
Log . e ( “ Logger “ , “ Started the indicator setter mechanism “ ) ;
homeAppSect . setIndicator ( “ Home “ , thisAct . getResorces ( ) . getDrwable
( R . Drwable . home ) ) ;
cameraAppSect . setIndicator ( “ Camera “ , thisAct . getResorces ( ) .
getDrwable ( R . Drwable . cameraicon ) ) ;
imageAppSect . setIndicator ( “ Image “ , thisAct . getResorces ( ) . getDrwable
( R . Drwable . image ) ) ;
Log . e ( “ Logger “ , “ Started the Contxt setter mechanism “ ) ;
homeAppSect . setContnt ( new Intent ( thisAct , HomeLayout . class ) ) ;
cameraAppSect . setContnt ( new Intent ( thisAct , CameraImageLoader . class )
);
imageAppSect . setContnt ( new Intent ( thisAct , ImageRenderer . class ) ) ;
Log . e ( “ Logger “ , “ Started the adding tab mechanism “ ) ;
aplicationSects . addTab ( homeAppSect ) ;
aplicationSects . addTab ( cameraAppSect ) ;
aplicationSects . addTab ( imageAppSect ) ;
Log . e ( “ Logger “ , “ Setting listner events and activation . “ ) ;
aplicationSects . getTabWidget ( ) . setCurrentTab ( 0 ) ;
aplicationSects . setOnTabChangedListener ( MyOnTabChangeListener ) ;
}
60
Blutooth Image Pro – Android Application
private static OnTabChangeListener MyOnTabChangeListener = new
OnTabChangeListener ( ) {
@Override
public void onTabChanged ( String tabId ) {
Log . e ( “ Logger “ , “ Tab change event fired . “ ) ;
}
};
}
2) CameraImageLoader
public class CameraImageLoader extends Activity {
Button mStartCameraButton;
Button mStartImageLoad;
Button mStartBluetooth;
ImageView lastClickedImageView;
void onCreate ( Bundle cameraImageLoaderState ) {
super . onCreate ( cameraImageLoaderState ) ;
setContntView ( R . layout . gprs_activity ) ;
Log . d ( “ Logger “ , “ Image Directory debug log: “ +Environment .
getExternalStorageDirectory ( ) ) ;
String myJpgPath = “ /sdcard/bluetoothpro/camerapic . jpg “ ;
ImageView cameraLoaderViewImage = ( ImageView ) findViewById ( R . id .
ImageCamera ) ;
BitmapFactory . Options bmpOpts = new BitmapFactory . Options ( ) ;
bmpOpts . inSampleSize = 2;
Bitmap defaultImage = BitmapFactory . decodeFile ( myJpgPath , bmpOpts ) ;
cameraLoaderViewImage . setImageBitmap ( defaultImage ) ;
mStartCameraButton = ( Button ) findViewById ( R . id . button_StartCamera ) ;
61
Blutooth Image Pro – Android Application
mStartCameraButton . setOnClickListener ( new OnClickListener ( ) {
public void onClick ( View v ) {
try
{ Log . d ( “ Logger “ , “ Starting the camera pro activity from BTIP “ ) ;
Intent cameraPro = new Intent ( Intent . ACTION_MAIN ) ;
cameraPro . setClassName ( “ com . android . CameraPro “ , “ com
. android . CameraPro . CameraPro “ ) ;
startActivity ( cameraPro ) ;
Log . d ( “ Logger “ , “ Started the camera pro activity from BTIP “
);
}
catch ( Exception ex )
{
Log . d ( “ Logger “ , “ Exception in starting the camera pro
activity from BTIP: “ + ex . getMessage ( ) ) ;
}
}} ) ;
mStartImageLoad = ( Button ) findViewById ( R . id . button_LoadImage ) ;
mStartImageLoad . setOnClickListener ( new OnClickListener ( ) {
public void onClick ( View btipView ) {
try
{
Log . d ( “ Logger “ , “ Starting the view image activity from BTIP “
);
String myJpgPath = “ /sdcard/bluetoothpro/camerapic . jpg “ ;
//UPDATE WITH YOUR OWN JPG FILE
jpgName . setText ( myJpgPath ) ;
BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options .
inSampleSize = 2; Bitmap bm = BitmapFactory . decodeFile ( myJpgPath , options ) ;
jpgView . setImageBitmap ( bm ) ;
ImageView cameraLoaderViewImage = ( ImageView ) findViewById ( R
. id . ImageCamera ) ;
62
Blutooth Image Pro – Android Application
BitmapFactory . Options bmpOpts = new BitmapFactory . Options ( ) ;
bmpOpts . inSampleSize = 2;
Bitmap lastClickedImage = BitmapFactory . decodeFile ( myJpgPath ,
bmpOpts ) ;
cameraLoaderViewImage . setImageBitmap ( lastClickedImage ) ;
Log . d ( “ Logger “ , “ View image activity from BTIP completed “ ) ;
}
catch ( Exception ex )
{
Log . d ( “ Logger “ , “ Exception in starting the view image
activity from BTIP: “ + ex . getMessage ( ) ) ;
}
}} ) ;
mStartBluetooth = ( Button ) findViewById ( R . id . button_BluetoothSend ) ;
mStartBluetooth . setOnClickListener ( new OnClickListener ( ) {
public void onClick ( View v ) {
try
{
Log . d ( “ Logger “ , “ Starting the send image activity from BTIP “
);
File f = new File ( Environment . getExternalStorageDirectory ( ) +
“ \\bluetoothpro\\camerapic . jpg “ ) ;
Intent intent = new Intent ( ) ;
intent . setAction ( Intent . ACTION_SEND ) ;
intent . setType ( “ image/jpg “ ) ;
intent . putExtra ( Intent . EXTRA_STREAM , Uri . fromFile ( f ) ) ;
startActivity ( intent ) ;
Log . d ( “ Logger “ , “ Send image activity from BTIP completed “ ) ;
}
catch ( Exception ex )
63
Blutooth Image Pro – Android Application
{
Log . d ( “ Logger “ , “ Exception in starting the send image
activity from BTIP: “ + ex . getMessage ( ) ) ;
}
}} ) ;
}
private Drwable getDrwableView ( String serverMapPath )
{
try
{
InputStream streamGetterFrom_SMP = ( InputStream ) new URL (
serverMapPath ) . getContnt ( ) ;
Drwable DrwableGetterFrom_SMP = Drwable . createFromStream (
streamGetterFrom_SMP , “ streamGetterFrom_SMP “ ) ;
return DrwableGetterFrom_SMP;
}catch ( Exception ex ) {
Log . d ( “ Logger “ , “ Exception in getDrwableView activity from
BTIP: “ + ex . getMessage ( ) ) ;
return null;
}
}
}
3) Home Layout
public class HomeLayout extends Activity {
@Override
public void onCreate ( Bundle homeTabInstState ) {
64
Blutooth Image Pro – Android Application
//This is the home page of the aplication , and displays the splash screen
super . onCreate ( homeTabInstState ) ;
setContntView ( R . layout . home ) ;
ImageView splashScreenImgVwr = ( ImageView ) findViewById ( R . id .
ImageViewHome ) ;
splashScreenImgVwr . setImageResource ( R . Drwable . splash ) ;
}
}
4) ImageRenderer
public class ImageRenderer extends Activity {
private Gallery btip_imageLayout;
private ImageView btip_imagePreview;
private int currentCurLocation = 0;
private Integer[] btip_imageList = {
R . Drwable . driving_directions , R . Drwable . map , R . Drwable .
score_board , R . Drwable . traffic_uk , R . Drwable . weather , R . Drwable . weather2 ,
R . Drwable . graph
};
private Button sendImageActivity;
@Override
public void onCreate ( Bundle imageRenderInstState ) {
super . onCreate ( imageRenderInstState ) ;
setContntView ( R . layout . image_renderer ) ;
btip_imagePreview = ( ImageView ) findViewById ( R . id . ImageView01 ) ;
65
Blutooth Image Pro – Android Application
btip_imagePreview . setImageResource ( btip_imageList[0] ) ;
btip_imageLayout = ( Gallery ) findViewById ( R . id . examplegallery ) ;
btip_imageLayout . setAdapter ( new IncorporateImageADA ( this ) ) ;
btip_imageLayout . setOnItemClickListener ( new OnItemClickListener ( ) {
public void onItemClick ( AdapterView btip_imageRenderer , View
btip_imageVw , int location , long cursor ) {
currentCurLocation = location;
btip_imagePreview . setImageResource ( btip_imageList[location] ) ;
}} ) ;
sendImageActivity = ( Button ) findViewById ( R . id . button_receive ) ;
sendImageActivity . setOnClickListener ( new OnClickListener ( ) {
public void onClick ( View v ) {
String path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\driving_directions . gif “ ;
if ( currentCurLocation == 0 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\driving_directions . gif “ ;
else if ( currentCurLocation == 1 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\map . gif “ ;
else if ( currentCurLocation == 2 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\score_board . jpg “ ;
else if ( currentCurLocation == 3 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\traffic_uk . jpg “ ;
else if ( currentCurLocation == 4 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\weather . png “ ;
66
Blutooth Image Pro – Android Application
else if ( currentCurLocation == 5 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\weather2 . bmp “ ;
else if ( currentCurLocation == 6 )
path = Environment . getExternalStorageDirectory ( ) + “
\\bluetoothpro\\graph . jpg “ ;
File imageSrc = new File ( path ) ;
Intent sendImageCativityInt = new Intent ( ) ;
sendImageCativityInt . setAction ( Intent . ACTION_SEND ) ;
sendImageCativityInt . setType ( “ image/* “ ) ;
sendImageCativityInt . putExtra ( Intent . EXTRA_STREAM , Uri . fromFile (
imageSrc ) ) ;
startActivity ( sendImageCativityInt ) ;
}
});
}
public class IncorporateImageADA extends BaseAdapter {
int currentImage;
private Contxt ContxtADA;
public IncorporateImageADA ( Contxt thisCont ) {
ContxtADA = thisCont;
TypedArray styleList = obtainStyledAttributes ( R . styleable . GalleryTheme )
;
currentImage = styleList . getResourceId ( R . styleable .
GalleryTheme_android_galleryItemBackground , 0 ) ;
styleList . recycle ( ) ;
}
67
Blutooth Image Pro – Android Application
public int getCount ( ) {
return btip_imageList . length;
}
public Object getItem ( int location ) {
return location;
}
public long getItemId ( int location ) {
return location;
}
public View getView ( int location , View btip_imgvw , ViewGroup
btip_imageRendrer ) {
ImageView currentIgPreview = new ImageView ( ContxtADA ) ;
Log . e ( “ Logger “ , “ Set btip_imageList[location] “ ) ;
currentIgPreview . setImageResource ( btip_imageList[location] ) ;
Log . e ( “ Logger “ , “ Set the parms of currentIgPreview “ ) ;
currentIgPreview . setLayoutParams ( new Gallery . LayoutParams ( 80 , 70 ) )
;
Log . e ( “ Logger “ , “ Set the XY origin of currentIgPreview “ ) ;
currentIgPreview . setScaleType ( ImageView . ScaleType . FIT_XY ) ;
Log . e ( “ Logger “ , “ Set the image of currentIgPreview “ ) ;
currentIgPreview . setBackgroundResource ( currentImage ) ;
return currentIgPreview;
}
}
}
68
Blutooth Image Pro – Android Application
5) Layout Render
public void onCreate ( Bundle BTIP_layoutSet ) {
super . onCreate ( BTIP_layoutSet ) ;
setContntView ( R . layout . tab ) ;
Log . e ( “ Logger “ , “ Layout manager initiate . “ ) ;
layourExecuter = ( TabHost ) findViewById ( android . R . id .
tabhost ) ;
Log . e ( “ Logger “ , “ Set the Layout manager tabs . “ ) ;
AplicationTabs . setMyTabs ( layourExecuter , this ) ;
Log . e ( “ Logger “ , “ Aplication tabs have been created . “ ) ;
btip_this = this;
}
}
69
Download