forked from YarikSOffice/OpenCV-Playground
-
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 e79e0b9
Showing
38 changed files
with
1,144 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,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,47 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
applicationId 'com.yariksoffice.javaopencvplaygroung' | ||
minSdkVersion 16 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
multiDexEnabled true | ||
} | ||
buildTypes { | ||
debug { | ||
minifyEnabled false | ||
shrinkResources false | ||
} | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
incremental true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'com.squareup.picasso:picasso:2.5.2' | ||
implementation "com.github.chrisbanes:PhotoView:2.3.0" | ||
|
||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' | ||
implementation 'io.reactivex.rxjava2:rxjava:2.2.11' | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" | ||
|
||
implementation 'org.bytedeco:javacv:1.4.4' | ||
implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm64' | ||
// u can drop redundant platforms here | ||
implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm' | ||
implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-x86' | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.yariksoffice.javaopencvplaygroung"> | ||
|
||
<uses-permission | ||
android:name="android.permission.WRITE_EXTERNAL_STORAGE" | ||
android:maxSdkVersion="18" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="GoogleAppIndexingWarning"> | ||
<activity android:name="com.yariksoffice.javaopencvplaygroung.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/com/yariksoffice/javaopencvplaygroung/FileUtil.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,82 @@ | ||
package com.yariksoffice.javaopencvplaygroung | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.os.Environment | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class FileUtil(private val context: Context) { | ||
|
||
@Throws(IOException::class) | ||
fun urisToFiles(uris: List<Uri>): List<File> { | ||
val files = ArrayList<File>(uris.size) | ||
for (uri in uris) { | ||
val file = createTempFile() | ||
writeUriToFile(uri, file) | ||
files.add(file) | ||
} | ||
return files | ||
} | ||
|
||
@Throws(IOException::class) | ||
private fun createTempFile(): File { | ||
// don't need read/write permission for this directory starting from android 19 | ||
val root = requirePicturesDirectory() | ||
root.mkdirs() // make sure that directory exists | ||
|
||
val date = SimpleDateFormat(DATE_FORMAT_TEMPLATE, Locale.getDefault()).format(Date()) | ||
val filePrefix = IMAGE_NAME_TEMPLATE.format(date) | ||
return File.createTempFile(filePrefix, JPG_EXTENSION, root) | ||
} | ||
|
||
@Throws(IOException::class) | ||
private fun writeUriToFile(target: Uri, destination: File) { | ||
val inputStream = context.contentResolver.openInputStream(target)!! | ||
val outputStream = FileOutputStream(destination) | ||
inputStream.use { input -> | ||
outputStream.use { out -> | ||
input.copyTo(out) | ||
} | ||
} | ||
} | ||
|
||
fun createResultFile(): File { | ||
val pictures = requirePicturesDirectory() | ||
//noinspection ConstantConditions,ResultOfMethodCallIgnored | ||
pictures.mkdirs() | ||
return File("${pictures.absolutePath}$RESULT_FILE_NAME") | ||
} | ||
|
||
private fun requirePicturesDirectory(): File { | ||
return context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) ?: throw IOException( | ||
"Can't access folder") | ||
} | ||
|
||
fun cleanUpWorkingDirectory() { | ||
deleteFile(requirePicturesDirectory()) | ||
} | ||
|
||
// there is no build in function for deleting folders. <3 | ||
private fun deleteFile(file: File) { | ||
if (file.isDirectory) { | ||
val entries = file.listFiles() | ||
if (entries != null) { | ||
for (entry in entries) { | ||
deleteFile(entry) | ||
} | ||
} | ||
} | ||
file.delete() | ||
} | ||
|
||
companion object { | ||
private const val RESULT_FILE_NAME = "/result.jpg" | ||
private const val DATE_FORMAT_TEMPLATE = "yyyyMMdd_HHmmss" | ||
private const val IMAGE_NAME_TEMPLATE = "IMG_%s_" | ||
private const val JPG_EXTENSION = ".jpg" | ||
} | ||
} |
Oops, something went wrong.