Laman

Thursday, December 30, 2010

Implement takePicture function of Android Camera

In order to implement takePicture function of Android Camera, we have to implement ShutterCallback, PictureCallback for RAW and PictureCallback for JPG. To take picture, simple call camera.takePicture() method passing with the Callbacks.

takePicture

Modify from the last exercise "Add a overlay on Camera Preview SurfaceView". Modify AndroidCamera.java
package com.exercise.AndroidCamera;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;

public class AndroidCamera extends Activity implements SurfaceHolder.Callback{

Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;

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

getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control, null);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);

Button buttonTakePicture = (Button)findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
camera.takePicture(myShutterCallback,
myPictureCallback_RAW, myPictureCallback_JPG);
}});
}

ShutterCallback myShutterCallback = new ShutterCallback(){

@Override
public void onShutter() {
// TODO Auto-generated method stub

}};

PictureCallback myPictureCallback_RAW = new PictureCallback(){

@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub

}};

PictureCallback myPictureCallback_JPG = new PictureCallback(){

@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
Bitmap bitmapPicture
= BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
}};

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopPreview();
previewing = false;
}

if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
}


Download the files.

next:
- Save the camera image using MediaStore



READ MORE - Implement takePicture function of Android Camera

Wednesday, December 29, 2010

3G Airtel's New Signature AD | Street Performer

Airtel's 2010 New Signature AD



Download

READ MORE - 3G Airtel's New Signature AD | Street Performer

Add a overlay on Camera Preview SurfaceView

Modify from last exercise "Camera Preview, version II", a overlay will be add on the Camera Preview SurfaceView. Controls; such as "Take Picture" button is added on the overlay.

Add a overlay on Camera Preview SurfaceView

Keep using the AndroidManifest.xml and main.xml in last exercise "Camera Preview, version II" without change.

Add a layout xml file, control.xml, under /res/layout folder. It define the layout of the control layer.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<Button
android:id="@+id/takepicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" * Take Picture "
android:layout_gravity="right"
android:layout_margin="10px"
/>
</LinearLayout>


Modify AndroidCamera.java to inflate a layer using control.xml
package com.exercise.AndroidCamera;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class AndroidCamera extends Activity implements SurfaceHolder.Callback{

Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;

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

getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control, null);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);

}



@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopPreview();
previewing = false;
}

if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
}


Download the files.

next:
- Implement takePicture function of Android Camera
READ MORE - Add a overlay on Camera Preview SurfaceView

Tuesday, December 28, 2010

Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets


Product Description

Mobile devices have evolved to focus on rich media production and consumption. Developers of mobile applications are able to create applications that allow people to play, capture, and share media in a variety of new ways on mobile devices. The popularity of Android has soared in part because the platform offers developers a rich set of capabilities including access to media capturing and playback functions.

Pro Android Media provides concise and clear instruction on how to utilize the media APIs made available through Android to create dynamic apps. It takes you from a simple means to gain access to the camera to complex video capture and sharing examples. It also covers sound, graphics, painting, and more—everything you need to make your app come "alive."

After reading this book, the app you create will showcase the best of multimedia that Android has to offer.

What you’ll learn

  • Develop graphics, music, video and rich media apps for Android smartphones and tablets
  • Build touchscreen input features into Android apps that allow users to draw, paint, and do other creative forms of input.
  • Turn the Android smartphone into a full fledged media player
  • How to integrate and use location based services and media related web service APIs

Who this book is for

This book is aimed primarily at the growing market of Android developers. It is written in such a way that it may be used by those who are familiar with Android, but have no experience developing applications that deal with images, audio, or video.



READ MORE - Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets

Camera Preview, version II

In the exercise "Camera Preview on SurfaceView", I show how to using Android's camera preview on a SurfaceView. The preview is set Start/Stop using buttons, it's not a good approach I think. In this exercise, it is re-arranged to handle the preview in SurfaceHolder.Callback methods: surfaceCreated(), surfaceChanged() and surfaceDestroyed().

Android's Camera Preview

Remember to grant permission to access Camera AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidCamera"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidCamera"
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>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
</manifest>


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView
android:id="@+id/camerapreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


AndroidCamera.java
package com.exercise.AndroidCamera;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class AndroidCamera extends Activity implements SurfaceHolder.Callback{

Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;;

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

getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}



