|
@@ -4,13 +4,17 @@ import android.app.AlertDialog
|
|
import android.app.ProgressDialog
|
|
import android.app.ProgressDialog
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
|
|
+import android.content.ContentResolver
|
|
|
|
+import android.content.ContentValues
|
|
import android.content.DialogInterface
|
|
import android.content.DialogInterface
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.os.Environment
|
|
import android.os.Environment
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
|
|
+import android.provider.MediaStore
|
|
import android.support.v4.app.DialogFragment
|
|
import android.support.v4.app.DialogFragment
|
|
|
|
+import android.support.v4.content.FileProvider
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.widget.CompoundButton
|
|
import android.widget.CompoundButton
|
|
@@ -375,7 +379,37 @@ class MovieEditActivity : AppCompatActivity(),
|
|
override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
|
override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- onClickBomo = Runnable { saveMovie() }
|
|
|
|
|
|
+ onClickBomo = Runnable {
|
|
|
|
+ saveMovie(object : OnMovieSavedListener {
|
|
|
|
+ override fun onSaved(file: File) {
|
|
|
|
+ AlertDialog.Builder(this@MovieEditActivity)
|
|
|
|
+ .setMessage("Complete")
|
|
|
|
+ .setPositiveButton("Play") { _, _ ->
|
|
|
|
+ val uri = Uri.parse(file.absolutePath)
|
|
|
|
+ val intent = Intent(Intent.ACTION_VIEW, uri).apply {
|
|
|
|
+ setDataAndType(uri, "video/mp4")
|
|
|
|
+ }
|
|
|
|
+ if (intent.resolveActivity(packageManager) != null) {
|
|
|
|
+ Intent.createChooser(intent, "").apply {
|
|
|
|
+ startActivity(this)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Toast.makeText(this@MovieEditActivity, "No app can play video", Toast.LENGTH_SHORT).show()
|
|
|
|
+ }
|
|
|
|
+ }.show()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ onClickYoutube = Runnable {
|
|
|
|
+ saveMovie(object : OnMovieSavedListener {
|
|
|
|
+ override fun onSaved(file: File) {
|
|
|
|
+ val isSuc = shareToOtherApp(file, "com.google.android.youtube")
|
|
|
|
+ if (!isSuc) {
|
|
|
|
+ Toast.makeText(context, R.string.share_youtube_not_found, Toast.LENGTH_SHORT).show()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
onClickExportPdf = Runnable { onClickExportPdf() }
|
|
onClickExportPdf = Runnable { onClickExportPdf() }
|
|
onClickPlay = Runnable {
|
|
onClickPlay = Runnable {
|
|
moviePlayer.moviePlayListener = dialogMoviePlayListener
|
|
moviePlayer.moviePlayListener = dialogMoviePlayListener
|
|
@@ -385,6 +419,30 @@ class MovieEditActivity : AppCompatActivity(),
|
|
}.show(supportFragmentManager)
|
|
}.show(supportFragmentManager)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun shareToOtherApp(file: File, packageNameKeyWord: String): Boolean {
|
|
|
|
+ val authority = "$packageName"
|
|
|
|
+ val context = this@MovieEditActivity
|
|
|
|
+ val uri = FileProvider.getUriForFile(context, authority, file)
|
|
|
|
+
|
|
|
|
+ val intent = Intent(Intent.ACTION_SEND)
|
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
|
|
|
|
+ intent.type = "video/mp4"
|
|
|
|
+ intent.putExtra(Intent.EXTRA_STREAM, uri)
|
|
|
|
+
|
|
|
|
+ val activities = packageManager.queryIntentActivities(intent, 0)
|
|
|
|
+ if (!activities.isEmpty()) {
|
|
|
|
+ activities.forEach {
|
|
|
|
+ val name = it.activityInfo.packageName
|
|
|
|
+ if (name.contains(packageNameKeyWord)) {
|
|
|
|
+ intent.setClassName(name, it.activityInfo.name)
|
|
|
|
+ startActivity(intent)
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun onClickExportPdf() {
|
|
private fun onClickExportPdf() {
|
|
ExportPdfDialog().also { exportPdfDialog ->
|
|
ExportPdfDialog().also { exportPdfDialog ->
|
|
exportPdfDialog.image1Path = viewModel.project?.scene1File?.path ?: ""
|
|
exportPdfDialog.image1Path = viewModel.project?.scene1File?.path ?: ""
|
|
@@ -422,7 +480,11 @@ class MovieEditActivity : AppCompatActivity(),
|
|
}.show(supportFragmentManager)
|
|
}.show(supportFragmentManager)
|
|
}
|
|
}
|
|
|
|
|
|
- private fun saveMovie() {
|
|
|
|
|
|
+ interface OnMovieSavedListener {
|
|
|
|
+ fun onSaved(file: File)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun saveMovie(onMovieSavedListener: OnMovieSavedListener) {
|
|
val scaledWidth = resources.getDimensionPixelSize(R.dimen.movie_width)
|
|
val scaledWidth = resources.getDimensionPixelSize(R.dimen.movie_width)
|
|
val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
|
|
val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
|
|
|
|
|
|
@@ -462,21 +524,7 @@ class MovieEditActivity : AppCompatActivity(),
|
|
AlertDialog.Builder(this).setMessage(msg).show()
|
|
AlertDialog.Builder(this).setMessage(msg).show()
|
|
delayedHide(100)
|
|
delayedHide(100)
|
|
}, {
|
|
}, {
|
|
- AlertDialog.Builder(this)
|
|
|
|
- .setMessage("Complete")
|
|
|
|
- .setPositiveButton("Play") { _, _ ->
|
|
|
|
- val uri = Uri.parse(outputFile.absolutePath)
|
|
|
|
- val intent = Intent(Intent.ACTION_VIEW, uri).apply {
|
|
|
|
- setDataAndType(uri, "video/mp4")
|
|
|
|
- }
|
|
|
|
- if (intent.resolveActivity(packageManager) != null) {
|
|
|
|
- Intent.createChooser(intent, "").apply {
|
|
|
|
- startActivity(this)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- Toast.makeText(this, "No app can play video", Toast.LENGTH_SHORT).show()
|
|
|
|
- }
|
|
|
|
- }.show()
|
|
|
|
|
|
+ onMovieSavedListener.onSaved(outputFile)
|
|
delayedHide(100)
|
|
delayedHide(100)
|
|
})
|
|
})
|
|
}
|
|
}
|