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
*/
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

View File

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

View File

@ -84,6 +84,13 @@ public:
*/
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.
@param new width

View File

@ -32,9 +32,11 @@ import java.lang.Runnable;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager.OnActivityResultListener;
import android.util.DisplayMetrics;
@ -171,6 +173,18 @@ public class Cocos2dxHelper {
((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) {
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
bool getBoolForKeyJNI(const char* key, bool defaultValue)
{

View File

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

View File

@ -86,6 +86,13 @@ public:
*/
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.
@param new width

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) {
}

View File

@ -136,6 +136,12 @@ Application::Platform Application::getTargetPlatform()
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
//////////////////////////////////////////////////////////////////////////

View File

@ -78,6 +78,13 @@ public:
*/
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);
/**
* Sets the Resource root path.

View File

@ -91,6 +91,13 @@ public:
*/
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.
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.

View File

@ -213,6 +213,13 @@ LanguageType Application::getCurrentLanguage()
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)
{
_resourceRootPath = rootResDir;

View File

@ -30,6 +30,7 @@ THE SOFTWARE.
#include "base/CCDirector.h"
#include <algorithm>
#include "platform/CCFileUtils.h"
#include <shellapi.h>
/**
@brief This function change the PVRFrame show/hide setting in register.
@param bEnable If true show the PVRFrame window, otherwise hide.
@ -206,6 +207,15 @@ Application::Platform Application::getTargetPlatform()
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)
{
_resourceRootPath = rootResDir;

View File

@ -75,6 +75,13 @@ public:
*/
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.
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.

View File

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

View File

@ -63,6 +63,13 @@ public:
*/
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.
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPaths() instead.