Monday, 15 September 2014

How to use TableLayout and simple demo with conversions

yes, we will demonstract here for conversion, Integer.Parse
package com.andriodproject.helloandriod;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity  implements OnClickListener
{
   EditText edt1;
   EditText edt2;
   int result;
   TextView tvresult;
   Button btnadd,btnsubstract,btnexit;
int total;

   @Override
         protected void onCreate(Bundle savedInstanceState)
   {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
       
         edt1=(EditText)findViewById(R.id.editText1);
         edt2=(EditText)findViewById(R.id.editText2);
       
         tvresult=(TextView)findViewById(R.id.textView3);
       
         btnadd=(Button)findViewById(R.id.btn_add);
         btnsubstract=(Button)findViewById(R.id.btn_sub);
         btnexit=(Button)findViewById(R.id.btn_exit);
         btnadd.setOnClickListener(this);
         btnsubstract.setOnClickListener(this);
         btnexit.setOnClickListener(this);
   }
@Override
public void onClick(View v)
{
if(v==btnexit)
{ finish();
}
else
{
String first=edt1.getText().toString().trim();
String second=edt2.getText().toString().trim();
if(first.length()<=0)
{
tvresult.setText("Enter First No");
       edt1.requestFocus();
return;
}
if(second.length()<=0)
{
tvresult.setText("Enter second No");
       edt2.requestFocus();
         return;
}
try
{
  int a=Integer.parseInt(first);
  int b=Integer.parseInt(second);                                                                   if(v==btnadd)
                                    total=a+b;
else if(v==btnsubstract)
total=a-b;
  tvresult.setText(String.valueOf(total));
}
catch(Exception ex)
{
tvresult.setText("error occured");
}
}

}
}

Sunday, 14 September 2014

Layouts : Relative,Linear,Grid,Table,TableRow


Android Provides few layouts for structure  user interface such a Linear,Relative,Grid,Table,Frame layouts

by default main activity contains Relative layout, Relative layout provides advantage is 

 we can place our components/views like one another other, one below another. however we need, but we need to specify with respect another view or parent. 

 Relative layout is good customized layout for all our components/views. 

1. Place view center of the relative layout.

andriod:layout_centerInParent, Vertical,Horizontal---are true/false /

 In Java[ Center_IN_Parent,     Center_Vertical,   Center_Horizontal].

2. Alignment between view with its parent edge

android:layout_alignParentTop                     // ALIGN_PARENT_TOP
android:layout_alignParentButtom               // ALIGN_PARENT_BUTTOM
android:layout_alignParentLeft                    // ALIGN_PARENT_LEFT
android:layout_alignParentRight                 //  ALIGN_PARENT_RIGHT
















3. Alignment between the views using 

android:layout_above
android:layout_below
android:layout_toLeftOf
android:layout_toRightOf

android:layout_below="@id/textView1"   ----then button is place below the textview control.

4. Define alignment between 2 views
 android:layout_alignTop/Button,Left,Right,Baseline.


Relative layout doesn't provides weight and gravity properties to align them like linear layout.

Linear layout : by placing views and specifing weight to same value, all views has same size or width. linear layout can be horizontal or vertical.

Gridlayout: which has rowscount and columcount values to specify the size of Gird. 

Grid lines are reference with indices, based on our need we will place them in respective cells/rows in the grid layout.

Framelayout is place holder for view or viewgroup.in this also all views are bydefault place to top left. using gravity enum we can specify : center,right,left.

Tablelayout to represent the views in table format.



Wednesday, 10 September 2014

Andriod register events and implementation


Android provides controls as components to design our application layout. in eclipse palette provides various categories of components : TextFileds,Layouts,Composite, Images & Media , Date and time.Tansitions,,ect

Layouts: these are main controls/components to design screen/activity UI. using respective layout contorl(Grid,Linear,Relative,Frame,Table,TableRow,Fragement,Space).


in this we created/default design layout is RelativeLayout, in that we place button and editText controls/components in Relativelayout. andriod.layout_below: order of control placed in layout/relativelayout.

in Code of  MainActivity.we need refer these components, so that we need find these control. then handling/registering the events.


here we casted 2 ways --1 is view casting && 2nd is direct casting to repective control(EditText) type. next article is types of layouts.

2nd implementation:

       Button b1;
       TextView tv;

        tv=(TextView)findViewById(R.id.textView1);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {
       public void onClick(View v)
       {
        tv.setText("welcome to android");
       }});
     
         }
3rd implementation

        Button b1;
        TextView tv;
   
            protected void onCreate(Bundle savedInstanceState)
   {
                     super.onCreate(savedInstanceState);
                     setContentView(R.layout.activity_main);
                     tv=(TextView)findViewById(R.id.textView1);
                     b1=(Button)findViewById(R.id.button1);
                     b1.setOnClickListener(myhandler1);  ****
   }    
   OnClickListener myhandler1 = new View.OnClickListener()
   {
       public void onClick(View v) {        
        tv.setText("welcome to androids");
       }
     };
     
4th implementation : declare funcation in Code & at activity_main.xml

  <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_first" android:onClick="ButtonOnClick" />


     


type castings: View is base type

View v=findViewById(R.id.button1);
Button b=(Button)v;
or 
Button b=(Button)findViewById(R.id.button1);

public void onClick(View v)
{
   if(v==b1)
       tv.setText("Button-1 Clicked");
        else if(v.getId()==R.id.button2)
       tv.setText("Button-2 Clicked");
else
     finish();
 }


