title: Get buttons to open custom dialog with camera preview in surface view
body: <p>I have two buttons that need to open a custom dialog that has a surface view that's supposed to hold a camera preview. I need to not have the default camera controls, just the preview itself, behind another included layout that's holding buttons.</p>
  
  <p>Here's the code for my buttons:</p>
  
  <pre><code>topeyebtn.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View arg3) {
  
                                  //Starting a new Intent
  
                                  Intent topClick = new Intent(Intent.ACTION_VIEW,      Uri.parse("http://funnmag.com"));
  
                                  // starting new activity
  
                                  startActivity(topClick);      
               }});
  </code></pre>
  
  <p>And here's the code for my surface view and camera preview:</p>
  
  <pre><code>package com.adanawtn.FunnMagViewerWindow;
  
  import java.io.IOException;
  import android.app.Activity;
  import android.graphics.PixelFormat;
  import android.hardware.Camera;
  import android.os.Bundle;
   import android.view.SurfaceHolder;
   import android.view.SurfaceView;
   import android.view.ViewGroup.LayoutParams;
  
   public class camerapreview extends Activity {
  
   private SurfaceView surface_view;  
   private Camera mCamera;
   SurfaceHolder.Callback sh_ob = null;
   SurfaceHolder surface_holder        = null;
   SurfaceHolder.Callback sh_callback  = null;
  
  
  @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
  
       getWindow().setFormat(PixelFormat.TRANSLUCENT);
  
       surface_view = new SurfaceView(getApplicationContext());
       addContentView(surface_view, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  
       if (surface_holder == null) {
           surface_holder = surface_view.getHolder();
       }
  
       sh_callback = my_callback();
       surface_holder.addCallback(sh_callback);
   }
  
       SurfaceHolder.Callback my_callback() {      
           SurfaceHolder.Callback ob1 = new SurfaceHolder.Callback() {
  
               @Override
               public void surfaceDestroyed(SurfaceHolder holder) {
                     mCamera.stopPreview();
                     mCamera.release();
                     mCamera = null;
               }
  
               @Override
               public void surfaceCreated(SurfaceHolder holder) {
                   mCamera = Camera.open();
  
                     try {
                          mCamera.setPreviewDisplay(holder);  
                     } catch (IOException exception) {  
                           mCamera.release();  
                           mCamera = null;  
                     }
               }
  
               @Override
               public void surfaceChanged(SurfaceHolder holder, int format, int width,
                       int height) {
                   mCamera.startPreview();
               }
           };
           return ob1;
   }
  }
  </code></pre>