Sunday, February 24, 2013

Update Gallery photos in background thread

Last article "Display photos from SD in android.widget.Gallery" load Gallery photos in UI thread. As I mentioned in some previous posts, it's not a good practice to perform long time operation in UI thread, specially when you load many large size photos.


The main code, AndroidGalleryActivity.java, is further modified to perform the re-size job in background thread. Before the photos re-sized, the Gallery show items as a default bitmap (android.R.drawable.ic_menu_gallery). After re-size, myPhotoBarAdapter.notifyDataSetChanged() is called (in UI thread) to update Gallery.

Because every photo have its own background thread to re-size, and independent to each others. So the update sequence is not in order.

  
package com.AndroidGallery;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.R.color;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidGalleryActivity extends Activity {

Gallery photoBar;

Button buttonOpenDialog;
Button buttonUp, buttonSelectFolder;
TextView jpgList;

String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;

ListView dialog_ListView;

File root;
File curFolder;

private List fileList = new ArrayList();

class PhotoItem{

String bitmapImageSrc;
Bitmap bitmapImage = null;

final static int itemWidth = 150;
final static int itemHeight = 150;

Handler handler;

public PhotoItem(String src){
bitmapImageSrc = src;
StratBackgroundProcess();

bitmapImage = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_menu_gallery);
}

public Bitmap getImage(){
return bitmapImage;
}

private void runResize(){
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;

Bitmap bitmap = BitmapFactory.decodeFile(bitmapImageSrc, bmpFactoryOptions);

int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)itemHeight);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)itemWidth);

if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio){
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}

bmpFactoryOptions.inJustDecodeBounds = false;

bitmapImage = BitmapFactory.decodeFile(bitmapImageSrc, bmpFactoryOptions);

}

private void StratBackgroundProcess(){
Runnable runnable = new Runnable(){

@Override
public void run() {

runResize();

handler.post(new Runnable(){

@Override
public void run() {
myPhotoBarAdapter.notifyDataSetChanged();
}});

}

};

handler = new Handler();
new Thread(runnable).start();
}

}

PhotoBarAdapter myPhotoBarAdapter;

public class PhotoBarAdapter extends BaseAdapter {

Context context;
ArrayList arrayPhotoItem;

PhotoBarAdapter(Context c){
context = c;
arrayPhotoItem = new ArrayList();
}

public void clear(){
arrayPhotoItem.clear();
}

public void addPhotoItem(PhotoItem item){
arrayPhotoItem.add(item);
}

@Override
public int getCount() {
return arrayPhotoItem.size();
}

@Override
public Object getItem(int position) {
return arrayPhotoItem.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

LinearLayout viewLayout = new LinearLayout(context);
viewLayout.setLayoutParams(new Gallery.LayoutParams(200, 200));
viewLayout.setGravity(Gravity.CENTER);
viewLayout.setBackgroundColor(color.background_light);

ImageView imageView;
imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 150));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(arrayPhotoItem.get(position).getImage());
//return imageView;

viewLayout.addView(imageView);
return viewLayout;
}

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

photoBar = (Gallery)findViewById(R.id.photobar);
myPhotoBarAdapter = new PhotoBarAdapter(this);
photoBar.setAdapter(myPhotoBarAdapter);

jpgList = (TextView)findViewById(R.id.jpglist);

buttonOpenDialog = (Button)findViewById(R.id.opendialog);
buttonOpenDialog.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});

root = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());

curFolder = root;
//ListJpgInFolder(curFolder);
preparePhotoBarInFolder(curFolder);

}

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = null;

switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(AndroidGalleryActivity.this);
dialog.setContentView(R.layout.dialoglayout);
dialog.setTitle("Select JPG");

dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);

buttonUp = (Button)dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {

ListDir(curFolder.getParentFile());
}});

buttonSelectFolder = (Button)dialog.findViewById(R.id.selectfolder);
buttonSelectFolder.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {

Toast.makeText(AndroidGalleryActivity.this,
curFolder + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);

//ListJpgInFolder(curFolder);
preparePhotoBarInFolder(curFolder);

}});


