Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

更新支持gradle版本 #229

Open
wants to merge 2 commits into
base: master
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
3 changes: 0 additions & 3 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,17 +19,21 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
buildToolsVersion = '25.0.2'
compileSdkVersion = 25
minSdkVersion = 9
targetSdkVersion = 25
supportLibraryVersion = '25.3.1'
}
//
//ext {
// buildToolsVersion = '25.0.2'
// compileSdkVersion = 25
// minSdkVersion = 14
// targetSdkVersion = 25
// supportLibraryVersion = '25.3.1'
//}
26 changes: 5 additions & 21 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion

buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion 23

defaultConfig {
applicationId 'com.google.android.cameraview.demo'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId 'cameraview.demo'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
Expand All @@ -38,7 +22,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:design:23.4.0"
compile project(':library')

// Tests
Expand Down
15 changes: 1 addition & 14 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest package="com.google.android.cameraview.demo"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
* $ adb pull /sdcard/Android/data/com.google.android.cameraview.demo/files/Pictures/picture.jpg
*/
public class MainActivity extends AppCompatActivity implements
ActivityCompat.OnRequestPermissionsResultCallback,
AspectRatioFragment.Listener {

private static final String TAG = "MainActivity";
Expand Down Expand Up @@ -106,6 +105,7 @@ public void onClick(View v) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("ly", "onCreate");
setContentView(R.layout.activity_main);
mCameraView = (CameraView) findViewById(R.id.camera);
if (mCameraView != null) {
Expand All @@ -126,6 +126,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
Log.e("ly", "onResume");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
mCameraView.start();
Expand All @@ -147,11 +148,13 @@ protected void onResume() {
protected void onPause() {
mCameraView.stop();
super.onPause();
Log.e("ly", "onPause");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.e("ly", "onDestroy");
if (mBackgroundHandler != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mBackgroundHandler.getLooper().quitSafely();
Expand Down Expand Up @@ -206,7 +209,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
mCameraView.setFlash(FLASH_OPTIONS[mCurrentFlash]);
}
return true;
case R.id.switch_camera:
case R.id.switch_camera://切换前后摄像头
if (mCameraView != null) {
int facing = mCameraView.getFacing();
mCameraView.setFacing(facing == CameraView.FACING_FRONT ?
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<com.google.android.cameraview.CameraView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 06 09:02:59 JST 2016
#Thu Jan 18 12:59:06 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
25 changes: 5 additions & 20 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion 23

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
minSdkVersion 14
targetSdkVersion 23
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand All @@ -39,8 +24,8 @@ android {
}

dependencies {
compile "com.android.support:support-annotations:$supportLibraryVersion"
compile "com.android.support:support-v4:$supportLibraryVersion"
compile "com.android.support:support-annotations:27.0.2"
compile "com.android.support:support-v4:23.4.0"

// Tests
testCompile 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ private void openCamera() {
if (mCamera != null) {
releaseCamera();
}
mCamera = Camera.open(mCameraId);
try {
mCamera = Camera.open(mCameraId);
} catch (Exception e) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
mCamera = Camera.open(mCameraId);
}
mCameraParameters = mCamera.getParameters();
// Supported preview sizes
mPreviewSizes.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.android.cameraview;

import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.os.Build;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Expand All @@ -42,8 +42,10 @@ public void surfaceCreated(SurfaceHolder h) {
@Override
public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
setSize(width, height);
if (!ViewCompat.isInLayout(mSurfaceView)) {
dispatchSurfaceChanged();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (!mSurfaceView.isInLayout()) {
dispatchSurfaceChanged();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.support.annotation.Nullable;
import android.support.v4.os.ParcelableCompat;
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.widget.FrameLayout;

Expand Down Expand Up @@ -142,7 +141,7 @@ private PreviewImpl createPreviewImpl(Context context) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!isInEditMode()) {
mDisplayOrientationDetector.enable(ViewCompat.getDisplay(this));
mDisplayOrientationDetector.enable(this.getDisplay());
}
}

Expand Down