CLAHE Python bindings
[profile/ivi/opencv.git] / platforms / android / service / doc / BaseLoaderCallback.rst
1 *********************************************
2 Base Loader Callback Interface Implementation
3 *********************************************
4
5 .. highlight:: java
6 .. class:: BaseLoaderCallback
7
8     Basic implementation of ``LoaderCallbackInterface``. Logic of this implementation is
9     well-described by the following scheme:
10
11 .. image:: img/AndroidAppUsageModel.png
12
13 Using in Java Activity
14 ----------------------
15
16 There is a very base code snippet implementing the async initialization with ``BaseLoaderCallback``.
17 See the "15-puzzle" OpenCV sample for details.
18
19 .. code-block:: java
20     :linenos:
21
22     public class MyActivity extends Activity implements HelperCallbackInterface
23     {
24     private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
25        @Override
26        public void onManagerConnected(int status) {
27          switch (status) {
28            case LoaderCallbackInterface.SUCCESS:
29            {
30               Log.i(TAG, "OpenCV loaded successfully");
31               // Create and set View
32               mView = new puzzle15View(mAppContext);
33               setContentView(mView);
34            } break;
35            default:
36            {
37               super.onManagerConnected(status);
38            } break;
39          }
40        }
41     };
42
43     /** Call on every application resume **/
44     @Override
45     protected void onResume()
46     {
47         Log.i(TAG, "Called onResume");
48         super.onResume();
49
50         Log.i(TAG, "Trying to load OpenCV library");
51         if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_4, this, mOpenCVCallBack))
52         {
53             Log.e(TAG, "Cannot connect to OpenCV Manager");
54         }
55     }
56
57 Using in Service
58 ----------------
59
60 Default ``BaseLoaderCallback`` implementation treats application context as ``Activity`` and calls
61 ``Activity.finish()`` method to exit in case of initialization failure.
62 To override this behavior you need to override ``finish()`` method of ``BaseLoaderCallback`` class
63 and implement your own finalization method.