Commit 11839e2c authored by Alexander Smorkalov's avatar Alexander Smorkalov

Wating for OpenCV Manager installation added.

parent 601b87e3
...@@ -33,8 +33,7 @@ class AsyncServiceHelper ...@@ -33,8 +33,7 @@ class AsyncServiceHelper
} }
} }
protected AsyncServiceHelper(String Version, Context AppContext, protected AsyncServiceHelper(String Version, Context AppContext, LoaderCallbackInterface Callback)
LoaderCallbackInterface Callback)
{ {
mOpenCVersion = Version; mOpenCVersion = Version;
mUserAppCallback = Callback; mUserAppCallback = Callback;
...@@ -48,62 +47,109 @@ class AsyncServiceHelper ...@@ -48,62 +47,109 @@ class AsyncServiceHelper
protected String mOpenCVersion; protected String mOpenCVersion;
protected Context mAppContext; protected Context mAppContext;
protected int mStatus = LoaderCallbackInterface.SUCCESS; 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() { boolean result = true;
private Context mAppContext = AppContext; try
private LoaderCallbackInterface mUserAppCallback = Callback; {
public String getPackageName() Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
{ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return "OpenCV Manager"; context.startActivity(intent);
} }
public void install() { catch(Exception e)
Log.d(TAG, "Trying to install OpenCV Manager via Google Play"); {
result = false;
}
boolean result = true; return result;
try }
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()
{ {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL)); return "OpenCV Manager";
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mAppContext.startActivity(intent);
} }
catch(Exception e) public void install() {
{ Log.d(TAG, "Trying to install OpenCV Manager via Google Play");
result = false;
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);
}
} }
if (result) public void cancel()
{ {
int Status = LoaderCallbackInterface.RESTART_REQUIRED; Log.d(TAG, "OpenCV library installation was canceled");
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
Log.d(TAG, "Init finished with status " + Status); Log.d(TAG, "Init finished with status " + Status);
Log.d(TAG, "Calling using callback"); Log.d(TAG, "Calling using callback");
mUserAppCallback.onManagerConnected(Status); mUserAppCallback.onManagerConnected(Status);
} }
else
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.d(TAG, "OpenCV package was not installed!"); Log.e(TAG, "Nothing to install we just wait current installation");
int Status = LoaderCallbackInterface.MARKET_ERROR; }
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, "Init finished with status " + Status);
Log.d(TAG, "Unbind from service");
Log.d(TAG, "Calling using callback"); Log.d(TAG, "Calling using callback");
mUserAppCallback.onManagerConnected(Status); mUserAppCallback.onManagerConnected(Status);
} }
} public void wait_install()
{
public void cancel() InstallServiceQuiet(AppContext);
{ }
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); Callback.onPackageInstall(InstallCallbackInterface.INSTALLATION_PROGRESS, WaitQuery);
}
} }
/** /**
* URL of OpenCV Manager page on Google Play Market. * URL of OpenCV Manager page on Google Play Market.
*/ */
...@@ -122,6 +168,7 @@ class AsyncServiceHelper ...@@ -122,6 +168,7 @@ class AsyncServiceHelper
} }
else else
{ {
mServiceInstallationProgress = false;
try try
{ {
if (mEngineService.getEngineVersion() < MINIMUM_ENGINE_VERSION) if (mEngineService.getEngineVersion() < MINIMUM_ENGINE_VERSION)
...@@ -177,9 +224,12 @@ class AsyncServiceHelper ...@@ -177,9 +224,12 @@ class AsyncServiceHelper
Log.d(TAG, "Calling using callback"); Log.d(TAG, "Calling using callback");
mUserAppCallback.onManagerConnected(mStatus); 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; return;
} }
else else
...@@ -218,13 +268,13 @@ class AsyncServiceHelper ...@@ -218,13 +268,13 @@ class AsyncServiceHelper
} }
} }
} }
public void onServiceDisconnected(ComponentName className) public void onServiceDisconnected(ComponentName className)
{ {
mEngineService = null; mEngineService = null;
} }
}; };
private boolean loadLibrary(String AbsPath) private boolean loadLibrary(String AbsPath)
{ {
boolean result = true; boolean result = true;
......
...@@ -27,18 +27,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface { ...@@ -27,18 +27,7 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
/** OpenCV Manager or library package installation is in progress. Restart the application. **/ /** OpenCV Manager or library package installation is in progress. Restart the application. **/
case LoaderCallbackInterface.RESTART_REQUIRED: case LoaderCallbackInterface.RESTART_REQUIRED:
{ {
Log.d(TAG, "OpenCV downloading. App restart is needed!"); 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();
} break; } break;
/** OpenCV loader can not start Google Play Market. **/ /** OpenCV loader can not start Google Play Market. **/
case LoaderCallbackInterface.MARKET_ERROR: case LoaderCallbackInterface.MARKET_ERROR:
...@@ -96,29 +85,54 @@ public abstract class BaseLoaderCallback implements LoaderCallbackInterface { ...@@ -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(); switch (operation)
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) 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)
{
callback.cancel();
}
});
public void onClick(DialogInterface dialog, int which) 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; protected Activity mAppContext;
......
...@@ -5,6 +5,15 @@ package org.opencv.android; ...@@ -5,6 +5,15 @@ package org.opencv.android;
*/ */
public interface InstallCallbackInterface 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. * Target package name.
* @return Return target package name. * @return Return target package name.
...@@ -18,4 +27,8 @@ public interface InstallCallbackInterface ...@@ -18,4 +27,8 @@ public interface InstallCallbackInterface
* Installation is canceled. * Installation is canceled.
*/ */
public void cancel(); public void cancel();
/**
* Wait for package installation.
*/
public void wait_install();
}; };
...@@ -40,5 +40,5 @@ public interface LoaderCallbackInterface ...@@ -40,5 +40,5 @@ public interface LoaderCallbackInterface
* Callback method, called in case the package installation is needed. * Callback method, called in case the package installation is needed.
* @param callback answer object with approve and cancel methods and the package description. * @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);
}; };
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment