diff options
author | Byunghun Jeon <bjeon@codeaurora.org> | 2016-09-16 12:59:14 -0700 |
---|---|---|
committer | Byunghun Jeon <bjeon@codeaurora.org> | 2016-11-14 11:01:16 -0800 |
commit | 70790e941a1c23dc62b2bf06236cb4d8dde2bec9 (patch) | |
tree | a13050484ff747e0e4587ae0d30153ebaf906591 /src/com/android/camera/ui | |
parent | ea7548840f9152b636e75f36b3ef9cd66f363108 (diff) | |
download | android_packages_apps_Snap-70790e941a1c23dc62b2bf06236cb4d8dde2bec9.tar.gz android_packages_apps_Snap-70790e941a1c23dc62b2bf06236cb4d8dde2bec9.tar.bz2 android_packages_apps_Snap-70790e941a1c23dc62b2bf06236cb4d8dde2bec9.zip |
SnapdragonCamera: Add ProMode
Add ProMode. User can change iso, white balance, exposure,
and focus mode using this new scene mode
Change-Id: I58885d3a05d6d9e8264e58cb8c4de2e1f13646b0
CRs-Fixed: 1089100
Diffstat (limited to 'src/com/android/camera/ui')
-rw-r--r-- | src/com/android/camera/ui/OneUICameraControls.java | 160 | ||||
-rw-r--r-- | src/com/android/camera/ui/ProMode.java | 372 |
2 files changed, 529 insertions, 3 deletions
diff --git a/src/com/android/camera/ui/OneUICameraControls.java b/src/com/android/camera/ui/OneUICameraControls.java index 63e1b5b4d..413221211 100644 --- a/src/com/android/camera/ui/OneUICameraControls.java +++ b/src/com/android/camera/ui/OneUICameraControls.java @@ -27,15 +27,16 @@ import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; -import org.codeaurora.snapcam.R; - import com.android.camera.Storage; import com.android.camera.imageprocessor.filter.BeautificationFilter; +import org.codeaurora.snapcam.R; + public class OneUICameraControls extends RotatableLayout { private static final String TAG = "CAM_Controls"; @@ -53,6 +54,8 @@ public class OneUICameraControls extends RotatableLayout { private View mMakeupSeekBarLowText; private View mMakeupSeekBarHighText; private View mMakeupSeekBarLayout; + private ViewGroup mProModeLayout; + private View mProModeCloseButton; private ArrowTextView mRefocusToast; @@ -76,9 +79,27 @@ public class OneUICameraControls extends RotatableLayout { private int mHeight; private boolean mVisible; + private ProMode mProMode; + private ImageView mExposureIcon; + private ImageView mManualIcon; + private ImageView mWhiteBalanceIcon; + private ImageView mIsoIcon; + private TextView mExposureText; + private TextView mManualText; + private TextView mWhiteBalanceText; + private TextView mIsoText; + private boolean mProModeOn = false; + private LinearLayout mExposureLayout; + private LinearLayout mManualLayout; + private LinearLayout mWhiteBalanceLayout; + private LinearLayout mIsoLayout; + private RotateLayout mExposureRotateLayout; + private RotateLayout mManualRotateLayout; + private RotateLayout mWhiteBalanceRotateLayout; + private RotateLayout mIsoRotateLayout; + public OneUICameraControls(Context context, AttributeSet attrs) { super(context, attrs); - mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); setWillNotDraw(false); @@ -117,6 +138,83 @@ public class OneUICameraControls extends RotatableLayout { mFilterModeSwitcher = findViewById(R.id.filter_mode_switcher); mRemainingPhotos = (LinearLayout) findViewById(R.id.remaining_photos); mRemainingPhotosText = (TextView) findViewById(R.id.remaining_photos_text); + mProModeLayout = (ViewGroup) findViewById(R.id.pro_mode_layout); + mProModeCloseButton = findViewById(R.id.promode_close_button); + + mExposureIcon = (ImageView) findViewById(R.id.exposure); + mManualIcon = (ImageView) findViewById(R.id.manual); + mWhiteBalanceIcon = (ImageView) findViewById(R.id.white_balance); + mIsoIcon = (ImageView) findViewById(R.id.iso); + mExposureText = (TextView) findViewById(R.id.exposure_value); + mManualText = (TextView) findViewById(R.id.manual_value); + mWhiteBalanceText = (TextView) findViewById(R.id.white_balance_value); + mIsoText = (TextView) findViewById(R.id.iso_value); + mProMode = (ProMode) findViewById(R.id.promode_slider); + mProMode.initialize(this); + + mExposureLayout = (LinearLayout) findViewById(R.id.exposure_layout); + mManualLayout = (LinearLayout) findViewById(R.id.manual_layout); + mWhiteBalanceLayout = (LinearLayout) findViewById(R.id.white_balance_layout); + mIsoLayout = (LinearLayout) findViewById(R.id.iso_layout); + + mExposureRotateLayout = (RotateLayout) findViewById(R.id.exposure_rotate_layout); + mManualRotateLayout = (RotateLayout) findViewById(R.id.manual_rotate_layout); + mWhiteBalanceRotateLayout = (RotateLayout) findViewById(R.id.white_balance_rotate_layout); + mIsoRotateLayout = (RotateLayout) findViewById(R.id.iso_rotate_layout); + + mExposureLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.EXPOSURE_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mExposureIcon.setImageResource(R.drawable.icon_exposure_blue); + mProMode.setMode(ProMode.EXPOSURE_MODE); + } + } + }); + mManualLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.MANUAL_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mManualIcon.setImageResource(R.drawable.icon_manual_blue); + mProMode.setMode(ProMode.MANUAL_MODE); + } + } + }); + mWhiteBalanceLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.WHITE_BALANCE_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mWhiteBalanceIcon.setImageResource(R.drawable.icon_white_balance_blue); + mProMode.setMode(ProMode.WHITE_BALANCE_MODE); + } + } + }); + mIsoLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.ISO_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mIsoIcon.setImageResource(R.drawable.icon_iso_blue); + mProMode.setMode(ProMode.ISO_MODE); + } + } + }); + mViews = new View[]{ mSceneModeSwitcher, mFilterModeSwitcher, mFrontBackSwitcher, mTsMakeupSwitcher, mFlashButton, mShutter, mPreview, mVideoShutter @@ -142,6 +240,14 @@ public class OneUICameraControls extends RotatableLayout { if(mMakeupSeekBar != null) { mMakeupSeekBar.setMinimumWidth(mWidth/2); } + + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mWidth/ 4,mWidth/4); + mExposureLayout.setLayoutParams(lp); + + mManualLayout.setLayoutParams(lp); + mWhiteBalanceLayout.setLayoutParams(lp); + mIsoLayout.setLayoutParams(lp); + initializeProMode(mProModeOn); } public boolean isControlRegion(int x, int y) { @@ -212,6 +318,7 @@ public class OneUICameraControls extends RotatableLayout { setLocation(mShutter, false, 2); setLocation(mVideoShutter, false, 3.15f); setLocationCustomBottom(mMakeupSeekBarLayout, 0, 1); + setLocation(mProModeCloseButton, false, 4); layoutToast(mRefocusToast, w, h, rotation); } @@ -332,6 +439,11 @@ public class OneUICameraControls extends RotatableLayout { ((Rotatable) v).setOrientation(orientation, animation); } } + mExposureRotateLayout.setOrientation(orientation, animation); + mManualRotateLayout.setOrientation(orientation, animation); + mWhiteBalanceRotateLayout.setOrientation(orientation, animation); + mIsoRotateLayout.setOrientation(orientation, animation); + mProMode.setOrientation(orientation); layoutRemaingPhotos(); } @@ -377,4 +489,46 @@ public class OneUICameraControls extends RotatableLayout { mPath.lineTo(x1, y1); } } + + public void setProMode(boolean promode) { + mProModeOn = promode; + initializeProMode(mProModeOn); + resetProModeIcons(); + } + + private void resetProModeIcons() { + mExposureIcon.setImageResource(R.drawable.icon_exposure); + mManualIcon.setImageResource(R.drawable.icon_manual); + mWhiteBalanceIcon.setImageResource(R.drawable.icon_white_balance); + mIsoIcon.setImageResource(R.drawable.icon_iso); + } + + public void initializeProMode(boolean promode) { + if (!promode) { + mProMode.setMode(ProMode.NO_MODE); + mProModeLayout.setVisibility(INVISIBLE); + mProModeCloseButton.setVisibility(INVISIBLE); + return; + } + mProModeLayout.setVisibility(VISIBLE); + mProModeCloseButton.setVisibility(VISIBLE); + mProModeLayout.setY(mHeight - mBottom - mProModeLayout.getHeight()); + } + + public void updateProModeText(int mode, String value) { + switch (mode) { + case ProMode.EXPOSURE_MODE: + mExposureText.setText(value); + break; + case ProMode.MANUAL_MODE: + mManualText.setText(value); + break; + case ProMode.WHITE_BALANCE_MODE: + mWhiteBalanceText.setText(value); + break; + case ProMode.ISO_MODE: + mIsoText.setText(value); + break; + } + } } diff --git a/src/com/android/camera/ui/ProMode.java b/src/com/android/camera/ui/ProMode.java new file mode 100644 index 000000000..9f7d576dc --- /dev/null +++ b/src/com/android/camera/ui/ProMode.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.camera.ui; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PathMeasure; +import android.graphics.Point; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.android.camera.SettingsManager; + +import org.codeaurora.snapcam.R; + +import java.util.ArrayList; + +public class ProMode extends View { + public static final int NO_MODE = -1; + public static final int EXPOSURE_MODE = 0; + public static final int MANUAL_MODE = 1; + public static final int WHITE_BALANCE_MODE = 2; + public static final int ISO_MODE = 3; + private static final int DRAG_Y_THRESHOLD = 100; + private static final int DRAG_X_THRESHOLD = 30; + private static final int BLUE = 0xff4693fb; + private static final int SELECTED_DOT_SIZE = 20; + private static final int DOT_SIZE = 10; + private static final int[] wbIcons = {R.drawable.auto, R.drawable.incandecent, + R.drawable.fluorescent, R.drawable.sunlight, R.drawable.cloudy}; + private static final int[] wbIconsBlue = {R.drawable.auto_blue, R.drawable.incandecent_blue, + R.drawable.fluorescent_blue, R.drawable.sunlight_blue, R.drawable.cloudy_blue}; + private static final int WB_ICON_SIZE = 80; + private PathMeasure mCurveMeasure; + private int mCurveLeft; + private int mCurveRight; + private float mSlider = -1; + private Paint mPaint = new Paint(); + private int mNums; + private int mIndex; + private Point[] mPoints; + private float mClickThreshold; + private int mStride; + private SettingsManager mSettingsManager; + private int mMode = NO_MODE; + private Context mContext; + private ViewGroup mParent; + private float minFocus; + private OneUICameraControls mUI; + private int mWidth; + private int mHeight; + private int mCurveY; + private ArrayList<View> mAddedViews; + private float curveCoordinate[] = new float[2]; + private Path mCurvePath = new Path(); + private int mCurveHeight; + private int mOrientation; + + public ProMode(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + mPaint.setStrokeWidth(7f); + mSettingsManager = SettingsManager.getInstance(); + } + + private void init() { + init(EXPOSURE_MODE); + init(WHITE_BALANCE_MODE); + init(ISO_MODE); + mUI.updateProModeText(MANUAL_MODE, "Manual"); + } + + private void init(int mode) { + String key = getKey(mode); + if (key == null) return; + int index = mSettingsManager.getValueIndex(key); + CharSequence[] cc = mSettingsManager.getEntries(key); + mUI.updateProModeText(mode, cc[index].toString()); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if (mMode != NO_MODE) { + mPaint.setColor(Color.WHITE); + mPaint.setStyle(Paint.Style.STROKE); + canvas.drawPath(mCurvePath, mPaint); + } + mPaint.setStyle(Paint.Style.FILL); + if (mMode == MANUAL_MODE) { + mPaint.setColor(Color.WHITE); + canvas.drawCircle(mCurveLeft, mCurveY, DOT_SIZE, mPaint); + canvas.drawCircle(mCurveRight, mCurveY, DOT_SIZE, mPaint); + mPaint.setColor(BLUE); + if (mSlider >= 0f) { + mCurveMeasure.getPosTan(mCurveMeasure.getLength() * mSlider, curveCoordinate, null); + canvas.drawCircle(curveCoordinate[0], curveCoordinate[1], SELECTED_DOT_SIZE, + mPaint); + } + } else { + for (int i = 0; i < mNums; i++) { + if (i == mIndex) { + mPaint.setColor(BLUE); + canvas.drawCircle(mPoints[i].x, mPoints[i].y, SELECTED_DOT_SIZE, mPaint); + } else { + mPaint.setColor(Color.WHITE); + canvas.drawCircle(mPoints[i].x, mPoints[i].y, DOT_SIZE, mPaint); + } + } + } + } + + public void initialize(OneUICameraControls ui) { + mParent = (ViewGroup) getParent(); + mUI = ui; + init(); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + mWidth = right - left; + mHeight = bottom - top; + mCurveLeft = mWidth / 10; + mCurveRight = mWidth - mCurveLeft; + mCurveHeight = mWidth / 7; + mCurveY = (int) (mHeight * 0.67); + + float cx = (mCurveLeft + mCurveRight) / 2; + mCurvePath.moveTo(mCurveLeft, mCurveY); + mCurvePath.quadTo(cx, mCurveY - mCurveHeight, mCurveRight, mCurveY); + mCurveMeasure = new PathMeasure(mCurvePath, false); + } + + public void setOrientation(int orientation) { + mOrientation = orientation; + if (mAddedViews != null) { + int rotation = mOrientation; + if (rotation == 90 || rotation == 270) rotation += 180; + rotation %= 360; + for (View v : mAddedViews) { + v.setRotation(rotation); + } + } + } + + public int getMode() { + return mMode; + } + + public void setMode(int mode) { + mMode = mode; + removeViews(); + if (mMode == NO_MODE) { + setVisibility(INVISIBLE); + return; + } else { + setVisibility(VISIBLE); + } + mIndex = -1; + String key = currentKey(); + if (mMode == MANUAL_MODE) { + minFocus = mSettingsManager + .getMinimumFocusDistance(mSettingsManager.getCurrentCameraId()); + float value = 0.5f; + setSlider(value); + int stride = mCurveRight - mCurveLeft; + for (int i = 0; i < 2; i++) { + TextView v = new TextView(mContext); + String s = "infinity"; + if (i == 1) s = "macro"; + v.setText(s); + v.setTextColor(Color.WHITE); + v.measure(0, 0); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(v.getMeasuredWidth(), + v.getMeasuredHeight()); + v.setLayoutParams(lp); + v.setX(mCurveLeft + i * stride - v.getMeasuredWidth() / 2); + v.setY(mCurveY - 2 * v.getMeasuredHeight()); + mParent.addView(v); + mAddedViews.add(v); + } + } else { + if (key == null) return; + CharSequence[] cc = mSettingsManager.getEntries(key); + int length = mSettingsManager.getEntryValues(key).length; + int index = mSettingsManager.getValueIndex(key); + updateSlider(length); + + for (int i = 0; i < length; i++) { + View v; + if (mMode == WHITE_BALANCE_MODE) { + v = new ImageView(mContext); + ((ImageView) v).setImageResource(wbIcons[i]); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams( + WB_ICON_SIZE, WB_ICON_SIZE); + v.setLayoutParams(lp); + v.setX(mPoints[i].x - WB_ICON_SIZE / 2); + v.setY(mPoints[i].y - 2 * WB_ICON_SIZE); + } else { + v = new TextView(mContext); + ((TextView) v).setText(cc[i]); + ((TextView) v).setTextColor(Color.WHITE); + v.measure(0, 0); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(v.getMeasuredWidth(), + v.getMeasuredHeight()); + v.setLayoutParams(lp); + v.setX(mPoints[i].x - v.getMeasuredWidth() / 2); + v.setY(mPoints[i].y - 2 * v.getMeasuredHeight()); + } + + + mParent.addView(v); + mAddedViews.add(v); + } + setIndex(index, true); + } + setOrientation(mOrientation); + } + + private String getKey(int mode) { + switch (mode) { + case EXPOSURE_MODE: + return SettingsManager.KEY_EXPOSURE; + case WHITE_BALANCE_MODE: + return SettingsManager.KEY_WHITE_BALANCE; + case ISO_MODE: + return SettingsManager.KEY_ISO; + } + return null; + } + + private String currentKey() { + return getKey(mMode); + } + + private void updateSlider(int n) { + mNums = n; + mStride = (mCurveRight - mCurveLeft) / (mNums - 1); + mClickThreshold = mStride * 0.45f; + mPoints = new Point[mNums]; + + float slide = 1f / (mNums - 1); + for (int i = 0; i < mNums; i++) { + mCurveMeasure.getPosTan(mCurveMeasure.getLength() * (slide * i), curveCoordinate, null); + mPoints[i] = new Point((int) curveCoordinate[0], (int) curveCoordinate[1]); + } + + invalidate(); + } + + public void setSlider(float slider) { + mSlider = slider; + mSettingsManager.setFocusDistance(mSlider * minFocus); + mUI.updateProModeText(mMode, "Manual"); + invalidate(); + } + + private void setIndex(int index, boolean force) { + if (mIndex == index && !force) return; + if (mIndex != -1) { + View v = mAddedViews.get(mIndex); + if (v instanceof TextView) { + ((TextView) v).setTextColor(Color.WHITE); + } else if (v instanceof ImageView) { + if (mMode == WHITE_BALANCE_MODE) { + ((ImageView) v).setImageResource(wbIcons[mIndex]); + } + } + } + + mIndex = index; + String key = currentKey(); + View v = mAddedViews.get(mIndex); + if (v instanceof TextView) { + ((TextView) v).setTextColor(BLUE); + } else if (v instanceof ImageView) { + if (mMode == WHITE_BALANCE_MODE) { + ((ImageView) v).setImageResource(wbIconsBlue[mIndex]); + } + } + if (key != null) mSettingsManager.setValueIndex(key, mIndex); + CharSequence[] cc = mSettingsManager.getEntries(key); + mUI.updateProModeText(mMode, cc[mIndex].toString()); + invalidate(); + } + + private void removeViews() { + ViewGroup vg = (ViewGroup) getParent(); + if (mAddedViews != null) { + for (int i = 0; i < mAddedViews.size(); i++) { + vg.removeView(mAddedViews.get(i)); + } + } + mAddedViews = new ArrayList<View>(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (mMode == MANUAL_MODE) { + float slider = getSlider(event.getX(), event.getY()); + if (slider >= 0) { + setSlider(slider); + } + } else { + int idx = findButton(event.getX(), event.getY()); + if (idx != -1) { + setIndex(idx, false); + } + return true; + } + return true; + } + + private int findButton(float x, float y) { + for (int i = 0; i < mNums; i++) { + float xdiff = Math.abs(mPoints[i].x - x); + float ydiff = Math.abs(mPoints[i].y - y); + float dist = xdiff * xdiff + ydiff * ydiff; + if (dist < mClickThreshold * mClickThreshold) return i; + } + return -1; + } + + private float getSlider(float x, float y) { + if (x > mCurveLeft - DRAG_X_THRESHOLD && x < mCurveRight + DRAG_X_THRESHOLD + && y > mCurveY - mCurveHeight - DRAG_Y_THRESHOLD + && y < mCurveY + DRAG_Y_THRESHOLD) { + if (x < mCurveLeft) x = mCurveLeft; + if (x > mCurveRight) x = mCurveRight; + return (x - mCurveLeft) / (mCurveRight - mCurveLeft); + } else { + return -1; + } + } + +} |