forked from googlearchive/android-Camera2Basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b304ea9
Showing
36 changed files
with
1,556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
|
||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:0.11.+' | ||
} | ||
} | ||
|
||
apply plugin: 'android' | ||
|
||
|
||
dependencies { | ||
|
||
compile "com.android.support:support-v4:+" | ||
compile "com.android.support:support-v13:+" | ||
|
||
} | ||
|
||
// The sample build uses multiple directories to | ||
// keep boilerplate and common code separate from | ||
// the main sample code. | ||
List<String> dirs = [ | ||
'main', // main sample code; look here for the interesting stuff. | ||
'common', // components that are reused by multiple samples | ||
'template'] // boilerplate code that is generated by the sample template process | ||
|
||
android { | ||
compileSdkVersion "android-L" | ||
|
||
buildToolsVersion "19.1.0" | ||
|
||
sourceSets { | ||
main { | ||
dirs.each { dir -> | ||
java.srcDirs "src/${dir}/java" | ||
res.srcDirs "src/${dir}/res" | ||
} | ||
} | ||
androidTest.setRoot('tests') | ||
androidTest.java.srcDirs = ['tests/src'] | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2014 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 xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.android.camera2basic" | ||
android:versionCode="1" | ||
android:versionName="1.0"> | ||
|
||
<uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L" /> | ||
|
||
<application android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:icon="@drawable/ic_launcher" | ||
android:theme="@style/MaterialTheme"> | ||
|
||
<activity android:name=".CameraActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
76 changes: 76 additions & 0 deletions
76
Camera2BasicSample/src/main/java/com/example/android/camera2basic/AutoFitTextureView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2014 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. | ||
*/ | ||
|
||
package com.example.android.camera2basic; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.TextureView; | ||
|
||
/** | ||
* A {@link TextureView} that can be adjusted to a specified aspect ratio. | ||
*/ | ||
public class AutoFitTextureView extends TextureView { | ||
|
||
private int mRatioWidth = 0; | ||
private int mRatioHeight = 0; | ||
|
||
public AutoFitTextureView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public AutoFitTextureView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
/** | ||
* Sets the aspect ratio for this view. The size of the view will be measured based on the ratio | ||
* calculated from the parameters. Note that the actual sizes of parameters don't matter, that | ||
* is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. | ||
* | ||
* @param width Relative horizontal size | ||
* @param height Relative vertical size | ||
*/ | ||
public void setAspectRatio(int width, int height) { | ||
if (width < 0 || height < 0) { | ||
throw new IllegalArgumentException("Size cannot be negative."); | ||
} | ||
mRatioWidth = width; | ||
mRatioHeight = height; | ||
requestLayout(); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
int width = MeasureSpec.getSize(widthMeasureSpec); | ||
int height = MeasureSpec.getSize(heightMeasureSpec); | ||
if (0 == mRatioWidth || 0 == mRatioHeight) { | ||
setMeasuredDimension(width, height); | ||
} else { | ||
if (width < height * mRatioWidth / mRatioHeight) { | ||
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); | ||
} else { | ||
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.