Thursday 13 October 2011

Android Simple calculator program

This is a small calculator program for beginners.With this program you can learn adding buttons to UI,adding sliders to UI.This program uses simple functions like add(),sub(),div(),mul().
JAVA CODE
package simple.calculator;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class SimpleCalculatorActivity extends Activity {
private EditText txtinput1;
private EditText txtinput2;
private EditText txtinput3;
private Button buttonte;
private Button buttonte1;
private Button buttonte2;
private Button buttonte3;
private Button buttonte46;
private Button buttonte47;
private Button buttonte48;
private Button buttonte49;
private Button buttonte50;
private Button buttonte51;
private Button buttonte52;
private Button buttonte53;
private Button buttonte54;
private Button buttonte55;
private ImageView imageView;
private double input1 =0;
private double input2 =0;
private double input3 =0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calc);
initctrls();}
public void onCreate1(Bundle bundle) {
super.onCreate(bundle);
/**Hello World Image JFD*/
/**BEGIN */
/**Create the ImageView */
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
imageView.setImageResource(R.drawable.icon);
/**Set the ContentView to the ImageView */
setContentView(HelloWorldImageView);
/**END*/}
private void initctrls(){
txtinput1 = (EditText)findViewById(R.id.widget41);
txtinput2 = (EditText)findViewById(R.id.widget43);
txtinput3 = (EditText)findViewById(R.id.widget45);
buttonte = (Button)findViewById(R.id.widget56);
buttonte1 = (Button)findViewById(R.id.widget57);
buttonte2 = (Button)findViewById(R.id.widget58);
buttonte3 = (Button)findViewById(R.id.widget59);
buttonte46 = (Button)findViewById(R.id.widget46);
buttonte47 = (Button)findViewById(R.id.widget47);
buttonte48 = (Button)findViewById(R.id.widget48);
buttonte49 = (Button)findViewById(R.id.widget49);
buttonte50 = (Button)findViewById(R.id.widget50);
buttonte51 = (Button)findViewById(R.id.widget51);
buttonte52 = (Button)findViewById(R.id.widget52);
buttonte53 = (Button)findViewById(R.id.widget53);
buttonte54 = (Button)findViewById(R.id.widget54);
buttonte55 = (Button)findViewById(R.id.widget55);
buttonte.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ add(); }});
buttonte1.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ sub(); }});
buttonte2.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ mul(); }});
buttonte3.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ div(); }});
buttonte46.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(1); }});
buttonte47.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(2); }});
buttonte48.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(3); }});
buttonte49.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(4); }});
buttonte50.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(5); }});
buttonte51.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(6); }});
buttonte52.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(7); }});
buttonte53.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(8); }});
buttonte54.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(9); }});
buttonte55.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(0); }});
txtinput1.setInputType(InputType.TYPE_CLASS_NUMBER);
txtinput2.setInputType(InputType.TYPE_CLASS_NUMBER);
txtinput3.setInputType(InputType.TYPE_CLASS_NUMBER);}
void num(int y){
// int i =Integer.parseInt(txtinput1.getText().toString());
if(txtinput1.isFocused()){
txtinput1.append(String.valueOf(y));}
if(txtinput2.isFocused()){
txtinput2.append(String.valueOf(y));}
// txtinput1.setText("1");
// txtinput2.setText("1");}
private void add(){
input1=Double.parseDouble(txtinput1.getText().toString());
input2=Double.parseDouble(txtinput2.getText().toString());
input3 = (input1+input2);
txtinput3.setText(Double.toString(input3));}
private void sub(){
input1=Double.parseDouble(txtinput1.getText().toString());
input2=Double.parseDouble(txtinput2.getText().toString());
input3=(input1-input2);
txtinput3.setText(Double.toString(input3));}
 private void mul(){
input1=Double.parseDouble(txtinput1.getText().toString());
input2=Double.parseDouble(txtinput2.getText().toString());
input3=(input1*input2);
txtinput3.setText(Double.toString(input3));}
private void div(){
input1=Double.parseDouble(txtinput1.getText().toString());
input2=Double.parseDouble(txtinput2.getText().toString());
input3=(input1/input2);
 txtinput3.setText(Double.toString(input3));}}
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">
 <ScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">
