Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikSOffice committed Aug 5, 2019
0 parents commit e79e0b9
Show file tree
Hide file tree
Showing 38 changed files with 1,144 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
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
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

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

7 changes: 7 additions & 0 deletions .idea/dictionaries/yari.xml

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

19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

9 changes: 9 additions & 0 deletions .idea/misc.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
27 changes: 27 additions & 0 deletions app/src/main/AndroidManifest.xml
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>
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"
}
}
Loading

0 comments on commit e79e0b9

Please sign in to comment.