//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);

dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
File selected = new File(fileList.get(position));
if(selected.isDirectory()){
ListDir(selected);
}
}});

break;
}
return dialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {

super.onPrepareDialog(id, dialog, bundle);

switch(id) {
case CUSTOM_DIALOG_ID:
ListDir(curFolder);

break;
}
}

void ListDir(File f){

if(f.equals(root)){
buttonUp.setEnabled(false);
}else{
buttonUp.setEnabled(true);
}

curFolder = f;
buttonSelectFolder.setText("Select Folder " + curFolder);

File[] files = f.listFiles();
fileList.clear();
for (File file : files){
if(file.isDirectory()){
fileList.add(file.getPath());
}else{
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
fileList.add(file.getName());
}
}
}

ArrayAdapter directoryList
= new ArrayAdapter(this,
android.R.layout.simple_list_item_1, fileList);
dialog_ListView.setAdapter(directoryList);
}

private void preparePhotoBarInFolder(File folder){

String jpgs = "JPG fiels in folder " + folder.getAbsolutePath() + "\n\n";

File[] files = folder.listFiles();

myPhotoBarAdapter.clear();

for (File file : files){
if(!file.isDirectory()){
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
jpgs += file.getAbsolutePath() + "\n";

PhotoItem pItem = new PhotoItem(file.getAbsolutePath());
myPhotoBarAdapter.addPhotoItem(pItem);

myPhotoBarAdapter.notifyDataSetChanged();
}
}
}
jpgList.setText(jpgs);
}

}



Update Gallery photos in background thread
Cheers Guys!!

Display photos from SD in android.widget.Gallery

The photos in the selected folder will be loaded in a custom adapter to display in Gallery widget.

Modify main.xml, to add <Gallery>.










Modify AndroidGalleryActivity.java.

In order to reduce the resource need to keep the bitmaps, we have to implement a new class PhotoItem hold the path of individual jpg file, and the re-sized bitmap. And a custom BaseAdapter, PhotoBarAdapter, for PhotoItem is implemented for the Gallery.

 

package com.AndroidGallery;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.R.color;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidGalleryActivity extends Activity {

Gallery photoBar;

Button buttonOpenDialog;
Button buttonUp, buttonSelectFolder;
TextView jpgList;

String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;

ListView dialog_ListView;

File root;
File curFolder;

private List fileList = new ArrayList();

class PhotoItem{

String bitmapImageSrc;
Bitmap bitmapImage = null;

final static int itemWidth = 150;
final static int itemHeight = 150;

public PhotoItem(String src){
bitmapImageSrc = src;
bitmapImage = resize();
}

public Bitmap getImage(){
return bitmapImage;
}

private Bitmap resize(){
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;

Bitmap bitmap = BitmapFactory.decodeFile(bitmapImageSrc, bmpFactoryOptions);

int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)itemHeight);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)itemWidth);

if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio){
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}

bmpFactoryOptions.inJustDecodeBounds = false;

bitmap = BitmapFactory.decodeFile(bitmapImageSrc, bmpFactoryOptions);

return bitmap;
}
}

PhotoBarAdapter myPhotoBarAdapter;

public class PhotoBarAdapter extends BaseAdapter {

Context context;
ArrayList arrayPhotoItem;


PhotoBarAdapter(Context c){
context = c;
arrayPhotoItem = new ArrayList();
}

public void clear(){
arrayPhotoItem.clear();
}

public void addPhotoItem(PhotoItem item){
arrayPhotoItem.add(item);
}

@Override
public int getCount() {
return arrayPhotoItem.size();
}

@Override
public Object getItem(int position) {
return arrayPhotoItem.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

LinearLayout viewLayout = new LinearLayout(context);
viewLayout.setLayoutParams(new Gallery.LayoutParams(200, 200));
viewLayout.setBackgroundColor(color.background_light);

ImageView imageView;
imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 150));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(arrayPhotoItem.get(position).getImage());
//return imageView;

