CameraPreview.java 3.07 KB
package com.bitstrips.imoji.ui.views;

import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View.MeasureSpec;
import java.io.IOException;

public class CameraPreview
  extends SurfaceView
  implements SurfaceHolder.Callback
{
  private SurfaceHolder a = getHolder();
  private Camera b;
  
  public CameraPreview(Context paramContext)
  {
    super(paramContext);
  }
  
  public CameraPreview(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
  }
  
  public void attachCamera(Camera paramCamera)
  {
    this.b = paramCamera;
    this.a.addCallback(this);
    try
    {
      if (!this.a.isCreating())
      {
        this.b.setPreviewDisplay(this.a);
        this.b.startPreview();
      }
      requestLayout();
      return;
    }
    catch (IOException paramCamera)
    {
      for (;;)
      {
        Log.e("CameraPreview", "Error setting camera preview: " + paramCamera.getMessage());
      }
    }
    catch (RuntimeException paramCamera)
    {
      for (;;)
      {
        Log.e("CameraPreview", "Runtime error setting camera preview: " + paramCamera.getMessage());
      }
    }
    catch (Exception paramCamera)
    {
      for (;;)
      {
        Log.e("CameraPreview", "Some error setting camera preview: " + paramCamera.getMessage());
      }
    }
  }
  
  protected void onMeasure(int paramInt1, int paramInt2)
  {
    if (this.b == null)
    {
      super.onMeasure(paramInt1, paramInt2);
      return;
    }
    paramInt1 = View.MeasureSpec.getSize(paramInt1);
    paramInt2 = View.MeasureSpec.getSize(paramInt2);
    Camera.Size localSize = this.b.getParameters().getPreviewSize();
    if (localSize.height >= localSize.width) {}
    int j;
    for (float f = localSize.width / localSize.height;; f = localSize.height / localSize.width)
    {
      int i = (int)(paramInt2 * f);
      j = (int)(paramInt1 / f);
      if (i <= paramInt1) {
        break;
      }
      setMeasuredDimension(i, paramInt2);
      return;
    }
    setMeasuredDimension(paramInt1, j);
  }
  
  public void releaseCamera()
  {
    this.a.removeCallback(this);
    this.b = null;
  }
  
  public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1, int paramInt2, int paramInt3) {}
  
  public void surfaceCreated(SurfaceHolder paramSurfaceHolder)
  {
    try
    {
      this.b.setPreviewDisplay(paramSurfaceHolder);
      this.b.startPreview();
      return;
    }
    catch (IOException paramSurfaceHolder)
    {
      Log.e("CameraPreview", "Error setting camera preview: " + paramSurfaceHolder.getMessage());
    }
  }
  
  public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder) {}
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/ui/views/CameraPreview.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */