Permalink
Browse files

Sync with sdt-anpr-sdk 1.0.11

  • Loading branch information...
sd-toolkit committed Jan 6, 2018
1 parent de577ff commit 06793c78849fb7f0bdf5c4f8e4a1a2b874937aa4
Showing with 715 additions and 0 deletions.
  1. +9 −0 AnprReader/.gitignore
  2. +1 −0 AnprReader/app/.gitignore
  3. +26 −0 AnprReader/app/build.gradle
  4. +21 −0 AnprReader/app/proguard-rules.pro
  5. +21 −0 AnprReader/app/src/main/AndroidManifest.xml
  6. +267 −0 AnprReader/app/src/main/java/com/sdtoolkit/anprreader/MainActivity.java
  7. +34 −0 AnprReader/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
  8. +170 −0 AnprReader/app/src/main/res/drawable/ic_launcher_background.xml
  9. +53 −0 AnprReader/app/src/main/res/layout-land/activity_main.xml
  10. +49 −0 AnprReader/app/src/main/res/layout/activity_main.xml
  11. +5 −0 AnprReader/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  12. +5 −0 AnprReader/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  13. BIN AnprReader/app/src/main/res/mipmap-hdpi/ic_launcher.png
  14. BIN AnprReader/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
  15. BIN AnprReader/app/src/main/res/mipmap-mdpi/ic_launcher.png
  16. BIN AnprReader/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
  17. BIN AnprReader/app/src/main/res/mipmap-xhdpi/ic_launcher.png
  18. BIN AnprReader/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  19. BIN AnprReader/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  20. BIN AnprReader/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  21. BIN AnprReader/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  22. BIN AnprReader/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
  23. +6 −0 AnprReader/app/src/main/res/values/colors.xml
  24. +6 −0 AnprReader/app/src/main/res/values/strings.xml
  25. +11 −0 AnprReader/app/src/main/res/values/styles.xml
  26. +30 −0 AnprReader/build.gradle
  27. +1 −0 AnprReader/settings.gradle