viewLayout.addView(imageView);
return viewLayout;
}

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

photoBar = (Gallery)findViewById(R.id.photobar);
myPhotoBarAdapter = new PhotoBarAdapter(this);
photoBar.setAdapter(myPhotoBarAdapter);

jpgList = (TextView)findViewById(R.id.jpglist);

buttonOpenDialog = (Button)findViewById(R.id.opendialog);
buttonOpenDialog.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});

root = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());

curFolder = root;
//ListJpgInFolder(curFolder);
preparePhotoBarInFolder(curFolder);

}

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = null;

switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(AndroidGalleryActivity.this);
dialog.setContentView(R.layout.dialoglayout);
dialog.setTitle("Select JPG");

dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);

buttonUp = (Button)dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ListDir(curFolder.getParentFile());
}});

buttonSelectFolder = (Button)dialog.findViewById(R.id.selectfolder);
buttonSelectFolder.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(AndroidGalleryActivity.this,
curFolder + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);

//ListJpgInFolder(curFolder);
preparePhotoBarInFolder(curFolder);

}});


//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);

dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
File selected = new File(fileList.get(position));
if(selected.isDirectory()){
ListDir(selected);
}
}});

break;
}
return dialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);

switch(id) {
case CUSTOM_DIALOG_ID:
ListDir(curFolder);

break;
}
}

void ListDir(File f){

if(f.equals(root)){
buttonUp.setEnabled(false);
}else{
buttonUp.setEnabled(true);
}

curFolder = f;
buttonSelectFolder.setText("Select Folder " + curFolder);

File[] files = f.listFiles();
fileList.clear();
for (File file : files){
if(file.isDirectory()){
fileList.add(file.getPath());
}else{
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
fileList.add(file.getName());
}
}
}

ArrayAdapter directoryList
= new ArrayAdapter(this,
android.R.layout.simple_list_item_1, fileList);
dialog_ListView.setAdapter(directoryList);
}

private void preparePhotoBarInFolder(File folder){

String jpgs = "JPG fiels in folder " + folder.getAbsolutePath() + "\n\n";

File[] files = folder.listFiles();

myPhotoBarAdapter.clear();

for (File file : files){
if(!file.isDirectory()){
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
jpgs += file.getAbsolutePath() + "\n";

PhotoItem pItem = new PhotoItem(file.getAbsolutePath());
myPhotoBarAdapter.addPhotoItem(pItem);

myPhotoBarAdapter.notifyDataSetChanged();
}
}
}
jpgList.setText(jpgs);
}

}
Display photos from SD in Gallery widget

Implement custom dialog to open folder

Custom dialog was implemented to load individual image(jpg). In this article, the custom dialog is used to open folder, instead of individual file. After dismissed, the images(jpg) in the selected folder will be listed.

dialoglayout.xml, layout of the custom dislog.
  





AndroidGalleryActivity.java, the main code.

  
package com.AndroidGallery;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidGalleryActivity extends Activity {

Button buttonOpenDialog;
Button buttonUp, buttonSelectFolder;
TextView jpgList;

String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;

ListView dialog_ListView;

File root;
File curFolder;

private List fileList = new ArrayList();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

jpgList = (TextView)findViewById(R.id.jpglist);

buttonOpenDialog = (Button)findViewById(R.id.opendialog);
buttonOpenDialog.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});

root = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());

curFolder = root;
ListJpgInFolder(curFolder);

}

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = null;

switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(AndroidGalleryActivity.this);
dialog.setContentView(R.layout.dialoglayout);
dialog.setTitle("Select JPG");

dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);

buttonUp = (Button)dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ListDir(curFolder.getParentFile());
}});

buttonSelectFolder = (Button)dialog.findViewById(R.id.selectfolder);
buttonSelectFolder.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(AndroidGalleryActivity.this,
curFolder + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);

