replacing the home made photo editor with PhotoEditorSDK

This commit is contained in:
tibbi 2019-12-17 18:16:30 +01:00
parent bc37973603
commit 68f9ceeea3
6 changed files with 233 additions and 2 deletions

View File

@ -33,7 +33,8 @@ android {
buildTypes {
debug {
applicationIdSuffix ".debug"
// we cannot change the original package name, else PhotoEditorSDK won't work
//applicationIdSuffix ".debug"
}
release {
minifyEnabled true
@ -84,3 +85,27 @@ dependencies {
implementation 'androidx.room:room-runtime:2.2.2'
annotationProcessor 'androidx.room:room-compiler:2.2.2'
}
// Apply the PESDKPlugin
apply plugin: 'ly.img.android.pesdk'
pesdkConfig {
licencePath 'pesdk_license'
supportLibVersion "28.0.0"
modules {
include 'ly.img.android.pesdk.ui.mobile_ui:core'
include 'ly.img.android.pesdk.ui.mobile_ui:text'
include 'ly.img.android.pesdk.ui.mobile_ui:focus'
include 'ly.img.android.pesdk.ui.mobile_ui:brush'
include 'ly.img.android.pesdk.ui.mobile_ui:filter'
include 'ly.img.android.pesdk.ui.mobile_ui:transform'
include 'ly.img.android.pesdk.ui.mobile_ui:adjustment'
include 'ly.img.android.pesdk.ui.mobile_ui:text-design'
// Add asset packs if you need
include 'ly.img.android.pesdk.assets:font-basic'
include 'ly.img.android.pesdk.assets:filter-basic'
}
}

View File

@ -10,6 +10,9 @@
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
tools:node="remove"/>
<uses-permission
android:name="android.permission.CAMERA"
tools:node="remove"/>
<uses-sdk
tools:overrideLibrary="com.google.vr.widgets.common, com.google.vr.sdk.widgets.pano"/>
@ -198,7 +201,7 @@
</activity>
<activity
android:name=".activities.EditActivity"
android:name=".activities.NewEditActivity"
android:label="@string/editor">
<intent-filter>
<action android:name="android.intent.action.EDIT"/>
@ -207,6 +210,11 @@
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
<activity
android:name=".activities.EditActivity"
android:label="@string/editor">
<intent-filter>
<action android:name="com.android.camera.action.CROP"/>

View File

@ -0,0 +1 @@
{"api_token":"aulo3T5M9uyXgeJauoiJjw","app_identifiers":["com.simplemobiletools.gallery.pro"],"available_actions":[],"domains":["https://api.photoeditorsdk.com"],"enterprise_license":false,"expires_at":null,"features":["camera","library","export","customassets","whitelabel","adjustment","brush","filter","focus","text","textdesign","transform"],"issued_at":1576163964,"minimum_sdk_version":"1.0","owner":"Tikap s.r.o.","platform":"Android","products":["pesdk"],"version":"2.4","signature":"JvD7pjiy3iomgGW7XgEaHCs7aWxTIRl/PN7dp1muFSpE6S+IVmKDfSR5+enE2Tdh2EFC/3lyVuG7S5FcyOyxeXtyfKW/+H2y8Oem6VQzgTlYus8Eacz3/mk+GShUq+C+xQvbp5cWB/prScOZHPOaiZCu531rFYOGfwgaThtpawtG4B6wxvRWfjJor8fbsIHzEQnUnsEKsQR4UhwAUQvpDnCE0JtuP0CAxFyP03XfLlwIGhbUiCbaHh/kcG3IVzeQxSjjjsefu3rCtjYbm0eZKLbgsCvbNoVv2p011P2XN1pAu1uTMFscD74FbAFAgO12vYHfJ4iQE6cmZBiVSIJftJw3Gawj91NsiJbnLmPSqwSuUApatE5pMAff443s7ML32rHj+gD2IQ3oAHowGtbyofC0LrLPxaIMZEcd9Ttfk3ujn001rvekVXk6Uj/l3P3RpyLs6FHpMMSHo5nAk7ab7MYeR6PZfWDE+ggM1sqWV5fd4rh9qd36ioJgGaL6OnYCh/2t1xeMrFG2aw55hhjZPjxw3yfTvbJrOs1p0G503nkPCzRn4TCvPefkFDquAFCQaVmIJuFi51j4HA34o2E4Twru2SkI0od5ewHE5+hAR+9JalOaZWN/kLi59B9VrAEfskYmfVszqIpekpAyloMPYrpBseUDlWVCqbJIlyQt564="}

View File

@ -0,0 +1,187 @@
package com.simplemobiletools.gallery.pro.activities
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import androidx.core.util.Pair
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.interfaces.CopyMoveListener
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic
import ly.img.android.pesdk.assets.font.basic.FontPackBasic
import ly.img.android.pesdk.backend.model.state.EditorLoadSettings
import ly.img.android.pesdk.backend.model.state.EditorSaveSettings
import ly.img.android.pesdk.backend.model.state.manager.SettingsList
import ly.img.android.pesdk.ui.activity.PhotoEditorBuilder
import ly.img.android.pesdk.ui.model.state.UiConfigFilter
import ly.img.android.pesdk.ui.model.state.UiConfigText
import ly.img.android.pesdk.ui.model.state.UiConfigTheme
import java.io.File
class NewEditActivity : SimpleActivity() {
private val PESDK_EDIT_IMAGE = 1
private val SOURCE_IMAGE_PATH = "SOURCE_IMAGE_PATH"
private val RESULT_IMAGE_PATH = "RESULT_IMAGE_PATH"
private var sourceFileLastModified = 0L
private var destinationFilePath = ""
private var imagePathFromEditor = "" // delete the file stored at the internal app storage (the editor saves it there) in case moving to the selected location fails
private lateinit var uri: Uri
private lateinit var saveUri: Uri
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_edit)
if (checkAppSideloading()) {
return
}
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
initEditActivity()
} else {
toast(R.string.no_storage_permissions)
finish()
}
}
}
private fun initEditActivity() {
if (intent.data == null) {
toast(R.string.invalid_image_path)
finish()
return
}
uri = intent.data!!
if (uri.scheme != "file" && uri.scheme != "content") {
toast(R.string.unknown_file_location)
finish()
return
}
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
val realPath = intent.extras!!.getString(REAL_FILE_PATH)
uri = when {
isPathOnOTG(realPath!!) -> uri
realPath.startsWith("file:/") -> Uri.parse(realPath)
else -> Uri.fromFile(File(realPath))
}
} else {
(getRealPathFromURI(uri))?.apply {
uri = Uri.fromFile(File(this))
}
}
saveUri = when {
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
else -> uri
}
openEditor(uri)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (requestCode == PESDK_EDIT_IMAGE) {
val extras = resultData?.extras
val source = extras?.getString(SOURCE_IMAGE_PATH, "") ?: ""
imagePathFromEditor = extras?.getString(RESULT_IMAGE_PATH, "") ?: ""
if (resultCode != Activity.RESULT_OK || source.isEmpty() || imagePathFromEditor.isEmpty() || source == imagePathFromEditor) {
finish()
} else {
// the image is stored at the internal app storage first, for example /data/user/0/com.simplemobiletools.gallery.pro/files/editor/IMG_20191207_183023.jpg
// first we rename it to the desired name, then move
SaveAsDialog(this, source, true, cancelCallback = {
toast(R.string.image_editing_failed)
finish()
}, callback = {
destinationFilePath = it
handleSAFDialog(destinationFilePath) {
if (it) {
sourceFileLastModified = File(source).lastModified()
val newFile = File("${imagePathFromEditor.getParentPath()}/${destinationFilePath.getFilenameFromPath()}")
File(imagePathFromEditor).renameTo(newFile)
val sourceFile = FileDirItem(newFile.absolutePath, newFile.name)
val conflictResolutions = LinkedHashMap<String, Int>()
conflictResolutions[destinationFilePath] = CONFLICT_OVERWRITE
val pair = Pair(arrayListOf(sourceFile), destinationFilePath.getParentPath())
CopyMoveTask(this, false, true, conflictResolutions, editCopyMoveListener, true).execute(pair)
} else {
toast(R.string.image_editing_failed)
File(imagePathFromEditor).delete()
finish()
}
}
})
}
}
super.onActivityResult(requestCode, resultCode, resultData)
}
private val editCopyMoveListener = object : CopyMoveListener {
override fun copySucceeded(copyOnly: Boolean, copiedAll: Boolean, destinationPath: String) {
if (config.keepLastModified) {
updateLastModified(destinationFilePath, sourceFileLastModified)
}
val paths = arrayListOf(destinationFilePath)
rescanPaths(paths) {
fixDateTaken(paths, false)
}
setResult(Activity.RESULT_OK, intent)
toast(R.string.file_edited_successfully)
finish()
}
override fun copyFailed() {
toast(R.string.unknown_error_occurred)
File(imagePathFromEditor).delete()
finish()
}
}
private fun openEditor(inputImage: Uri) {
val filename = inputImage.toString().getFilenameFromPath()
val settingsList = createPesdkSettingsList(filename)
settingsList.getSettingsModel(EditorLoadSettings::class.java).imageSource = inputImage
PhotoEditorBuilder(this)
.setSettingsList(settingsList)
.startActivityForResult(this, PESDK_EDIT_IMAGE)
}
private fun createPesdkSettingsList(filename: String): SettingsList {
val settingsList = SettingsList()
settingsList.getSettingsModel(UiConfigFilter::class.java).setFilterList(
FilterPackBasic.getFilterPack()
)
settingsList.getSettingsModel(UiConfigText::class.java).setFontList(
FontPackBasic.getFontPack()
)
settingsList.getSettingsModel(UiConfigTheme::class.java).theme = R.style.Imgly_Theme_NoFullscreen
settingsList.getSettingsModel(EditorSaveSettings::class.java)
.setOutputFilePath("$filesDir/editor/$filename")
.savePolicy = EditorSaveSettings.SavePolicy.RETURN_SOURCE_OR_CREATE_OUTPUT_IF_NECESSARY
return settingsList
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_new_edit_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>

View File

@ -6,11 +6,13 @@ buildscript {
repositories {
google()
jcenter()
maven { url 'https://artifactory.img.ly/artifactory/imgly' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'ly.img.android.pesdk:plugin:6.6.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files