Powered By Blogger

Wednesday, 7 March 2012

Android And its Version


What Is Android?
Android is a mobile operating system that is based on a modified version of Linux. It was originally
developed by a startup of the same name, Android, Inc. In 2005, as part of its strategy to enter the
mobile space, Google purchased Android and took over its development work (as well as its development
team).
Google wanted Android to be open and free; hence, most of the Android code was released under
the open-source Apache License, which means that anyone who wants to use Android can do so by
downloading the full Android source code. Moreover, vendors (typically hardware manufacturers)
can add their own proprietary extensions to Android and customize Android to differentiate their
products from others. This simple development model makes Android very attractive and has thus
piqued the interest of many vendors. This has been especially true for companies affected by the phenomenon
of Apple’s iPhone, a hugely successful product that revolutionized the smartphone industry.
Such companies include Motorola and Sony Ericsson, which for many years have been developing
their own mobile operating systems. When the iPhone was launched, many of these manufacturers
had to scramble to find new ways of revitalizing their products. These manufacturers see Android as
a solution — they will continue to design their own hardware and use Android as the operating system
that powers it.
The main advantage of adopting Android is that it offers a unified approach to application development.
Developers need only develop for Android, and their applications should be able to run on numerous
different devices, as long as the devices are powered using Android. In the world of smartphones, applications
are the most important part of the success chain. Device manufacturers therefore see Android
as their best hope to challenge the onslaught of the iPhone, which already commands a large base of
applications.
Android Versions
Android has gone through quite a number of updates since its first release. Table 1-1 shows the various
versions of Android and their codenames.
Tab le 1-1: A Brief History of Android Versions
Android Version Releas e Da te Codename
1.1 9 February 2009
1.5 30 April 2009 Cupcake
1.6 15 September 2009 Donut
2.0/2.1 26 October 2009 Eclair
2.2 20 May 2010 Froyo
2.3 6 December 2010 Gingerbread
3.0 Unconfirmed at the time of writing Honeycomb

Features of Android



As Android is open source and freely available to manufacturers for customization, there are no fixed
hardware and software configurations. However, Android itself supports the following features:
➤➤ Storage — Uses SQLite, a lightweight relational database, for data storage. Chapter 6 discusses
data storage in more detail.
➤➤ Connectivity — Supports GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (includes
A2DP and AVRCP), WiFi, LTE, and WiMAX. Chapter 8 discusses networking in more detail.
➤➤ Messaging — Supports both SMS and MMS. Chapter 8 discusses messaging in more detail.
➤➤ Web browser — Based on the open-source WebKit, together with Chrome’s V8 JavaScript engine
➤➤ Media support — Includes support for the following media: H.263, H.264 (in 3GP or MP4
container), MPEG-4 SP, AMR, AMR-WB (in 3GP container), AAC, HE-AAC (in MP4 or
3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP
➤➤ Hardware support — Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor,
and GPS
➤➤ Multi-touch — Supports multi-touch screens
➤➤ Multi-tasking — Supports multi-tasking applications
➤➤ Flash support — Android 2.3 supports Flash 10.1.
➤➤ Tethering — Supports sharing of Internet connections as a wired/wireless hotspot

Wednesday, 29 February 2012

Animation in android


import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class AnimationEx extends Activity {
    /** Called when the activity is first created. */
 
Button b1;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
parentButtonClicked(v);
/*ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.ani);
AnimationDrawable ad=(AnimationDrawable)img.getBackground();
*/


}
       
        });
    }
    private void parentButtonClicked(View v)
    {
    animate();
    }
    private void animate()
    {
    ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.ani);
AnimationDrawable ad=(AnimationDrawable)img.getBackground();
if(ad.isRunning())
{
ad.stop();
b1.setText("start");
}
else
{
ad.start();
b1.setText("stop");
}


   
    }
}



anim.xml in drawable folder in same folder were your picture or snaps are kept


<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/icon"
android:duration="550" />
<item
android:drawable="@drawable/anim"
android:duration="550" />
<item
android:drawable="@drawable/cute"
android:duration="550"></item>
<item
android:drawable="@drawable/dolphin"
android:duration="550"></item>
<item
android:drawable="@drawable/man"
android:duration="550"></item>
</animation-list>

Monday, 27 February 2012

Sms via Intent


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

