├── settings.gradle ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_circle.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_circle.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_circle.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_circle.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_circle.png │ │ │ ├── drawable-v24 │ │ │ │ ├── button_bg.xml │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── layout │ │ │ │ ├── dialog_header.xml │ │ │ │ └── activity_main.xml │ │ │ ├── drawable │ │ │ │ ├── find_box.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── values-es │ │ │ │ └── strings.xml │ │ │ └── values-tr-rTR │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── hasbis │ │ │ │ └── findonpage │ │ │ │ ├── features │ │ │ │ ├── ocr │ │ │ │ │ ├── OCRActions.java │ │ │ │ │ └── ImageToText.java │ │ │ │ └── views │ │ │ │ │ └── DrawableImageView.java │ │ │ │ ├── utils │ │ │ │ └── FirebaseAnalyticsUtils.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── hasbis │ │ │ └── findonpage │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── hasbis │ │ └── findonpage │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | google-services.json -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_circle.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_circle.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_circle.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_circle.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasbisevinc/Find-on-Page/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_circle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/button_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #000000 6 | #d3dbdc 7 | #a9eca2 8 | #bbded6 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/hasbis/findonpage/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/hasbis/findonpage/features/ocr/OCRActions.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage.features.ocr; 2 | 3 | 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import androidx.annotation.IntDef; 7 | 8 | 9 | @IntDef({ 10 | OCRActions.PROCESS_STARTED, 11 | OCRActions.PROCESS_FINISHED, 12 | OCRActions.PROCESS_FAIL, 13 | OCRActions.PROCESS_TEXT_NOT_FOUND, 14 | }) 15 | @Retention(RetentionPolicy.SOURCE) 16 | public @interface OCRActions { 17 | int PROCESS_STARTED = 0; 18 | int PROCESS_FINISHED = 1; 19 | int PROCESS_FAIL = 2; 20 | int PROCESS_TEXT_NOT_FOUND = 3; 21 | } 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /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/main/res/drawable/find_box.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hasbis/findonpage/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage; 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hasbis.findonpage", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Find-on-Page 2 | An android application that finds desired words in a hard-copy paper. Just like searching with CTRL + F 3 | 4 | ## Introduction 5 | Have you ever want to search a word in a paper? This application will find any desired word in a hard copy page just like searching with CTRL+F. You just need to take a photo of paper and type the word. We will highlight these words in seconds... 6 | 7 | ![Screenshoot 2](https://lh3.googleusercontent.com/pQrlG7zksfSyoBkF38fgzXf9e0rzIyjUMnUy0qSvn58G_g3i-N9RuNIGcEe_-wecny52=w1920-h969-rw) 8 | ![Screenshoot 2](https://lh3.googleusercontent.com/lrpVBwWipYdDojf3rYt8PpFldCZL097_payHara4lByiVh_s6UL9PATsmtQBiylHwFLs=w1920-h969-rw) 9 | 10 | 11 | ## How to Use 12 | Way 1: download from playstore 13 | https://play.google.com/store/apps/details?id=com.hasbis.findonpage 14 | 15 | Way 2: Download apk from releases: 16 | https://github.com/hasbisevinc/Find-on-Page/releases 17 | 18 | Way 3: clone source code and build it 19 | 20 | ## How to Build 21 | - Clone this repo into your local 22 | ``` 23 | git clone git@github.com:hasbisevinc/Find-on-Page.git 24 | ``` 25 | - Create a firebase project and download google-services.json file into app directory. 26 | 27 | To learn how to create a firebase: https://firebase.google.com/docs/android/setup 28 | - Open project with Android Studio and compile it 29 | 30 | ## Contributions 31 | Currently we need: 32 | 33 | - Translate of string.xml file 34 | - Testing application with different phones 35 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Find On Page 3 | Take a new photo 4 | Find 5 | Select all 6 | Text to search 7 | permission denied 8 | No result found 9 | %1$s result found 10 | Please try again 11 | No text found in image, please try again 12 | Please wait 13 | Show search bar 14 | Hide search bar 15 | Close 16 | Take a photo from camera 17 | Take a photo from gallery 18 | Take new photo from: 19 | Cancel 20 | Capture a photo from your camera and search any words on this photo 21 | Required credits:1 22 | Capture a photo from your gallery and search any words on this photo 23 | 24 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'io.fabric' 3 | 4 | android { 5 | compileSdkVersion 28 6 | defaultConfig { 7 | applicationId "com.hasbis.findonpage" 8 | minSdkVersion 21 9 | targetSdkVersion 28 10 | versionCode 2 11 | versionName "1.1" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | android { 22 | packagingOptions { 23 | exclude 'META-INF/proguard/androidx-annotations.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'androidx.appcompat:appcompat:1.1.0' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | implementation 'com.google.firebase:firebase-core:17.2.0' 33 | apply plugin: 'com.google.gms.google-services' 34 | implementation 'com.google.firebase:firebase-ml-vision:23.0.0' 35 | implementation 'com.github.d-max:spots-dialog:1.1@aar' 36 | implementation 'io.reactivex.rxjava2:rxjava:2.2.9' 37 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' 38 | implementation 'com.google.firebase:firebase-core:17.2.0' 39 | implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' 40 | implementation 'com.orhanobut:dialogplus:1.11@aar' 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/hasbis/findonpage/features/views/DrawableImageView.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage.features.views; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | import android.util.AttributeSet; 9 | import android.widget.ImageView; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class DrawableImageView extends ImageView { 14 | 15 | ArrayList rects; 16 | Paint paint = new Paint(); 17 | 18 | public DrawableImageView(Context context, AttributeSet attributeSet) { 19 | super(context, attributeSet); 20 | this.setWillNotDraw(false); 21 | rects = new ArrayList<>(); 22 | } 23 | 24 | public DrawableImageView(Context context) { 25 | super(context); 26 | this.setWillNotDraw(false); 27 | rects = new ArrayList<>(); 28 | } 29 | 30 | public void setRects(ArrayList rects) { 31 | this.rects = rects; 32 | invalidate(); 33 | } 34 | 35 | @Override 36 | protected void onDraw(Canvas canvas) { 37 | super.onDraw(canvas); 38 | 39 | // Initialize a new Paint instance to draw the Rectangle 40 | paint.setStyle(Paint.Style.FILL); 41 | paint.setColor(Color.YELLOW); 42 | paint.setAntiAlias(true); 43 | paint.setAlpha(125); 44 | 45 | // Finally, draw the rectangle on the canvas 46 | for (Rect rec : rects) { 47 | canvas.drawRect(rec, paint); 48 | } 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /app/src/main/res/values-es/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Encuéntralo en la página 3 | Tomar una nueva foto 4 | Encontrar 5 | Seleccionar todo 6 | Texto a buscar 7 | permiso denegado 8 | No se han encontrado resultados 9 | Se encontró %1$s resultado 10 | Inténtalo de nuevo 11 | No se encontró texto en la imagen, intente nuevamente 12 | por favor espera 13 | Mostrar barra de búsqueda 14 | Ocultar barra de búsqueda 15 | Cerrar 16 | Tomar una foto de la cámara 17 | Toma una foto de la galería 18 | Tomar nueva foto de: 19 | Cancelar 20 | Capture una foto de su cámara y busque cualquier palabra en esta foto 21 | Créditos requeridos: 1 22 | Capture una foto de su galería y busque cualquier palabra en esta foto 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/values-tr-rTR/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Kağıtta Bul 4 | Yeni Fotoğraf 5 | Bul 6 | Hepsini seç 7 | Aranacak kelime 8 | İzin alınamadı 9 | Sonuç bulunamadı 10 | %1$s tane sonuç bulundu 11 | Lütfen tekrar deneyiniz 12 | Resimde kelime bulunamadı, lütfen tekrar deneyiniz 13 | Lütfen bekleyin 14 | Arama barını göster 15 | Arama barını gizle 16 | Kapat 17 | Kameradan görüntü yakala 18 | Galeriden resim seç 19 | Yeni fotoğrafı şuradan al: 20 | İptal 21 | Kameranızdan taratmak istediğiniz belgenin fotoğrafını çekin ve bu belge üzerinde kelime aramaya hemen başlayın 22 | Gerekli kredi:1 23 | Galeriden taratmak istediğiniz belgenin fotoğrafını çekin ve bu belge üzerinde kelime aramaya hemen başlayın 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/hasbis/findonpage/utils/FirebaseAnalyticsUtils.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage.utils; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | 6 | import com.google.firebase.analytics.FirebaseAnalytics; 7 | 8 | public class FirebaseAnalyticsUtils { 9 | private final static String TAG = "FirebaseAnalyticsUtils"; 10 | 11 | private static FirebaseAnalyticsUtils instance = null; 12 | private FirebaseAnalytics mFirebaseAnalytics; 13 | 14 | private FirebaseAnalyticsUtils() 15 | { 16 | } 17 | 18 | public static FirebaseAnalyticsUtils getInstance() { 19 | synchronized (TAG) { 20 | if (instance == null) { 21 | synchronized (TAG) { 22 | instance = new FirebaseAnalyticsUtils(); 23 | } 24 | } 25 | } 26 | return instance; 27 | } 28 | 29 | public void init(Context context) { 30 | mFirebaseAnalytics = FirebaseAnalytics.getInstance(context); 31 | } 32 | 33 | private void saveLog(String id, String name) { 34 | Bundle bundle = new Bundle(); 35 | bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id); 36 | bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name); 37 | bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image"); 38 | mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); 39 | } 40 | 41 | public void onNewPhoto() { 42 | saveLog("PHOTO", "NEW_PHOTO"); 43 | } 44 | 45 | public void onNewGalleryPhoto() { 46 | saveLog("GALLERY", "NEW_GALLERY"); 47 | } 48 | 49 | public void onNewSearch() { 50 | saveLog("SEARCH", "NEW_SEARCH"); 51 | } 52 | 53 | public void onSelectAll() { 54 | saveLog("SELECT_ALL", "NEW_SELECT_ALL"); 55 | } 56 | 57 | public void onShowFindBoxClicked() { 58 | saveLog("SHOW_FIND_BOX", "NEW_SHOW_FIND_BOX"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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/java/com/hasbis/findonpage/features/ocr/ImageToText.java: -------------------------------------------------------------------------------- 1 | package com.hasbis.findonpage.features.ocr; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Matrix; 6 | import android.graphics.Rect; 7 | import android.net.Uri; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | 11 | import com.google.android.gms.tasks.OnFailureListener; 12 | import com.google.android.gms.tasks.OnSuccessListener; 13 | import com.google.firebase.ml.vision.FirebaseVision; 14 | import com.google.firebase.ml.vision.common.FirebaseVisionImage; 15 | import com.google.firebase.ml.vision.text.FirebaseVisionText; 16 | import com.google.firebase.ml.vision.text.FirebaseVisionTextRecognizer; 17 | 18 | import java.io.IOException; 19 | import java.util.ArrayList; 20 | 21 | import io.reactivex.Observable; 22 | import io.reactivex.Observer; 23 | import io.reactivex.annotations.NonNull; 24 | import io.reactivex.subjects.PublishSubject; 25 | 26 | public class ImageToText { 27 | private static final String TAG = "ImageToText"; 28 | 29 | private Context context; 30 | private FirebaseVisionText firebaseVisionText = null; 31 | private int mlImageHeight = -1; 32 | private int mlImageWidth = -1; 33 | 34 | PublishSubject actionSubject = PublishSubject.create(); 35 | PublishSubject resultSubject = PublishSubject.create(); 36 | 37 | public Observable getActionObserveable() { 38 | return actionSubject; 39 | } 40 | 41 | public Observable getResultObserveable() { 42 | return resultSubject; 43 | } 44 | 45 | public ImageToText(Context context) { 46 | this.context = context; 47 | } 48 | 49 | public void startOCR(Uri uri) { 50 | FirebaseVisionImage image; 51 | try { 52 | image = FirebaseVisionImage.fromFilePath(context, uri); 53 | mlImageWidth = image.getBitmap().getWidth(); 54 | mlImageHeight = image.getBitmap().getHeight(); 55 | } catch (IOException e) { 56 | Log.e(TAG, "findText: ", e); 57 | return; 58 | } 59 | 60 | sendAction(OCRActions.PROCESS_STARTED); 61 | runOCR(image); 62 | } 63 | 64 | public void markText(String text) { 65 | if (firebaseVisionText == null) { 66 | sendAction(OCRActions.PROCESS_TEXT_NOT_FOUND); 67 | return; 68 | } 69 | 70 | Log.d(TAG, "markText: all text:"+firebaseVisionText.getText()); 71 | ArrayList rects = new ArrayList<>(); 72 | for (FirebaseVisionText.TextBlock block: firebaseVisionText.getTextBlocks()) { 73 | for (FirebaseVisionText.Line line: block.getLines()) { 74 | for (FirebaseVisionText.Element element: line.getElements()) { 75 | String elementText = element.getText(); 76 | Rect elementFrame = element.getBoundingBox(); 77 | 78 | if (elementFrame != null && 79 | elementText.toLowerCase().contains(text.toLowerCase())) { 80 | rects.add(elementFrame); 81 | } 82 | 83 | } 84 | } 85 | } 86 | 87 | sendResult(rects); 88 | } 89 | 90 | public String getAllText() { 91 | return (firebaseVisionText == null) ? null : firebaseVisionText.getText(); 92 | } 93 | 94 | private void sendAction(@OCRActions int action) { 95 | actionSubject.onNext(action); 96 | } 97 | 98 | private void sendResult(ArrayList rects) { 99 | resultSubject.onNext(new OCRResult(rects, mlImageWidth, mlImageHeight)); 100 | } 101 | private void runOCR(final FirebaseVisionImage image) { 102 | runOCR(image,false, false); 103 | } 104 | 105 | private void runOCR(final FirebaseVisionImage image, final boolean rotatedLeft, final boolean rotatedRight) { 106 | FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance() 107 | .getOnDeviceTextRecognizer(); 108 | 109 | detector.processImage(image) 110 | .addOnSuccessListener(new OnSuccessListener() { 111 | @Override 112 | public void onSuccess(FirebaseVisionText local_firebaseVisionText) { 113 | firebaseVisionText = local_firebaseVisionText; 114 | if (firebaseVisionText == null || 115 | TextUtils.isEmpty(firebaseVisionText.getText())) { 116 | if (!rotatedLeft) { 117 | // rotate left 118 | runOCR(rotateImage(image, true), 119 | true, false); 120 | } else if (rotatedLeft && !rotatedRight) { 121 | // rotate right 122 | runOCR(rotateImage(image, false), 123 | true, true); 124 | } else { 125 | //fail 126 | sendAction(OCRActions.PROCESS_FAIL); 127 | } 128 | } else { 129 | sendAction(OCRActions.PROCESS_FINISHED); 130 | } 131 | } 132 | }) 133 | .addOnFailureListener( 134 | new OnFailureListener() { 135 | @Override 136 | public void onFailure(@NonNull Exception e) { 137 | sendAction(OCRActions.PROCESS_FAIL); 138 | Log.e(TAG, "onFailure: ", e); 139 | } 140 | }); 141 | } 142 | 143 | private FirebaseVisionImage rotateImage(final FirebaseVisionImage image, final boolean rotateLeft) { 144 | float angle = 270; 145 | if (rotateLeft) { 146 | angle = 90; 147 | } 148 | 149 | Bitmap bitmap = rotateBitmap(image.getBitmap(), angle); 150 | return FirebaseVisionImage.fromBitmap(bitmap); 151 | } 152 | 153 | private Bitmap rotateBitmap(Bitmap source, float angle) 154 | { 155 | Matrix matrix = new Matrix(); 156 | matrix.postRotate(angle); 157 | return Bitmap.createBitmap(source, 0, 0, 158 | source.getWidth(), source.getHeight(), matrix, true); 159 | } 160 | 161 | public class OCRResult { 162 | public ArrayList rects; 163 | public int height; 164 | public int width; 165 | 166 | public OCRResult(ArrayList rects, 167 | int width, 168 | int height) { 169 | this.rects = rects; 170 | this.height = height; 171 | this.width = width; 172 | } 173 | } 174 | 175 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 27 | 28 | 29 | 40 | 41 |