ListJpgInFolder(curFolder);

}});


//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);

dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
File selected = new File(fileList.get(position));
if(selected.isDirectory()){
ListDir(selected);
}else {
/*
Toast.makeText(AndroidGalleryActivity.this,
selected.toString() + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);

Bitmap bm = BitmapFactory.decodeFile(selected.getAbsolutePath());
image.setImageBitmap(bm);
*/
}
}});

break;
}
return dialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);

switch(id) {
case CUSTOM_DIALOG_ID:
ListDir(curFolder);

break;
}
}

void ListDir(File f){

if(f.equals(root)){
buttonUp.setEnabled(false);
}else{
buttonUp.setEnabled(true);
}

curFolder = f;
buttonSelectFolder.setText("Select Folder " + curFolder);

File[] files = f.listFiles();
fileList.clear();
for (File file : files){
if(file.isDirectory()){
fileList.add(file.getPath());
}else{
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
fileList.add(file.getName());
}
}
}

ArrayAdapter directoryList
= new ArrayAdapter(this,
android.R.layout.simple_list_item_1, fileList);
dialog_ListView.setAdapter(directoryList);
}

private void ListJpgInFolder(File folder){
String jpgs = "JPG fiels in folder " + folder.getAbsolutePath() + "\n\n";
File[] files = folder.listFiles();
for (File file : files){
if(!file.isDirectory()){
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
jpgs += file.getAbsolutePath() + "\n";
}
}
}

jpgList.setText(jpgs);
}

}

main.xml, the main layout.

 







custom dialog to open folder

Gets IP addresses of a given host - InetAddress.getAllByName()

java.net.InetAddress is a class of Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in practice you'll have an instance of either Inet4Address or Inet6Address (this class cannot be instantiated directly). Most code does not need to distinguish between the two families, and should use InetAddress.

The method getAllByName() gets all IP addresses associated with the given host identified by name or literal IP address. The IP address is resolved by the configured name service. If the host name is empty or null an UnknownHostException is thrown. If the host name is a literal IP address string an array with the corresponding single InetAddress is returned.

This example list all IP addresses associated with the user enter host name.

Note:

"android.permission.INTERNET" is needed.

For Applications targeting the Honeycomb SDK or higher, cannot attempts to perform a networking operation on its main thread. Otherwise, NetworkOnMainThreadException will be thrown. So the network operation is moved into AsyncTask.

I haven't IPv6 connection currently, I don't know if it will show Inet6Address with IPv6 connection. If you have, please let me know.

Java Code:

  
package com.AndroidInet;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class AndroidInetActivity extends Activity {

EditText hostinput;
TextView info;
Button btnTest;
ListView resultList;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hostinput = (EditText)findViewById(R.id.testhost);
info = (TextView)findViewById(R.id.info);
resultList = (ListView)findViewById(R.id.result);
btnTest = (Button)findViewById(R.id.test);
btnTest.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View view) {
info.setText("Wait...");
new Task().execute();

}});
}



private class Task extends AsyncTask{
Boolean error = false;
String error_info = "";
InetAddress[] inetAddress = null;

List hostList = new ArrayList();

@Override
protected Void doInBackground(Void... arg0) {
doTest();
return null;
}

@Override
protected void onPostExecute(Void result) {
if(error){
info.setText("Error: \n" + error_info);
}else{
info.setText("Finished");

ArrayAdapter adapter
= new ArrayAdapter(
AndroidInetActivity.this,
android.R.layout.simple_list_item_1,
hostList);

resultList.setAdapter(adapter);
}

super.onPostExecute(result);
}

private void doTest(){

String host = hostinput.getText().toString();

try {
inetAddress = InetAddress.getAllByName(host);

for(int i = 0; i < inetAddress.length; i++){

hostList.add(inetAddress[i].getClass() + " -\n"
+ inetAddress[i].getHostName() + "\n"
+ inetAddress[i].getHostAddress());
}

} catch (UnknownHostException e) {

e.printStackTrace();

error = true;
error_info = e.toString();
}

}
}
}

