Android Programming PDF Ebook

Document Sample
Android Programming PDF Ebook Powered By Docstoc
					           Faculty of Art and Science
Department of Mathematics and Computer Science

         MCS491 Graduation Project I


       Sevgi CANPOLAT 200622006
         Ceren GÜZEL 200622020
       Başak ZÜLFİKAR 200622037


                 Jan 2011 Ankara


  1.1. General Information of Android ………………………....4
  1.2. Requirements.……………………………...………….10
  1.3. Design (Data Flow Diagram)……………….…………..11

2. Main Part……………………………………………………12
  2.1. Source Code Explanation………………………………12
  2.2. IMobileAcademy Running in the Mobile Phone………….26
  2.3. Conclusion……………………………………………32


Nowadays, there is lots of mobile application and most of the phone user prefer
powerful smart phones. It is now a regular choice for consumers. So, developers
start to develop many kind of application. Some of these application based on web.
Android hardware is designed to tempt consumers of course, but the real win is for
developers. With existing mobile development built on proprietary operating
systems that restrict third-party applications, android offers an open and equal

We think that Çankaya University needs a mobile application which has many
different part in a menu. We observe the necessity that students need to connect the
website of our university with mobile phones easily. With this aim, we start to
develop iMobileAcademy application with Android OS.

Android is a kind of new mobile application developer tool which is an operating
system based on Google market. We choose Android specifically because Android
is based on Java programming language which is developed in Eclipse IDE and it
has open-source codes.

The kernel of Android is Linux. In addition, Android provides libraries, a handset
emulator, documentation and tutorials.

We start our project with reading a lot of documentations about android operating
system. Firstly, we learned using Eclipse IDE with some basic java codes. We
learned how could relate more than one classes. Then, we set up the Android SDK
in our computers. We begin android programming with basic examples.

In android, a project includes src, gen, assets, res folders and an
AndroidManifest.xml, default. properties files. Moreover, the project includes an
android emulator which is used to run the project. We can create more than one
emulator with different versions. As an example, 2 different emulator screen is
shown at figure below.

The src folder includes a package. The project‟s codes are in this package in the
.java format. The gen folder is formed automatically by the system. The res folder
is a resource for project which includes lots of folders for project. Some of them
are drawable, layout and menu folders. The AndroidManifest.xml is formed
automatically which includes the all programs xml codes.

We developed our application in Android platform. Now we will mention android,
its structure and usage briefly.

Android is an open source software stack that includes the operating system,
middleware, and key applications along with a set of API libraries for writing
mobile applications that can shape the look, feel and function of mobile handsets.
Android represents many new opportunities to write innovative applications for
mobile devices. Also, android offers an opportunity for developers to create
innovative software applications for mobile devices without the restrictions
generally associated with the existing proprietary mobile development frameworks.

Android is the combination of a free, open-source operating system for mobile
devices, an open-source development platform for creating mobile applications and
devices, actually mobile phones that run the Android operating system and the

At that point, we should summarize the advantages of android platform such as
following articles:

      No licensing, distribution, or development fees or release approval
processes for becoming an android developer

      Has no approval process for application distribution from android market.

      Wi-Fi hardware access

      GSM, EDGE, and 3G networks for telephony or data transfer, enabling
you to make or receive calls or SMS messages, or to send and retrieve data across
mobile networks

      Comprehensive APIs for location-based services such as GPS

      Full multimedia hardware control, including playback and recording with
the camera and microphone

      Libraries for using bluetooth for peer-to-peer data transfer

      IPC message passing

      Shared data stores

      Background applications and processes

      The ability to integrate application search results into the system search

      An integrated open-source HTML5WebKit-based browser

       Full support for applications that integrate map controls as part of their
user interface

      Mobile-optimized hardware-accelerated graphics, including a path-based
2D graphics library and support for 3D graphics using OpenGL ES 2.0

      Media libraries for playing and recording a variety of audio/video or still
image formats

     An application framework that encourages reuse of application
components and the replacement of native applications.

These are the unique features for android:

       Google Map applications

       Background services and applications

       Shared data and inter process communication

       All applications are created equal

       Home-screen Widgets, Live Folders, Live Wallpaper, and the quick
search box

