diff --git a/BlinkMoto/plugin.xml b/BlinkMoto/plugin.xml index 0947a0c..787bca3 100644 --- a/BlinkMoto/plugin.xml +++ b/BlinkMoto/plugin.xml @@ -52,22 +52,21 @@ - + - - - - + + + + - - - + + + - diff --git a/BlinkMoto/src/android/blinkid-android/LibBlinkID.aar b/BlinkMoto/src/android/blinkid-android/LibBlinkID.aar deleted file mode 100755 index 5fe3b7a..0000000 Binary files a/BlinkMoto/src/android/blinkid-android/LibBlinkID.aar and /dev/null differ diff --git a/BlinkMoto/src/android/blinkid-android/libBlinkID.gradle b/BlinkMoto/src/android/blinkid-android/libBlinkID.gradle index a51d3e6..94d2d3f 100644 --- a/BlinkMoto/src/android/blinkid-android/libBlinkID.gradle +++ b/BlinkMoto/src/android/blinkid-android/libBlinkID.gradle @@ -1,13 +1,14 @@ -repositories{ - jcenter() - flatDir{ - dirs 'aar' - } +repositories { + jcenter() + mavenCentral() + maven { url 'http://maven.microblink.com' } } dependencies { - compile(name:'LibBlinkID', ext:'aar') - compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support:appcompat-v7:25.0.0' + compile('com.microblink:blinkid:3.11.0@aar') { + transitive = false + } } android { diff --git a/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/FakeR.java b/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/FakeR.java new file mode 100644 index 0000000..bf11723 --- /dev/null +++ b/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/FakeR.java @@ -0,0 +1,54 @@ +package com.phonegap.plugins.blinkid; + +import android.app.Activity; +import android.content.Context; + +/** + * Replacement for android resources R in PhoneGap plugins.
+ * Used for resources added with a plugin. Since the application has its own R the plugin must fetch its resources through the activity's context. + */ +public class FakeR { + private Context context; + private String packageName; + + public FakeR(Activity activity) { + context = activity.getApplicationContext(); + packageName = context.getPackageName(); + } + + public FakeR(Context context) { + this.context = context; + packageName = context.getPackageName(); + } + + /** + * Get resource identifier from given group. + * + * @param group id, string, layout, dimen, bool, etc. + * @param key Resource key + * @return Resource identifier + */ + public int getIdFrom(String group, String key) { + return context.getResources().getIdentifier(key, group, packageName); + } + + /** + * Get resource identifier from group id. + * + * @param key Resource key + * @return Resource value + */ + public int getId(String key) { + return getIdFrom("id", key); + } + + /** + * Get resource identifier from group string. + * + * @param key Resource key + * @return Resource value + */ + public String getString(String key) { + return context.getResources().getString(getIdFrom("string", key)); + } +} diff --git a/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/ScanActivity.java b/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/ScanActivity.java index fc504c6..3e70a2a 100644 --- a/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/ScanActivity.java +++ b/BlinkMoto/src/android/java/com/phonegap/plugins/blinkid/ScanActivity.java @@ -22,7 +22,6 @@ import android.widget.ImageView; import android.widget.TextView; -import com.microblink.blinkmoto.R; import com.microblink.detectors.DetectorResult; import com.microblink.detectors.points.PointsDetectorResult; import com.microblink.geometry.Rectangle; @@ -82,6 +81,8 @@ public enum RecognizerType { private final String OCR_PARSER_NAME = "parser"; + private FakeR mFakeR; + private CameraPermissionManager mCameraPermManager; private RecognizerView mRecognizerView; private PointSetView mPointSetView; @@ -109,9 +110,10 @@ private enum ActivityState { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + mFakeR = new FakeR(this); super.onCreate(savedInstanceState); try { - setContentView(R.layout.custom_scan_layout); + setContentView(mFakeR.getIdFrom("layout", "custom_scan_layout")); } catch (InflateException ie) { Throwable cause = ie.getCause(); while (cause.getCause() != null) { @@ -131,7 +133,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { // Set internationalized strings. Bundle extras = getIntent().getExtras(); - mRecognizerView = (RecognizerView) findViewById(R.id.recognizerView); + mRecognizerView = (RecognizerView) findViewById(mFakeR.getId("recognizerView")); // Set license key. String licenseKey = extras.getString(EXTRAS_LICENSE_KEY); @@ -143,7 +145,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { // Add the camera permissions overlay. mCameraPermManager = new CameraPermissionManager(this); - mRecognizerViewRoot = (FrameLayout) findViewById(R.id.recognozerViewRoot); + mRecognizerViewRoot = (FrameLayout) findViewById(mFakeR.getId("recognizerViewRoot")); View cameraPermissionView = mCameraPermManager.getAskPermissionOverlay(); if (cameraPermissionView != null) { mRecognizerViewRoot.addView(cameraPermissionView); @@ -211,20 +213,20 @@ public void onOrientationChange(Orientation orientation) { mRecognizerView.addChildView(mOcrResultView.getView(), false); // Inflate the overlay view. - final ViewGroup overlay = (ViewGroup) getLayoutInflater().inflate(R.layout.custom_scan_overlay, null); + final ViewGroup overlay = (ViewGroup) getLayoutInflater().inflate(mFakeR.getIdFrom("layout", "custom_scan_overlay"), null); // Bind view elements. - mScanViewfinder = (FrameLayout) overlay.findViewById(R.id.fl_scan_frame); - mScanTitleView = (TextView) overlay.findViewById(R.id.tv_scan_title); - mScanResultStringView = (TextView) overlay.findViewById(R.id.tv_scan_result); - mScanResultImageView = (ImageView) overlay.findViewById(R.id.iv_scan_result); - mAcceptButton = (Button) overlay.findViewById(R.id.btn_accept); - mCancelButton = (Button) overlay.findViewById(R.id.btn_cancel); - mRepeatButton = (Button) overlay.findViewById(R.id.btn_repeat); + mScanViewfinder = (FrameLayout) overlay.findViewById(mFakeR.getId("fl_scan_frame")); + mScanTitleView = (TextView) overlay.findViewById(mFakeR.getId("tv_scan_title")); + mScanResultStringView = (TextView) overlay.findViewById(mFakeR.getId("tv_scan_result")); + mScanResultImageView = (ImageView) overlay.findViewById(mFakeR.getId("iv_scan_result")); + mAcceptButton = (Button) overlay.findViewById(mFakeR.getId("btn_accept")); + mCancelButton = (Button) overlay.findViewById(mFakeR.getId("btn_cancel")); + mRepeatButton = (Button) overlay.findViewById(mFakeR.getId("btn_repeat")); // Set user defined titles. - mScanTitleView.setText(extras.getString(EXTRAS_TITLE_STRING, getString(R.string.scanning_title))); - mAcceptButton.setText(extras.getString(EXTRAS_ACCEPT_STRING, getString(R.string.accept))); - mCancelButton.setText(extras.getString(EXTRAS_CANCEL_STRING, getString(R.string.cancel))); - mRepeatButton.setText(extras.getString(EXTRAS_REPEAT_STRING, getString(R.string.repeat))); + mScanTitleView.setText(extras.getString(EXTRAS_TITLE_STRING, mFakeR.getString("blinkid_scanning_title"))); + mAcceptButton.setText(extras.getString(EXTRAS_ACCEPT_STRING, mFakeR.getString("blinkid_accept"))); + mCancelButton.setText(extras.getString(EXTRAS_CANCEL_STRING, mFakeR.getString("blinkid_cancel"))); + mRepeatButton.setText(extras.getString(EXTRAS_REPEAT_STRING, mFakeR.getString("blinkid_repeat"))); // Result image invisible at start. mScanResultImageView.setVisibility(View.GONE); // Cannot accept or retry when scanning is in progress. @@ -267,7 +269,7 @@ public void run() { } // Subtract the relative horizontal padding - int horizontalPadding = (int) getResources().getDimension(R.dimen.scan_region_padding); + int horizontalPadding = (int) getResources().getDimension(mFakeR.getIdFrom("dimen", "blinkid_scan_region_padding")); width -= horizontalPadding * 2; // Calculate the height based on given aspect ratio @@ -426,30 +428,28 @@ public void onActivityFlip() { } public void onButtonClicked(View view) { - switch (view.getId()) { - case R.id.btn_accept: - Intent intent = new Intent(); - intent.putExtra(EXTRAS_RESULT_STRING, mScanResultStringView.getText().toString()); - setResult(RESULT_OK, intent); - finish(); - break; - - case R.id.btn_cancel: - setResult(RESULT_CANCELED); - finish(); - break; - - case R.id.btn_repeat: - mScanResultImageView.setBackground(null); - mScanResultImageView.setVisibility(View.GONE); - mScanResultStringView.setVisibility(View.INVISIBLE); - mAcceptButton.setEnabled(false); - mRepeatButton.setEnabled(false); - mRecognizerView.resumeScanning(true); - break; + int id = view.getId(); + if (id == mFakeR.getId("btn_accept")) { + Intent intent = new Intent(); + intent.putExtra(EXTRAS_RESULT_STRING, mScanResultStringView.getText().toString()); + setResult(RESULT_OK, intent); + finish(); + + } else if (id == mFakeR.getId("btn_cancel")) { + setResult(RESULT_CANCELED); + finish(); + + } else if (id == mFakeR.getId("btn_repeat")) { + mScanResultImageView.setBackground(null); + mScanResultImageView.setVisibility(View.GONE); + mScanResultStringView.setVisibility(View.INVISIBLE); + mAcceptButton.setEnabled(false); + mRepeatButton.setEnabled(false); + mRecognizerView.resumeScanning(true); } } + @Override public void onScanningDone(@Nullable final RecognitionResults recognitionResults) { if (mRecognizerView != null) { @@ -496,7 +496,7 @@ public void run() { mScanResultImageView.setImageBitmap(bitmap); } - String resultString = getString(R.string.unknown_result); + String resultString = mFakeR.getString("blinkid_unknown_result"); if (result instanceof VinScanResult) { resultString = ((VinScanResult) result).getVin(); @@ -509,7 +509,7 @@ public void run() { resultString = parsedAmount; } } else { - resultString = getString(R.string.invalid_result_message); + resultString = mFakeR.getString("blinkid_invalid_result_message"); } } @@ -536,9 +536,9 @@ public void onError(Throwable throwable) { if (mActivityState == ActivityState.RESUMED || mActivityState == ActivityState.STARTED) { AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setCancelable(false) - .setTitle(R.string.error_dialog_title) + .setTitle(mFakeR.getString("blinkid_error_dialog_title")) .setMessage(throwable.getClass().getSimpleName() + ": " + throwable.getMessage()) - .setNeutralButton(R.string.error_dialog_ok, new DialogInterface.OnClickListener() { + .setNeutralButton(mFakeR.getString("blinkid_error_dialog_ok"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (dialog != null) dialog.dismiss(); diff --git a/BlinkMoto/src/android/res/drawable/button_accent.xml b/BlinkMoto/src/android/res/drawable/blinkid_button_accent.xml similarity index 71% rename from BlinkMoto/src/android/res/drawable/button_accent.xml rename to BlinkMoto/src/android/res/drawable/blinkid_button_accent.xml index 666a41d..c81935c 100644 --- a/BlinkMoto/src/android/res/drawable/button_accent.xml +++ b/BlinkMoto/src/android/res/drawable/blinkid_button_accent.xml @@ -3,14 +3,14 @@ - + - + diff --git a/BlinkMoto/src/android/res/drawable/blinkid_button_accent_text_color.xml b/BlinkMoto/src/android/res/drawable/blinkid_button_accent_text_color.xml new file mode 100644 index 0000000..7142e54 --- /dev/null +++ b/BlinkMoto/src/android/res/drawable/blinkid_button_accent_text_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/BlinkMoto/src/android/res/drawable/button_normal.xml b/BlinkMoto/src/android/res/drawable/blinkid_button_normal.xml similarity index 71% rename from BlinkMoto/src/android/res/drawable/button_normal.xml rename to BlinkMoto/src/android/res/drawable/blinkid_button_normal.xml index 3327db1..7f79bb6 100644 --- a/BlinkMoto/src/android/res/drawable/button_normal.xml +++ b/BlinkMoto/src/android/res/drawable/blinkid_button_normal.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/BlinkMoto/src/android/res/drawable/scan_frame.xml b/BlinkMoto/src/android/res/drawable/blinkid_scan_frame.xml similarity index 74% rename from BlinkMoto/src/android/res/drawable/scan_frame.xml rename to BlinkMoto/src/android/res/drawable/blinkid_scan_frame.xml index dcc71e4..010c3c5 100644 --- a/BlinkMoto/src/android/res/drawable/scan_frame.xml +++ b/BlinkMoto/src/android/res/drawable/blinkid_scan_frame.xml @@ -2,6 +2,6 @@ + android:color="@color/blinkid_scan_frame_border_color" /> \ No newline at end of file diff --git a/BlinkMoto/src/android/res/drawable/button_accent_text_color.xml b/BlinkMoto/src/android/res/drawable/button_accent_text_color.xml deleted file mode 100644 index b65ef50..0000000 --- a/BlinkMoto/src/android/res/drawable/button_accent_text_color.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/BlinkMoto/src/android/res/layout/custom_scan_layout.xml b/BlinkMoto/src/android/res/layout/custom_scan_layout.xml index ace1c21..099692f 100644 --- a/BlinkMoto/src/android/res/layout/custom_scan_layout.xml +++ b/BlinkMoto/src/android/res/layout/custom_scan_layout.xml @@ -1,7 +1,7 @@ diff --git a/BlinkMoto/src/android/res/layout/custom_scan_overlay.xml b/BlinkMoto/src/android/res/layout/custom_scan_overlay.xml index 05e51f8..58c16cd 100644 --- a/BlinkMoto/src/android/res/layout/custom_scan_overlay.xml +++ b/BlinkMoto/src/android/res/layout/custom_scan_overlay.xml @@ -17,12 +17,12 @@ android:layout_above="@+id/horizontal_container" android:layout_alignParentTop="true" - android:background="@color/scan_shade" + android:background="@color/blinkid_scan_shade" android:padding="6dp" android:gravity="center_horizontal|bottom" android:textColor="#fff" - android:textSize="@dimen/scan_title_text_size" + android:textSize="@dimen/blinkid_scan_title_text_size" tools:text="Bitte die FIN / VIN oder Barcode in diesem Bereich erfassen" /> + android:background="@color/blinkid_scan_shade" /> + android:background="@color/blinkid_scan_shade" /> - #a0000000 - #fff + #a0000000 + #fff - #aaaaaa - #10a3c1 - #fff - #555 + #aaaaaa + #10a3c1 + #fff + #555 \ No newline at end of file diff --git a/BlinkMoto/src/android/res/values/dimens.xml b/BlinkMoto/src/android/res/values/dimens.xml index 0766957..86c2528 100644 --- a/BlinkMoto/src/android/res/values/dimens.xml +++ b/BlinkMoto/src/android/res/values/dimens.xml @@ -1,10 +1,10 @@ - 32dp + 32dp - 36dp - 8dp - 10dp - 12sp - 16sp + 36dp + 8dp + 10dp + 12sp + 16sp \ No newline at end of file diff --git a/BlinkMoto/src/android/res/values/strings.xml b/BlinkMoto/src/android/res/values/strings.xml index 1bd6e2b..049bd6c 100644 --- a/BlinkMoto/src/android/res/values/strings.xml +++ b/BlinkMoto/src/android/res/values/strings.xml @@ -1,18 +1,15 @@ - BlinkMotoDemo - @string/app_name - @string/launcher_name - Scanning result holder + Scanning result holder - Position the data here - Accept - Cancel - Repeat + Position the data here + Accept + Cancel + Repeat - Unknown result - Invalid result, please try again. + Unknown result + Invalid result, please try again. - Error - OK + Error + OK