View
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
@@ -0,0 +1 @@
/build
@@ -0,0 +1,26 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.sdtoolkit.anprreader"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.sd-toolkit.developer:anpr-sdk:1.0.11'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sdtoolkit.anprreader">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,267 @@
package com.sdtoolkit.anprreader;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.sdtoolkit.anpr.api.AnprEngineFactory;
import com.sdtoolkit.anpr.api.AnprErrors;
import com.sdtoolkit.anpr.api.AnprResult;
import com.sdtoolkit.anpr.api.DeviceParams;
import com.sdtoolkit.anpr.api.IAnprEngine;
import com.sdtoolkit.anpr.api.IAnprEngineListener;
import com.sdtoolkit.anpr.api.RecognitionParams;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private final int REQUEST_ALL_PERMISSIONS = 0x4562;
private final int REQUEST_INSTALL_SDTANPR = 0x4563;
private final int REQUEST_CONFIGURE_SDTANPR = 0x4563;
private Button mButStart;
private Button mButStop;
private Button mButConfigure;
private TextView mTextResults;
private IAnprEngine mAnprEngine;
private DeviceParams mDeviceParams = new DeviceParams();
private RecognitionParams mRecognitionParams = new RecognitionParams();
private IAnprEngineListener mAnprEngineListener = new IAnprEngineListener() {
@Override
public void onAnprOpened(int result,
DeviceParams currentDeviceParams,
RecognitionParams currentRecognitionParams) {
// Recognition parameters currently set in the ANPR Service
// This application does not modify any parameters and just update local copy
mDeviceParams.copyFrom(currentDeviceParams);
mRecognitionParams.copyFrom(currentRecognitionParams);
if (!mAnprEngine.isRecognitionRunning()) {
mAnprEngine.setup(mDeviceParams);
}
}
@Override
public void onAnprClosed(int result) {
}
@Override
public void onAnprSetupComplete(int result, DeviceParams currentDeviceParams) {
}
@Override
public void onAnprStarted(int result) {
}
@Override
public void onAnprStopped(int result) {
}
@Override
public void onAnprResult(int status, AnprResult[] results, Bitmap resultFrame) {
if (status == AnprErrors.SUCCESS) {
populateRecognitionResults(results, resultFrame);
}
}
@Override
public void onAnprSettingsChanged(DeviceParams currentDeviceParams,
RecognitionParams currentRecognitionParams) {
mDeviceParams.copyFrom(currentDeviceParams);
mRecognitionParams.copyFrom(currentRecognitionParams);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] permissions = retrieveNotGrantedPermissions();
if (permissions != null && permissions.length > 0) {
ActivityCompat.requestPermissions(this, permissions, REQUEST_ALL_PERMISSIONS);
}
if (!isAnprServiceIsInstalled()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Unable to find SD-TOOLKIT ANPR Serivce");
builder.setCancelable(false);
builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.sdtoolkit.anprservice"));
startActivityForResult(intent, REQUEST_INSTALL_SDTANPR);
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
mButStart = findViewById(R.id.but_start);
mButStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onAnprEngineStart();
}
});
mButStop = findViewById(R.id.but_stop);
mButStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onAnprEngineStop();
}
});
mButConfigure = findViewById(R.id.but_configure);
mButConfigure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onAnprEngineConfigure();
}
});
mTextResults = findViewById(R.id.text_results);
// Create Anpr Engine instance
mAnprEngine = AnprEngineFactory.createAnprEngine(this);
// Create intent to be used when user clicks system notification bar icon
Intent runIntent = new Intent(this, this.getClass());
runIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
mAnprEngine.open(mAnprEngineListener, runIntent);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mAnprEngine != null) {
mAnprEngine.close();
mAnprEngine = null;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_INSTALL_SDTANPR) {
recreate();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == REQUEST_ALL_PERMISSIONS) {
for(int gC = 0; gC < grantResults.length; gC++) {
if (grantResults[gC] != PackageManager.PERMISSION_GRANTED) {
// Notify User that not all permissions are granted
Toast.makeText(this,
"Not all permissions has been granted. Quitting...",
Toast.LENGTH_LONG).show();
finish();
}
}
recreate();
}
}
private String[] retrieveNotGrantedPermissions() {
ArrayList<String> nonGrantedPerms = new ArrayList<>();
try {
String[] manifestPerms = getPackageManager()
.getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS)
.requestedPermissions;
if (manifestPerms == null || manifestPerms.length == 0) {
return null;
}
for (String permName : manifestPerms) {
int permission = ActivityCompat.checkSelfPermission(this, permName);
if (permission != PackageManager.PERMISSION_GRANTED) {
nonGrantedPerms.add(permName);
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return nonGrantedPerms.toArray(new String[nonGrantedPerms.size()]);
}
private boolean isAnprServiceIsInstalled() {
try {
ApplicationInfo info = getPackageManager().getApplicationInfo(
"com.sdtoolkit.anprservice", 0);
if (info != null && info.enabled) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return false;
}
private void onAnprEngineStart() {
if (mAnprEngine != null) {
mAnprEngine.beginRecognition(mRecognitionParams);
}
}
private void onAnprEngineStop() {
if (mAnprEngine != null) {
mAnprEngine.endRecognition();
}
}
private void onAnprEngineConfigure() {
// Call SDT Anpr service property here
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.sdtoolkit.anprservice",
"com.sdtoolkit.anpr.activity.AnprSettingsActivity"));
startActivityForResult(intent, REQUEST_CONFIGURE_SDTANPR);
}
private void populateRecognitionResults(final AnprResult[] results, final Bitmap resultsFrame) {
if (results == null || results.length == 0) {
return;
}
this.runOnUiThread(new Runnable() {
@Override
public void run() {
for (AnprResult result : results) {
mTextResults.append(result.getPlate() + "\r\n");
}
}
});
}
}
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
Oops, something went wrong.

0 comments on commit 06793c7

Please sign in to comment.