How mmilord/cribbageforchromecast works
Project Type and Purpose
• This is an Android “sender” application that uses Google’s Cast SDK to implement a multiplayer Cribbage game.
• It comprises two parts:
• An Android client (“sender”) written in Java/Kotlin (app/)
• A simple HTML/JS “receiver” loaded on the Chromecast device (Chromecast/)
File-Structure Analysis
• Top-level:
• app/ – Contains the Android Studio project (src, res, Gradle scripts)
• Chromecast/ – Contains two static HTML files (chromecast.html, chromcastreceiver.html) for the Chromecast receiver.
• build.gradle, settings.gradle, gradle/… – Build and wrapper configuration.
• Inside app/src/main:
• java/cast/chrome/cribbageforchromecast/Model – Core game classes (Card, Deck, Player, DealerCardManagement).
• …/Interfaces – Abstractions for CastGameInterface, LocalGameInterface, JSONSerializable.
• …/NewStuff – Controllers and listeners for Cast<–>Game comms (ChromecastControl, CastToGSListener, JSONHandler, SendKeys/ReceiveKeys, GameState).
• …/Utils – Utility classes (MessageService, DrawingAndAnimating, Scoring, AppPreferences, ChromecastManagement).
• res/ – Layouts, drawables, animations, menus, values (strings, styles, themes).
• Test code under app/src/androidTest replicates the package structure for instrumentation tests.
README Insights
• Purpose: two-player Cribbage via Chromecast; receiver app must be uploaded in Cast Developer Console.
• Key steps: configure app_id and namespace in /res/values/strings.xml.
• Roadmap items reference a pending MVC refactor, state-save on reconnection, fragment layouts, etc.
a. Main Components
1. Android Sender App
• UI Layer (Activities: PrimaryActivity, CrazyEightsActivity, UserSettingsActivity)
• Controller Layer (ChromecastControl, MessageService, JSONHandler)
• Model Layer (Card, Deck, Player, GameState)
• Cast SDK Sender Module (com.google.android.gms.cast.*)
2. Google Cast Infrastructure
• Discovery & Session Manager on the Android device
• Network layer (mDNS, WebSockets under the hood)
3. Chromecast Receiver App
• HTML + JavaScript entry point (chromecast.html)
• Receiver logic (chromcastreceiver.html) that listens on the same namespace
4. External Dependencies
• Google Cast Developer Console (to register/update receiver)
• Android OS (Lollipop+), Google Play Services
b. Interactions & Data Flow
1. User taps “Start Game” in Android UI → Activity invokes ChromecastControl.startSession()
2. Cast SDK establishes a session with Chromecast → loads HTML receiver
3. Android Sender → sends JSON messages (SendKeys) via CastMessageParserLocal → network transport
4. Chromecast Receiver JS → parses JSON → updates game board on TV
5. Receiver → can send messages back if needed (e.g., game events)
6. LocalGameInterface allows play without Cast for testing or fallback.
c. Architectural Patterns & Principles
• MVC separation (planned): Model classes under Model/, View = Android layouts + Chromecast HTML, Controller = NewStuff/ utilities.
• Interface-based abstraction (CastGameInterface vs LocalGameInterface) for pluggable backends.
• JSON-based messaging over Cast data channel for decoupled comms.
d. Key Technologies & Frameworks
• Android SDK (Activities, Resources, Gradle)
• Google Cast SDK (Sender, Receiver)
• Java JSON serialization (custom JSONSerializable, JSONHandler)
• HTML/CSS/JavaScript on receiver side
Detail Level
• Break out sub-components: UI vs Model vs Messaging vs Receiver logic.
• Interfaces (CastGameInterface, JSONSerializable) to show extension points.
• External requirements (Cast Dev Console, Play Services) as contextual notes.