Tuesday, 23 February 2016

TabView in Android

activitymain.xml


<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

AndroidTabLayoutActivity

package com.raj.tab;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        TabHost tabHost = getTabHost();
     
        // Tab for Photos
        TabSpec photospec = tabHost.newTabSpec("Photos");
        photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
        Intent photosIntent = new Intent(this, PhotosActivity.class);
        photospec.setContent(photosIntent);
     
        // Tab for Songs
        TabSpec songspec = tabHost.newTabSpec("Songs");
        // setting Title and Icon for the Tab
        songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
        Intent songsIntent = new Intent(this, SongsActivity.class);
        songspec.setContent(songsIntent);
     
        // Tab for Videos
        TabSpec videospec = tabHost.newTabSpec("Videos");
        videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
        Intent videosIntent = new Intent(this, VideosActivity.class);
        videospec.setContent(videosIntent);
     
        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab
    }
}


photos_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!-- Screen Design for Photos -->
  <TextView android:text="PHOTOS HERE"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
 
</LinearLayout>

PhotosActivity.java


package com.raj.tab;

import android.app.Activity;
import android.os.Bundle;

public class PhotosActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photos_layout);
    }
}


songs_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!-- Screen Design for the SONGS -->
  <TextView android:text="SONGS HERE"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
</LinearLayout>

SongsActivity.java


package com.raj.tab;

import android.app.Activity;
import android.os.Bundle;

public class SongsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.songs_layout);    }
}

videos_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  
  <!--  Screen Design for VIDEOS -->
  <TextView android:text="VIDEOS HERE"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
</LinearLayout>

VideosActivity.java

package com.raj.tab;

import android.app.Activity;
import android.os.Bundle;

public class VideosActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videos_layout);
    }
}


Androimanifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.raj.tab"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AndroidTabLayoutActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!--  Songs Activity -->
        <activity android:name=".SongsActivity" />
        
        <!--  Videos Activity -->
        <activity android:name=".VideosActivity" />
        
        <!--  Photos Activity -->
        <activity android:name=".PhotosActivity" />

    </application>
</manifest>


Output:







Dynamic Linear Layout in Android

package com.example.dynamiclayout;

import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

LinearLayout ll;
EditText et;
Button bt;

    @SuppressLint("NewApi") @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_main);
       
        ll=new LinearLayout(this);    
        ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);
       
        et=new EditText(this);
        et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        ll.addView(et);
       
        bt=new Button(this);
        bt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        bt.setText("DDDD");
        bt.setTextColor(Color.BLACK);
        ll.addView(bt);
       
       
       
        setContentView(ll);
       
       
    }
}

Share Option in Android

activity_share.XML


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f6546a"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ShareActivityMainActivity" >

    <ImageView
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="28sp"
        android:typeface="serif" />

    <Button
        android:id="@+id/shareit"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_marginTop="40dp"
        android:background="#20b2aa"
        android:drawableRight="@drawable/ic_launcher"
        android:text="Share it"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:typeface="serif" />

</LinearLayout>

ShareActivity.Java



package com.example.share;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;



public class ShareActivity extends Activity {


   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_share);
     
       System.out.println("HIII");

       Button btn_share=(Button)findViewById(R.id.shareit);
       btn_share.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
           
            System.out.println("ggvhj");
               shareIt();
           }
       });
   }
   private void shareIt() {
//sharing implementation here
       Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
       sharingIntent.setType("text/plain");
       sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AndroidSolved");
       sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Now Learn Android with AndroidSolved clicke here to visit https://androidsolved.wordpress.com/ ");
       startActivity(Intent.createChooser(sharingIntent, "Share via"));
   }

   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
       // Handle action bar item clicks here. The action bar will
       // automatically handle clicks on the Home/Up button, so long
       // as you specify a parent activity in AndroidManifest.xml.
       int id = item.getItemId();

       //noinspection SimplifiableIfStatement
       if (id == R.id.action_settings) {
           return true;
       }

       return super.onOptionsItemSelected(item);
   }
}

Manifest.XML


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.share"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ShareActivity"
            android:label="@string/raj"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.raj.MainActivity"
            android:label="@string/title_activity_main" >
        </activity>
    </application>

</manifest>

Output:



Monday, 22 February 2016

alertdialog android example

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alert Dialogue Demo" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="45dp"
        android:text="click" />

</RelativeLayout>

MainActivity.java


package com.example.alertdialog;

