Wednesday, February 19, 2014

View Switcher example

view flipper

download:  http://www.mediafire.com/download/7j0ycdg5j2mdpvy/ViewFlipperDemos.zip



package com.ui.yogeshblogspot;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ViewFlipper;

public class Main extends Activity {

ViewFlipper flipper;
Button btBackPage;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Getting View Flipper from main.xml and assigning to flipper reference
// variable
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
btBackPage = (Button) findViewById(R.id.btBackPage);

btBackPage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showPrevious();// shows the next view element of ViewFlipper
}
});
}

public void flipByClick(View v) {
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showNext();// shows the next view element of ViewFlipper
}

public void flipByInterval(View v) {
flipper.setFlipInterval(500);// setting the interval 500 milliseconds
flipper.startFlipping(); // views flipping starts.
}
}


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

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <!-- Calling flipByInterval() method of Activity class -->
       
         <Button
            android:id="@+id/btBackPage"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
             android:layout_weight="0.40"
            android:text="Back Flip"
            android:background="@android:color/holo_green_dark"/>

        <Button
            android:id="@+id/flipbyclick"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.40"
            android:background="@android:color/holo_green_dark"
            android:onClick="flipByClick"
            android:layout_marginLeft="10dp"
            android:text="Flip By Click" />

        <!-- calling flipByClick() method of Activity class -->
    </LinearLayout>
    <!-- ViewFlipper can contains any view elements in this case it contains 5 ImageView view Component with different Images -->

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/dialog_text" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img1" />
        <!-- Setting img1 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img2" />
        <!-- Setting img2 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img3" />
        <!-- Setting img3 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img4" />
        <!-- Setting img4 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img5" />
        <!-- Setting img5 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img6" />
        <!-- Setting img6 from drawable folder in ImageView -->

       

    </ViewFlipper>
   
 
   
    <Button
            android:id="@+id/flipbyinterval"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:onClick="flipByInterval"
            android:text="Flip By Interval" />

</LinearLayout>



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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >

        <Button
            android:id="@+id/imageViewSearchBanner"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:text="new btn" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >

        <Button
            android:id="@+id/ivForText"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:text="other btn" />
    </LinearLayout>

</LinearLayout>

Tuesday, February 11, 2014

file download with asynctask & progress bar


download:  http://www.mediafire.com/download/zlvy8f0gomntnhj/DownloadFileByProgressBar.zip



package com.example.androidhive;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class AndroidDownloadFileByProgressBarActivity extends Activity {

// button to show progress dialog
Button btnShowProgress;

// Progress Dialog
private ProgressDialog pDialog;
ImageView my_image;
// Progress dialog type (0 - for Horizontal progress bar)
public static final int progress_bar_type = 0;

// File url to download
private static String file_url = "http://api.androidhive.info/progressdialog/hive.jpg";

String download_path = "";

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

download_path = Environment.getExternalStorageDirectory().toString() + "/Download/";

// show progress bar button
btnShowProgress = (Button) findViewById(R.id.btnProgressBar);
// Image view to show image after downloading
my_image = (ImageView) findViewById(R.id.my_image);
/**
* Show Progress bar click event
* */
btnShowProgress.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// starting new Async Task
new DownloadFileFromURL().execute(file_url);
}
});
}

/**
* Showing Dialog
* */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}

/**
* Background Async Task to download file
* */
class DownloadFileFromURL extends AsyncTask<String, String, String> {

/**
* Before starting background thread
* Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}

/**
* Downloading file in background thread
* */
@Override
protected String doInBackground(String... f_url) {
int count;
       try {
           URL url = new URL(f_url[0]);
           URLConnection conection = url.openConnection();
           conection.connect();
           // getting file length
           int lenghtOfFile = conection.getContentLength();

           // input stream to read file - with 8k buffer
           InputStream input = new BufferedInputStream(url.openStream(), 8192);
         
           // Output stream to write file
           OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory().toString() +"/Download/downloadedfile.jpg");

           byte data[] = new byte[1024];

           long total = 0;

           while ((count = input.read(data)) != -1) {
               total += count;
               // publishing the progress....
               // After this onProgressUpdate will be called
               publishProgress(""+(int)((total*100)/lenghtOfFile));
             
               // writing data to file
               output.write(data, 0, count);
           }

           // flushing output
           output.flush();
         
           // closing streams
           output.close();
           input.close();
         
       } catch (Exception e) {
        Log.e("Error: ", e.getMessage());
       }
     
