.. image:: img/AndroidAppUsageModel.png
+Using in Java Activity
+----------------------
+
+There is a very base code snippet implementing the async initialization with BaseLoaderCallback. See the "15-puzzle" OpenCV sample for details.
+
+.. code-block:: java
+ :linenos:
+
+ public class MyActivity extends Activity implements HelperCallbackInterface
+ {
+ private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
+ @Override
+ public void onManagerConnected(int status) {
+ switch (status) {
+ case LoaderCallbackInterface.SUCCESS:
+ {
+ Log.i(TAG, "OpenCV loaded successfully");
+ // Create and set View
+ mView = new puzzle15View(mAppContext);
+ setContentView(mView);
+ } break;
+ default:
+ {
+ super.onManagerConnected(status);
+ } break;
+ }
+ }
+ };
+
+ /** Call on every application resume **/
+ @Override
+ protected void onResume()
+ {
+ Log.i(TAG, "called onResume");
+ super.onResume();
+
+ Log.i(TAG, "Trying to load OpenCV library");
+ if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
+ {
+ Log.e(TAG, "Cannot connect to OpenCV Manager");
+ }
+ }
+
+Using in Service
+----------------
+
+Default BaseLoaderCallback implementation treat application context as Activity and calls Activity.finish() method to exit in case of initialization failure.
+To override this behavior you need to override finish() method of BaseLoaderCallback class and implement your own finalization method.
+
It this case application works with OpenCV Manager in asynchronous fashion. ``OnManagerConnected`` callback will be called in UI thread, when initialization finishes.
Please note, that it is not allowed to use OpenCV calls or load OpenCV-dependent native libs before invoking this callback.
Load your own native libraries that depend on OpenCV after the successful OpenCV initialization.
+Default BaseLoaderCallback implementation treat application context as Activity and calls Activity.finish() method to exit in case of initialization failure.
+To override this behavior you need to override finish() method of BaseLoaderCallback class and implement your own finalization method.
Application development with static initialization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;
*/
public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
- public BaseLoaderCallback(Activity AppContext) {
+ public BaseLoaderCallback(Context AppContext) {
mAppContext = AppContext;
}
MarketErrorMessage.setCancelable(false); // This blocks the 'BACK' button
MarketErrorMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- mAppContext.finish();
+ finish();
}
});
MarketErrorMessage.show();
case LoaderCallbackInterface.INSTALL_CANCELED:
{
Log.d(TAG, "OpenCV library instalation was canceled by user");
- mAppContext.finish();
+ finish();
} break;
/** Application is incompatible with this version of OpenCV Manager. Possibly, a service update is required. **/
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button
IncomatibilityMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- mAppContext.finish();
+ finish();
}
});
IncomatibilityMessage.show();
InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- mAppContext.finish();
+ finish();
}
});
}
}
- protected Activity mAppContext;
+ void finish()
+ {
+ ((Activity) mAppContext).finish();
+ }
+
+ protected Context mAppContext;
private final static String TAG = "OpenCVLoader/BaseLoaderCallback";
}
+++ /dev/null
-#!/usr/bin/python
-
-import os
-import shutil
-
-for f in os.listdir("."):
- shutil.copyfile(f, os.path.join("../../../../../../modules/java/generator/src/java/", "android+" + f));
\ No newline at end of file