### Permissions and Setup Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Guides users through integrating and setting up the EasyWindow framework, covering Gradle dependency setup, permission handling, API level compatibility, troubleshooting, and performance optimization. ```APIDOC ## Permissions and Setup Guide ### Description Provides instructions for integrating and configuring the EasyWindow framework, including dependency setup, permission requirements, and optimization tips. ### Sections - Gradle dependency setup - Required permissions - API level compatibility information - Troubleshooting common issues - Performance optimization strategies ``` -------------------------------- ### Quick Start Examples Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Contains over 20 practical code examples demonstrating common use cases, best practices, and usage patterns for the EasyWindow framework. ```APIDOC ## Quick Start Examples ### Description Offers 20+ runnable code examples illustrating common use cases, best practices, and practical usage patterns for the EasyWindow framework. ### Content - Window creation scenarios - Lifecycle management examples - View interaction demonstrations - Drag and animation usage - Multi-window management patterns ``` -------------------------------- ### Complete Example: Draggable Window with Spring-Back Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md An example demonstrating how to create a draggable window with horizontal spring-back behavior. It includes setting content, size, location, drag rules, click listeners, and lifecycle callbacks. ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create a spring-back draggable window EasyWindow.with(this) .setContentView(R.layout.floating_window) .setWindowSize(200, 200) .setWindowLocation(Gravity.CENTER, 0, 0) // Enable spring-back to left/right edges .setWindowDraggableRule(new SpringBackWindowDraggableRule( SpringBackWindowDraggableRule.ORIENTATION_HORIZONTAL)) // Monitor drag events .setOnClickListenerByView(R.id.content, (window, view) -> { Toast.makeText(MainActivity.this, "Content clicked", Toast.LENGTH_SHORT).show(); }) // Monitor lifecycle .setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() { @Override public void onWindowShow(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Draggable window displayed"); } }) .show(); } } ``` -------------------------------- ### Handle EasyWindow Lifecycle Callbacks Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Implement OnWindowLifecycleCallback to perform setup when a window is shown or cleanup when it is recycled. ```java easyWindow.setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() { @Override public void onWindowShow(@NonNull EasyWindow easyWindow) { // Setup when shown } @Override public void onWindowRecycle(@NonNull EasyWindow easyWindow) { // Cleanup when recycled } }); ``` -------------------------------- ### EasyWindow Listener Setup Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Methods for setting click, long-click, touch, and key listeners for EasyWindow instances. Listeners can be set on the root layout or specific views by their ID. ```APIDOC ## EasyWindow Listener Methods ### Description Methods to set various listeners for EasyWindow instances. Listeners can be applied to the entire window or specific views within it. ### Methods - `setOnClickListener(@Nullable OnWindowViewClickListener listener)`: Sets a click listener for the root layout. - `setOnClickListenerByView(@IdRes int id, @Nullable OnWindowViewClickListener listener)`: Sets a click listener for a specific view identified by its ID. - `setOnLongClickListener(@Nullable OnWindowViewLongClickListener listener)`: Sets a long-click listener for the root layout. - `setOnLongClickListenerByView(@IdRes int id, @Nullable OnWindowViewLongClickListener listener)`: Sets a long-click listener for a specific view identified by its ID. - `setOnTouchListener(@Nullable OnWindowViewTouchListener listener)`: Sets a touch listener for the root layout. - `setOnTouchListenerByView(@IdRes int id, @Nullable OnWindowViewTouchListener listener)`: Sets a touch listener for a specific view identified by its ID. - `setOnKeyListener(@Nullable OnWindowViewKeyListener listener)`: Sets a key listener for the root layout. - `setOnKeyListenerByView(@IdRes int id, @Nullable OnWindowViewKeyListener listener)`: Sets a key listener for a specific view identified by its ID. ``` -------------------------------- ### Launch Activity with EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Start a new Activity using either a Class reference or an Intent object. This is useful for navigating to other screens from the EasyWindow. ```java easyWindow.startActivity(@Nullable Class clazz); easyWindow.startActivity(@Nullable Intent intent); ``` -------------------------------- ### EasyWindow Activity and Task Management Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Methods for launching activities and managing tasks within the EasyWindow context. This includes starting activities via Class or Intent, posting, delaying, and canceling tasks. ```APIDOC ## EasyWindow Activity and Task Methods ### Description Provides functionality to launch activities and manage background tasks associated with an EasyWindow. ### Methods - `startActivity(@Nullable Class clazz)`: Launches an Activity using its Class object. - `startActivity(@Nullable Intent intent)`: Launches an Activity using an Intent object. - `sendTask(Runnable runnable)`: Posts a Runnable task to be executed. - `sendTask(@NonNull Runnable runnable, long delayMillis)`: Posts a Runnable task to be executed after a specified delay. - `cancelTask(@NonNull Runnable runnable)`: Cancels a specific previously posted task. - `cancelAllTask()`: Cancels all currently posted tasks. ``` -------------------------------- ### Java: OnWindowViewClickListener Lambda Example Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md A concise way to handle click events on specific views within an EasyWindow using lambda expressions (requires Android 7.0+). This example cancels the window on click. ```java easyWindow.setOnClickListenerByView(R.id.action_button, (window, view) -> window.cancel()); ``` -------------------------------- ### Start Activity by Class Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Launches a new Activity specified by its class from the current floating window context. This method is part of the activity navigation utilities and supports chaining. ```java public X startActivity(@Nullable Class clazz) ``` -------------------------------- ### Start Activity by Intent Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Launches a new Activity using an explicit Intent object from the floating window context. This provides more control over the activity launch parameters. Chaining is supported. ```java public X startActivity(@Nullable Intent intent) ``` -------------------------------- ### Create Local Floating Window (Kotlin - chained) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md A chained Kotlin example for creating a local floating window associated with an Activity. It does not require overlay permission. Set the content view, duration, and define click actions. ```kotlin EasyWindow.with(activity) .setContentView(R.layout.toast_hint) // Make the window draggable //.setWindowDraggableRule() // Set display duration .setWindowDuration(1000) // Set animation style //.setWindowAnim(android.R.style.Animation_Translucent) // Whether the outside area can be touched //.setOutsideTouchable(false) // Set background dim amount //.setBackgroundDimAmount(0.5f) .setImageDrawableByImageView(android.R.id.icon, R.mipmap.ic_dialog_tip_finish) .setTextByTextView(android.R.id.message, "Tap me to dismiss") .setOnClickListenerByView(android.R.id.message, OnWindowViewClickListener { easyWindow: EasyWindow<*>, view: TextView -> easyWindow.cancel() // Navigate to a specific Activity // easyWindow.startActivity(intent) }) .show() ``` -------------------------------- ### Combine Multiple EasyWindow Callbacks Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Chain multiple callbacks when creating an EasyWindow to manage its lifecycle, respond to screen rotations, and handle view interactions. This example demonstrates setting up listeners for window show/cancel events, screen rotation, and button clicks. ```java EasyWindow.with(activity) .setContentView(R.layout.window_layout) // Lifecycle monitoring .setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() { @Override public void onWindowShow(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Window shown"); } @Override public void onWindowCancel(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Window hidden"); } }) // Rotation handling .setOnWindowScreenRotationCallback(new OnWindowScreenRotationCallback() { @Override public void onWindowScreenRotationAfter(@NonNull EasyWindow easyWindow, int screenOrientation) { Log.d("EasyWindow", "Screen rotated"); } }) // View interaction .setOnClickListenerByView(R.id.button, (window, view) -> { window.cancel(); }) .show(); ``` -------------------------------- ### Get All Window Instances Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Obtain a list of all currently registered window instances, irrespective of their visibility or state. Useful for auditing or global operations. ```java public static synchronized List> getAllWindowInstances() ``` ```java List> allWindows = EasyWindowManager.getAllWindowInstances(); System.out.println("Total windows: " + allWindows.size()); ``` -------------------------------- ### Implement Custom Drag Rule Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Implement `IWindowDraggableRule` to define custom drag behavior. This example shows how to track touch movement and update the window's position. ```java public class CustomDraggableRule extends BaseWindowDraggableRule { private float mDownX, mDownY; private boolean mIsTouching = false; @Override public boolean isTouchMoving() { return mIsTouching; } @Override public boolean onDragWindow(@NonNull EasyWindow easyWindow, @NonNull ViewGroup rootLayout, @NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownX = event.getRawX(); mDownY = event.getRawY(); mIsTouching = false; break; case MotionEvent.ACTION_MOVE: float moveX = event.getRawX() - mDownX; float moveY = event.getRawY() - mDownY; if (Math.abs(moveX) > 5 || Math.abs(moveY) > 5) { mIsTouching = true; // Update window position updateLocation((int) moveX, (int) moveY, true); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsTouching = false; break; } return mIsTouching; } } ``` -------------------------------- ### Create Custom Window Subclass in Java Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/07-module-structure.md Extend EasyWindow to create domain-specific window types. This example shows a NotificationWindow with a custom setMessage method. ```java public class NotificationWindow extends EasyWindow { public NotificationWindow(@NonNull Activity activity) { super(activity); } public NotificationWindow setMessage(String msg) { setTextByTextView(R.id.message, msg); return this; } } ``` -------------------------------- ### Java: OnWindowLayoutInflateListener Example Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Implement this listener to execute code after a window's layout has been inflated. Access and manipulate inflated views within the callback. ```java EasyWindow.with(activity) .setContentView(R.layout.floating_window, (window, view, layoutId, parent) -> { // Access views after inflation TextView textView = view.findViewById(R.id.my_text); textView.setText("Window inflated!"); // Set up listeners on inflated views Button button = view.findViewById(R.id.my_button); button.setOnClickListener(v -> { // Button clicked }); }) .show(); ``` -------------------------------- ### OnSpringBackAnimCallback Methods Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Callback methods for monitoring spring-back animation events. Use these to track the animation's start and end, including start and end coordinates. ```java default void onSpringBackAnimStart(int fromX, int fromY, int toX, int toY) default void onSpringBackAnimEnd(int x, int y) ``` -------------------------------- ### Java: OnWindowViewClickListener Anonymous Class Example Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Use this to handle click events on specific views within an EasyWindow using an anonymous inner class. This example shows how to close the window when a close button is clicked. ```java easyWindow.setOnClickListenerByView(R.id.close_button, new OnWindowViewClickListener() { @Override public void onClick(@NonNull EasyWindow easyWindow, @NonNull ImageView view) { Log.d("EasyWindow", "Close button clicked"); easyWindow.cancel(); } }); ``` -------------------------------- ### Set Bitmap Format Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Sets the bitmap pixel format. For example, `PixelFormat.TRANSLUCENT` can be used. ```java public X setBitmapFormat(int format) ``` -------------------------------- ### startActivity Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Launches an Activity from the context of the floating window. Can be launched using a Class or an Intent. ```APIDOC ## startActivity ### Description Launches an Activity from the floating window context. ### Method Signatures ```java public X startActivity(@Nullable Class clazz) public X startActivity(@Nullable Intent intent) ``` ### Parameters * `clazz` (@Nullable Class) - The Activity class to launch. * `intent` (@Nullable Intent) - The Intent to launch the Activity. ### Returns `X` (generic return type for chaining) ``` -------------------------------- ### Create a Keyboard-Interactive EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/06-quick-start.md Configure keyboard behavior using `setSoftInputMode` for visibility and adjustment. Use `setOnKeyListenerByView` to handle key events, such as processing input when the Enter key is pressed. ```java EasyWindow.with(activity) .setContentView(R.layout.input_window) // Configure keyboard behavior .setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE ) // Handle key events .setOnKeyListenerByView(R.id.input_field, new OnWindowViewKeyListener() { @Override public boolean onKey(@NonNull EasyWindow easyWindow, @NonNull EditText view, @NonNull KeyEvent event, int keyCode) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String input = view.getText().toString(); // Process input easyWindow.cancel(); return true; } return false; } }) .show(); ``` -------------------------------- ### Window View Visibility Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Sets or gets the visibility state of the window's view. ```APIDOC ## setWindowViewVisibility ### Description Sets the visibility of the window view. ### Method `easyWindow.setWindowViewVisibility(int visibility)` ### Parameters - **visibility** (int) - Required - The desired visibility state (e.g., VISIBLE, GONE). ``` ```APIDOC ## getWindowViewVisibility ### Description Gets the current visibility state of the window view. ### Method `easyWindow.getWindowViewVisibility()` ### Returns - (int) - The current visibility state. ``` -------------------------------- ### showAllWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Shows all previously hidden but not recycled windows. ```APIDOC ## showAllWindow ### Description Shows all previously hidden but not recycled windows. ### Method ```java public static synchronized void showAllWindow() ``` ### Example ```java EasyWindowManager.showAllWindow(); // Restore all windows ``` ``` -------------------------------- ### Get Current Window View Height Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the current height of the window view in pixels. ```java public int getWindowViewHeight() ``` -------------------------------- ### Create a Screen-Size Responsive EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/06-quick-start.md Use `setWindowSizePercent` and `setWindowLocationPercent` to define the window's dimensions and position relative to the screen. `setBackgroundDimAmount` controls the background dimming, and `setOutsideTouchable(true)` allows closing the window by tapping outside. ```java EasyWindow.with(activity) .setContentView(R.layout.responsive_window) // Set size as percentage of screen .setWindowSizePercent(0.8f, 0.6f) // 80% width, 60% height // Center on screen .setWindowLocationPercent(0.5f, 0.5f) // Show with background dim .setBackgroundDimAmount(0.5f) .setOutsideTouchable(true) // Close on outside tap .setOnClickListener((window, view) -> { // This is called only if tap is on the window itself }) .show(); ``` -------------------------------- ### Get Current Window View Width Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the current width of the window view in pixels. ```java public int getWindowViewWidth() ``` -------------------------------- ### EasyWindow Core Package Structure Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/07-module-structure.md Illustrates the directory and file organization for the main EasyWindow library components, including core classes, event listeners, and draggable behavior modules. ```tree com.hjq.window ├── EasyWindow.java # Main floating window class ├── EasyWindowManager.java # Global window management utility ├── WindowRootLayout.java # Internal root layout container ├── WindowLifecycleControl.java # Activity lifecycle monitoring ├── WindowTaskHandler.java # Background task handling ├── ScreenOrientationMonitor.java # Screen rotation detection │ ├── Callbacks (Event listeners) ├── OnWindowLifecycleCallback.java # Lifecycle events (show, hide, recycle) ├── OnWindowScreenRotationCallback.java # Rotation events ├── OnWindowLayoutInflateListener.java # Layout inflation completion ├── OnWindowViewClickListener.java # View click events ├── OnWindowViewLongClickListener.java # View long-click events ├── OnWindowViewTouchListener.java # View touch events ├── OnWindowViewKeyListener.java # View key events │ ├── draggable/ │ ├── IWindowDraggableRule.java # Drag behavior interface │ ├── BaseWindowDraggableRule.java # Abstract base class │ ├── MovingWindowDraggableRule.java # Follow-finger drag │ ├── SpringBackWindowDraggableRule.java # Spring-back animation │ ├── IWindowDraggableInfo.java # Drag info interface │ ├── IWindowDraggableAuxiliary.java # Drag helper interface │ └── callback/ │ ├── OnWindowDraggingCallback.java # Drag event listener │ └── OnSpringBackAnimCallback.java # Spring animation listener │ └── Wrapper Classes (for internal event handling) ├── ViewClickListenerWrapper.java ├── ViewLongClickListenerWrapper.java ├── ViewTouchListenerWrapper.java └── ViewKeyListenerWrapper.java ``` -------------------------------- ### Get Window View Dimensions Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Retrieves the current width and height of the window's view. ```Java easyWindow.getWindowViewWidth(); ``` ```Java easyWindow.getWindowViewHeight(); ``` -------------------------------- ### Get Window View Visibility Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Retrieves the current visibility state of the window's view. ```Java easyWindow.getWindowViewVisibility(); ``` -------------------------------- ### Event Listener Methods Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Methods for setting up various event listeners. ```APIDOC ## Event Listeners ### `setOnClickListener(OnClickListener listener)` Sets a click listener for the window. ### `setOnClickListenerByView(View view, OnClickListener listener)` Sets a click listener for a specific view. ### `setOnLongClickListener(OnLongClickListener listener)` Sets a long click listener for the window. ### `setOnLongClickListenerByView(View view, OnLongClickListener listener)` Sets a long click listener for a specific view. ### `setOnTouchListener(OnTouchListener listener)` Sets a touch listener for the window. ### `setOnTouchListenerByView(View view, OnTouchListener listener)` Sets a touch listener for a specific view. ### `setOnKeyListener(OnKeyListener listener)` Sets a key listener for the window. ### `setOnKeyListenerByView(View view, OnKeyListener listener)` Sets a key listener for a specific view. ### `setOnWindowLifecycleCallback(WindowLifecycleCallback callback)` Sets a callback for window lifecycle events. ### `setOnWindowScreenRotationCallback(WindowScreenRotationCallback callback)` Sets a callback for window screen rotation events. ``` -------------------------------- ### OnSpringBackAnimCallback Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Callback interface for monitoring spring-back animation events. It allows tracking the start and end of the animation. ```APIDOC ## OnSpringBackAnimCallback Monitors spring-back animation events. ### Methods - `onSpringBackAnimStart(int fromX, int fromY, int toX, int toY)`: Called when the spring-back animation starts, providing the start and target positions. - `onSpringBackAnimEnd(int x, int y)`: Called when the spring-back animation ends, providing the final position. ### Parameters - **fromX, fromY** (int): Starting position of the animation. - **toX, toY** (int): Target edge position of the animation. - **x, y** (int): Final position of the window after the animation. ``` -------------------------------- ### Use Older EasyWindow Version (Support Library) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md If your project is still using the Support Library and not AndroidX, you can implement an older version of the EasyWindow framework. Migration to AndroidX is recommended. ```groovy dependencies { // Floating window framework:https://github.com/getActivity/EasyWindow implementation 'com.github.getActivity:EasyWindow:13.5' } ``` -------------------------------- ### getWindowViewVisibility Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Gets the current visibility state of the window view. Returns an integer constant representing the visibility. ```APIDOC ## getWindowViewVisibility ### Description Gets the current visibility of the window view. ### Method (Not specified, likely a Java method call) ### Parameters None ### Request Example (Java method call example) ```java // Example: getWindowViewVisibility(); ``` ### Response #### Success Response * **int** - Visibility constant #### Response Example (Not specified) ``` -------------------------------- ### Configure Percentage-Based Window Size and Position Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Define window dimensions and position relative to the screen size using floating-point percentages. This ensures responsiveness across different screen densities. ```java easyWindow .setWindowSizePercent(0.5f, 0.3f) .setWindowLocationPercent(0.5f, 0.5f); ``` -------------------------------- ### Request SYSTEM_ALERT_WINDOW with XXPermissions Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Use the XXPermissions library to simplify requesting the SYSTEM_ALERT_WINDOW permission. ```java XXPermissions.with(context) .permission(Permission.SYSTEM_ALERT_WINDOW) .request(new OnAllPermissionsGranted() { @Override public void onAllPermissionsGranted() { // All permissions granted EasyWindow.with(application).show(); } }); ``` -------------------------------- ### Get Window Tag Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the tag identifier previously assigned to the window. Returns null if no tag is set. ```java public String getWindowTag() ``` -------------------------------- ### OnWindowDraggingCallback Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Callback interface for monitoring drag events of a window. It provides methods to be notified when a drag starts, moves, or ends. ```APIDOC ## OnWindowDraggingCallback Monitors drag events. ### Methods - `onWindowDraggingStart(@NonNull EasyWindow easyWindow)`: Called when the window drag starts. - `onWindowDraggingMove(@NonNull EasyWindow easyWindow, int x, int y)`: Called when the window is being dragged, providing the current coordinates. - `onWindowDraggingEnd(@NonNull EasyWindow easyWindow, int x, int y)`: Called when the window drag ends, providing the final coordinates. ### Parameters - **easyWindow** (EasyWindow): The window being dragged. - **x** (int): The current X coordinate (for Move/End methods). - **y** (int): The current Y coordinate (for Move/End methods). ``` -------------------------------- ### SpringBackWindowDraggableRule Animation Callback Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Set a callback to monitor the start and end of the spring-back animation. Useful for logging or triggering actions. ```java SpringBackWindowDraggableRule springRule = new SpringBackWindowDraggableRule(); springRule.setOnSpringBackAnimCallback(new OnSpringBackAnimCallback() { @Override public void onSpringBackAnimStart(int fromX, int fromY, int toX, int toY) { Log.d("EasyWindow", "Animation started"); } @Override public void onSpringBackAnimEnd(int x, int y) { Log.d("EasyWindow", "Animation ended at " + x + ", " + y); } }); easyWindow.setWindowDraggableRule(springRule); ``` -------------------------------- ### Reuse EasyWindow Instances Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Create a window instance once and reuse it for multiple show/hide operations to improve performance. ```java private EasyWindow mWindow = EasyWindow.with(activity) .setContentView(R.layout.window) .setWindowSize(200, 200); public void show() { mWindow.show(); } public void hide() { mWindow.cancel(); } ``` -------------------------------- ### Get Root Window View Visibility Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the current visibility state of the window view. Returns a visibility constant. ```java public int getWindowViewVisibility() ``` -------------------------------- ### Get Content View from EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the current content view of the floating window. Returns null if no content has been set. ```java public ViewGroup getContentView() ``` -------------------------------- ### OnWindowDraggingCallback Methods Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/04-draggable.md Callback methods for monitoring window drag events. Implement these to react to the start, move, and end of a drag operation. ```java default void onWindowDraggingStart(@NonNull EasyWindow easyWindow) default void onWindowDraggingMove(@NonNull EasyWindow easyWindow, int x, int y) default void onWindowDraggingEnd(@NonNull EasyWindow easyWindow, int x, int y) ``` -------------------------------- ### Combining Multiple Callbacks Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Demonstrates how to chain multiple callbacks for different event types when creating an EasyWindow. ```APIDOC ## Combining Multiple Callbacks ### Description Demonstrates how to chain multiple callbacks for different event types when creating an EasyWindow, including lifecycle monitoring, rotation handling, and view interactions. ### Usage Example ```java EasyWindow.with(activity) .setContentView(R.layout.window_layout) // Lifecycle monitoring .setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() { @Override public void onWindowShow(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Window shown"); } @Override public void onWindowCancel(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Window hidden"); } }) // Rotation handling .setOnWindowScreenRotationCallback(new OnWindowScreenRotationCallback() { @Override public void onWindowScreenRotationAfter(@NonNull EasyWindow easyWindow, int screenOrientation) { Log.d("EasyWindow", "Screen rotated"); } }) // View interaction .setOnClickListenerByView(R.id.button, (window, view) -> { window.cancel(); }) .show(); ``` ``` -------------------------------- ### Get EasyWindow Drag Rule Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Retrieves the currently active drag rule for the window. Returns the rule or null if none is set. ```java public IWindowDraggableRule getWindowDraggableRule() ``` -------------------------------- ### Hide and Show All Windows Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Temporarily hide all windows to perform an action and then restore them. Ensure to call `showAllWindow()` after `cancelAllWindow()` to make windows visible again. ```java // Hide all windows temporarily EasyWindowManager.cancelAllWindow(); // Do something... // Restore windows EasyWindowManager.showAllWindow(); ``` -------------------------------- ### Organize and Manage Windows by Tag Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Use tags to group and manage windows, such as for debugging overlays. This enables showing, hiding, and checking the existence of windows associated with a specific tag. ```java // Organize windows by function using tags EasyWindow.with(activity) .setWindowTag("debug_overlay") .setContentView(R.layout.debug_view) .show(); // Later: hide all debug windows EasyWindowManager.cancelWindowByTag("debug_overlay"); // Check if any debug windows are active if (EasyWindowManager.existWindowShowingByTag("debug_overlay")) { // Debug mode is visible } ``` -------------------------------- ### Manage Multiple EasyWindows with Tags Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/06-quick-start.md Assign tags to windows for easy identification and management. Use EasyWindowManager to show, hide, or check the existence of windows by their tags. ```java // Create first window EasyWindow window1 = EasyWindow.with(activity) .setWindowTag("overlay_1") .setContentView(R.layout.overlay) .setWindowLocation(0, 0) .show(); // Create second window EasyWindow window2 = EasyWindow.with(activity) .setWindowTag("overlay_2") .setContentView(R.layout.overlay) .setWindowLocation(400, 0) .show(); // Later: hide all overlays EasyWindowManager.cancelWindowByTag("overlay_1"); EasyWindowManager.cancelWindowByTag("overlay_2"); // Or cancel all windows with a tag prefix EasyWindowManager.cancelAllWindow(); // Check if overlay is still visible if (EasyWindowManager.existWindowShowingByTag("overlay_1")) { // Overlay is displayed } ``` -------------------------------- ### Use Correct Context for EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Use Activity context for local windows and Application context for global windows to avoid 'BadTokenException'. ```java EasyWindow.with(activity) // ✓ Correct .setContentView(R.layout.window) .show(); ``` ```java EasyWindow.with(application) // ✓ Correct for global .setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY) .show(); ``` -------------------------------- ### Show All Windows Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Restores visibility to all windows that were previously hidden but not recycled. This brings back all managed windows to their displayed state. ```java EasyWindowManager.showAllWindow(); // Restore all windows ``` -------------------------------- ### Handle Screen Rotation with EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/06-quick-start.md Implement callbacks to adjust window behavior before and after screen rotation. Adjust window size and position based on the new orientation. ```java EasyWindow easyWindow = EasyWindow.with(activity) .setContentView(R.layout.rotation_sensitive) .setWindowLocation(Gravity.CENTER, 0, 0) // Monitor rotation events .setOnWindowScreenRotationCallback(new OnWindowScreenRotationCallback() { @Override public void onWindowScreenRotationBefore(@NonNull EasyWindow easyWindow, int screenOrientation) { Log.d("Window", "Screen is about to rotate"); } @Override public void onWindowScreenRotationAfter(@NonNull EasyWindow easyWindow, int screenOrientation) { if (screenOrientation == Configuration.ORIENTATION_LANDSCAPE) { Log.d("Window", "Now in landscape"); // Adjust window size/position for landscape easyWindow.setWindowSizePercent(0.5f, 1.0f); } else { Log.d("Window", "Now in portrait"); // Adjust for portrait easyWindow.setWindowSizePercent(1.0f, 0.5f); } } }) .show(); ``` -------------------------------- ### Thread-Safe Window Management Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md All `EasyWindowManager` methods are synchronized, making them safe to call from any thread, including background threads. This example demonstrates calling `cancelAllWindow()` from a new thread. ```java // Safe to call from background thread new Thread(() -> { EasyWindowManager.cancelAllWindow(); }).start(); ``` -------------------------------- ### Global Floating Window Lifecycle Management (Java) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Implement global floating window display across all Activities by registering an Application.ActivityLifecycleCallbacks. This Java code shows how to create a window in each Activity's onCreate method. ```java public final class WindowLifecycleControl implements Application.ActivityLifecycleCallbacks { static void with(Application application) { application.registerActivityLifecycleCallbacks(new FloatingLifecycle()); } @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { EasyWindow.with(activity) .setContentView(R.layout.xxx) .show(); } ...... } ``` -------------------------------- ### Callback Interfaces Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Defines 8 callback interfaces for handling various events, including window lifecycle, view interactions, and drag events. Practical examples are provided. ```APIDOC ## Callbacks and Event Listeners ### Description Provides 8 distinct callback interfaces to handle window lifecycle events, view interactions, and drag events. ### Interfaces - OnWindowLifecycleCallback - OnWindowScreenRotationCallback - OnWindowLayoutInflateListener - OnWindowViewClickListener - OnWindowViewLongClickListener - OnWindowViewTouchListener - OnWindowViewKeyListener - OnWindowDraggingCallback - OnSpringBackAnimCallback ### Usage Register listeners to receive notifications for specific events. ``` -------------------------------- ### Implement onWindowScreenRotationBefore Callback Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Implement this method to execute logic before the screen rotates. It's useful for preparing UI or state changes. ```java easyWindow.setOnWindowScreenRotationCallback(new OnWindowScreenRotationCallback() { @Override public void onWindowScreenRotationBefore(@NonNull EasyWindow easyWindow, int screenOrientation) { if (screenOrientation == Configuration.ORIENTATION_LANDSCAPE) { Log.d("EasyWindow", "Rotating to landscape"); } } }); ``` -------------------------------- ### Create Global Application Window Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Create a window that spans the entire application. This requires the SYSTEM_ALERT_WINDOW permission and setting the window type to TYPE_APPLICATION_OVERLAY. ```java EasyWindow.with(application) .setContentView(R.layout.window) .setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY) .show(); ``` -------------------------------- ### Window Properties Methods Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Methods for setting various properties of the window. ```APIDOC ## Window Properties ### `setWindowTag(Object tag)` Sets a tag object for the window. ### `getWindowTag()` Retrieves the tag object associated with the window. ### `setWindowDuration(long duration)` Sets a duration for the window's display. ### `setWindowType(int type)` Sets the type of the window. ### `setWindowAnim(int anim)` Sets the animation for the window. ### `setWindowTitle(CharSequence title)` Sets the title for the window. ``` -------------------------------- ### Register Global Window Lifecycle Callback Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Implement Application.ActivityLifecycleCallbacks to manage global windows. This allows windows to be shown across the entire app without requiring the SYSTEM_ALERT_WINDOW permission by creating windows as Activities are created. ```java public class WindowLifecycleCallback implements Application.ActivityLifecycleCallbacks { private final Application mApplication; public WindowLifecycleCallback(Application application) { mApplication = application; } public static void register(Application application) { application.registerActivityLifecycleCallbacks(new WindowLifecycleCallback(application)); } @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { // Create window when each Activity is created EasyWindow.with(activity) .setContentView(R.layout.floating_window) .setWindowTag("global_window") .show(); } @Override public void onActivityStarted(Activity activity) {} @Override public void onActivityResumed(Activity activity) {} @Override public void onActivityPaused(Activity activity) {} @Override public void onActivityStopped(Activity activity) {} @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {} @Override public void onActivityDestroyed(Activity activity) {} } ``` -------------------------------- ### Handle Key Events with KeyEvent Constants Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/05-types-and-constants.md Use KeyEvent constants to identify specific key presses and actions within the OnWindowViewKeyListener. This example shows how to close the window when the back button is released. ```java easyWindow.setOnKeyListenerByView(R.id.content, new OnWindowViewKeyListener() { @Override public boolean onKey(@NonNull EasyWindow easyWindow, @NonNull View view, @NonNull KeyEvent event, int keyCode) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { easyWindow.cancel(); return true; } return false; } }); ``` -------------------------------- ### Create Local Floating Window (Kotlin - apply block) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md This Kotlin snippet uses an apply block for a more concise way to configure a local floating window tied to an Activity. Overlay permission is not needed. Customize content, duration, and click events. ```kotlin EasyWindow.with(activity).apply { setContentView(R.layout.toast_hint) // Make the window draggable //setWindowDraggableRule() // Set display duration setWindowDuration(1000) // Set animation style //setWindowAnim(android.R.style.Animation_Translucent) // Whether the outside area can be touched //setOutsideTouchable(false) // Set background dim amount //setBackgroundDimAmount(0.5f) setImageDrawableByImageView(android.R.id.icon, R.mipmap.ic_dialog_tip_finish) setTextByTextView(android.R.id.message, "Tap me to dismiss") setOnClickListenerByView(android.R.id.message, OnWindowViewClickListener { easyWindow: EasyWindow<*>, view: TextView -> easyWindow.cancel() // Navigate to a specific Activity // easyWindow.startActivity(intent) }) }.show() ``` -------------------------------- ### Advanced Methods Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Miscellaneous advanced methods for window configuration. ```APIDOC ## Advanced ### `setWindowManager(WindowManager windowManager)` Sets the window manager. ### `setWindowParams(WindowManager.LayoutParams params)` Sets the window layout parameters. ### `setRootLayout(View rootLayout)` Sets the root layout for the window. ### `setVerticalMargin(int topMargin, int bottomMargin)` Sets the top and bottom margins for the window. ### `setHorizontalMargin(int leftMargin, int rightMargin)` Sets the left and right margins for the window. ### `setVerticalWeight(float weight)` Sets the vertical weight for layout distribution. ### `setBitmapFormat(Bitmap.Config format)` Sets the bitmap format for the window. ### `setSystemUiVisibility(int visibility)` Sets the system UI visibility flags. ### `setScreenOrientation(int orientation)` Sets the screen orientation for the window. ``` -------------------------------- ### Show Windows by Class Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Makes visible all windows that are instances of a specified class type. This allows for targeted restoration of specific window types. ```java EasyWindowManager.showWindowByClass(MyCustomWindow.class); ``` -------------------------------- ### CustomWindow Subclassing with Generics Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/07-module-structure.md Demonstrates how to subclass EasyWindow with proper type safety, ensuring that methods return the subclass type for fluent chaining. ```java public class CustomWindow extends EasyWindow { public CustomWindow setColor(int color) { // Returns CustomWindow, not EasyWindow return this; } } ``` -------------------------------- ### Set Window Location with Percentage Offsets Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Configure the window's position using percentages of the screen dimensions. This is useful for responsive layouts where the window should be positioned relative to the screen size. ```java public X setWindowLocationPercent(int gravity, @FloatRange(from = 0, to = 1) float horizontalPercent, @FloatRange(from = 0, to = 1) float verticalPercent) ``` ```java public X setWindowLocationPercent(@FloatRange(from = 0, to = 1) float horizontalPercent, @FloatRange(from = 0, to = 1) float verticalPercent) ``` ```java easyWindow.setWindowLocationPercent(0.5f, 0.5f); // Center of screen ``` ```java easyWindow.setWindowLocationPercent(Gravity.RIGHT, 1.0f, 0.5f); // Right side, vertically centered ``` -------------------------------- ### Responsive Dialog Configuration with EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/00-index.md Configure a dialog to be responsive to screen size. This snippet sets the window size and location as percentages of the screen and adjusts the background dim amount. ```java easyWindow .setWindowSizePercent(0.8f, 0.6f) .setWindowLocationPercent(0.5f, 0.5f) .setBackgroundDimAmount(0.5f); ``` -------------------------------- ### Window Properties and Flags Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Methods for configuring touchability, background dimming, window flags, and window type. ```APIDOC ## Window Properties and Flags ### Description Methods for configuring touchability, background dimming, window flags, and window type. ### Methods - `easyWindow.setOutsideTouchable(boolean touchable)`: Determines if the area outside the floating window is touchable. - `easyWindow.setBackgroundDimAmount(@FloatRange(from = 0.0, to = 1.0) float amount)`: Sets the dim amount for the background behind the floating window. - `easyWindow.addWindowFlags(int flags)`: Adds specified flags to the window. - `easyWindow.removeWindowFlags(int flags)`: Removes specified flags from the window. - `easyWindow.setWindowFlags(int flags)`: Sets the window flags, replacing any existing flags. - `easyWindow.hasWindowFlags(int flags)`: Checks if a specific window flag is currently set. - `easyWindow.setWindowType(int type)`: Sets the window type. ``` -------------------------------- ### Module Structure Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Documentation detailing the architecture and design of the EasyWindow framework, including package structure, class hierarchy, API layers, extension points, and design patterns. ```APIDOC ## Module Structure and Architecture ### Description Details the internal architecture and design of the EasyWindow framework, covering package structure, class hierarchy, API layers, and design patterns. ### Topics - Package organization - Class hierarchy overview - API layers and responsibilities - Extension points for customization - Design patterns employed ``` -------------------------------- ### Post Tasks with EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Schedule tasks to be executed on the EasyWindow's thread. Tasks can be posted immediately, with a delay, or cancelled individually or all at once. ```java easyWindow.sendTask(Runnable runnable); easyWindow.sendTask(@NonNull Runnable runnable, long delayMillis); easyWindow.cancelTask(@NonNull Runnable runnable); easyWindow.cancelAllTask(); ``` -------------------------------- ### EasyWindow Class API Reference Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt The EasyWindow class provides over 200 public methods for creating, configuring, and managing floating windows. This includes factory methods, lifecycle management, view manipulation, event listeners, and advanced display features. ```APIDOC ## EasyWindow Class API ### Description Provides access to over 200 public methods for managing floating windows, including creation, configuration, lifecycle, view manipulation, and event handling. ### Methods - Factory Methods - Lifecycle Methods (show, cancel, recycle, update) - Configuration Methods - View Manipulation Methods - Event Listener Registration - Advanced Display Features ### Parameters Detailed documentation for each of the 200+ methods is available in the full API reference. ``` -------------------------------- ### Find Window Instances by Tag Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Retrieve all windows associated with a specific tag. This is helpful for grouping and managing windows by their designated purpose or identifier. ```java public static synchronized List> findWindowInstancesByTag(@Nullable String tag) ``` ```java List> notificationWindows = EasyWindowManager.findWindowInstancesByTag("notification"); ``` -------------------------------- ### Create Local Floating Window Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/06-quick-start.md Use this to create a floating window scoped to a specific Activity. It requires no special permissions. ```java EasyWindow.with(activity) .setContentView(R.layout.floating_window) .show(); ``` -------------------------------- ### Lazy Initialization of EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/08-permissions-and-setup.md Initialize EasyWindow instances only when they are needed to defer resource allocation until the last possible moment. ```java private EasyWindow mWindow; public void showWindow() { if (mWindow == null) { mWindow = EasyWindow.with(activity) .setContentView(R.layout.window) .setWindowSize(300, 400); } mWindow.show(); } ``` -------------------------------- ### showWindowByTag Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/02-easywindowmanager.md Shows windows with a specific tag. ```APIDOC ## showWindowByTag ### Description Shows windows with a specific tag. ### Method ```java public static synchronized void showWindowByTag(@Nullable String tag) ``` ### Parameters #### Path Parameters - **tag** (String) - Required - Tag identifier ### Example ```java EasyWindowManager.showWindowByTag("notification"); ``` ``` -------------------------------- ### Create Local Floating Window (Java) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Use this Java snippet to create a local floating window tied to an Activity. No overlay permission is required. Configure content, duration, and click listeners. ```java EasyWindow.with(this) .setContentView(R.layout.toast_hint) // Make the window draggable //.setWindowDraggableRule() // Set display duration .setWindowDuration(1000) // Set animation style //.setWindowAnim(android.R.style.Animation_Translucent) // Whether the outside area can be touched //.setOutsideTouchable(false) // Set background dim amount //.setBackgroundDimAmount(0.5f) .setImageDrawableByImageView(android.R.id.icon, R.mipmap.ic_dialog_tip_finish) .setTextByTextView(android.R.id.message, "Tap me to dismiss") .setOnClickListenerByView(android.R.id.message, new OnWindowViewClickListener() { @Override public void onClick(@NonNull EasyWindow easyWindow, @NonNull TextView view) { easyWindow.cancel(); // Navigate to a specific Activity // easyWindow.startActivity(intent); } }) .show(); ``` -------------------------------- ### Show EasyWindow Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Displays the floating window. If the window is already visible, this method will update it. An IllegalArgumentException is thrown if the root layout or content view is not set. ```java public void show() ``` ```java easyWindow.show(); ``` -------------------------------- ### Implement OnWindowLifecycleCallback for Window Display Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/03-callbacks.md Use this callback to execute logic when a window is displayed. It requires an instance of EasyWindow. ```java easyWindow.setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() { @Override public void onWindowShow(@NonNull EasyWindow easyWindow) { Log.d("EasyWindow", "Window displayed"); } }); ``` -------------------------------- ### Set Window Location with Gravity and Coordinates Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/01-easywindow.md Use this method to set the window's position using a gravity constant and specific pixel coordinates. The gravity determines the reference point for the coordinates. ```java public X setWindowLocation(int gravity, @Px int x, @Px int y) ``` ```java public X setWindowLocation(@Px int x, @Px int y) ``` ```java easyWindow.setWindowLocation(Gravity.BOTTOM | Gravity.RIGHT, 0, 0); // Bottom-right corner ``` ```java easyWindow.setWindowLocation(100, 200); // 100px from left, 200px from top ``` -------------------------------- ### Types and Constants Reference Source: https://github.com/getactivity/easywindow/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt A comprehensive reference for Android constants used within the EasyWindow framework, including WindowManager constants, flags, types, modes, and view-related constants. ```APIDOC ## Types and Constants ### Description Provides a complete reference for over 100 constants related to WindowManager, window flags, types, modes, view visibility, gravity, and more. ### Categories - WindowManager constants - Window flags and types - View visibility and gravity - MotionEvent and KeyEvent codes - Pixel format and size constants ``` -------------------------------- ### Configure JitPack Repository (Gradle < 7.0) Source: https://github.com/getactivity/easywindow/blob/master/README-en.md Add this configuration to your project's root build.gradle file if your Gradle version is below 7.0 to include the JitPack remote repository. ```groovy allprojects { repositories { // JitPack remote repository:https://jitpack.io maven { url 'https://jitpack.io' } } } ```