import android.animation.AnimatorSet.Builder;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {


final Context context = this;
private Button button;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = (Button) findViewById(R.id.button1);

// add button listener
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);

// set title
alertDialogBuilder.setTitle("Your Title");

// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
 })
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();

// show it
alertDialog.show();
}
});
}
}


Output:



Progress Dialog in Android

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Progress Dialog Demo" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="59dp"
        android:layout_toRightOf="@+id/textView1"
        android:text="Button"
        android:onClick="download" />

</RelativeLayout>


MainActivity.Java


package com.example.progressbar;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
Button b1;
  private ProgressDialog progress;
  
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     b1 = (Button) findViewById(R.id.button1);
     
    
  }
  
  public void download(View view){
     progress=new ProgressDialog(this);
     progress.setMessage("Downloading Music");
     progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
     progress.setIndeterminate(true);
     progress.setProgress(0);
     progress.show();
     
     final int totalProgressTime = 100;
     final Thread t = new Thread() {
        @Override
        public void run() {
           int jumpTime = 0;
           
           while(jumpTime < totalProgressTime) {
              try {
                 sleep(200);
                 jumpTime += 5;
                 progress.setProgress(jumpTime);
              }
              catch (InterruptedException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
              }
           }
        }
     };
     t.start();
  }
}


Output:




in MainActivity.java just am changing the style in below line.

Instead of this line
 progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

am putting below line so out is :
  progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);



Rating Bar example

Activity Main.XML


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="24dp" 
        android:numStars="4"
        android:rating="1.0" 
         android:stepSize="0.5"/>
    
    
    

</RelativeLayout>



ActiviyMain.XML


package com.example.ratingbars;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}


Strings.XML


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Rating Bars</string>
    <string name="hello_world">Rating Bar Example</string>

</resources>

Manifest.XML


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ratingbars"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Output









Monday, 15 February 2016

Android Course Content

Introduction 

a. Introduction to Mobile Operating systems
b. Manufacturer-built proprietary Operating systems
c. Third party proprietary Operating systems
d. Free &open source Operating systems

Android Programming Platform 

a. A Brief History of the Android Platform
b. Google and the Open Handset Aliance announce Android Open source Availability
c. Android Platform Versions-API Levels
d. Android Features
e. Android Architecture

Android SDK(Software Development Kit)

a. Emulator (Android Virtual Device)
b. Android Debug Bridge
c. Application Components
d. Preparing Development Environment &Creating  “Hello World”  Program
e. Settingup the Development Environment
f. Settingup the Android SDK
g. Installing Eclipse
h. A Quick Tour of Eclipse
i. Workspace
j. Hello World, Android Style
k. Creating Project
l. Creating an Android Virtual Device
m. Logcat & DDMS

        Manifest and Activities

a. Inside the Manifest
b. Structure of Manifest file File

Android Components

a. Activities
b. Services
c. Broadcast Receivers
d. Content Provider

File Features

a. Intent
b. Intent Filters
c. Icons & Labels
d. Permissions

  User Interface

a. User interface Layout
b. User interface Components
c. Basic Layouts
d. Attribute
e. ID
f. Layout Parameters
g. Size,Padding & Margins
h. Common Layouts
i. Handling Click Events

Layouts 

a. Linear Layout
b. Relative Layout
c. Absolute Layout
d. Frame Layout
e. Table Layout
f. Scroll View
g. ListView
h. GridView
i. Input Controls
j. Common Controls

Buttons & Views

a. Responding to Click Event
b. Using an OnClick Listener
c. Styling the Button
d. Text Fields
e. Checkbox
f. Radio Buttons
g. Spinner
h. Pickers

Notification & Toast


a.Creating a Simple Notification

b.Managing Notifications

c.Settingup a reguler Activity Pending Intent

d.Displaying Progress in a Notification

e.Custom Notification Layouts

Toast


f.   Positioning the toast

g.  Alert Dialogue

h. Progress Dialogue

Menus


a. Styles and themes
b. Style Properties
c. Applying Styles and themes to the UI

Data Storage


a. Shared Preferences
b. Internal Storage
c. External Storage
d. SQ Lite Databases
e. Network Connection

Maps Integration


a. Intro to Maps
b. Android location API
c. Location Manager and Provider
d. Security
e. Using Android location to API
f. Creating API Key
g. MapView


Animations & Graphics


a. Android animated GIF image example
b. Screenshot
c. Graphics

Web Services

a. JSON implementation
b. Rest full web services
c. Xml Parsing

Publishing Android application to the market








Ads Inside Post