XML Code:

 







Cheers Guys!!!!!

Tuesday, February 19, 2013

JPG File Chooser

Main layout:








Main code:

package com.AndroidCustomDialog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidCustomDialogActivity extends Activity {

Button buttonOpenDialog;
Button buttonUp;
TextView textFolder;
ImageView image;

String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;

ListView dialog_ListView;

File root;
File curFolder;

private List fileList = new ArrayList();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

image = (ImageView)findViewById(R.id.image);

buttonOpenDialog = (Button)findViewById(R.id.opendialog);
buttonOpenDialog.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});

root = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());

curFolder = root;

}

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = null;

switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(AndroidCustomDialogActivity.this);
dialog.setContentView(R.layout.dialoglayout);
dialog.setTitle("Select JPG");

dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);

textFolder = (TextView)dialog.findViewById(R.id.folder);

buttonUp = (Button)dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ListDir(curFolder.getParentFile());
}});

//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);

dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {

File selected = new File(fileList.get(position));
if(selected.isDirectory()){
ListDir(selected);
}else {
Toast.makeText(AndroidCustomDialogActivity.this,
selected.toString() + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);

Bitmap bm = BitmapFactory.decodeFile(selected.getAbsolutePath());
image.setImageBitmap(bm);

}

}});

break;
}

return dialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);

switch(id) {
case CUSTOM_DIALOG_ID:
ListDir(curFolder);
break;
}

}

void ListDir(File f){

if(f.equals(root)){
buttonUp.setEnabled(false);
}else{
buttonUp.setEnabled(true);
}

curFolder = f;
textFolder.setText(f.getPath());

File[] files = f.listFiles();
fileList.clear();
for (File file : files){

if(file.isDirectory()){
fileList.add(file.getPath());
}else{
Uri selectedUri = Uri.fromFile(file);
String fileExtension
= MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
if(fileExtension.equalsIgnoreCase("jpg")){
fileList.add(file.getPath());
}
}

}

ArrayAdapter directoryList
= new ArrayAdapter(this,
android.R.layout.simple_list_item_1, fileList);
dialog_ListView.setAdapter(directoryList);
}

}



JPG File Chooser
 Cheers Guys!

Implement custom file explorer dialog

dialoglayout.xml, the layout of the custom dialog.
  









Java Code:

 
package com.AndroidCustomDialog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidCustomDialogActivity extends Activity {

Button buttonOpenDialog;
Button buttonUp;
TextView textFolder;

String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;

ListView dialog_ListView;

File root;
File curFolder;

private List fileList = new ArrayList();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

buttonOpenDialog = (Button)findViewById(R.id.opendialog);
buttonOpenDialog.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});

root = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());

curFolder = root;

}

@Override
protected Dialog onCreateDialog(int id) {

Dialog dialog = null;

switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(AndroidCustomDialogActivity.this);
dialog.setContentView(R.layout.dialoglayout);
dialog.setTitle("Custom Dialog");

dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);

textFolder = (TextView)dialog.findViewById(R.id.folder);

buttonUp = (Button)dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ListDir(curFolder.getParentFile());
}});

//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);

dialog_ListView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {

File selected = new File(fileList.get(position));
if(selected.isDirectory()){
ListDir(selected);
}else {
Toast.makeText(AndroidCustomDialogActivity.this,
selected.toString() + " selected",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);
}

}});

break;
}

return dialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);

switch(id) {
case CUSTOM_DIALOG_ID:
ListDir(curFolder);
break;
}

}

void ListDir(File f){

if(f.equals(root)){
buttonUp.setEnabled(false);
}else{
buttonUp.setEnabled(true);
}

curFolder = f;
textFolder.setText(f.getPath());

File[] files = f.listFiles();
fileList.clear();
for (File file : files){
fileList.add(file.getPath());
}

ArrayAdapter directoryList
= new ArrayAdapter(this,
android.R.layout.simple_list_item_1, fileList);
dialog_ListView.setAdapter(directoryList);
}

}

