Skip to content

Commit

Permalink
Required Featured added
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulshah456 committed Oct 11, 2019
1 parent 454199b commit 2d8515d
Show file tree
Hide file tree
Showing 45 changed files with 871 additions and 52 deletions.
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.PreviewActivity"></activity>
<activity android:name=".activities.HistoryActivity"></activity>
<activity android:name=".activities.PreviewActivity" />
<activity android:name=".activities.CropActivity" />
<activity android:name=".activities.CameraActivity" />
<activity android:name=".activities.LiveActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 97 additions & 6 deletions app/src/main/java/com/droid2developers/frozenocr/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
import androidx.cardview.widget.CardView;
import androidx.core.content.FileProvider;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.droid2developers.frozenocr.activities.CameraActivity;
import com.droid2developers.frozenocr.activities.LiveActivity;
import com.droid2developers.frozenocr.activities.CropActivity;
import com.droid2developers.frozenocr.activities.HistoryActivity;
import com.droid2developers.frozenocr.controller.SQLiteHandler;

import java.io.File;
import java.io.IOException;
Expand All @@ -30,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
private static final int PICK_IMAGE_REQUEST = 5;
private ImageView optionsImage;
private String imageFilePath;
private SQLiteHandler sqLiteHandler;
private static final int CAPTURE_IMAGE_REQUEST = 10;

@Override
Expand All @@ -43,12 +49,13 @@ protected void onCreate(Bundle savedInstanceState) {
CardView cameraButton = findViewById(R.id.cameraCardId);
CardView storageButton = findViewById(R.id.storageCardId);
CardView historyButton = findViewById(R.id.historyCardId);
sqLiteHandler = new SQLiteHandler(this);


optionsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OpenOptionsMenu();
openPopupMenu();
}
});

Expand All @@ -57,7 +64,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {

Intent intent = new Intent(MainActivity.this, CameraActivity.class);
Intent intent = new Intent(MainActivity.this, LiveActivity.class);
startActivity(intent);

}
Expand All @@ -83,6 +90,18 @@ public void onClick(View view) {



historyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
startActivity(intent);

}
});



}


Expand Down Expand Up @@ -127,14 +146,86 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {



private void openPopupMenu(){


//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(MainActivity.this, optionsImage);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.main_menu,popup.getMenu());

//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {

switch (item.getItemId()){

case R.id.clear_menuID:
ShowDeleteDialog();
break;
case R.id.feedback_menuID:
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"rahulkumarshah5000@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback - Frozen OCR");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Write your feedback here...");

// TODO menu main
public void OpenOptionsMenu(){
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(emailIntent, "Open gmail..."));
break;
case R.id.about_menuID:
String url = "https://github.com/rahulshah456";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
break;
case R.id.exit_menuID:
finish();
break;
}
return true;
}
});

popup.show();//showing popup menu

}


private void ShowDeleteDialog(){

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Delete History?");
alertDialog.setMessage("Are you sure you want to delete all your recognition data...");
alertDialog.setCancelable(true);
alertDialog.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (sqLiteHandler.getAllRecognitions().size()>0){
sqLiteHandler.deleteRecognitionData();
Toast.makeText(MainActivity.this, "History Cleaned!", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, "Nothing to Delete!", Toast.LENGTH_SHORT).show();
}

}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.d(TAG, "onClick: Cancelled Delete!");
}
});
alertDialog.show();

}




private void openStorageIntent(){

Intent intent = new Intent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
import androidx.core.content.FileProvider;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListAdapter;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.droid2developers.frozenocr.R;
import com.droid2developers.frozenocr.custom.RotateTransformation;
import com.droid2developers.frozenocr.controller.RotateTransformation;
import com.droid2developers.frozenocr.model.OCRModel;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.text.TextBlock;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.droid2developers.frozenocr.activities;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.droid2developers.frozenocr.R;
import com.droid2developers.frozenocr.controller.HistoryAdapter;
import com.droid2developers.frozenocr.controller.SQLiteHandler;
import com.droid2developers.frozenocr.model.OCRModel;

import java.util.List;
import java.util.Objects;

public class HistoryActivity extends AppCompatActivity {

public static final String TAG = HistoryActivity.class.getSimpleName();
private RecyclerView recyclerView;
private SQLiteHandler sqLiteHandler;
private HistoryAdapter historyAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);

CardView backButton = findViewById(R.id.backButtonId);
sqLiteHandler = new SQLiteHandler(this);
recyclerView = findViewById(R.id.recyclerViewId);
RelativeLayout relativeLayout = findViewById(R.id.relativeId);

List<OCRModel> list = sqLiteHandler.getAllRecognitions();
if (list.size()>0){
recyclerView.setVisibility(View.VISIBLE);
relativeLayout.setVisibility(View.GONE);
GenerateRecyclerView(list);
}

backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});

}

