### Register Glyph Toy Service (Minimum Example) Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md This XML snippet shows the minimal configuration required to register a Glyph Toy service. It includes the essential metadata for the toy's name and preview image, ensuring it appears in the Glyph Toys manager list and allows users to see a preview in the settings. ```xml ``` -------------------------------- ### Construct GlyphMatrixObject Example Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md This example illustrates the process of constructing a GlyphMatrixObject named 'butterfly' by setting its image source, scale, orientation, and position using the builder pattern. ```java GlyphMatrixObject.Builder butterflyBuilder = new GlyphMatrixObject.Builder(); GlyphMatrixObject butterfly = butterflyBuilder .setImageSource(GlyphMatrixUtils.drawableToBitmap(getResources().getDrawable(R.drawable.butterfly))) .setScale(100) .setOrientation(0) .setPosition(0, 0) .setReverse(false) .build(); ``` -------------------------------- ### Register Glyph Toy Service (Full Example) Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md This XML snippet demonstrates the complete registration of a Glyph Toy service within the AndroidManifest.xml file. It includes all optional metadata fields for name, preview image, summary, introduction activity, long-press support, and Always-On Display support, providing enhanced functionality and user experience. ```xml ``` -------------------------------- ### Toy Lifecycle Management Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Manages the start and stop lifecycle of a Glyph Toy when it is selected or deselected by the user. Implements onBind to initialize the toy's experience and onUnbind to clean up resources. ```java import android.os.IBinder; import android.content.Intent; // ... other imports @Override public IBinder onBind(Intent intent) { init(); // Experience that you want to create when Glyph Toy is selected return null; } @Override public boolean onUnbind(Intent intent) { mGM.unInit(); mGM = null; mCallback = null; return false; } ``` -------------------------------- ### Glyph Toy Service Implementation in Java Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md This Java code demonstrates the core functionality of a Glyph Toy Service. It shows how to initialize the GlyphMatrixManager, handle service connection callbacks, register a device, and display a custom image (butterfly) on the Glyph Matrix. It includes methods for binding, unbinding, initialization, and displaying content. ```java public class GlyphToyService extends Service { private GlyphMatrixManager mGM; private GlyphMatrixManager.Callback mCallback; @Override public IBinder onBind(Intent intent) { init(); return null; } @Override public boolean onUnbind(Intent intent) { if (mGM != null) { mGM.turnOff(); mGM.unInit(); mGM = null; } mCallback = null; return false; } private void init() { mGM = GlyphMatrixManager.getInstance(getApplicationContext()); mCallback = new GlyphMatrixManager.Callback() { @Override public void onServiceConnected(ComponentName componentName) { mGM.register(Glyph.DEVICE_23112); action(); } @Override public void onServiceDisconnected(ComponentName componentName) { } }; mGM.init(mCallback); } private void action() { GlyphMatrixObject.Builder butterflyBuilder = new GlyphMatrixObject.Builder(); GlyphMatrixObject butterfly = butterflyBuilder .setImageSource(GlyphMatrixUtils.drawableToBitmap(getResources().getDrawable(R.drawable.butterfly))) .setScale(100) .setOrientation(0) .setPosition(0, 0) .setReverse(false) .build(); GlyphMatrixFrame.Builder frameBuilder = new GlyphMatrixFrame.Builder(); GlyphMatrixFrame frame = frameBuilder.addTop(butterfly).build(); mGM.setMatrixFrame(frame.render()); } } ``` -------------------------------- ### Glyph Matrix Manager Public Methods Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Provides methods for initializing, uninitializing, and managing the Glyph Matrix display. Includes functions for closing the app matrix, registering applications, and updating the matrix with raw color data or structured frame objects. Some methods have specific phone system version requirements. ```APIDOC init(Callback callback) - Binds the Service. Recommended to be called when components start. - Parameters: - callback: Callback function for binding. unInit() - Unbinds the Service. Recommended to be called when components end. closeAppMatrix() - Closes the app matrix display. Stops displaying content from your app. - Requires phone system version on 20250801 or later. register(String target) - Registers your app for service. - Sends the target device information. - For Phone 3, target should be Glyph.DEVICE_23112. - Parameters: - target: The target device identifier. setMatrixFrame(int[] color) - Updates the Glyph Matrix display using raw color data. - Expects a 25x25 integer array. - Parameters: - color: A 25x25 integer array representing the color data. setMatrixFrame(GlyphMatrixFrame frame) - Updates the Glyph Matrix display using a structured GlyphMatrixFrame object. - Parameters: - frame: The GlyphMatrixFrame object to display. setAppMatrixFrame(int[] color) - Updates the Glyph Matrix display with raw color data for app usage. - Same as setMatrixFrame(int[] color). - Requires phone system version on 20250801 or later. - Parameters: - color: A 25x25 integer array representing the color data. setAppMatrixFrame(GlyphMatrixFrame frame) - Updates the Glyph Matrix display with a structured GlyphMatrixFrame object for app usage. - Same as setMatrixFrame(GlyphMatrixFrame frame). - Requires phone system version on 20250801 or later. - Parameters: - frame: The GlyphMatrixFrame object to display. ``` -------------------------------- ### GlyphMatrixObject.Builder Public Methods Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Describes the public methods available in GlyphMatrixObject.Builder for configuring image source, text, position, orientation, brightness, and scale before building the GlyphMatrixObject. ```APIDOC GlyphMatrixObject.Builder: setImageSource(Object imagesource): void - Sets the image source. Must be a 1:1 bitmap. Higher resolutions may impact performance. setText(String text): void - Sets the string content to be displayed. setPosition(int x, int y): void - Sets the object's top-left corner position. setOrientation(int): void - Sets the object's clockwise rotation angle in degrees (0-360). setBrightness(int brightness): void - Sets the brightness level (0-255). Values above 255 are capped. setScale(int scale): void - Sets the scaling factor (0-200). Anchor point is the object's middle. build(): GlyphMatrixObject - Constructs and returns a GlyphMatrix Object instance. ``` -------------------------------- ### GlyphMatrixFrame.Builder Constructors and Methods Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Provides methods for constructing and configuring a GlyphMatrixFrame using the Builder pattern. Allows adding objects to different layers (top, mid, low) and building the final frame. ```APIDOC GlyphMatrixFrame.Builder: Builder() - Initializes a new Builder instance. - Creates an empty Builder ready for configuration. - Default Matrix size is 25x25. addTop(GlyphMatrixObject object) - Adds an object to the top layer, rendered above middle and low layers. - Parameters: - object: The GlyphMatrixObject to add. addMid(GlyphMatrixObject object) - Adds an object to the middle layer, rendered between top and low layers. - Parameters: - object: The GlyphMatrixObject to add. addLow(GlyphMatrixObject object) - Adds an object to the bottom layer, rendered below top and middle layers. - Parameters: - object: The GlyphMatrixObject to add. build(Context context) - Constructs and returns a new GlyphMatrixFrame instance. - Based on the currently accumulated settings. - Ready for display or further manipulation. - Parameters: - context: The application context. - Returns: GlyphMatrixFrame - The constructed GlyphMatrixFrame instance. ``` -------------------------------- ### GlyphMatrixObject.Builder Public Constructors Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Details the default values used by the GlyphMatrixObject.Builder if properties are not explicitly set. These include position, orientation, scale, and brightness. ```APIDOC GlyphMatrixObject.Builder: Builder(): N/A - Initializes with default values: Position (0, 0), Orientation 0 degrees, Scale 100, Brightness 255. ``` -------------------------------- ### Glyph Matrix Library Integration (Java/Gradle) Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Instructions for integrating the Glyph Matrix Android library (AAR file) into an Android project. This involves placing the AAR file in the 'libs' directory and adding it as a dependency in the 'build.gradle' file. ```gradle implementation files('libs/GlyphMatrixSDK.aar') ``` -------------------------------- ### GlyphMatrixObject Public Accessor Methods Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Provides details on the public accessor methods for GlyphMatrixObject, which allow retrieval of image source, position, orientation, scale, and brightness. ```APIDOC GlyphMatrixObject: getImageSource(): Object - Returns the image source object getPositionX(): Int - Returns the X-coordinate of the object's top-left corner. getPositionY(): Int - Returns the Y-coordinate of the object's top-left corner. getOrientation(): Int - Returns the counterclockwise rotation angle of the object from the original (default: 0) getScale(): Int - Returns the scaling factor of the object. (0-200, default: 100) getBrightness(): Int - Returns the brightness level of the object. (0-255, default: 255) ``` -------------------------------- ### GlyphMatrixFrame Rendering Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Renders all objects added via the Builder into Glyph Matrix data. This method can either directly drive hardware or return data for further processing. ```APIDOC GlyphMatrixFrame: render() - Renders all objects previously added via the Builder and integrates them into the corresponding Glyph Matrix data. - The implementation may vary depending on project requirements. - Can directly drive hardware or return array/bitmap data. - Returns: int[] - The rendered Glyph Matrix data. ``` -------------------------------- ### GlyphMatrixManager API Reference Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Provides direct control over the Glyph Matrix display from an application. It handles connecting/disconnecting to services, registering the application, and updating the display with raw color data or structured frames. Use setAppMatrixFrame for app-based control to avoid conflicts with active Glyph Toys. Requires phone system version on 20250801 or later. Note that Glyph Toys have higher display priority than app content. ```APIDOC GlyphMatrixManager: Responsibilities: - Connecting to and disconnecting from an underlying service or device. - Registering your application to use that service/device. - Updating the display of a Glyph Matrix with either raw color data or structured frame objects. Methods: setAppMatrixFrame(frame: FrameObject | RawColorData): Description: Directly controls the Glyph Matrix display from your own app. Usage: Use instead of setMatrixFrame to avoid conflicts with active Glyph Toys. Prerequisites: Phone system version on 20250801 or later. Note: Glyph Toy content has higher display priority and can override app content. setMatrixFrame(frame: FrameObject | RawColorData): Description: Updates the Glyph Matrix display. May conflict with active Glyph Toys. Display Priority: - Glyph Toys have a higher display priority than third-party app usage on the Glyph Matrix. - User interaction with the Glyph Button triggers a Glyph Toy carousel that overrides app content. ``` -------------------------------- ### Create and Render GlyphMatrixFrame Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md This snippet demonstrates how to create a GlyphMatrixFrame with a butterfly object on the top layer and render it to the Glyph Matrix using the GlyphMatrixManager (mGM). ```java GlyphMatrixFrame.Builder frameBuilder = new GlyphMatrixFrame.Builder(); GlyphMatrixFrame frame = frameBuilder.addTop(butterfly).build(); mGM.setMatrixFrame(frame.render()); ``` -------------------------------- ### Handling AOD Event Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Handles the AOD (Always-On Display) event for toys that support it. The toy receives the EVENT_AOD every minute when selected as the AOD toy. ```java import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Bundle; // ... other imports private final Handler serviceHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case GlyphToy.MSG_GLYPH_TOY: { Bundle bundle = msg.getData(); String event = bundle.getString(GlyphToy.MSG_GLYPH_TOY_DATA); if (GlyphToy.EVENT_AOD.equals(event)) { // Your action for aod } break; } default: super.handleMessage(msg); } } }; ``` -------------------------------- ### AndroidManifest.xml - Required Permission Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Specifies the necessary permission to be added to the AndroidManifest.xml file for enabling Glyph Matrix functionality. This permission is crucial for the Glyph Matrix SDK to operate. ```xml ``` -------------------------------- ### Handling Glyph Button Events (Long Press) Source: https://github.com/nothing-developer-programme/glyphmatrix-developer-kit/blob/main/README.md Handles user interactions with the Glyph Button, specifically the long press (change) event. Uses a Handler and Messenger to receive and process messages from the system, reacting to the EVENT_CHANGE. ```java import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Bundle; import android.os.IBinder; import android.content.Intent; import android.os.Messenger; // ... other imports @Override public IBinder onBind(Intent intent) { init(); return serviceMessenger.getBinder(); } private final Handler serviceHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case GlyphToy.MSG_GLYPH_TOY: { Bundle bundle = msg.getData(); String event = bundle.getString(GlyphToy.MSG_GLYPH_TOY_DATA); if (GlyphToy.EVENT_CHANGE.equals(event)) { // Your reaction for the long press. } break; } default: super.handleMessage(msg); } } }; private final Messenger serviceMessenger = new Messenger(serviceHandler); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.