mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
Wating for OpenCV Manager installation added.
This commit is contained in:
parent
601b87e3ed
commit
11839e2cc9
@ -33,8 +33,7 @@ class AsyncServiceHelper
|
||||
}
|
||||
}
|
||||
|
||||
protected AsyncServiceHelper(String Version, Context AppContext,
|
||||
LoaderCallbackInterface Callback)
|
||||
protected AsyncServiceHelper(String Version, Context AppContext, LoaderCallbackInterface Callback)
|
||||
{
|
||||
mOpenCVersion = Version;
|
||||
mUserAppCallback = Callback;
|
||||
@ -48,62 +47,109 @@ class AsyncServiceHelper
|
||||
protected String mOpenCVersion;
|
||||
protected Context mAppContext;
|
||||
protected int mStatus = LoaderCallbackInterface.SUCCESS;
|
||||
protected static boolean mServiceInstallationProgress = false;
|
||||
protected static boolean mLibraryInstallationProgress = false;
|
||||
|
||||
private static void InstallService(final Context AppContext, final LoaderCallbackInterface Callback)
|
||||
protected static boolean InstallServiceQuiet(Context context)
|
||||
{
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
private Context mAppContext = AppContext;
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV Manager via Google Play");
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mAppContext.startActivity(intent);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
int Status = LoaderCallbackInterface.RESTART_REQUIRED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
int Status = LoaderCallbackInterface.MARKET_ERROR;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallQuery);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected static void InstallService(final Context AppContext, final LoaderCallbackInterface Callback)
|
||||
{
|
||||
if (!mServiceInstallationProgress)
|
||||
{
|
||||
Log.d(TAG, "Request new service installation");
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV Manager via Google Play");
|
||||
|
||||
boolean result = InstallServiceQuiet(AppContext);
|
||||
if (result)
|
||||
{
|
||||
mServiceInstallationProgress = true;
|
||||
int Status = LoaderCallbackInterface.RESTART_REQUIRED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
int Status = LoaderCallbackInterface.MARKET_ERROR;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
|
||||
public void wait_install()
|
||||
{
|
||||
Log.e(TAG, "Instalation was not started! Nothing to wait!");
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallCallbackInterface.NEW_INSTALLATION, InstallQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Wating current installation process");
|
||||
InstallCallbackInterface WaitQuery = new InstallCallbackInterface() {
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager";
|
||||
}
|
||||
public void install()
|
||||
{
|
||||
Log.e(TAG, "Nothing to install we just wait current installation");
|
||||
}
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "Wating for OpenCV canceled by user");
|
||||
mServiceInstallationProgress = false;
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
public void wait_install()
|
||||
{
|
||||
InstallServiceQuiet(AppContext);
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallCallbackInterface.INSTALLATION_PROGRESS, WaitQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of OpenCV Manager page on Google Play Market.
|
||||
*/
|
||||
@ -122,6 +168,7 @@ class AsyncServiceHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
mServiceInstallationProgress = false;
|
||||
try
|
||||
{
|
||||
if (mEngineService.getEngineVersion() < MINIMUM_ENGINE_VERSION)
|
||||
@ -177,9 +224,12 @@ class AsyncServiceHelper
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
}
|
||||
public void wait_install() {
|
||||
Log.e(TAG, "Instalation was not started! Nothing to wait!");
|
||||
}
|
||||
};
|
||||
|
||||
mUserAppCallback.onPackageInstall(InstallQuery);
|
||||
mUserAppCallback.onPackageInstall(InstallCallbackInterface.NEW_INSTALLATION, InstallQuery);
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -218,13 +268,13 @@ class AsyncServiceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onServiceDisconnected(ComponentName className)
|
||||
{
|
||||
mEngineService = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private boolean loadLibrary(String AbsPath)
|
||||
{
|
||||
boolean result = true;
|
||||
|
@ -27,18 +27,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
||||
/** OpenCV Manager or library package installation is in progress. Restart the application. **/
|
||||
case LoaderCallbackInterface.RESTART_REQUIRED:
|
||||
{
|
||||
Log.d(TAG, "OpenCV downloading. App restart is needed!");
|
||||
AlertDialog RestartMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
RestartMessage.setTitle("App restart is required");
|
||||
RestartMessage.setMessage("Application will be closed now. Start it when installation will be finished!");
|
||||
RestartMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
RestartMessage.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAppContext.finish();
|
||||
}
|
||||
});
|
||||
|
||||
RestartMessage.show();
|
||||
Log.d(TAG, "OpenCV downloading. App restart is needed!");
|
||||
} break;
|
||||
/** OpenCV loader can not start Google Play Market. **/
|
||||
case LoaderCallbackInterface.MARKET_ERROR:
|
||||
@ -96,29 +85,54 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPackageInstall(final InstallCallbackInterface callback)
|
||||
public void onPackageInstall(final int operation, final InstallCallbackInterface callback)
|
||||
{
|
||||
AlertDialog InstallMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
InstallMessage.setTitle("Package not found");
|
||||
InstallMessage.setMessage(callback.getPackageName() + " package was not found! Try to install it?");
|
||||
InstallMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener()
|
||||
switch (operation)
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
case InstallCallbackInterface.NEW_INSTALLATION:
|
||||
{
|
||||
callback.install();
|
||||
}
|
||||
});
|
||||
AlertDialog InstallMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
InstallMessage.setTitle("Package not found");
|
||||
InstallMessage.setMessage(callback.getPackageName() + " package was not found! Try to install it?");
|
||||
InstallMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.install();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new OnClickListener() {
|
||||
InstallMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.show();
|
||||
} break;
|
||||
case InstallCallbackInterface.INSTALLATION_PROGRESS:
|
||||
{
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog WaitMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
WaitMessage.setTitle("OpenCV is not ready");
|
||||
WaitMessage.setMessage("Installation is in progeress. Wait or exit?");
|
||||
WaitMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
WaitMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Wait", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
callback.wait_install();
|
||||
}
|
||||
});
|
||||
WaitMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.show();
|
||||
WaitMessage.show();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
protected Activity mAppContext;
|
||||
|
@ -5,6 +5,15 @@ package org.opencv.android;
|
||||
*/
|
||||
public interface InstallCallbackInterface
|
||||
{
|
||||
/**
|
||||
* New package installation is required.
|
||||
*/
|
||||
static final int NEW_INSTALLATION = 0;
|
||||
/**
|
||||
* Current package installation is in progress.
|
||||
*/
|
||||
static final int INSTALLATION_PROGRESS = 1;
|
||||
|
||||
/**
|
||||
* Target package name.
|
||||
* @return Return target package name.
|
||||
@ -18,4 +27,8 @@ public interface InstallCallbackInterface
|
||||
* Installation is canceled.
|
||||
*/
|
||||
public void cancel();
|
||||
/**
|
||||
* Wait for package installation.
|
||||
*/
|
||||
public void wait_install();
|
||||
};
|
||||
|
@ -40,5 +40,5 @@ public interface LoaderCallbackInterface
|
||||
* Callback method, called in case the package installation is needed.
|
||||
* @param callback answer object with approve and cancel methods and the package description.
|
||||
*/
|
||||
public void onPackageInstall(InstallCallbackInterface callback);
|
||||
public void onPackageInstall(final int operation, InstallCallbackInterface callback);
|
||||
};
|
||||
|
7
modules/java/generator/src/java/android+android+sync.py
Normal file
7
modules/java/generator/src/java/android+android+sync.py
Normal file
@ -0,0 +1,7 @@
|
||||
#!/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…
Reference in New Issue
Block a user