import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera;
import android.hardware.Camera.Face;
-import android.hardware.Camera.Size;
import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.TextureView;
import com.android.camera.CameraPreference.OnPreferenceChangedListener;
import com.android.camera.FocusOverlayManager.FocusUI;
+import com.android.camera.ui.ModuleSwitcher;
import com.android.camera.util.ApiHelper;
import com.android.camera.ui.AbstractSettingPopup;
import com.android.camera.ui.CameraControls;
import com.android.camera.ui.CameraRootView;
-import com.android.camera.ui.CameraSwitcher;
-import com.android.camera.ui.CameraSwitcher.CameraSwitchListener;
import com.android.camera.ui.CountDownView;
import com.android.camera.ui.CountDownView.OnCountDownFinishedListener;
import com.android.camera.ui.FaceView;
private View mMenuButton;
private PhotoMenu mMenu;
- private CameraSwitcher mSwitcher;
+ private ModuleSwitcher mSwitcher;
private CameraControls mCameraControls;
private AlertDialog mLocationDialog;
int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int width = right - left;
int height = bottom - top;
- // Full-screen screennail
+ // Full-screen preview
int w = width;
int h = height;
if (CameraUtil.getDisplayRotation(mActivity) % 180 != 0) {
if (mPreviewWidth != width || mPreviewHeight != height) {
mPreviewWidth = width;
mPreviewHeight = height;
+ setTransformMatrix(width, height);
mController.onScreenSizeChanged(width, height, w, h);
}
}
private class DecodeTask extends AsyncTask<Integer, Void, Bitmap> {
private final byte [] mData;
+ private int mOrientation;
+ private boolean mMirror;
- public DecodeTask(byte[] data) {
+ public DecodeTask(byte[] data, int orientation, boolean mirror) {
mData = data;
+ mOrientation = orientation;
+ mMirror = mirror;
}
@Override
protected Bitmap doInBackground(Integer... params) {
// Decode image in background.
- return CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR);
+ Bitmap bitmap = CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR);
+ if (mOrientation != 0 || mMirror) {
+ Matrix m = new Matrix();
+ m.preRotate(mOrientation);
+ if (mMirror) {
+ // Flip horizontally
+ m.setScale(-1f, 1f);
+ }
+ return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m,
+ false);
+ }
+ return bitmap;
}
@Override
initIndicators();
mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
- mSwitcher = (CameraSwitcher) mRootView.findViewById(R.id.camera_switcher);
- mSwitcher.setCurrentIndex(CameraSwitcher.PHOTO_MODULE_INDEX);
+ mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
+ mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
mSwitcher.setSwitchListener(mActivity);
mMenuButton = mRootView.findViewById(R.id.menu);
if (ApiHelper.HAS_FACE_DETECTION) {
private void setTransformMatrix(int width, int height) {
mMatrix = mTextureView.getTransform(mMatrix);
- int orientation = CameraUtil.getDisplayRotation(mActivity);
float scaleX = 1f, scaleY = 1f;
float scaledTextureWidth, scaledTextureHeight;
if (width > height) {
return true;
}
+ @Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// Do nothing.
}
updateOnScreenIndicators(params, prefGroup, prefs);
}
- public void animateCapture(final byte[] jpegData) {
+ public void animateCapture(final byte[] jpegData, int orientation, boolean mirror) {
// Decode jpeg byte array and then animate the jpeg
- DecodeTask task = new DecodeTask(jpegData);
+ DecodeTask task = new DecodeTask(jpegData, orientation, mirror);
task.execute();
}
mPreviewThumb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- // TODO: go to filmstrip
- // mActivity.gotoGallery();
+ mActivity.gotoGallery();
}
});
mMenuButton = mRootView.findViewById(R.id.menu);
}
}
+ @Override
public void showGpsOnScreenIndicator(boolean hasSignal) { }
+ @Override
public void hideGpsOnScreenIndicator() { }
public void overrideSettings(final String ... keyvalues) {
}
}
- public void onSwitchMode(boolean toCamera) {
- if (toCamera) {
+ public void onPreviewFocusChanged(boolean previewFocused) {
+ if (previewFocused) {
showUI();
} else {
hideUI();
}
if (mFaceView != null) {
- mFaceView.setBlockDraw(!toCamera);
+ mFaceView.setBlockDraw(!previewFocused);
}
if (mGestures != null) {
- mGestures.setEnabled(toCamera);
+ mGestures.setEnabled(previewFocused);
}
if (mRenderOverlay != null) {
// this can not happen in capture mode
- mRenderOverlay.setVisibility(toCamera ? View.VISIBLE : View.GONE);
+ mRenderOverlay.setVisibility(previewFocused ? View.VISIBLE : View.GONE);
}
if (mPieRenderer != null) {
- mPieRenderer.setBlockFocus(!toCamera);
+ mPieRenderer.setBlockFocus(!previewFocused);
}
- setShowMenu(toCamera);
- if (!toCamera && mCountDownView != null) mCountDownView.cancelCountDown();
+ setShowMenu(previewFocused);
+ if (!previewFocused && mCountDownView != null) mCountDownView.cancelCountDown();
}
public void showPopup(AbstractSettingPopup popup) {
return mShutterButton.isPressed();
}
+ /**
+ * Enables or disables the shutter button.
+ */
public void enableShutter(boolean enabled) {
if (mShutterButton != null) {
mShutterButton.setEnabled(enabled);
mFaceView.setFaces(faces);
}
+ @Override
public void onDisplayChanged() {
mCameraControls.checkLayoutFlip();
mController.updateCameraOrientation();