@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopPreview();
previewing = false;
}

if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
}


Download the files.

next:
- Add a overlay on Camera Preview SurfaceView



READ MORE - Camera Preview, version II

Monday, December 27, 2010

Wallpaper Iqbal Khan

http://1.bp.blogspot.com/-BiAeCS4LgYg/Ta8CYBZnonI/AAAAAAAAG6I/c9iA4Vl-Umw/s1600/104792-iqbal-khan.jpg
... Selena Gomez Hot Hot Girl Wallpapers 3D Wallpapers Nature Wallpapers




http://4.bp.blogspot.com/-hFVoSal9K50/Ta8CMIVSJ9I/AAAAAAAAG5o/i6VIH71YuBs/s1600/iqbal_khan.jpg
Iqbal Khan Wallpaper Pack 1 ~ Wallpaper Fetch


http://1.bp.blogspot.com/-M_KY-caiP9c/Ta8CL96ohAI/AAAAAAAAG5g/NKqTBGKNesE/s1600/iqbal1.jpg
Wallpaper Millenium Era: Iqbal Khan Wallpaper Pack 1


twofuckinpresents.xvideosplay.com


http://3.bp.blogspot.com/-1lQwroNfVZU/Ta8CciEjA9I/AAAAAAAAG6Y/3-tUbcV2KFQ/s1600/2006-10-14_8344_iqbal_khan_59_1024x768.jpg
Wallpaper Millenium Era: Iqbal Khan Wallpaper Pack 1


http://1.bp.blogspot.com/-AH24w-bv90A/Ta8CK_uM20I/AAAAAAAAG5I/r5ZscfdYkrY/s1600/photo-35987.jpg
Iqbal Khan Wallpaper Pack 1 ~ Wallpaper Fetch


http://3.bp.blogspot.com/-PiZCUFxmDkQ/Ta8CYQJE7DI/AAAAAAAAG6Q/6m3y7cqKY9g/s1600/94131-iqbal-khan-in-tv-show-sanjog-se-bani-sangini.jpg
Wallpaper Millenium Era: Iqbal Khan Wallpaper Pack 1


http://3.bp.blogspot.com/-I-s-mw7qgt0/Ta8CLUZY-5I/AAAAAAAAG5Y/8PPbWHWTriQ/s1600/MIKWP.png
Iqbal Khan Wallpaper Pack 1 ~ Wallpaper Fetch


http://1.bp.blogspot.com/-rJ08DKI8uj0/Tpw56P18M4I/AAAAAAAAASs/R1lhqsN1Ga8/s1600/Amir_Khan_Wallpaper.jpg
Posted by muhammad faisal iqbal at 07:22


http://1.bp.blogspot.com/-pGb_umbGcgk/Ta8CK4Nsy5I/AAAAAAAAG5Q/4RLlpTZSFR8/s1600/photo-35986.jpg
Wallpaper Millenium Era: Iqbal Khan Wallpaper Pack 1


http://1.bp.blogspot.com/-GMYII0E2_3Q/TdOR_pGNnMI/AAAAAAAAGlo/tbGdvQ9smeI/s1600/img_2219.jpg
iqbal khan movie 3 thay bhai posters free


http://4.bp.blogspot.com/-sznnBe60wVU/Tpw53EDlhLI/AAAAAAAAASM/zkoGURAzCJs/s1600/aamir+khan+ghajini+wallpaper+photo+image+poster+pic.jpg
Celebrities Corner: Aamir Khan


http://1.bp.blogspot.com/-5vDl4jDea2U/TawiIhvY8II/AAAAAAAAC8U/maZ6ww_hE9U/s1600/Saif%2Bali%2Bkhan%2Bwallpapers.jpg
Saif Ali Khan’s Dhishum Dhishum Act – What Tweeples Are Saying?


http://1.bp.blogspot.com/-dNQe79SjfbQ/UGM59c0NCaI/AAAAAAAAByU/GJUbUMD68Q8/s1600/Aris%2BBerbagi%2BInfo-Iqbal%2BCoboy%2BJr%2B10.jpg
Fotos de Iqbal / Imagenes de Iqbal - Photos


http://1.bp.blogspot.com/-XfuCVCU_HZ0/Teoqu48yjNI/AAAAAAAAG8Y/1w4TOjEDR6Q/s1600/Wallpaper+Imran+Khan.jpg
... Khan Photo | Free Imran Khan Wallpaper | Free Imran Khan Pictures


