/** * @param myContext * @param cb * @return true if loaded. False if executor should pause. */ public boolean create(WF_Context myContext, final AsyncResumeExecutorI cb) { Context ctx = myContext.getContext(); gs = GlobalState.getInstance(); o = gs.getLogger(); this.cb = cb; this.myContext = myContext; PersistenceHelper ph = gs.getPreferences(); PersistenceHelper globalPh = gs.getGlobalPreferences(); final String serverFileRootDir = server(globalPh.get(PersistenceHelper.SERVER_URL)) + globalPh.get(PersistenceHelper.BUNDLE_NAME).toLowerCase() + "/extras/"; final String cacheFolder = Constants.VORTEX_ROOT_DIR + globalPh.get(PersistenceHelper.BUNDLE_NAME) + "/cache/"; if (source == null || source.length() == 0) { Log.e("vortex", "Pic url null! GisImageView will not load"); o.addRow(""); o.addRedText("GisImageView failed to load. No picture defined"); // continue execution immediately. return true; } final String picName = Tools.parseString(source); Log.d("vortex", "ParseString result: " + picName); // Load asynchronously. Put up a loadbar. Tools.onLoadCacheImage( serverFileRootDir, picName, cacheFolder, new WebLoaderCb() { @Override public void progress(int bytesRead) { Log.d("vortex", "progress: " + bytesRead); } @Override public void loaded(Boolean result) { if (result) loadImageMetaData(picName, serverFileRootDir, cacheFolder); else { Log.e("vortex", "Pic url null! GisImageView will not load"); o.addRow(""); o.addRedText( "GisImageView failed to load. File not found: " + serverFileRootDir + picName); cb.abortExecution( "GisImageView failed to load. File not found: " + serverFileRootDir + picName); } } }); return false; }
public void createAfterLoad(PhotoMeta photoMeta, final String cachedImgFilePath) { this.photoMetaData = photoMeta; final Container myContainer = myContext.getContainer(containerId); if (myContainer != null && photoMetaData != null) { LayoutInflater li = LayoutInflater.from(myContext.getContext()); final FrameLayout mapView = (FrameLayout) li.inflate(R.layout.image_gis_layout, null); final View avstRL = mapView.findViewById(R.id.avstRL); final View createMenuL = mapView.findViewById(R.id.createMenuL); r = null; if (cutOut == null) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(cachedImgFilePath, options); imageHeight = options.outHeight; imageWidth = options.outWidth; Log.d("vortex", "image rect h w is " + imageHeight + "," + imageWidth); r = new Rect(0, 0, imageWidth, imageHeight); } else { // This is a cutout. pop the correct slice specification from the stack. r = cutOut.r; Location topC = cutOut.geoR.get(0); Location botC = cutOut.geoR.get(1); photoMetaData = new PhotoMeta(topC.getY(), botC.getX(), botC.getY(), topC.getX()); cutOut = null; } new Handler() .postDelayed( new Runnable() { public void run() { Bitmap bmp = Tools.getScaledImageRegion(myContext.getContext(), cachedImgFilePath, r); if (bmp != null) { gis = new WF_Gis_Map( CreateGisBlock.this, r, blockId, mapView, isVisible, bmp, myContext, photoMetaData, avstRL, createMenuL, myLayers, imageWidth, imageHeight); // need to throw away the reference to myLayers. myLayers = null; myContainer.add(gis); myContext.addGis(gis.getId(), gis); myContext.addEventListener(gis, EventType.onSave); myContext.addDrawable(name, gis); final View menuL = mapView.findViewById(R.id.menuL); menuL.setVisibility(View.INVISIBLE); avstRL.setVisibility(View.INVISIBLE); final ImageButton menuB = (ImageButton) mapView.findViewById(R.id.menuB); menuB.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int menuState = menuL.getVisibility(); if (menuState == View.VISIBLE) menuL.setVisibility(View.INVISIBLE); else { gis.initializeLayersMenu(gis.getLayers()); menuL.setVisibility(View.VISIBLE); } } }); cb.continueExecution(); } else { Log.e("vortex", "Failed to create map image. Will exit"); cb.abortExecution( "Failed to create GisImageView. The map file [" + cachedImgFilePath + "] could not be parsed"); } } }, 0); } else { o.addRow(""); if (photoMetaData == null) { Log.e("vortex", "Photemetadata null! Cannot add GisImageView!"); o.addRedText( "Adding GisImageView to " + containerId + " failed. Photometadata missing (the boundaries of the image on the map)"); cb.abortExecution( "Adding GisImageView to " + containerId + " failed. Photometadata missing (the boundaries of the image on the map)"); } else { Log.e("vortex", "Container null! Cannot add GisImageView!"); o.addRedText( "Adding GisImageView to " + containerId + " failed. Container cannot be found in template"); cb.abortExecution("Missing container for GisImageView: " + containerId); } } }