private void GenerateRecyclerView(List<OCRModel> ocrModelList){

// Set up RecyclerView
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this,
RecyclerView.VERTICAL,false);
historyAdapter = new HistoryAdapter(this,ocrModelList);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(historyAdapter);
recyclerView.setItemViewCacheSize(20);
recyclerView.setDrawingCacheEnabled(true);
recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
historyAdapter.setOnItemClickListener(new HistoryAdapter.OnItemClickListener() {
@Override
public void OnItemClick(int position) {

OCRModel ocrModel = historyAdapter.getItemAt(position);
Intent intent = new Intent(HistoryActivity.this, PreviewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("timeStamp",ocrModel.getTimeStamp());
intent.putExtra("savedURL",ocrModel.getImageUri());
intent.putExtra("extraText",ocrModel.getExtaText());
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(HistoryActivity.this, Objects.requireNonNull(recyclerView
.findViewHolderForAdapterPosition(position)).itemView.findViewById(R.id.imageViewId)
, Objects.requireNonNull(ViewCompat.getTransitionName(Objects.requireNonNull(recyclerView
.findViewHolderForAdapterPosition(position)).itemView.findViewById(R.id.imageViewId))));
startActivity(intent,options.toBundle());

}

@Override
public void OnItemOptionsClick(int position) {
openPopupMenu(position);
}
});

}


private void openPopupMenu(final int position){


//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(HistoryActivity.this, Objects.requireNonNull(recyclerView
.findViewHolderForAdapterPosition(position)).itemView.findViewById(R.id.optionsButtonId));
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.delete_menu,popup.getMenu());

//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {

if (item.getItemId() == R.id.delete_menuID) {
sqLiteHandler.deleteRecognition(historyAdapter.getItemAt(position));
historyAdapter.removeItem(position);
}
return true;
}
});

popup.show();//showing popup menu

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import android.widget.Toast;

import com.droid2developers.frozenocr.R;
import com.droid2developers.frozenocr.ocr.CameraSource;
import com.droid2developers.frozenocr.ocr.CameraSourcePreview;
import com.droid2developers.frozenocr.ocr.GraphicOverlay;
import com.droid2developers.frozenocr.ocr.OcrDetectorProcessor;
import com.droid2developers.frozenocr.ocr.OcrGraphic;
import com.droid2developers.frozenocr.views.CameraSource;
import com.droid2developers.frozenocr.views.CameraSourcePreview;
import com.droid2developers.frozenocr.views.GraphicOverlay;
import com.droid2developers.frozenocr.views.OcrDetectorProcessor;
import com.droid2developers.frozenocr.views.OcrGraphic;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.vision.text.TextBlock;
Expand All @@ -40,7 +40,7 @@
import java.io.IOException;
import java.util.Locale;

public class CameraActivity extends AppCompatActivity {
public class LiveActivity extends AppCompatActivity {

private static final String TAG = "OcrCaptureActivity";
// Intent request code to handle updating play services if needed.
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
gestureDetector = new GestureDetector(this, new CaptureGestureListener());
scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

Snackbar.make(graphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
ShowTip();

// Set up the Text To Speech engine.
TextToSpeech.OnInitListener listener =
Expand Down Expand Up @@ -119,6 +119,23 @@ public void onClick(View view) {
}


private void ShowTip(){

AlertDialog.Builder alertDialog = new AlertDialog.Builder(LiveActivity.this);
alertDialog.setTitle("Tip!");
alertDialog.setMessage("Tap on highlighted text to Speak. Pinch/Stretch to zoom.");
alertDialog.setCancelable(true);
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.d(TAG, "onClick: Cancelled Delete!");
}
});
alertDialog.show();

}


/**
* Handles the requesting of the camera permission. This includes
* showing a "Snackbar" message of why the permission is needed then
Expand Down
Loading

0 comments on commit 2d8515d

Please sign in to comment.