public class SmsIntent extends Activity {
    /** Called when the activity is first created. */
   
Button b1;
EditText et,et1;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        et=(EditText)findViewById(R.id.editText1);
        et1=(EditText)findViewById(R.id.editText2);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String no=et.getText().toString();
String mssg=et1.getText().toString();
Intent i=new Intent(android.content.Intent.ACTION_VIEW);
i.putExtra("address",no);
i.putExtra("message", mssg);
i.setType("vnd.android-dir/mms-sms");
startActivity(i);

}
       
        });
    }

SmsReceiver.java


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle b=intent.getExtras();
SmsMessage[] msg=null;
String str="";
if(b!=null)
{
Object[] p=(Object[])b.get("pdus");
msg=new SmsMessage[p.length];
for(int i=0;i<msg.length;i++)
{
msg[i]=SmsMessage.createFromPdu((byte[])p[i]);
str+="sms from"+msg[i].getOriginatingAddress();
str+=":";
str+=msg[i].getMessageBody().toString();
str+="\n";
}
Toast.makeText(context,str,Toast.LENGTH_LONG).show();
}

}

ProgressBar


import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ProgressBar extends Activity {

//String items[]={"Googel","Appel","MacBook"};
//boolean[] itemchecked= new boolean[items.length];
/*ProgressThread progthread;
ProgressThread progThread;
*/
ProgressDialog progressdialog;
int progress=0;
Handler progresshandler;
Button b1;
Dialog dialog;
static int maxBarValue = 200;
//ProgressThread progressthread;
//protected Message Message;
    /** Called when the activity is first created. */
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        progresshandler=new Handler()
        {
        public void handleMessage(Message msg)
        {
        super.handleMessage(msg);
        if (progress >= 100) {
        Toast.makeText(getApplicationContext(),"Sucess!!", Toast.LENGTH_LONG).show();
        progressdialog.dismiss();
        } else {
        progress++;
        progressdialog.incrementProgressBy(1);
        progresshandler.sendEmptyMessageDelayed(0, 100);
        }
        }
       
        };
       
       
       
 
       
       
       
       
     
       
        progressdialog=new ProgressDialog(this);
        progressdialog.setTitle("Downloading files");
        progressdialog.setProgressStyle(progressdialog.STYLE_HORIZONTAL);
        progressdialog.setButton(DialogInterface.BUTTON_POSITIVE,"Hide",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Hide Clicked!!",Toast.LENGTH_LONG).show();
}
});
        progressdialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel Clicked!!",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Cancel Clicked!!",Toast.LENGTH_LONG).show();

}
});
       
           
       
     
       
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {

@Override
public void onClick(View v) {
progressdialog.show();
progress=0;
/*Thread t=new Thread();
t.start();*/
ProgressThread progressthread=new ProgressThread(progresshandler);
progressthread.start();


progressdialog.setProgress(0);
progresshandler.sendEmptyMessage(0);
}

});
       
       
       
     
       
     
    }
}


class ProgressThread extends Thread
{

final static int DONE = 0;
    final static int RUNNING = 1;
   
    Handler mHandler;
    int mState;
    int total;
    ProgressThread(Handler m)
    {
    mHandler=m;
    }
    public void run() {
        mState = RUNNING;  
        total = ProgressBar.maxBarValue;
        while (mState == RUNNING) {
           
            try {
                // Control speed of update (but precision of delay not guaranteed)
                Thread.sleep(40);
               
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
           
         
           
            total--;  



}}}

MediaPlayer with Visualization And Equalizer


import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.audiofx.Equalizer;
import android.media.audiofx.Visualizer;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.VideoView;

public class MediaDemo extends Activity {
    /** Called when the activity is first created. */
   
private static final String TAG = "AudioFxDemo";

    private static final float VISUALIZER_HEIGHT_DIP = 50f;

    private MediaPlayer mp;
    private Visualizer mVisualizer;
    private Equalizer mEqualizer;

    private LinearLayout ll;
    private VideoView vv;
    private VisualizerView mVisualizerView;
    private TextView tv;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        tv=new TextView(this);
        vv=new VideoView(this);
        ll=new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.addView(tv);
        setContentView(ll);
        mp=MediaPlayer.create(getApplicationContext(), R.raw.jan);
        Log.d(TAG, "MediaPlayer audio session ID: " + mp.getAudioSessionId());
       
