Issue #2284 BaseLoaderCallback requires use of Activity fixed.
This commit is contained in:
parent
a9f36dfcfe
commit
306ed9801a
@ -9,3 +9,52 @@ Base Loader Callback Interface implementation
|
|||||||
|
|
||||||
.. image:: img/AndroidAppUsageModel.png
|
.. 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.
|
||||||
|
|
||||||
|
@ -112,6 +112,8 @@ There is a very base code snippet implementing the async initialization. It show
|
|||||||
It this case application works with OpenCV Manager in asynchronous fashion. ``OnManagerConnected`` callback will be called in UI thread, when initialization finishes.
|
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.
|
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.
|
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
|
Application development with static initialization
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -2,6 +2,7 @@ package org.opencv.android;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -11,7 +12,7 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
||||||
|
|
||||||
public BaseLoaderCallback(Activity AppContext) {
|
public BaseLoaderCallback(Context AppContext) {
|
||||||
mAppContext = AppContext;
|
mAppContext = AppContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
|||||||
MarketErrorMessage.setCancelable(false); // This blocks the 'BACK' button
|
MarketErrorMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||||
MarketErrorMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
MarketErrorMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
mAppContext.finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
MarketErrorMessage.show();
|
MarketErrorMessage.show();
|
||||||
@ -43,7 +44,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
|||||||
case LoaderCallbackInterface.INSTALL_CANCELED:
|
case LoaderCallbackInterface.INSTALL_CANCELED:
|
||||||
{
|
{
|
||||||
Log.d(TAG, "OpenCV library instalation was canceled by user");
|
Log.d(TAG, "OpenCV library instalation was canceled by user");
|
||||||
mAppContext.finish();
|
finish();
|
||||||
} break;
|
} break;
|
||||||
/** Application is incompatible with this version of OpenCV Manager. Possibly, a service update is required. **/
|
/** Application is incompatible with this version of OpenCV Manager. Possibly, a service update is required. **/
|
||||||
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
|
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
|
||||||
@ -55,7 +56,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
|||||||
IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button
|
IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||||
IncomatibilityMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
IncomatibilityMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
mAppContext.finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
IncomatibilityMessage.show();
|
IncomatibilityMessage.show();
|
||||||
@ -71,7 +72,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
|||||||
InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
mAppContext.finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -130,6 +131,11 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Activity mAppContext;
|
void finish()
|
||||||
|
{
|
||||||
|
((Activity) mAppContext).finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Context mAppContext;
|
||||||
private final static String TAG = "OpenCVLoader/BaseLoaderCallback";
|
private final static String TAG = "OpenCVLoader/BaseLoaderCallback";
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
#!/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));
|
|
Loading…
x
Reference in New Issue
Block a user