├── app ├── .gitignore ├── libs │ ├── symjalib.aar │ └── arity-2.1.7.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── plus.png │ │ │ │ ├── icn_back.png │ │ │ │ ├── photo_shutter.png │ │ │ │ └── white_border_rect.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ └── menu_carmera.xml │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── attrs.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_result.xml │ │ │ │ ├── crop_control.xml │ │ │ │ └── fragment_camera.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── app │ │ │ │ └── mathpix_sample │ │ │ │ ├── ScanConstants.java │ │ │ │ ├── evaluator │ │ │ │ ├── convert │ │ │ │ │ ├── Converter.java │ │ │ │ │ ├── BaseConverter.java │ │ │ │ │ ├── SystemEquationConverter.java │ │ │ │ │ ├── EquationConverter.java │ │ │ │ │ ├── ConvertFactory.java │ │ │ │ │ └── FormatTransformer.java │ │ │ │ ├── CalculateHandler.java │ │ │ │ ├── thread │ │ │ │ │ ├── ResultCallback.java │ │ │ │ │ ├── Command.java │ │ │ │ │ ├── BaseThread.java │ │ │ │ │ └── CalculateThread.java │ │ │ │ ├── exceptions │ │ │ │ │ ├── MathExceptionManager.java │ │ │ │ │ ├── NonBalanceBracketException.java │ │ │ │ │ ├── TooBigNumberException.java │ │ │ │ │ ├── ParsingException.java │ │ │ │ │ ├── ExpressionChecker.java │ │ │ │ │ └── ExceptionManager.java │ │ │ │ ├── base │ │ │ │ │ ├── Base.java │ │ │ │ │ ├── Module.java │ │ │ │ │ ├── NumberBaseManager.java │ │ │ │ │ └── Evaluator.java │ │ │ │ ├── util │ │ │ │ │ └── ConfigApp.java │ │ │ │ ├── LaTexFactory.java │ │ │ │ ├── CustomFunctions.java │ │ │ │ ├── DLog.java │ │ │ │ ├── DecimalFormatter.java │ │ │ │ ├── CalculatorContract.java │ │ │ │ ├── CalculatorPresenter.java │ │ │ │ ├── Utility.java │ │ │ │ ├── SystemLoader.java │ │ │ │ ├── model │ │ │ │ │ ├── ExprInput.java │ │ │ │ │ ├── StepItem.java │ │ │ │ │ ├── EquationItem.java │ │ │ │ │ ├── SolveItem.java │ │ │ │ │ └── SystemEquationItem.java │ │ │ │ ├── DecimalFactory.java │ │ │ │ ├── EvaluateConfig.java │ │ │ │ ├── LogicEvaluator.java │ │ │ │ ├── tokenizer │ │ │ │ │ └── Tokenizer.java │ │ │ │ ├── Constants.java │ │ │ │ ├── data │ │ │ │ │ └── CalculatorSetting.java │ │ │ │ └── FormatExpression.java │ │ │ │ ├── Constant.java │ │ │ │ ├── cropcontrol │ │ │ │ ├── CropView.java │ │ │ │ ├── CropTransformation.java │ │ │ │ ├── CropController.java │ │ │ │ └── CornerView.java │ │ │ │ ├── api │ │ │ │ ├── request │ │ │ │ │ └── SingleProcessRequest.java │ │ │ │ └── response │ │ │ │ │ └── DetectionResult.java │ │ │ │ ├── camera │ │ │ │ ├── DisplayUtils.java │ │ │ │ ├── PhotoTaker.java │ │ │ │ ├── CameraPreview.java │ │ │ │ └── CameraUtil.java │ │ │ │ ├── CarmeraActivity.java │ │ │ │ ├── ResultActivity.java │ │ │ │ ├── ImageUtil.java │ │ │ │ ├── MarshmallowPermissions.java │ │ │ │ ├── UploadImageTask.java │ │ │ │ └── CameraFragment.java │ │ ├── assets │ │ │ └── latex.html │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── app │ │ │ └── mathpix_sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── app │ │ └── mathpix_sample │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── screenshots_for_readme ├── 01.png ├── 02.png ├── 03.png ├── 04.png ├── 06.png ├── 07.png ├── 051.png ├── 052.png ├── 053.png ├── 061.png └── 071.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── .gitignore ├── local.properties ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/libs/symjalib.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/libs/symjalib.aar -------------------------------------------------------------------------------- /app/libs/arity-2.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/libs/arity-2.1.7.jar -------------------------------------------------------------------------------- /screenshots_for_readme/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/01.png -------------------------------------------------------------------------------- /screenshots_for_readme/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/02.png -------------------------------------------------------------------------------- /screenshots_for_readme/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/03.png -------------------------------------------------------------------------------- /screenshots_for_readme/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/04.png -------------------------------------------------------------------------------- /screenshots_for_readme/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/06.png -------------------------------------------------------------------------------- /screenshots_for_readme/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/07.png -------------------------------------------------------------------------------- /screenshots_for_readme/051.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/051.png -------------------------------------------------------------------------------- /screenshots_for_readme/052.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/052.png -------------------------------------------------------------------------------- /screenshots_for_readme/053.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/053.png -------------------------------------------------------------------------------- /screenshots_for_readme/061.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/061.png -------------------------------------------------------------------------------- /screenshots_for_readme/071.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/screenshots_for_readme/071.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/drawable/plus.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /newExpr.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/icn_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/drawable/icn_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/photo_shutter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/drawable/photo_shutter.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yishuinanfeng/ScanCalculator/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/ScanConstants.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | /** 4 | * 创建时间: 2018/10/15 5 | * 作者:yanyinan 6 | * 功能描述:扫描计算处理的字符串常量 7 | */ 8 | public class ScanConstants { 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 10 04:34:32 PDT 2017 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.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/white_border_rect.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/convert/Converter.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.evaluator.convert; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * 创建时间: 2018/10/12 7 | * 作者:yanyinan 8 | * 功能描述:图像扫描库识别结果运算式子文本转化为具体计算结果 9 | */ 10 | public interface Converter { 11 | // 输入为图像识别结果的lateX的集合 12 | String getConvertResult() throws Exception; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your newExpr configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Fri Oct 12 14:29:33 CST 2018 8 | sdk.dir=C\:\\Users\\LeFei\\AppData\\Local\\Android\\Sdk 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/Constant.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | /** 4 | * Created by Admin on 2/1/2017. 5 | */ 6 | public class Constant { 7 | 8 | public Constant(){} 9 | public static String app_id="mathpix"; 10 | public static String app_key="139ee4b61be2e4abcfb1238d9eb99902"; 11 | public static String base_Url="https://api.mathpix.com/v2/latex"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/app/mathpix_sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/cropcontrol/CropView.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.cropcontrol; 2 | 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.widget.RelativeLayout; 7 | 8 | public class CropView extends RelativeLayout { 9 | public CropView(Context context, AttributeSet attrs) { 10 | super(context, attrs); 11 | setWillNotDraw(true); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/app/mathpix_sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_carmera.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 75dp 6 | 38dp 7 | 8 | 300dp 9 | 200dp 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #66000000 8 | #000000 9 | #FFFFFF 10 | #abffffff 11 | #2cffffff 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 100dp 7 | 50dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A project that is able to get the result of calculation only by scanning a Calculation formula.(Without using any cellula of your brain,just scan a formula by your phone!Is it cool?!) 2 | 3 | It is based on https://github.com/Mathpix/android-sample,it need two core modules:Symja library and Mathpix. 4 | The first libreary is a Java Symbolic Math System,you can find more on https://github.com/axkr/symja_android_library, and I also use it to do job about calculation. Mathpix is able to translate a image to lateX.Find more on https://mathpix.com/. 5 | 6 | What i do is building a bridge between them which contain lot of work of parsing String into which Symja can identify. 7 | 8 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/assets/latex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Latex app 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Admin\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/CalculateHandler.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.evaluator; 2 | 3 | import android.content.Context; 4 | 5 | import com.app.mathpix_sample.evaluator.convert.ConvertFactory; 6 | import com.app.mathpix_sample.evaluator.convert.Converter; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | * 创建时间: 2018/10/12 12 | * 作者:yanyinan 13 | * 功能描述:数学计算总的处理器 14 | */ 15 | public class CalculateHandler { 16 | 17 | public String getCalculateResult(Context context,ArrayList scanResultList) throws Exception{ 18 | Converter converter = ConvertFactory.createConverter(scanResultList,context); 19 | 20 | if (converter == null){ 21 | return ""; 22 | } 23 | 24 | return converter.getConvertResult(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/api/request/SingleProcessRequest.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.api.request; 2 | 3 | import android.graphics.Bitmap; 4 | import android.util.Base64; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | 10 | public class SingleProcessRequest { 11 | @SerializedName("url") 12 | private String url; 13 | 14 | public SingleProcessRequest(Bitmap bm) { 15 | url = "data:image/jpeg;base64," + bitmapToBase64(bm); 16 | } 17 | 18 | public SingleProcessRequest(byte[] fileBytes) { 19 | url = "data:image/jpeg;base64," + Base64.encodeToString(fileBytes, Base64.DEFAULT); 20 | } 21 | 22 | private String bitmapToBase64(Bitmap image) { 23 | ByteArrayOutputStream os = new ByteArrayOutputStream(); 24 | image.compress(Bitmap.CompressFormat.JPEG, 100, os); 25 | return Base64.encodeToString(os.toByteArray(), Base64.DEFAULT); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/convert/BaseConverter.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.evaluator.convert; 2 | 3 | import com.app.mathpix_sample.evaluator.MathEvaluator; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * 创建时间: 2018/10/12 9 | * 作者:yanyinan 10 | * 功能描述:基本运算式转化器 11 | */ 12 | public class BaseConverter implements Converter { 13 | private String scanResult = ""; 14 | 15 | public BaseConverter(ArrayList scanResultList) { 16 | if (scanResultList != null && scanResultList.size() > 0) { 17 | scanResult = scanResultList.get(0); 18 | } 19 | } 20 | 21 | @Override 22 | public String getConvertResult() throws Exception{ 23 | // 移除末尾的“=” 24 | if (scanResult.endsWith("=")){ 25 | scanResult = scanResult.replace("=",""); 26 | } 27 | 28 | MathEvaluator mathEvaluator = MathEvaluator.getInstance(); 29 | return mathEvaluator.evaluateWithResultNormal(scanResult); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/camera/DisplayUtils.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample.camera; 2 | 3 | import android.content.Context; 4 | import android.content.res.Configuration; 5 | import android.view.Display; 6 | import android.view.WindowManager; 7 | 8 | public class DisplayUtils { 9 | 10 | public static int getScreenOrientation(Context context) { 11 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 12 | Display display = wm.getDefaultDisplay(); 13 | int orientation = Configuration.ORIENTATION_UNDEFINED; 14 | if (display.getWidth() == display.getHeight()) { 15 | orientation = Configuration.ORIENTATION_SQUARE; 16 | } else { 17 | if (display.getWidth() < display.getHeight()) { 18 | orientation = Configuration.ORIENTATION_PORTRAIT; 19 | } else { 20 | orientation = Configuration.ORIENTATION_LANDSCAPE; 21 | } 22 | } 23 | return orientation; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/thread/ResultCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.thread; 20 | 21 | import java.util.ArrayList; 22 | 23 | public interface ResultCallback { 24 | void onSuccess(ArrayList result); 25 | 26 | void onError(Exception e); 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/CarmeraActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.Toolbar; 9 | import android.view.View; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | 13 | public class CarmeraActivity extends FragmentActivity { 14 | 15 | @Override 16 | public void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | if(!MarshmallowPermissions.checkPermissionForCamera(this)) { 21 | MarshmallowPermissions.requestPermissionForCamera(this); 22 | } 23 | } 24 | 25 | @Override 26 | protected void onPause() { 27 | super.onPause(); 28 | } 29 | 30 | @Override 31 | public void onBackPressed() { 32 | finish(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.widget.TextView; 8 | 9 | import io.github.kexanie.library.MathView; 10 | 11 | public class ResultActivity extends AppCompatActivity { 12 | 13 | public static final String RESULT = "result"; 14 | 15 | public static void goResultActivity(Activity activity,String result){ 16 | Intent intent = new Intent(activity,ResultActivity.class).putExtra(RESULT,result); 17 | activity.startActivity(intent); 18 | } 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_result); 24 | 25 | MathView mathView = (MathView) findViewById(R.id.tv_result); 26 | 27 | Intent intent = getIntent(); 28 | String result = intent.getStringExtra(RESULT); 29 | mathView.setText(result); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package com.app.mathpix_sample; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.graphics.Matrix; 6 | import android.util.Base64; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | 10 | 11 | public class ImageUtil { 12 | private static byte[] bitmapToBytes(Bitmap image) { 13 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 14 | image.compress(Bitmap.CompressFormat.JPEG, 100, baos); 15 | return baos.toByteArray(); 16 | } 17 | 18 | public static String bitmapToBase64(Bitmap image) { 19 | byte[] buffer = bitmapToBytes(image); 20 | return Base64.encodeToString(buffer, Base64.DEFAULT); 21 | } 22 | 23 | public static Bitmap toBitmap(byte[] data) { 24 | return BitmapFactory.decodeByteArray(data , 0, data.length); 25 | } 26 | 27 | public static Bitmap rotate(Bitmap in, int angle) { 28 | Matrix mat = new Matrix(); 29 | mat.postRotate(angle); 30 | return Bitmap.createBitmap(in, 0, 0, in.getWidth(), in.getHeight(), mat, true); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/thread/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.thread; 20 | 21 | /** 22 | * Uses the Command Design Pattern to effectively have lambda expressions in a pre-Java 8 environment. 23 | * Note: e is the return Object, F is the param Object. 24 | * 25 | * @author Alston Lin 26 | * @version 3.0 27 | */ 28 | public interface Command { 29 | public RETURN execute(INPUT input); 30 | } -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/exceptions/MathExceptionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.exceptions; 20 | 21 | 22 | import com.app.mathpix_sample.evaluator.MathEvaluator; 23 | 24 | /** 25 | * Created by Duy on 22-Jan-17. 26 | */ 27 | 28 | public class MathExceptionManager { 29 | private final MathEvaluator mEvaluator; 30 | 31 | public MathExceptionManager(MathEvaluator e) { 32 | this.mEvaluator = e; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/base/Base.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.base; 20 | 21 | /** 22 | * Represents changing the number of characters available when writing numbers. 23 | */ 24 | public enum Base { 25 | BINARY(2), 26 | OCTAL(8), 27 | DECIMAL(10), 28 | HEXADECIMAL(16); 29 | 30 | int quickSerializable; 31 | 32 | Base(int num) { 33 | this.quickSerializable = num; 34 | } 35 | 36 | public int getQuickSerializable() { 37 | return quickSerializable; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/exceptions/NonBalanceBracketException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.exceptions; 20 | 21 | /** 22 | * Created by Duy on 01-Jul-17. 23 | */ 24 | 25 | public class NonBalanceBracketException extends ParsingException { 26 | 27 | public NonBalanceBracketException(String expr, int index) { 28 | super(expr, index); 29 | } 30 | 31 | @Override 32 | public String getMessage() { 33 | return "Non balance bracket of " + getExpr() + " at " + getIndex(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/exceptions/TooBigNumberException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.exceptions; 20 | 21 | /** 22 | * Error when handling large numbers or small numers 23 | *

24 | * Created by Duy on 24-Jan-17. 25 | */ 26 | public class TooBigNumberException extends Exception { 27 | 28 | /** 29 | * Constructor 30 | * @param isTooBig - is value too big 31 | */ 32 | public TooBigNumberException(boolean isTooBig) { 33 | super(isTooBig ? "Number too big" : "Number to small"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Mathpix_Sample 3 | Settings 4 | 5 | 6 | Dummy Button 7 | DUMMY\nCONTENT 8 | Drag to resize 9 | 10 | Taking picture 11 | Processing Image 12 | 13 | 14 | Log(x) is the natural logarithm 16 | ]]> 17 | 18 | Cannot find root of the equation. 19 | This equation has no solution. 20 | 21 | key_pref_instant_res_ 22 | key_pref_precision 23 | key_hide_status_bar 24 | Syntax error 25 | Reason 26 | Math error 27 | Error 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/app/mathpix_sample/evaluator/util/ConfigApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Duy Tran Le 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | package com.app.mathpix_sample.evaluator.util; 20 | 21 | 22 | import com.app.mathpix_sample.BuildConfig; 23 | 24 | /** 25 | * Created by Duy on 28-Nov-16. 26 | */ 27 | public class ConfigApp { 28 | public static final boolean DEBUG = false; 29 | public static final int VERSION_CODE = BuildConfig.VERSION_CODE; 30 | public static final String APPLICATION_ID = BuildConfig.APPLICATION_ID; 31 | public static final String BUILD_TYPE = BuildConfig.BUILD_TYPE; 32 | public static final String VERSION_NAME = BuildConfig.VERSION_NAME; 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 18 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 18 | 19 | 22 | 23 | 27 | 28 |