mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
adding the initial code for VideoPlayerActivity used for video playing
This commit is contained in:
parent
3277b95da3
commit
50dd2766c8
5 changed files with 177 additions and 4 deletions
|
@ -122,6 +122,10 @@
|
|||
android:name=".activities.PhotoVideoActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.VideoPlayerActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.PanoramaPhotoActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
package com.simplemobiletools.gallery.pro.activities
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromUri
|
||||
import com.simplemobiletools.commons.extensions.getParentPath
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.extensions.*
|
||||
import com.simplemobiletools.gallery.pro.fragments.VideoFragment
|
||||
import com.simplemobiletools.gallery.pro.fragments.ViewPagerFragment
|
||||
import com.simplemobiletools.gallery.pro.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.pro.helpers.TYPE_VIDEOS
|
||||
import com.simplemobiletools.gallery.pro.models.Medium
|
||||
import kotlinx.android.synthetic.main.activity_video_player.*
|
||||
import java.io.File
|
||||
|
||||
open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentListener {
|
||||
|
||||
private var mMedium: Medium? = null
|
||||
private var mIsFullScreen = false
|
||||
private var mCurrentOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||
private var mFragment: ViewPagerFragment? = null
|
||||
private var mUri: Uri? = null
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_video_player)
|
||||
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
if (it) {
|
||||
checkIntent(savedInstanceState)
|
||||
} else {
|
||||
toast(R.string.no_storage_permissions)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
|
||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
}
|
||||
|
||||
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
||||
mUri = intent.data ?: return
|
||||
val filename = getFilenameFromUri(mUri!!)
|
||||
|
||||
if (isPiePlus()) {
|
||||
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
|
||||
showSystemUI(true)
|
||||
val bundle = Bundle()
|
||||
val file = File(mUri.toString())
|
||||
val type = TYPE_VIDEOS
|
||||
|
||||
mMedium = Medium(null, filename, mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, 0, false, 0L)
|
||||
supportActionBar?.title = mMedium!!.name
|
||||
bundle.putSerializable(MEDIUM, mMedium)
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mFragment = VideoFragment()
|
||||
mFragment!!.listener = this
|
||||
mFragment!!.arguments = bundle
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragment_placeholder, mFragment!!).commit()
|
||||
}
|
||||
|
||||
if (config.blackBackground) {
|
||||
fragment_holder.background = ColorDrawable(Color.BLACK)
|
||||
}
|
||||
|
||||
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||
val isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
|
||||
mFragment?.fullscreenToggled(isFullscreen)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_video_player, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (mMedium == null || mUri == null) {
|
||||
return true
|
||||
}
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.menu_force_portrait -> forceOrientation(true)
|
||||
R.id.menu_force_landscape -> forceOrientation(false)
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun forceOrientation(portrait: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
override fun fragmentClicked() {
|
||||
mIsFullScreen = !mIsFullScreen
|
||||
if (mIsFullScreen) {
|
||||
hideSystemUI(true)
|
||||
} else {
|
||||
showSystemUI(true)
|
||||
}
|
||||
|
||||
val newAlpha = if (mIsFullScreen) 0f else 1f
|
||||
top_shadow.animate().alpha(newAlpha).start()
|
||||
}
|
||||
|
||||
override fun videoEnded() = false
|
||||
|
||||
override fun goToPrevItem() {}
|
||||
|
||||
override fun goToNextItem() {}
|
||||
}
|
|
@ -129,10 +129,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
setupRotation()
|
||||
invalidateOptionsMenu()
|
||||
|
||||
if (config.blackBackground) {
|
||||
updateStatusbarColor(Color.BLACK)
|
||||
}
|
||||
|
||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
}
|
||||
|
|
19
app/src/main/res/layout/activity_video_player.xml
Normal file
19
app/src/main/res/layout/activity_video_player.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fragment_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/top_shadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/default_status_action_height"
|
||||
android:background="@drawable/gradient_background_flipped"/>
|
||||
|
||||
</RelativeLayout>
|
23
app/src/main/res/menu/menu_video_player.xml
Normal file
23
app/src/main/res/menu/menu_video_player.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/menu_force_portrait"
|
||||
android:icon="@drawable/ic_orientation_portrait"
|
||||
android:title="@string/force_portrait"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_force_landscape"
|
||||
android:icon="@drawable/ic_orientation_landscape"
|
||||
android:title="@string/force_landscape"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_share"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_open_with"
|
||||
android:title="@string/open_with"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
Loading…
Reference in a new issue