Of course there are another source software stacks for programming a mobile
device. We can say that Symbian platform, Palm OS and iPhone is the most
powerful ones but android has most powerful advantages which is being open
source, so android improves rapidly. Some kind of computing between android and
iPhone in terms of input methods and hardware capabilities is shown in the figure:

Versions of the Android SDK, Java, and Eclipse are available for Windows, Mac
OS, and Linux, so anyone can explore Android for all OS. The Android SDK
includes an emulator for all three OS environments, and because Android
applications are run on a virtual machine, your OS preference is not important
when you want to develop an android project. With a simple and powerful SDK,
no licensing fees, excellent documentation, and a thriving developer community,
Android represents an excellent opportunity to create software that changes how
and why people use their mobile phones.

Android code is written using Java syntax, and the core Android libraries include
most of the features from the core Java APIs. Before they can be run, though, your
projects are first translated into Dalvik byte code. This means that Dalvik is custom
JVM. As a result, you get the benefits of using Java, while your applications have
the advantage of running on a virtual machine optimized for Android devices.

General flow diagram for android is shown above.

The SDK download includes all the Android libraries, full documentation. It also
includes tools to help you write and debug your applications, like the Android
Emulator is used to run projects and the Dalvik Debug Monitoring Service
(DDMS) is used to help debugging.

The building block of the user interface is the activity. Activity can be thought as
being the android analogue for the window or dialog in a desktop application.
While it is possible for activities to not have a user interface, most likely your
“headless” code will be packaged in the form of content providers or services.

1. When iMobileAcademy is clicked, a start page displays on the screen.
2. After first start button is clicked, user has a new menu with multiple choices.
3. Application continues with Faculty Selection. This part includes six different
   options like “Art and Science”, “Engineering and Architecture”, “Economics
   and Administrative”, “Law”, “Graduation School” and “Vocational School”.
4. Each faculty has own department item.
          4.1 In “Art and Science” menu, there are three choices for
                  departments such as “Mathematics and Computer Science”,
                  ”English Language and Literature” and “Translation and
          4.2 In “Engineering and Architecture” menu, there are four choices
                  for departments such as “Computer Engineering”, “Electronic
                  Engineering”, “Interior Architecture” and “Industrial
          4.3 In “Economics and Administrative” menu, there are four
                  choices for departments such as “Economics”, “Management”,
                  “Political Science” and “International Trading”.
          4.4 In “Law” menu, there is only one choice for department such as
          4.5 In “Graduation School”, there are two choices for departments
                  such as “Natural Applied Science” and “Social Science”.
          4.6 In “Vocational School”, there is only one choice for department
                  such as “Foreign Trade”.
5. Each department has six options such as “Department Members”,
   “Undergraduate Courses”, “Announcements”, “Student System”, “Call
   Department”, “and General Information”.
6. When user clicks one of the options in Department section, he/she can
   connect related link.



For create an android project, the programmer should give a name for application
and then choose SDK Version. After that, he/she give a package name, application
name which is appearing name of the application on emulator and create start
activity for main class.
Android application has many folders. These are src, gen, assets and res. There is
also an AndroidManifest.xml file which is generated automatically when an
application is created and manifest consists of all activities in it.
In src folder, there exist java classes. There is a package which has our java files
in it. The package name is for our project.
Same structure is valid for gen folder. In gen folder, class generated
automatically. A class which is in src works with an xml file which is in res/layout
folder. There are many png files for xml in res/layout folder in it.

There are drawable, layout and values folders. Drawable folder has png, jpeg or
gif files which are used in .xml files of a project and called in our classes. Layout
folder keeps the .xml files of the project and this folder is very important for
appearing design of the application to user when all the classes run.

To create new android project, follow these steps: When creating a new project of
Android, the user should choice new project after that Android project then, user

must see New Android Project page. There are project name, create new project in
workspace, Build Target, Application Name, Package Name, Creative Activity in
this page. Programmer has a new project now.

After that simple explanation, we can start to explain our own IMobileAcademy
project. We design our application with multiple activities. (This part can be
followed on UML diagram) This means that BeginPage class comes on
ScreeSelectFaculty class which has six faculties of Çankaya University. And every
faculty has own departments and there is an other menu which has department
members, announcements, undergraduate, student system, call department,
general info for each department. In addition, all new projects generate an
AndroidManifest.xml, and String.xml and later steps, we add our built
activities which is used extends Activity in it.

This screenshot shows us AndroidManifest.xml which is brain of our project.
Manifest obtains to combine our classes and .xml files via Activity‟s. All
implemented classes from Activity must be stated in AndroidManifest.xml.

As you see on the picture above, keeps our id of variables type which are
defined in classes and in .xml files. As you know, all drawable and layout parts is
kept in our res folder. When we add a file or image in res folder, id of these item
generate in Also, there is a warning like “do not modify this file” and
normally java cannot permit to change anything in that class. So, generally
is not modified but the programmer can interference class in some extreme

Application is begun with ScreenSplash class which in this step, IMobileAcademy
is loading in the class. ScreenSplash class calls .xml for appearing when user of
Çankaya University is waiting.

setContentView(R.layout.splash);           // call creat.xml file

And then, for new handler to start and run, we use public run method in class and a
special form Intent which is new and special for Android. Use of intent is shown at
the figure below:
public void run() {

      // Create an Intent that will start the Menu-Activity.

Intent     mainIntent            =      new        Intent(ScreenSplash.this,



BeginPage class is our starting part of our project. When we click our start button
in BeginPage class, after application runs, with using intent which is used to
connect the other class in android. BeginPage is first class of the application for
entering the IMobileAcademy. We use 2 important variables in this class. These

      private Builder alert1;

      private TextToSpeech tts;

In BeginPage extends Activity which implements Listener, call create.xml file for
user can see the desinged page to enter the application. In this class, there are
callIntent, loadDialog, onActivityResult, startVoiceRecognitionActivity and onInit
methods. This class has one button which extends to pass next ScreenSelectFaculty
class and the user sees the other interface which is create.xml in application.
switch (view.getId()) {

               intent = new


               alert1 = new AlertDialog.Builder(BeginPage.this)
               .setMessage("Please choose one category!")
               .setPositiveButton("OK", new

                          public void onClick(DialogInterface dialog,
int whichButton) {
                          Intent i = new Intent(BeginPage.this,


 In ScreenSelectFaculty class, with respect to users‟ choice, one of the faculty class
run via intent. After faculty selection, we have another screen which has
department selections on it.         We extend with switch case structure. In
IMobileAcademy, we appoint six buttons for different six faculties and a image
which is a logo of Cankaya University button for contacting web site
“”. The other buttons are created from the android library and
connect to every faculty class. For example this part of the code shows us buttons
and intent to the other faculty class which is connected FacultyEngineering.

switch (view.getId()) {


               intent = new

We create two variables in ScreenSelectFaculty like BeginPage class, and call
facultyselection.xml for showing its interface.
     public void onCreate(Bundle savedInstanceState) {



onCreate method which unites the methods and codes in its like main method of
Java, is used in Android programming. A part from that, there are onInit,
startVoiceRecognitionActivity,       onActivityResultFaculty,  onBackPressed,
onActivityResult, loadDialog, callIntent methods in the class.


When IMobileAcademy application runs and then, the user chooses one of the
faculties so one of the buttons is clicked in the program, departments of chosen
faculty is seen, and the program passes other chosen class and .xml.

Let say the user in application chooses Engineering and Architecture Faculty
button at the same time, in the back of the application, codes of ScreeSelectFaculty
leads to FacultyEngineering which has two variables. These are alert and tts2.
This class extends Activity and implements OnInitListener.
 FacultyEngineering        again      has,     onInit,startVoiceRecognitionActivity,
onActivityResultFaculty, onBackPressed, onActivityResult, loadDialog, callIntent
methods in the class like ScreenSelectFaculty. In callIntent method of the class
makes buttons with switch case structure and Intent other classes.

public void callIntent(View view) {

            Intent intent = null;

            switch (view.getId()) {

Switch-case structure / this methods run with seeming interface in application
when the user of Çankaya University clicks one of buttons which are Computer
Engineering, Electronic Engineering, Industrial Engineering and Interior


This interface is derived this code in class



Moreover, we write a little part of code for using IMobileAcademy application
affectively. onInit method makes when the user accesses the application, program
tells the steps of the IMobileAcademy and we add „voice‟. This voice processes for
users being able choose easily.

String speech1=" , Please select your department" ;


        tts2.speak(speech1, TextToSpeech.QUEUE_FLUSH, null);

In FacultyEngineering, final method is onBackPressed() which enables if user
wants to go back previous steps/ choices, application can be returned the previous
one classes in the program. This main structure is valid for other faculty classes. It
is been able to follow on this code:

Intent i=new



Let say on our application, the user is a student of computer engineering in
Çankaya University and s/he selects Computer Engineering buttons when program
is running. After that, layout of web_announce. xml is shown users like that:

This xml file is called via every department, so if the user selects the other
departments of different faculties, same interface seems in mobile screen of
devices again. Because, we aims every users of any department can use efficiently
in mobile phone and they see similar structure for any department when we design
our project. This makes to facilitate that users do not slog on Çankaya University
web sites when they use on mobile devices. class has six buttons which are Department Member,
Undergraduate Courses, Announcements, Student System, Call Department and
General Info. Otherwise, we have an image button for connecting the web page
Çankaya University again. This button system is created switch case structure.
 In ComputerEngineering class; Department Member, Undergraduate Courses,
Announcements, Student System buttons connect the links of Çankaya University‟s
relevant department. This part of the code from ComputerEngineering class is
shown as:



                   intent = new Intent(Intent.ACTION_VIEW,







                   intent = new Intent(Intent.ACTION_VIEW,




Button01 gets id of department members button from .xml and when it is clicked,
first case is running, the program gets the user to the page of , browser is opened and link is active.
Similarly, while the other buttons are being clicked, the chosen button‟ case is run.

intent = new Intent(Intent.ACTION_VIEW,

intent = new Intent(Intent.ACTION_VIEW,

intent = new Intent(Intent.ACTION_VIEW,


Button05 gets id of Call Department button from and does not connect the internet
network, it enables to call own or intended department with the user‟s mobile

intent = new Intent(Intent.ACTION_CALL,



This telephone number is telephone center of Çankaya University. Part of this
code, “Intent.ACTION_CALL” makes connected Çankaya University with help
of the telephone operator when the user click Call Department button in Mobile
Phone. This code is running in every department class and this can see in
IMobileAcademy application.

 i.   Select our application in our emulator.

ii.   Our application is starting.

iii.   Start page of application is like this:

iv.    Press the start button and we get faculty selection screen. Also, the speaker
       helps us to follow steps.

v.    After we press the Engineering Faculty button, we get departments of
      Engineering as following:

vi.   We can choose a department which we want. By the way, there is a screen
      like the following when we press a button. Intents are executing here mostly.

        vii.   In any department, you can see the same screen but of course indexes are

viii.   When you click Department Members button:

ix.   When you click Undergraduate Courses button:

x.    When you click Department Members button:

xi.    When you click Student System button:

xii.   When you click General Information button:

      2.3 CONCLUSION
As you can understand, there is no chance for stating some parts of the program
and giving up other parts. All the classes, images and .xml files are related each
other effectively. As a summarize, we can say that classes are related to each other
with Intent structure and .xml files are called when we want to show layout part on
the screen.

At the beginning of this term, we aimed this kind of structural application. At the
end of the term, we obtain an application for mobile devices about our university
faculties and departments and our application is exactly same with our aim. Both
code part and application view, we are at the Since Android is new technology and
it has rapid improvement, we can say that this situation can be an advantage for our
future life.




3. Android Application Development, Gramlich Nicolas, Android
   Programming with Tutorials from the Community, [Online]

4. Burnette Ed, Hello, Android Introducing Google‟s Mobile Development
   Platform, [Online]

5. Burnette Ed, Introduction to Android Development, 2009 [Online]

6. Meier Reto, Professional Android Application Development, [Online]

7. Meier Reto, Professional Android Application Development2, [Online]

8. Murpht Mark L., Beginning Android, [Online],

9. Hashimi Sayed Y., Komatineni Satya, Pro Android, [Online]


Description: Pdf ebook, The Android, Kumpulan Cerita Sex, Search Terms, 3rd edition, Programming Tutorials, Search Engine, PDF files, Solution Approach, Search API, Milwaukee WI, Gay Story, phần mềm, tutorial PDF, pdf reader,