       return null;
}

/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
            pDialog.setProgress(Integer.parseInt(progress[0]));
       }

/**
* After completing background task
* Dismiss the progress dialog
* **/
@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);

// Displaying downloaded image into image view
// Reading image path from sdcard
String imagePath =  download_path +"downloadedfile.jpg";
// setting downloaded into image view
my_image.setImageDrawable(Drawable.createFromPath(imagePath));
}

}
}

Monday, February 10, 2014

scrollView with linearLayout



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- non-scrolling top pane -->

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".1" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="This text will not scroll" />
    </LinearLayout>

    <!-- scrolling bottom pane -->

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".80" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <TableLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@android:color/black" >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                     >

                    <Button
                        android:id="@+id/button1"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button2"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 3" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp" >

                    <Button
                        android:id="@+id/button3"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button4"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 3" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp" >

                    <Button
                        android:id="@+id/button5"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button6"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 3" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp" >

                    <Button
                        android:id="@+id/button7"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button8"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 3" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp" >

                    <Button
                        android:id="@+id/button9"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button10"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/fish_pressed"
                        android:text="Column 3" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp" >

                    <Button
                        android:id="@+id/button11"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 2" />

                    <Button
                        android:id="@+id/button12"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/gentleman_2"
                        android:text="Column 3" />
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>
   
   
     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".1" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="This text will not scroll" />
    </LinearLayout>

</LinearLayout>

Tuesday, February 4, 2014

facebook wall post with image

download: http://www.mediafire.com/download/dd0qqra99yrnbs1/facebookLoginWallPostWithSdk3.0.zip




public class MainActivity extends Activity {

private static final String APP_ID = "529772120384562";
private static final String[] PERMISSIONS = new String[] { "publish_stream" };

private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-credentials";

private Facebook facebook;
private String messageToPost;

Button btFacebookShareButton;

public boolean saveCredentials(Facebook facebook) {
Editor editor = getApplicationContext().getSharedPreferences(KEY,
Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, facebook.getAccessToken());
editor.putLong(EXPIRES, facebook.getAccessExpires());
return editor.commit();
}

public boolean deleteCredentials(Facebook facebook) {
Editor editor = getApplicationContext().getSharedPreferences(KEY,
Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, "");
editor.putLong(EXPIRES, 0);

Log.e("------deleteCredentials() ", " ");

return editor.commit();
}

public boolean restoreCredentials(Facebook facebook) {
SharedPreferences sharedPreferences = getApplicationContext()
.getSharedPreferences(KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

facebook = new Facebook(APP_ID);
restoreCredentials(facebook);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_main);

btFacebookShareButton = (Button) findViewById(R.id.btFacebookShareButton);

btFacebookShareButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
if (!facebook.isSessionValid()) {
loginAndPostToWall();
} else {
postToWall(messageToPost);
// loginAndPostToWall();
}

}
});

String facebookMessage = getIntent().getStringExtra("facebookMessage");
if (facebookMessage == null) {
facebookMessage = "https://play.google.com/store/apps/details?id=com.polarbit.rthunder2lite"
+ " minute = "
+ new Date().getMinutes()
+ " "
+ new Date().getSeconds();
}
messageToPost = facebookMessage;
}

@Override
public void onBackPressed() {

Log.e("------onBackPressed() ", " ");

// TODO Auto-generated method stub
super.onBackPressed();

deleteCredentials(facebook);
}

@Override
protected void onDestroy() {

Log.e("------onDestroy", " ");
// TODO Auto-generated method stub
super.onDestroy();

deleteCredentials(facebook);

}

