diff --git a/app/build.gradle b/app/build.gradle index 81fb5ea..eb9bb59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.gms:play-services-vision:15.0.0' + implementation 'org.jetbrains:annotations-java5:15.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/app/src/main/java/com/borderlandsdpscalculator/borderlands3dpscalculator/activities/CameraActivity.java b/app/src/main/java/com/borderlandsdpscalculator/borderlands3dpscalculator/activities/CameraActivity.java index 6607850..4ca978d 100644 --- a/app/src/main/java/com/borderlandsdpscalculator/borderlands3dpscalculator/activities/CameraActivity.java +++ b/app/src/main/java/com/borderlandsdpscalculator/borderlands3dpscalculator/activities/CameraActivity.java @@ -95,7 +95,7 @@ private void startCameraSource() { //Create the TextRecognizer final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build(); - accuracyIsPercent = false; + accuracyIsPercent = false; //makes it so sequential launches of the detector will search for both 5 and 6 matches if (!textRecognizer.isOperational()) { Log.w("Camera", "Detector dependencies not loaded yet"); @@ -255,28 +255,37 @@ private static boolean isInteger(String s, int radix) { //function that iterates if(s.length() == 1) return false; else continue; }*/ - if(s.charAt(i) != 'x'){ //checks if the character encountered is not 'x'. If not 'x', checks if character is valid for given base (base 10) numbering system. Returns false if not a valid digit - if(Character.digit(s.charAt(i),radix) < 0) return false; + if (s.charAt(i) != 'x') { //checks if the character encountered is not 'x'. If not 'x', checks if character is valid for given base (base 10) numbering system. Returns false if not a valid digit + if (Character.digit(s.charAt(i), radix) < 0) return false; } else { - if(i == s.length()-1 || i == 0) return false; //checks if the 'x' that was encountered is the last character in the string or is at the beginning. If either of these are true, returns false + if (i == s.length() - 1 || i == 0) + return false; //checks if the 'x' that was encountered is the last character in the string or is at the beginning. If either of these are true, returns false } } return true; } + private static boolean contains_percent(List allMatches) { //Loops through matches checking if any consecutive matches contain a percentage symbol + for (int i = 1; i < allMatches.size(); i++) { + if (String.valueOf(allMatches.get(i)).contains("%") && String.valueOf(allMatches.get(i - 1)).contains("%")) { + return true; + } + } + return false; + } + private static boolean validMatches(List allMatches) { //checks whether certain values are integers. if any are not, returns false, which causes the program to not attempt to construct a weapon from the data and throw an error if (allMatches.size() == 6) { boolean damage_is_int = isInteger((String.valueOf(allMatches.get(0)).replaceAll("[^\\dx.]", ""))); boolean accuracy_is_int = isInteger((String.valueOf(allMatches.get(1)).replaceAll("[^\\d.]", ""))); //accuracy is represented as an integer (whole-number percent sign) in BL3, so check for that - accuracyIsPercent = String.valueOf(allMatches.get(1)).contains("%"); Log.d("Accuracy", "Is accuracy percent: " + accuracyIsPercent); boolean handling_is_int = isInteger((String.valueOf(allMatches.get(2)).replaceAll("[^\\d.]", ""))); boolean magazine_size_is_int = isInteger((String.valueOf(allMatches.get(5)).replaceAll("[^\\d.]", ""))); return damage_is_int && accuracy_is_int && handling_is_int && magazine_size_is_int; } else if (allMatches.size() == 5) { + accuracyIsPercent = contains_percent(allMatches); //no longer searches for 5 matches if accuracy and handling are percentages (meaning weapon is from BL3) boolean damage_is_int = isInteger((String.valueOf(allMatches.get(0)).replaceAll("[^\\dx.]", ""))); - //accuracyIsPercent = String.valueOf(allMatches.get(1)).contains("%"); Log.d("Accuracy", "Is accuracy percent: " + accuracyIsPercent); boolean magazine_size_is_int = isInteger((String.valueOf(allMatches.get(4)).replaceAll("[^\\d.]", ""))); return damage_is_int && magazine_size_is_int;