TITANIUM_FUNCTION(API, log)
	{
		const auto js_context = this_object.get_context();
		if (arguments.size() == 1) {
			ENSURE_STRING_AT_INDEX(message, 0);
			GetStaticObject(js_context).GetPrivate<API>()->log("info", message);
		} else if (arguments.size() == 2) {
			ENSURE_ARGUMENT_INDEX(1);
			ENSURE_STRING_AT_INDEX(level, 0);
			JOIN_ARGUMENT_STRINGS(message, 1);
			GetStaticObject(js_context).GetPrivate<API>()->log(level, message.str());
		}

		return js_context.CreateUndefined();
	}
	TITANIUM_FUNCTION(API, trace)
	{
		JOIN_ARGUMENT_STRINGS(message, 0);

		const auto js_context = this_object.get_context();
		GetStaticObject(js_context).GetPrivate<API>()->trace(message.str());
		return js_context.CreateUndefined();
	}
	TITANIUM_FUNCTION(API, trace)
	{
		ENSURE_STRING_AT_INDEX(message, 0);
		
		const auto js_context = this_object.get_context();
		GetStaticObject(js_context).GetPrivate<API>()->trace(message);
		return js_context.CreateUndefined();
	}
TITANIUM_FUNCTION(Properties, hasProperty)
{
    ENSURE_STRING_AT_INDEX(property, 0);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    return js_context.CreateBoolean(object_ptr->hasProperty(property));
}
TITANIUM_FUNCTION(Properties, _loadAppProperties)
{
    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    object_ptr->loadAppProperties();

    return get_context().CreateUndefined();
}
	TITANIUM_FUNCTION(TiModule, setUserAgent)
	{
		const auto js_context = this_object.get_context();
		const auto object_ptr = GetStaticObject(js_context).GetPrivate<TiModule>();
		
		object_ptr->js_set_userAgent(arguments.at(0));

		return get_context().CreateUndefined();
	}
	TITANIUM_FUNCTION(FilesystemModule, createTempFile)
	{
		const auto js_context = this_object.get_context();
		const auto filesystem_ptr = GetStaticObject(js_context).GetPrivate<FilesystemModule>();
		const auto object_ptr = filesystem_ptr->createTempFile(this_object.get_context());
		if (object_ptr != nullptr) {
			return object_ptr->get_object();
		}
		return this_object.get_context().CreateUndefined();
	}
