﻿B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=10.5
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
  
	Dim player1 As SimpleExoPlayer
		
	Dim doubleTapDelay As Timer

	Dim timer_play_time As Timer

End Sub

Sub Globals
	Dim int_play_time As Int
	
	Dim GD As GestureDetector
	
	Dim SimpleExoPlayerView1 As SimpleExoPlayerView
	
	Dim show_or_hide As Boolean = True

	Dim ActionBar As Panel
	Dim  lb_onvan , lb_close As Label

	Dim Volume As Int
	Dim Brightness As Int
	Dim pho_Volume As Phone
	Dim pho_Brightness As Phone
	Dim lb_Volume As Label
	Dim lb_Brightness As Label
	Dim lb_time As Label
	
	Dim bol1 As Boolean = False

	Dim img_logo As ImageView
	
	Dim p_setBrightness As Phone
	
	Dim LVCircularRing1 As RotateLoading
	
 	
	Dim wake As PhoneWakeState

	Dim lb_lock As Label
	Dim lb_lock_release As Label
	Dim bol_lock As Boolean = False
  
	Dim p_paly As Panel
	Dim img_play As Label
	Dim img_pause As Label
	Dim L_Speed2 As Label

	Dim p_Volume As Panel
	Dim lb_kamel_Volume As Label
	Dim lb_border_Volume As Label
	Dim cvs_Volume As B4XCanvas

	Dim p_Brightness As Panel
	Dim lb_kamel_Brightness As Label
	Dim lb_border_Brightness As Label
	Dim cvs_Brightness As B4XCanvas

 	Dim p_preview As Panel
	Dim img_preview As ImageView
		
	Dim bol_der_right_left As Boolean = False
	Dim bol_Brightness As Boolean = False
	Dim bol_Volume As Boolean = False

	Dim mLastScrollY As Int = 0
	Dim mLastScrollX As Int = 0
		
	Dim p_next_dubble As Panel
	Dim p_back_dubble As Panel
	
	Dim img_next_dubble1 As ImageView
	Dim img_next_dubble12 As ImageView
	Dim img_next_dubble13 As ImageView
	
	Dim img_back_dubble1 As ImageView
	Dim img_back_dubble12 As ImageView
	Dim img_back_dubble13 As ImageView
 	
	Dim urlAll As String
	
	Dim speedSound As Float = 1
	
	Dim labShare As Label
	Dim labDl 	 As Label
  	
 	Dim idDs As String
	Dim sName As String
	
End Sub
  