public void doNotShare(View button) {
finish();
}

/*
* public void share(View button) { if (!facebook.isSessionValid()) {
* loginAndPostToWall(); } else { postToWall(messageToPost); //
* loginAndPostToWall(); } }
*/

public void loginAndPostToWall() {
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
new LoginDialogListener());
}

public void postToWall(String message) {
Bundle parameters = new Bundle();
parameters.putString("message", message);
parameters.putString("description", "topic share");

parameters.putString("picture", "http://upload.wikimedia.org/wikipedia/commons/a/a6/Bottlenose_Dolphin_KSC04pd0178.jpg");
parameters.putString("name", "BanglaGaan");
parameters.putString("caption", "G-Series Online Music Store");
parameters.putString("description", "Listening to ......");

try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("")
|| response.equals("false")) {
showToast("Blank response.");
} else {
showToast("Message posted to your facebook wall!");
}
// finish();
} catch (Exception e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
}

class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
saveCredentials(facebook);
if (messageToPost != null) {
postToWall(messageToPost);
}
}

public void onFacebookError(FacebookError error) {
showToast("Authentication with Facebook failed!");
finish();
}

public void onError(DialogError error) {
showToast("Authentication with Facebook failed!");
finish();
}

public void onCancel() {
showToast("Authentication with Facebook cancelled!");
finish();
}
}

private void showToast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
.show();
}

}

Thursday, December 19, 2013

andEngine full screen image backGround & jumping sprite

download: http://www.mediafire.com/download/xmj35iv0ovkz30o/jumpSprite(2).zip






package com.example.animationsprite;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.extension.physics.box2d.PhysicsConnector;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.extension.physics.box2d.util.Vector2Pool;
import org.andengine.input.sensor.acceleration.AccelerationData;
import org.andengine.input.sensor.acceleration.IAccelerationListener;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.debug.Debug;

