diff --git a/solver/src/main/java/mg/rivolink/app/sudokusolver/ImageActivity.java b/solver/src/main/java/mg/rivolink/app/sudokusolver/ImageActivity.java
index acf645c..0c3e3f9 100644
--- a/solver/src/main/java/mg/rivolink/app/sudokusolver/ImageActivity.java
+++ b/solver/src/main/java/mg/rivolink/app/sudokusolver/ImageActivity.java
@@ -1,28 +1,29 @@
package mg.rivolink.app.sudokusolver;
+import mg.rivolink.app.sudokusolver.core.SolverCore;
+import mg.rivolink.app.sudokusolver.core.sudoku.bfb.SolverBFB;
+import mg.rivolink.app.sudokusolver.core.tess.TessBaseAPI;
+
+import org.opencv.android.OpenCVLoader;
+import org.opencv.android.BaseLoaderCallback;
+import org.opencv.android.LoaderCallbackInterface;
+
+import android.os.Bundle;
+import android.net.Uri;
import android.app.ProgressDialog;
+import android.view.View;
+import android.widget.Toast;
+import android.widget.ImageView;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.net.Uri;
-import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.Toast;
import java.io.InputStream;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import mg.rivolink.app.sudokusolver.core.SolverCore;
-import mg.rivolink.app.sudokusolver.core.sudoku.bfb.SolverBFB;
-import mg.rivolink.app.sudokusolver.core.tess.TessBaseAPI;
-
-import org.opencv.android.BaseLoaderCallback;
-import org.opencv.android.LoaderCallbackInterface;
-import org.opencv.android.OpenCVLoader;
-
public class ImageActivity extends AppCompatActivity{
private static final int FILE_KEY=89;
@@ -68,17 +69,26 @@ public void onClick(View view){
actions();
}
});
+
+
+ if(getIntent().getStringExtra("image")!=null) try{
+ String filename=getIntent().getStringExtra("image");
+ FileInputStream is=this.openFileInput(filename);
+ imageView.setImageBitmap(bmp=BitmapFactory.decodeStream(is));
+ is.close();
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
- if(getIntent().getData()!=null){
- try{
- Uri uri=getIntent().getData();
- InputStream is=getContentResolver().openInputStream(uri);
- imageView.setImageBitmap(bmp=BitmapFactory.decodeStream(is));
- }
- catch(FileNotFoundException e){
- e.printStackTrace();
- }
- }
+ else if(getIntent().getData()!=null) try{
+ Uri uri=getIntent().getData();
+ InputStream is=getContentResolver().openInputStream(uri);
+ imageView.setImageBitmap(bmp=BitmapFactory.decodeStream(is));
+ }
+ catch(FileNotFoundException e){
+ e.printStackTrace();
+ }
}
diff --git a/solver/src/main/java/mg/rivolink/app/sudokusolver/PlayActivity.java b/solver/src/main/java/mg/rivolink/app/sudokusolver/PlayActivity.java
index d14bb03..8f5365f 100644
--- a/solver/src/main/java/mg/rivolink/app/sudokusolver/PlayActivity.java
+++ b/solver/src/main/java/mg/rivolink/app/sudokusolver/PlayActivity.java
@@ -1,14 +1,23 @@
package mg.rivolink.app.sudokusolver;
+import java.io.FileOutputStream;
import java.util.List;
import java.util.LinkedList;
import android.os.Bundle;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
import android.view.View;
import android.widget.Toast;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
+import android.content.Intent;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.graphics.Color;
+import android.graphics.Canvas;
+import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import mg.rivolink.app.sudokusolver.core.sudoku.SudokuGenerator;
@@ -93,13 +102,59 @@ public void onMenuSelect(PlayPopup.Menu menu,int filled){
break;
}
case Export:{
- Toast.makeText(this,"Export",Toast.LENGTH_SHORT).show();
-
- break;
+ final ProgressDialog dialog=ProgressDialog.show(this,"","Please wait...",true);
+ final String filename="bitmap.png";
+
+ new Thread(){
+ @Override
+ public void run(){
+ export(filename);
+ runOnUiThread(new Runnable(){
+ @Override
+ public void run(){
+ dialog.cancel();
+
+ Intent intent=new Intent(PlayActivity.this,ImageActivity.class);
+ intent.putExtra("image",filename);
+
+ startActivity(intent);
+ }
+ });
+ }
+ }.start();
}
}
}
+ private void export(String filename){
+ View card=findViewById(R.id.card_grid);
+ card.setDrawingCacheEnabled(true);
+ card.buildDrawingCache();
+ Bitmap bmp=Bitmap.createBitmap(card.getDrawingCache());
+ card.setDrawingCacheEnabled(false);
+ card.destroyDrawingCache();
+
+ int border=30;
+ Bitmap bmpBorder=Bitmap.createBitmap(bmp.getWidth()+2*border,bmp.getHeight()+2*border,bmp.getConfig());
+ Canvas canvas=new Canvas(bmpBorder);
+ canvas.drawColor(Color.WHITE);
+ canvas.drawBitmap(bmp,border,border,null);
+
+ try {
+
+ FileOutputStream stream=this.openFileOutput(filename,Context.MODE_PRIVATE);
+ bmpBorder.compress(Bitmap.CompressFormat.PNG,100,stream);
+
+ stream.close();
+ bmp.recycle();
+ bmpBorder.recycle();
+
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
public void onPause(View view){
paused=!paused;
@@ -178,16 +233,27 @@ private boolean verifyUserSoluce(){
@Override
public void run(){
- boolean solved=verifyUserSoluce();
- final String text=(solved)?"Solved":"Wrong";
-
- this.runOnUiThread(new Runnable(){
+ final boolean solved=verifyUserSoluce();
+
+ runOnUiThread(new Runnable(){
@Override
public void run(){
- Toast.makeText(PlayActivity.this,text,Toast.LENGTH_SHORT).show();
+ if(!solved)
+ Toast.makeText(PlayActivity.this,"Wrong...,",Toast.LENGTH_SHORT).show();
+ else{
+ AlertDialog alertDialog = new AlertDialog.Builder(PlayActivity.this).create();
+ alertDialog.setTitle("Sudoku Solved");
+ alertDialog.setMessage("Congratulation, you solved the sudoku in 2'00");
+ alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,"OK",new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ onMenu(null);
+ }
+ });
+ alertDialog.show();
+ }
}
});
-
}
private void countFilled(int id,int val){
@@ -264,9 +330,7 @@ public void onVerify(View view){
}
}
- public void onRefresh(View view){
-
- }
+
}
diff --git a/solver/src/main/java/mg/rivolink/app/sudokusolver/views/sudoku/SudokuView.java b/solver/src/main/java/mg/rivolink/app/sudokusolver/views/sudoku/SudokuView.java
index 392a68a..18fc380 100644
--- a/solver/src/main/java/mg/rivolink/app/sudokusolver/views/sudoku/SudokuView.java
+++ b/solver/src/main/java/mg/rivolink/app/sudokusolver/views/sudoku/SudokuView.java
@@ -12,6 +12,7 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Canvas;
+import android.graphics.Typeface;
import mg.rivolink.app.sudokusolver.R;
@@ -101,12 +102,12 @@ public void fill(int[][] mat){
if(0
diff --git a/solver/src/main/res/layout/activity_play.xml b/solver/src/main/res/layout/activity_play.xml
index 4f8d7ce..ead0dd5 100644
--- a/solver/src/main/res/layout/activity_play.xml
+++ b/solver/src/main/res/layout/activity_play.xml
@@ -14,6 +14,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
+
+ android:src="@drawable/ic_open_in_new_white_48dp"/>