### Set Up TextMate Language Highlighting Source: https://context7.com/rosemoe/sora-editor/llms.txt Guides through registering file providers, themes, and grammars, then applying a TextMate color scheme and language to the editor. This setup should be done once, typically in Application.onCreate. ```kotlin // 1. Register an asset-based file provider (done once, e.g., in Application) FileProviderRegistry.getInstance().addFileProvider( AssetsFileResolver(assets) ) // 2. Register themes (JSON / tmTheme format stored in assets/textmate/) val themeRegistry = ThemeRegistry.getInstance() themeRegistry.loadTheme( ThemeModel(IThemeSource.fromInputStream( FileProviderRegistry.getInstance().tryGetInputStream("textmate/darcula.json"), "darcula.json", null ), "darcula") ) // 3. Register grammars via DSL GrammarRegistry.getInstance().loadGrammars( languages { language("source.java") { grammar = "textmate/java/syntaxes/java.tmLanguage.json" languageConfiguration = "textmate/java/language-configuration.json" defaultScopePattern(/* ... */) } language("source.kotlin") { grammar = "textmate/kotlin/syntaxes/Kotlin.tmLanguage" languageConfiguration = "textmate/kotlin/language-configuration.json" } language("source.python") { grammar = "textmate/python/syntaxes/python.tmLanguage.json" languageConfiguration = "textmate/python/language-configuration.json" } } ) // 4. Apply matching color scheme before creating the language editor.colorScheme = TextMateColorScheme.create(themeRegistry) // 5. Create language and attach to editor val language = TextMateLanguage.create("source.java", /* collectIdentifiers = */ true) editor.setEditorLanguage(language) // Switch theme at runtime ThemeRegistry.getInstance().setTheme("darcula") ``` -------------------------------- ### Get Start Padding (RTL Aware) Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the start padding based on layout direction. May include space for scrollbars. ```java public int getPaddingStart() { if (!isPaddingResolved()) { resolvePadding(); } return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? mPaddingRight : mPaddingLeft; } ``` -------------------------------- ### dispatchWindowInsetsAnimationStart Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Dispatches WindowInsetsAnimation.Callback.onStart when Window Insets animation is started. ```APIDOC ## dispatchWindowInsetsAnimationStart(@NonNull WindowInsetsAnimation animation, @NonNull Bounds bounds) ### Description Notifies the registered callback that a window insets animation has started. ### Method Signature @NonNull public Bounds dispatchWindowInsetsAnimationStart(@NonNull WindowInsetsAnimation animation, @NonNull Bounds bounds) ### Parameters * **animation** (WindowInsetsAnimation) - The current animation. * **bounds** (Bounds) - The upper and lower Bounds that provide the range of the animation. ### Return Value (@NonNull Bounds) - The upper and lower Bounds. ``` -------------------------------- ### startActionMode Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Starts an action mode with the given callback. If a type is not specified, it defaults to primary. ```APIDOC ## startActionMode(ActionMode.Callback callback) ### Description Starts an action mode with the given callback. Defaults to primary type. ### Method Signature public ActionMode startActionMode(ActionMode.Callback callback) ### Returns The new action mode if it is started, null otherwise. ``` ```APIDOC ## startActionMode(ActionMode.Callback callback, int type) ### Description Starts an action mode with the given callback and type. ### Method Signature public ActionMode startActionMode(ActionMode.Callback callback, int type) ### Parameters #### Path Parameters - **callback** (ActionMode.Callback) - Callback that will control the lifecycle of the action mode - **type** (int) - One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}. ### Returns The new action mode if it is started, null otherwise. ``` -------------------------------- ### Start Moving Task Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initiates the movement of a window task. This is a hidden API and should be used with caution. ```java public final boolean startMovingTask(float startX, float startY) { if (ViewDebug.DEBUG_POSITIONING) { Log.d(VIEW_LOG_TAG, "startMovingTask: {" + startX + "," + startY + "}"); } try { return mAttachInfo.mSession.startMovingTask(mAttachInfo.mWindow, startX, startY); } catch (RemoteException e) { Log.e(VIEW_LOG_TAG, "Unable to start moving", e); } return false; } ``` -------------------------------- ### Start Drag and Drop Operation Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initiates a drag and drop operation. Use this method to start a drag when a user long-presses on a view. Ensure the view is attached and has a valid surface. ```java public final boolean startDragAndDrop(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags) { if (ViewDebug.DEBUG_DRAG) { Log.d(VIEW_LOG_TAG, "startDragAndDrop: data=" + data + " flags=" + flags); } if (mAttachInfo == null) { Log.w(VIEW_LOG_TAG, "startDragAndDrop called on a detached view."); return false; } if (!mAttachInfo.mViewRootImpl.mSurface.isValid()) { Log.w(VIEW_LOG_TAG, "startDragAndDrop called with an invalid surface."); return false; } if ((flags & DRAG_FLAG_GLOBAL) != 0 && ((flags & DRAG_FLAG_GLOBAL_SAME_APPLICATION) != 0)) { Log.w(VIEW_LOG_TAG, "startDragAndDrop called with both DRAG_FLAG_GLOBAL " + "and DRAG_FLAG_GLOBAL_SAME_APPLICATION, the drag will default to " + "DRAG_FLAG_GLOBAL_SAME_APPLICATION"); flags &= ~DRAG_FLAG_GLOBAL; } if (data != null) { if (com.android.window.flags.Flags.delegateUnhandledDrags()) { data.prepareToLeaveProcess( (flags & (DRAG_FLAG_GLOBAL_SAME_APPLICATION | DRAG_FLAG_GLOBAL)) != 0); if ((flags & DRAG_FLAG_START_INTENT_SENDER_ON_UNHANDLED_DRAG) != 0) { if (!hasActivityPendingIntents(data)) { // Reset the flag if there is no launchable activity intent flags &= ~DRAG_FLAG_START_INTENT_SENDER_ON_UNHANDLED_DRAG; Log.w(VIEW_LOG_TAG, "startDragAndDrop called with " + "DRAG_FLAG_START_INTENT_ON_UNHANDLED_DRAG but the clip data " + "contains non-activity PendingIntents"); } } } else { data.prepareToLeaveProcess((flags & DRAG_FLAG_GLOBAL) != 0); } } Rect bounds = new Rect(); getBoundsOnScreen(bounds, true); Point lastTouchPoint = new Point(); mAttachInfo.mViewRootImpl.getLastTouchPoint(lastTouchPoint); final ViewRootImpl root = mAttachInfo.mViewRootImpl; // Skip surface logic since shadows and animation are not required during the a11y drag final boolean a11yEnabled = AccessibilityManager.getInstance(mContext).isEnabled(); if (a11yEnabled && (flags & View.DRAG_FLAG_ACCESSIBILITY_ACTION) != 0) { try { IBinder token = mAttachInfo.mSession.performDrag( mAttachInfo.mWindow, flags, null, mAttachInfo.mViewRootImpl.getLastTouchSource(), mAttachInfo.mViewRootImpl.getLastTouchDeviceId(), mAttachInfo.mViewRootImpl.getLastTouchPointerId(), 0f, 0f, 0f, 0f, data); if (ViewDebug.DEBUG_DRAG) { Log.d(VIEW_LOG_TAG, "startDragAndDrop via a11y action returned " + token); } if (token != null) { root.setLocalDragState(myLocalState); mAttachInfo.mDragToken = token; mAttachInfo.mDragData = data; mAttachInfo.mViewRootImpl.setDragStartedViewForAccessibility(this); setAccessibilityDragStarted(true); } return token != null; } catch (Exception e) { Log.e(VIEW_LOG_TAG, "Unable to initiate a11y drag", e); } } return false; } ``` -------------------------------- ### Start Drag Operation - Deprecated Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Deprecated method for starting a drag operation. Use startDragAndDrop for newer platform versions. ```java @Deprecated public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags) { return startDragAndDrop(data, shadowBuilder, myLocalState, flags); } ``` -------------------------------- ### startDragAndDrop Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Starts a drag and drop operation, allowing the system to handle the drag shadow. ```APIDOC ## startDragAndDrop(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags) ### Description Starts a drag and drop operation. The system uses the provided `DragShadowBuilder` to get metrics and draw the drag shadow. Drag events are then sent to visible View objects. ### Method `public boolean startDragAndDrop(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags)` ### Parameters * **data** (ClipData) - Required - A {@link android.content.ClipData} object pointing to the data to be transferred by the drag and drop operation. * **shadowBuilder** (DragShadowBuilder) - Required - A {@link android.view.View.DragShadowBuilder} object for building the drag shadow. * **myLocalState** (Object) - Required - An {@link java.lang.Object} containing local data about the drag and drop operation. * **flags** (int) - Required - Flags for the drag operation. ``` -------------------------------- ### Get Foreground Gravity Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the gravity used for positioning the foreground drawable. Defaults to START and TOP. ```java @InspectableProperty(valueType = InspectableProperty.ValueType.GRAVITY) public int getForegroundGravity() { return mForegroundInfo != null ? mForegroundInfo.mGravity : Gravity.START | Gravity.TOP; } ``` -------------------------------- ### Get Camera Distance Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the distance along the Z axis from the camera to the view, adjusted by screen density. ```java public float getCameraDistance() { final float dpi = mResources.getDisplayMetrics().densityDpi; return mRenderNode.getCameraDistance() * dpi; } ``` -------------------------------- ### On Apply Framework Optional Fit System Windows Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Handles the application of framework optional fit system windows. This method computes system window insets and applies them. ```java private WindowInsets onApplyFrameworkOptionalFitSystemWindows(WindowInsets insets) { Rect localInsets = sThreadLocal.get(); WindowInsets result = computeSystemWindowInsets(insets, localInsets); applyInsets(localInsets); return result; } ``` -------------------------------- ### dispatchWindowInsetsAnimationPrepare Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Dispatches WindowInsetsAnimation.Callback.onPrepare when Window Insets animation is being prepared. ```APIDOC ## dispatchWindowInsetsAnimationPrepare(@NonNull WindowInsetsAnimation animation) ### Description Notifies the registered callback that a window insets animation is being prepared. ### Method Signature public void dispatchWindowInsetsAnimationPrepare(@NonNull WindowInsetsAnimation animation) ### Parameters * **animation** (WindowInsetsAnimation) - The current animation. ``` -------------------------------- ### Set Accessibility Drag Started Flag Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Sets or unsets the flag indicating that a drag operation has started for accessibility purposes. This method updates internal flags and may trigger accessibility events. ```java void setAccessibilityDragStarted(boolean started) { int pflags4 = mPrivateFlags4; if (started) { pflags4 |= PFLAG4_DRAG_A11Y_STARTED; } else { pflags4 &= ~PFLAG4_DRAG_A11Y_STARTED; } if (pflags4 != mPrivateFlags4) { mPrivateFlags4 = pflags4; sendWindowContentChangedAccessibilityEvent(CONTENT_CHANGE_TYPE_UNDEFINED); } } ``` -------------------------------- ### LSP Integration with LspProject and LspEditor Source: https://context7.com/rosemoe/sora-editor/llms.txt Wire a Language Server Protocol server to CodeEditor instances using LspProject and LspEditor. This involves defining a custom server, initializing the project, creating an LspEditor, and binding it to a CodeEditor view. ```kotlin // Requires minSdk 26 // 1. Create a project rooted at the workspace directory val project = LspProject("/data/user/0/com.example.app/files/workspace") // 2. Define a custom server that connects over a TCP socket val serverDefinition = CustomLanguageServerDefinition( ext = "java", serverConnectProvider = { workingDir -> SocketStreamConnectionProvider(host = "localhost", port = 6008) }, name = "eclipse.jdt.ls" ) project.addServerDefinition(serverDefinition) // 3. Initialize the project event emitter project.init() // 4. Create an LspEditor for the file to be edited val lspEditor = project.createEditor("/data/.../workspace/Main.java") // 5. Bind the LspEditor to a CodeEditor view lspEditor.editor = binding.editor // 6. Attach the LSP-backed language to the view val language: Language = lspEditor.createLanguage() binding.editor.setEditorLanguage(language) // 7. Open the document (triggers textDocument/didOpen) lspEditor.open() // or call after setting editor text // Dispose when the Activity is destroyed override fun onDestroy() { super.onDestroy() lspEditor.dispose() project.dispose() } ``` -------------------------------- ### Gradle Setup for Sora Editor Source: https://context7.com/rosemoe/sora-editor/llms.txt Add the Bill of Materials (BOM) and desired artifacts to your project's build files. The BOM aligns all sora-editor artifact versions. ```kotlin // build.gradle.kts dependencies { // BOM – aligns all sora-editor artifact versions implementation(platform("io.github.rosemoe:editor-bom:0.24.5")) // Core editor widget (required) implementation("io.github.rosemoe:editor") // Optional language modules implementation("io.github.rosemoe:language-java") implementation("io.github.rosemoe:language-textmate") implementation("io.github.rosemoe:language-treesitter") implementation("io.github.rosemoe:language-monarch") // Optional LSP module (minSdk 26) implementation("io.github.rosemoe:editor-lsp") } ``` -------------------------------- ### getViewRootImpl Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the view root associated with the View. ```APIDOC ## getViewRootImpl ### Description Gets the view root associated with the View. ### Method GET ### Endpoint View.getViewRootImpl() ### Response #### Success Response (200) - **viewRootImpl** (ViewRootImpl) - The view root, or null if none. ``` -------------------------------- ### Register Inlay Hint Renderers and Add Hints Source: https://context7.com/rosemoe/sora-editor/llms.txt Register built-in text and color renderers for inlay hints. Then, build a container with hints for specific lines and columns, specifying text or color and their associated renderer type. ```kotlin editor.registerInlayHintRenderers( TextInlayHintRenderer.DefaultInstance, // renders text labels inline ColorInlayHintRenderer.DefaultInstance // renders color swatches inline ) // Build a container with hints val hints = InlayHintsContainer() hints.addInlayHint( 0, // line (0-based) InlayHintTarget(/* startColumn = */ 5, /* endColumn = */ 5), TextInlayHint( text = ": Int", typeName = TextInlayHintRenderer.DefaultInstance.typeName, color = Color.GRAY ) ) hints.addInlayHint( 3, InlayHintTarget(14, 14), ColorInlayHint( color = Color.parseColor("#FF5733"), typeName = ColorInlayHintRenderer.DefaultInstance.typeName ) ) editor.setInlayHints(hints) // Listen for hint clicks editor.subscribeAlways { event -> println("Clicked hint at line ${event.line}: ${event.hint}") } ``` -------------------------------- ### getUniqueDrawingId Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Get the identifier used for this view by the drawing system. ```APIDOC ## getUniqueDrawingId ### Description Get the identifier used for this view by the drawing system. ### Method public long getUniqueDrawingId() ### Returns A long that uniquely identifies this view's drawing component. ``` -------------------------------- ### Get Bottom Padding Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the bottom padding of the view. ```java public int getPaddingBottom() { return mPaddingBottom; } ``` -------------------------------- ### Apply Built-in and Custom Color Schemes Source: https://context7.com/rosemoe/sora-editor/llms.txt Demonstrates how to apply predefined color schemes or create and apply a custom `EditorColorScheme`. Modifications to colors must be done on a looper thread. ```kotlin editor.colorScheme = EditorColorScheme.getDefault() editor.colorScheme = SchemeDarcula() editor.colorScheme = SchemeEclipse() editor.colorScheme = SchemeGitHub() editor.colorScheme = SchemeNotepadXX() editor.colorScheme = SchemeVS2019() ``` ```kotlin val scheme = editor.colorScheme scheme.setColor(EditorColorScheme.KEYWORD, Color.parseColor("#CC7832")) scheme.setColor(EditorColorScheme.COMMENT, Color.parseColor("#808080")) scheme.setColor(EditorColorScheme.LITERAL, Color.parseColor("#6A8759")) scheme.setColor(EditorColorScheme.PROBLEM_ERROR, Color.RED) ``` ```kotlin class MyColorScheme : EditorColorScheme() { override fun applyDefault() { super.applyDefault() // always call super setColor(KEYWORD, Color.parseColor("#569CD6")) setColor(TEXT_NORMAL, Color.WHITE) setColor(WHOLE_BACKGROUND,Color.parseColor("#1E1E1E")) } } editor.colorScheme = MyColorScheme() ``` -------------------------------- ### getPaddingTop Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the current top padding of the view in pixels. ```APIDOC ## getPaddingTop() ### Description Returns the current top padding of the view in pixels. ### Method Signature @InspectableProperty public int getPaddingTop() ### Returns * **int** - The top padding in pixels. ``` -------------------------------- ### Initialize AttachInfo Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initializes various window and display-related properties for view attachment. ```Java mWindow = window; mWindowToken = window.asBinder(); mDisplay = display; mViewRootImpl = viewRootImpl; mHandler = handler; mRootCallbacks = effectPlayer; mTreeObserver = new ViewTreeObserver(context); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); mDensity = displayMetrics.density; float pixelCount = (float) displayMetrics.widthPixels * displayMetrics.heightPixels; mDisplayPixelCount = pixelCount == 0f ? Float.POSITIVE_INFINITY : pixelCount; } ``` -------------------------------- ### getRight Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the right position of this view relative to its parent. ```APIDOC ## getRight() ### Description Gets the right position of this view relative to its parent. ### Method public final int getRight() ### Parameters None ### Request Example ```java int right = view.getRight(); ``` ### Response #### Success Response (200) - **return value** (int) - The right edge of this view, in pixels. ### Response Example ```json { "example": 150 } ``` ``` -------------------------------- ### TextMateLanguage - TextMate Grammar Highlighting Source: https://context7.com/rosemoe/sora-editor/llms.txt TextMateLanguage provides full TextMate grammar support for syntax highlighting. It requires setup of FileProviderRegistry, GrammarRegistry, and ThemeRegistry. ```APIDOC ## TextMateLanguage ### Description Provides full TextMate grammar support for syntax highlighting. Requires initial setup of registries and then language instance creation per editor. ### Setup ```kotlin // 1. Register an asset-based file provider (done once, e.g., in Application) FileProviderRegistry.getInstance().addFileProvider( AssetsFileResolver(assets) ) // 2. Register themes (JSON / tmTheme format stored in assets/textmate/) val themeRegistry = ThemeRegistry.getInstance() themeRegistry.loadTheme( ThemeModel(IThemeSource.fromInputStream( FileProviderRegistry.getInstance().tryGetInputStream("textmate/darcula.json"), "darcula.json", null ), "darcula") ) // 3. Register grammars via DSL GrammarRegistry.getInstance().loadGrammars( languages { language("source.java") { grammar = "textmate/java/syntaxes/java.tmLanguage.json" languageConfiguration = "textmate/java/language-configuration.json" defaultScopePattern(/* ... */) } language("source.kotlin") { grammar = "textmate/kotlin/syntaxes/Kotlin.tmLanguage" languageConfiguration = "textmate/kotlin/language-configuration.json" } language("source.python") { grammar = "textmate/python/syntaxes/python.tmLanguage.json" languageConfiguration = "textmate/python/language-configuration.json" } } ) // 4. Apply matching color scheme before creating the language editor.colorScheme = TextMateColorScheme.create(themeRegistry) // 5. Create language and attach to editor val language = TextMateLanguage.create("source.java", /* collectIdentifiers = */ true) editor.setEditorLanguage(language) // Switch theme at runtime ThemeRegistry.getInstance().setTheme("darcula") ``` ``` -------------------------------- ### getLeft Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the left position of this view relative to its parent. ```APIDOC ## getLeft() ### Description Gets the left position of this view relative to its parent. ### Method public final int getLeft() ### Parameters None ### Request Example ```java int left = view.getLeft(); ``` ### Response #### Success Response (200) - **return value** (int) - The left edge of this view, in pixels. ### Response Example ```json { "example": 50 } ``` ``` -------------------------------- ### onReceiveContent Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Implements the default behavior for receiving content. The default implementation is a no-op. Widgets should override this to define their default behavior. ```APIDOC ## onReceiveContent ### Description Implements the default behavior for receiving content. The default implementation is a no-op (returns the passed-in content without acting on it). Widgets should override this method to define their default behavior for receiving content. ### Method @Nullable public ContentInfo onReceiveContent(@NonNull ContentInfo payload) ### Parameters #### Path Parameters - **payload** (ContentInfo) - Required - The content to insert and related metadata. ### Request Example ```java // Assuming 'contentInfo' is a ContentInfo object: ContentInfo unhandledContent = onReceiveContent(contentInfo); ``` ### Response #### Success Response (ContentInfo) - **unhandledContent** (ContentInfo) - The portion of the passed-in content that was not handled (may be all, some, or none of the passed-in content). #### Response Example ```json { "example": "ContentInfo object representing unhandled content" } ``` ``` -------------------------------- ### Deprecated fitSystemWindows Method Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Handles system window insets by applying them to the view's padding. This method is deprecated and should be replaced with WindowInsets handling. ```java @Deprecated protected boolean fitSystemWindows(Rect insets) { if ((mPrivateFlags3 & PFLAG3_APPLYING_INSETS) == 0) { if (insets == null) { ``` -------------------------------- ### Alpha Property Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Methods for getting and setting the opacity of a view. ```APIDOC ## getAlpha() ### Description The opacity of the view. This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

By default this is 1.0f.

### Method public float getAlpha() ### Parameters None ### Response #### Success Response (float) - Returns the opacity of the view. ## setAlpha(float alpha) ### Description Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Note: setting alpha to a translucent value (0 < alpha < 1) can have significant performance implications, especially for large views. It is best to use the alpha property sparingly and transiently, as in the case of fading animations.

For a view with a frequently changing alpha, such as during a fading animation, it is ### Method public void setAlpha(float alpha) ### Parameters - **alpha** (float) - Required - The opacity value between 0.0f and 1.0f. ### Response None ``` -------------------------------- ### isAccessibilityHeading Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets whether this view is a heading for accessibility purposes. ```APIDOC ## isAccessibilityHeading ### Description Gets whether this view is a heading for a section of content for accessibility purposes. Users of some accessibility services can choose to navigate between headings instead of between paragraphs, words, etc. Apps that provide headings on sections of text can help the text navigation experience. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (boolean) - **true**: The view is a heading. - **false**: The view is not a heading. ### Response Example ``` false ``` ``` -------------------------------- ### requestApplyInsets Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Asks that a new dispatch of onApplyWindowInsets(WindowInsets) be performed. ```APIDOC ## requestApplyInsets ### Description Ask that a new dispatch of {@link #onApplyWindowInsets(WindowInsets)} be performed. ### Method public void requestApplyInsets() ### Request Example ```java // Example usage view.requestApplyInsets(); ``` ``` -------------------------------- ### getPointerIcon Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the mouse pointer icon currently set for the view. ```APIDOC ## getPointerIcon() ### Description Gets the mouse pointer icon for the current view. ### Returns * PointerIcon - The current mouse pointer icon. ### See Also * {@link #setPointerIcon(PointerIcon)} ``` -------------------------------- ### Start Drag and Drop Operation Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initiates a drag and drop operation. This method handles the creation of the drag shadow surface, drawing the shadow, and performing the drag with the system. It returns a token representing the drag operation if successful. ```java final float overrideInvScale = CompatibilityInfo.getOverrideInvertedScale(); if (overrideInvScale != 1f) { shadowTouchPoint.x = (int) (shadowTouchPoint.x / overrideInvScale); shadowTouchPoint.y = (int) (shadowTouchPoint.y / overrideInvScale); } // Create 1x1 surface when zero surface size is specified because SurfaceControl.Builder // does not accept zero size surface. if (shadowSize.x == 0 || shadowSize.y == 0) { if (!sAcceptZeroSizeDragShadow) { throw new IllegalStateException("Drag shadow dimensions must be positive"); } shadowSize.x = 1; shadowSize.y = 1; } if (ViewDebug.DEBUG_DRAG) { Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); } final SurfaceControl surfaceControl = new SurfaceControl.Builder() .setName("drag surface") .setParent(root.getSurfaceControl()) .setBufferSize(shadowSize.x, shadowSize.y) .setFormat(PixelFormat.TRANSLUCENT) .setCallsite("View.startDragAndDrop") .build(); if (overrideInvScale != 1f) { final SurfaceControl.Transaction transaction = new SurfaceControl.Transaction(); transaction.setMatrix(surfaceControl, 1 / overrideInvScale, 0, 0, 1 / overrideInvScale) .apply(); } final Surface surface = new Surface(); surface.copyFrom(surfaceControl); IBinder token = null; try { Trace.traceBegin(TRACE_TAG_VIEW, "startDragAndDrop#drawDragShadow"); final Canvas canvas = isHardwareAccelerated() ? surface.lockHardwareCanvas() : surface.lockCanvas(null); try { canvas.drawColor(0, PorterDuff.Mode.CLEAR); shadowBuilder.onDrawShadow(canvas); } finally { surface.unlockCanvasAndPost(canvas); Trace.traceEnd(TRACE_TAG_VIEW); } Trace.traceBegin(TRACE_TAG_VIEW, "startDragAndDrop#performDrag"); try { token = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, flags, surfaceControl, root.getLastTouchSource(), root.getLastTouchDeviceId(), root.getLastTouchPointerId(), lastTouchPoint.x, lastTouchPoint.y, shadowTouchPoint.x, shadowTouchPoint.y, data); if (ViewDebug.DEBUG_DRAG) { Log.d(VIEW_LOG_TAG, "performDrag returned " + token); } if (token != null) { if (mAttachInfo.mDragSurface != null) { mAttachInfo.mDragSurface.release(); } if (mAttachInfo.mDragData != null) { // Clean up previous drag data intents View.cleanUpPendingIntents(mAttachInfo.mDragData); } mAttachInfo.mDragSurface = surface; mAttachInfo.mDragToken = token; mAttachInfo.mDragData = data; // Cache the local state object for delivery with DragEvents root.setLocalDragState(myLocalState); if (a11yEnabled) { // Set for AccessibilityEvents mAttachInfo.mViewRootImpl.setDragStartedViewForAccessibility(this); } } return token != null; } finally { Trace.traceEnd(TRACE_TAG_VIEW); } } catch (Exception e) { Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); return false; } finally { if (token == null) { surface.destroy(); } surfaceControl.release(); } ``` -------------------------------- ### getLocationOnScreen Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the coordinates of this view in the coordinate space of the device screen. ```APIDOC ## getLocationOnScreen(int[] outLocation) ### Description Gets the coordinates of this view in the coordinate space of the device screen, irrespective of system decorations and whether the system is in multi-window mode. ### Method public void getLocationOnScreen(@Size(2) int[] outLocation) ### Parameters #### Path Parameters - **outLocation** (int[]) - A two-element integer array in which the view coordinates are stored. The x-coordinate is at index 0; the y-coordinate, at index 1. ``` -------------------------------- ### Get View Resources Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the Resources object associated with this view. ```java public Resources getResources() { return mResources; } ``` -------------------------------- ### Implement Custom Language Support Source: https://context7.com/rosemoe/sora-editor/llms.txt Provides a template for implementing the `Language` interface to add custom highlighting, completion, and formatting for a new programming language. Ensure background thread operations for analysis. ```kotlin class MyLanguage : Language { private val analyzeManager = SimpleAnalyzeManager { ref, receiver -> // Build Styles on a background thread and push them to the receiver val styles = Styles() // ... populate spans / code blocks ... receiver.setStyles(this, styles) } override fun getAnalyzeManager(): AnalyzeManager = analyzeManager override fun getInterruptionLevel() = Language.INTERRUPTION_LEVEL_STRONG @WorkerThread override fun requireAutoComplete( content: ContentReference, position: CharPosition, publisher: CompletionPublisher, extraArguments: Bundle ) { val prefix = CompletionHelper.computePrefix(content, position, MyCharacter::isJavaIdentifierPart) val keywords = listOf("if", "else", "while", "for", "return", "class", "fun") for (kw in keywords) { if (kw.startsWith(prefix)) { publisher.addItem( SimpleCompletionItem(kw, "Keyword", prefix.length, kw) .kind(CompletionItemKind.KEYWORD) ) } } } override fun getIndentAdvance(content: ContentReference, line: Int, column: Int) = 0 override fun useTab() = false override fun getFormatter(): Formatter = EmptyLanguage.EmptyFormatter.INSTANCE override fun getSymbolPairs(): SymbolPairMatch = EmptyLanguage.EMPTY_SYMBOL_PAIRS override fun getNewlineHandlers() = null override fun destroy() { analyzeManager.destroy() } } editor.setEditorLanguage(MyLanguage()) ``` -------------------------------- ### getCameraDistance Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the distance along the Z axis from the camera to this view. ```APIDOC ## getCameraDistance ### Description Gets the distance along the Z axis from the camera to this view. ### Method ```java public float getCameraDistance() ``` ``` -------------------------------- ### On Moved to Display Callback Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Called by the system when the hosting activity is moved from one display to another without recreation. Use this to track changes to displays if functionality relies on display properties. ```java public void onMovedToDisplay(int displayId, Configuration config) { } ``` -------------------------------- ### Handle Window Visibility Change Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initializes scroll bars when the view becomes visible. ```java protected void onWindowVisibilityChanged(@Visibility int visibility) { if (visibility == VISIBLE) { initialAwakenScrollBars(); } } ``` -------------------------------- ### getAccessibilityTraversalBefore Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the ID of a view before which this view is visited in accessibility traversal. ```APIDOC ## getAccessibilityTraversalBefore ### Description Gets the ID of a view before which this view is visited in accessibility traversal. Returns {@link #NO_ID} if no such view is specified. ### Method ```java public int getAccessibilityTraversalBefore() ``` ### Parameters None ### Response #### Success Response (200) * **return value** (int) - The ID of the preceding view in accessibility traversal, or {@link #NO_ID}. ``` -------------------------------- ### Configure Tree-sitter Grammar Highlighting with TsLanguage Source: https://context7.com/rosemoe/sora-editor/llms.txt Load native libraries and build a TsLanguageSpec using SCM query files. Map capture names to color scheme IDs for syntax highlighting. The theme can be updated at runtime, and the language spec is automatically closed when the language is disposed. ```kotlin // Load native libraries (typically in the Application companion object) System.loadLibrary("android-tree-sitter") System.loadLibrary("tree-sitter-java") // Build the language spec from scm query sources val javaSpec = TsLanguageSpec( language = TSLanguage.Java, highlightScmSource = assets.open("tree-sitter-queries/java/highlights.scm") .bufferedReader().readText(), codeBlocksScmSource = assets.open("tree-sitter-queries/java/blocks.scm") .bufferedReader().readText(), bracketsScmSource = assets.open("tree-sitter-queries/java/brackets.scm") .bufferedReader().readText() ) // Create language with theme mapping val javaLanguage = TsLanguage(javaSpec, tab = false) { // Map tree-sitter capture names → EditorColorScheme color IDs textStyle("keyword") { foreground = EditorColorScheme.KEYWORD } textStyle("string") { foreground = EditorColorScheme.LITERAL } textStyle("comment") { foreground = EditorColorScheme.COMMENT } textStyle("function") { foreground = EditorColorScheme.FUNCTION_NAME } textStyle("type") { foreground = EditorColorScheme.IDENTIFIER_NAME } textStyle("variable") { foreground = EditorColorScheme.IDENTIFIER_VAR } textStyle("number") { foreground = EditorColorScheme.LITERAL } } editor.setEditorLanguage(javaLanguage) // Update theme at runtime without recreating the language javaLanguage.updateTheme { textStyle("keyword") { foreground = EditorColorScheme.KEYWORD } } // Close the spec when the language is no longer needed (frees native memory) // Note: destroy() on the language calls languageSpec.close() automatically editor.setEditorLanguage(null) // releases javaLanguage → closes javaSpec ``` -------------------------------- ### Get Top Padding Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Returns the current top padding of the View in pixels. ```java @InspectableProperty public int getPaddingTop() { return mPaddingTop; } ``` -------------------------------- ### Request Focus (General) Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initiates a request to give focus to a specific view or its descendants. This is a general entry point for focus requests. ```java /** * Call this to try to give focus to a specific view or to one of its descendants. This is a ``` -------------------------------- ### getParent Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the parent of this view. Note that the parent is a ViewParent and not necessarily a View. ```APIDOC ## ViewParent getParent() ### Description Gets the parent of this view. Note that the parent is a ViewParent and not necessarily a View. ### Returns * **ViewParent** - Parent of this view. ``` -------------------------------- ### getAccessibilityWindowId Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the unique identifier of the window in which this View resides for accessibility purposes. ```APIDOC ## getAccessibilityWindowId() ### Description Gets the unique identifier of the window in which this View resides for accessibility purposes. ### Method GET ### Endpoint N/A (SDK Method) ### Parameters None ### Response #### Success Response (int) - Returns the accessibility window ID. Returns UNDEFINED_WINDOW_ID if attach info is not available. ``` -------------------------------- ### Apply View Flags and Initialize Components Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Sets view flags and initializes scrollbars and scroll indicators. This logic is executed after initial padding and view flags are set. ```java if (viewFlagMasks != 0) { setFlags(viewFlagValues, viewFlagMasks); } if (initializeScrollbars) { initializeScrollbarsInternal(a); } if (initializeScrollIndicators) { initializeScrollIndicatorsInternal(); } a.recycle(); ``` -------------------------------- ### Replace Built-in UI Components with Custom Implementations Source: https://context7.com/rosemoe/sora-editor/llms.txt Access and configure built-in UI components like auto-completion or the magnifier using `getComponent`. You can also replace these components with custom implementations by providing a new class instance. ```kotlin // Access and configure the auto-completion window val autoCompletion = editor.getComponent(EditorAutoCompletion::class.java) autoCompletion.isEnabled = true autoCompletion.setEnabledAnimation(true) // Disable the magnifier editor.getComponent(Magnifier::class.java).isEnabled = false // Replace the auto-completion window with a custom one class MyAutoCompletion(editor: CodeEditor) : EditorAutoCompletion(editor) { override fun applyColorScheme(colors: EditorColorScheme) { super.applyColorScheme(colors) // custom styling … } } editor.replaceComponent(EditorAutoCompletion::class.java, MyAutoCompletion(editor)) // Available built-in component types: // EditorAutoCompletion – floating completion popup // Magnifier – text magnifier on long press // EditorTextActionWindow – copy/paste/cut floating toolbar // EditorDiagnosticTooltipWindow – diagnostic message tooltip // EditorContextMenuCreator – long-press context menu ``` -------------------------------- ### View Rotation Property Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Provides a Property wrapper for setting and getting the rotation of a View. ```APIDOC ## View.ROTATION Property ### Description A Property wrapper around the `rotation` functionality handled by the `View#setRotation(float)` and `View#getRotation()` methods. ### Method `setValue(View object, float value)` `get(View object)` ### Parameters - `object` (View) - The target View object. - `value` (float) - The rotation value to set. ``` -------------------------------- ### Request Keyboard Shortcuts Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Placeholder method to request keyboard shortcuts. It currently does nothing. ```java public void requestKeyboardShortcuts(List data, int deviceId) { // Do nothing. } ``` -------------------------------- ### View Z Property Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Provides a Property wrapper for setting and getting the Z-order of a View. ```APIDOC ## View.Z Property ### Description A Property wrapper around the `z` functionality handled by the `View#setZ(float)` and `View#getZ()` methods. ### Method `setValue(View object, float value)` `get(View object)` ### Parameters - `object` (View) - The target View object. - `value` (float) - The Z-order value to set. ``` -------------------------------- ### setFitsSystemWindows Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Sets whether or not this view should account for system screen decorations and inset its content. ```APIDOC ## setFitsSystemWindows ### Description Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of {@link #fitSystemWindows(Rect)} will be executed. ### Method public void setFitsSystemWindows(boolean fitSystemWindows) ### Parameters #### Path Parameters - **fitSystemWindows** (boolean) - If true, then the default implementation of {@link #fitSystemWindows(Rect)} will be executed. ### Request Example ```java // Example usage view.setFitsSystemWindows(true); ``` ``` -------------------------------- ### Get Optical Insets Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the optical insets of the view. Computes them if they haven't been already. ```java public Insets getOpticalInsets() { if (mLayoutInsets == null) { mLayoutInsets = computeOpticalInsets(); } return mLayoutInsets; } ``` -------------------------------- ### Get Foreground Tint List Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the tint color applied to the foreground drawable, if any. ```java /** * Return the tint applied to the foreground drawable, if specified. * * @return the tint applied to the foreground drawable * @attr ref android.R.styleable#View_foregroundTint * @see #setForegroundTintList(ColorStateList) */ @InspectableProperty(name = "foregroundTint") @Nullable public ColorStateList getForegroundTintList() { return mForegroundInfo != null && mForegroundInfo.mTintInfo != null ? mForegroundInfo.mTintInfo.mTintList : null; } ``` -------------------------------- ### onInitializeAccessibilityNodeInfo Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets common properties like parent, bounds, package name, class name, content description, and states. ```APIDOC ## void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) ### Description Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets common properties like parent, bounds, package name, class name, content description, and states. ### Parameters #### Path Parameters - **info** (AccessibilityNodeInfo) - The AccessibilityNodeInfo to initialize. ``` -------------------------------- ### setOnKeyListener Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Registers a callback to be invoked when a hardware key is pressed in this view. ```APIDOC ## setOnKeyListener(OnKeyListener l) ### Description Register a callback to be invoked when a hardware key is pressed in this view. Key presses in software input methods will generally not trigger the methods of this listener. ### Method Signature public void setOnKeyListener(OnKeyListener l) ### Parameters #### Path Parameters - **l** (OnKeyListener) - the key listener to attach to this view ``` -------------------------------- ### getGlobalVisibleRect Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Gets the visible rectangle of the view in the root view's coordinate space. ```APIDOC ## getGlobalVisibleRect(Rect r, Point globalOffset) ### Description Sets {@code r} to the coordinates of the non-clipped area of this view in the coordinate space of the view's root view. Sets {@code globalOffset} to the offset of the view's x and y coordinates from the coordinate space origin, which is the top left corner of the root view irrespective of screen decorations and system UI elements. To convert {@code r} to coordinates relative to the top left corner of this view (without taking view rotations into account), offset {@code r} by the inverse values of {@code globalOffset}—{@code r.offset(-globalOffset.x, -globalOffset.y)}—which is equivalent to calling {@link #getLocalVisibleRect(Rect) getLocalVisibleRect(Rect)}. **Note:** Do not use this method to determine the size of a window in multi-window mode; use {@link WindowManager#getCurrentWindowMetrics()}. ### Parameters #### Path Parameters - **r** (Rect) - If the method returns true, contains the coordinates of the visible portion of this view in the coordinate space of the view's root view. If the method returns false, the contents of {@code r} are undefined. - **globalOffset** (Point) - If the method returns true, contains the offset of the x and y coordinates of this view from the top left corner of the view's root view. If the method returns false, the contents of {@code globalOffset} are undefined. The argument can be null (see {@link #getGlobalVisibleRect(Rect) getGlobalVisibleRect(Rect)}). ### Returns (boolean) - True if at least part of the view is visible within the root view; false if the view is completely clipped or translated out of the visible area of the root view. ``` ```APIDOC ## getGlobalVisibleRect(Rect r) ### Description Sets {@code r} to the coordinates of the non-clipped area of this view in the coordinate space of the view's root view. See {@link #getGlobalVisibleRect(Rect, Point) getGlobalVisibleRect(Rect, Point)} for more information. ### Parameters #### Path Parameters - **r** (Rect) - If the method returns true, contains the coordinates of the visible portion of this view in the coordinate space of the view's root view. If the method returns false, the contents of {@code r} are undefined. ### Returns (boolean) - True if at least part of the view is visible within the root view; false if the view is completely clipped or translated out of the visible area of the root view. ``` -------------------------------- ### Get View Elevation Source: https://github.com/rosemoe/sora-editor/blob/main/app/src/main/assets/samples/big_sample.txt Retrieves the base elevation of the view relative to its parent in pixels. ```java /** * The base elevation of this view relative to its parent, in pixels. * * @return The base depth position of the view, in pixels. */ @ViewDebug.ExportedProperty(category = "drawing") @InspectableProperty public float getElevation() { return mRenderNode.getElevation(); } ```