import android.hardware.SensorManager;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class MainActivity extends SimpleBaseGameActivity implements
        IAccelerationListener {

    private static final int CAMERA_WIDTH = 360;
    private static final int CAMERA_HEIGHT = 240;

    private BitmapTextureAtlas mBitmapTextureAtlas,
            backgroundBitmapTextureAtlas;

    private TiledTextureRegion mBoxFaceTextureRegion;
    ITextureRegion backgroundTiledTextureRegion;

    private int mFaceCount = 0;

    private PhysicsWorld mPhysicsWorld;

    float mGravityX;
    float mGravityY;

    private Scene mScene;

    AnimatedSprite faceAnimatedSprite;
    Body bodyFace;
    FixtureDef faceFixtureDef = PhysicsFactory.createFixtureDef(100, 0.1f, 0.0f),
            wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.0f, 0.0f);

    Camera camera;
    BuildableBitmapTextureAtlas mBuildableBitmapTextureAtlas;

    Sprite backGroundSprite;

    @Override
    public EngineOptions onCreateEngineOptions() {

        camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

        return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
                new FillResolutionPolicy(), camera);
    }

    @Override
    public void onCreateResources()

    {
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

        // this.mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(
        // this.getTextureManager(), 1024, 512, TextureOptions.DEFAULT);

        this.mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(
                this.getTextureManager(), 1024, 512, TextureOptions.DEFAULT);

        setBackgroundImage();

       

        this.mBitmapTextureAtlas = new BitmapTextureAtlas(
                this.getTextureManager(), 64, 64, TextureOptions.BILINEAR);
        this.mBoxFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createTiledFromAsset(this.mBitmapTextureAtlas, this,
                        "face_box_tiled.png", 0, 0, 2, 1); // 64x32

        this.mBitmapTextureAtlas.load();

        try {
            this.mBuildableBitmapTextureAtlas
                    .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                            0, 0, 1));
            this.mBuildableBitmapTextureAtlas.load();
        } catch (TextureAtlasBuilderException e) {
            Debug.e(e);
        }
    }

    void setBackgroundImage() {
        this.backgroundBitmapTextureAtlas = new BitmapTextureAtlas(
                this.getTextureManager(), 512, 1024, TextureOptions.NEAREST_PREMULTIPLYALPHA);
        backgroundTiledTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(backgroundBitmapTextureAtlas, this,
                        "background_sky.png", 0, 0);
        this.backgroundBitmapTextureAtlas.load();

    }

    @Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,
                SensorManager.GRAVITY_EARTH), false);

        this.mScene = new Scene();
        // this.mScene.setBackground(new Background(0, 0, 0));
        backGroundSprite = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT,
                this.backgroundTiledTextureRegion,
                this.getVertexBufferObjectManager());

        // scene.setBackground(new Background(Color.WHITE));
        mScene.setBackgroundEnabled(false);
        this.mScene.attachChild(backGroundSprite);

        create_4_Wall();

        create_face_sprite();

        mScene.setOnSceneTouchListener(new IOnSceneTouchListener() {

            @Override
            public boolean onSceneTouchEvent(Scene pScene,
                    TouchEvent pSceneTouchEvent) {

                if (pSceneTouchEvent.isActionDown()) {
                    // body.setLinearVelocity(new
                    // Vector2(body.getLinearVelocity().x,-8f));
                    jumpFace(bodyFace);

                }
                return false;
            }
        });

        return this.mScene;
    }

    private void create_face_sprite() {
        // for sprite
        faceAnimatedSprite = new AnimatedSprite(200, 200,
                this.mBoxFaceTextureRegion, this.getVertexBufferObjectManager());

        bodyFace = PhysicsFactory.createBoxBody(this.mPhysicsWorld,
                faceAnimatedSprite, BodyType.DynamicBody, faceFixtureDef);
        faceAnimatedSprite.animate(new long[] { 200, 200 }, 0, 1, true);
        faceAnimatedSprite.setUserData(bodyFace);
        // this.mScene.registerTouchArea(face);

        // physicsHandler = new PhysicsHandler(face);
        // face.registerUpdateHandler(physicsHandler);
        this.mScene.attachChild(faceAnimatedSprite);
        this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
                faceAnimatedSprite, bodyFace, true, true));
        // end for sprite

    }

    private void create_4_Wall() {
        final VertexBufferObjectManager vertexBufferObjectManager = this
                .getVertexBufferObjectManager();
        final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2,
                CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle roof = new Rectangle(0, 0, CAMERA_WIDTH, 2,
                vertexBufferObjectManager);
        final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT,
                vertexBufferObjectManager);
        final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2,
                CAMERA_HEIGHT, vertexBufferObjectManager);

        PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
                BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
                BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
                BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
                BodyType.StaticBody, wallFixtureDef);

        this.mScene.attachChild(ground);
        this.mScene.attachChild(roof);
        this.mScene.attachChild(left);
        this.mScene.attachChild(right);

        this.mScene.registerUpdateHandler(this.mPhysicsWorld);

    }

    @Override
    public void onAccelerationAccuracyChanged(
            final AccelerationData pAccelerationData) {

    }

    @Override
    public void onAccelerationChanged(final AccelerationData pAccelerationData) {
        this.mGravityX = pAccelerationData.getX();
        this.mGravityY = pAccelerationData.getY();

        final Vector2 gravity = Vector2Pool.obtain(this.mGravityX,
                this.mGravityY);

        // this.mPhysicsWorld.setVelocityIterations(10);
        this.mPhysicsWorld.setGravity(gravity);
        Vector2Pool.recycle(gravity);
    }

    @Override
    public void onResumeGame() {
        super.onResumeGame();

        this.enableAccelerationSensor(this);
    }

    @Override
    public void onPauseGame() {
        super.onPauseGame();

        this.disableAccelerationSensor();
    }

    void jumpFace(Body _body) {

        Body body = _body;

        Vector2 velocity = Vector2Pool.obtain(0, -5);

        // Vector2 velocity = Vector2Pool.obtain(10, 10);

        body.setLinearVelocity(velocity);
        Vector2Pool.recycle(velocity);

    }

}