openUrl function for all platform but on windows RT empty function

This commit is contained in:
Sergey 2014-09-09 12:07:33 +04:00
parent ebfdd956c3
commit 2255cf91ba
16 changed files with 121 additions and 0 deletions

View File

@ -133,6 +133,15 @@ public:
* @lua NA * @lua NA
*/ */
virtual Platform getTargetPlatform() = 0; virtual Platform getTargetPlatform() = 0;
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
* @js NA
* @lua NA
*/
virtual bool openURL(const std::string &url) = 0;
}; };
// end of platform group // end of platform group

View File

@ -176,6 +176,11 @@ Application::Platform Application::getTargetPlatform()
return Platform::OS_ANDROID; return Platform::OS_ANDROID;
} }
bool Application::openURL(const std::string &url)
{
return openURLJNI(url.c_str());
}
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) { void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
} }

View File

@ -83,6 +83,13 @@ public:
@brief Get target platform @brief Get target platform
*/ */
virtual Platform getTargetPlatform(); virtual Platform getTargetPlatform();
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**
@brief This function will be called when the application screen size is changed. @brief This function will be called when the application screen size is changed.

View File

@ -32,9 +32,11 @@ import java.lang.Runnable;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager.OnActivityResultListener; import android.preference.PreferenceManager.OnActivityResultListener;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -170,6 +172,18 @@ public class Cocos2dxHelper {
public static void setKeepScreenOn(boolean value) { public static void setKeepScreenOn(boolean value) {
((Cocos2dxActivity)sActivity).setKeepScreenOn(value); ((Cocos2dxActivity)sActivity).setKeepScreenOn(value);
} }
public static boolean openURL(String url) {
boolean ret = false;
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
sActivity.startActivity(i);
ret = true;
} catch (Exception e) {
}
return ret;
}
public static void preloadBackgroundMusic(final String pPath) { public static void preloadBackgroundMusic(final String pPath) {
Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath); Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath);

View File

@ -219,6 +219,20 @@ void setKeepScreenOnJni(bool value) {
} }
} }
extern bool openURLJNI(const char* url) {
JniMethodInfo t;
bool ret = false;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "openURL", "(Ljava/lang/String;)Z")) {
jstring stringArg = t.env->NewStringUTF(url);
ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
return ret;
}
// functions for UserDefault // functions for UserDefault
bool getBoolForKeyJNI(const char* key, bool defaultValue) bool getBoolForKeyJNI(const char* key, bool defaultValue)
{ {

View File

@ -40,6 +40,7 @@ extern void enableAccelerometerJni();
extern void disableAccelerometerJni(); extern void disableAccelerometerJni();
extern void setAccelerometerIntervalJni(float interval); extern void setAccelerometerIntervalJni(float interval);
extern void setKeepScreenOnJni(bool value); extern void setKeepScreenOnJni(bool value);
extern bool openURLJNI(const char* url);
// functions for UserDefault // functions for UserDefault
extern bool getBoolForKeyJNI(const char* key, bool defaultValue); extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
extern int getIntegerForKeyJNI(const char* key, int defaultValue); extern int getIntegerForKeyJNI(const char* key, int defaultValue);

View File

@ -85,6 +85,13 @@ public:
@brief Get target platform @brief Get target platform
*/ */
virtual Platform getTargetPlatform(); virtual Platform getTargetPlatform();
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**
@brief This function will be called when the application screen size is changed. @brief This function will be called when the application screen size is changed.

View File

@ -167,6 +167,13 @@ Application::Platform Application::getTargetPlatform()
} }
} }
bool Application::openURL(const std::string &url)
{
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
NSURL* nsUrl = [NSURL URLWithString:msg];
return [[UIApplication sharedApplication] openURL:nsUrl];
}
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) { void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
} }

View File

@ -136,6 +136,12 @@ Application::Platform Application::getTargetPlatform()
return Platform::OS_LINUX; return Platform::OS_LINUX;
} }
bool Application::openURL(const std::string &url)
{
std::string op = std::string("open ").append(url);
return system(op.c_str())!=-1;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// static member function // static member function
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View File

@ -77,6 +77,13 @@ public:
@return Current language iso 639-1 code @return Current language iso 639-1 code
*/ */
virtual const char * getCurrentLanguageCode(); virtual const char * getCurrentLanguageCode();
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**

View File

@ -90,6 +90,13 @@ public:
@brief Get target platform @brief Get target platform
*/ */
virtual Platform getTargetPlatform(); virtual Platform getTargetPlatform();
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**
* Sets the Resource root path. * Sets the Resource root path.

View File

@ -213,6 +213,13 @@ LanguageType Application::getCurrentLanguage()
return ret; return ret;
} }
bool Application::openURL(const std::string &url)
{
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
NSURL* nsUrl = [NSURL URLWithString:msg];
return [[NSWorkspace sharedWorkspace] openURL:nsUrl];
}
void Application::setResourceRootPath(const std::string& rootResDir) void Application::setResourceRootPath(const std::string& rootResDir)
{ {
_resourceRootPath = rootResDir; _resourceRootPath = rootResDir;

View File

@ -30,6 +30,7 @@ THE SOFTWARE.
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include <algorithm> #include <algorithm>
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"
#include <shellapi.h>
/** /**
@brief This function change the PVRFrame show/hide setting in register. @brief This function change the PVRFrame show/hide setting in register.
@param bEnable If true show the PVRFrame window, otherwise hide. @param bEnable If true show the PVRFrame window, otherwise hide.
@ -206,6 +207,15 @@ Application::Platform Application::getTargetPlatform()
return Platform::OS_WINDOWS; return Platform::OS_WINDOWS;
} }
bool Application::openURL(const std::string &url)
{
WCHAR *temp = new WCHAR[url.size() + 1];
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.size() + 1, temp, url.size() + 1);
HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL);
delete[] temp;
return (int)r>32;
}
void Application::setResourceRootPath(const std::string& rootResDir) void Application::setResourceRootPath(const std::string& rootResDir)
{ {
_resourceRootPath = rootResDir; _resourceRootPath = rootResDir;

View File

@ -74,6 +74,13 @@ public:
@brief Get target platform @brief Get target platform
*/ */
virtual Platform getTargetPlatform(); virtual Platform getTargetPlatform();
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**
* Sets the Resource root path. * Sets the Resource root path.

View File

@ -177,6 +177,12 @@ Application::Platform Application::getTargetPlatform()
return Platform::OS_WP8; return Platform::OS_WP8;
} }
bool Application::openURL(const std::string &url)
{
//TODO release this method
return false;
}
void Application::setResourceRootPath(const std::string& rootResDir) void Application::setResourceRootPath(const std::string& rootResDir)
{ {
m_resourceRootPath = rootResDir; m_resourceRootPath = rootResDir;

View File

@ -62,6 +62,13 @@ public:
@brief Get target platform @brief Get target platform
*/ */
virtual Platform getTargetPlatform() override; virtual Platform getTargetPlatform() override;
/**
@brief Open url in default browser
@param String with url to open.
@return true if the resource located by the URL was successfully opened; otherwise false.
*/
virtual bool openURL(const std::string &url);
/** /**
* Sets the Resource root path. * Sets the Resource root path.