Example #1
0
void
Accelerometer::Run(const String& command) {
	if (!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() == 1) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
		}
		if(method == L"com.cordova.Accelerometer.watchAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			StartSensor();
		}
		if(method == L"com.cordova.Accelerometer.clearWatch" && IsStarted()) {
			StopSensor();
		}
		if(method == L"com.cordova.Accelerometer.getCurrentAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			GetLastAcceleration();
		}
		AppLogDebug("Acceleration command %S completed", command.GetPointer());
	} else {
		AppLogDebug("Can't run empty command");
	}
}
Example #2
0
void
UserProfileForm::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool rs)
{

	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	if(pHttpResponse == null)
		return;
	HttpHeader* pHttpHeader = pHttpResponse->GetHeader();
	if(pHttpHeader != null)
	{
		String* tempHeaderString = pHttpHeader->GetRawHeaderN();
		AppLog("HeaderString=%ls\n",tempHeaderString->GetPointer());
	}

	AppLog("OnTransactionHeaderCompleted\n");
}
Example #3
0
void
UserProfileForm::SendRequestGet(String requestUrl)
{
	result r = E_SUCCESS;
	HttpRequest* pRequest = null;
	String hostAddr(L"https://graph.facebook.com");

	if(__pSession == null)
	{
		__pSession = new HttpSession();
		r = __pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
		if (IsFailed(r))
		{
			AppLog("Fail to HttpSession::Construct. [%s]", GetErrorMessage(r));
			return;
		}
		__pSession->SetAutoRedirectionEnabled(true);
	}


	__pTransaction = __pSession->OpenTransactionN();
	if (__pTransaction)
	{
		result r = __pTransaction->AddHttpTransactionListener(*this);

			pRequest = __pTransaction->GetRequest();
			if (pRequest)
			{
				pRequest->SetUri(requestUrl);
				pRequest->SetMethod(NET_HTTP_METHOD_GET);
				r = __pTransaction->Submit();
				AppLog("RequestUrl is =%ls",requestUrl.GetPointer());
				if(IsFailed(r))
				{
					AppLog("Fail to HttpRequest::Submit. [%s]", GetErrorMessage(r));
				}
			}
			else
			{
				delete __pTransaction;
				__pTransaction = null;
			}
	}
}
Example #4
0
BadaFileStream *BadaFileStream::makeFromPath(const String &path, bool writeMode) {
	File *ioFile = new File();

	String filePath = path;
	if (writeMode && (path[0] != '.' && path[0] != '/')) {
		filePath.Insert(PATH_HOME_X, 0);
	}

	AppLog("Open file %S", filePath.GetPointer());

	result r = ioFile->Construct(filePath, writeMode ? L"w" : L"r", writeMode);
	if (r == E_SUCCESS) {
		return new BadaFileStream(ioFile, writeMode);
	}

	AppLog("Failed to open file");
	delete ioFile;
	return 0;
}
Example #5
0
result
UserProfileForm::OnInitializing(void)
{
	BaseForm::OnInitializing();

	AppResource* pAppResource = Application::GetInstance()->GetAppResource();
	__pLeftItemBitmap = pAppResource->GetBitmapN(L"facebook_icon1.png");

	ButtonItem  buttonLeftItem;
	buttonLeftItem.Construct(BUTTON_ITEM_STYLE_ICON,NULL);
	buttonLeftItem.SetIcon(BUTTON_ITEM_STATUS_NORMAL, __pLeftItemBitmap);

	Header* pHeader = GetHeader();
	pHeader->SetStyle(HEADER_STYLE_TITLE);
	pHeader->SetButton(BUTTON_POSITION_LEFT, buttonLeftItem);
	pHeader->SetTitleText(L"Your Profile Page");


	result r = E_SUCCESS;

	//Read Access Token

	Registry reg;
	r = reg.Construct(L"/Home/FacebookReg.ini", false );
	String token;
	String section = L"Facebook";
	String entry = L"AccessToken";
	r = reg.GetValue(section, entry , token);
	if(r == E_SUCCESS)
		AppLog("token is %ls",token.GetPointer());
	else
		AppLog("Reading failed: %s", GetErrorMessage(r));
	__accessToken =token;

	String profileurl;
	profileurl.Append(L"https://graph.facebook.com/me?");
	profileurl.Append(L"access_token=");
	profileurl.Append(__accessToken);
	SendRequestGet(profileurl);

	return r;
}
Example #6
0
result
Device::SetDeviceInfo() {
	result r = E_SUCCESS;
	String platformVersion;
	String apiVersion;
	String imei;
	int screen_height = 0;
	int screen_width = 0;

	/*screen*/
    r = SystemInfo::GetValue("ScreenWidth", screen_width);
    TryCatch(r == E_SUCCESS, , "SystemInfo: To get a value is failed");

    r = SystemInfo::GetValue("ScreenHeight", screen_height);
    TryCatch(r == E_SUCCESS, , "SystemInfo: To get a value is failed");

    r = SystemInfo::GetValue("PlatformVersion", platformVersion);
    TryCatch(r == E_SUCCESS, , "SystemInfo: To get a value is failed");

    r = SystemInfo::GetValue("APIVersion", apiVersion);
    TryCatch(r == E_SUCCESS, , "SystemInfo: To get a value is failed");

    r = SystemInfo::GetValue("IMEI", imei);
    TryCatch(r == E_SUCCESS, , "SystemInfo: To get a value is failed");

    if(r == E_SUCCESS) {
    	String res;
    	res.Format(1024, L"window.device={platform:'bada',version:'%S',name:'n/a',cordova:'2.4.0',uuid:'%S'}", platformVersion.GetPointer(), imei.GetPointer());
    	//AppLogDebug("%S", res.GetPointer());
    	pWeb->EvaluateJavascriptN(res);
    }
    return r;

CATCH:
	AppLog("Error = %s\n", GetErrorMessage(r));
    return r;
}
void BuyEngine::OnAppControlCompleteResponseReceived(
    const AppId& appId,
    const String& operationId,
    AppCtrlResult appControlResult,
    const Collection::IMap* pExtraData )
{
    AppLog("%s: %d", __FUNCTION__, appControlResult);

    String method;
    // TODO logthis removethis
    /*
    IList * keys = pExtraData->GetKeysN();
    IList * vlaues = pExtraData->GetValuesN();
    if ( !keys || !vlaues ) {
        AppLog("keys %p", keys);
        AppLog("vlaues %p", vlaues);
    }
    else
    {
        for( int i = 0; i < keys->GetCount(); ++i )
        {
            const String * key = dynamic_cast<String*>(keys->GetAt(i));
            const String * value = dynamic_cast<String*>(vlaues->GetAt(i));
            if ( key && value ) {
                AppLog("key: %ls value: %ls", key->GetPointer(), value->GetPointer());
            }
            else {
                AppLog("key %p", key);
                AppLog("value %p", value);
            }
        }
    }
    */
    result res = BuyHashMapUtils::GetStringValue(pExtraData, BUY_APPCTRL_KEY_METHOD, method);

    if (res == E_SUCCESS) {
        int statusTemp;
        BuyHashMapUtils::GetIntegerValue(pExtraData, BUY_APPCTRL_KEY_RESULT_CODE, statusTemp);
        BuyListener::StatusCode status = BuyListener::Unknown;

        if ( res == E_SUCCESS ) {
            switch(statusTemp) {
            case BuyListener::Succeed:
            case BuyListener::Cancel:
            case BuyListener::NetworkError:
            case BuyListener::ProcessError:
            case BuyListener::ServiceUnavailable:
            case BuyListener::ItemGroupIdNotFound:
            case BuyListener::PaymentIdNotFound:
            case BuyListener::ItemIdNotFound:
                status = (BuyListener::StatusCode)statusTemp;
                break;
            }
        }

        int transId;
        res = BuyHashMapUtils::GetIntegerValue(pExtraData, BUY_APPCTRL_KEY_TRANSACTION_ID, transId);

        if (IsFailed(res)) {
            transId =  -1;
        }

        if (method == BUY_METHOD_PURCHASE_FINISHED) {
            BuyPurchasedItemInformation info;

            res = PurchasedItemInformation::FromIMap(*pExtraData, &info);
            if (IsFailed(res)) {
                status = BuyListener::ProcessError;
            }

            __pListener->OnPurchaseItemFinished(transId, status, info);
        } else if (method == BUY_METHOD_PURCHASE_INITIALIZED) {
            BuyPurchaseTicket ticket;
            res = PurchaseTicket::FromIMap(*pExtraData, &ticket);
            String str = L"ItemID: " + ticket.GetItemId() + "\n"
                         + "Purchase ID: " + ticket.GetPurchaseId() + "\n"
                         + "VerifyURL: " + ticket.GetVerifyUrl() + "\n"
                         + "Param1: " + ticket.GetParam1() + "\n" + "Param2: "
                         + ticket.GetParam2() + "\n" + "Param3: "
                         + ticket.GetParam3();
            AppLogDebugTag(TAG, "%s: %s", __FUNCTION__, str.GetPointer());
            if (IsFailed(res)) {
                status = BuyListener::ProcessError;
            }

            if (status == BuyListener::Succeed) {
                // Only if this call develuscceeded we will get purchaseFinished
                // make new request to handle purchaseFinished
                BuyAppControlRequest req;
                result res = req.Construct(BUY_APPCTRL_OP_PURCHASE, __configInfo);
                if (res == E_SUCCESS) {
                    res = req.Add(BUY_APPCTRL_KEY_TRANSACTION_ID, transId);
                    res = res | req.Add(BUY_APPCTRL_KEY_PURCHASE_RESUME, 1);

                    if (res == E_SUCCESS) {
                        res = req.Send(this);
                    }
                }
            }

            AppLog(GetErrorMessage(res));
            __pListener->OnPurchaseItemInitialized(transId, status, ticket);

            if (IsFailed(res)) {
                // Client does not have new request id so we won't receive response
                __pListener->OnPurchaseItemFinished(transId, BuyListener::ProcessError, BuyPurchasedItemInformation());
            }
        } else if (method == BUY_METHOD_INFORMATION_LIST_RECEIVED) {
            BuyItemInformationList list;
            res = ItemInformationList::FromIMap(*pExtraData, &list);
            if (IsFailed(res)) {
                status = BuyListener::ItemGroupIdNotFound;
            }

            __pListener->OnItemInformationListReceived(transId, status, list);
        }
        else if (method == BUY_METHOD_PURCHASED_LIST_RECEIVED)
        {
            BuyPurchasedItemInformationList list;
            res = PurchasedItemInformationList::FromIMap(*pExtraData, &list);
            if (IsFailed(res)) {
                status = BuyListener::ProcessError;
            }

            __pListener->OnPurchasedItemInformationListReceived(transId, status, list);
        }
        else if ( method == IAP_METHOD_COUNTRY_LIST_RECEIVED)
        {
            HashMap * pCountryMap = new HashMap();
            pCountryMap->Construct();

            int startNumber;
            int endNumber;
            result r = BuyHashMapUtils::GetIntegerValue(pExtraData, BUY_APPCTRL_KEY_START_NUMBER, startNumber);
            TryLogReturn( !IsFailed(r), , GetErrorMessage(r) );
            r = BuyHashMapUtils::GetIntegerValue(pExtraData, BUY_APPCTRL_KEY_END_NUMBER, endNumber);
            TryLogReturn( !IsFailed(r), , GetErrorMessage(r) );

            for ( int i = startNumber; i <= endNumber; ++i )
            {
                String countryKey;
                countryKey.Append(i);
                const String * pCountryValue;
                countryKey.Append(L"_countryName");
                pCountryValue = dynamic_cast<const String*>(pExtraData->GetValue(countryKey));
                String mccKey;
                mccKey.Append(i);
                const String * pMccValue;
                mccKey.Append(L"_mcc");
                pMccValue = dynamic_cast<const String*>(pExtraData->GetValue(mccKey));

                if ( pCountryValue && pMccValue )
                {
                    pCountryMap->Add( new String(*pCountryValue), new String(*pMccValue) );
                }
                else
                {
                    AppLog("Error failed to get country(%p) or mcc(%p)", pCountryValue, pMccValue);
                }
            }
            __pListener->OnCountryListReceived(transId, status, pCountryMap);
        }