How etcparking/screencapture works
1. The “app” module, which is a sample Android application demonstrating how to integrate and use the ScreenCapture library.
2. The “screencapture” module, which contains the core library code (including classes like ScreenCapture, VideoComposer, and associated Android utility classes).
Main Components
• Sample Application (app module): Represents the consumer or demonstration of the library. It includes the Android UI and activities (e.g., MainActivity) where the ScreenCapture API is instantiated and used.
• ScreenCapture Library Module (screencapture): Houses the core classes that actualize functionalities like screen capture, screen recording, and event handling.
• VideoComposer Component: A specialized part of the library for joining video files, which depends on specific video/audio encoding parameters.
• Android Framework & External Services: Components such as MediaProjection, permission and activity lifecycle callbacks (onActivityResult, onRequestPermissionsResult), and file system storage for saving screens captures and recordings.
Relationships and Interactions
• The Sample Application interacts with the ScreenCapture library API by:
• Creating an instance (via newInstance(this)).
• Setting up event listeners to receive callbacks on successful or failed operation (for both capture and recording).
• Handling Android permissions and lifecycle events to forward them to the library (e.g., onActivityResult for MediaProjection permissions).
• The ScreenCapture library internally uses Android’s MediaProjection API to trigger the actual screen capture/recording.
• The library manages file I/O to save images and videos and interacts with external storage paths as configured by the client.
• The VideoComposer gets fed a list of video files (ensuring matching encoding conditions) and outputs a composed (merged) video.
Important Architectural Patterns and Design Principles
• Modularity: The clear separation between the sample application (client side) and the library itself clarifies responsibilities – the app only handles UI and permission logic, whereas the library encapsulates the actual media handling.
• Callback/Listener Pattern: The library uses listener interfaces (e.g., OnCaptureListener) to notify the application about events such as success or failure, ensuring loose coupling.
• Lifecycle Integration: Hooks into Android’s activity lifecycle (e.g., onDestroy, onActivityResult) are managed to ensure the library cleans up resources properly.
• Abstraction and Reusability: Exposing a simple API (like the newInstance() method) and relying on configuration via setter methods (e.g., to set image/video save paths) encourages reusability in varied Android contexts.
Relevant Technologies, Frameworks, or Libraries
• Android Framework (Activities, Permissions, MediaProjection).
• Gradle Build System (as seen in the build.gradle files at the root and module levels).
• Java for Android (as indicated by the source files and package structure, e.g., com.shark.screencapture).
• Standard Android UI elements (such as the layout defined in activity_main.xml) for the sample app.
• Media codecs and file I/O for processing video and images.
Elements
• How the app initiates a screen capture or recording.
• Event flow from MediaProjection API (invoked by the library) leading to image/video file storage.
• Use of callbacks in notifying the app about results (success or failure).
• The composition process where VideoComposer compiles multiple videos into one output file.
• Left: “Sample Application” block (showing UI layer and MainActivity).
• Right: “ScreenCapture Library” block (containing subcomponents for capture/record, video composition, and utility classes).
• Below or alongside these, include a block for “Android Framework & External Services” (showing MediaProjection API, Storage APIs, and Permission Management).
• Instantiation (newInstance)
• Setting listener callbacks (e.g., setCaptureListener)
• Event forwarding (onActivityResult, onRequestPermissionsResult)
• Invocation of functions (screenCapture() and record())
• Within the “ScreenCapture Library” block, visually separate:
• The screen capture/recording functionality that interacts with MediaProjection.
• The VideoComposer portion for merging videos.
• Use annotations to highlight critical points such as cleanup operations and configuration of file storage paths.
• Every component is clearly labeled and that data flow directions (requests, responses, event notifications) are explicitly indicated.