Main Layout:

  









custom file explorer dialog
 Cheers Guys!!!!!

Monday, February 4, 2013

Get the canvas bitmap of custom View

I have a series of previous articles to draw something on custom view's canvas. All these code lose everythng after the app exit. Now I want to save the drawing in a file. In this article, I will demonstrate how to get the canvas bitmap of custom view.
package com.sunil;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MyView extends View {

boolean freeTouched = false;
Path freePath;

Bitmap myCanvasBitmap = null;
Canvas myCanvas = null;

Matrix identityMatrix;

public MyView(Context context) {
super(context);
}

public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected void onDraw(Canvas canvas) {

if(freeTouched){
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.RED);
paint.setStrokeWidth(10);

myCanvas.drawPath(freePath, paint);
canvas.drawBitmap(myCanvasBitmap, identityMatrix, null);

}
}

@Override
public boolean onTouchEvent(MotionEvent event) {

switch(event.getAction()){
case MotionEvent.ACTION_UP:
freeTouched = false;
break;
case MotionEvent.ACTION_DOWN:
freeTouched = true;
freePath = new Path();
freePath.moveTo(event.getX(), event.getY());

myCanvasBitmap.eraseColor(Color.BLACK);

break;
case MotionEvent.ACTION_MOVE:
freePath.lineTo(event.getX(), event.getY());
invalidate();
break;
}

return true;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int w = MeasureSpec.getSize(widthMeasureSpec);
int h = MeasureSpec.getSize(heightMeasureSpec);

myCanvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
myCanvas = new Canvas();
myCanvas.setBitmap(myCanvasBitmap);

identityMatrix = new Matrix();

setMeasuredDimension(w, h);
}

public Bitmap getCanvasBitmap(){

return myCanvasBitmap;

}

}

Create /res/menu/menu.xml to define our option menu.
   


The main code, AndroidMyCanvasActivity.java.
package com.sunil;

import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class AndroidMyCanvasActivity extends Activity {

MyView myView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myView = new MyView(this);

setContentView(myView);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.opt_capture:
openCaptureDialog();
return true;
default:
return false;

}
}

private void openCaptureDialog(){

Bitmap bmMyView = myView.getCanvasBitmap();

AlertDialog.Builder captureDialog = new AlertDialog.Builder(AndroidMyCanvasActivity.this);
captureDialog.setTitle("Canvas Captured");

ImageView bmImage = new ImageView(AndroidMyCanvasActivity.this);

bmImage.setImageBitmap(bmMyView);

LayoutParams bmImageLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
bmImage.setLayoutParams(bmImageLayoutParams);

LinearLayout dialogLayout = new LinearLayout(AndroidMyCanvasActivity.this);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
dialogLayout.addView(bmImage);
captureDialog.setView(dialogLayout);

captureDialog.setPositiveButton("OK", null);
captureDialog.show();

}

}

Cheers Guys!

Friday, February 1, 2013

Gestures detection and canvas scale, translate and rotate.

In this article we are going to implement GestureOverlayView to detect gestures input, and apply scale, translate and rotate on canvas accordingly. (May be I build the Gestures too simple, the detection is not accurate. You are advised to create your own.) -

 Modify main.xml to add android.gesture.GestureOverlayView.












- Modify MyGameActivity.java to handle Gesture.
package com.MyGame;

import java.util.ArrayList;

import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.SurfaceView;
import android.widget.Toast;

public class MyGameActivity extends Activity {

MyGameSurfaceView myGameSurfaceView1;
MyForeground myForeground;

//MyAccelerometer myAccelerometer;

GestureLibrary gestureLibrary = null;
GestureOverlayView gestureOverlayView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myGameSurfaceView1 = (MyGameSurfaceView)findViewById(R.id.myview1);
myForeground = (MyForeground)findViewById(R.id.myforeground);

//Set myForeground using transparent background
myForeground.setZOrderOnTop(true);
myForeground.getHolder().setFormat(PixelFormat.TRANSPARENT);

//myAccelerometer = new MyAccelerometer(this);

gestureOverlayView = (GestureOverlayView)findViewById(R.id.gestures);
gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
gestureLibrary.load();
gestureOverlayView.addOnGesturePerformedListener(gesturePerformedListener);

}

