Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "start with front camera" support #317

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions album/src/main/java/com/yanzhenjie/album/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public final class Album {
public static final String KEY_INPUT_CAMERA_QUALITY = "KEY_INPUT_CAMERA_QUALITY";
public static final String KEY_INPUT_CAMERA_DURATION = "KEY_INPUT_CAMERA_DURATION";
public static final String KEY_INPUT_CAMERA_BYTES = "KEY_INPUT_CAMERA_BYTES";
public static final String KEY_START_WITH_FRONT_CAMERA = "KEY_START_WITH_FRONT_CAMERA";

// Filter.
public static final String KEY_INPUT_FILTER_VISIBILITY = "KEY_INPUT_FILTER_VISIBILITY";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(Album.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(Album.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(Album.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(Album.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public abstract class BasicCameraWrapper<Returner extends BasicCameraWrapper> {
Action<String> mResult;
Action<String> mCancel;
String mFilePath;
boolean mStartWithFrontCamera = false;

public BasicCameraWrapper(Context context) {
this.mContext = context;
Expand Down Expand Up @@ -64,6 +65,14 @@ public Returner filePath(@Nullable String filePath) {
return (Returner) this;
}

/**
* Switch the default camera to the front.
*/
public Returner startWithFrontCamera(boolean v) {
this.mStartWithFrontCamera = v;
return (Returner) this;
}

/**
* Start up.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class BasicChoiceAlbumWrapper<Returner extends BasicChoiceAlbumW
int mQuality = 1;
long mLimitDuration = Integer.MAX_VALUE;
long mLimitBytes = Integer.MAX_VALUE;
boolean mStartWithFront = false;

/**
* Set the quality when taking video, should be 0 or 1. Currently value 0 means low quality, and value 1 means high quality.
Expand Down Expand Up @@ -60,4 +61,16 @@ public Returner cameraVideoLimitBytes(@IntRange(from = 1) long bytes) {
this.mLimitBytes = bytes;
return (Returner) this;
}


/**
* Start camera with front camera
*
* @param v
* @return
*/
public Returner cameraStartWithFront(boolean v) {
this.mStartWithFront = v;
return (Returner) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class BasicChoiceWrapper<Returner extends BasicChoiceWrapper, Re
Filter<String> mMimeTypeFilter;

boolean mFilterVisibility = true;
boolean mCameraStartWithFront = false;

BasicChoiceWrapper(Context context) {
super(context);
Expand Down Expand Up @@ -85,4 +86,14 @@ public Returner afterFilterVisibility(boolean visibility) {
return (Returner) this;
}

/**
* Start camera with front camera
*
* @param v
* @return
*/
public Returner cameraStartWithFront(boolean v) {
this.mCameraStartWithFront = v;
return (Returner) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.content.Context;
import android.support.annotation.IntRange;

import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.ItemAction;

import java.util.ArrayList;
Expand All @@ -32,6 +31,7 @@ public abstract class BasicGalleryWrapper<Returner extends BasicGalleryWrapper,
ItemAction<Checked> mItemLongClick;
int mCurrentPosition;
boolean mCheckable;
boolean mStartWithFrontCamera;

public BasicGalleryWrapper(Context context) {
super(context);
Expand Down Expand Up @@ -86,4 +86,14 @@ public Returner checkable(boolean checkable) {
this.mCheckable = checkable;
return (Returner) this;
}

/**
*
* @param frontCamera
* @return
*/
public Returner startWithFrontCamera(boolean frontCamera) {
this.mStartWithFrontCamera = frontCamera;
return (Returner) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumFile;
import com.yanzhenjie.album.app.gallery.GalleryActivity;
import com.yanzhenjie.album.app.gallery.GalleryAlbumActivity;

/**
Expand All @@ -44,6 +43,7 @@ public void start() {
intent.putParcelableArrayListExtra(Album.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(Album.KEY_INPUT_CURRENT_POSITION, mCurrentPosition);
intent.putExtra(Album.KEY_INPUT_GALLERY_CHECKABLE, mCheckable);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFrontCamera);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.app.gallery.GalleryActivity;
import com.yanzhenjie.album.app.gallery.GalleryAlbumActivity;

/**
* <p>Gallery wrapper.</p>
Expand All @@ -43,6 +42,7 @@ public void start() {
intent.putStringArrayListExtra(Album.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(Album.KEY_INPUT_CURRENT_POSITION, mCurrentPosition);
intent.putExtra(Album.KEY_INPUT_GALLERY_CHECKABLE, mCheckable);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFrontCamera);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void start() {

intent.putExtra(Album.KEY_INPUT_FUNCTION, Album.FUNCTION_CAMERA_IMAGE);
intent.putExtra(Album.KEY_INPUT_FILE_PATH, mFilePath);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFrontCamera);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(Album.KEY_INPUT_LIMIT_COUNT, mLimitCount);
intent.putExtra(Album.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mCameraStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(Album.KEY_INPUT_LIMIT_COUNT, 1);
intent.putExtra(Album.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mCameraStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(Album.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(Album.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mStartWithFrontCamera);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(Album.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(Album.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mCameraStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void start() {
intent.putExtra(Album.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(Album.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(Album.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
intent.putExtra(Album.KEY_START_WITH_FRONT_CAMERA, mCameraStartWithFront);
mContext.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class AlbumActivity extends BaseActivity implements
private int mQuality;
private long mLimitDuration;
private long mLimitBytes;
private boolean mStartWithFront;

private boolean mFilterVisibility;

Expand Down Expand Up @@ -123,6 +124,7 @@ private void initializeArgument() {
mQuality = argument.getInt(Album.KEY_INPUT_CAMERA_QUALITY);
mLimitDuration = argument.getLong(Album.KEY_INPUT_CAMERA_DURATION);
mLimitBytes = argument.getLong(Album.KEY_INPUT_CAMERA_BYTES);
mStartWithFront = argument.getBoolean(Album.KEY_START_WITH_FRONT_CAMERA);
mFilterVisibility = argument.getBoolean(Album.KEY_INPUT_FILTER_VISIBILITY);
}

Expand Down Expand Up @@ -317,6 +319,7 @@ private void takePicture() {
}
Album.camera(this)
.image()
.startWithFrontCamera(mStartWithFront)
.filePath(filePath)
.onResult(mCameraAction)
.start();
Expand All @@ -332,6 +335,7 @@ private void takeVideo() {
}
Album.camera(this)
.video()
.startWithFrontCamera(mStartWithFront)
.filePath(filePath)
.quality(mQuality)
.limitDuration(mLimitDuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,25 @@
public class NullActivity extends BaseActivity implements Contract.NullPresenter {

private static final String KEY_OUTPUT_IMAGE_PATH = "KEY_OUTPUT_IMAGE_PATH";

public static String parsePath(Intent intent) {
return intent.getStringExtra(KEY_OUTPUT_IMAGE_PATH);
}

private Widget mWidget;
private int mQuality = 1;
private long mLimitDuration;
private long mLimitBytes;

private boolean mCameraStartWithFront = false;
private Contract.NullView mView;
private Action<String> mCameraAction = new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Intent intent = new Intent();
intent.putExtra(KEY_OUTPUT_IMAGE_PATH, result);
setResult(RESULT_OK, intent);
finish();
}
};

public static String parsePath(Intent intent) {
return intent.getStringExtra(KEY_OUTPUT_IMAGE_PATH);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -59,6 +67,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mQuality = argument.getInt(Album.KEY_INPUT_CAMERA_QUALITY);
mLimitDuration = argument.getLong(Album.KEY_INPUT_CAMERA_DURATION);
mLimitBytes = argument.getLong(Album.KEY_INPUT_CAMERA_BYTES);
mCameraStartWithFront = argument.getBoolean(Album.KEY_START_WITH_FRONT_CAMERA);

mWidget = argument.getParcelable(Album.KEY_INPUT_WIDGET);
mView.setupViews(mWidget);
Expand Down Expand Up @@ -94,6 +103,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
public void takePicture() {
Album.camera(this)
.image()
.startWithFrontCamera(mCameraStartWithFront)
.onResult(mCameraAction)
.start();
}
Expand All @@ -102,20 +112,11 @@ public void takePicture() {
public void takeVideo() {
Album.camera(this)
.video()
.startWithFrontCamera(mCameraStartWithFront)
.quality(mQuality)
.limitDuration(mLimitDuration)
.limitBytes(mLimitBytes)
.onResult(mCameraAction)
.start();
}

private Action<String> mCameraAction = new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Intent intent = new Intent();
intent.putExtra(KEY_OUTPUT_IMAGE_PATH, result);
setResult(RESULT_OK, intent);
finish();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class CameraActivity extends BaseActivity {
private static final String INSTANCE_CAMERA_QUALITY = "INSTANCE_CAMERA_QUALITY";
private static final String INSTANCE_CAMERA_DURATION = "INSTANCE_CAMERA_DURATION";
private static final String INSTANCE_CAMERA_BYTES = "INSTANCE_CAMERA_BYTES";
private static final String INSTANCE_START_WITH_FRONT_CAMERA = "INSTANCE_USE_FRONT_CAMERA";

private static final int CODE_PERMISSION_IMAGE = 1;
private static final int CODE_PERMISSION_VIDEO = 2;
Expand All @@ -57,6 +58,7 @@ public class CameraActivity extends BaseActivity {
private int mQuality;
private long mLimitDuration;
private long mLimitBytes;
private boolean mStartWithFrontCamera;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -71,6 +73,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mQuality = savedInstanceState.getInt(INSTANCE_CAMERA_QUALITY);
mLimitDuration = savedInstanceState.getLong(INSTANCE_CAMERA_DURATION);
mLimitBytes = savedInstanceState.getLong(INSTANCE_CAMERA_BYTES);
mStartWithFrontCamera = savedInstanceState.getBoolean(INSTANCE_START_WITH_FRONT_CAMERA);
} else {
Bundle bundle = getIntent().getExtras();
assert bundle != null;
Expand All @@ -79,6 +82,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mQuality = bundle.getInt(Album.KEY_INPUT_CAMERA_QUALITY);
mLimitDuration = bundle.getLong(Album.KEY_INPUT_CAMERA_DURATION);
mLimitBytes = bundle.getLong(Album.KEY_INPUT_CAMERA_BYTES);
mStartWithFrontCamera = bundle.getBoolean(Album.KEY_START_WITH_FRONT_CAMERA);

switch (mFunction) {
case Album.FUNCTION_CAMERA_IMAGE: {
Expand Down Expand Up @@ -107,18 +111,19 @@ public void onSaveInstanceState(Bundle outState) {
outState.putInt(INSTANCE_CAMERA_QUALITY, mQuality);
outState.putLong(INSTANCE_CAMERA_DURATION, mLimitDuration);
outState.putLong(INSTANCE_CAMERA_BYTES, mLimitBytes);
outState.putBoolean(INSTANCE_START_WITH_FRONT_CAMERA, mStartWithFrontCamera);
super.onSaveInstanceState(outState);
}

@Override
protected void onPermissionGranted(int code) {
switch (code) {
case CODE_PERMISSION_IMAGE: {
AlbumUtils.takeImage(this, CODE_ACTIVITY_TAKE_IMAGE, new File(mCameraFilePath));
AlbumUtils.takeImage(this, CODE_ACTIVITY_TAKE_IMAGE, new File(mCameraFilePath), mStartWithFrontCamera);
break;
}
case CODE_PERMISSION_VIDEO: {
AlbumUtils.takeVideo(this, CODE_ACTIVITY_TAKE_VIDEO, new File(mCameraFilePath), mQuality, mLimitDuration, mLimitBytes);
AlbumUtils.takeVideo(this, CODE_ACTIVITY_TAKE_VIDEO, new File(mCameraFilePath), mQuality, mLimitDuration, mLimitBytes, mStartWithFrontCamera);
break;
}
default: {
Expand Down
Loading