Sunday, 7 September 2014

How to Create Andriod Project : Hello Andriod

In this article we will discuss about "How to Create Andriod Project using Eclipse"

we have no'f tools to develop andriod applications like eclipse,visual stuido, andriod studio, presently i am using eclipse.--open eclipse--File--New --Andriod Application Project


in this we specified

Application name :  name of application display in tablet or mobile.

Project name :  which creates a folder at andriod workspace.

package name : which our package/library for Currently implementation code is packaged into to it.

Min SDK :  lowest version of our application supports.
Max SDK : highest version of our application supports.
Compile with : Andriod runtime for execution code.
Theme :  theme is to support for good design.


Activity name and custom/predefined logo && location of project ---giving option/control to developer as optionals.



then, we can create our own custom text and images/logos or utilize andriod supported images also.
and select one of templet of andriod predefined templets as per our requirements. example our project requires any actionbar support ---choose--Actionbar templet this below image does has that templet.



these templets are available based our ---project creation environment(Min,Max SDK's, compile...ect).--our first above image project settings.

once andriod project is created :
in this project structure : we have

src:-  implementation as a package // com.andriodproject.helloandriod.

gen:- our source code written in java language
      com.andriodproject.helloandriod
         -R.java. // deleted by our self--andriod runtime will create automatically every time.

Andriod 4.2.2
       andriod .jar file. which has predefined packages, which placed under

G:\Softwares\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-19

this platfrom is selected by it self eclipse editor while choosing 

Complie with : API level--below .jar file will be andriod runtime will take the platfrom of apporiarite envirnoment for andriod project compliation.

G:\Softwares\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-19
G:\Softwares\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20
G:\Softwares\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-L

so that once the project is created with Min and Max SDK, then we simple changes in AndriodManifest.xml.--> also project will not run because the the project platfrom/compile platfrom for execution excepting respective .jar file. otherwise "unable to resolve target andriod-8"

bin : andriod apk & manfiest.xml

res : which has various sub folders as per our application resources we need to take respective folders and design the application.

layouts, values, colors,,...ect  base on resources.

Activity Name : MainActivity
Layout Name   : activity_main      //  graphical style and activity_main.xml.





this is best pratice to declare variables/string values in Values folder. for accessing styles, string values,images,colors...base on type of resource define respective resource files in respective folders.

How these values are accessed through xml to R.java file.

activity_main.xml
strings.xml
styles.xml



strings.xml

<resources>
    <string name="app_name">HelloAndriod</string>
    <string name="hello_world">Hello world!</string>
    <string name="hello_demo">Welcome to android!</string>
</resources>

MainActivity.java



then these variables / resources accessble in java program as like

R.string.hello_world
R.string.hello_demo
R.string.app_name
R.drawable.andriod

setContentView(R.layout.activity_main);    as well

R.java

        public static final int activity_main=0x7f030018;
        public static final int app_name=0x7f0a000d;
        public static final int hello_demo=0x7f0a000f;
        public static final int hello_world=0x7f0a000e;


Sunday, 24 August 2014

Introduction to Mobile applications

Yes, an application which is installed in mobile operating system is called mobile application,simply called as mobile app's. now we have various mobile operating systems available(Andriod,IOS,Windows) are widely used operating systems.
                         All these operating systems/various platforms has their own runtimes, specifications to run the mobile applications.

Ex : Mobile operating systems : 1andriod platfrom ,
                                                2. ios platform,
                                                3.windows platform

every operating system has their native run time to run the mobile application. so that if we need an application for these operating systems. we have 2 options

1. Individual applications to develop using

   Andriod platform----------using Java language ---using eclipse/andriod studio editors
   IOS platform--------------using Objective-c -----using XCode editor
   Windows platfrom---------using C# or xaml-----using Visual studio.

2. Hybrid/Cross mobile applications(write once, deploy any device)

   1. Phonegap--------Html5,Javascript,CSS, & Phonegap API or Cordova

   Phone gap is open source API to develop an application which run in all mobile platfoms(andriod,windows,ios).

   2.  Xamarin---------using C# language-----xamarin studio or visual studio extension.
 
  Xamarin is not open source which has various editions to develop mobile hybrid apps. which generates respective native app code to other platfroms. xamarin is excepts C# language to develop the mobile applications.

these are currently available mobile platroms,languages,editors to develop mobile applications(mobile app's).

now we learn Andriod,IOS,Windows applications then Cross platform/Hybrid apps.

Andriod:

Andriod is a mobile plafrom/os run the applications, save the informations. Andriod has it's architecture.



Android Architecture



Andriod is Stack based architecture of operating system. it has 4 parts

1. Linux Kernal
2. Libraries & Runtime      
3. Application Framework   // for developing user defined apps
4. Applications.                   // built in apps.

Linux Kernal
               andriod operating system is modified linux operating system. which provides abstraction service to run andriod applications. this is abstraction layer to run the applications on andriod envirnoment/platrom/os.

Libraries
             libraries are built in services to run in-built and custom applications to in andriod envirnoment.
\
Application framework
            which provides built in framework to develop custom applications using java.
Applications
            Andriod operting system provides few built in applications like contacts,galary,calcualtor...ect

this is basic overview of andriod operating system. Andriod API(Name,Version,Code)provides few services which helps to develop the applicaions as early.more productively.