OnGesturePerformedListener gesturePerformedListener
= new OnGesturePerformedListener(){

@Override
public void onGesturePerformed(GestureOverlayView view, Gesture gesture) {
ArrayList prediction = gestureLibrary.recognize(gesture);

if(prediction.size() > 0){
String gesturePerformed = prediction.get(0).name;
if(gesturePerformed.equals("up")){
myForeground.canvasUp();
Toast.makeText(MyGameActivity.this,
"up", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("down")){
myForeground.canvasDown();
Toast.makeText(MyGameActivity.this,
"down", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("left")){
myForeground.canvasLeft();
Toast.makeText(MyGameActivity.this,
"left", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("right")){
myForeground.canvasRight();
Toast.makeText(MyGameActivity.this,
"right", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("clockwise")){
myForeground.canvasClockwise();
Toast.makeText(MyGameActivity.this,
"clockwise", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("anti-clockwise")){
myForeground.canvasAntiClockwise();
Toast.makeText(MyGameActivity.this,
"anti-clockwise", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("enlarge")){
myForeground.canvasEnlarge();
Toast.makeText(MyGameActivity.this,
"enlarge", Toast.LENGTH_LONG).show();
}else if(gesturePerformed.equals("reduce")){
myForeground.canvasReduce();
Toast.makeText(MyGameActivity.this,
"reduce", Toast.LENGTH_LONG).show();
}
}

}

};

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myGameSurfaceView1.MyGameSurfaceView_OnResume();
myForeground.MyGameSurfaceView_OnResume();

//myAccelerometer.registerListener();

}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myGameSurfaceView1.MyGameSurfaceView_OnPause();
myForeground.MyGameSurfaceView_OnPause();

//myAccelerometer.unregisterListener();
}

void updateAccelerometer(float tx, float ty){
int w = myForeground.getWidth();
int h = myForeground.getHeight();

float x = ((w/2) * tx) + (w/2);
float y = ((h/2) * ty) + (h/2);
myForeground.updateAccelerometer(x, y);
}

}

Modify MyForeground.java to handle canvas scale, translate and rotate.
package com.MyGame;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;

public class MyForeground extends MyGameSurfaceView {

Sprite mySprite;

float canvasScaleX = 1.0f;
float canvasScaleY = 1.0f;
float canvasTranslateX = 0.0f;
float canvasTranslateY = 0.0f;
float canvasRotate = 0.0f;

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

public MyForeground(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public MyForeground(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

private void init(){
mySprite = new Sprite(
BitmapFactory.decodeResource(getResources(), R.drawable.icon_me),
100, 100);
}

@Override
protected void onDraw(Canvas canvas) {
//Clear Canvas with transparent background
canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);

canvas.scale(canvasScaleX, canvasScaleY);
canvas.translate(canvasTranslateX, canvasTranslateY);
canvas.rotate(canvasRotate, mySprite.getX(), mySprite.getY());
mySprite.draw(canvas);

}

@Override
public void updateStates() {
// TODO Auto-generated method stub
mySprite.update();
}

void updateAccelerometer(float tx, float ty){
mySprite.setX((int)tx);
mySprite.setY((int)ty);
}

public void canvasUp(){
canvasTranslateY -= 10.0f;
}

public void canvasDown(){
canvasTranslateY += 10.0f;
}

public void canvasLeft(){
canvasTranslateX -= 10.0f;
}

public void canvasRight(){
canvasTranslateX += 10.0f;
}

public void canvasClockwise(){
canvasRotate += 10.0f;
}

public void canvasAntiClockwise(){
canvasRotate -= 10.0f;
}

public void canvasEnlarge(){
canvasScaleX *= 2.0f;
canvasScaleY *= 2.0f;
}

public void canvasReduce(){
canvasScaleX /= 2.0f;
canvasScaleY /= 2.0f;
}

}


Gestures detection and canvas scale, translate and rotate.
Gestures BuilderCheers Guys!!!!!!!!

Create our Android Compass

Android compass is implemented here. In the implementation, the final result (base on Accelerometer and Magnetic Field sensors) is show in RED, point to the north.
Create a custom View, Compass, extends View. The method update() is called from onSensorChanged() of main activity, with the updated direction.


package com.AndroidDetOrientation;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class Compass extends View {

private float direction;

public Compass(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

public Compass(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

public Compass(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(
MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}

@Override
protected void onDraw(Canvas canvas) {

int w = getMeasuredWidth();
int h = getMeasuredHeight();
int r;
if(w > h){
r = h/2;
}else{
r = w/2;
}

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
paint.setColor(Color.WHITE);

canvas.drawCircle(w/2, h/2, r, paint);

paint.setColor(Color.RED);
canvas.drawLine(
w/2,
h/2,
(float)(w/2 + r * Math.sin(-direction)),
(float)(h/2 - r * Math.cos(-direction)),
paint);

}

public void update(float dir){
direction = dir;
invalidate();
}

}

Modify main activity, AndroidDetOrientationActivity, to update Compass.
package com.AndroidDetOrientation;

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.widget.TextView;

public class AndroidDetOrientationActivity extends Activity
implements SensorEventListener{

SensorManager sensorManager;
private Sensor sensorAccelerometer;
private Sensor sensorMagneticField;

private float[] valuesAccelerometer;
private float[] valuesMagneticField;

private float[] matrixR;
private float[] matrixI;
private float[] matrixValues;

TextView readingAzimuth, readingPitch, readingRoll;
Compass myCompass;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
readingAzimuth = (TextView)findViewById(R.id.azimuth);
readingPitch = (TextView)findViewById(R.id.pitch);
readingRoll = (TextView)findViewById(R.id.roll);

myCompass = (Compass)findViewById(R.id.mycompass);

sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorMagneticField = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

valuesAccelerometer = new float[3];
valuesMagneticField = new float[3];

matrixR = new float[9];
matrixI = new float[9];
matrixValues = new float[3];
}

@Override
protected void onResume() {

sensorManager.registerListener(this,
sensorAccelerometer,
SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this,
sensorMagneticField,
SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
}

@Override
protected void onPause() {

sensorManager.unregisterListener(this,
sensorAccelerometer);
sensorManager.unregisterListener(this,
sensorMagneticField);
super.onPause();
}

@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub

}

@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub

switch(event.sensor.getType()){
case Sensor.TYPE_ACCELEROMETER:
for(int i =0; i < 3; i++){
valuesAccelerometer[i] = event.values[i];
}
break;
case Sensor.TYPE_MAGNETIC_FIELD:
for(int i =0; i < 3; i++){
valuesMagneticField[i] = event.values[i];
}
break;
}

boolean success = SensorManager.getRotationMatrix(
matrixR,
matrixI,
valuesAccelerometer,
valuesMagneticField);

if(success){
SensorManager.getOrientation(matrixR, matrixValues);

double azimuth = Math.toDegrees(matrixValues[0]);
double pitch = Math.toDegrees(matrixValues[1]);
double roll = Math.toDegrees(matrixValues[2]);

readingAzimuth.setText("Azimuth: " + String.valueOf(azimuth));
readingPitch.setText("Pitch: " + String.valueOf(pitch));
readingRoll.setText("Roll: " + String.valueOf(roll));

myCompass.update(matrixValues[0]);
}

}
}


Modify main.xml to add a View of Compass











our Android CompassCheers Guys!!!!!!!!

 

Copyright @ 2013 Android Developers Tipss.