Skip to main content

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.

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.

How to Start the Puzzle

The puzzle flow begins from FinalmainScreen, which calls puzzlemain() to launch Puzzlemainscreen. Once the player chooses their image and taps Play, Puzzlestart loads and the game begins.
1

Launch Puzzlemainscreen

FinalmainScreen.puzzlemain() fires an Intent targeting Puzzlemainscreen. The screen locks to portrait orientation and inflates activity_puzzlemainscreen.
2

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.
3

Start the Game

Tap Play to pass the chosen image to Puzzlestart, which sets up the tile grid and begins the puzzle.

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.
On Android 6.0 (API 23) and above, CAMERA and WRITE_EXTERNAL_STORAGE are runtime permissions. The app prompts the user before launching the camera. If either permission is denied, the capture flow will not proceed. Make sure to handle the permission denial gracefully in your builds.

Play Button Logic

bplay_game.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent2 = new Intent(Puzzlemainscreen.this, Puzzlestart.class);
        if (IMGBitmap != null) {
            intent.putExtra("bmIMG", IMGBitmap);
            startActivity(intent);
        } else {
            intent2.putExtra("bmIMG", "Birds");
            startActivity(intent2);
        }
    }
});
When 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"); if null, R.drawable.birds is loaded as the fallback.
  • A reference ImageView (imgshow) displays the completed image so kids know what they are building.
  • The custom PuzzleLayout view group (R.id.activity_swipe_card) handles all tile rendering. The image and grid size are applied with:
puzzleLayout.setImage(IMG, squareRootNum);

Tile Swap Logic

All puzzle state is managed by DataHelper, 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.
MethodDescription
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

N = -1  →  No valid swap
L =  0  →  Slide Left
T =  1  →  Slide Up
R =  2  →  Slide Right
B =  3  →  Slide Down

Bitmap Rotation Helper

Puzzlemainscreen exposes a static utility for rotating captured images before they enter the puzzle:
public static Bitmap RotateBitmap(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0,
            source.getWidth(), source.getHeight(), matrix, true);
}

Completing the Puzzle

PuzzleLayout fires OnCompleteCallback.onComplete() when the last tile snaps into place. Puzzlestart responds with an 800 ms delay before calling run():
onComplete() → postDelayed(this, 800) → run()
Inside run():
  • squareRootNum is 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.
During gameplay, holding a finger anywhere on the screen toggles ivTips — a semi-transparent overlay showing the fully assembled reference image. This helps younger players figure out where tiles belong without giving up entirely.

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.

Build docs developers (and LLMs) love