<AbsoluteLayout android:id="@+id/AbsoluteLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
<AbsoluteLayout android:id="@+id/AbsoluteLayout1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I1"
android:layout_x="15px"
android:layout_y="16px">
</TextView>
<EditText android:id="@+id/widget41"
android:layout_width="350px"
android:layout_height="80px"
android:inputType="number"
android:text=""
android:textSize="18sp"
android:layout_x="40px"
android:layout_y="16px">
</EditText>
<TextView android:id="@+id/widget42"
android:layout_width="350px"
android:layout_height="wrap_content"
android:text="I2"
android:layout_x="15px"
android:layout_y="100px">
</TextView>
<EditText android:id="@+id/widget43"
android:layout_width="350px"
android:layout_height="80px"
android:text=""
android:textSize="18sp"
android:layout_x="40px"
android:layout_y="90px">
</EditText>
<TextView android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="28px"
android:text="Output"
android:layout_x="2px"
android:layout_y="190px">
</TextView>
<EditText android:id="@+id/widget45"
android:layout_width="425px"
android:layout_height="80px"
android:text=""
android:textSize="18sp"
android:layout_x="19px"
android:layout_y="205px">
</EditText>
<Button android:id="@+id/widget46"
android:layout_width="55px"
android:layout_height="55px"
android:text="1"
android:layout_x="40px"
android:layout_y="323px">
</Button>
<Button android:layout_width="55px"
android:layout_height="55px"
android:text="2"
android:layout_x="138px"
android:layout_y="321px"
android:id="@+id/widget47">
</Button>
<Button android:id="@+id/widget48"
android:layout_width="55px"
android:layout_height="55px"
android:text="3"
android:layout_x="236px"
android:layout_y="321px">
</Button>
<Button android:id="@+id/widget49"
android:layout_width="55px"
android:layout_height="55px"
android:text="4"
android:layout_x="40px"
android:layout_y="383px">
</Button>
<Button android:id="@+id/widget50"
android:layout_width="55px"
android:layout_height="55px"
android:text="5"
android:layout_x="138px"
android:layout_y="381px">
</Button>
<Button android:id="@+id/widget51"
android:layout_width="55px"
android:layout_height="55px"
android:text="6"
android:layout_x="236px"
android:layout_y="381px">
</Button>
<Button android:id="@+id/widget52"
android:layout_width="55px"
android:layout_height="55px"
android:text="7"
android:layout_x="40px"
android:layout_y="443px">
</Button>
<Button android:id="@+id/widget53"
android:layout_width="55px"
android:layout_height="55px"
android:text="8"
android:layout_x="138px"
android:layout_y="441px">
</Button>
<Button android:id="@+id/widget54"
android:layout_width="55px"
android:layout_height="55px"
android:text="9"
android:layout_x="236px"
android:layout_y="441px">
</Button>
<Button android:id="@+id/widget55"
android:layout_width="55px"
android:layout_height="55px"
android:text="0"
android:layout_x="138px"
android:layout_y="501px">
</Button>
<Button android:layout_width="105px"
android:layout_height="55px"
android:text="+"
android:layout_x="361px"
android:layout_y="321px"
android:id="@+id/widget56">
</Button>
<Button android:id="@+id/widget57"
android:layout_width="105px"
android:layout_height="55px"
android:text="-"
android:layout_x="361px"
android:layout_y="381px">
</Button>
<Button android:id="@+id/widget58"
android:layout_width="105px"
android:layout_height="55px"
android:text="*"
android:layout_x="361px"
android:layout_y="441px">
</Button>
<Button android:id="@+id/widget59"
android:layout_width="105px"
android:layout_height="55px"
android:text="/"
android:layout_x="361px"
android:layout_y="501px">
</Button>
<ImageView android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="-5dip"
android:layout_y="380dip"
android:id="@+id/imageView1">
</ImageView>
</AbsoluteLayout>
</AbsoluteLayout>
</ScrollView>
</HorizontalScrollView>
</AbsoluteLayout>                                                      

Friday 16 September 2011

Installing new apk in android emulator using ubuntu.

Steps: Before installation
1.Go to sdk/platform-tools
Cmd:   cd  /home/android-sdk/platform-tools
2. List the devices
Cmd:   ./adb devices
Ex:    ./adb devices
List of devices attached
emulator-5554    device

3.To install
Cmd:  ./adb install .filename.apk
Ex:   ./adb install AndExplorer.apk
1083 KB/s (338651 bytes in 0.305s)
pkg: /data/local/tmp/AndExplorer.apk
Success

Steps: After installation.
tec@tec-G41M-Combo:~$ sudo su
root@tec-G41M-Combo:/home/tec# cd /home/tec/
root@tec-G41M-Combo:/home/tec# chmod 777 -R android-sdk-linux_x86/
root@tec-G41M-Combo:/home/tec# clear
root@tec-G41M-Combo:/home/tec# cd android-sdk-linux_x86/platform-tools/
root@tec-G41M-Combo:/home/tec/android-sdk-linux_x86/platform-tools# ls3dspusbbus dexdump  Maid with the Flaxen Hair.mp3
3dspusbwlan.ko     dhd.ko         NOTICE.txt
3dspusbwlanpriv    dmesg.log      Ny
aapt               dmesg_mod.txt  pdf
adb                dmesg.txt      sample
aidl               drive          Sleep Away.mp3
apps               Driver         source.properties
binary             driver_src     test2
BlueW-2310U_2.0.0  dx             untitled folder
con                img            uwb
config             lib            uwbtest
config~            llvm-rs-cc     wlan
root@tec-G41M-Combo:/home/tec/android-sdk-linux_x86/platform-tools# ./adb devices
List of devices attached
emulator-5554    offline
root@tec-G41M-Combo:/home/tec/android-sdk-linux_x86/platform-tools# ./adb devices
List of devices attached
emulator-5554    device
root@tec-G41M-Combo:/home/tec/android-sdk-linux_x86/platform-tools# ./adb install AndExplorer.apk
1083 KB/s (338651 bytes in 0.305s)
    pkg: /data/local/tmp/AndExplorer.apk
Success

Sunday 24 April 2011

Android Platform Debugging:

Process For Platform Debugging:
Steps:
* Get into the Source Root folder and type environment setup command ------>  "source build/envsetup.sh"
* Choose which target to build with lunch. The exact configuration can be passed as an argument ----> "lunch"
* Build the source by make command -------> "make"
Emulator launching:
* once the build is over launch the emulator with following instruction
For emulator without keypad:
"sudo out/host/linux-x86/bin/emulator -system out/target/product/generic -kernel prebuilt/android-arm/kernel/kernel-qemu -data out/target/product/generic/userdata.img"
For emulator with keypad:
"out/host/linux-x86/bin/emulator -data out/target/product/generic/userdata.img"
Using Eclipse:
* Go to the eclipse Folder and launch Eclipse -------> ./eclipse.
* copy the .classpath file from "development/ide/eclipse" to root folder. get into your source root folder then type the following with "." in end  --------->  "cp development/ide/eclipse/.classpath ."
* Then "chmod u+w .classpath"
* now the .classpath file is copied. To check list all the files on root folder and find the .classpath file on
that -------> "ll"
* In eclipse now create a new java project   new --> javaproject --> import --> source(path)
* Check weather source included without any error.
* If you are getting following error "
1) 'out/target/common/obj/JAVA_LIBRARIES/google-common_intermediates/javalib.jar'
Generic-Android         Build path      Build Path Problem "
* If u get the problem .jar(out/target/common/obj/JAVA_LIBRARIES/google-common_intermediates/javalib.jar)  change above jar name to "out/target/common/obj/JAVA_LIBRARIES/android-common_intermediates/javalib.jar" on .classpath.
2) 'out/target/common/obj/JAVA_LIBRARIES/gsf-client_intermediates/javalib.jar'
Generic-Android         Build path      Build Path Problem
* If u get the problem .jar file error just delete that line on .classpath.
once these error is closed you may get error on  "com.android.providers.calendar,   com.android.providers.contacts "
* To solve that error we need to import "EventLogTags.java" to their corresponding packages.
1) For error on    "com.android.providers.calendar" eventlogtags  right click on that package  new --> file -->advanced --> link to file in the filesystem --> browse ..your source root -->out -->target --> common -->obj -->Apps -->calenderprovider_intermediates -->srs --> src --> com -->android --> providers --> calender -->EventLogTags.java
2) For error on    "com.android.providers.contacts" eventlogtags  right click on that package  new --> file -->advanced --> link to file in the filesystem --> browse ..your source root -->out -->target --> common -->obj -->Apps -->contactsprovider_intermediates -->srs --> src --> com -->android --> providers --> contacts -->EventLogTags.java
* clean and refresh and build again.
* launch the emulator in another terminal shell.
ddms setup:
* in eclipse goto run --> Debug configuration --> Remote java application --> new
* In project name give your source name.
* Change the port number to 8700 and click Debug.
* Open new terminal shell and start ddms. goto root folder and type ddms.
* Select the process to debug and start debug.

Tuesday 12 April 2011

ANDROID DEBUGGING

PROCEDURE TO CONNECT  GDB CLIENT AND SERVER
RUN THIS COMMAND ON THE DEVICE
COMMAND:

gdbserver :5039 /system/bin/executable
EX:gdbserver :5039 /system/bin/bluetoothd
ON THE HOST MACHINE FORWARD PORT 5039 TO DEVICE WITH ADB

COMMAND:adb forward tcp:5039 tcp:5039
TRY STARTING SPECIAL VERSION OF GDB IN THE PATH "prebuilt" area of the source tree

COMMAND:prebuilt/Linux/
toolchain-eabi-4.2.1/bin/arm-eabi-gdb
RUN FIND IN YOUR SOURCE TREE

COMMAND:
prebuilt -name arm-eabi-gdb
SPECIFY THE PATH FOR REFERENCE

COMMAND:prebuilt/Linux/toolchain-eabi-4.2.1/bin/arm-eabi-gdb  out/target/product/product-name/symbols/system/bin/executable
IN GDB,SPECIFY WHERE TO FIND THE SHARED LIBRARIES THAT WILL GET LOADED:

COMMAND:set solib-absolute-prefix /absolute-source-path/out/target/product/product-name/symbols
set solib-search-path /absolute-source-path/out/target/product/product-name/symbols/system/lib

EX:set solib-absolute-prefix /home/parthiban/mydroid//out/target/product/generic/symbols
set solib-search-path /home/parthiban/out/target/product/generic/symbols/system/lib
absolute-source-path is the path to your source tree; for example, /work/device or /Users/hoser/android/device.
product-name is the same as above; for example, sooner.
CONNECT TO DEVICE BY ISSUING THE GDB COMMAND:
target remote :5039
ALLOW SHARED
COMMAND:
shared

PLEASE POST YOUR DOUBTS AND COMMENTS