@ -333,29 +333,8 @@ class ScreenCaptureService : Service() {
return
return
}
}
// Initialize long screenshot system with shared MediaProjection
// Long screenshot system will be initialized lazily when first used
val screenDimensions = screenCaptureManager . getScreenDimensions ( )
PGHLog . d ( TAG , " 📸 Long screenshot system prepared for lazy initialization " )
val mediaProjection = screenCaptureManager . getMediaProjection ( )
val screenDensity = screenCaptureManager . getScreenDensity ( )
if ( screenDimensions != null && mediaProjection != null ) {
val ( screenWidth , screenHeight ) = screenDimensions
longScreenshotCapture = LongScreenshotCapture ( this , handler )
// Initialize with the shared MediaProjection
val initialized = longScreenshotCapture !! . initialize (
mediaProjection , screenWidth , screenHeight , screenDensity
)
if ( initialized ) {
PGHLog . i ( TAG , " ✅ Long screenshot system initialized successfully " )
} else {
PGHLog . e ( TAG , " ❌ Failed to initialize long screenshot system " )
longScreenshotCapture = null
}
} else {
PGHLog . w ( TAG , " ⚠️ Cannot initialize long screenshot - missing MediaProjection or screen dimensions " )
}
PGHLog . d ( TAG , " Screen capture setup complete " )
PGHLog . d ( TAG , " Screen capture setup complete " )
// Show floating overlay
// Show floating overlay
@ -1249,6 +1228,12 @@ class ScreenCaptureService : Service() {
{
{
PGHLog . i ( TAG , " 🚀 Starting long screenshot collection " )
PGHLog . i ( TAG , " 🚀 Starting long screenshot collection " )
// Try to initialize if not already done
if ( longScreenshotCapture == null ) {
PGHLog . i ( TAG , " 🔧 Long screenshot not initialized, attempting to initialize now... " )
initializeLongScreenshotSystem ( )
}
longScreenshotCapture ?. let { capture ->
longScreenshotCapture ?. let { capture ->
// Set up callbacks
// Set up callbacks
capture . setProgressCallback { count ->
capture . setProgressCallback { count ->
@ -1275,7 +1260,7 @@ class ScreenCaptureService : Service() {
PGHLog . i ( TAG , " ✅ Long screenshot collection started successfully " )
PGHLog . i ( TAG , " ✅ Long screenshot collection started successfully " )
}
}
} ?: run {
} ?: run {
PGHLog . e ( TAG , " ❌ Long screenshot system not initialized " )
PGHLog . e ( TAG , " ❌ Long screenshot system could not be initialized " )
enhancedFloatingFAB ?. exitLongScreenshotModeExternal ( )
enhancedFloatingFAB ?. exitLongScreenshotModeExternal ( )
}
}
@ -1287,6 +1272,46 @@ class ScreenCaptureService : Service() {
}
}
}
}
private fun initializeLongScreenshotSystem ( )
{
try
{
PGHLog . d ( TAG , " 🔧 Initializing long screenshot system... " )
val screenDimensions = screenCaptureManager . getScreenDimensions ( )
val mediaProjection = screenCaptureManager . getMediaProjection ( )
val screenDensity = screenCaptureManager . getScreenDensity ( )
PGHLog . d ( TAG , " 🔍 Long screenshot init check - dimensions= $screenDimensions , mediaProjection= $mediaProjection , density= $screenDensity " )
if ( screenDimensions != null && mediaProjection != null ) {
val ( screenWidth , screenHeight ) = screenDimensions
PGHLog . d ( TAG , " 🔧 Creating LongScreenshotCapture instance... " )
longScreenshotCapture = LongScreenshotCapture ( this , handler )
// Initialize with the shared MediaProjection
PGHLog . d ( TAG , " 🔧 Initializing with MediaProjection: ${screenWidth} x ${screenHeight} , density= $screenDensity " )
val initialized = longScreenshotCapture !! . initialize (
mediaProjection , screenWidth , screenHeight , screenDensity
)
if ( initialized ) {
PGHLog . i ( TAG , " ✅ Long screenshot system initialized successfully " )
} else {
PGHLog . e ( TAG , " ❌ Failed to initialize long screenshot system " )
longScreenshotCapture = null
}
} else {
PGHLog . w ( TAG , " ⚠️ Cannot initialize long screenshot - missing MediaProjection ( $mediaProjection ) or screen dimensions ( $screenDimensions ) " )
}
}
catch ( e : Exception )
{
PGHLog . e ( TAG , " ❌ Error initializing long screenshot system " , e )
longScreenshotCapture = null
}
}
private fun captureLongScreenshot ( )
private fun captureLongScreenshot ( )
{
{
try
try