        setupVisualizer();
        setupEqualizer();
        mVisualizer.setEnabled(true);
        mp.setOnCompletionListener(new OnCompletionListener()
        {

@Override
public void onCompletion(MediaPlayer arg0) {
// TODO Auto-generated method stub
mVisualizer.setEnabled(false);

}
       
        });
        mp.start();
        tv.setText("playing audio");
    }
    public void setupEqualizer()
    {
    mEqualizer=new Equalizer(0,mp.getAudioSessionId());
    mEqualizer.setEnabled(true);
    TextView tv=new TextView(this);
    tv.setText("equalizer");
    ll.addView(tv);
    short bands=mEqualizer.getNumberOfBands();
    final short min=mEqualizer.getBandLevelRange()[0];
    final short max=mEqualizer.getBandLevelRange()[1];
    for(short i=0;i<bands;i++)
    {
    final short band=1;
    TextView tv1=new TextView(this);
    tv1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    tv1.setGravity(Gravity.CENTER_HORIZONTAL);
    tv1.setText((mEqualizer.getCenterFreq(band)/1000)+"hz");
    ll.addView(tv1);
    LinearLayout lv=new LinearLayout(this);
    lv.setOrientation(LinearLayout.HORIZONTAL);
    //TextView tv2=new TextView(this);
    //tv2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    //tv2.setText((min/100)+"db");
    //TextView tv3=new TextView(this);
    //tv3.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    //tv3.setText((max/100)+"db");
    LinearLayout.LayoutParams param=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    param.weight=1;
    SeekBar bar=new SeekBar(this);
    bar.setLayoutParams(param);
    bar.setMax(max-min);
    bar.setProgress(mEqualizer.getBandLevel(band));
    bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
mEqualizer.setBandLevel(band, (short)(progress+min));

}
});
    //lv.addView(tv2);
    //lv.addView(tv3);
    lv.addView(bar);
    ll.addView(lv);
    }
   
    }
    public void setupVisualizer()
    {
    mVisualizerView=new VisualizerView(this);
    mVisualizerView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                (int)(VISUALIZER_HEIGHT_DIP * getResources().getDisplayMetrics().density)));
    /*vv.getBackground();
    ll.addView(vv);*/
    ll.addView(mVisualizerView);
   
   mVisualizer=new Visualizer(mp.getAudioSessionId());
   
   
   
   
    mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
    mVisualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {

@Override
public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
int samplingRate) {
// TODO Auto-generated method stub
mVisualizerView.updateVisualizer(bytes);

}

@Override
public void onFftDataCapture(Visualizer visualizer, byte[] fft,
int samplingRate) {
// TODO Auto-generated method stub

}
}, Visualizer.getMaxCaptureRate()/2, true,false);
   
    }
    protected void onPause() {
        super.onPause();

        if (isFinishing() && mp != null) {
            mVisualizer.release();
            mEqualizer.release();
            mp.release();
            mp = null;
        }
    }
}
class VisualizerView extends View {
    private byte[] mBytes;
    private float[] mPoints;
    private Rect mRect = new Rect();

    private Paint mForePaint = new Paint();

    public VisualizerView(Context context) {
        super(context);
        init();
    }

    private void init() {
        mBytes = null;

        mForePaint.setStrokeWidth(1f);
        mForePaint.setAntiAlias(true);
        mForePaint.setColor(Color.rgb(0, 128, 255));
    }

    public void updateVisualizer(byte[] bytes) {
        mBytes = bytes;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (mBytes == null) {
            return;
        }

        if (mPoints == null || mPoints.length < mBytes.length * 4) {
            mPoints = new float[mBytes.length * 4];
        }

        mRect.set(0, 0, getWidth(), getHeight());

        for (int i = 0; i < mBytes.length - 1; i++) {
            mPoints[i * 4] = mRect.width() * i / (mBytes.length - 1);
            mPoints[i * 4 + 1] = mRect.height() / 2
                    + ((byte) (mBytes[i] + 128)) * (mRect.height() / 2) / 128;
            mPoints[i * 4 + 2] = mRect.width() * (i + 1) / (mBytes.length - 1);
            mPoints[i * 4 + 3] = mRect.height() / 2
                    + ((byte) (mBytes[i + 1] + 128)) * (mRect.height() / 2) / 128;
        }

        canvas.drawLines(mPoints, mForePaint);
    }
}

ListView


import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListEx extends ListActivity {
    /** Called when the activity is first created. */
   
String s[];
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        ListView l1=getListView();
        s=getResources().getStringArray(R.array.s);
       
        l1.setChoiceMode(2);
        l1.setTextFilterEnabled(true);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,s));
       
    }
    public void onListItemClick(ListView parent, View v, int position, long id)
    {
    parent.setItemChecked(position,parent.isItemChecked(position));
    Toast.makeText(this,"you have selected" +":"+ s[position],
    Toast.LENGTH_SHORT).show();
    }
}