├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── dragosholban │ │ └── com │ │ └── androidpuzzlegame │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── img │ │ │ ├── bobby-burch-145906-unsplash.jpg │ │ │ ├── macie-jones-287939-unsplash.jpg │ │ │ ├── ricardo-gomez-angel-273521-unsplash.jpg │ │ │ ├── spencer-bryan-1891-unsplash.jpg │ │ │ └── yuriy-garnaev-395879-unsplash.jpg │ ├── java │ │ └── dragosholban │ │ │ └── com │ │ │ └── androidpuzzlegame │ │ │ ├── ImageAdapter.java │ │ │ ├── MainActivity.java │ │ │ ├── PuzzleActivity.java │ │ │ ├── PuzzlePiece.java │ │ │ └── TouchListener.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ ├── puzzle_frame.jpg │ │ └── table_background.jpg │ │ ├── drawable │ │ ├── ic_image_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_photo_camera_black_24dp.xml │ │ └── photo.jpg │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_puzzle.xml │ │ └── grid_element.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── file_paths.xml │ └── test │ └── java │ └── dragosholban │ └── com │ └── androidpuzzlegame │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidPuzzleGame 2 | This is the source code for the tutorial published on my website: [How to Build a Jigsaw Puzzle Android Game](https://dragosholban.com/2018/03/09/how-to-build-a-jigsaw-puzzle-android-game/) 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "dragosholban.com.androidpuzzlegame" 7 | minSdkVersion 16 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | implementation 'com.android.support:design:26.1.0' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/dragosholban/com/androidpuzzlegame/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("dragosholban.com.androidpuzzlegame", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/assets/img/bobby-burch-145906-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/assets/img/bobby-burch-145906-unsplash.jpg -------------------------------------------------------------------------------- /app/src/main/assets/img/macie-jones-287939-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/assets/img/macie-jones-287939-unsplash.jpg -------------------------------------------------------------------------------- /app/src/main/assets/img/ricardo-gomez-angel-273521-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/assets/img/ricardo-gomez-angel-273521-unsplash.jpg -------------------------------------------------------------------------------- /app/src/main/assets/img/spencer-bryan-1891-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/assets/img/spencer-bryan-1891-unsplash.jpg -------------------------------------------------------------------------------- /app/src/main/assets/img/yuriy-garnaev-395879-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/assets/img/yuriy-garnaev-395879-unsplash.jpg -------------------------------------------------------------------------------- /app/src/main/java/dragosholban/com/androidpuzzlegame/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Rect; 8 | import android.os.AsyncTask; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.BaseAdapter; 13 | import android.widget.ImageView; 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | 18 | public class ImageAdapter extends BaseAdapter { 19 | private Context mContext; 20 | private AssetManager am; 21 | private String[] files; 22 | 23 | public ImageAdapter(Context c) { 24 | mContext = c; 25 | am = mContext.getAssets(); 26 | try { 27 | files = am.list("img"); 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | public int getCount() { 34 | return files.length; 35 | } 36 | 37 | public Object getItem(int position) { 38 | return null; 39 | } 40 | 41 | public long getItemId(int position) { 42 | return 0; 43 | } 44 | 45 | // create a new ImageView for each item referenced by the Adapter 46 | public View getView(final int position, View convertView, ViewGroup parent) { 47 | if (convertView == null) { 48 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); 49 | convertView = layoutInflater.inflate(R.layout.grid_element, null); 50 | } 51 | 52 | final ImageView imageView = convertView.findViewById(R.id.gridImageview); 53 | imageView.setImageBitmap(null); 54 | // run image related code after the view was laid out 55 | imageView.post(new Runnable() { 56 | @Override 57 | public void run() { 58 | new AsyncTask() { 59 | private Bitmap bitmap; 60 | @Override 61 | protected Void doInBackground(Void... voids) { 62 | bitmap = getPicFromAsset(imageView, files[position]); 63 | return null; 64 | } 65 | 66 | @Override 67 | protected void onPostExecute(Void aVoid) { 68 | super.onPostExecute(aVoid); 69 | imageView.setImageBitmap(bitmap); 70 | } 71 | }.execute(); 72 | } 73 | }); 74 | 75 | return convertView; 76 | } 77 | 78 | private Bitmap getPicFromAsset(ImageView imageView, String assetName) { 79 | // Get the dimensions of the View 80 | int targetW = imageView.getWidth(); 81 | int targetH = imageView.getHeight(); 82 | 83 | if(targetW == 0 || targetH == 0) { 84 | // view has no dimensions set 85 | return null; 86 | } 87 | 88 | try { 89 | InputStream is = am.open("img/" + assetName); 90 | // Get the dimensions of the bitmap 91 | BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 92 | bmOptions.inJustDecodeBounds = true; 93 | BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions); 94 | int photoW = bmOptions.outWidth; 95 | int photoH = bmOptions.outHeight; 96 | 97 | // Determine how much to scale down the image 98 | int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 99 | 100 | is.reset(); 101 | 102 | // Decode the image file into a Bitmap sized to fill the View 103 | bmOptions.inJustDecodeBounds = false; 104 | bmOptions.inSampleSize = scaleFactor; 105 | bmOptions.inPurgeable = true; 106 | 107 | return BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions); 108 | } catch (IOException e) { 109 | e.printStackTrace(); 110 | 111 | return null; 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /app/src/main/java/dragosholban/com/androidpuzzlegame/MainActivity.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.Manifest; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.content.res.AssetManager; 7 | import android.graphics.Bitmap; 8 | import android.graphics.Canvas; 9 | import android.graphics.Matrix; 10 | import android.graphics.Paint; 11 | import android.graphics.Path; 12 | import android.graphics.PorterDuff; 13 | import android.graphics.PorterDuffXfermode; 14 | import android.graphics.drawable.BitmapDrawable; 15 | import android.graphics.drawable.Drawable; 16 | import android.net.Uri; 17 | import android.os.Environment; 18 | import android.provider.MediaStore; 19 | import android.support.annotation.NonNull; 20 | import android.support.constraint.ConstraintLayout; 21 | import android.support.v4.app.ActivityCompat; 22 | import android.support.v4.content.ContextCompat; 23 | import android.support.v4.content.FileProvider; 24 | import android.support.v7.app.AppCompatActivity; 25 | import android.os.Bundle; 26 | import android.view.View; 27 | import android.widget.AdapterView; 28 | import android.widget.GridView; 29 | import android.widget.ImageView; 30 | import android.widget.RelativeLayout; 31 | import android.widget.Toast; 32 | 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.text.SimpleDateFormat; 36 | import java.util.ArrayList; 37 | import java.util.Date; 38 | 39 | import static java.lang.Math.abs; 40 | 41 | public class MainActivity extends AppCompatActivity { 42 | String mCurrentPhotoPath; 43 | private static final int REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE = 2; 44 | private static final int REQUEST_IMAGE_CAPTURE = 1; 45 | static final int REQUEST_PERMISSION_READ_EXTERNAL_STORAGE = 3; 46 | static final int REQUEST_IMAGE_GALLERY = 4; 47 | 48 | @Override 49 | protected void onCreate(Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_main); 52 | 53 | AssetManager am = getAssets(); 54 | try { 55 | final String[] files = am.list("img"); 56 | 57 | GridView grid = findViewById(R.id.grid); 58 | grid.setAdapter(new ImageAdapter(this)); 59 | grid.setOnItemClickListener(new AdapterView.OnItemClickListener() { 60 | @Override 61 | public void onItemClick(AdapterView adapterView, View view, int i, long l) { 62 | Intent intent = new Intent(getApplicationContext(), PuzzleActivity.class); 63 | intent.putExtra("assetName", files[i % files.length]); 64 | startActivity(intent); 65 | } 66 | }); 67 | } catch (IOException e) { 68 | Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT); 69 | } 70 | } 71 | 72 | public void onImageFromCameraClick(View view) { 73 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 74 | if (intent.resolveActivity(getPackageManager()) != null) { 75 | File photoFile = null; 76 | try { 77 | photoFile = createImageFile(); 78 | } catch (IOException e) { 79 | Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG); 80 | } 81 | 82 | if (photoFile != null) { 83 | Uri photoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", photoFile); 84 | intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); 85 | startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); 86 | } 87 | } 88 | } 89 | 90 | private File createImageFile() throws IOException { 91 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 92 | // permission not granted, initiate request 93 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE); 94 | } else { 95 | // Create an image file name 96 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 97 | String imageFileName = "JPEG_" + timeStamp + "_"; 98 | File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 99 | File image = File.createTempFile( 100 | imageFileName, /* prefix */ 101 | ".jpg", /* suffix */ 102 | storageDir /* directory */ 103 | ); 104 | mCurrentPhotoPath = image.getAbsolutePath(); // save this to use in the intent 105 | 106 | return image; 107 | } 108 | 109 | return null; 110 | } 111 | 112 | @Override 113 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 114 | switch (requestCode) { 115 | case REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE: { 116 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 117 | onImageFromCameraClick(new View(this)); 118 | } 119 | 120 | return; 121 | } 122 | } 123 | } 124 | 125 | @Override 126 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 127 | if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 128 | Intent intent = new Intent(this, PuzzleActivity.class); 129 | intent.putExtra("mCurrentPhotoPath", mCurrentPhotoPath); 130 | startActivity(intent); 131 | } 132 | if (requestCode == REQUEST_IMAGE_GALLERY && resultCode == RESULT_OK) { 133 | Uri uri = data.getData(); 134 | 135 | Intent intent = new Intent(this, PuzzleActivity.class); 136 | intent.putExtra("mCurrentPhotoUri", uri.toString()); 137 | startActivity(intent); 138 | } 139 | } 140 | 141 | public void onImageFromGalleryClick(View view) { 142 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 143 | ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSION_READ_EXTERNAL_STORAGE); 144 | } else { 145 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 146 | intent.setType("image/*"); 147 | startActivityForResult(intent, REQUEST_IMAGE_GALLERY); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /app/src/main/java/dragosholban/com/androidpuzzlegame/PuzzleActivity.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.content.Intent; 4 | import android.content.res.AssetManager; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Canvas; 8 | import android.graphics.Matrix; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.PorterDuff; 12 | import android.graphics.PorterDuffXfermode; 13 | import android.graphics.Rect; 14 | import android.graphics.drawable.BitmapDrawable; 15 | import android.graphics.drawable.Drawable; 16 | import android.media.ExifInterface; 17 | import android.net.Uri; 18 | import android.support.v7.app.AppCompatActivity; 19 | import android.os.Bundle; 20 | import android.widget.ImageView; 21 | import android.widget.RelativeLayout; 22 | import android.widget.Toast; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.util.ArrayList; 27 | import java.util.Collections; 28 | import java.util.Random; 29 | 30 | import static java.lang.Math.abs; 31 | 32 | public class PuzzleActivity extends AppCompatActivity { 33 | ArrayList pieces; 34 | String mCurrentPhotoPath; 35 | String mCurrentPhotoUri; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_puzzle); 41 | 42 | final RelativeLayout layout = findViewById(R.id.layout); 43 | final ImageView imageView = findViewById(R.id.imageView); 44 | 45 | Intent intent = getIntent(); 46 | final String assetName = intent.getStringExtra("assetName"); 47 | mCurrentPhotoPath = intent.getStringExtra("mCurrentPhotoPath"); 48 | mCurrentPhotoUri = intent.getStringExtra("mCurrentPhotoUri"); 49 | 50 | // run image related code after the view was laid out 51 | // to have all dimensions calculated 52 | imageView.post(new Runnable() { 53 | @Override 54 | public void run() { 55 | if (assetName != null) { 56 | setPicFromAsset(assetName, imageView); 57 | } else if (mCurrentPhotoPath != null) { 58 | setPicFromPath(mCurrentPhotoPath, imageView); 59 | } else if (mCurrentPhotoUri != null) { 60 | imageView.setImageURI(Uri.parse(mCurrentPhotoUri)); 61 | } 62 | pieces = splitImage(); 63 | TouchListener touchListener = new TouchListener(PuzzleActivity.this); 64 | // shuffle pieces order 65 | Collections.shuffle(pieces); 66 | for (PuzzlePiece piece : pieces) { 67 | piece.setOnTouchListener(touchListener); 68 | layout.addView(piece); 69 | // randomize position, on the bottom of the screen 70 | RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) piece.getLayoutParams(); 71 | lParams.leftMargin = new Random().nextInt(layout.getWidth() - piece.pieceWidth); 72 | lParams.topMargin = layout.getHeight() - piece.pieceHeight; 73 | piece.setLayoutParams(lParams); 74 | } 75 | } 76 | }); 77 | } 78 | 79 | private void setPicFromAsset(String assetName, ImageView imageView) { 80 | // Get the dimensions of the View 81 | int targetW = imageView.getWidth(); 82 | int targetH = imageView.getHeight(); 83 | 84 | AssetManager am = getAssets(); 85 | try { 86 | InputStream is = am.open("img/" + assetName); 87 | // Get the dimensions of the bitmap 88 | BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 89 | bmOptions.inJustDecodeBounds = true; 90 | BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions); 91 | int photoW = bmOptions.outWidth; 92 | int photoH = bmOptions.outHeight; 93 | 94 | // Determine how much to scale down the image 95 | int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 96 | 97 | is.reset(); 98 | 99 | // Decode the image file into a Bitmap sized to fill the View 100 | bmOptions.inJustDecodeBounds = false; 101 | bmOptions.inSampleSize = scaleFactor; 102 | bmOptions.inPurgeable = true; 103 | 104 | Bitmap bitmap = BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions); 105 | imageView.setImageBitmap(bitmap); 106 | } catch (IOException e) { 107 | e.printStackTrace(); 108 | Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); 109 | } 110 | } 111 | 112 | private ArrayList splitImage() { 113 | int piecesNumber = 12; 114 | int rows = 4; 115 | int cols = 3; 116 | 117 | ImageView imageView = findViewById(R.id.imageView); 118 | ArrayList pieces = new ArrayList<>(piecesNumber); 119 | 120 | // Get the scaled bitmap of the source image 121 | BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 122 | Bitmap bitmap = drawable.getBitmap(); 123 | 124 | int[] dimensions = getBitmapPositionInsideImageView(imageView); 125 | int scaledBitmapLeft = dimensions[0]; 126 | int scaledBitmapTop = dimensions[1]; 127 | int scaledBitmapWidth = dimensions[2]; 128 | int scaledBitmapHeight = dimensions[3]; 129 | 130 | int croppedImageWidth = scaledBitmapWidth - 2 * abs(scaledBitmapLeft); 131 | int croppedImageHeight = scaledBitmapHeight - 2 * abs(scaledBitmapTop); 132 | 133 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledBitmapWidth, scaledBitmapHeight, true); 134 | Bitmap croppedBitmap = Bitmap.createBitmap(scaledBitmap, abs(scaledBitmapLeft), abs(scaledBitmapTop), croppedImageWidth, croppedImageHeight); 135 | 136 | // Calculate the with and height of the pieces 137 | int pieceWidth = croppedImageWidth/cols; 138 | int pieceHeight = croppedImageHeight/rows; 139 | 140 | // Create each bitmap piece and add it to the resulting array 141 | int yCoord = 0; 142 | for (int row = 0; row < rows; row++) { 143 | int xCoord = 0; 144 | for (int col = 0; col < cols; col++) { 145 | // calculate offset for each piece 146 | int offsetX = 0; 147 | int offsetY = 0; 148 | if (col > 0) { 149 | offsetX = pieceWidth / 3; 150 | } 151 | if (row > 0) { 152 | offsetY = pieceHeight / 3; 153 | } 154 | 155 | // apply the offset to each piece 156 | Bitmap pieceBitmap = Bitmap.createBitmap(croppedBitmap, xCoord - offsetX, yCoord - offsetY, pieceWidth + offsetX, pieceHeight + offsetY); 157 | PuzzlePiece piece = new PuzzlePiece(getApplicationContext()); 158 | piece.setImageBitmap(pieceBitmap); 159 | piece.xCoord = xCoord - offsetX + imageView.getLeft(); 160 | piece.yCoord = yCoord - offsetY + imageView.getTop(); 161 | piece.pieceWidth = pieceWidth + offsetX; 162 | piece.pieceHeight = pieceHeight + offsetY; 163 | 164 | // this bitmap will hold our final puzzle piece image 165 | Bitmap puzzlePiece = Bitmap.createBitmap(pieceWidth + offsetX, pieceHeight + offsetY, Bitmap.Config.ARGB_8888); 166 | 167 | // draw path 168 | int bumpSize = pieceHeight / 4; 169 | Canvas canvas = new Canvas(puzzlePiece); 170 | Path path = new Path(); 171 | path.moveTo(offsetX, offsetY); 172 | if (row == 0) { 173 | // top side piece 174 | path.lineTo(pieceBitmap.getWidth(), offsetY); 175 | } else { 176 | // top bump 177 | path.lineTo(offsetX + (pieceBitmap.getWidth() - offsetX) / 3, offsetY); 178 | path.cubicTo(offsetX + (pieceBitmap.getWidth() - offsetX) / 6, offsetY - bumpSize, offsetX + (pieceBitmap.getWidth() - offsetX) / 6 * 5, offsetY - bumpSize, offsetX + (pieceBitmap.getWidth() - offsetX) / 3 * 2, offsetY); 179 | path.lineTo(pieceBitmap.getWidth(), offsetY); 180 | } 181 | 182 | if (col == cols - 1) { 183 | // right side piece 184 | path.lineTo(pieceBitmap.getWidth(), pieceBitmap.getHeight()); 185 | } else { 186 | // right bump 187 | path.lineTo(pieceBitmap.getWidth(), offsetY + (pieceBitmap.getHeight() - offsetY) / 3); 188 | path.cubicTo(pieceBitmap.getWidth() - bumpSize,offsetY + (pieceBitmap.getHeight() - offsetY) / 6, pieceBitmap.getWidth() - bumpSize, offsetY + (pieceBitmap.getHeight() - offsetY) / 6 * 5, pieceBitmap.getWidth(), offsetY + (pieceBitmap.getHeight() - offsetY) / 3 * 2); 189 | path.lineTo(pieceBitmap.getWidth(), pieceBitmap.getHeight()); 190 | } 191 | 192 | if (row == rows - 1) { 193 | // bottom side piece 194 | path.lineTo(offsetX, pieceBitmap.getHeight()); 195 | } else { 196 | // bottom bump 197 | path.lineTo(offsetX + (pieceBitmap.getWidth() - offsetX) / 3 * 2, pieceBitmap.getHeight()); 198 | path.cubicTo(offsetX + (pieceBitmap.getWidth() - offsetX) / 6 * 5,pieceBitmap.getHeight() - bumpSize, offsetX + (pieceBitmap.getWidth() - offsetX) / 6, pieceBitmap.getHeight() - bumpSize, offsetX + (pieceBitmap.getWidth() - offsetX) / 3, pieceBitmap.getHeight()); 199 | path.lineTo(offsetX, pieceBitmap.getHeight()); 200 | } 201 | 202 | if (col == 0) { 203 | // left side piece 204 | path.close(); 205 | } else { 206 | // left bump 207 | path.lineTo(offsetX, offsetY + (pieceBitmap.getHeight() - offsetY) / 3 * 2); 208 | path.cubicTo(offsetX - bumpSize, offsetY + (pieceBitmap.getHeight() - offsetY) / 6 * 5, offsetX - bumpSize, offsetY + (pieceBitmap.getHeight() - offsetY) / 6, offsetX, offsetY + (pieceBitmap.getHeight() - offsetY) / 3); 209 | path.close(); 210 | } 211 | 212 | // mask the piece 213 | Paint paint = new Paint(); 214 | paint.setColor(0XFF000000); 215 | paint.setStyle(Paint.Style.FILL); 216 | 217 | canvas.drawPath(path, paint); 218 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 219 | canvas.drawBitmap(pieceBitmap, 0, 0, paint); 220 | 221 | // draw a white border 222 | Paint border = new Paint(); 223 | border.setColor(0X80FFFFFF); 224 | border.setStyle(Paint.Style.STROKE); 225 | border.setStrokeWidth(8.0f); 226 | canvas.drawPath(path, border); 227 | 228 | // draw a black border 229 | border = new Paint(); 230 | border.setColor(0X80000000); 231 | border.setStyle(Paint.Style.STROKE); 232 | border.setStrokeWidth(3.0f); 233 | canvas.drawPath(path, border); 234 | 235 | // set the resulting bitmap to the piece 236 | piece.setImageBitmap(puzzlePiece); 237 | 238 | pieces.add(piece); 239 | xCoord += pieceWidth; 240 | } 241 | yCoord += pieceHeight; 242 | } 243 | 244 | return pieces; 245 | } 246 | 247 | private int[] getBitmapPositionInsideImageView(ImageView imageView) { 248 | int[] ret = new int[4]; 249 | 250 | if (imageView == null || imageView.getDrawable() == null) 251 | return ret; 252 | 253 | // Get image dimensions 254 | // Get image matrix values and place them in an array 255 | float[] f = new float[9]; 256 | imageView.getImageMatrix().getValues(f); 257 | 258 | // Extract the scale values using the constants (if aspect ratio maintained, scaleX == scaleY) 259 | final float scaleX = f[Matrix.MSCALE_X]; 260 | final float scaleY = f[Matrix.MSCALE_Y]; 261 | 262 | // Get the drawable (could also get the bitmap behind the drawable and getWidth/getHeight) 263 | final Drawable d = imageView.getDrawable(); 264 | final int origW = d.getIntrinsicWidth(); 265 | final int origH = d.getIntrinsicHeight(); 266 | 267 | // Calculate the actual dimensions 268 | final int actW = Math.round(origW * scaleX); 269 | final int actH = Math.round(origH * scaleY); 270 | 271 | ret[2] = actW; 272 | ret[3] = actH; 273 | 274 | // Get image position 275 | // We assume that the image is centered into ImageView 276 | int imgViewW = imageView.getWidth(); 277 | int imgViewH = imageView.getHeight(); 278 | 279 | int top = (int) (imgViewH - actH)/2; 280 | int left = (int) (imgViewW - actW)/2; 281 | 282 | ret[0] = left; 283 | ret[1] = top; 284 | 285 | return ret; 286 | } 287 | 288 | public void checkGameOver() { 289 | if (isGameOver()) { 290 | finish(); 291 | } 292 | } 293 | 294 | private boolean isGameOver() { 295 | for (PuzzlePiece piece : pieces) { 296 | if (piece.canMove) { 297 | return false; 298 | } 299 | } 300 | 301 | return true; 302 | } 303 | 304 | private void setPicFromPath(String mCurrentPhotoPath, ImageView imageView) { 305 | // Get the dimensions of the View 306 | int targetW = imageView.getWidth(); 307 | int targetH = imageView.getHeight(); 308 | 309 | // Get the dimensions of the bitmap 310 | BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 311 | bmOptions.inJustDecodeBounds = true; 312 | BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 313 | int photoW = bmOptions.outWidth; 314 | int photoH = bmOptions.outHeight; 315 | 316 | // Determine how much to scale down the image 317 | int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 318 | 319 | // Decode the image file into a Bitmap sized to fill the View 320 | bmOptions.inJustDecodeBounds = false; 321 | bmOptions.inSampleSize = scaleFactor; 322 | bmOptions.inPurgeable = true; 323 | 324 | Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 325 | Bitmap rotatedBitmap = bitmap; 326 | 327 | // rotate bitmap if needed 328 | try { 329 | ExifInterface ei = new ExifInterface(mCurrentPhotoPath); 330 | int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); 331 | switch (orientation) { 332 | case ExifInterface.ORIENTATION_ROTATE_90: 333 | rotatedBitmap = rotateImage(bitmap, 90); 334 | break; 335 | case ExifInterface.ORIENTATION_ROTATE_180: 336 | rotatedBitmap = rotateImage(bitmap, 180); 337 | break; 338 | case ExifInterface.ORIENTATION_ROTATE_270: 339 | rotatedBitmap = rotateImage(bitmap, 270); 340 | break; 341 | } 342 | } catch (IOException e) { 343 | Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); 344 | } 345 | 346 | imageView.setImageBitmap(rotatedBitmap); 347 | } 348 | 349 | public static Bitmap rotateImage(Bitmap source, float angle) { 350 | Matrix matrix = new Matrix(); 351 | matrix.postRotate(angle); 352 | return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), 353 | matrix, true); 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /app/src/main/java/dragosholban/com/androidpuzzlegame/PuzzlePiece.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.content.Context; 4 | 5 | public class PuzzlePiece extends android.support.v7.widget.AppCompatImageView { 6 | public int xCoord; 7 | public int yCoord; 8 | public int pieceWidth; 9 | public int pieceHeight; 10 | public boolean canMove = true; 11 | 12 | public PuzzlePiece(Context context) { 13 | super(context); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/dragosholban/com/androidpuzzlegame/TouchListener.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import android.view.MotionEvent; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.RelativeLayout; 7 | 8 | import static java.lang.Math.pow; 9 | import static java.lang.Math.sqrt; 10 | import static java.lang.StrictMath.abs; 11 | 12 | public class TouchListener implements View.OnTouchListener { 13 | private float xDelta; 14 | private float yDelta; 15 | private PuzzleActivity activity; 16 | 17 | public TouchListener(PuzzleActivity activity) { 18 | this.activity = activity; 19 | } 20 | 21 | @Override 22 | public boolean onTouch(View view, MotionEvent motionEvent) { 23 | float x = motionEvent.getRawX(); 24 | float y = motionEvent.getRawY(); 25 | final double tolerance = sqrt(pow(view.getWidth(), 2) + pow(view.getHeight(), 2)) / 10; 26 | 27 | PuzzlePiece piece = (PuzzlePiece) view; 28 | if (!piece.canMove) { 29 | return true; 30 | } 31 | 32 | RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams(); 33 | switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) { 34 | case MotionEvent.ACTION_DOWN: 35 | xDelta = x - lParams.leftMargin; 36 | yDelta = y - lParams.topMargin; 37 | piece.bringToFront(); 38 | break; 39 | case MotionEvent.ACTION_MOVE: 40 | lParams.leftMargin = (int) (x - xDelta); 41 | lParams.topMargin = (int) (y - yDelta); 42 | view.setLayoutParams(lParams); 43 | break; 44 | case MotionEvent.ACTION_UP: 45 | int xDiff = abs(piece.xCoord - lParams.leftMargin); 46 | int yDiff = abs(piece.yCoord - lParams.topMargin); 47 | if (xDiff <= tolerance && yDiff <= tolerance) { 48 | lParams.leftMargin = piece.xCoord; 49 | lParams.topMargin = piece.yCoord; 50 | piece.setLayoutParams(lParams); 51 | piece.canMove = false; 52 | sendViewToBack(piece); 53 | activity.checkGameOver(); 54 | } 55 | break; 56 | } 57 | 58 | return true; 59 | } 60 | 61 | public void sendViewToBack(final View child) { 62 | final ViewGroup parent = (ViewGroup)child.getParent(); 63 | if (null != parent) { 64 | parent.removeView(child); 65 | parent.addView(child, 0); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/puzzle_frame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/drawable-xxhdpi/puzzle_frame.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/table_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/drawable-xxhdpi/table_background.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_image_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_photo_camera_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/drawable/photo.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 27 | 28 | 41 | 42 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_puzzle.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 | 39 | 40 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/grid_element.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidPuzzleGame 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/xml/file_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/test/java/dragosholban/com/androidpuzzlegame/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package dragosholban.com.androidpuzzlegame; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.0.1' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosholban/AndroidPuzzleGame/6da3eafc6188ca1afe5ac19eff096f27297f6e9e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Mar 08 10:15:47 EET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------