Skip to content

Commit

Permalink
PlayActivity to ImageActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
RivoLink committed Nov 3, 2019
1 parent 75c9bae commit 6b565d1
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

}

Expand Down
88 changes: 76 additions & 12 deletions solver/src/main/java/mg/rivolink/app/sudokusolver/PlayActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -264,9 +330,7 @@ public void onVerify(View view){
}
}

public void onRefresh(View view){

}


}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -101,12 +102,12 @@ public void fill(int[][] mat){
if(0<val){
view.setText(""+val);
view.setEnabled(false);
view.setTextColor(primary_blue);
view.setTextColor(primary);
}
else{
view.setText("");
view.setEnabled(true);
view.setTextColor(primary);
view.setTextColor(primary_blue);
}
}
}
Expand Down Expand Up @@ -178,7 +179,8 @@ public int getId(){
cells[i].setOnTouchListener(listener);
cells[i].setGravity(Gravity.CENTER);
cells[i].setTextColor(primary);
cells[i].setTextSize(20);
cells[i].setTypeface(Typeface.DEFAULT_BOLD);
cells[i].setTextSize(23);
addView(cells[i]);
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion solver/src/main/res/layout/activity_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<ImageView
android:id="@+id/image_image_view"
android:gravity="center"
android:background="@color/primary_light"
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
2 changes: 2 additions & 0 deletions solver/src/main/res/layout/activity_play.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:layout_height="match_parent"
android:orientation="vertical">


<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -55,6 +56,7 @@
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/card_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
Expand Down
2 changes: 1 addition & 1 deletion solver/src/main/res/layout/popup_play.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
android:layout_width="30dp"
android:layout_height="30dp"
android:tint="@color/primary"
android:src="@drawable/ic_done_white_48dp"/>
android:src="@drawable/ic_open_in_new_white_48dp"/>

<ImageView
android:id="@+id/img_new"
Expand Down

0 comments on commit 6b565d1

Please sign in to comment.