Skip to content
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 app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:id="@+id/jcameraview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:isExpandCapture="true"
app:duration_max="10000"
app:iconMargin="20dp"
app:iconSize="30dp"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ public void setSwitchView(ImageView mSwitchView) {
//视频质量
private int mediaQuality = JCameraView.MEDIA_QUALITY_MIDDLE;

private int mTxtTopMargin=0;//0 default

private int mCaptureAppend=0;//0 default

public void setTextTopMargin(int topMargin){
mTxtTopMargin=topMargin;
}
public void setCaptureAppend(int append){
mCaptureAppend=append;
}


public int getTxtTopMargin() {
return mTxtTopMargin;
}

public int getCaptureAppend() {
return mCaptureAppend;
}

private SensorManager sm = null;
private SensorEventListener sensorEventListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ public CaptureLayout(Context context, AttributeSet attrs, int defStyleAttr) {
layout_width = outMetrics.widthPixels / 2;
}
button_size = (int) (layout_width / 4.5f);
layout_height = button_size + (button_size / 5) * 2 + 100;
layout_height = button_size + (button_size / 5) * 2 + CameraInterface.getInstance().getCaptureAppend();

initView();
initEvent();
}

public int getCaptureHeight(){
return layout_height;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Expand Down Expand Up @@ -271,7 +275,7 @@ public void onClick(View v) {
txt_tip = new TextView(getContext());
LayoutParams txt_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
txt_param.gravity = Gravity.CENTER_HORIZONTAL;
txt_param.setMargins(0, 0, 0, 0);
txt_param.setMargins(0, CameraInterface.getInstance().getTxtTopMargin(), 0, 0);
txt_tip.setText("轻触拍照,长按摄像");
txt_tip.setTextColor(0xFFFFFFFF);
txt_tip.setGravity(Gravity.CENTER);
Expand Down
50 changes: 34 additions & 16 deletions camera/src/main/java/com/cjt2325/cameralibrary/JCameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class JCameraView extends FrameLayout implements CameraInterface.CamOpenO
private int iconMargin = 0;
private int iconSrc = 0;
private int duration = 0;
private boolean isExpandCapture;

/**
* constructor
Expand Down Expand Up @@ -129,6 +130,16 @@ public JCameraView(Context context, AttributeSet attrs, int defStyleAttr) {
TypedValue.COMPLEX_UNIT_SP, 15, getResources().getDisplayMetrics()));
iconSrc = a.getResourceId(R.styleable.JCameraView_iconSrc, R.drawable.ic_sync_black_24dp);
duration = a.getInteger(R.styleable.JCameraView_duration_max, 10 * 1000);
isExpandCapture =a.getBoolean(R.styleable.JCameraView_isExpandCapture, false);

int captureAppend = a.getDimensionPixelSize(R.styleable.JCameraView_captureAppend, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 80, getResources().getDisplayMetrics()));
int tipTopMargin = a.getDimensionPixelSize(R.styleable.JCameraView_tipTopMargin, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 8, getResources().getDisplayMetrics()));

CameraInterface.getInstance().setCaptureAppend(captureAppend);
CameraInterface.getInstance().setTextTopMargin(tipTopMargin);

a.recycle();
initData();
initView();
Expand All @@ -147,20 +158,7 @@ private void initData() {
private void initView() {
setWillNotDraw(false);
this.setBackgroundColor(0xff000000);
//VideoView
mVideoView = new VideoView(mContext);
LayoutParams videoViewParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// videoViewParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
mVideoView.setLayoutParams(videoViewParam);

//mPhoto
mPhoto = new ImageView(mContext);
LayoutParams photoParam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams
.MATCH_PARENT);
// photoParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
mPhoto.setLayoutParams(photoParam);
mPhoto.setBackgroundColor(0xff000000);
mPhoto.setVisibility(INVISIBLE);
//switchCamera
mSwitchCamera = new ImageView(mContext);
LayoutParams imageViewParam = new LayoutParams(iconSize + 2 * iconMargin, iconSize + 2 * iconMargin);
Expand Down Expand Up @@ -198,6 +196,25 @@ public void run() {
mCaptureLayout.setLayoutParams(layout_param);
mCaptureLayout.setDuration(duration);

//限制录制的高度
//VideoView
mVideoView = new VideoView(mContext);
LayoutParams videoViewParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// videoViewParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
if(isExpandCapture)videoViewParam.setMargins(0, 0, 0, mCaptureLayout.getCaptureHeight());
mVideoView.setLayoutParams(videoViewParam);

//mPhoto
mPhoto = new ImageView(mContext);
LayoutParams photoParam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams
.MATCH_PARENT);
if(isExpandCapture)photoParam.setMargins(0, 0, 0, mCaptureLayout.getCaptureHeight());

// photoParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
mPhoto.setLayoutParams(photoParam);
mPhoto.setBackgroundColor(0xff000000);
mPhoto.setVisibility(INVISIBLE);

//mFoucsView
mFoucsView = new FoucsView(mContext, fouce_size);
LayoutParams foucs_param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Expand Down Expand Up @@ -396,6 +413,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
float widthSize = MeasureSpec.getSize(widthMeasureSpec);
float heightSize = MeasureSpec.getSize(heightMeasureSpec);
if(isExpandCapture)heightSize-=mCaptureLayout.getCaptureHeight();
screenProp = heightSize / widthSize;
}

Expand Down Expand Up @@ -564,10 +582,10 @@ private void handlerPictureOrVideo(int type, boolean confirm) {
}
}
mCaptureLayout.isRecord(false);
LayoutParams videoViewParam = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
// LayoutParams videoViewParam = new LayoutParams(LayoutParams.MATCH_PARENT,
// LayoutParams.MATCH_PARENT);
// videoViewParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
mVideoView.setLayoutParams(videoViewParam);
// mVideoView.setLayoutParams(videoViewParam);
CameraInterface.getInstance().doOpenCamera(JCameraView.this);
break;
}
Expand Down
6 changes: 6 additions & 0 deletions camera/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
<attr name="iconMargin" format="dimension"/>
<attr name="iconSrc" format="reference"/>
<attr name="duration_max" format="integer"/>
<attr name="captureAppend" format="dimension"/>
<attr name="isExpandCapture" format="boolean"/>
<attr name="tipTopMargin" format="dimension"/>
<declare-styleable name="JCameraView">
<attr name="iconSize"/>
<attr name="iconMargin"/>
<attr name="iconSrc"/>
<attr name="duration_max"/>
<attr name="captureAppend"/>
<attr name="isExpandCapture"/>
<attr name="tipTopMargin"/>
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions cameraapplication/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
app:duration_max="10000"
app:iconMargin="20dp"
app:iconSize="30dp"
app:isExpandCapture="true"
app:iconSrc="@drawable/ic_camera_enhance_black_24dp"/>
</LinearLayout>
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#Wed Mar 01 20:51:02 CST 2017
#Wed Jun 14 11:08:51 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=file:///D:/gradle_offline/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip