The Puzzle feature lets kids snap a photo with the device camera — or use the built-in bird image — and then reassemble it as a 3×3 sliding tile puzzle. As they progress, the grid grows larger, increasing the challenge while reinforcing spatial reasoning and fine-motor skills.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/SaadAhmed1122/Kids_learnig_App/llms.txt
Use this file to discover all available pages before exploring further.
How to Start the Puzzle
The puzzle flow begins fromFinalmainScreen, which calls puzzlemain() to launch Puzzlemainscreen. Once the player chooses their image and taps Play, Puzzlestart loads and the game begins.
Launch Puzzlemainscreen
FinalmainScreen.puzzlemain() fires an Intent targeting Puzzlemainscreen. The screen locks to portrait orientation and inflates activity_puzzlemainscreen.Choose Your Image
A default bird image (
R.drawable.birds) is shown in the central ImageView. The player can keep it or tap Take Photo to capture their own image with the device camera.Setup Screen
Puzzlemainscreen presents two action buttons alongside the preview image.
Take Photo
The bfoto_cap button requests
CAMERA and WRITE_EXTERNAL_STORAGE permissions (PERMIS_CAMARA = 200), then fires an ACTION_IMAGE_CAPTURE intent (PERMIS_CAPTURA_IMATGE = 300). When the camera returns (onActivityResult), the resulting Bitmap is read from extras.get("data") and stored in IMGBitmap.Play
The bplay_game button passes the selected image — or the default bird string — to
Puzzlestart via an Intent extra ("bmIMG"). If no photo was taken, the string "Birds" is sent instead, and Puzzlestart loads R.drawable.birds automatically.Play Button Logic
IMGBitmap is non-null (a photo was captured), it is bundled as a Parcelable extra. Otherwise the string "Birds" signals Puzzlestart to fall back to the built-in drawable.
Puzzle Mechanics
Puzzlestart implements both Runnable and View.OnTouchListener, and inflates activity_puzzlestart.
Grid Setup
- squareRootNum starts at
3, producing a 3×3 grid of tiles. - The bitmap is retrieved via
intent.getParcelableExtra("bmIMG"); ifnull,R.drawable.birdsis loaded as the fallback. - A reference
ImageView(imgshow) displays the completed image so kids know what they are building. - The custom
PuzzleLayoutview group (R.id.activity_swipe_card) handles all tile rendering. The image and grid size are applied with:
Tile Swap Logic
All puzzle state is managed byDataHelper, which maintains a List<Block>. Each Block carries a target position, a horizontal position (hPosition), and a vertical position (vPosition). One tile is always the invisible (blank) tile at index 0, which neighbouring tiles slide into.
| Method | Description |
|---|---|
setSquareRootNum(int) | Initializes the block list with squareRootNum × squareRootNum entries |
swapValueWithInvisibleModel(int) | Swaps the tile at the given index with the invisible blank tile |
isCompleted() | Returns true when every model.position equals its list index |
getScrollDirection(int) | Returns L, T, R, or B if the tile is adjacent to the blank; otherwise returns N (no move) |
Direction Constants
Bitmap Rotation Helper
Puzzlemainscreen exposes a static utility for rotating captured images before they enter the puzzle:
Completing the Puzzle
PuzzleLayout fires OnCompleteCallback.onComplete() when the last tile snaps into place. Puzzlestart responds with an 800 ms delay before calling run():
run():
squareRootNumis incremented.- If
squareRootNum > 2(i.e., the player has already completed the easier grids),showDialog()is called. - Otherwise the puzzle resets with a larger grid, using the same image.
Win Dialog
showDialog() builds an AlertDialog using the string resources R.string.TituloGanar (title) and R.string.DescGanar (message). Tapping OK closes the Activity, returning the player to the main screen.
Ads Integration
AdsClass.showintertialeAds() is called inside Puzzlemainscreen.onCreate() to display an interstitial ad at the natural pause before the game starts, keeping ad interruptions away from active gameplay.