diff --git a/README.md b/README.md index cbede38..ee99360 100644 --- a/README.md +++ b/README.md @@ -422,7 +422,36 @@ private void action() { ``` -### Other userful resource +### Example Projects + +#### Cricket Live Score Glyph Toy 🏏 +An AI-enhanced example showing how to build a real-world Glyph Toy that displays live cricket scores on the Glyph Matrix. This comprehensive example includes: + +- **Complete source code** - Production-ready implementation with API integration +- **Multiple display modes** - Score, run rate, overs, and match status displays +- **Smart features** - Favorite team filtering, auto-refresh, AOD support +- **Animated graphics** - Bouncing cricket ball and smooth text scrolling +- **Full documentation** - Setup guide, API integration, and customization tips + +📁 **Location**: [`cricket-score-example/`](cricket-score-example/) +📖 **Quick Start**: See [README.md](cricket-score-example/README.md) and [SETUP_GUIDE.md](cricket-score-example/SETUP_GUIDE.md) + +**Key Features**: +- Real-time score updates every 30 seconds +- Support for multiple cricket APIs (CricketData.org, Entity Sport, custom) +- Configuration activity for user preferences +- Long press Glyph Button to cycle display modes +- Intelligent caching to reduce API calls +- Mock data fallback for testing + +Perfect for learning: +- Glyph Matrix API usage patterns +- Service lifecycle management +- API integration and error handling +- Custom animations and text rendering +- User configuration with SharedPreferences + +### Other Useful Resources For a practical demo project on building Glyph Toys, see the [GlyphMatrix-Example-Project](https://github.com/KenFeng04/GlyphMatrix-Example-Project)
Kits for building a Glyph Interface experience around devices with a Glyph Light Stripe [Glyph-Developer-Kit](https://github.com/Nothing-Developer-Programme/Glyph-Developer-Kit) diff --git a/cricket-score-example/API_REFERENCE.md b/cricket-score-example/API_REFERENCE.md new file mode 100644 index 0000000..a9d7c99 --- /dev/null +++ b/cricket-score-example/API_REFERENCE.md @@ -0,0 +1,622 @@ +# Cricket Score Glyph Toy - API Reference + +## Quick Reference + +### Classes Overview + +| Class | Purpose | Key Methods | +|-------|---------|-------------| +| CricketScoreToyService | Main service managing display | onBind(), displayCurrentMatch() | +| CricketApiClient | Fetches cricket data | getLiveMatches() | +| CricketMatch | Data model for matches | getShortName(), isComplete() | +| CricketScoreConfig | User preferences | getFavoriteTeams(), setBrightness() | +| CricketScoreConfigActivity | Settings UI | saveConfiguration() | + +--- + +## CricketScoreToyService + +### Overview +Main Android Service that implements the Glyph Toy functionality. Manages the lifecycle, handles Glyph Button events, and renders frames to the LED matrix. + +### Lifecycle Methods + +#### `onCreate()` +```java +@Override +public void onCreate() +``` +Initialize service components, create handlers, and setup clients. + +#### `onBind(Intent intent)` +```java +@Override +public IBinder onBind(Intent intent) +``` +Called when toy is selected. Initializes Glyph Matrix and starts score updates. +- **Returns**: Messenger binder for receiving events +- **Calls**: initGlyphMatrix() + +#### `onUnbind(Intent intent)` +```java +@Override +public boolean onUnbind(Intent intent) +``` +Called when toy is deselected. Cleans up resources. +- **Returns**: false (no rebind needed) +- **Calls**: cleanup() + +### Display Methods + +#### `displayCurrentMatch()` +```java +private void displayCurrentMatch() +``` +Main display method that renders based on current display mode. +- Uses current match from mMatches[mCurrentMatchIndex] +- Switches between display modes + +#### `displayScore(CricketMatch match)` +```java +private void displayScore(CricketMatch match) +``` +Displays team scores with animated cricket ball. +- **Parameters**: match - The match to display +- **Creates**: Animated ball + scrolling text + +#### `displayRunRate(CricketMatch match)` +```java +private void displayRunRate(CricketMatch match) +``` +Shows current and required run rates. + +#### `displayOvers(CricketMatch match)` +```java +private void displayOvers(CricketMatch match) +``` +Shows overs information for both teams. + +#### `displayMatchStatus(CricketMatch match)` +```java +private void displayMatchStatus(CricketMatch match) +``` +Displays match status message. + +### Animation Methods + +#### `createCricketBallAnimation()` +```java +private GlyphMatrixObject createCricketBallAnimation() +``` +Creates animated cricket ball with bouncing effect. +- **Returns**: GlyphMatrixObject with animation +- Uses sine wave for smooth motion + +#### `startScrollAnimation()` +```java +private void startScrollAnimation() +``` +Starts timer for text scrolling and animations. +- Updates every ANIMATION_FRAME_DELAY ms +- Increments mAnimationFrame counter + +### Event Handlers + +#### Glyph Button Events +```java +private final Handler serviceHandler +``` +Handles messages from Glyph Button: +- `EVENT_CHANGE` - Long press (cycle display modes) +- `EVENT_AOD` - AOD update (refresh scores) +- `EVENT_ACTION_DOWN` - Button pressed +- `EVENT_ACTION_UP` - Button released + +### Constants + +```java +private static final int UPDATE_INTERVAL_MS = 30000; // 30s between API calls +private static final int SCROLL_DELAY_MS = 100; // Scroll speed +private static final int ANIMATION_FRAME_DELAY = 150; // Animation frame rate +``` + +--- + +## CricketApiClient + +### Overview +Handles all API communication with cricket score providers. Implements caching, retry logic, and fallback mechanisms. + +### Constructor + +```java +public CricketApiClient(Context context) +``` +- **Parameters**: context - Application context +- Initializes executor service for async operations + +### Main Methods + +#### `getLiveMatches(ApiCallback callback)` +```java +public void getLiveMatches(ApiCallback callback) +``` +Fetches live cricket matches. +- **Parameters**: callback - Receives results +- **Cache**: Returns cached data if < 15s old +- **Async**: Runs on background thread + +#### Callback Interface +```java +public interface ApiCallback { + void onSuccess(List matches); + void onError(String error); +} +``` + +### API Methods + +#### `fetchFromPrimaryApi()` +```java +private List fetchFromPrimaryApi() +``` +Fetches from main API (CricketData.org by default). +- **Returns**: List of matches or empty list +- Uses configured API key if available + +#### `fetchFromFallbackApi()` +```java +private List fetchFromFallbackApi() +``` +Called if primary API fails. +- **Returns**: Mock data for testing + +#### `makeHttpRequest(String url)` +```java +private String makeHttpRequest(String url) throws Exception +``` +Makes HTTP GET request. +- **Parameters**: url - API endpoint +- **Returns**: Response body as string +- **Timeout**: 10s connect, 10s read +- **Throws**: Exception on network errors + +### Parsing Methods + +#### `parseCricketDataResponse(String response)` +```java +private List parseCricketDataResponse(String response) +``` +Parses JSON from CricketData.org API. +- **Parameters**: response - JSON string +- **Returns**: List of parsed matches + +#### `calculateRunRates(CricketMatch match)` +```java +private void calculateRunRates(CricketMatch match) +``` +Calculates current and required run rates. +- **Modifies**: match.currentRunRate, match.requiredRunRate + +### Utility Methods + +#### `getMockMatches()` +```java +private List getMockMatches() +``` +Returns hardcoded mock matches for testing. +- **Returns**: 2 sample matches + +#### `shutdown()` +```java +public void shutdown() +``` +Shuts down executor service. + +--- + +## CricketMatch + +### Overview +Data model representing a cricket match. + +### Fields + +```java +// Match identification +public String id; +public String name; +public String matchType; // "T20", "ODI", "Test" +public String venue; + +// Teams +public String team1; +public String team2; + +// Scores +public String score1, score2; +public String wickets1, wickets2; +public String overs1, overs2; + +// State +public boolean isLive; +public String status; + +// Statistics +public double currentRunRate; +public double requiredRunRate; +``` + +### Methods + +#### `getShortName()` +```java +public String getShortName() +``` +Returns abbreviated match name (e.g., "IND vs AUS"). +- Uses getTeamAbbreviation() for short forms + +#### `getTeamAbbreviation(String teamName)` +```java +private String getTeamAbbreviation(String teamName) +``` +Converts team name to 3-letter abbreviation. +- **Examples**: "India" → "IND", "Australia" → "AUS" + +#### `isComplete()` +```java +public boolean isComplete() +``` +Checks if match has all required data. +- **Returns**: true if team1, team2, score1, overs1 are set + +--- + +## CricketScoreConfig + +### Overview +Manages user preferences using SharedPreferences. + +### Constructor + +```java +public CricketScoreConfig(Context context) +``` +- Creates/opens shared preferences file + +### Team Management + +#### `getFavoriteTeams()` +```java +public List getFavoriteTeams() +``` +Gets list of favorite teams. +- **Returns**: List of team names + +#### `setFavoriteTeams(List teams)` +```java +public void setFavoriteTeams(List teams) +``` +Sets favorite teams list. + +#### `addFavoriteTeam(String team)` +```java +public void addFavoriteTeam(String team) +``` +Adds a team to favorites (if not already present). + +#### `removeFavoriteTeam(String team)` +```java +public void removeFavoriteTeam(String team) +``` +Removes a team from favorites. + +### API Configuration + +#### `getApiKey()` / `setApiKey(String key)` +```java +public String getApiKey() +public void setApiKey(String apiKey) +``` +Get/set API key for cricket data provider. + +#### `getCustomApiUrl()` / `setCustomApiUrl(String url)` +```java +public String getCustomApiUrl() +public void setCustomApiUrl(String url) +``` +Get/set custom API endpoint URL. + +### Display Settings + +#### `getUpdateInterval()` / `setUpdateInterval(int seconds)` +```java +public int getUpdateInterval() +public void setUpdateInterval(int seconds) +``` +Get/set update interval (10-120 seconds). +- **Default**: 30 seconds + +#### `getBrightness()` / `setBrightness(int brightness)` +```java +public int getBrightness() +public void setBrightness(int brightness) +``` +Get/set LED brightness (0-255). +- **Default**: 255 + +#### `isAnimationsEnabled()` / `setAnimationsEnabled(boolean enabled)` +```java +public boolean isAnimationsEnabled() +public void setAnimationsEnabled(boolean enabled) +``` +Get/set animation preference. +- **Default**: true + +#### `getScrollSpeed()` / `setScrollSpeed(int speedMs)` +```java +public int getScrollSpeed() +public void setScrollSpeed(int speedMs) +``` +Get/set text scroll speed in milliseconds. +- **Default**: 100ms + +### Utility Methods + +#### `resetToDefaults()` +```java +public void resetToDefaults() +``` +Resets all preferences to default values. + +#### `getPopularTeams()` (static) +```java +public static List getPopularTeams() +``` +Returns list of popular international cricket teams. +- **Returns**: 13 major teams + +--- + +## CricketScoreConfigActivity + +### Overview +Configuration UI for user preferences. Activity for setting up favorite teams, API settings, and display options. + +### Lifecycle Methods + +#### `onCreate(Bundle savedInstanceState)` +```java +@Override +protected void onCreate(Bundle savedInstanceState) +``` +Initializes UI, loads current config, sets up listeners. + +### UI Methods + +#### `initializeViews()` +```java +private void initializeViews() +``` +Finds all views from layout XML. + +#### `createTeamCheckboxes()` +```java +private void createTeamCheckboxes() +``` +Dynamically creates checkboxes for popular teams. + +#### `loadCurrentConfig()` +```java +private void loadCurrentConfig() +``` +Loads saved preferences into UI controls. + +#### `setupListeners()` +```java +private void setupListeners() +``` +Attaches event listeners to buttons and controls. + +### Action Methods + +#### `saveConfiguration()` +```java +private void saveConfiguration() +``` +Saves all settings to SharedPreferences. + +#### `testConfiguration()` +```java +private void testConfiguration() +``` +Tests API connection and shows result. + +#### `navigateToGlyphToysManager()` +```java +private void navigateToGlyphToysManager() +``` +Opens system Glyph Toys Manager. +- Implements GDK best practice + +--- + +## Display Modes Enum + +```java +private enum DisplayMode { + SCORE, // Current score with animation + RUN_RATE, // Current and required run rate + OVERS, // Overs for both teams + MATCH_STATUS // Match status message +} +``` + +Cycled with long press on Glyph Button. + +--- + +## Usage Examples + +### Basic Service Usage + +```java +// Service is automatically bound when toy is selected +// No manual initialization needed +``` + +### API Client Usage + +```java +CricketApiClient client = new CricketApiClient(context); +client.getLiveMatches(new CricketApiClient.ApiCallback() { + @Override + public void onSuccess(List matches) { + // Handle matches + for (CricketMatch match : matches) { + Log.d(TAG, match.getShortName()); + } + } + + @Override + public void onError(String error) { + // Handle error + Log.e(TAG, "Error: " + error); + } +}); +``` + +### Configuration Usage + +```java +CricketScoreConfig config = new CricketScoreConfig(context); + +// Add favorite team +config.addFavoriteTeam("India"); + +// Set brightness +config.setBrightness(200); + +// Get settings +int interval = config.getUpdateInterval(); +List teams = config.getFavoriteTeams(); +``` + +### Creating Custom Display + +```java +private void displayCustom(CricketMatch match) { + // Create text object + GlyphMatrixObject textObj = new GlyphMatrixObject.Builder() + .setText("Your custom text") + .setPosition(5, 12) + .setBrightness(config.getBrightness()) + .build(); + + // Build frame + GlyphMatrixFrame frame = new GlyphMatrixFrame.Builder() + .addTop(textObj) + .build(); + + // Render + mGlyphManager.setMatrixFrame(frame.render()); +} +``` + +--- + +## Threading Model + +- **Main Thread**: UI operations, GlyphMatrix rendering +- **Background Thread**: API calls (ExecutorService) +- **Timer Threads**: Animations, scroll updates + +### Thread Safety + +- Use `Handler.post()` to update UI from background threads +- API client manages its own executor +- Config uses thread-safe SharedPreferences + +--- + +## Error Handling + +### API Errors +- Network failures: Retry with exponential backoff +- Empty response: Use mock data +- Parse errors: Log and continue + +### Display Errors +- No matches: Show "No matches" message +- No favorite teams playing: Show appropriate message +- Glyph service disconnected: Log warning + +--- + +## Performance Considerations + +### Memory +- Single instance services +- Cleanup in onUnbind() +- Cancel timers properly + +### Network +- Cache for 15 seconds +- Configurable update intervals +- Use WiFi when possible + +### Battery +- Reasonable update intervals (30s+) +- Efficient rendering +- Proper cleanup + +--- + +## Extension Points + +### Adding New Display Mode +1. Add to DisplayMode enum +2. Create display method +3. Add case in displayCurrentMatch() + +### Adding New API Provider +1. Add constants for API URL +2. Implement parsing method +3. Add to fetchFromFallbackApi() + +### Custom Animation +1. Override createCricketBallAnimation() +2. Adjust ANIMATION_FRAME_DELAY +3. Implement custom motion logic + +--- + +## Constants Reference + +```java +// Update intervals +UPDATE_INTERVAL_MS = 30000 // API fetch interval +SCROLL_DELAY_MS = 100 // Scroll speed +ANIMATION_FRAME_DELAY = 150 // Animation frame rate + +// Cache +CACHE_DURATION_MS = 15000 // API cache duration + +// Defaults +DEFAULT_UPDATE_INTERVAL = 30 // seconds +DEFAULT_BRIGHTNESS = 255 // max brightness +DEFAULT_SCROLL_SPEED = 100 // milliseconds +DEFAULT_SHOW_ANIMATIONS = true +``` + +--- + +## Related Documentation + +- [README.md](README.md) - Overview and features +- [SETUP_GUIDE.md](SETUP_GUIDE.md) - Installation instructions +- [Main GDK README](../README.md) - Glyph Matrix Developer Kit + +--- + +*Last updated: 2025* diff --git a/cricket-score-example/AndroidManifest_snippet.xml b/cricket-score-example/AndroidManifest_snippet.xml new file mode 100644 index 0000000..d8db168 --- /dev/null +++ b/cricket-score-example/AndroidManifest_snippet.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cricket-score-example/README.md b/cricket-score-example/README.md new file mode 100644 index 0000000..1b7c3a8 --- /dev/null +++ b/cricket-score-example/README.md @@ -0,0 +1,370 @@ +# Cricket Live Score - Glyph Matrix Toy 🏏 + +![Version](https://img.shields.io/badge/version-1.0-blue) +![Platform](https://img.shields.io/badge/platform-Nothing%20Phone-red) +![License](https://img.shields.io/badge/license-MIT-green) + +An AI-enhanced Glyph Matrix toy that displays live cricket scores on your Nothing Phone's LED matrix. Track your favorite teams and never miss a crucial moment! + +## ✨ Features + +### Core Functionality +- 🔴 **Real-time Score Updates** - Live scores updated every 30 seconds +- 🏏 **Animated Cricket Ball** - Smooth bouncing animation +- 📊 **Multiple Display Modes** - Score, Run Rate, Overs, Match Status +- ⭐ **Favorite Teams** - Filter matches by your favorite teams +- 🔄 **Smart Scrolling** - Auto-scrolling text for long team names +- 🌙 **AOD Support** - Always-On Display for continuous updates + +### AI-Enhanced Features +- **Smart Team Detection** - Automatically shows matches when your favorite teams are playing +- **Intelligent Caching** - Reduces API calls while keeping data fresh +- **Auto-fallback** - Multiple API sources with automatic failover +- **Adaptive Display** - Optimizes content based on match state + +### User Experience +- Long press Glyph Button to cycle through display modes +- Configurable update intervals (10-120 seconds) +- Adjustable brightness (0-255) +- Enable/disable animations +- Custom API endpoint support + +## 🚀 Quick Start + +### Prerequisites +- Nothing Phone 3 (or compatible device with Glyph Matrix) +- Android Studio Arctic Fox or later +- System version 20250829 or later (for some features) +- Java 8 or later + +### Installation + +1. **Clone or download this example** + ```bash + git clone + cd cricket-score-example + ``` + +2. **Copy the Glyph Matrix SDK** + ```bash + mkdir -p app/libs + cp ../glyph-matrix-sdk-1.0.aar app/libs/ + ``` + +3. **Open in Android Studio** + - File → Open → Select the project directory + - Wait for Gradle sync to complete + +4. **Add to your build.gradle** + ```gradle + dependencies { + implementation files('libs/glyph-matrix-sdk-1.0.aar') + } + ``` + +5. **Copy files to your project** + - Copy all `.java` files from `src/` to your app's package + - Copy `res/values/strings.xml` content to your strings.xml + - Add the service and activity declarations from `AndroidManifest_snippet.xml` to your AndroidManifest.xml + +6. **Build and install** + ```bash + ./gradlew installDebug + ``` + +## 📱 Usage + +### First Time Setup + +1. **Install the app** on your Nothing Phone +2. **Open the app** to configure settings +3. **Select favorite teams** (optional - leave empty to show all matches) +4. **Configure API settings** (optional - uses free API by default) +5. **Tap "Test Connection"** to verify API access +6. **Tap "Activate Toy"** to open Glyph Toys Manager +7. **Add the toy** to your active toys list + +### Using the Toy + +1. **Press Glyph Button** to cycle through toys until Cricket Score is selected +2. **Long press Glyph Button** to change display mode: + - **Score Mode**: Shows team scores with animated ball + - **Run Rate Mode**: Shows current and required run rates + - **Overs Mode**: Shows overs for each team + - **Status Mode**: Shows match status message + +### Display Modes + +#### Score Display +``` +🏏 🔴 LIVE: IND 185/5 (20.0) vs AUS 142/3 (15.2) +``` + +#### Run Rate Display +``` +CRR: 9.25 | RRR: 9.50 +``` + +#### Overs Display +``` +IND: 20.0 | AUS: 15.2 +``` + +#### Status Display +``` +India need 44 runs from 28 balls +``` + +## 🔧 Configuration + +### Favorite Teams +Select from popular international teams: +- India, Australia, England, Pakistan +- South Africa, New Zealand, Sri Lanka +- West Indies, Bangladesh, Afghanistan +- And more... + +### API Settings + +#### Using the Default Free API (CricketData.org) +No configuration needed! The app uses a free API by default with mock data fallback. + +#### Using Custom API +1. Get your API key from [CricketData.org](https://cricketdata.org) +2. Enter API key in settings (optional for free tier) +3. Or use a custom API endpoint + +#### Custom API Format +Your custom API should return JSON in this format: +```json +{ + "data": [ + { + "id": "match_123", + "name": "India vs Australia - T20", + "matchType": "T20", + "status": "live", + "venue": "Mumbai", + "teams": ["India", "Australia"], + "score": { + "team": [ + {"runs": "185", "wickets": "5", "overs": "20.0"}, + {"runs": "142", "wickets": "3", "overs": "15.2"} + ] + } + } + ] +} +``` + +### Display Preferences + +| Setting | Range | Default | Description | +|---------|-------|---------|-------------| +| Brightness | 0-255 | 255 | LED brightness level | +| Update Interval | 10-120s | 30s | How often to fetch new scores | +| Animations | On/Off | On | Enable cricket ball animation | +| Scroll Speed | 50-200ms | 100ms | Text scrolling speed | + +## 🏗️ Architecture + +### Project Structure +``` +cricket-score-example/ +├── src/ +│ ├── CricketScoreToyService.java # Main service +│ ├── CricketApiClient.java # API client +│ ├── CricketMatch.java # Data model +│ ├── CricketScoreConfig.java # Configuration +│ └── CricketScoreConfigActivity.java # Settings UI +├── res/ +│ └── values/ +│ └── strings.xml # String resources +├── AndroidManifest_snippet.xml # Manifest additions +├── build.gradle # Dependencies +└── README.md # This file +``` + +### Key Components + +#### CricketScoreToyService +- Extends Android `Service` +- Implements Glyph Matrix lifecycle (onBind, onUnbind) +- Manages timers for updates and animations +- Handles Glyph Button events +- Renders frames to LED matrix + +#### CricketApiClient +- Fetches data from cricket APIs +- Implements caching mechanism +- Auto-retry with exponential backoff +- Fallback to mock data for testing +- Thread-safe execution + +#### CricketMatch +- Data model for match information +- Team abbreviation generation +- Helper methods for display + +#### CricketScoreConfig +- SharedPreferences wrapper +- Manages user settings +- Provides default values +- Popular teams list + +## 🎨 Customization + +### Changing Animation +Edit `createCricketBallAnimation()` in `CricketScoreToyService.java`: +```java +private GlyphMatrixObject createCricketBallAnimation() { + // Customize animation here + int yOffset = (int) (Math.sin(mAnimationFrame * 0.3) * 3); + // ... +} +``` + +### Adding Display Modes +1. Add mode to `DisplayMode` enum +2. Create display method (e.g., `displayCustomMode()`) +3. Add case in `displayCurrentMatch()` + +### Using Different APIs +1. Implement parsing method in `CricketApiClient` +2. Add API URL constant +3. Update `fetchFromPrimaryApi()` or `fetchFromFallbackApi()` + +### Customizing Text Display +Modify `formatScoreText()` in `CricketScoreToyService.java`: +```java +private String formatScoreText(CricketMatch match) { + // Customize text format here + StringBuilder sb = new StringBuilder(); + // ... + return sb.toString(); +} +``` + +## 🐛 Troubleshooting + +### No matches showing +- Check internet connection +- Verify API key (if using paid tier) +- Test connection in settings +- Check if favorite teams are spelled correctly +- Try with empty favorite teams list + +### Matrix not lighting up +- Ensure device has Glyph Matrix support +- Check system version (20250829+ for some features) +- Verify service is registered in AndroidManifest.xml +- Test with other Glyph Toys to confirm hardware works + +### Slow updates +- Increase update interval +- Check API rate limits +- Verify network speed +- Enable caching + +### Animation stuttering +- Reduce scroll speed +- Lower update frequency +- Disable animations +- Reduce brightness + +## 📊 API Information + +### Supported APIs + +#### 1. CricketData.org (Default) +- **Free tier**: 100 requests/day +- **Rate limit**: Reasonable for personal use +- **Coverage**: ICC, IPL, BBL, and more +- **Documentation**: https://cricketdata.org/docs + +#### 2. Entity Sport +- **Free tier**: Limited +- **Rate limit**: Check documentation +- **Coverage**: Extensive +- **Documentation**: https://www.entitysport.com/ + +#### 3. Custom API +- Configure in settings +- Must follow JSON format (see Configuration section) + +### API Best Practices +- Use appropriate update intervals +- Implement caching +- Handle rate limits gracefully +- Provide fallback data + +## 🔒 Permissions + +Required permissions in AndroidManifest.xml: +```xml + + + +``` + +## 🚦 Performance Tips + +1. **Optimize Update Frequency** + - Use 30s for live matches + - Use 60s+ for general monitoring + - Enable caching + +2. **Reduce Resource Usage** + - Disable animations if not needed + - Lower brightness + - Limit number of favorite teams + +3. **Network Efficiency** + - Use WiFi when possible + - Monitor API quota + - Implement proper caching + +## 🤝 Contributing + +Contributions are welcome! Areas for improvement: +- Additional API integrations +- More animation styles +- Better error handling +- UI enhancements +- Performance optimizations + +## 📄 License + +This example is provided under the MIT License. See LICENSE file for details. + +## 🙏 Acknowledgments + +- Nothing for the Glyph Matrix Developer Kit +- Cricket API providers (CricketData.org, Entity Sport) +- Android developer community +- AI enhancement for intelligent features + +## 📞 Support + +For issues and questions: +- **GDK Issues**: [GDKsupport@nothing.tech](mailto:GDKsupport@nothing.tech) +- **Community**: [Nothing Community](https://nothing.community/t/glyph-sdk) +- **API Issues**: Check respective API provider documentation + +## 🔮 Future Enhancements + +Planned features: +- [ ] Player statistics display +- [ ] Match notifications +- [ ] Score predictions +- [ ] Historical match data +- [ ] Custom team logos +- [ ] Voice score updates +- [ ] Widget support +- [ ] Multi-language support + +--- + +**Built with ❤️ using AI enhancement for Nothing Phone Glyph Matrix** + +*Version 1.0 - Last updated: 2025* diff --git a/cricket-score-example/SETUP_GUIDE.md b/cricket-score-example/SETUP_GUIDE.md new file mode 100644 index 0000000..3b12672 --- /dev/null +++ b/cricket-score-example/SETUP_GUIDE.md @@ -0,0 +1,443 @@ +# Cricket Score Glyph Toy - Setup Guide + +## Step-by-Step Installation + +### 1. Project Setup + +#### Create a New Android Project +```bash +# In Android Studio +File → New → New Project +Select "Empty Activity" +Name: CricketScoreGlyph +Package: com.example.cricketglyph +Minimum SDK: API 29 (Android 10) +``` + +#### Project Structure +``` +app/ +├── src/ +│ └── main/ +│ ├── java/com/example/cricketglyph/ +│ │ ├── CricketScoreToyService.java +│ │ ├── CricketApiClient.java +│ │ ├── CricketMatch.java +│ │ ├── CricketScoreConfig.java +│ │ └── CricketScoreConfigActivity.java +│ ├── res/ +│ │ ├── values/ +│ │ │ └── strings.xml +│ │ ├── drawable/ +│ │ │ └── cricket_score_preview.xml (vector asset) +│ │ └── layout/ +│ │ └── activity_cricket_config.xml +│ └── AndroidManifest.xml +└── build.gradle +``` + +### 2. Copy Files + +#### Copy SDK +```bash +# Create libs directory +mkdir -p app/libs + +# Copy the Glyph Matrix SDK +cp /path/to/glyph-matrix-sdk-1.0.aar app/libs/ +``` + +#### Copy Source Files +Copy all Java files from the `cricket-score-example/src/` directory to your `app/src/main/java/com/example/cricketglyph/` directory. + +#### Copy Resources +Merge the content from `cricket-score-example/res/values/strings.xml` into your `app/src/main/res/values/strings.xml`. + +### 3. Configure build.gradle + +Add to your `app/build.gradle`: + +```gradle +android { + namespace 'com.example.cricketglyph' + compileSdk 34 + + defaultConfig { + applicationId "com.example.cricketglyph" + minSdk 29 + targetSdk 34 + versionCode 1 + versionName "1.0" + } +} + +dependencies { + // Glyph Matrix SDK + implementation files('libs/glyph-matrix-sdk-1.0.aar') + + // AndroidX + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' +} +``` + +### 4. Configure AndroidManifest.xml + +Add the following to your `AndroidManifest.xml`: + +#### Permissions (inside ``, before ``) +```xml + + + +``` + +#### Service and Activity (inside ``) +```xml + + + + + + + + + + + + + + + + + + + + + +``` + +### 5. Create Preview Image + +#### Option A: Use Figma Template +1. Visit the [Figma template](https://www.figma.com/design/ryjvvPM2ZxI3OGdajSzb5J/Glyph-Toy--preview-icon-template) +2. Design your cricket ball icon (recommended: 1:1 ratio, 512x512px) +3. Use the [Figma plugin](https://www.figma.com/community/plugin/1526505846480298025) to convert +4. Export as SVG + +#### Option B: Use Vector Asset Studio +1. In Android Studio: Right-click `res/drawable` → New → Vector Asset +2. Choose a cricket or sports icon from Material Icons +3. Name it: `cricket_score_preview` +4. Customize colors to match Glyph aesthetic (white on transparent) + +#### Simple SVG Example +Create `app/src/main/res/drawable/cricket_score_preview.xml`: +```xml + + + + + + + + + +``` + +### 6. Create Layout (Optional but Recommended) + +Create `app/src/main/res/layout/activity_cricket_config.xml`: + +```xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +