May 30, 2011

Android Clipboard Framework

Android SDK 3.0 has various new API. Android 3.0 has 1180 new classes, methods and interfaces. (Click Here for complete list).  Clipboard Framework is newly introduce in Android 3.0. basic purpose of this framework is to provide copy and paste data between various application.  It is very powerful framework. It supports simple data like text (String) and complex type like binary data, objects etc.

Here I am going to explain very simple example of Android Clipboard Framework. Let's start with introduction of key classes.

1. ClipboardManager: It is represent as global object. We do not need to create new object of ClipboardManager. We can directly fetch object from system service. we can get reference by invoking getSystemService(CLIPBOARD_SERVICE).

2. ClipData: To put any object in clipboard we need to create object of ClipData class. ClipData object contain ClipData.Item and ClipDescription.

3. ClipData.Item: It contain object which we copied. Object can be Text, URI or Intent data.

4. ClipDescription: It is metadata about clip. It contain MIME type of clip data.
 
Let's start with very simple demo of ClipBoard Framework.
continue reading Android Clipboard Framework

May 25, 2011

Android API Difference between 2.0 and 3.1 OS

History of Android API Changes in Percentages.

The table below list the changes from version 2.0 to 3.1. The table includes only the highest-level program elements— that is, if a class with two methods was added, the number of methods added does not include those two methods, but the number of classes added does include that class.


OS Version API Level % change Addition Changes Removals Total
Android 2.0 to 2.1 6 to 7 0.48 81 37 0 118
Android 2.1 to 2.2 7 to 8 5.7 475 225 33 733
Android 2.2 to 2.3 8 to 9
Android 2.3 to 2.3.4 9 to 10 0.65 25 17 2 44
Android 2.3.4 to 3.0 10 to 11 2.56 1182 375 27 1584
Android 3.0 to 3.1 11 to 12 1.15 174 126 14 314

Calculation of Change Percentages

The percent change statistic reported for all elements in the "to" API Level specification is defined recursively as follows:

Percentage difference = 100 * (added + removed + 2*changed)
                        -----------------------------------
                        sum of public elements in BOTH APIs
where added is the number of packages added, removed is the number of packages removed, and changed  is the number of packages changed. This definition is applied recursively for the classes and their program  elements, so the value for a changed package will be less than 1,  unless every class in that package has changed. The definition ensures that if all packages are removed and all new  packages are added, the change will be 100%.

Related Post

1. Android API Difference between 3.0 and 3.1 OS

continue reading Android API Difference between 2.0 and 3.1 OS

Android API Difference between 3.0 and 3.1 OS


Android 3.1 is the first revision to Android 3.0 (Honeycomb), It is optimized for Tablet.  Google announced the update on 10 May 2011. The first major update to Honeycomb refines many of the features in the original Honeycomb version. I am not going to discuss the new feature or functionality Google has added but I am going to discuss API difference specially things which are removed in 3.1
API Changes between Android OS 3.0 and Android OS 3.1,

Overall difference between API Levels 11 and 12 is 1.15%. Table shows statics, additions, changes and removals.


Type Additions Changes Removals Total
Packages 3 24 0 27
Classes and Interfaces 5 65 6 76
Constructors 4 1 6 11
Methods 75 27 2 104
Fields 87 9 0 96
Total 174 126 14 314


Here I found the list of removed classes, methods and interfaces in Android SDK 3.1.

1. Config()  - Removed Constructor
2. DebugUtils() - Removed Constructor
3. EventLog() - Removed Constructor
4. getPluginList()  - Remove Method
5. Plugin   - Remove Classes and Interface
6. Plugin.PerferencesClickHandler - Remove Classes and Interface
7. Plugin.Data - Remove Classes and Interface
8. PluginList - Remove Classes and Interface
9. refereshPlugins() - Removed Method
10. StateSet() - Removed Constructor
11. TimeUtils() - Removed Constructor
12. UrlInterceptHandler - Remove Classes and Interface
13 UrlInterceptRegistry - Remove Classes and Interface
14. Xml() - Removed Constructor

Related Post
1. Android API Difference between 2.0 and 3.1 OS

continue reading Android API Difference between 3.0 and 3.1 OS

May 23, 2011

Android Light Sensor

Hello Guys,

Here I am explaining you how to use Light Sensor of Android.
1. Implement SensorEventListener
2. Create variable for SensorManager and Sensor
3. Get Object of SensorManager using system service
4. Get Object of Light Sensor from SensorManager
5. Implement onAccuracyChanged and onSensorChanged method



package com.test;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;

public class Test extends Activity implements SensorEventListener{

 private SensorManager mSensorManager;
 private Sensor mLight;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

   mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
         mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

 }
 @Override
 protected void onResume() {
   mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL);
  super.onResume();
 }
 @Override
 protected void onPause() {
  mSensorManager.unregisterListener(this);
  super.onPause();
 }
 public void onAccuracyChanged(Sensor sensor, int accuracy) {
   if(sensor.getType() == Sensor.TYPE_LIGHT){
    Log.i("Sensor Changed", "Accuracy :" + accuracy);
   }
  
 }

 public void onSensorChanged(SensorEvent event) {
  if( event.sensor.getType() == Sensor.TYPE_LIGHT){
   Log.i("Sensor Changed", "onSensor Change :" + event.values[0]);
  }
  
 }
}

Screen Shot of Change Values


continue reading Android Light Sensor

May 20, 2011

Android Loading Image from Server

Hello Guys,


Here I am writing easiest way to download image from server. Following function return Drawable object.  Use drawable object as per your  requirement.




private Drawable LoadImageFromWeb(String url) {
  try {
   InputStream is = (InputStream) new URL(url).getContent();
   Drawable d = Drawable.createFromStream(is, "src name");
   return d;
  } catch (Exception e) {
   System.out.println("Exc=" + e);
   return null;
  }
 }
continue reading Android Loading Image from Server

May 8, 2011

Android: Seek Bar with Two Thumb

Seek bar with two thumb control is badly required by some developer, including my self, When I start looking this control I was tired and frustrated.  and finally I have decided to create my own seek bar control with two thumb. I have used my control in one of the my android project. Initially I tried to extend SeekBar control but I am unable to extend it. so finally I decided to extend ImageView control and I got succes.




Here I am publishing my own seek bar control with two thumb.

continue reading Android: Seek Bar with Two Thumb

May 4, 2011

Android:Bottom Tabbar Control

Introduction

In this tutorial, You will learn how to create application with bottom TabBar Control. Tab Bar control is present in Android UI component but It always displays at top of screen. Many times we required to display Tabs at bottom of screen, just like iPhone, Unfortunately Android native TabBar control does not provide facility to display Tabs at bottom of the screen.  

Tabbar Control Screen Shots






Download Source Code from Here : Click
[Note: Click On File-> Download To download source code zip file]
continue reading Android:Bottom Tabbar Control

May 2, 2011

Android: How to fetch Media File list


You can use following code to fetch media files. It is possible using managedQuery function. Android has default MediaPlayer application. MediaPlayer application manage Audio and Video files list.. so, We can fetch list from MediaPlayer application using following code.

Using managedQuery we can fetch media file list

 String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
            musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);


I assume that you have basic knowledge of create & execute Android Projects.
Let's create project step by step to use above code.

continue reading Android: How to fetch Media File list