TITANIUM_FUNCTION(Properties, getObject)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_OPTIONAL_OBJECT_AT_INDEX(defaultValue, 1);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    return object_ptr->getObject(property, defaultValue);
}
TITANIUM_FUNCTION(Properties, getInt)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_OPTIONAL_DOUBLE_AT_INDEX(defaultValue, 1, 0);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    return js_context.CreateNumber(object_ptr->getInt(property, defaultValue));
}
TITANIUM_FUNCTION(Properties, getBool)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_OPTIONAL_BOOL_AT_INDEX(defaultValue, 1, false);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    return js_context.CreateBoolean(object_ptr->getBool(property, defaultValue));
}
TITANIUM_FUNCTION(Properties, removeProperty)
{
    ENSURE_STRING_AT_INDEX(property, 0);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    object_ptr->removeProperty(property);
    return js_context.CreateUndefined();
}
TITANIUM_FUNCTION(Properties, getList)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_OPTIONAL_ARRAY_AT_INDEX(defaultValue, 1);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    const auto list = object_ptr->getList(property, static_cast<std::vector<JSValue>>(defaultValue));
    return js_context.CreateArray(list);
}
TITANIUM_FUNCTION(Properties, setList)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_ARRAY_AT_INDEX(array, 1);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    object_ptr->setList(property, array);
    return js_context.CreateUndefined();
}
TITANIUM_FUNCTION(Properties, setString)
{
    ENSURE_STRING_AT_INDEX(property, 0);
    ENSURE_STRING_AT_INDEX(value, 1);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    object_ptr->setString(property, value);
    return js_context.CreateUndefined();
}
Beispiel #15
0
void GetFlagValues(JNIEnv *env, jclass wFlagsClass)
{
    jboolean d3dEnabled = env->GetStaticBooleanField(wFlagsClass, d3dEnabledID);
    jboolean d3dSet = env->GetStaticBooleanField(wFlagsClass, d3dSetID);
    if (!d3dSet) {
        // Only check environment variable if user did not set Java
        // command-line parameter; values of sun.java2d.d3d override
        // any setting of J2D_D3D environment variable.
        char *d3dEnv = getenv("J2D_D3D");
        if (d3dEnv) {
            if (strcmp(d3dEnv, "false") == 0) {
                // printf("Java2D Direct3D usage disabled by J2D_D3D env\n");
                d3dEnabled = FALSE;
                d3dSet = TRUE;
                SetD3DEnabledFlag(env, d3dEnabled, d3dSet);
            } else if (strcmp(d3dEnv, "true") == 0) {
                // printf("Java2D Direct3D usage forced on by J2D_D3D env\n");
                d3dEnabled = TRUE;
                d3dSet = TRUE;
                SetD3DEnabledFlag(env, d3dEnabled, d3dSet);
            }
        }
    }
    useD3D = d3dEnabled;
    forceD3DUsage = d3dSet;
    g_offscreenSharing = GetStaticBoolean(env, wFlagsClass,
                                          "offscreenSharingEnabled");
    accelReset = GetStaticBoolean(env, wFlagsClass, "accelReset");
    checkRegistry = GetStaticBoolean(env, wFlagsClass, "checkRegistry");
    disableRegistry = GetStaticBoolean(env, wFlagsClass, "disableRegistry");
    jstring javaVersionString = (jstring)GetStaticObject(env, wFlagsClass,
                                                         "javaVersion",
                                                         "Ljava/lang/String;");

    setHighDPIAware =
        (IS_WINVISTA && GetStaticBoolean(env, wFlagsClass, "setHighDPIAware"));

    J2dTraceLn(J2D_TRACE_INFO, "WindowsFlags (native):");
    J2dTraceLn1(J2D_TRACE_INFO, "  d3dEnabled = %s",
                (useD3D ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  d3dSet = %s",
                (forceD3DUsage ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  offscreenSharing = %s",
                (g_offscreenSharing ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  accelReset = %s",
                (accelReset ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  checkRegistry = %s",
                (checkRegistry ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  disableRegistry = %s",
                (disableRegistry ? "true" : "false"));
    J2dTraceLn1(J2D_TRACE_INFO, "  setHighDPIAware = %s",
                (setHighDPIAware ? "true" : "false"));
}
TITANIUM_FUNCTION(Properties, listProperties)
{
    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    const auto props = object_ptr->listProperties();
    std::vector<JSValue> converted;
    for (size_t i = 0; i < props.size(); i++) {
        converted.push_back(js_context.CreateString(props.at(i)));
    }
    return js_context.CreateArray(converted);
}
	TITANIUM_FUNCTION(Analytics, navEvent)
	{
		const auto js_context = this_object.get_context();
		const auto analytics = GetStaticObject(js_context).GetPrivate<Analytics>();

		// lazy loading
		const auto loaded = analytics->loadJS();
		if (loaded) {
			auto func = analytics->getTiObject().GetProperty("navEvent");
			return static_cast<JSObject>(func)(arguments, this_object);
		} else {
			TITANIUM_LOG_ERROR("Failed to execute Database.navEvent");
			return get_context().CreateNull();
		}
	}
TITANIUM_FUNCTION(Properties, getString)
{
    ENSURE_STRING_AT_INDEX(property, 0);

    boost::optional<std::string> defaultValue = nullptr;
    if (arguments.size() > 1) {
        const auto _1 = arguments.at(1);
        if (_1.IsString()) {
            defaultValue = static_cast<std::string>(_1);
        }
    }

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    const auto result = object_ptr->getString(property, defaultValue);
    if (result) {
        return js_context.CreateString(*result);
    }
    return js_context.CreateNull();
}
	TITANIUM_FUNCTION(FilesystemModule, getFile)
	{
		const auto js_context = this_object.get_context();

		const auto filesystem_ptr = GetStaticObject(js_context).GetPrivate<FilesystemModule>();
		std::string separator = filesystem_ptr->separator();

		// join paths with separator
		std::ostringstream oss;
		const auto size = arguments.size();
		for (size_t i = 0; i < size; i++) {
			auto segment = static_cast<std::string>(arguments.at(i));
			oss << segment;
			if (i + 1 < size && segment.find(separator) != (segment.size() - 1)) {
				oss << separator;
			}
		}
		const auto object_ptr = filesystem_ptr->getFile(js_context, oss.str());
		if (object_ptr != nullptr) {
			return object_ptr->get_object();
		}
		return this_object.get_context().CreateUndefined();
	}
	TITANIUM_FUNCTION(TiModule, getBuildDate)
	{
		const auto js_context = this_object.get_context();
		const auto object_ptr = GetStaticObject(js_context).GetPrivate<TiModule>();
		return object_ptr->js_get_buildDate();
	}
	TITANIUM_FUNCTION(FilesystemModule, getTempDirectory)
	{
		const auto js_context = this_object.get_context();
		const auto filesystem_ptr = GetStaticObject(js_context).GetPrivate<FilesystemModule>();
		return this_object.get_context().CreateString(filesystem_ptr->tempDirectory());
	}
	TITANIUM_FUNCTION(FilesystemModule, isExternalStoragePresent)
	{
		const auto js_context = this_object.get_context();
		const auto filesystem_ptr = GetStaticObject(js_context).GetPrivate<FilesystemModule>();
		return this_object.get_context().CreateBoolean(filesystem_ptr->isExternalStoragePresent());
	}
	TITANIUM_FUNCTION(Gesture, getLandscape)
	{
		const auto js_context = this_object.get_context();
		const auto gesture_ptr = GetStaticObject(js_context).GetPrivate<Gesture>();
		return gesture_ptr->js_get_landscape();
	}
	TITANIUM_FUNCTION(Gesture, isPortrait)
	{
		const auto js_context = this_object.get_context();
		const auto gesture_ptr = GetStaticObject(js_context).GetPrivate<Gesture>();
		return gesture_ptr->js_get_portrait();
	}
	TITANIUM_FUNCTION(Gesture, isFaceUp)
	{
		const auto js_context = this_object.get_context();
		const auto gesture_ptr = GetStaticObject(js_context).GetPrivate<Gesture>();
		return this_object.get_context().CreateBoolean(gesture_ptr->get_orientation() == UI::ORIENTATION::FACE_UP);
	}
	TITANIUM_FUNCTION(Gesture, getOrientation)
	{
		const auto js_context = this_object.get_context();
		const auto gesture_ptr = GetStaticObject(js_context).GetPrivate<Gesture>();
		return this_object.get_context().CreateNumber(UI::Constants::to_underlying_type(gesture_ptr->get_orientation()));
	}
	TITANIUM_FUNCTION(Analytics, _start)
	{
		const auto analytics = GetStaticObject(this_object.get_context()).GetPrivate<Analytics>();
		return this_object.get_context().CreateBoolean(analytics->loadJS());
	}