Skip to content

Commit

Permalink
Merge pull request #223 from BlinkID/release/v5.7.0
Browse files Browse the repository at this point in the history
Release/v5.7.0
  • Loading branch information
matvidako authored Aug 17, 2020
2 parents 39a3a26 + fdc5fb3 commit e271e5d
Show file tree
Hide file tree
Showing 58 changed files with 2,706 additions and 496 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.microblink.result;

public enum ResultSource {

MIXED,
FRONT,
BACK,
MRZ,
BARCODE

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.widget.AppCompatSpinner;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -12,7 +14,6 @@

import com.microblink.libutils.R;
import com.microblink.locale.LanguageUtils;
import com.microblink.result.activity.fragment.ResultEntryAdapter;
import com.microblink.result.extract.RecognitionResultEntry;

import java.util.List;
Expand All @@ -21,6 +22,8 @@
public abstract class BaseResultFragment extends Fragment {

private ListView mListView;
protected View resultTypeSection;
protected AppCompatSpinner resultTypeSpinner;

@Override
public void onAttach(Context context) {
Expand All @@ -45,29 +48,27 @@ public void onAttach(Context context) {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mListView = new ListView(getActivity());
mListView.setDividerHeight(1);
mListView.setScrollbarFadingEnabled(false);

// some id is required so that android can save listview's scroll state
// when activity goes to background
// the id does not need to be unique
mListView.setId(android.R.id.text2);

return mListView;
View view = inflater.inflate(R.layout.fragment_results, container, false);
mListView = view.findViewById(R.id.list_view);
resultTypeSection = view.findViewById(R.id.result_type_section);
resultTypeSpinner = view.findViewById(R.id.result_type_spinner);
return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupListAdapter();
// Hide virtual keyboard
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

protected void setupListAdapter() {
List<RecognitionResultEntry> resultEntries = createResultEntries(getActivity());

// Create adapter which will be used to populate ListView.
ResultEntryAdapter adapter = new ResultEntryAdapter(getActivity(), R.layout.result_entry,
resultEntries);
mListView.setAdapter(adapter);
// Hide virtual keyboard
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;

import com.microblink.entities.recognizers.Recognizer;
import com.microblink.result.ResultSource;
import com.microblink.result.extract.BaseResultExtractor;
import com.microblink.result.extract.RecognitionResultEntry;
import com.microblink.result.extract.ResultExtractorFactoryProvider;
Expand All @@ -17,8 +23,28 @@
public class ResultFragment extends BaseResultFragment {

public static final String RECOGNIZER_POSITION = "RECOGNIZER_POSITION";

private int mRecognizerPosition;
private ResultSource resultSource = ResultSource.MIXED;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
resultTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> view, View view1, int pos, long l) {
ResultSource newResultSource = ResultSource.values()[pos];
if (newResultSource != resultSource) {
resultSource = newResultSource;
setupListAdapter();
}
}

@Override
public void onNothingSelected(AdapterView<?> view) {
}
});
return view;
}

/**
* Fragment factory.
Expand Down Expand Up @@ -49,13 +75,18 @@ protected List<RecognitionResultEntry> createResultEntries(Context context) {
((ResultFragmentActivity) getActivity()).getRecognizerAtPosition(
mRecognizerPosition);


// Extract data from BaseRecognitionResult
BaseResultExtractor resultExtractor = ResultExtractorFactoryProvider.get().createExtractor(recognizer);
List<RecognitionResultEntry> extractedData = resultExtractor.extractData(getActivity(), recognizer);
List<RecognitionResultEntry> extractedData;

if (resultExtractor.doesSupportResultSourceExtraction()) {
resultTypeSection.setVisibility(View.VISIBLE);
}

extractedData = resultExtractor.extractData(getActivity(), recognizer, resultSource);
if (extractedData.size() <= 0) {
Toast.makeText(getActivity(), "Result list is empty", Toast.LENGTH_SHORT).show();
getActivity().finish();
}

return extractedData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;

import com.microblink.entities.recognizers.Recognizer;
import com.microblink.result.ResultSource;
import com.microblink.results.date.Date;
import com.microblink.results.date.DateResult;

Expand All @@ -16,23 +17,34 @@ public abstract class BaseResultExtractor<ResultType extends Recognizer.Result,
protected RecognizerType mRecognizer;
protected Context mContext;

public List<RecognitionResultEntry> extractData(Context context, RecognizerType recognizer) {
public List<RecognitionResultEntry> extractData(Context context, RecognizerType recognizer, ResultSource resultSource) {
mContext = context;
mBuilder = new RecognitionResultEntry.Builder(context);
mExtractedData = new ArrayList<>();
mRecognizer = recognizer;

ResultType result = recognizer.getResult();
extractData(result);
onDataExtractionDone(result);
extractData(result, resultSource);
onDataExtractionDone(result, resultSource);

return mExtractedData;
}

// override if needed
public boolean doesSupportResultSourceExtraction() {
return false;
}

// override if needed
protected void onDataExtractionDone(ResultType result) {}
protected void onDataExtractionDone(ResultType result, ResultSource resultSource) {
onDataExtractionDone(result);
}

protected abstract void extractData(ResultType result);
protected void extractData(ResultType result, ResultSource resultSource) {
extractData(result);
}

protected void add(int key, String value) {
mExtractedData.add(mBuilder.build(key, value));
Expand All @@ -52,6 +64,13 @@ protected void add(int key, DateResult date) {
mExtractedData.add(mBuilder.build(key, date.getDate()));
}

protected void addIfNotEmpty(int key, DateResult dateResult) {
Date date = dateResult.getDate();
if (date != null && date.getDay() > 0) {
mExtractedData.add(mBuilder.build(key, date));
}
}

protected void add(int key, Date date) {
mExtractedData.add(mBuilder.build(key, date));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import com.microblink.entities.recognizers.Recognizer;
import com.microblink.entities.recognizers.successframe.SuccessFrameGrabberRecognizer;
import com.microblink.libutils.R;
import com.microblink.result.extract.BaseResultExtractor;
import com.microblink.result.extract.ResultExtractorFactoryProvider;
import com.microblink.result.ResultSource;

public class SuccessFrameGrabberResultExtractor extends BaseResultExtractor<SuccessFrameGrabberRecognizer.Result, SuccessFrameGrabberRecognizer> {

@Override
protected void extractData(SuccessFrameGrabberRecognizer.Result result) {
Recognizer slaveRecognizer = mRecognizer.getSlaveRecognizer();
BaseResultExtractor slaveExtractor = ResultExtractorFactoryProvider.get().createExtractor(slaveRecognizer);
mExtractedData.addAll(slaveExtractor.extractData(mContext, slaveRecognizer));
mExtractedData.addAll(slaveExtractor.extractData(mContext, slaveRecognizer, ResultSource.MIXED));
mExtractedData.add(mBuilder.build(
R.string.PPSuccessFrame,
mRecognizer.getResult().getSuccessFrame()
Expand Down
Loading

0 comments on commit e271e5d

Please sign in to comment.