This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
1 parent
73e125d
commit 0b6a163
Showing
40 changed files
with
1,843 additions
and
11 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
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
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
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,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion '26.0.2' | ||
defaultConfig { | ||
applicationId "com.example.android.camera2basic" | ||
minSdkVersion 21 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "com.android.support:appcompat-v7:26.1.0" | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
} |
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,40 @@ | ||
<?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"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<uses-feature android:name="android.hardware.camera" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<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> |
34 changes: 34 additions & 0 deletions
34
kotlinApp/Application/src/main/java/com/example/android/camera2basic/ActivityExtensions.kt
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,34 @@ | ||
/* | ||
* Copyright 2017 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.support.v4.app.FragmentActivity | ||
import android.support.v4.content.ContextCompat | ||
import android.widget.Toast | ||
|
||
/** | ||
* This file illustrates Kotlin's Extension Functions by extending FragmentActivity. | ||
*/ | ||
|
||
/** | ||
* Shows a [Toast] on the UI thread. | ||
* | ||
* @param text The message to show | ||
*/ | ||
fun FragmentActivity.showToast(text: String) { | ||
runOnUiThread { Toast.makeText(this, text, Toast.LENGTH_SHORT).show() } | ||
} |
68 changes: 68 additions & 0 deletions
68
kotlinApp/Application/src/main/java/com/example/android/camera2basic/AutoFitTextureView.kt
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,68 @@ | ||
/* | ||
* Copyright 2017 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 | ||
import android.view.View | ||
|
||
/** | ||
* A [TextureView] that can be adjusted to a specified aspect ratio. | ||
*/ | ||
class AutoFitTextureView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0 | ||
) : TextureView(context, attrs, defStyle) { | ||
|
||
private var ratioWidth = 0 | ||
private var ratioHeight = 0 | ||
|
||
/** | ||
* 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 | ||
*/ | ||
fun setAspectRatio(width: Int, height: Int) { | ||
if (width < 0 || height < 0) { | ||
throw IllegalArgumentException("Size cannot be negative.") | ||
} | ||
ratioWidth = width | ||
ratioHeight = height | ||
requestLayout() | ||
} | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
val width = View.MeasureSpec.getSize(widthMeasureSpec) | ||
val height = View.MeasureSpec.getSize(heightMeasureSpec) | ||
if (ratioWidth == 0 || ratioHeight == 0) { | ||
setMeasuredDimension(width, height) | ||
} else { | ||
if (width < height * ratioWidth / ratioHeight) { | ||
setMeasuredDimension(width, width * ratioHeight / ratioWidth) | ||
} else { | ||
setMeasuredDimension(height * ratioWidth / ratioHeight, height) | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.