Skip to content

Commit

Permalink
Merge pull request #14 from regulaforensics/release-6.3
Browse files Browse the repository at this point in the history
Release 6.3
  • Loading branch information
syakimchik authored Apr 22, 2022
2 parents 5ee716c + 580b32a commit 5fbf4f6
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 11,108 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
**/bin/*
**/packages/*
*.license
DocumentReaderSample.Forms/DocumentReaderSample.iOS/Resources/db.dat
DocumentReaderSample.Forms/DocumentReaderSample.Android/Assets/Regula/db.dat
**/db.dat
**/Resource.designer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@
<Version>2.0.4.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.DocumentReader.Core.FullRfid.Android">
<Version>6.2.6659</Version>
<Version>6.3.6945</Version>
</PackageReference>
<PackageReference Include="Xamarin.DocumentReader.Api.Android">
<Version>6.2.6717</Version>
</PackageReference>
<PackageReference Include="Xamarin.DocumentReader.Common.Android">
<Version>6.2.974</Version>
<Version>6.3.6946</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.1" />
<PackageReference Include="Xamarin.DocumentReader.Api.iOS">
<Version>6.2.2441</Version>
</PackageReference>
<PackageReference Include="Xamarin.DocumentReader.Core.FullRfid.iOS">
<Version>6.2.6022</Version>
<Version>6.3.6220</Version>
</PackageReference>
<PackageReference Include="Xamarin.DocumentReader.Api.iOS">
<Version>6.3.2494</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
Expand Down
Empty file.
358 changes: 231 additions & 127 deletions DocumentReaderSample/Droid/DocumentReaderSample.Droid.csproj

Large diffs are not rendered by default.

102 changes: 31 additions & 71 deletions DocumentReaderSample/Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
Expand All @@ -15,21 +14,18 @@
using Com.Regula.Documentreader.Api.Enums;
using Android.Util;
using Android.Graphics;
using Android;
using Android.Support.V4.App;
using Android.Support.V4.Content;
using Com.Regula.Documentreader.Api.Completions;
using Com.Regula.Documentreader.Api.Errors;
using Com.Regula.Documentreader.Api.Params;

namespace DocumentReaderSample.Droid
{
[Activity(Label = "DocumentReaderSample", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : FragmentActivity, IDocumentReaderInitCompletion, IDocumentReaderCompletion, IDocumentReaderPrepareCompletion
public class MainActivity : Activity, IDocumentReaderInitCompletion, IDocumentReaderCompletion, IDocumentReaderPrepareCompletion
{
const int REQUEST_BROWSE_PICTURE = 11;
const int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 22;
const String MY_SHARED_PREFS = "MySharedPrefs";
const String DO_RFID = "doRfid";
const string MY_SHARED_PREFS = "MySharedPrefs";
const string DO_RFID = "doRfid";

public TextView nameTv;
public TextView showScanner;
Expand All @@ -43,8 +39,8 @@ public class MainActivity : FragmentActivity, IDocumentReaderInitCompletion, IDo
private ListView scenarioLv;

private ISharedPreferences sharedPreferences;
private Boolean doRfid;
private Boolean isStartRfid;
private bool doRfid;
private bool isStartRfid;

AlertDialog initDialog;
AlertDialog updateDBDialog;
Expand Down Expand Up @@ -72,28 +68,25 @@ protected override void OnCreate(Bundle bundle)

sharedPreferences = GetSharedPreferences(MY_SHARED_PREFS, FileCreationMode.Private);

updateDBDialog = showDialog("Updating DB");
updateDBDialog = ShowDialog("Updating DB");
DocumentReader.Instance().PrepareDatabase(this, "Full", this);
}

protected void initReader()
protected void InitReader()
{
var bytes = default(byte[]);
using (var streamReader = new StreamReader(Assets.Open("regula.license")))
{
using (var memstream = new MemoryStream())
{
streamReader.BaseStream.CopyTo(memstream);
bytes = memstream.ToArray();
}
using var memstream = new MemoryStream();
streamReader.BaseStream.CopyTo(memstream);
bytes = memstream.ToArray();
}

initDialog = showDialog("Initializing");
DocumentReader.Instance().InitializeReader(this, bytes, this);
initDialog = ShowDialog("Initializing");
DocumentReader.Instance().InitializeReader(this, new DocReaderConfig(bytes), this);
}


protected AlertDialog showDialog(String msg)
protected AlertDialog ShowDialog(string msg)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
View dialogView = LayoutInflater.Inflate(Resource.Layout.simple_dialog, null);
Expand All @@ -115,7 +108,7 @@ public void DisplayResults(DocumentReaderResults results)
if (results != null)
{
var name = results.GetTextFieldValueByType(EVisualFieldType.FtSurnameAndGivenNames);
if (!String.IsNullOrEmpty(name))
if (!string.IsNullOrEmpty(name))
{
nameTv.Text = name;
}
Expand All @@ -130,17 +123,13 @@ public void DisplayResults(DocumentReaderResults results)
}
}

using (var portraitImage = results.GetGraphicFieldImageByType(EGraphicFieldType.GfPortrait))
{
if (portraitImage != null)
portraitIv.SetImageBitmap(portraitImage);
}
using var portraitImage = results.GetGraphicFieldImageByType(EGraphicFieldType.GfPortrait);
if (portraitImage != null)
portraitIv.SetImageBitmap(portraitImage);

using (var documentImage = results.GetGraphicFieldImageByType(EGraphicFieldType.GfDocumentImage))
{
if (documentImage != null)
docImageIv.SetImageBitmap(documentImage);
}
using var documentImage = results.GetGraphicFieldImageByType(EGraphicFieldType.GfDocumentImage);
if (documentImage != null)
docImageIv.SetImageBitmap(documentImage);

}
}
Expand All @@ -156,24 +145,6 @@ private void CreateImageBrowsingRequest()
StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), REQUEST_BROWSE_PICTURE);
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE)
{
// If request is cancelled, the result arrays are empty.
if (grantResults.Length > 0 && grantResults[0] == Permission.Granted)
{
//access to gallery is allowed
CreateImageBrowsingRequest();
}
else
{
Toast.MakeText(this, "Permission required, to browse images", ToastLength.Long).Show();
}
}
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Expand All @@ -185,7 +156,7 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int
var selectedImage = data.Data;
var bmp = GetBitmap(selectedImage, 1920, 1080);

