1818 along with wX. If not, see <http://www.gnu.org/licenses/>.
1919
2020 */
21- // Modded by ELY M.
2221
2322package joshuatee.wx.radar
2423
25- import android.Manifest
26- import android.app.Activity
27- import android.content.Context
2824import android.content.Intent
2925import android.content.pm.PackageManager
30- import android.media.projection.MediaProjectionManager
3126import android.net.Uri
32- import android.os.Build
3327import android.os.Bundle
3428import android.provider.Settings
35- import androidx.core.app.ActivityCompat
3629import androidx.appcompat.app.AppCompatActivity
3730import androidx.appcompat.widget.Toolbar
3831import joshuatee.wx.R
@@ -45,8 +38,6 @@ import joshuatee.wx.util.UtilityLog
4538abstract class VideoRecordActivity : AppCompatActivity () {
4639
4740 companion object {
48- private const val CREATE_SCREEN_CAPTURE = 4242
49-
5041 /* * code to post/handler request for permission */
5142 private const val REQUEST_CODE_PERM = 999
5243 }
@@ -56,6 +47,7 @@ abstract class VideoRecordActivity : AppCompatActivity() {
5647 lateinit var toolbarBottom: Toolbar
5748 lateinit var objectToolbar: ObjectToolbar
5849 lateinit var objectToolbarBottom: ObjectToolbar
50+ private lateinit var telecineService: TelecineService
5951
6052 protected fun onCreate (savedInstanceState : Bundle ? , layoutResId : Int , menuResId : Int? , bottomToolbar : Boolean ) {
6153 setTheme(UIPreferences .themeInt)
@@ -90,96 +82,38 @@ abstract class VideoRecordActivity : AppCompatActivity() {
9082 }
9183
9284 protected fun checkOverlayPerms () {
93- UtilityLog .d(" wx" , " checkOverlayPerms start" )
94- if (isStoragePermissionGranted) {
95- UtilityLog .d(" wx" , " checkOverlayPerms start, storage granted" )
96- checkDrawOverlayPermission()
97- } else {
98- UtilityLog .d(" wx" , " checkOverlayPerms start, storage not granted" )
99- }
100- }
101-
102- private fun fireScreenCaptureIntent () {
103- val manager = getSystemService(Context .MEDIA_PROJECTION_SERVICE ) as MediaProjectionManager
104- val intent = manager.createScreenCaptureIntent()
105- startActivityForResult(intent, CREATE_SCREEN_CAPTURE )
85+ checkDrawOverlayPermission()
10686 }
10787
10888 override fun onActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
10989 if (requestCode == REQUEST_CODE_PERM ) {
11090 if (Settings .canDrawOverlays(this )) {
111- fireScreenCaptureIntent()
112- }
113- }
114- if (requestCode == CREATE_SCREEN_CAPTURE && resultCode == Activity .RESULT_OK ) {
115- if (Build .VERSION .SDK_INT > 31 ) { // was 32, Android 12L is showing in crash reports
116- val intent = TelecineService .newIntent(this , 1 , Intent ())
117- intent.putExtra(" show_distance_tool" , showDistanceTool)
118- intent.putExtra(" show_recording_tools" , " false" )
119- startService(intent)
120- } else {
121- val intent = TelecineService .newIntent(applicationContext, resultCode, data)
122- intent.putExtra(" show_distance_tool" , showDistanceTool)
123- intent.putExtra(" show_recording_tools" , " true" )
124- startService(intent)
91+ telecineService = TelecineService ()
92+ telecineService.start(this )
12593 }
126- // draw tools only?
127- // val intent = TelecineService.newIntent(this, 1, Intent())
128- // intent.putExtra("show_distance_tool", showDistanceTool)
129- // intent.putExtra("show_recording_tools", "false")
130- // startService(intent)
13194 }
13295 }
13396
13497 private fun checkDrawOverlayPermission () {
135- /* * check if we already have permission to draw over other apps */
13698 if (! Settings .canDrawOverlays(this )) {
13799 UtilityLog .d(" wx" , " checkDrawOverlayPermission - perm check" )
138- /* * if not construct intent to request permission */
139100 val intent = Intent (Settings .ACTION_MANAGE_OVERLAY_PERMISSION , Uri .parse(" package:$packageName " ))
140- /* * request permission via start activity for result */
141101 startActivityForResult(intent, REQUEST_CODE_PERM )
142102 } else {
143- UtilityLog .d( " wx " , " checkDrawOverlayPermission - fireScreenCaptureIntent " )
144- fireScreenCaptureIntent( )
103+ telecineService = TelecineService ( )
104+ telecineService.start( this )
145105 }
146106 }
147107
148- private val isStoragePermissionGranted: Boolean
149- get() {
150- if (Build .VERSION .SDK_INT >= 33 ) {
151- return true
152- }
153- return if (checkSelfPermission(Manifest .permission.WRITE_EXTERNAL_STORAGE ) == PackageManager .PERMISSION_GRANTED ) {
154- true
155- } else {
156- ActivityCompat .requestPermissions(this , arrayOf(Manifest .permission.WRITE_EXTERNAL_STORAGE ), 1 )
157- false
158- }
159- }
160-
161- // private val isStoragePermissionGranted: Boolean
162- // get() {
163- // return if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
164- // true
165- // } else {
166- // ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
167- // false
168- // }
169- // }
170-
171108 // https://developer.android.com/training/permissions/requesting.html
172-
173109 override fun onRequestPermissionsResult (requestCode : Int , permissions : Array <String >, grantResults : IntArray ) {
174110 when (requestCode) {
175111 1 -> {
176112 // If request is cancelled, the result arrays are empty.
177113 if (grantResults.isNotEmpty() && grantResults[0 ] == PackageManager .PERMISSION_GRANTED ) {
178114 checkDrawOverlayPermission()
179- // permission was granted, yay! Do the
180- // contacts-related task you need to do.
181115 }
182116 }
183- }// other 'case' lines to check for other
117+ }
184118 }
185119}
0 commit comments