allow editing third party images

This commit is contained in:
tibbi 2016-12-04 15:47:46 +01:00
parent a66d72abde
commit 9fb2ec55d9
4 changed files with 28 additions and 14 deletions

View file

@ -7,14 +7,15 @@ import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.openEditor
import com.simplemobiletools.gallery.extensions.openWith import com.simplemobiletools.gallery.extensions.openWith
import com.simplemobiletools.gallery.extensions.setAsWallpaper import com.simplemobiletools.gallery.extensions.setAsWallpaper
import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.extensions.shareMedium
import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.VideoFragment import com.simplemobiletools.gallery.fragments.VideoFragment
import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import java.io.File import java.io.File
@ -72,7 +73,10 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.photo_video_menu, menu) menuInflater.inflate(R.menu.photo_video_menu, menu)
menu.findItem(R.id.menu_set_as_wallpaper).isVisible = mMedium.isImage() menu.findItem(R.id.menu_set_as_wallpaper).isVisible = mMedium.isImage()
menu.findItem(R.id.menu_edit).isVisible = mMedium.isImage()
return true return true
} }
@ -90,6 +94,10 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
shareMedium(mMedium) shareMedium(mMedium)
true true
} }
R.id.menu_edit -> {
openEditor(File(mMedium.path))
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }

View file

@ -149,7 +149,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
true true
} }
R.id.menu_edit -> { R.id.menu_edit -> {
openEditor() openEditor(getCurrentFile())
true true
} }
R.id.menu_properties -> { R.id.menu_properties -> {
@ -185,18 +185,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}) })
} }
private fun openEditor() {
val intent = Intent(Intent.ACTION_EDIT)
intent.setDataAndType(Uri.fromFile(getCurrentFile()), "image/*")
val chooser = Intent.createChooser(intent, getString(R.string.edit_image_with))
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(chooser, REQUEST_EDIT_IMAGE)
} else {
toast(R.string.no_editor_found)
}
}
private fun showProperties() { private fun showProperties() {
PropertiesDialog(this, getCurrentFile().absolutePath, false) PropertiesDialog(this, getCurrentFile().absolutePath, false)
} }

View file

@ -10,6 +10,7 @@ import android.view.KeyEvent
import android.view.ViewConfiguration import android.view.ViewConfiguration
import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.filepicker.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import java.io.File import java.io.File
@ -67,6 +68,18 @@ fun Activity.openWith(file: File) {
} }
} }
fun Activity.openEditor(file: File) {
val intent = Intent(Intent.ACTION_EDIT)
intent.setDataAndType(Uri.fromFile(file), "image/*")
val chooser = Intent.createChooser(intent, getString(R.string.edit_image_with))
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(chooser, REQUEST_EDIT_IMAGE)
} else {
toast(R.string.no_editor_found)
}
}
fun Activity.hasNavBar(): Boolean { fun Activity.hasNavBar(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val display = windowManager.defaultDisplay val display = windowManager.defaultDisplay

View file

@ -6,6 +6,11 @@
android:icon="@mipmap/share" android:icon="@mipmap/share"
android:title="@string/share" android:title="@string/share"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_edit"
android:icon="@mipmap/edit"
android:title="@string/edit"
app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/menu_set_as_wallpaper" android:id="@+id/menu_set_as_wallpaper"
android:title="@string/set_as_wallpaper" android:title="@string/set_as_wallpaper"