Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit b304ea9

Browse files
committed
Initial commit
0 parents  commit b304ea9

36 files changed

+1556
-0
lines changed

Camera2BasicSample/build.gradle

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:0.11.+'
11+
}
12+
}
13+
14+
apply plugin: 'android'
15+
16+
17+
dependencies {
18+
19+
compile "com.android.support:support-v4:+"
20+
compile "com.android.support:support-v13:+"
21+
22+
}
23+
24+
// The sample build uses multiple directories to
25+
// keep boilerplate and common code separate from
26+
// the main sample code.
27+
List<String> dirs = [
28+
'main', // main sample code; look here for the interesting stuff.
29+
'common', // components that are reused by multiple samples
30+
'template'] // boilerplate code that is generated by the sample template process
31+
32+
android {
33+
compileSdkVersion "android-L"
34+
35+
buildToolsVersion "19.1.0"
36+
37+
sourceSets {
38+
main {
39+
dirs.each { dir ->
40+
java.srcDirs "src/${dir}/java"
41+
res.srcDirs "src/${dir}/res"
42+
}
43+
}
44+
androidTest.setRoot('tests')
45+
androidTest.java.srcDirs = ['tests/src']
46+
47+
}
48+
}
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2014 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
19+
20+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
21+
package="com.example.android.camera2basic"
22+
android:versionCode="1"
23+
android:versionName="1.0">
24+
25+
<uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L" />
26+
27+
<application android:allowBackup="true"
28+
android:label="@string/app_name"
29+
android:icon="@drawable/ic_launcher"
30+
android:theme="@style/MaterialTheme">
31+
32+
<activity android:name=".CameraActivity"
33+
android:label="@string/app_name">
34+
<intent-filter>
35+
<action android:name="android.intent.action.MAIN" />
36+
<category android:name="android.intent.category.LAUNCHER" />
37+
</intent-filter>
38+
</activity>
39+
</application>
40+
41+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.camera2basic;
18+
19+
import android.content.Context;
20+
import android.util.AttributeSet;
21+
import android.view.TextureView;
22+
23+
/**
24+
* A {@link TextureView} that can be adjusted to a specified aspect ratio.
25+
*/
26+
public class AutoFitTextureView extends TextureView {
27+
28+
private int mRatioWidth = 0;
29+
private int mRatioHeight = 0;
30+
31+
public AutoFitTextureView(Context context) {
32+
this(context, null);
33+
}
34+
35+
public AutoFitTextureView(Context context, AttributeSet attrs) {
36+
this(context, attrs, 0);
37+
}
38+
39+
public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) {
40+
super(context, attrs, defStyle);
41+
}
42+
43+
/**
44+
* Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
45+
* calculated from the parameters. Note that the actual sizes of parameters don't matter, that
46+
* is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
47+
*
48+
* @param width Relative horizontal size
49+
* @param height Relative vertical size
50+
*/
51+
public void setAspectRatio(int width, int height) {
52+
if (width < 0 || height < 0) {
53+
throw new IllegalArgumentException("Size cannot be negative.");
54+
}
55+
mRatioWidth = width;
56+
mRatioHeight = height;
57+
requestLayout();
58+
}
59+
60+
@Override
61+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
62+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
63+
int width = MeasureSpec.getSize(widthMeasureSpec);
64+
int height = MeasureSpec.getSize(heightMeasureSpec);
65+
if (0 == mRatioWidth || 0 == mRatioHeight) {
66+
setMeasuredDimension(width, height);
67+
} else {
68+
if (width < height * mRatioWidth / mRatioHeight) {
69+
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
70+
} else {
71+
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
72+
}
73+
}
74+
}
75+
76+
}

0 commit comments

Comments
 (0)