MAHandle FacebookResponse::getImageData() const { MAHandle data = maCreatePlaceholder(); maCreateData(data, getDataSize()); maWriteData(data, getData(), 0, getDataSize()); MAHandle image = maCreatePlaceholder(); maCreateImageFromData(image, data, 0, getDataSize()); maDestroyPlaceholder(data); return image; }
/** * Inherited from HighLevelHttpConnection. * Called when the HTTP connection has finished * downloading data. * Calls onDownloadComplete. * @param data Handle to the data, will be * 0 on error, > 0 on success. * @param result Result code, RES_OK on success, * otherwise an HTTP error code. */ void HighLevelImageDownloader::dataDownloaded(MAHandle data, int result) { // The resulting image. MAHandle image = 0; // Do we have any data? if (data) { // Convert data to image. image = maCreatePlaceholder(); int res = maCreateImageFromData( image, data, 0, maGetDataSize(data)); // Do we have an error? if (RES_OUT_OF_MEMORY == res) { // The image could not be created, set data handle to zero. image = 0; } // Deallocate the data object, we are done with it. maDestroyPlaceholder(data); } // Notify download complete. onDownloadComplete(image); }
/** * Used for Android only. * Stores the registration ID in a store for later use. * @param token The registration_ID. */ void MainScreen::storeRegistrationID(MAUtil::String* token) { mToken = token; // Store doesn't exist. MAHandle myStore = maOpenStore("MyPushStore", MAS_CREATE_IF_NECESSARY); // Create store and write Registration ID MAHandle myData = maCreatePlaceholder(); if(maCreateData(myData, token->length()) == RES_OK) { maWriteData(myData, token->c_str(), 0, token->length()); // Write the data resource to the store. int result = maWriteStore(myStore, myData); if ( result < 0 ) { printf("Cannot write to store the token!!"); } maCloseStore(myStore, 0); } // Finally, send it over TCP to the server. // mConnection->sendData(token); }
/** * Creates an image with a gray gradient. */ Image* ScreenImageSwiper::createBackgroundGradient() { // Create gradient bitmap. int *gradientBitmap = new int[16 * 16]; for (int i = 0; i < 16; ++i) { for (int j = 0; j<16; ++j) { int color = 0xFF - (i * 0xFF / 16); gradientBitmap[i*16 + j] = color | (color << 8) | (color << 16); } } // Create image with gradient. MAHandle imageHandle = maCreatePlaceholder(); maCreateImageRaw(imageHandle, gradientBitmap, EXTENT(16, 16), 0); delete gradientBitmap; // Create image widget. Image* imageWidget = new Image(); imageWidget->setImage(imageHandle); imageWidget->setPosition(0, 0); imageWidget->setSize( MAW_CONSTANT_FILL_AVAILABLE_SPACE, MAW_CONSTANT_FILL_AVAILABLE_SPACE); // Tell image to stretch. imageWidget->setProperty("scaleMode", "scaleXY"); return imageWidget; }
Controller::~Controller() { // remember the selected font scale and path char path[FILENAME_MAX + 1]; getcwd(path, FILENAME_MAX); int pathLength = strlen(path) + 1; int dataLength = (sizeof(int) * 3) + pathLength; MAHandle data = maCreatePlaceholder(); if (maCreateData(data, dataLength) == RES_OK) { int storeVersion = STORE_VERSION; int offset = 0; // write the version number maWriteData(data, &storeVersion, offset, sizeof(int)); offset += sizeof(int); // write the fontScale maWriteData(data, &_fontScale, offset, sizeof(int)); offset += sizeof(int); // write the current path maWriteData(data, &pathLength, offset, sizeof(int)); maWriteData(data, path, offset + sizeof(int), pathLength); MAHandle store = maOpenStore(PACKAGE, MAS_CREATE_IF_NECESSARY); maWriteStore(store, data); maCloseStore(store, 0); } maDestroyPlaceholder(data); delete _output; delete [] _programSrc; }
void ImageCache::httpFinished(MAUtil::HttpConnection* http, int result) { if (result == 200) { MAUtil::String *contentLengthStr = new MAUtil::String("-1"); int responseBytes = mHttp.getResponseHeader("content-length", contentLengthStr); mContentLength = 0; mDataOffset = 0; mData = maCreatePlaceholder(); if(responseBytes == CONNERR_NOHEADER) { } else { mContentLength = atoi(contentLengthStr->c_str()); } delete contentLengthStr; if (maCreateData(mData, mContentLength) == RES_OK){ } if(mContentLength >= 1024 || mContentLength == 0) { mHttp.recv(mBuffer, 1024); } else { mBuffer[mContentLength] = 0; mHttp.recv(mBuffer, mContentLength); } } else { finishedDownloading(); } }
/** * Implementation of standard API exposed to JavaScript * This function is used to detect different messages from JavaScript * and call the respective function in MoSync. * * @return true if stream was handled, false if not. */ bool ResourceMessageHandler::handleMessage(Wormhole::MessageStream& stream) { char buffer[512]; const char * action = stream.getNext(); if (0 == strcmp("loadImage", action)) { const char* imagePath = stream.getNext(); const char* imageID = stream.getNext(); // Load the Image resource. MAHandle imageHandle = loadImageResource(imagePath); if (imageHandle > 0) { sprintf(buffer, "mosync.resource.imageLoaded(\"%s\", %d)", imageID, imageHandle); mWebView->callJS(buffer); } else { // TODO: Better way to inform about the error? // Call JS function with error code? // mosync.resource.imageLoaded(<imageID>, -1) ?? char errorMessage[1024]; sprintf(errorMessage, "@@@ MoSync: ResourceMessageHandler could not load image: %s", imagePath); maWriteLog(errorMessage, strlen(errorMessage)); } } else if (0 == strcmp("loadRemoteImage", action)) { const char* imageURL = stream.getNext(); const char* imageID = stream.getNext(); MAHandle imageHandle = maCreatePlaceholder(); mImageDownloader->beginDownloading(imageURL,imageHandle); sprintf(buffer, "mosync.resource.imageDownloadStarted(\"%s\", %d)", imageID, imageHandle); mWebView->callJS(buffer); } else if (0 == strcmp("DestroyPlaceholder", action)) { MAHandle handle = stringToInteger(stream.getNext()); maDestroyPlaceholder(handle); } else if (0 == strcmp("sendRemoteLogMessage", action)) { const char* url = stream.getNext(); const char* message = stream.getNext(); sendRemoteLogMessage(message, url); } return true; }
/** * Create a colored image. * @param color The color of the image (a hex value). * @param width The width of the image. * @param height The height of the image. * @return Handle to the image. The image needs to be * deallocated with maDestoryObject. */ MAHandle ScreenColorList::createColorImage(int color, int width, int height) { MAHandle image = maCreatePlaceholder(); maCreateDrawableImage(image, width, height); MAHandle previousDrawTarget = maSetDrawTarget(image); maSetColor(color); maFillRect(0, 0, width, height); maSetDrawTarget(previousDrawTarget); return image; }
bool Controller::construct() { MAExtent screenSize = maGetScrSize(); _output = new AnsiWidget(this, EXTENT_X(screenSize), EXTENT_Y(screenSize)); _output->construct(); _initialFontSize = _output->getFontSize(); _runMode = init_state; opt_ide = IDE_NONE; opt_graphics = true; opt_pref_bpp = 0; opt_nosave = true; opt_interactive = true; opt_verbose = false; opt_quiet = true; opt_command[0] = 0; opt_usevmt = 0; os_graphics = 1; // restore the selected font scale and path MAHandle data = maCreatePlaceholder(); MAHandle store = maOpenStore(PACKAGE, 0); if (store != STERR_NONEXISTENT) { if (maReadStore(store, data) == RES_OK) { int offset = 0; int storeVersion; int pathLength; char path[FILENAME_MAX + 1]; maReadData(data, &storeVersion, offset, sizeof(int)); offset += sizeof(int); if (storeVersion == STORE_VERSION) { maReadData(data, &_fontScale, offset, sizeof(int)); offset += sizeof(int); if (_fontScale != 100) { int fontSize = (_initialFontSize * _fontScale / 100); _output->setFontSize(fontSize); } maReadData(data, &pathLength, offset, sizeof(int)); maReadData(data, &path, offset+ sizeof(int), pathLength); if (pathLength > 1) { chdir(path); } } } maCloseStore(store, 0); } maDestroyPlaceholder(data); return true; }
// save status to a store, so the loader can read it. // if this store is not saved, the loader will assume something went // catastrophically wrong with the test. static void exit_status_save(int status, void* dummy) { printf("exit_status_save\n"); // we don't check for errors here, because there can be no reasonable error handling at this stage. // better then, to let the runtime's panic system deal with it. MAHandle data = maCreatePlaceholder(); maCreateData(data, sizeof(int)); maWriteData(data, &status, 0, sizeof(int)); MAHandle store = maOpenStore("exit_status", MAS_CREATE_IF_NECESSARY); maWriteStore(store, data); maCloseStore(store, 0); }
/** * Constructor. * @param productID String that identifies the product. * This string must be used by the App Store / Google Play to identify * the product. * @param listener The listener that will receive purchase events. */ Purchase::Purchase(const MAUtil::String& productID, PurchaseListener* listener): mHandle(-1), mReceipt(NULL), mIsRestored(false) { this->addPurchaseListener(listener); mHandle = maCreatePlaceholder(); PurchaseManager::getInstance()->registerPurchase(this); maPurchaseCreate(mHandle, productID.c_str()); }
static MA_FILE* openReadWrite(const char *filename, int modeFlags) { MA_FILE *file; char sfilename[1024]; MAHandle store; MAHandle data=0; int size = BUFFER_SIZE; int realLength = 0; filterStoreName(sfilename, 1024, filename); store = maOpenStore(sfilename, MAS_CREATE_IF_NECESSARY); if(!store) return NULL; file = (MA_FILE*) malloc(sizeof(MA_FILE)); if(modeFlags&(MODE_READ|MODE_WRITE)) file->type = TYPE_READWRITE; else file->type = TYPE_WRITEONLY; file->modeFlags = modeFlags; if(modeFlags&(MODE_READ|MODE_APPEND)) { data = maCreatePlaceholder(); maReadStore(store, data); realLength = size = maGetDataSize(data); } file->buffer = (unsigned char*) malloc(size); if(!file->buffer) { free(file->buffer); free(file); return NULL; } file->bufferStart = 0; file->bufferSize = size; file->volEntry = (VolumeEntry*) malloc(sizeof(VolumeEntry)); file->filePtr = 0; file->volEntry->dataOffset = 0; file->volEntry->dataLength = realLength; file->resultFlags = 0; if(modeFlags&(MODE_READ|MODE_APPEND)) { maReadData(data, file->buffer, 0, size); maDestroyObject(data); if(modeFlags&MODE_APPEND) { file->filePtr = size; } } file->store = store; file->volEntry->type=VOL_TYPE_FILE; return file; }
/* * Load the images from resources according to the screen resolution. * @param screenWidth The width of the screen. */ void ScreenImageSwiper::loadImages(int screenWidth) { // Set the image indexes inside the resources according to the resolution. int firstImage = RES_FIRST_IMAGE_LARGE; int lastImage = RES_LAST_IMAGE_LARGE; if (screenWidth <= SMALL_SCREEN_RESOLUTION) { firstImage = RES_FIRST_IMAGE_SMALL; lastImage = RES_LAST_IMAGE_SMALL; } else if (screenWidth <= MEDIUM_SCREEN_RESOLUTION) { firstImage = RES_FIRST_IMAGE_MEDIUM; lastImage = RES_LAST_IMAGE_MEDIUM; } // Compute the number of images. mImagesSize = lastImage - firstImage - 1; // Create the image widgets. for (int i = 0; i < mImagesSize; i++) { // Byte index in the resource data. int pos = 0; // Create an image object. mImages[i] = new ScreenImage(); // Get the resource id of the current image. int resID = firstImage + i + 1; // Create a placeholder to store the current image. mImages[i]->setHandle(maCreatePlaceholder()); // Load the image name from resources. MAUtil::String name; // This reads the string into name and updates // the value of pos to the start of the image data. readStringFromResource(resID, pos, name); // Set the image name. mImages[i]->setName(name); // Create the image from ubin. Note that pos is // updated by the call to readStringFromResource // to point at the start of the image data. maCreateImageFromData( mImages[i]->getHandle(), resID, pos, maGetDataSize(resID) - mImages[i]->getName().length() - 1); } }
/** * TODO: This function also has the JNIEnv fix. */ static int nativeCreatePlaceholder( JNIEnv* env, jobject jthis ) { JNIEnv* prevJNIEnv = Base::gSyscall->getJNIEnvironment(); jobject prevJThis = Base::gSyscall->getJNIThis(); Base::gSyscall->setJNIEnvironment(env, jthis); int result = maCreatePlaceholder(); Base::gSyscall->setJNIEnvironment(prevJNIEnv, prevJThis); return result; }
void MoSyncCamController::snapshotRequested() { mCameraScreen->showSnapshotInProgress(); if ( mLastSnapshotDataHandle > 0 ) { maDestroyPlaceholder(mLastSnapshotDataHandle); mLastSnapshotDataHandle = 0; } mLastSnapshotDataHandle = maCreatePlaceholder(); mCameraScreen->takeSnapshot(mLastSnapshotDataHandle); }
//TestCase virtual void start() { printf("Testing stores.\n"); //open, cin MAHandle store = maOpenStore("test.store", MAS_CREATE_IF_NECESSARY); TI(store); //write TI(maWriteStore(store, CLIENT_DATA)); //close maCloseStore(store, 0); //open store = maOpenStore("test.store", 0); TI(store); //read MAHandle data = maCreatePlaceholder(); maReadStore(store, data); //compare char storeBuf[DATA_SIZE], clientBuf[DATA_SIZE]; maReadData(data, storeBuf, 0, DATA_SIZE); maReadData(CLIENT_DATA, clientBuf, 0, DATA_SIZE); if(memcmp(storeBuf, clientBuf, DATA_SIZE) != 0) { assert(name, false); suite->runNextCase(); return; } //close, delete maCloseStore(store, true); maDestroyObject(data); //open, should fail store = maOpenStore("test.store", 0); if(store >= 0) { maCloseStore(store, true); assert(name, false); suite->runNextCase(); return; } printf("Store test succeded!\n"); //succeed assert(name, true); suite->runNextCase(); }
void WidgetSkin::draw(int x, int y, int width, int height, eType type) { MAHandle cached = 0; // Calculate numTiles needed to be drawn, if they are many, we need to cache, otherwise draw directly... int numTiles = calculateNumTiles(width, height); if(!useCache || numTiles<100) { drawDirect(x, y, width, height, type); return; } CacheKey newKey = CacheKey(this, width, height, type); cached = getFromCache(newKey); // If we didn't find a cached widgetskin, let's generate one and save it in the cache. if(!cached) { // set malloc handler to null so that we can catch if we're out of heap and write directly to the screen then. #ifndef MOSYNC_NATIVE malloc_handler mh = set_malloc_handler(NULL); #endif int *data = new int[width*height]; if(!data) { drawDirect(x, y, width, height, type); return; } #ifndef MOSYNC_NATIVE set_malloc_handler(mh); #endif drawToData(data, 0, 0, width, height, type); CacheElement cacheElem; flushCacheUntilNewImageFits(width*height); cacheElem.image = maCreatePlaceholder(); if(maCreateImageRaw(cacheElem.image,data,EXTENT(width,height),1)!=RES_OK) { maPanic(1, "Could not create raw image"); } delete data; cacheElem.lastUsed = maGetMilliSecondCount(); cached = cacheElem.image; addToCache(newKey, cacheElem); } // Draw the cached widgetskin. Gfx_drawImage(cached, x, y); }
void HighLevelReaderThatReadsChunks::finishedDownloadingChunkedData() { // Allocate big handle and copy the chunks to it. // mContentLength holds the accumulated size of read data. // We create a new placeholder here, not using the pool. // TODO: Consider using PlaceholderPool also for this handle. MAHandle dataHandle = maCreatePlaceholder(); int errorCode = maCreateData(dataHandle, mContentLength); if (RES_OUT_OF_MEMORY == errorCode) { mConnection->downloadError(RES_OUT_OF_MEMORY); return; } // Copy chunks to the data object. int offset = 0; char* buf = new char[mDataChunkSize]; while (0 < mDataChunks.size()) { // Last chunk should only be partially written. int dataLeftToWrite = mContentLength - offset; // Set size to min(dataLeftToWrite, mDataChunkSize) int size = (dataLeftToWrite < mDataChunkSize ? dataLeftToWrite : mDataChunkSize); // Copy first remaining chunk. MAHandle chunk = mDataChunks[0]; maReadData(chunk, buf, 0, size); maWriteData(dataHandle, buf, offset, size); // Return chunk to pool. DeallocateHandle(chunk); // Remove chunk from list. mDataChunks.remove(0); // Increment offset. offset += mDataChunkSize; } delete[] buf; // Download is finished! Tell the connection about this. mConnection->downloadSuccess(dataHandle); }
void testDrawableImages() { const unsigned int colors[] = { 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff, }; const unsigned int NUMCOLORS = sizeof(colors)/sizeof(int); unsigned int colors2[NUMCOLORS]; MAHandle testImg = maCreatePlaceholder(); printf("testing resources\n"); int res = maCreateDrawableImage(testImg, NUMCOLORS, 1); assert("maCreateImageRaw", res == RES_OK); MAExtent e1 = maGetImageSize(testImg); assert("maGetImageSize", e1 == EXTENT(NUMCOLORS,1)); maSetDrawTarget(testImg); for(unsigned int i = 0; i < NUMCOLORS; i++) { maSetColor(colors[i]); maPlot(i, 0); } MARect rect = {0, 0, NUMCOLORS, 1}; maSetDrawTarget(0); maGetImageData(testImg, colors2, &rect, NUMCOLORS); assert( "testing drawable image res", (memcmp(colors, colors2, sizeof(colors)) == 0) ); }
void BundleDownloader::downloadBundle() { //Prepare a reciever for the download mResourceFile = maCreatePlaceholder(); //Start the bundle download if(mDownloader->isDownloading()) { mDownloader->cancelDownloading(); } int res = mDownloader->beginDownloading(mBundleAddress, mResourceFile); if(res > 0) { printf("Downloading Started with %d\n", res); } else { //showConErrorMessage(res); } }
void Font::setResource(MAHandle font) { //printf("Font is using resource: %d\n", font); if(font == 0) { mFontImage = 0; return; } initFontReader(font); int fontInfoSize = readInt(); int imageSize = readInt(); if(this->mCharset) { delete this->mCharset; } this->mCharset = new Charset; if(!parseBitmapFontGeneratorFile( font, 8+fontInfoSize, this->mCharset)) { maPanic(0, "Font::setResource(MAHandle font), could not parse font"); return; } closeFontReader(); this->mFontImage = maCreatePlaceholder(); int err; if((err=maCreateImageFromData( this->mFontImage, font, 8+fontInfoSize, imageSize))!=RES_OK) { if(err==RES_OUT_OF_MEMORY) { maPanic(0, "Font::setResource(MAHandle font), out of memory, " "image could not be loaded"); } if(err==RES_BAD_INPUT) { maPanic(0, "Font::setResource(MAHandle font), " "image could not be loaded due to bad input"); } } }
void CBHttpConnection::httpFinished(MAUtil::HttpConnection *conn, int result) { if ( result >= 0) { String contentLengthStr; theConnection.getResponseHeader("Content-Length", &contentLengthStr); int contentLength = 0; contentLength = atoi(contentLengthStr.c_str()); //printf("received content length: %s", contentLengthStr.c_str()); mBuffer[contentLength] = 0; if (this->isDownload) { this->downloadFileData = maCreatePlaceholder(); maCreateData(this->downloadFileData,(contentLength == NULL?CONNECTION_BUFFER_SIZE:contentLength)); theConnection.readToData(this->downloadFileData, 0, (contentLength == NULL?CONNECTION_BUFFER_SIZE:contentLength)); } else { theConnection.read(mBuffer, (contentLength == NULL?CONNECTION_BUFFER_SIZE:contentLength)); } } else { theConnection.close(); } }
void ImageCache::process(bool afterFin) { //Check to see if the cache can process this request at this time if(mIsBusy) return; //Check to see if there are any outstanding requests if(mRequests.size() == 0) return; //Set the mIsBusy flag, so we don't try to do too much at once mIsBusy = true; //Get the next image request from the queue mNextRequest = mRequests[0]; if(mHttp.isOpen()){ mHttp.close(); } if (mNextRequest->getType() == 5) { MAHandle store = maOpenStore((FILE_PREFIX+mNextRequest->getSaveName()).c_str(), 0); if(store != STERR_NONEXISTENT) { MAHandle cacheimage = maCreatePlaceholder(); maReadStore(store, cacheimage); maCloseStore(store, 0); if (maGetDataSize(cacheimage) > 0) { Util::returnImage(mNextRequest->getImage(), cacheimage, 64); } maDestroyObject(cacheimage); cacheimage = -1; } store = -1; finishedDownloading(); } else { mHttp = HttpConnection(this); int res = mHttp.create(mNextRequest->getUrl().c_str(), HTTP_GET); if(res < 0) { finishedDownloading(); } else { mHttp.finish(); } } }
void MoSyncCamController::snapshotDisplayRequested() { if ( !isDisplayed(*mImageViewerScreen) ) { if ( mLastSnapshotDataHandle > 0 ) { mDisplayedImageHandle = maCreatePlaceholder(); maCreateImageFromData( mDisplayedImageHandle, mLastSnapshotDataHandle, 0, maGetDataSize(mLastSnapshotDataHandle)); mImageViewerScreen->setImageWithData(mDisplayedImageHandle); mImageViewerScreen->showWithTransition(mForwardTransition, SCREEN_TRANSITION_DURATION); setCurrentScreen(*mImageViewerScreen); } } }
VisueelScherm::VisueelScherm( WeerData* weerData ) { //sla de weerdata op in het attribuut this->weerData = weerData; //ken font en skin toe this->font = new Font(RES_FONT); this->skin = new WidgetSkin(RES_SELECTED, RES_UNSELECTED, 16,32,16,32,false, false); //maak een achtergrond label om alle andere widgets in op te slaan, en te tonen Label* achtergrond = new Label(0,0,0,0,NULL); achtergrond->setBackgroundColor(0x000000); //maak een listbox waar update en visueelknop aan toegevoegd worden this->listBox = new ListBox(5,0,150,40,achtergrond); //knop om data te updaten this->updateKnop = new Label(5,0,50,25,achtergrond, "Update!", 0, font); this->updateKnop->setSkin( this->skin ); //knop om naar visueel scherm te schakelen this->textueelKnop = new Label(55,0,50,25,achtergrond, "Visueel!", 0, font); this->textueelKnop->setSkin( this->skin ); //staafdiagram //maak eerst een placeholder this->diagramTekening = maCreatePlaceholder(); //laat de placeholder tekenbaar zijn maCreateDrawableImage( this->diagramTekening, EXTENT_X( maGetScrSize() ), EXTENT_Y( maGetScrSize() ) - 30 ); //mak een nieuwe image met de placeholder this->diagramImage = new Image( 0, 30, EXTENT_X( maGetScrSize() ), EXTENT_Y( maGetScrSize() ) - 30, achtergrond, true, true, this->diagramTekening ); this->setMain( achtergrond ); this->update(); }
int NativeScreen::handleImageData(MAHandle myImageData) { printf("handleImageData(%d)", myImageData); int resCode = -1; MAHandle hImage = maCreatePlaceholder(); int dataSize = maGetDataSize(myImageData); int createImageRes = maCreateImageFromData(hImage, myImageData, 0, dataSize); // Used for testing only. MAUtil::String info = "Ready.Size = " + MAUtil::integerToString(dataSize) + " res = " + MAUtil::integerToString(createImageRes); printf("\n%s\n", info.c_str()); if (createImageRes != RES_OK) { // If the Android VM gets an out of memory exception, get the image handle instead. maAlert("Memory Warning", " The image cannot be created. Try again", NULL, NULL, NULL); maWidgetSetProperty(mEventReturnTypeCheckbox, MAW_CHECK_BOX_CHECKED, "false"); maImagePickerOpen(); } else { char imgHandle[256]; sprintf(imgHandle, "%d", hImage); printf("imgHandle=%s---hImage=%d", imgHandle, hImage); // display the preview resCode = maWidgetSetProperty(mPreview, MAW_IMAGE_IMAGE, imgHandle); } // at this point the new selected image is either displayed or non-existent (out of memory) // the former displayed image (if exists) can be now safely deleted and reused if (mLastDisplayedImageHandle != -1) { maDestroyPlaceholder(mLastDisplayedImageHandle); } mLastDisplayedImageHandle = hImage; return resCode; }
void testImageRawData() { const unsigned int NUMCOLORS = sizeof(sColors)/sizeof(int); unsigned int colors2[NUMCOLORS]; MAHandle testImg = maCreatePlaceholder(); printf("imageRawData\n"); int res = maCreateImageRaw(testImg, sColors, EXTENT(NUMCOLORS,1), 1); assert("maCreateImageRaw", res == RES_OK); MAExtent e1 = maGetImageSize(testImg); assert("maGetImageSize", e1 == EXTENT(NUMCOLORS,1)); MARect rect = {0, 0, NUMCOLORS, 1}; maGetImageData(testImg, colors2, &rect, NUMCOLORS); assert("image: createRaw then getData", (memcmp(sColors, colors2, sizeof(sColors)) == 0) ); }
static MAHandle AllocateHandle() { return maCreatePlaceholder(); }
/** * Handle widget events. * @param event A MoSync event data structure. */ void NativeScreen::customEvent(const MAEvent& event) { // Get the information sent by the widget. MAWidgetEventData* widgetEventData = (MAWidgetEventData*) event.data; if ( event.type == EVENT_TYPE_IMAGE_PICKER) { if ( event.imagePickerState == 1 ) { // ready, get handle MAHandle myImage = event.imagePickerItem; char checkboxBuffer[BUF_SIZE]; maWidgetGetProperty(mEventReturnTypeCheckbox, MAW_CHECK_BOX_CHECKED, checkboxBuffer, BUF_SIZE); MAUtil::String value = MAUtil::lowerString(checkboxBuffer); if ( strcmp(value.c_str(),"true") == 0 ) { MAHandle hImage = maCreatePlaceholder(); int dataSize = maGetDataSize(event.imagePickerItem); int createImageRes= maCreateImageFromData(hImage, event.imagePickerItem, 0, dataSize); // Used for testing only. MAUtil::String info = "Ready.Size = " + MAUtil::integerToString(dataSize) + "res = " + MAUtil::integerToString(createImageRes) + ", mime type = " + MAUtil::integerToString(event.imagePickerEncodingType); if ( createImageRes != RES_OK ) { maAlert("Memory Warning", " The image cannot be created. Try again", NULL, NULL, NULL); maWidgetSetProperty(mEventReturnTypeCheckbox, MAW_CHECK_BOX_CHECKED, "false"); // If the Android VM gets an out of memory exception, get the image handle instead. maImagePickerOpen(); } else { char imgHandle[256]; sprintf(imgHandle, "%d", hImage); int resCode = maWidgetSetProperty(mPreview, MAW_IMAGE_IMAGE, imgHandle); } maDestroyPlaceholder(hImage); } else { char buffer[256]; sprintf(buffer, "%d", myImage); int resCode = maWidgetSetProperty(mPreview, MAW_IMAGE_IMAGE, buffer); } setLabelText(mLabel, "Preview is available"); } else { setLabelText(mLabel, "The user canceled the image selection"); } } // Check that the event was a click (touch) event. if (widgetEventData->eventType == MAW_EVENT_CLICKED) { // Handle the event emitted by the widget widgetClicked(widgetEventData->widgetHandle); } }
/** * TODO: This function also has the JNIEnv fix. */ static int nativeCreatePlaceholder( JNIEnv* env, jobject jthis ) { int result = maCreatePlaceholder(); return result; }