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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/


Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.Surface;
Expand All @@ -44,7 +45,7 @@
import java.util.Date;
import java.util.List;

public class MainActivity extends Activity {
public class MainActivity extends AppCompatActivity {
private static final SparseIntArray ORIENTATION = new SparseIntArray();

static {
Expand Down Expand Up @@ -75,17 +76,18 @@ protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_main);
mTextureView = (TextureView) findViewById(R.id.textureView);
this.mTextureView = (TextureView) findViewById(R.id.textureView);
}

@Override
protected void onResume() {
super.onResume();
startCameraThread();
if (!mTextureView.isAvailable()) {
mTextureView.setSurfaceTextureListener(mTextureListener);
this.startCameraThread();
if (!this.mTextureView.isAvailable()) {
// 设置监听SurefaceTexture的事件
this.mTextureView.setSurfaceTextureListener(this.mTextureListener);
} else {
startPreview();
this.startPreview();
}
}

Expand Down Expand Up @@ -182,9 +184,12 @@ private void openCamera() {
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
// return;
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 1);
} else {
manager.openCamera(mCameraId, mStateCallback, mCameraHandler);
}
manager.openCamera(mCameraId, mStateCallback, mCameraHandler);
// manager.openCamera(mCameraId, mStateCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -361,4 +366,22 @@ public void run() {
}
}
}



// 向用户申请授权, 授权的结果封装在grantResults中。
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case 1:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
this.openCamera();
} else {
Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
}
4 changes: 3 additions & 1 deletion Camera/CameraV2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.4.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions Camera/CameraV2/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Mon May 13 18:03:22 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip