Escolar Documentos
Profissional Documentos
Cultura Documentos
ANDROID:
13/03/2014
13/03/2014
includes an calendar, email client, SMS program, maps, making phone calls, accessing the Web
browser, accessing your contacts list and others.
2. Application FrameWork:
to follow. The developers can access all framework APIs an manage phones basic functions like
resource allocation, switching between processes or programs, telephone applications, and
keeping track of the phones physical location.
3.
Libraries:
a. Core Libraries: The Android runtime layer which includes set of core java
libraries and DVM (Dalvik Virtual Machine) is also located in same layer.
b. Native Libraries: This layer consists of Android libraries written in C, C++, and used by various
system. These libraries tells the device how to handle different kinds of data and are exposed to Android
developers via Android Application framework. Some of these libraries includes media , graphics,
3d,SQLite,web browser library etc.
required for java libraries. Every Android application gets its own instance of Dalvik virtual machine.
Dalvik has been written so that a device can run multiple VMs efficiently and it executes files in
executable (.Dex) optimized for minimum memory.
13/03/2014
power management software and several drivers for hardware , file system access, networking and interprocess-communication. The kernel also acts as an abstraction layer between hardware and the rest of
the software stack.
Android Versions:
Android
2.3.32.3.7 Gingerbread (API level 10)
First
Major version of Android is 1.5 (CupCake)
may 2009
Android 2.2(Froyo)
2.3,2.3.2,2.3.3,.(GingarBread)
Android
Android 2.0.1
Eclair (API level 6)
Android
Android 2.13.1,3.2,3.2.1,3.2.2,3.2.3.(HoneyComb)
Eclair (API level 7)
Android 2.22.2.3
Froyo
(API level
8)
Android
4.0(ice
Cream
Sandwitch)
Android
Features:
2.12
Android 3.1 Honeycomb (API level 12)
level
Dalvik
15) virtual machine optimized for mobile devices
Optimized graphics
Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC,
AMR, JPG, PNG, GIF)
13/03/2014
To Create , Test and build Android applications we need the following Softwares:
1. Eclipse IDE (is optional can use any other tool. But Eclipse is recommended ) + added with
Android Development plugin
2. Android SDK(Software Development Kit
we can download these s/w from this site http://www.android.com
Required Softwares:
The android app can be developed on any OS such as Windows, Linux, and MAC Os
The following are the resources that are required to set up into the system for android application
development
1. An IDE (Integrated Development Environment) : The Eclipse is the most prefered IDE. We can
download the Eclipse IDE from
the following website.
http://www.eclipse.org
13/03/2014
Activity:
The Activity is the one of the core components of Android App
This is crated as a Java Object subtype ofandroid.app.Activity
This component is managed by the Android App Framework
13/03/2014
The onCreate() :
The onCreate() methos is used to implement initialization code like presenting the View for the
Activity.
The onStart():
The onStart() method allows writing the code executing on getting the activity foreground
The onRestart() :
The onRestart() method can initialize the resources that are closed in the onStop().
The onStop() :
The onStop() method can use the resources that are not required on paused activity. This may
even required to solve the start of the activity.
The onResume() :
13/03/2014
Or
Creating an Activity: While creating/starting the activity the following methods are invoked.
onCreate()
onStart()
13/03/2014
13/03/2014
For the first time want to take the following points to check
Once Creating the Android project we find the project is created with one activity bydefault.
10
13/03/2014
src
A folder that holds the Java source code
gen
This is where Android's build tools will place source code that they generate.
R.java" is a generated class which contains the text and the UI elements.
Android projects come with this free class 'R' which is short for Resource.
This is an automatically generated class that we can use to reference
resources in our project. We should not try to modify this class manually.
assets
A folder that holds other static files you wish packaged with the application
for deployment onto the device.
bin
In Eclipse, the ADT plugin incrementally builds our project as we make
changes to the source code. Eclipse outputs an .apk file automatically to the
bin folder of the project, so we do not have to do anything extra to generate
the .apk.
res
A folder that holds resources such as icons, graphic user interface (GUI)
layouts, etc. that are packaged with the compiled Java in the application.
AndroidMainFest.xml
An XML file describing the application being built and which components
(activities, services, and so on) are being supplied by the application. This file
is the foundation for any Android application. This is where you declare what
is inside your application. You also indicate how these pieces attach
themselves to the overall Android systems; for example, you can indicate
which activity or activities should appear on the device's main menu (a.k.a.
the
launcher).
When you create your application, a starter manifest will be generated for
you automatically. For a simple application, offering a single activity and
nothing else, the auto generated manifest will probably work out fine, or
perhaps require a few minor modifications. But on the other spectrum, the
manifest file for the Android API demo suite is more that 1,000 lines long.
Your production applications will probably falls somewhere in the middle.
Most of the manifest will be describes detail in later chapters.
project.properties
Property files used by the Ant build script.
Creating an Activity:
The activity class needs to be a subtype of android.app.Activity
The onCreate() method is one basic method which minimum we want to override . Like
we may want to create / locate the View and set it to the Activity.
The following methods of Activity are used to set the View
11
13/03/2014
12
13/03/2014
13
13/03/2014
@String/test
R.<type>.<name>
We can use the following method for getting the string resource declared in the xml.
String s1=getResources().getString(R.String.test);
Similar to String we can have a Boolean resource .this is declared using <bool> tag.
Starting an Activity:
The activity with ACTION_MAIN, and CATEGORY_LAUNCHER is main activity to run on
accessing the application.
In addition we may want to start another activity from such main activity.
We use startActivity(Intent) method of the Activity to do this.
14
super.onCreate(b);
setContentView(R.layout.main1.xml);
}
}
This new Activity is requited to register into the AndroidManifest.xml
<activity android:name=.Activity2 android:label=Activity2></activity>
In the existing Activity:
following tag.
Lets consider the main.xml is the layout document and has the
<Button
.
Android:onClick=myMethod/>
The following method needs to added into the existence Activity
public void myMethod(View view)
{
Intent i=new Intent();
i.setComponentName(new ComponentName(getApplicationContext(),Activity2.class));
startActivity(i); }
Implicit Intents:
Although the explicit intents are simple but are useful only to locate the activities whose names
are known to us, which is generally with the activities of our application.
In case if we want to access the activities of some other applications in the system explicit would
not meet our requirement
In this case the android system is responsible to find the suitable activities to handle this intent.
In case if none found the ActivityNotFoundException would be thrown.
15
13/03/2014
16
13/03/2014
17
13/03/2014
18
13/03/2014
<activity android:name=".Acitivity2"></activity>
i.setComponent(new ComponentName(getApplicationContext(),Activity2.class));
startActivity(i);
}
// Code for implicit Intents
public void MyMethod1(View view)
{
Intent i=new Intent();
i.setAction(Intent.ACTION_DIAL);
startActivity(i);
19
}
13/03/2014
Activity2.java
package com.durgasoft.android;
import --------------------------------------------;
public class Activity2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
} }
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" ></TextView>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:onClick="MyMethod"
android:text="Explicit Intent"></Button>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:onClick="MyMethod1"
android:text="Implicit Intent" ></Button>
20
13/03/2014
21
13/03/2014
<EditView....../>
Example:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=Click Me Boss
android:onClick=Submit />
To set this view as User Interface for the Activity we can have the following code in the
onCreate() method of the activity.
setContentView(R.layout.simpleButton);
Note:
The android XML file names cannot have uppercase and special and white space
characters.
If we want have multiple view components into a UI we shall work with ViewGroup such
as Layouts.
22
13/03/2014
23
13/03/2014
The Button:
We use the android.View.Button class to create this component. Or
<Button> tag in the XML document.
Example:
Button b=new Button(this);
b.setText(Submit);
In XML: <Button android:text=Submit/>
Configuring the Button to listen for Click event:
Programatic:
In Case we use the following method of Button to set the listener for
onClick event.
setOnClickListener(View.onClickListener)
The View.OnClickListener is an interface that declares only one method.
public void onClick(View v)
This method is invoked by the View component when a user clicks the
component.
We can create a class implementing this interface . most of the time we
prepare creating an anonymous class
Example:
Button b1=new Button(this);
OnClickListener l=new OnClickListener(){
public void onClick(View v)
{ .......................... };
b1.setOnClickListener(l);
Declarative :
This is simple ,here we want to use android:onClick attribute specifying
the name of the method to listen for this event.
The method needs to be implemented in the content of this Buutton , with
the following signature
public void <method-name> (View v)
24
13/03/2014
25
13/03/2014
26
13/03/2014
27
ViewGroup
LinearLayout
RelativeLayout
TableLayout
FrameLayout
ListView
ScrollView
TableView
RadioGroup
13/03/2014
ProgressBar
ImageButton
Image
The TextView autolink option ,this is used to have links automatically created for the phone
numbers , email ids and website address supporting us to click performing necessary action. We use
android:autolink attribute to configure this. This defaults to none, and we can specify phone, email, web,
map, or all.
The AutoCompleteTextView:
This is a subtype of EditView , this allows us get the help content listing to choose
the values from . we can use the following tag to declare this component.
<AutoCompleteTextView../>
Example:
<AutoCompleteTextView
android:layout_width="150px"
android:layout_height="wrap_content"
android:id="@+id/act1" >
</AutoCompleteTextView>
In the Activity onCreate() method we can have the following code for describing
the autocomplete words.
AutoCompleteTextView act=(AutoCompleteTextView)findViewById(R.id.act1);
String[] str=new
String[]{"SVU","OU","JNTUK","JNTUH","ANDHRA","SKU","YVU","VSU","PALAMURU","MAHATMA","OTHE
R"};
ArrayAdapter< String> aa=new
ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_dropdown_item_1line,str);
act.setThreshold(1);
act.setAdapter(aa);
The Toggle Button:
This is a subtype of button , this is a special type similar to the CheckBox allowing
us present the a view taking data like yes or no from the user.
We use the following tag to have this view.
<Toggle Button
android:layout_width="150px"
28
13/03/2014
The CheckBox:
This is also a subtype of button allows us to take checked/unchecked decisions
from the user.
We use the following tag to declare this view.
<CheckBox android:layout_width="50px"
android:layout_height="wrap_content"
android:id="@+id/cb1"
android:text="MCA"
android:onClick="CheckBox"></CheckBox>
In the activity class we can have the following method.
public void CheckBox(View view)
{
CheckBox cb1,cb2;
cb1=(CheckBox)findViewById(R.id.cb1);
cb2=(CheckBox)findViewById(R.id.cb2);
if(cb1.isChecked())
{ Toast.makeText(getApplicationContext(), "MCA is Selectd",Toast.LENGTH_LONG).show();
}
else if(cb2.isChecked())
{ Toast.makeText(getApplicationContext(), "BTech is Selectd",Toast.LENGTH_LONG).show();
} }
29
13/03/2014
The Spinner:
This is a list box type allowing us to choose between the given values.
We use the following tag for defining this type of View.
<Spinner android:layout_width="150px"
android:layout_height="50px"
android:id="@+id/sp1" > </Spinner>
We can add the String array resources using the following tag.
<String-array name=myarray>
30
13/03/2014
The ListView:
This View allows us to have set of values to list.We use <ListView> tag to define this view.
Example:
Add the following tag in main layout.
<ListView android:layout_width="150px"
android:layout_height="50px"
android:id=@+id/mylist/>
In the onCreate() method of the activity we can have the following code for setting a list of values.
ListView lv=(lv)findViewById(R.id.mylist);
String values[]={value1,value2};
ArrayAdapter<String> aa=new
ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item,values);
lv.setAdapter(aa);
31
13/03/2014
The GridView:
This is similar to the ListView , but supports arranging the elements into rows and
columns.
The following tag is used to define this View.
<GridView ....></>
We use android:numColumns attribute specifying the number of columns, and the
number of rows is decided decided based on the items.
Like done with the ListView we set the adapter for the items,and can set thee
OnItemClickListenr
The DatePicker:
This allows us to have a view that can take the date from the user. The following tag is
used to configure this view
<DatePicker .........../>
And the init() method of the DatePickerDialog is used to set
the initiated date and the onDateChangedListener.
If the method is not invoked it by default sets the date to the system date.
The TimePicker:
32
13/03/2014
33
13/03/2014
34
13/03/2014
35
13/03/2014
36
android:layout_height="wrap_content"
android:layout_width="fill_parent"
<TableRow >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Registration Form"
android:textStyle="bold|italic" >
</TextView>
13/03/2014
>
37
</TableRow>
<TableRow >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prefered Timings"
></TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tp"
android:text="Select Time"
android:onClick="TimeDialog" ></Button>
</TableRow>
</TableLayout>
</ScrollView>
Dialog Box:
The android.app.DialogInterface is the base interface representing any dialog.
The android.app.Dialog class supports declaring a dialog . This is the base class for
any dialog.
Example:
Dialog d=new Dialog(this);
d.setContentView(R.layout.dialog_layout);
The dialog_layout describes the view for the dialog just as done for the activity.
d.setOwnerActivity(MyActivity,this);
d.show(); // This will show the dialog
we can add onCancelListener and onDismissListeners set to the Dialog.
We use any of the following methods of Dialog to choose the dialog box.
Cancel();
Dismiss();
Android includes the following builtin dialogs implementation simplifying creating the
dialog box for most common requirements.
38
13/03/2014
The AlertDialog: This supports us to create a dialog that meets the most common requirement
of having a dialog for showing some alert, this includes
- A Optional Title
- Message Text
- Zero, one, two, or three buttons
- List of items
We use a AlertDialog.Builder object to crate this Dialog .
The following methods of this object allows us setting the details for the dialog.
- setTitle(String)
- setMessage(String)
- setPositiveButton(String lable,DialogInterface.OnClickLIstener listener)
- setNegiveeButton(String lable,DialogInterface.OnClickLIstener listener)
- setNutralButton(String lable,DialogInterface.OnClickLIstener listener)
- setItems(String[])
Once setting all the details , we can invoke create() method for the AlertDialog
object and further show() method for showing.
The following methods of Activity can be used to show and remove the Dialog
boxes.
showDialog(int): This shows the Dialog.
removeDialog(int): Removes the dialog from the Activity
The OnCreateDialog(int): method is invoked for the first time when a dialog is
requested to show. This method is responsible to create a dialog for the given
index to show.
The onPrepareDialog(int): method is invoked each time(including firsttime)
when a dialog is required to show.
Note:
The Activity retains the state of the dialog even on cancelled / dismiss of
the dialog is requested to show again . However invoking remove Dialog(int) will
release the dialog state with the activity.
The Menu:
39
13/03/2014
40
13/03/2014
41
13/03/2014
42
13/03/2014
43
13/03/2014
44
13/03/2014
45
13/03/2014
my_tabs_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/android:tabhost"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@id/android:tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@id/android:tabcontent"
46
13/03/2014
Storage Methods:
1. Shared Preferences
2. SQLite Databse
3. XML
1). Shared Preferences :
Interface for accessing and modifying preference
data returned by
getSharedPreferences(String, int).
SharedPreferences
47
spf=getSharedPreferences("mypreferences",Con
text.MODE_PRIVATE);
SharedPreferences.Editor
Interface used for modifying values in a
SharedPreferences object.
Create a new Editor for these preferences,
through which you can make modifications to
the data in the
13/03/2014
48
android:layout_marginTop="83dp"
android:text = "Enter Password :"
android:textAppearance="?android:attr/textApp
earanceMedium" />
< EditText
android:id="@+id/editText1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="27dp"
android:layout_toRightOf="@+id/textView1" >
<requestFocus />
</EditText>
< EditText
android:id="@+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="53dp"
android:onClick="Save"
android:text = "Save" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="34dp"
android:onClick="getDetails"
android:text = "getDetails" />
13/03/2014
49
50
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="66dp"
android:text = "Dept :"
android:textAppearance="?android:attr/textApp
earanceMedium" />
< EditText
android:id="@+id/editText1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView1"
android:layout_marginLeft="35dp"
android:layout_toRightOf="@+id/textView2" >
<requestFocus />
</EditText>
< EditText
android:id="@+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView2" />
< EditText
android:id="@+id/editText3"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText2"
android:layout_alignParentRight="true" />
< EditText
android:id="@+id/editText4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
13/03/2014
51
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button3"
android:onClick="getDetails"
android:text = "getDetails" />
</RelativeLayout>
TestProjectActivity .java
sqlite.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/ap
k/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="33dp"
android:text = "Employee id :"
android:textAppearance="?android:attr/textApp
earanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:text = "Employee Name:"
android:textAppearance="?android:attr/textApp
earanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
13/03/2014
52
android:textAppearance="?android:attr/textApp
earanceMedium" />
< EditText
android:id="@+id/editText4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText4"
android:onClick="Insert"
android:text = "Insert" />
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button3"
android:onClick="getDetails"
android:text = "getDetails" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button4"
android:onClick="Update"
android:text = "Update" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
13/03/2014
53
et1.setText("");
et2.setText("");
et3.setText("");
et4.setText("");
}
public void Update(View v){
EditText et1,et2,et3,et4;
et1=(EditText)findViewById(R.id.editText1);
et2=(EditText)findViewById(R.id.editText2);
et3=(EditText)findViewById(R.id.editText3);
et4=(EditText)findViewById(R.id.editText4);
ContentValues cv=new ContentValues();
cv.put("ename", et2.getText().toString());
cv.put("desig", et3.getText().toString());
cv.put("dept", et4.getText().toString());
db.update("employee", cv, "eid=?", new
String[]{et1.getText().toString()});
et1.setText("");
et2.setText("");
et3.setText("");
et4.setText("");
}
public void Delete(View v){
EditText et1;
et1=(EditText)findViewById(R.id.editText1);
db.delete("employee", "eid=?", new
String[]{et1.getText().toString()});
et1.setText("");
}
public void getDetails(View v){
EditText et1;
et1=(EditText)findViewById(R.id.editText1);
Cursor c=db.query("employee", new
String[]{"eid","ename","desig","dept"}, "eid=?",
new
String[]{et1.getText().toString()}, null, null, null);
while (c.moveToNext()) {
13/03/2014
54
55
56
}catch(Exception e){
e.printStackTrace();
}
}
public void getDetails(View v){
// i want to display the employee records in a
Toast message
try{
DocumentBuilderFactory
dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder
db=dbf.newDocumentBuilder();
File f=new
File(Environment.getExternalStorageDirectory()+
"/xml/Employees.xml");
// to parse the file there xml file should be
available with root tag <employees> <
/employees> otherwise create a new document
element
Document d=db.parse(f);
String msg="";
NodeList
nl=d.getElementsByTagName("employee");
for(int i=0;i<nl.getLength();i++){
Node n=nl.item(i);
NodeList nl1=n.getChildNodes();
for(int j=0;j<nl1.getLength();j++){
msg=msg+nl1.item(j).getFirstChild().getNodeVal
ue()+"\n";
}
Toast.makeText(getApplicationContext(), msg,
Toast.LENGTH_LONG).show();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
13/03/2014
57
Toast.makeText(getApplicationContext(),
"Employee Desig
is :"+new String(ch, start, length),
Toast.LENGTH_SHORT).show();
}
if(dept){
Toast.makeText(getApplicationContext(),
"Employee Dept
is :"+new String(ch, start, length),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void endElement(String uri, String
localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, qName);
if(qName.equals("eid")){
eid=false;
}
if(qName.equals("ename")){
ename=false;
}
if(qName.equals("desig")){
desig=false;
}
if(qName.equals("dept")){
dept=false;
}
}
@Override
public void startElement(String uri, String
localName,
String qName, Attributes attributes) throws
SAXException {
// TODO Auto-generated method stub
13/03/2014
58
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="32dp"
android:text = "Enter Name"
android:textAppearance="?android:attr/textApp
earanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="44dp"
android:text = "Enter Password"
android:textAppearance="?android:attr/textApp
earanceMedium" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_marginTop="35dp"
android:layout_toRightOf="@+id/textView2"
android:onClick="Login"
android:text = "Login" />
< EditText
android:id="@+id/editText1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_toRightOf="@+id/button1" >
<requestFocus />
13/03/2014
59
* HttpGet get=new
HttpGet("http://192.168.137.1:8888//rest/welc
ome?
name=mahesh&pass=bened);
*
* InCase of Matrix Parameters
*
* HttpGet get=new
HttpGet("http://192.168.137.1:8888//rest/welc
ome/name:mahesh;pass=bened);
*
*/
// Here I am getting the text/plain as a response
we need add as header
get.addHeader("accept", "text/plain");
/*
* Header are different based on your response if
your getting a image file
* get.addHeader("accept","image/jpg");
* if ur getting a XML as Output
* get.Header("accept","application/xml");
* if ur getting a JSON as Output
* get.Header("accept","application/json");
*/
HttpResponse response=httpClient.execute(get);
InputStream
isr=response.getEntity().getContent();
int i=isr.read();
String msg="";
while(i!=-1){
msg=msg+(char)i;
i=isr.read();
}
Toast.makeText(getApplicationContext(),
"Response from the server is :"+msg,
Toast.LENGTH_LONG).show();
}catch(Exception e){
e.printStackTrace();
13/03/2014
60
61
62
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/toggleButton1"
android:layout_marginLeft="95dp"
android:layout_marginTop="55dp"
android:onClick="getWifiList"
android:text = "getWifiList" />
</RelativeLayout>
WifiExample . java
package com.mahesh.xml;
import ..................;
public class WifiExample extends Activity {
WifiManager wManager;
Button button;
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
wManager=(WifiManager)getSystemService(Con
text.WIFI_SERVICE);
setContentView(R.layout.wifi);
button=(Button)findViewById(R.id.toggleButton
1);
if(wManager.getWifiState()==wManager.WIFI_S
TATE_DISABLED){
button.setText("Wifi On");
}else
if(wManager.getWifiState()==wManager.WIFI_S
TATE_ENABLED){
button.setText("Wifi Off");
}
}
public void Wifi(View v){
if(wManager.getWifiState()==wManager.WIFI_S
TATE_DISABLED){
wManager.setWifiEnabled(true);
button.setText("Wifi Off");
13/03/2014
63
64
}else
if(wManager.getWifiState()==wManager.WIFI_S
TATE_ENABLED){
button.setText("Wifi Off");
}
}
public void Wifi(View v){
if(wManager.getWifiState()==wManager.WIFI_S
TATE_DISABLED){
wManager.setWifiEnabled(true);
button.setText("Wifi Off");
notification=new
Notification(R.drawable.ic_launcher, "Wifi State
Changed",
System.currentTimeMillis());
notification.setLatestEventInfo(getBaseContext()
, "Wifi State Changed","Wifi
Enabled", getPendingIntent());
nManager.notify(1, notification);
vibrator.vibrate(1000);
}else
if(wManager.getWifiState()==wManager.WIFI_S
TATE_ENABLED){
wManager.setWifiEnabled(false);
button.setText("Wifi On");
notification=new
Notification(R.drawable.ic_launcher, "Wifi State
Changed", System.currentTimeMillis());
notification.setLatestEventInfo(getBaseContext()
, "Wifi State
Changed","Wifi Disabled", getPendingIntent());
nManager.notify(1, notification);
vibrator.vibrate(1000);
}
}
private PendingIntent getPendingIntent() {
Intent i=new Intent(getBaseContext(),
WifiExample.class);
13/03/2014
65
66
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location l) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"Latitude value
is :"+l.getLatitude()+"Logitude value is
:"+l.getLongitude(),
Toast.LENGTH_SHORT).show();
} }); }
public void getLocation(View v){
Location
l=lManager.getLastKnownLocation(LocationMan
ager.GPS_PROVIDER);
Toast.makeText(getApplicationContext(),
"Latitude value is :"+l.getLatitude()
+"Logitude value is :"+l.getLongitude(),
Toast.LENGTH_SHORT).show();
}}
ListActivity :
An activity that displays a list of items by binding
to a data source such as an array or Cursor,
and exposes event handlers when the user
selects an item.
ListActivity hosts a ListView object that can be
bound to different data sources, typically either
an
array or a Cursor holding query results. Binding,
screen layout, and row layout are discussed in
the
13/03/2014
67
<TextView id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:text="No data"/>
</LinearLayout>
Base Adapter :
Common base class of common implementation
for an Adapter that can be used in both
ListView (by implementing the specialized
ListAdapter interface} and Spinner (by
implementing the
specialized SpinnerAdapter interface.
Sample Program to display image names in
SDCARD using ListActivity:
package com.mahesh.xml;
import java.io.File;
import ..................;
public class ListActivityTest extends ListActivity{
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String
path=Environment.getExternalStorageDirectory(
)+"/images";
File f=new File(path);
if(f.exists()){
String[] images=f.list();
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_gallery_item,images);
setListAdapter(adapter);
}else{
Toast.makeText(getApplicationContext(), "There
is no file with the given
path",Toast.LENGTH_LONG).show();
13/03/2014
68
import ................;
public class ListActivityImagesActivity extends
ListActivity implements
AdapterView.OnItemSelectedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyAdapter(this));
getListView().setOnItemSelectedListener(this);
}
class MyAdapter extends BaseAdapter{
private LayoutInflater inflater;
private Bitmap icon1;
private String[] files;
String path;
public MyAdapter(ListActivityImagesActivity laia)
{
inflater=LayoutInflater.from(laia);
icon1=BitmapFactory.decodeResource(getResou
rces(),
R.drawable.ic_launcher);
path=Environment.getExternalStorageDirectory(
)+"/images";
File f=new File(path);
files=f.list();
}
public int getCount() {
// TODO Auto-generated method stub
return files.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
13/03/2014
69
70
Toast.makeText(getApplicationContext(),cb1.get
Text(),Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?>
arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
images_names.size(),Toast.LENGTH_LONG).sho
w();
}}
MyAdapter.java :
package com.mahesh.gallery;
import ..................;
public class MyAdapter extends BaseAdapter{
GalleryTestExActivity gta;
LayoutInflater inflater;
String
path=Environment.getExternalStorageDirectory(
)+"/images";
File f=new File(path);
String[] images=f.list();
public MyAdapter(GalleryTestExActivity gtea) {
gta=gtea;
inflater=LayoutInflater.from(gtea);
}
public int getCount() {
return images.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View view,
ViewGroup arg2) {
view=inflater.inflate(R.layout.main, null);
13/03/2014
71
PlaybackComplet
ed, Error}
Successful invoke of this method in a valid state
transfers the object to the Paused state. Calling
this method in an invalid state transfers the
object
to the Error state.
prepare {Initialized,
Stopped}
{Idle, Prepared,
Started, Paused,
PlaybackComplet
ed, Error}
Successful invoke of this method in a valid state
transfers the object to the Prepared state.
Calling
this method in an invalid state throws an
IllegalStateException.
setDataSource {Idle}
{Initialized,
Prepared, Started,
Paused, Stopped,
PlaybackComplet
ed, Error}
Successful invoke of this method in a valid state
transfers the object to the Initialized state.
Callingthis method in an invalid state throws an
IllegalStateExceptionsetVolume
{Idle, Initialized,Stopped, Prepared,
Started, Paused,PlaybackCompleted}
{Error} Successful invoke of this method does
not change the state start{Prepared,
Started,Paused,PlaybackComplete}
{Idle, Initialized,Stopped, Error}
Successful invoke of this method in a valid state
transfers the object to the Started state. Calling
this method in an invalid state transfers the
object to the Error state.stop {Prepared, Started,
13/03/2014
Contact Us
GEOSYS ENTERPRISE SOLUTIONS
Corporate Head Office: 6-3-841/A/2/C-1, III
Floor, Arun Aditya Building, Ameerpet,
Hyderabad, AP-500016
Contact Number:
040-65522333
94938806670
Email Address:
info@geosys.co.in
72
13/03/2014