http://4.bp.blogspot.com/-LVbBRzGAwTA/Tlhd6jsLz4I/AAAAAAAAADE/lAj1MDdLXss/s1600/salman-khan-wallpapers-2011-2.jpg
Andaleeb Raja


http://2.bp.blogspot.com/-ObSXCqesdWc/TpqX9eENBfI/AAAAAAAAALg/5ay0D1pL83o/s1600/Salman+khan+wallpapers+Download+salman+khan+desktop+wallpaper+free+pc+desktop.jpg
salman khan salman khan salman khan salman khan salman khan in veer


http://1.bp.blogspot.com/-z7DczACoQUw/TjyLPNpRZpI/AAAAAAAAEIU/kqNrhMMGWjc/s1600/Nangyaly+102.jpg
... New Movie "Nangyaly" Pics, Shahid Khan and Asma Lata Latest Images


http://3.bp.blogspot.com/-Y9JKtyng6tI/TjuOfdnYz6I/AAAAAAAAAN0/1GcLwL4rrDU/s1600/Divyanka%2BTripathi%2Bpicture.JPG
Welcome to Ahouraian Law, a full service corporate and entertainment ...


http://2.bp.blogspot.com/-6qK4md6g0dc/TqAoDIJQ-MI/AAAAAAAAC_8/TDJmsFN_vTg/s1600/Free-Zaheer-Khan-Wallpapers-.jpg
Khan Faree - Email, Fotos, Telefonnummern zu Khan Faree


http://1.bp.blogspot.com/--rxlvjX-w7w/UHQoE2sjBEI/AAAAAAAABAY/pR9tnuQXduM/s1600/Cricket_Wallpaper_HD_14.jpg
Cricket wallpapers ~ Free Wallpapers


http://3.bp.blogspot.com/-0D9L35ATRwA/UKDPEzuaB6I/AAAAAAAAAEk/uM514K15M6w/s1600/allama-iqbal-best-poetry.jpg
knowledge world: Poetry By Iqbal


http://3.bp.blogspot.com/-m0OqvqdCnKA/TpqX7Nada5I/AAAAAAAAALY/tjQ8z9Pc1Bw/s1600/Salman+khan+veer+wallpapers+Download+free+wallpaper.jpg
salman khan salman khan salman khan salman khan salman khan


http://3.bp.blogspot.com/-NrAfjDKFc5s/TfEm9U_6U0I/AAAAAAAAAKs/Uuv5z0sUfpI/s1600/aamir%252Bkhan%252Bwallpaper%252Bmangal%252Bpande%252Bbollywood%252Bmovie%252Bposter%252Bphoto%252Bimage.jpg
Email This BlogThis! Share to Twitter Share to Facebook


http://1.bp.blogspot.com/-SeWU0dAfYuk/UB3n16EZmLI/AAAAAAAACUQ/g9iAtSNj3IM/s1600/14-August-independence-day-of-Pakistan-HD-wallpaper-and-greeting-card-08-Quaid-i-Azam-allama-iqbal-liaquat-ali-khan-and-other.jpg
(Yaum-e-Azadi) pakistan zindabad wallpapers and 14 augest wallpapers ...


http://1.bp.blogspot.com/-Q4d29V9SiAY/TeXDHgFlicI/AAAAAAAAA0Y/L0Ucps9y2yk/s1600/Kajal+agarwal+%25282%2529.jpg
Posted by Shahid Khan at 21:44 1 comments


http://1.bp.blogspot.com/-uZ3HnJpOyiE/Tp7Wi3Am0XI/AAAAAAAAAuw/1gPVmAjD4mY/s1600/DSC09776.JPG
Celebrities Corner: Faisal Iqbal


http://1.bp.blogspot.com/_K2P7qPdEWCE/TNxL_FlPF7I/AAAAAAAAHIY/6w82Jj9rZAQ/s1600/ami160a.jpg
Khan Rzaq - Email, Fotos, Telefonnummern zu Khan Rzaq


http://1.bp.blogspot.com/-RQkFUGfzpcM/UHQn9ZWj4BI/AAAAAAAAA_4/HCoRvv1NqOA/s1600/B.LEE.aus+copy.jpg
Cricket wallpapers ~ Free Wallpapers


