Skip to content

Commit

Permalink
Added new method that executes if 5 matches, and checks if any consec…
Browse files Browse the repository at this point in the history
…utive matches have a percent symbol. If so, then program will no longer continue check for 5 matches unless camera is closed.
  • Loading branch information
Jacusaurus committed Dec 30, 2020
1 parent 2b88aef commit 7eb7418
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> 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<String> 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;
Expand Down

0 comments on commit 7eb7418

Please sign in to comment.