Screen Oreintation with custom camera in samsung mobile
<p>in my app requirement for custom camera so developing one, upto that ok everything working fine getting the picture also but when i take picture with my Samsung galaxy ace android phone(2.3) on landscape mode its ok but while going to portrait mode the view of the picture move to left side with 90 degree angle.As you can see in my code i had tried to change the surface position also but nothing happen.
Here is the code for Myactivity class</p>

<pre><code>package com.goutam.test_camera;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

public class CameraclassActivity extends Activity implements OnClickListener,
        PictureCallback {
    ImageButton take_picture, retake_button, save_picture, setting_button;
    FrameLayout camerapreviewsurface;
    Previewclass cameradisplayclass;
    ImageView capture_image;
    HorizontalScrollView myscrollview;
    private Camera myowncamera;

    byte[] finalimage;
    Bitmap pic_cap_bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_portrait);
        take_picture = (ImageButton) findViewById(R.id.imageButton1);
        //
        retake_button = (ImageButton) findViewById(R.id.imageButton3);
        //
        save_picture = (ImageButton) findViewById(R.id.imageButton4);
        //
        setting_button = (ImageButton) findViewById(R.id.imageButton2);
        //
        capture_image = (ImageView) findViewById(R.id.imageView1);
        //
        myscrollview = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
        //
        take_picture.setOnClickListener(this);
        retake_button.setOnClickListener(this);
        save_picture.setOnClickListener(this);
        //
        retake_button.setVisibility(View.INVISIBLE);
        save_picture.setVisibility(View.INVISIBLE);
        setting_button.setVisibility(View.INVISIBLE);
        capture_image.setVisibility(View.INVISIBLE);
        myscrollview.setVisibility(View.INVISIBLE);
        //
        myowncamera = Camera.open();
        camerapreviewsurface = (FrameLayout) findViewById(R.id.framelayout1);
        cameradisplayclass = new Previewclass(this, myowncamera);
        camerapreviewsurface.addView(cameradisplayclass);
        Log.i("ACTIVITY", "ON CREATE");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.imageButton1:
            takePicture();
            break;
        }

    }

    private void takePicture() {
        // TODO Auto-generated method stub
        take_picture.setVisibility(View.INVISIBLE);
        cameradisplayclass.takepicture(this);

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        // setContentView(R.layout.layout_portrait);
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        // TODO Auto-generated method stub
        finalimage = data;
        // camera.stopPreview();
        this.myowncamera = camera;
        retake_button.setVisibility(View.INVISIBLE);
        camerapreviewsurface.setVisibility(View.INVISIBLE);
        setting_button.setVisibility(View.VISIBLE);
        capture_image.setVisibility(View.VISIBLE);
        Toast.makeText(getApplicationContext(), "PICTURE TAKEN", 0).show();
        new DisplayImageTask().execute(finalimage);
    }

    private class DisplayImageTask extends AsyncTask&lt;byte[], Void, Bitmap&gt; {
        @Override
        protected Bitmap doInBackground(byte[]... parameter) {
            pic_cap_bitmap = BitmapFactory.decodeByteArray(finalimage, 0,
                    finalimage.length);
            return pic_cap_bitmap;
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            capture_image.setImageBitmap(pic_cap_bitmap);
            super.onPostExecute(result);
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            Toast.makeText(getApplicationContext(), "DISPLAYING IMAGE", 0)
                    .show();
            super.onProgressUpdate(values);
        }

    }

    // @Override
    // public boolean onCreateOptionsMenu(Menu menu) {
    // // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.layout_portrait, menu);
    // return true;
    @Override
    protected void onPause() {
        Log.i("ACTIVITY", "ON PAUSE");
        System.gc();
        this.finish();
        super.onPause();
    }

    @Override
    protected void onResume() {

        super.onResume();
    }

    @Override
    public void onBackPressed() {
        System.gc();
        this.finish();
        myowncamera.release();
        super.onBackPressed();
    }

    @Override
    protected void onDestroy() {
        this.finish();
        System.gc();
        super.onDestroy();
    }
}
</code></pre>

<hr>

<p>and here is the code for the preview class for my surfaceholder to hold the surface view </p>

<pre><code>package com.goutam.test_camera;

import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.util.Log;
import android.view.Display;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class Previewclass extends SurfaceView implements Callback {
    private Camera mcamera;
    boolean ispreviewing = false;
    // WindowManager manager;
    SurfaceHolder holder;

    public Previewclass(Context context, Camera mycamera) {

        super(context);
        this.mcamera = mycamera;
        // manager=(WindowManager)
        // context.getSystemService(Context.WINDOW_SERVICE);
        holder = this.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // mcamera=null;
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        Log.i("CAMERA", "ON SURFACE CHANGE");

        try {
            mcamera.setPreviewDisplay(this.holder);
            mcamera.startPreview();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // if(ispreviewing==true)
        // {
        // mcamera.stopPreview();
        // }
        // Parameters mparameters=mcamera.getParameters();
        // Display display=manager.getDefaultDisplay();
        // if(display.getRotation()==Surface.ROTATION_0)
        // {
        // mparameters.setPreviewSize(height, width);
        // mcamera.setDisplayOrientation(90);
        // }
        // if(display.getRotation()==Surface.ROTATION_90)
        // {
        // mparameters.setPreviewSize(width, height);
        // }
        // if(display.getRotation() == Surface.ROTATION_180)
        // {
        // mparameters.setPreviewSize(height, width);
        // }
        // if(display.getRotation() == Surface.ROTATION_270)
        // {
        // mparameters.setPreviewSize(width, height);
        // mcamera.setDisplayOrientation(180);
        // }
        // mcamera.setParameters(mparameters);
        // previewCamera();
    }

    // private void previewCamera()
    // {
    // try {
    // mcamera.setPreviewDisplay(this.holder);
    // mcamera.startPreview();
    // ispreviewing = true;
    // } catch (IOException e) {
    // Log.e("CAMERA DISPLAY", "ERROR");
    // e.printStackTrace();
    // }
    //
    // }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        Log.i("CAMERA", "ON SURFACE CREATED");
        try {

            mcamera.setPreviewDisplay(holder);
            ispreviewing = true;
            mcamera.startPreview();
        } catch (IOException e) {
            Log.e("CAMERA OPENING", "ERROR");
            e.printStackTrace();
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.i("CAMERA", "ON SURFACE DESTROY");
        this.mcamera = null;
        // this.manager=null;
        this.holder = null;
        // mcamera.stopPreview();
        // this.mcamera.release();

    }

    public void takepicture(PictureCallback imageCallback) {
        mcamera.takePicture(null, null, imageCallback);

    }

}
</code></pre>

<hr>

<p>here is my androidmanifest.xml</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.goutam.test_camera"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="16" /&gt;

    &lt;uses-permission android:name="android.permission.CAMERA" /&gt;

    &lt;uses-feature android:name="android.hardware.camera" /&gt;
    &lt;uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" /&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name="com.goutam.test_camera.CameraclassActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<blockquote>
  <p>i am stuck with this thing for very long time but didn't found any
  solution
      as i am new to android not able identify the behaviour on android device. 
      but one thing is there the same code is work very well with the htc made android phone.So,can i assume that this is the hardware
  default which is providing by the manufacturer.If anyone want the .apk
  file for test i can send to them.
      email id:gkundu07@gmail.com
      Sorry for my language and thanks for listening me.
      Any kind of help will be appreciate.</p>
</blockquote>