Sub Activity_Create(FirstTime As Boolean)
  		
	int_play_time = 0
	doubleTapDelay.Initialize("doubleTapDelay",500)
	timer_play_time.Initialize("timer_play_time",1000)
	
	TransparentNavigationBar
	
	urlAll = func.readPFM("list_film" )
	Dim title As String = func.readPFM("name_zirFilm" )

	sName = title
	idDs  = func.readPFM("idDs")
 		
	wake.KeepAlive(True)
		 
 
	player1.Initialize("player")
	
	Activity.LoadLayout("Player")
	SimpleExoPlayerView1.Player = player1
	SimpleExoPlayerView1.UseController = False
	
	
	
	SimpleExoPlayerView1.Height = SimpleExoPlayerView1.Height + StatusBarHeight
	Activity.Height = SimpleExoPlayerView1.Height
   	 
	 
	GD.SetOnGestureListener(SimpleExoPlayerView1, "Gesture")
	
	Dim jo As JavaObject = player1
	Dim event As Object = jo.CreateEventFromUI("com.google.android.exoplayer2.Player$EventListener", "statechanged", False)
	jo.GetFieldJO("player").RunMethod("addListener", Array(event))
	
	Dim jo1 As JavaObject = SimpleExoPlayerView1
	Dim event1 As Object = jo1.CreateEventFromUI("com/google/android/exoplayer2/ui/PlayerControlView.VisibilityListener".Replace("/", "."), "VisibilityChange", Null)
	jo1.RunMethod("setControllerVisibilityListener", Array(event1))

	Dim jo3 As JavaObject = SimpleExoPlayerView1
	jo3.RunMethod("setFastForwardIncrementMs", Array(10000))

	Dim jo4 As JavaObject = SimpleExoPlayerView1
	jo4.RunMethod("setRewindIncrementMs", Array(10000))

	Dim r As Reflector
	r.Target = SimpleExoPlayerView1
	r.Target = r.GetField("controller")
	Dim timebar As JavaObject = r.GetField("timeBar")
	Dim listener As Object = timebar.CreateEventFromUI("com.google.android.exoplayer2.ui.TimeBar$OnScrubListener", "Scrub", False)
	timebar.RunMethod("addListener", Array(listener))


	'*****************************************************************************************************dubble

	p_next_dubble.Initialize("p_next_dubble")
	Activity.AddView(p_next_dubble,70%x,-20%y,70%x,140%y+StatusBarHeight)
	func.color_border(p_next_dubble,0x14FFFFFF,1000dip)
	p_next_dubble.Visible = False
		
	img_next_dubble1.Initialize("img_next_dubble1")
	img_next_dubble1.Gravity = Gravity.FILL
	img_next_dubble1.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_next_dubble.AddView(img_next_dubble1,30%x/2-22.5dip,p_next_dubble.Height/2-7.5dip,15dip,15dip)
	
	img_next_dubble12.Initialize("img_next_dubble12")
	img_next_dubble12.Gravity = Gravity.FILL
	img_next_dubble12.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_next_dubble.AddView(img_next_dubble12,30%x/2-7.5dip,p_next_dubble.Height/2-7.5dip,15dip,15dip)
	
	img_next_dubble13.Initialize("img_next_dubble13")
	img_next_dubble13.Gravity = Gravity.FILL
	img_next_dubble13.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_next_dubble.AddView(img_next_dubble13,30%x/2+7.5dip,p_next_dubble.Height/2-7.5dip,15dip,15dip)
	
	p_back_dubble.Initialize("p_back_dubble")
	Activity.AddView(p_back_dubble,-40%x,-20%y,70%x,140%y+StatusBarHeight)
	func.color_border(p_back_dubble,0x14FFFFFF,1000dip)
	p_back_dubble.Visible = False
	
	img_back_dubble1.Initialize("img_back_dubble1")
	img_back_dubble1.Gravity = Gravity.FILL
	img_back_dubble1.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_back_dubble.AddView(img_back_dubble1,55%x+7.5dip,p_back_dubble.Height/2-7.5dip,15dip,15dip)
	func.SetRotation(img_back_dubble1,180)
	
	img_back_dubble12.Initialize("img_back_dubble12")
	img_back_dubble12.Gravity = Gravity.FILL
	img_back_dubble12.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_back_dubble.AddView(img_back_dubble12,55%x-7.5dip,p_back_dubble.Height/2-7.5dip,15dip,15dip)
	func.SetRotation(img_back_dubble12,180)

	img_back_dubble13.Initialize("img_back_dubble13")
	img_back_dubble13.Gravity = Gravity.FILL
	img_back_dubble13.Bitmap = LoadBitmap(File.DirAssets, "arrowhead.png")
	p_back_dubble.AddView(img_back_dubble13,55%x-22.5dip,p_back_dubble.Height/2-7.5dip,15dip,15dip)
	func.SetRotation(img_back_dubble13,180)

	'*****************************************************************************************************dubble

	p_paly.Initialize("p_paly")
	Activity.AddView(p_paly,50%x-35dip,50%y-35dip,70dip,70dip)
	func.color_border1(p_paly,0x5AFAFAFA,1000dip,3dip,0xFFFFFB81)
	p_paly.Visible = False
	
	img_play.Initialize("img_play")
	p_paly.AddView(img_play,0,0,70dip,70dip)
	img_play.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	img_play.Text = Chr(0xE037)
	img_play.TextColor = 0xFFFFFB81
	img_play.Typeface = Typeface.MATERIALICONS
	func.MinimomFontLabel(img_play,50)
	
	img_pause.Initialize("img_pause")
	p_paly.AddView(img_pause,0,0,70dip,70dip)
	img_pause.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	img_pause.Text = Chr(0xE034)
	img_pause.TextColor = 0xFFFFFB81
	img_pause.Typeface = Typeface.MATERIALICONS
	func.MinimomFontLabel(img_pause,50)
	
	img_play.Visible = True
	img_pause.Visible = False
	


	'*****************************************************************************************************controll
	
	p_preview.Initialize("p_preview")
	Activity.AddView(p_preview,8dip,100%y-GetHiControlView-100dip-20dip,150dip,100dip)
	func.color_border1(p_preview,Colors.Black,0,2dip,Colors.White)
	p_preview.Visible = False
	
	img_preview.Initialize("img_preview")
	p_preview.AddView(img_preview,0,0,150dip,100dip)
	img_preview.Gravity = Gravity.FILL

	'*****************************************************************************************************controll
	img_logo.Initialize("img_logo")
	Activity.AddView(img_logo,100%x-30dip,18dip+StatusBarHeight,20dip,20dip)
	img_logo.Gravity = Gravity.FILL
	img_logo.SetBackgroundImage(LoadBitmap(File.DirAssets,"logo.png"))
	img_logo.Visible = False

	ActionBar.Initialize("")
	Activity.AddView(ActionBar,0dip,StatusBarHeight,100%x,56dip)
	ActionBar.Color = 0x96000000
	
	lb_close.Initialize("lb_close")
	ActionBar.AddView(lb_close,100%x-56dip,0,56dip,56dip)
	lb_close.Text = Chr(0xE5C8)
	lb_close.TextColor = Colors.White
	lb_close.Typeface = Typeface.MATERIALICONS
	lb_close.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	lb_close.TextSize = 27

	lb_onvan.Initialize("lb_onvan")
	ActionBar.AddView(lb_onvan,56dip,0,100%x-112dip,56dip)
	lb_onvan.Text = title
	lb_onvan.Typeface = Typeface.LoadFromAssets(func.font3)
	lb_onvan.TextColor = Colors.White
	lb_onvan.TextSize = 16
	lb_onvan.Gravity = Bit.Or(Gravity.RIGHT,Gravity.CENTER_VERTICAL)
	lb_onvan.SingleLine = True
	lb_onvan.Ellipsize = "END"
  	
	
	labShare.Initialize("labShare")
	Activity.AddView(labShare,100%x-53dip,ActionBar.Height+ActionBar.Top+2dip,50dip,50dip)
	labShare.Text = Chr(0xE80D)
	labShare.TextColor = Colors.White
	labShare.Typeface = Typeface.MATERIALICONS
	labShare.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.MinimomFontLabel(labShare,25)
	func.color_border(labShare,0x96000000,1000dip)
 
	labDl.Initialize("labDl")
	Activity.AddView(labDl,100%x-63dip-50dip,ActionBar.Height+ActionBar.Top+2dip,50dip,50dip)
	labDl.Text = Chr(0xF0ED)
	labDl.TextColor = Colors.White
	labDl.Typeface = Typeface.FONTAWESOME
	labDl.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.MinimomFontLabel(labDl,25)
	func.color_border(labDl,0x96000000,1000dip)
 

	visLab(labShare,False)
	visLab(labDl,False)
 	
	If func.readPFM("typePlats") = 1 Then
 
		If File.Exists(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4") Then
			labDl.Typeface = Typeface.MATERIALICONS
			labDl.Text = Chr(0xE5CA)
		Else
			labDl.Typeface = Typeface.FONTAWESOME
			labDl.Text = Chr(0xF0ED)
		End If
 	 
	End If

     	
	lb_lock.Initialize("lb_lock")
	Activity.AddView(lb_lock,10dip+50dip,ActionBar.Height+ActionBar.Top+2dip,50dip,50dip)
	lb_lock.Text = Chr(0xE898)
	lb_lock.TextColor = Colors.White
	lb_lock.Typeface = Typeface.MATERIALICONS
	lb_lock.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.MinimomFontLabel(lb_lock,25)
	func.color_border(lb_lock,0x96000000,1000dip)
	lb_lock.Visible = False

	lb_lock_release.Initialize("lb_lock_release")
	Activity.AddView(lb_lock_release,10dip+50dip,ActionBar.Height+ActionBar.Top+2dip,50dip,50dip)
	lb_lock_release.Text = Chr(0xE899)
	lb_lock_release.TextColor = Colors.White
	lb_lock_release.Typeface = Typeface.MATERIALICONS
	lb_lock_release.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.MinimomFontLabel(lb_lock_release,25)
	func.color_border(lb_lock_release,0x96000000,1000dip)
	lb_lock_release.Visible = False
	
 	
	L_Speed2.Initialize("L_Speed2")
	Activity.AddView(L_Speed2,3dip,ActionBar.Height+ActionBar.Top+2dip,50dip,50dip)
	L_Speed2.Typeface = Typeface.CreateNew(Typeface.LoadFromAssets(func.font3),Typeface.STYLE_BOLD)
	L_Speed2.TextColor = Colors.White
	L_Speed2.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	L_Speed2.Text="1X"
	func.MinimomFontLabel(L_Speed2,17)
	speedSound = 1


	Volume = pho_Volume.GetVolume(pho_Volume.VOLUME_MUSIC)
	Try
		Brightness = pho_Brightness.GetSettings("screen_brightness")
	Catch
		Brightness = 50
		Log(LastException)
	End Try

	'*******************************************vv
	p_Volume.Initialize("p_Volume")
	Activity.AddView(p_Volume,100%x-40dip-6.5dip,lb_lock.Height+lb_lock.Top+10dip,40dip,100%y-90dip-10dip-(lb_lock.Height+lb_lock.Top+10dip))
	func.color_border(p_Volume,0x96000000,10dip)
	p_Volume.Visible = False
	
	lb_kamel_Volume.Initialize("lb_kamel_Volume")
	p_Volume.AddView(lb_kamel_Volume,12.5dip,10dip,15dip,p_Volume.Height-20dip)

	cvs_Volume.Initialize(lb_kamel_Volume)
	func.SetRotation(lb_kamel_Volume,180)

	lb_border_Volume.Initialize("lb_border_Volume")
	p_Volume.AddView(lb_border_Volume,lb_kamel_Volume.Left,lb_kamel_Volume.Top,lb_kamel_Volume.Width,lb_kamel_Volume.Height)
	func.color_border1(lb_border_Volume,Colors.Transparent,0,1dip,Colors.White)

	lb_Volume.Initialize("lb_Volume")
	Activity.AddView(lb_Volume,40%x,45%y,20%x,10%y)
	lb_Volume.TextColor = Colors.Black
	lb_Volume.Text = func.gland(355)&" : "&"100"&" %"
	lb_Volume.Typeface = Typeface.LoadFromAssets(func.font3)
	lb_Volume.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.color_border(lb_Volume,Colors.ARGB(150,255,255,255),10dip)
	func.MinimomFontLabel(lb_Volume,14)
	lb_Volume.Visible = False
	'*******************************************vv

	'**************************************************bb
	p_Brightness.Initialize("p_Brightness")
	Activity.AddView(p_Brightness,6.5dip,lb_lock.Height+lb_lock.Top+10dip,40dip,100%y-90dip-10dip-(lb_lock.Height+lb_lock.Top+10dip))
	func.color_border(p_Brightness,0x96000000,10dip)
	p_Brightness.Visible = False
	
	lb_kamel_Brightness.Initialize("lb_kamel_Brightness")
	p_Brightness.AddView(lb_kamel_Brightness,12.5dip,10dip,15dip,p_Brightness.Height-20dip)

	cvs_Brightness.Initialize(lb_kamel_Brightness)
	func.SetRotation(lb_kamel_Brightness,180)

	lb_border_Brightness.Initialize("lb_border_Brightness")
	p_Brightness.AddView(lb_border_Brightness,lb_kamel_Brightness.Left,lb_kamel_Brightness.Top,lb_kamel_Brightness.Width,lb_kamel_Brightness.Height)
	func.color_border1(lb_border_Brightness,Colors.Transparent,0,1dip,Colors.White)

	lb_Brightness.Initialize("lb_Brightness")
	Activity.AddView(lb_Brightness,40%x,45%y,20%x,10%y)
	lb_Brightness.TextColor = Colors.Black
	lb_Brightness.Text = func.gland(354)&" : "&"100"&" %"
	lb_Brightness.Typeface = Typeface.LoadFromAssets(func.font3)
	lb_Brightness.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.color_border(lb_Brightness,Colors.ARGB(150,255,255,255),10dip)
	func.MinimomFontLabel(lb_Brightness,14)
	lb_Brightness.Visible = False
	'**************************************************bb
	'**************************************************tt
	lb_time.Initialize("lb_time")
	Activity.AddView(lb_time,40%x,45%y,20%x,10%y)
	lb_time.TextColor = Colors.Black
	lb_time.Text = "99:99:99"
	lb_time.Typeface = Typeface.LoadFromAssets(func.font3)
	lb_time.Gravity = Bit.Or(Gravity.CENTER,Gravity.CENTER_VERTICAL)
	func.color_border(lb_time,Colors.ARGB(150,255,255,255),10dip)
	func.MinimomFontLabel(lb_time,14)
	lb_time.Visible = False
	'**************************************************tt

	LVCircularRing1.Initialize("LVCircularRing1")
	Activity.AddView(LVCircularRing1,50%x-35dip,50%y-35dip,70dip,70dip)
	LVCircularRing1.CircleWidth = 5
	LVCircularRing1.ShadowColor = Colors.Transparent
	LVCircularRing1.CircleColor =  Colors.White
	LVCircularRing1.FadeInTime = 10
	LVCircularRing1.FadeOutTime = 3000
	LVCircularRing1.start
	
 
	Show_Film1 

	show_navication(True,False)
		
End Sub

Sub visLab(lab As Label,vis As Boolean)
	If func.readPFM("typePlats") = 2 Or func.readPFM("typeLastDaySpeech") = 2 Then
		lab.Visible = False
	Else
		lab.Visible = vis
	End If
End Sub
#Region Show

Sub Show_Film1 
	
	Try
 		
		Log(File.Exists(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4"))
		Log(func.readPFM("typePlats"))
		Log(idDs&"-"&sName&".mp4")
		
		If func.readPFM("typePlats") = 1 Then
			If File.Exists(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4") Then
				player1.Prepare(player1.CreateFileSource(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4"))
			Else
				player1.Prepare(player1.CreateUriSource(urlAll))
			End If
		Else
			player1.Prepare(player1.CreateUriSource(urlAll))
		End If

 
		player1.Play
 
		lb_lock.Visible = True
		L_Speed2.Visible = True
		visLab(labDl,True)
		visLab(labShare,True)
  		
	Catch
		Log(LastException)
		func.ToastERROR(func.gland(175))

	End Try
	
End Sub


Sub p_paly_Click
	If img_pause.Visible Then
		player1.Pause
		If timer_play_time.IsInitialized And timer_play_time.Enabled Then timer_play_time.Enabled = False
	Else
		player1.Play
	End If
End Sub

Sub Player_Ready
	SimpleExoPlayerView1.UseController = True
	show_controller(True)
End Sub
Sub Player_Error (Message As String)
	Log("Error: " & Message)
	exit_ppplayer(False)
	func.ToastERROR(func.gland(175))
End Sub
Sub Player_Complete
	Log("complete")
	If img_pause.IsInitialized And img_play.IsInitialized Then
		player1.Position = 0
		img_pause.Visible = False
		img_play.Visible = True
		player1.Pause
	End If
End Sub
  
 
Sub StateChanged_Event (MethodName As String, Args() As Object) As Object
	
	Select MethodName
		
		Case "onPlayerStateChanged"
			Dim Playing As Boolean = Args(0)

			If Playing = False Then
				img_pause.Visible = False
				img_play.Visible = True
			Else
				If timer_play_time.IsInitialized And timer_play_time.Enabled = False Then timer_play_time.Enabled = True
				img_pause.Visible = True
				img_play.Visible = False
			End If
			
			If GetPlayState = 2 Then
				LVCircularRing1.Visible = True
				p_paly.Visible = False
			Else If GetPlayState = 3 Then
				If timer_play_time.IsInitialized And timer_play_time.Enabled = False Then timer_play_time.Enabled = True
				p_paly.Visible = True
				LVCircularRing1.Visible = False
			End If
						
	End Select

	Return Null
	
End Sub

Sub VisibilityChange_Event (MethodName As String, Args() As Object) As Object
	
	Dim IsVisible As Boolean = 0 = Args(0)
	ActionBar.Visible = IsVisible
	show_or_hide = IsVisible
	
	lb_lock.Visible = IsVisible
	L_Speed2.Visible = IsVisible
 	
	visLab(labShare,IsVisible)
	visLab(labDl,IsVisible)
 	
	p_paly.Visible = IsVisible
	
	img_logo.Visible = Not(IsVisible)

	show_navication(IsVisible,True)
	
	Return Null
	
End Sub


Sub GetPlayState As Int
	'    1 = IDLE
	'    2 = BUFFERING
	'    3 = READY
	'    4 = ENDED
	Dim jo2 As JavaObject = player1
	jo2 = jo2.GetField("player")
	Return jo2.RunMethod("getPlaybackState", Null)
End Sub
  
Sub GetHiControlView As Int
  	
	Return 10dip

End Sub

Private Sub DrawValue_Volume(Value As Float)
	cvs_Volume.ClearRect(cvs_Volume.TargetRect)
	cvs_Volume.DrawLine(cvs_Volume.TargetRect.CenterX, 0, cvs_Volume.TargetRect.CenterX, cvs_Volume.TargetRect.Bottom, Colors.Transparent, 15dip)
	cvs_Volume.DrawLine(cvs_Volume.TargetRect.CenterX, 0, cvs_Volume.TargetRect.CenterX,  Value / 100 * cvs_Volume.TargetRect.Bottom,0xFF4E78CC, 15dip)
	cvs_Volume.Invalidate
End Sub

Private Sub DrawValue_Brightness(Value As Float)
	cvs_Brightness.ClearRect(cvs_Brightness.TargetRect)
	cvs_Brightness.DrawLine(cvs_Brightness.TargetRect.CenterX, 0, cvs_Brightness.TargetRect.CenterX, cvs_Brightness.TargetRect.Bottom, Colors.Transparent, 15dip)
	cvs_Brightness.DrawLine(cvs_Brightness.TargetRect.CenterX, 0, cvs_Brightness.TargetRect.CenterX,  Value / 100 * cvs_Brightness.TargetRect.Bottom,0xFFD0A848, 15dip)
	cvs_Brightness.Invalidate
End Sub

Private Sub L_Speed2_Click
  
	If speedSound = 1 Then
		speedSound = 1.125
		L_Speed2.Text="1.15X"
	Else If speedSound = 1.125 Then
		speedSound = 1.25
		L_Speed2.Text="1.25X"
	Else If speedSound = 1.25 Then
		speedSound = 1.5
		L_Speed2.Text="1.5X"
	Else If speedSound = 1.5 Then
		speedSound = 1.75
		L_Speed2.Text="1.75X"
	Else If speedSound = 1.75 Then
		speedSound = 2
		L_Speed2.Text="2X"
	Else If speedSound = 2 Then
		speedSound = 0.75
		L_Speed2.Text="0.75X"
	Else If speedSound = 0.75 Then
		speedSound = 1
		L_Speed2.Text="1X"
	End If

	func.MinimomFontLabel(L_Speed2,17)

	ChangeSpeed(speedSound)
	
 
End Sub


Sub ChangeSpeed(s_speed As Float)
	Dim jo20 As JavaObject = player1
	jo20 = jo20.GetField("player")
	Dim PlaybackParameters As JavaObject
	Dim speed_f As Float = s_speed
	PlaybackParameters.InitializeNewInstance("com.google.android.exoplayer2.PlaybackParameters",Array(speed_f))
	jo20.RunMethod("setPlaybackParameters", Array(PlaybackParameters))
End Sub

Sub show_controller(bol_show As Boolean)
	Dim jo As JavaObject = SimpleExoPlayerView1
	If bol_show = True Then
		jo.RunMethod("showController", Null)
	Else
		jo.RunMethod("hideController", Null)
	End If
End Sub

#Region Preview
Sub Scrub_Event (MethodName As String, Args() As Object) As Object
	Select MethodName
		
		Case "onScrubMove"
			Dim position As Long = Args(1)
			p_preview.Visible = True
			Dim targetX As Int = updatePreviewX(position,player1.Duration)
			p_preview.Left = targetX
 
			lb_time.Visible = True
			lb_time.Text = func.ConvertMillisecondsToString(position)

		Case "onScrubStop"
			p_preview.Visible = False
 			
			lb_time.SetVisibleAnimated(500,False)
			
		Case "onScrubStart"
			
	End Select
	Return False
End Sub

Sub updatePreviewX(progress1 As Int, max1 As Int) As Int
	
	If max1 = 0 Then Return 0
	
	Dim offset As Float= progress1 / max1
	Dim minimumX As Float = 0
	Dim maximumX As Float = 100%x
	
	Dim previewLeftX As Float = 0
	Dim previewRightX As Float = 100%x
	Dim previewSeekBarStartX As Float = previewLeftX + 15dip + 70dip
	Dim previewSeekBarEndX As Float = previewRightX - 15dip
	
	Dim currentX  As Int = (previewSeekBarStartX + (previewSeekBarEndX - previewSeekBarStartX) * offset)
	
	Dim startX As Float = currentX - p_preview.width / 2
	Dim endX As Float = startX + p_preview.width
		
	If (startX >= minimumX And endX <= maximumX) Then
		Return startX
	else if (startX < minimumX) Then
		Return minimumX
	Else
		Return maximumX - p_preview.Width
	End If
	
End Sub

Sub GetRLSeekbarView(bol_left As Boolean) As Int 'ignore
	
	Dim asdasd As Canvas
	asdasd.Initialize(Activity)
	
	If bol_left = True Then
		Return asdasd.MeasureStringWidth(func.ConvertMillisecondsToString(player1.Position),Typeface.DEFAULT_BOLD,14) + 8dip
	Else
		Return asdasd.MeasureStringWidth(func.ConvertMillisecondsToString(player1.Duration),Typeface.DEFAULT_BOLD,14) + 8dip
	End If
	
End Sub
#End Region


#End Region

#Region lock

Sub lb_lock_Click
	
	show_controller(False)
	
	bol_lock = True
	
	lb_lock_release.Visible = True
	
	ActionBar.Visible = False
	lb_lock.Visible = False
	L_Speed2.Visible = False
	visLab(labDl,False)
	visLab(labShare,False)
	p_paly.Visible = False
	show_or_hide = False
	
	lb_lock_release.Top = lb_lock_release.Top - StatusBarHeight
	
End Sub
Sub lb_lock_release_Click
	
	show_controller(True)
	
	bol_lock = False
	
	lb_lock_release.Visible = False
	
	ActionBar.Visible = True
	lb_lock.Visible = True
	L_Speed2.Visible = True
	visLab(labDl,True)
	visLab(labShare,True)
	p_paly.Visible = True
	show_or_hide = True

	lb_lock_release.Top = lb_lock_release.Top + StatusBarHeight

End Sub

#End Region

 
#Region Gesture

Sub Gesture_onSingleTapConfirmed(X As Float, Y As Float, MotionEvent As Object)
	
	If bol_lock = True Then

		If show_or_hide = True Then
			lb_lock_release.Visible = True
			show_or_hide = False
		Else
			lb_lock_release.Visible = False
			show_or_hide = True
		End If

	Else
	
		If show_or_hide = True Then
			show_controller(False)
			ActionBar.Visible = False
			lb_lock.Visible = False
			L_Speed2.Visible = False
			visLab(labDl,False)
			visLab(labShare,False)
			show_or_hide = False
		Else
			show_controller(True)
			ActionBar.Visible = True
			lb_lock.Visible = True
			L_Speed2.Visible = True
			visLab(labDl,True)
			visLab(labShare,True)
			show_or_hide = True
		End If
	
	End If

End Sub
Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
				
	If bol_lock = False Then
	
		Select Action
		
			Case GD.ACTION_MOVE
				
				If bol_der_right_left = True Then
					If show_or_hide = False Then
						show_controller(True)
						ActionBar.Visible = True
						lb_lock.Visible = True
						L_Speed2.Visible = True
						visLab(labDl,True)
						visLab(labShare,True)
						show_or_hide = True
					End If
				End If
				
				If bol1 = True Then
					If bol_Volume = True Then
						lb_Volume.Visible = True
						p_Volume.Visible = True
					Else If bol_Brightness = True Then
						lb_Brightness.Visible = True
						p_Brightness.Visible = True
					Else If bol_der_right_left = True Then
						lb_time.Visible = True
					End If
				End If
			
			Case GD.ACTION_UP

				If bol1 = True Then
					
					bol1 = False
					
					bol_Volume = False
					bol_Brightness = False
					
					bol_der_right_left = False

					lb_Brightness.SetVisibleAnimated(500,False)
					lb_Volume.SetVisibleAnimated(500,False)
					p_Volume.SetVisibleAnimated(500,False)
					p_Brightness.SetVisibleAnimated(500,False)
					lb_time.SetVisibleAnimated(500,False)

				End If
				
		End Select
		
	End If

	Return True

End Sub
Sub Gesture_onScroll(distanceX As Float, distanceY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
	 
	If bol_lock = False Then
			
		Dim re1 As JavaObject = MotionEvent1
	
		Dim e1_getY As Float = re1.RunMethod("getY",Null) 'ignore
		Dim e1_getX As Float = re1.RunMethod("getX",Null)
	
		Dim e1_RawgetX As Float = re1.RunMethod("getRawX",Null)
		Dim e1_RawgetY As Float = re1.RunMethod("getRawY",Null)

		Dim re12 As JavaObject = MotionEvent2
	
		Dim e12_getY As Int = re12.RunMethod("getY",Null)
		Dim e12_getX As Float = re12.RunMethod("getX",Null) 'ignore
	
		Dim e12_RawgetX As Float = re12.RunMethod("getRawX",Null)
		Dim e12_RawgetY As Float = re12.RunMethod("getRawY",Null)

		Dim deltaX As Float = e1_RawgetX - e12_RawgetX 'ignore
		Dim deltaY As Float= e1_RawgetY - e12_RawgetY 'ignore
		
		If bol1 = False Then
			bol1 = True
			Select fromAngle(getAngle(e1_getX,e1_getY,e12_getX,e12_getY))
			
				Case "right"
					bol_der_right_left = True
				
				Case "left"
					bol_der_right_left = True
					
				Case "down"
					If e1_getX < 50%x Then
						bol_Volume = True
					Else
						bol_Brightness = True
					End If
					
				Case "up"
					If e1_getX < 50%x Then
						bol_Volume = True
					Else
						bol_Brightness = True
					End If
					
			End Select
		End If

					
		If bol_der_right_left = True Then
			If e12_getX > mLastScrollX Then
				Dim jo20 As JavaObject = player1
				jo20 = jo20.GetField("player")
				Dim position20 As Long = jo20.RunMethod("getCurrentPosition", Null)
				Dim seekto20 As Long = position20+1000
				If seekto20 > player1.Duration Then seekto20 = player1.Duration
				lb_time.Text = func.ConvertMillisecondsToString(seekto20)
				jo20.RunMethod("seekTo", Array(seekto20))
			Else
				Dim jo2 As JavaObject = player1
				jo2 = jo2.GetField("player")
				Dim position2 As Long = jo2.RunMethod("getCurrentPosition", Null)
				Dim seekto2 As Long = position2-1000
				If seekto2 < 0 Then seekto2 = 0
				lb_time.Text = func.ConvertMillisecondsToString(seekto2)
				jo2.RunMethod("seekTo", Array(seekto2))
			End If
			
		Else If bol_Volume = True Then
			If Abs(e12_getY - mLastScrollY) > 3 Then
				If e12_getY > mLastScrollY Then
					Volume = Max(Volume,0)
					Volume = Volume -1
					pho_Volume.SetVolume(pho_Volume.VOLUME_MUSIC,Max(Volume,0),False)
					lb_Volume.Text = func.gland(355)&" : "&Round((Max(Volume,0)*100)/15)&" %"
					DrawValue_Volume(Round((Max(Volume,0)*100)/15))
				Else
					Volume = Min(Volume,15)
					Volume = Volume +1
					pho_Volume.SetVolume(pho_Volume.VOLUME_MUSIC,Min(Volume,15),False)
					lb_Volume.Text = func.gland(355)&" : "&Round((Min(Volume,15)*100)/15)&" %"
					DrawValue_Volume(Round((Min(Volume,15)*100)/15))
				End If
			End If
								
		Else If bol_Brightness = True Then
			If Abs(e12_getY - mLastScrollY) > 3 Then
				If e12_getY > mLastScrollY Then
					Brightness = Max(Brightness,0)
					Brightness = Brightness - 10
					screenBrightness(Max(Brightness,0))
					lb_Brightness.Text = func.gland(354)&" : "&Round((Max(Brightness,0)*100)/250)&" %"
					DrawValue_Brightness(Round((Max(Brightness,0)*100)/250))
				Else
					Brightness = Min(Brightness,250)
					Brightness = Brightness + 10
					screenBrightness(Min(Brightness,250))
					lb_Brightness.Text = func.gland(354)&" : "&Round((Min(Brightness,250)*100)/250)&" %"
					DrawValue_Brightness(Round((Min(Brightness,250)*100)/250))
				End If
			End If

		End If
				
		mLastScrollY = e12_getY
		mLastScrollX = e12_getX
								
	End If

End Sub
Sub Gesture_onDoubleTap(X As Float, Y As Float, MotionEvent As Object)
	
	If bol_lock = False Then
								
		If show_or_hide = False Then
			show_controller(True)
			ActionBar.Visible = True
			lb_lock.Visible = True
			L_Speed2.Visible = True
			visLab(labDl,True)
			visLab(labShare,True)
			show_or_hide = True
		End If
	
		lb_time.Visible = True
		
		Dim re1 As JavaObject = MotionEvent
		Dim e1_getX As Float = re1.RunMethod("getX",Null)
	
		If e1_getX > 70%x Then
			p_next_dubble.Visible = True

			Dim jo20 As JavaObject = player1
			jo20 = jo20.GetField("player")
			Dim position20 As Long = jo20.RunMethod("getCurrentPosition", Null)
			Dim seekto20 As Long = position20+10000
			If seekto20 > player1.Duration Then seekto20 = player1.Duration
			lb_time.Text = func.ConvertMillisecondsToString(seekto20)
			jo20.RunMethod("seekTo", Array(seekto20))
			
			img_next_dubble1.SetVisibleAnimated(200,False)
			Sleep(50)
			img_next_dubble12.SetVisibleAnimated(200,False)
			Sleep(50)
			img_next_dubble13.SetVisibleAnimated(200,False)
			Sleep(50)
			img_next_dubble1.SetVisibleAnimated(200,True)
			Sleep(50)
			img_next_dubble12.SetVisibleAnimated(200,True)
			Sleep(50)
			img_next_dubble13.SetVisibleAnimated(200,True)
			Sleep(50)
			img_next_dubble1.SetVisibleAnimated(200,False)
			Sleep(50)
			img_next_dubble12.SetVisibleAnimated(200,False)
			Sleep(50)
			img_next_dubble13.SetVisibleAnimated(200,False)
			 
		Else If e1_getX < 30%x Then
			p_back_dubble.Visible = True

			Dim jo2 As JavaObject = player1
			jo2 = jo2.GetField("player")
			Dim position2 As Long = jo2.RunMethod("getCurrentPosition", Null)
			Dim seekto2 As Long = position2-10000
			If seekto2 < 0 Then seekto2 = 0
			lb_time.Text = func.ConvertMillisecondsToString(seekto2)
			jo2.RunMethod("seekTo", Array(seekto2))


			img_back_dubble1.SetVisibleAnimated(200,False)
			Sleep(50)
			img_back_dubble12.SetVisibleAnimated(200,False)
			Sleep(50)
			img_back_dubble13.SetVisibleAnimated(200,False)
			Sleep(50)
			img_back_dubble1.SetVisibleAnimated(200,True)
			Sleep(50)
			img_back_dubble12.SetVisibleAnimated(200,True)
			Sleep(50)
			img_back_dubble13.SetVisibleAnimated(200,True)
			Sleep(50)
			img_back_dubble1.SetVisibleAnimated(200,False)
			Sleep(50)
			img_back_dubble12.SetVisibleAnimated(200,False)
			Sleep(50)
			img_back_dubble13.SetVisibleAnimated(200,False)

		End If
		
		If doubleTapDelay.Enabled = True Then
			doubleTapDelay.Enabled = False
		End If
		doubleTapDelay.Enabled = True
		
	End If

End Sub
Sub doubleTapDelay_Tick
	p_next_dubble.Visible = False
	p_back_dubble.Visible = False
	doubleTapDelay.Enabled = False
	lb_time.SetVisibleAnimated(500,False)
End Sub

Sub getAngle(x19 As Float,y19 As Float,x29 As Float,y29 As Float) As Double
	Dim rad = ATan2(y19-y29,x29-x19) + 3.1415 As Double
	Return (rad*180/3.1415 + 180)Mod 360
End Sub
Sub inRange (angle As Double,init As Float,end11 As Float) As Boolean
	If (angle >= init) Then
		If (angle < end11) Then
			Return True
		Else
			Return False
		End If
	Else
		Return False
	End If
End Sub
'* Up: [45, 135]
'* Right: [0,45] And [315, 360]
'* Down: [225, 315]
'* Left: [135, 225]
Sub fromAngle(angle As Double) As String
	If (inRange(angle, 45, 135)) Then
		Return "up"
	else if(inRange(angle, 225, 315)) Then
		Return "down"
	else if(inRange(angle, 135, 225)) Then
		Return "left"
	else if(inRange(angle, 0,45) Or inRange(angle, 315, 360))Then
		Return "right"
	Else
		Return "Null"
	End If
End Sub

#End Region

#Region OtherFunction
Sub screenBrightness(brightnessInt As Float)
	p_setBrightness.SetScreenBrightness(brightnessInt/250)
End Sub

Sub show_navication(bol_show As Boolean,bol_img As Boolean)
	'SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096 (0x01000)
	'SYSTEM_UI_FLAG_IMMERSIVE = 2048 (0x0800)
	'SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024 (0x0400)
	'SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512 (0x0200)
	'SYSTEM_UI_FLAG_LAYOUT_STABLE = 256 (0x0100)
	'SYSTEM_UI_FLAG_FULLSCREEN = 4 (0x04)
	'SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2 (0x02)
	'SYSTEM_UI_FLAG_TRANSLUCENT_STATUS = 67108864 (0x04000000)
	'SYSTEM_UI_FLAG_TRANSLUCENT_NAVIGATION = 134217728 (0x08000000)
	Dim jo4 As JavaObject = Activity
	If bol_show = True Then
		jo4.RunMethod("setSystemUiVisibility", Array As Object(1280))
		If bol_img = True Then
			img_logo.Top = 18dip
			img_logo.Top = img_logo.Top + StatusBarHeight
		Else
			img_logo.Top = img_logo.Top
		End If
 	Else
		jo4.RunMethod("setSystemUiVisibility", Array As Object(5894))
		img_logo.Top = img_logo.Top - StatusBarHeight
 	End If
	
End Sub

Sub TransparentNavigationBar
	If pho_Volume.SdkVersion >= 21 Then
'	Dim context As JavaObject
'	context.InitializeContext
'	Dim window As JavaObject = context.RunMethod("getWindow", Null)
'	window.RunMethod("addFlags", Array(0x80000000)) 'FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
'	window.RunMethod("addFlags", Array(0x00000200)) 'FLAG_LAYOUT_NO_LIMITS
'	Activity.Height = GetDeviceLayoutValues.Height + 48dip
		Dim jo As JavaObject
		jo.InitializeContext
		jo.RunMethodJO("getWindow", Null).RunMethodJO("getDecorView", Null).RunMethod("setLayoutDirection", Array(1))
		Dim window As JavaObject = jo.RunMethod("getWindow", Null)
		window.RunMethod("addFlags", Array(0x08000000))
		jo.RunMethodJO("getWindow", Null).RunMethod("setNavigationBarColor", Array(Colors.Transparent))
	End If
End Sub

Sub StatusBarHeight As Int
	Dim ac As AppCompat
	Return ac.GetStatusBarHeight
End Sub
#End Region

Sub timer_play_time_Tick
	If SimpleExoPlayerView1.IsInitialized Then
		If player1.IsPlaying Then
			int_play_time = int_play_time + 1
		End If
	End If
End Sub

#Region close
Sub exit_ppplayer(save_ppotion As Boolean)
	If doubleTapDelay.IsInitialized And doubleTapDelay.Enabled Then doubleTapDelay.Enabled = False
	If timer_play_time.IsInitialized And timer_play_time.Enabled Then timer_play_time.Enabled = False
	player1.Pause
	player1.Release
	
	Activity.Finish
	
 
End Sub
Sub lb_close_Click
	If bol_lock = False Then
		exit_ppplayer(True)
	End If
End Sub

Sub labDl_Click
	
	If File.Exists(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4") Then
		func.ToastERROR(func.gland(250))
	Else
		
		func.savePFM("onvanDS",sName)

		player1.Pause
		If img_pause.IsInitialized And img_play.IsInitialized Then
			img_pause.Visible = False
			img_play.Visible = True
		End If
 		
	End If
End Sub
  
Sub download_pakhsh
	
	labDl.Typeface = Typeface.MATERIALICONS
 	labDl.Text = Chr(0xE5CA)
 
'	Show_Film1
	
End Sub
	
Sub labShare_Click
	
	player1.Pause
	If img_pause.IsInitialized And img_play.IsInitialized Then
		img_pause.Visible = False
		img_play.Visible = True
	End If
	
 	Dim Builder As MaterialDialogBuilder
	Builder.Initialize("Dialog_type")

	Builder.Title(func.gland(11))
	Builder.Items(Array As String(func.gland(12), func.gland(13)))
	Builder.Typeface(Typeface.LoadFromAssets(func.font3),Typeface.LoadFromAssets(func.font3))
	Builder.ItemsCallback
	Builder.ItemsGravity(Builder.GRAVITY_START)
	Builder.ItemsGravity(Builder.GRAVITY_START)
	Builder.Show
  
End Sub

Sub Dialog_type_ItemSelected (Dialog As MaterialDialog, Position As Int, Text As String)

	If Position = 0 Then
 		shareFiles
	Else
		shareLinks
	End If
	
End Sub

Sub shareLinks

 	Dim Smatn  As String = func.gland(331)&CRLF&CRLF& func.setThing000(func.readPFM("titleDs"),"Ꞅ")
	Dim smatn2 As String = CRLF&CRLF&"https://anvarvahy.com/appref?day="&func.readPFM("idDs")&"&types="&func.readPFM("typeDs")
 
	func.TextShare(func.PersianNumbers("‌"&CRLF&Smatn)&smatn2)
 
End Sub
  
  
Sub shareFiles
  	
	If File.Exists(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4") Then
		ShareMultipleFiles
	Else
		func.ToastERROR(func.gland(338))
	End If

End Sub

  
Sub ShareMultipleFiles
 
	Try
		File.copy(func.choose2DIR,"anvarvahy2/sokhan_roz/"&idDs&"-"&sName&".mp4", Starter.Provider.SharedFolder, idDs&"-"&sName&".mp4")
	
		Dim in As Intent
		in.Initialize(in.ACTION_SEND, "")
		in.SetType("text/plain")
		in.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(idDs&"-"&sName&".mp4"))
		in.Flags = 1
		StartActivity(in)
	Catch
		Log(LastException)
	End Try
  
End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean
			
	If KeyCode = KeyCodes.KEYCODE_BACK Then
				
		If bol_lock = False Then
			exit_ppplayer(True)
		End If
 		
	else If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Or KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
		
		If bol_lock = False Then

			Volume = pho_Volume.GetVolume(pho_Volume.VOLUME_MUSIC)
		
			lb_Volume.Text =func.gland(355)&" : "&Round((Volume*100)/15)&" %"

			DrawValue_Volume(Round((Volume*100)/15))
		
			p_Volume.Visible = True
			lb_Volume.Visible = True
				
		End If
		
		Return False
		
	End If
	
	Return True
	
End Sub
Sub Activity_KeyUp (KeyCode As Int) As Boolean 
	If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Or KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
		p_Volume.SetVisibleAnimated(500,False)
		lb_Volume.SetVisibleAnimated(500,False)
	End If
	Return True
End Sub
#End Region

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
	
	If SimpleExoPlayerView1.IsInitialized And player1.Position > 0 Then
		player1.Pause
		If img_pause.IsInitialized And img_play.IsInitialized Then
			img_pause.Visible = False
			img_play.Visible = True
		End If
	End If

	If UserClosed Then
		wake.ReleaseKeepAlive
	End If

End Sub
 