Lettura targa
unknown
java
4 years ago
6.2 kB
7
Indexable
package it.labconsulenze.beta.urbano.activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.WindowManager; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.Set; import at.nineyards.anyline.core.LicenseException; import io.anyline.AnylineSDK; import io.anyline.models.AnylineImage; import io.anyline.plugin.ScanResultListener; import io.anyline.plugin.licenseplate.LicensePlateScanMode; import io.anyline.plugin.licenseplate.LicensePlateScanPlugin; import io.anyline.plugin.licenseplate.LicensePlateScanResult; import io.anyline.plugin.licenseplate.LicensePlateScanViewPlugin; import io.anyline.view.BaseScanViewConfig; import io.anyline.view.ScanView; import io.anyline.view.ScanViewPluginConfig; import it.labconsulenze.beta.urbano.R; import it.labconsulenze.beta.urbano.core.objects.Setting; public class ScanLicensePlateActivity extends AppCompatActivity implements ScanResultListener<LicensePlateScanResult> { public static final String PLATE = "plate"; public static final String CALLER = "caller"; public static final String NATIONALITY = "nationality"; public static final String PATH = "path"; private static final String TAG = ScanLicensePlateActivity.class.getSimpleName(); protected TextView resultText; protected ScanView scanView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Set the flag to keep the screen on (otherwise the screen may go dark during scanning) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_scan_license_plate); // Get the view from the layout scanView = (ScanView) findViewById(R.id.scan_view); resultText = findViewById(R.id.result_text); // This must be called before doing anything Anyline-related! // Try/Catch this to check whether or not your license key is valid! SharedPreferences versionSetting = ScanLicensePlateActivity.this.getSharedPreferences(Setting.SETTING_DEFAULT, Context.MODE_PRIVATE); boolean anyLineEnabled = versionSetting.getBoolean(Setting.ANYLINE_ENABLED, false); if (!anyLineEnabled) { Intent data = new Intent(); data.putExtra("caller", "ScanPlate"); data.putExtra("PLATE", ""); data.putExtra("NATIONALITY", ""); setResult(RESULT_OK, data); finish(); return; } else { try { String license = versionSetting.getString(Setting.ANYLINE_CODE, ""); AnylineSDK.init(license, this); } catch (LicenseException e) { e.printStackTrace(); } } //init the scanViewPlugin configuration which hold the scan view ui configuration (cutoutConfig and ScanFeedbackConfig) ScanViewPluginConfig licensePlateScanviewPluginConfig = new ScanViewPluginConfig(ScanLicensePlateActivity.this, "license_plate_view_config.json"); //init the scan view LicensePlateScanViewPlugin scanViewPlugin = new LicensePlateScanViewPlugin(ScanLicensePlateActivity.this, licensePlateScanviewPluginConfig, "LICENSE_PLATE"); //set License Plate Scan Mode ((LicensePlateScanPlugin) scanViewPlugin.getScanPlugin()).setScanMode(LicensePlateScanMode.Auto); //init the base scanViewconfig which hold camera and flash configuration BaseScanViewConfig licensePlateBaseScanViewConfig = new BaseScanViewConfig(ScanLicensePlateActivity.this, "license_plate_view_config.json"); //set the base scanViewConfig to the ScanView scanView.setScanViewConfig(licensePlateBaseScanViewConfig); //set the scanViewPlugin to the ScanView scanView.setScanViewPlugin(scanViewPlugin); //add result listener scanViewPlugin.addScanResultListener(this); // disable the reporting if set to off in preferences scanView.start(); } @Override protected void onResume() { super.onResume(); } @Override protected void onPause() { super.onPause(); scanView.stop(); scanView.releaseCameraInBackground(); } @Override public void onResult(LicensePlateScanResult result) { scanView.stop(); scanView.releaseCameraInBackground(); final Bundle extras = getIntent().getExtras(); String imagePath = ""; boolean withImage = false; if (extras != null) { imagePath = extras.getString("IMAGEPATH"); withImage = true; } String finalImagePath = imagePath; boolean finalWithImage = withImage; HashMap<String, String> datamap = new HashMap<>(); if (finalWithImage) { AnylineImage imageResult = result.getFullImage(); assert finalImagePath != null; File fullFile = new File(finalImagePath); try { assert imageResult != null; imageResult.save(fullFile, 100); } catch (IOException e) { e.printStackTrace(); } datamap.put(PATH, finalImagePath); } resultText.setText(result.getResult()); datamap.put(PLATE, result.getResult()); datamap.put(NATIONALITY, result.getCountry()); datamap.put(CALLER, "ScanPlate"); Set<String> setKeys = datamap.keySet(); String[] arrayKeys = setKeys.toArray(new String[setKeys.size()]); Collection<String> values = datamap.values(); String[] arrayValues = values.toArray(new String[values.size()]); Intent dataIntent = new Intent(); dataIntent.putExtra("caller", "ScanPlate"); dataIntent.putExtra("resultDataKeys", arrayKeys); dataIntent.putExtra("resultDataValues", arrayValues); setResult(RESULT_OK, dataIntent); finish(); } }
Editor is loading...