http://2.bp.blogspot.com/-sZ4_X-iNmYE/S-afZa5emqI/AAAAAAAAAPs/mlph49whRTo/s1600/3d-wide-wallpapers-2650x1600.jpg
William Wallpaper: Abstract #D


http://3.bp.blogspot.com/-bOT8ranWo0w/TgG5EvxFe6I/AAAAAAAAG6c/nMwkYBGfY84/s1600/Mahabat%2BKhan%2BMosque%2BWallpapers%2B%25285%2529.jpg
Free Wallpapers: Mahabat Khan Mosque Wallpapers


http://4.bp.blogspot.com/-GPL1mf4WcVA/TdOR_dzZ77I/AAAAAAAAGlg/1RAWwBCq44s/s1600/126839-ragini-khanna-at-radio-mirchi-premiere-the-music-of-movie-teen.jpg
ragini khanna at the music of movie 3 thay bhai


http://4.bp.blogspot.com/-Q99yklFVQSo/T2Snayv6sHI/AAAAAAAAE4E/0vL0FuVhpWs/s1600/getimage.dll_.jpg
HD Wallpapers - Indian Actors, Hollywood Actors, Pakistani Actors


http://3.bp.blogspot.com/-PjqPgEf6vFM/TeoqnLFbkjI/AAAAAAAAG8E/8VYzNukyANA/s1600/Best+Wallpaper+Imran+Khan.jpg
Me-Wallpaper: Imran Khan Photo


http://1.bp.blogspot.com/-W2qOh-p2I1Q/TtHxOacwI8I/AAAAAAAAB54/8biCUG8GY_A/s1600/m1.jpg
Email This BlogThis! Share to Twitter Share to Facebook


http://4.bp.blogspot.com/-p5TEBp55Krc/UMZeXMGnQYI/AAAAAAAAKjg/gndrDcJwg8k/s1600/sara+khan+1+(1).jpg
Khan Faree - Email, Fotos, Telefonnummern zu Khan Faree


http://3.bp.blogspot.com/-ZzFeRMmNdgo/TdOVZ7Z6wkI/AAAAAAAAGl4/HgqiAbAnjD8/s1600/img_9538.jpg
... Movie Picture, Film Photos: latest hindi movie - 3 thay bhai wallpaper


http://3.bp.blogspot.com/-G7PwQ1pG2Fk/TmzWU25LqpI/AAAAAAAACFA/LbEO5NBV72g/s1600/Neha-Bamb_035.jpg
Neha Bamb | Wallpaper | Hot Pics | Bio


http://4.bp.blogspot.com/_W6jq30E3-X0/TF6V3LovmyI/AAAAAAAAAFQ/5N_9tl7Mcpk/s1600/taare_zameen_par.jpeg
August 2010 | Download bollywood songs


http://1.bp.blogspot.com/-PiGhBIxKICk/Tic-1zVYDyI/AAAAAAAAAKc/9bnbvw0vHR8/s1600/Sachin%2BTendulkar%2BWallpaper%2B0105.jpg
Email This BlogThis! Share to Twitter Share to Facebook


http://3.bp.blogspot.com/-F_m6OP52NuI/UHQoCbt3eaI/AAAAAAAABAQ/GvBoLrRylqA/s1600/Cricket_Wallpaper_HD_03.jpg
Cricket wallpapers ~ Free Wallpapers


READ MORE - Wallpaper Iqbal Khan

Sunday, December 26, 2010

In-correct arrow icon on Spinner with custom ArrayAdapter

Refer to the exercise "Custom ArrayAdapter for Spinner, with different icons"; it implement a Spinner with custom ArrayAdapter, base on Build Target of Android 1.6, and android:minSdkVersion="4".

When it run on AVD of Android 2.1, the drop-down arrow on the right side is in-corret.
Run on AVD of Android 2.1

The same code, when it run on AVD of Android 2.3, the arrow is displayed correctly.
Run on AVD of Android 2.3

Up to this minute, I have no any idea on this problem. Sorry for any inconvenience caused!

Updated@2012-01-13: Please read command by RSZ below.

READ MORE - In-correct arrow icon on Spinner with custom ArrayAdapter
Related Posts Plugin for WordPress, Blogger...