loadingDialog = showDialog("Processing image");
loadingDialog = ShowDialog("Processing image");

DocumentReader.Instance().StopScanner(this);
DocumentReader.Instance().RecognizeImage(bmp, this);
Expand All @@ -212,17 +183,7 @@ public void OnInitCompleted(bool success, DocumentReaderException error)

recognizeImage.Click += delegate {
СlearResults();

//checking for image browsing permissions
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}
else
{
//start image browsing
CreateImageBrowsingRequest();
}
CreateImageBrowsingRequest();
};

if (DocumentReader.Instance().IsRFIDAvailableForUse)
Expand All @@ -241,7 +202,7 @@ public void OnInitCompleted(bool success, DocumentReaderException error)

//getting current processing scenario and loading available scenarios to ListView
var currentScenario = DocumentReader.Instance().ProcessParams().Scenario;
var scenarios = new List<String>();
var scenarios = new List<string>();
foreach (DocumentReaderScenario scenario in DocumentReader.Instance().AvailableScenarios)
{
scenarios.Add(scenario.Name);
Expand Down Expand Up @@ -287,20 +248,20 @@ public void OnCompleted(int action, DocumentReaderResults results, DocumentReade
if (!isStartRfid && doRfid && results != null && results.ChipPage != 0)
{
//setting the chip's access key - mrz on car access number
string accessKey = null;
if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStringsIcaoRfid)) != null && !String.IsNullOrEmpty(accessKey))
string accessKey;
if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStringsIcaoRfid)) != null && !string.IsNullOrEmpty(accessKey))
{
accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStringsIcaoRfid).Replace("^", "").Replace("\n", "");
DocumentReader.Instance().RfidScenario().Mrz = accessKey;
DocumentReader.Instance().RfidScenario().PacePasswordType = ERFID_Password_Type.PptMrz;
}
else if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStrings)) != null && !String.IsNullOrEmpty(accessKey))
else if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStrings)) != null && !string.IsNullOrEmpty(accessKey))
{
accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStrings).Replace("^", "").Replace("\n", "");
DocumentReader.Instance().RfidScenario().Mrz = accessKey;
DocumentReader.Instance().RfidScenario().PacePasswordType = ERFID_Password_Type.PptMrz;
}
else if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtCardAccessNumber)) != null && !String.IsNullOrEmpty(accessKey))
else if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtCardAccessNumber)) != null && !string.IsNullOrEmpty(accessKey))
{
DocumentReader.Instance().RfidScenario().Password = accessKey;
DocumentReader.Instance().RfidScenario().PacePasswordType = ERFID_Password_Type.PptCan;
Expand Down Expand Up @@ -339,7 +300,7 @@ public void OnPrepareCompleted(bool status, DocumentReaderException error1)
updateDBDialog.Dismiss();
}

initReader();
InitReader();
}

public void OnPrepareProgressChanged(int progress)
Expand All @@ -350,8 +311,7 @@ public void OnPrepareProgressChanged(int progress)
private Bitmap GetBitmap(Android.Net.Uri selectedImage, int targetWidth, int targetHeight)
{
var inputStream = ContentResolver.OpenInputStream(selectedImage);
var options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
var options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeStream(inputStream, null, options);

//Re-reading the input stream to move it's pointer to start
Expand Down Expand Up @@ -391,7 +351,7 @@ private int CalculateInSampleSize(BitmapFactory.Options options, int bitmapWidth
return inSampleSize;
}

class ScenarioAdapter : ArrayAdapter<String>
class ScenarioAdapter : ArrayAdapter<string>
{
public int SelectedPosition
{
Expand Down
Loading

0 comments on commit 5fbf4f6

Please sign in to comment.