mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
13 years ago
|
*********************************************
|
||
12 years ago
|
Base Loader Callback Interface Implementation
|
||
13 years ago
|
*********************************************
|
||
|
|
||
|
.. highlight:: java
|
||
|
.. class:: BaseLoaderCallback
|
||
|
|
||
12 years ago
|
Basic implementation of ``LoaderCallbackInterface``. Logic of this implementation is
|
||
|
well-described by the following scheme:
|
||
13 years ago
|
|
||
13 years ago
|
.. image:: img/AndroidAppUsageModel.png
|
||
13 years ago
|
|
||
12 years ago
|
Using in Java Activity
|
||
|
----------------------
|
||
|
|
||
12 years ago
|
There is a very base code snippet implementing the async initialization with ``BaseLoaderCallback``.
|
||
|
See the "15-puzzle" OpenCV sample for details.
|
||
12 years ago
|
|
||
|
.. 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()
|
||
|
{
|
||
12 years ago
|
Log.i(TAG, "Called onResume");
|
||
12 years ago
|
super.onResume();
|
||
|
|
||
|
Log.i(TAG, "Trying to load OpenCV library");
|
||
12 years ago
|
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mOpenCVCallBack))
|
||
12 years ago
|
{
|
||
|
Log.e(TAG, "Cannot connect to OpenCV Manager");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Using in Service
|
||
|
----------------
|
||
|
|
||
12 years ago
|
Default ``BaseLoaderCallback`` implementation treats 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.
|