List of usage examples for android.graphics.drawable PictureDrawable PictureDrawable
public PictureDrawable(Picture picture)
From source file:com.rk.lib.view.SVGView.java
/** * Caches the previous reference resources or create the new reference if * the previous reference not availabe and Sets a drawable as the content of * this ImageView./*from ww w . j a v a 2 s .c o m*/ * * @param resourceId * - Integer value that refers the SVG resource * @param isSvgResource * - Boolean value that refers the resource is drawable or svg. * If the resource is SVG then it will be true, otherwise false. */ public void setCacheImageDrawable(int resourceId, boolean isSvgResource) { Drawable drawable = memoryCache.get(resourceId); if (drawable != null) { this.setImageDrawable(drawable); } else { if (isSvgResource) { drawable = new PictureDrawable(getPicture(resourceId)); } else { drawable = getResources().getDrawable(resourceId); } if (drawable != null) { this.setImageDrawable(drawable); memoryCache.put(resourceId, drawable); } } }
From source file:com.rk.lib.view.SVGView.java
/** * Caches the previous reference resources or create the new reference if * the previous reference not available and Sets a background drawable * associated with this ImageView// w w w . j a va2 s .c o m * * @param resourceId * - Integer value that refers the SVG resource * @param isSvgResource * - Boolean value that refers the resource is drawable or svg. * If the resource is SVG then it will be true, otherwise false. */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public void setCacheBackgroundDrawable(int resourceId, boolean isSvgResource) { Drawable drawable = memoryCache.get(resourceId); if (drawable != null) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { this.setBackgroundDrawable(drawable); } else { this.setBackground(drawable); } } else { if (isSvgResource) { drawable = new PictureDrawable(getPicture(resourceId)); } else { drawable = getResources().getDrawable(resourceId); } if (drawable != null) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { this.setBackgroundDrawable(drawable); } else { this.setBackground(drawable); } memoryCache.put(resourceId, drawable); } } }
From source file:rhcad.touchvg.view.internal.ImageCache.java
@SuppressWarnings("unused") public final Drawable addSVG(Resources res, int id, String name) { Drawable drawable = mCache != null ? mCache.get(name) : null; if (drawable == null && id != 0 && USE_SVG) { try {/* w w w. ja v a2s . c om*/ final Picture picture = SVG.getFromResource(res, id).renderToPicture(); if (picture != null && picture.getWidth() > 0) { drawable = new PictureDrawable(picture); addToCache(name, drawable); } } catch (SVGParseException e) { Log.e(TAG, "Parse resource fail", e); } } return drawable; }
From source file:uk.ac.ucl.excites.sapelli.collector.ui.items.ImageItem.java
@Override protected View createView(Context context, boolean recycleChildren) { ImageView view = new ImageView(context); // Set scaling (raster-based images are only scaled down, never up; vector-based ones can be scaled up or down): view.setScaleType(isVectorBased() ? (keepVectorAspectRatio ? ScaleType.FIT_CENTER : ScaleType.FIT_XY) : ScaleType.CENTER_INSIDE);//from w w w. j av a 2s . co m /* Disable h/w acceleration for vector (SVG) images * Reason explained here: * - https://github.com/japgolly/svg-android/commit/a1a613b * - http://stackoverflow.com/q/10384613/1084488 */ if (isVectorBased()) ViewCompat.setLayerType(view, ViewCompat.LAYER_TYPE_SOFTWARE, null); // Set image: try { if (!isVectorBased()) { // Raster image (PNG, JPG, GIF, ...): if (file != null) view.setImageBitmap(BitmapUtils.loadBitmap(context, file)); // use BitmapUtils for memory-safe load of (potentially very large) image else view.setImageResource(drawableResourceID); } else { // Vector image (SVG or SVGZ): // Using svg-android lib: /*view.setImageDrawable(new SVGDrawable((file != null ? new SVGBuilder().readFromInputStream(new FileInputStream(file)) : new SVGBuilder().readFromResource(context.getResources(), drawableResourceID)).build()));*/ // Using AndroidSVG lib: view.setImageDrawable( new PictureDrawable((file != null ? SVG.getFromInputStream(new FileInputStream(file)) : SVG.getFromResource(context.getResources(), drawableResourceID)) .renderToPicture())); } } catch (Exception e) { Log.e(TAG, "Could not load image from " + (file != null ? "file" : "drawable resource") + "(" + (file != null ? file.getAbsolutePath() : "id: " + drawableResourceID) + ")", e); } return view; }
From source file:rhcad.touchvg.view.internal.ImageCache.java
@SuppressWarnings("unused") public final Drawable addSVGFile(String filename, String name) { Drawable drawable = mCache != null ? mCache.get(name) : null; if (drawable == null && name.endsWith(".svg") && USE_SVG) { try {/* www. ja v a 2 s.c o m*/ final InputStream data = new FileInputStream(new File(filename)); final Picture picture = SVG.getFromInputStream(data).renderToPicture(); if (picture != null && picture.getWidth() > 0) { drawable = new PictureDrawable(picture); addToCache(name, drawable); } data.close(); } catch (FileNotFoundException e) { Log.e(TAG, "File not found", e); } catch (IOException e) { Log.e(TAG, "SVG read fail", e); } catch (SVGParseException e) { Log.e(TAG, "Parse file fail", e); } } return drawable; }
From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.itemQuit) { try {/* w w w . j a v a 2s . c o m*/ dataBaseData.deleteTable(DataBaseData.DB_TABLE_TABS); } catch (Exception e) { Log.e(TAG, "deleteTable: " + e.getMessage()); } this.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } else if (item.getItemId() == R.id.itemFeedback) { Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); String aEmailList[] = { "codeskraps@gmail.com" }; emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "sBrowser - Feedback"); emailIntent.setType("plain/text"); startActivity(Intent.createChooser(emailIntent, "Send your feedback in:")); /*- } else if (item.getItemId() == R.id.itemBuyMeAPint) { try { Intent marketIntent = new Intent(Intent.ACTION_VIEW); marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(marketIntent.setData(Uri.parse("market://developer?id=Codeskraps"))); } catch (Exception e) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/developer?id=Codeskraps")); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(browserIntent); Log.e(TAG, e.getMessage()); } */ } else { try { Picture picture = webView.capturePicture(); PictureDrawable pictureDrawable = new PictureDrawable(picture); Bitmap bitmap = Bitmap.createBitmap(300, 300, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, (OutputStream) bos); bitmap.isRecycled(); BookmarkItem bookmarkItem = new BookmarkItem(webView.getTitle(), webView.getUrl()); bookmarkItem.setImage(bos.toByteArray()); sBrowserData.setBookmarkItem(bookmarkItem); bos.close(); } catch (Exception e) { Log.e(TAG, "Picture:" + e.getMessage()); BookmarkItem bookmarkItem = new BookmarkItem("Set title", "Set url"); bookmarkItem.setImage(null); sBrowserData.setBookmarkItem(bookmarkItem); } SBrowserApplication sBrwoserApp = (SBrowserApplication) getApplication(); SBrowserActivity.this.startActivity(sBrwoserApp.getMenuIntent(item, SBrowserActivity.this)); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } return super.onOptionsItemSelected(item); }
From source file:org.samcrow.ridgesurvey.MainActivity.java
/** * Returns a drawable that represents an icon used to display the user's location * * @return an icon drawable// www . ja va 2 s . c om */ private Drawable getMyLocationDrawable() { try { final SVG svg = SVG.getFromResource(getResources(), R.raw.my_location_icon); // Resize based on screen density final float density = getResources().getDisplayMetrics().density; svg.setDocumentWidth(svg.getDocumentWidth() * density); svg.setDocumentHeight(svg.getDocumentHeight() * density); final Picture picture = svg.renderToPicture(); return new PictureDrawable(picture); } catch (SVGParseException e) { throw new RuntimeException("Could not load my location image", e); } }
From source file:com.google.appinventor.components.runtime.util.NativeOpenStreetMapController.java
private Drawable rasterizeSVG(MapMarker aiMarker, SVG markerSvg) { SVG.Svg svg = markerSvg.getRootElement(); final float density = view.getContext().getResources().getDisplayMetrics().density; float height = aiMarker.Height() <= 0 ? getBestGuessHeight(svg) : aiMarker.Height(); float width = aiMarker.Width() <= 0 ? getBestGuessWidth(svg) : aiMarker.Width(); float scaleH = height / getBestGuessHeight(svg); float scaleW = width / getBestGuessWidth(svg); float scale = (float) Math.sqrt(scaleH * scaleH + scaleW * scaleW); // update fill color of SVG <path> Paint fillPaint = new Paint(); Paint strokePaint = new Paint(); PaintUtil.changePaint(fillPaint, aiMarker.FillColor()); PaintUtil.changePaint(strokePaint, aiMarker.StrokeColor()); SVG.Length strokeWidth = new SVG.Length(aiMarker.StrokeWidth() / scale); for (SVG.SvgObject element : svg.getChildren()) { if (element instanceof SVG.SvgConditionalElement) { SVG.SvgConditionalElement path = (SVG.SvgConditionalElement) element; path.baseStyle.fill = new SVG.Colour(fillPaint.getColor()); path.baseStyle.fillOpacity = fillPaint.getAlpha() / 255.0f; path.baseStyle.stroke = new SVG.Colour(strokePaint.getColor()); path.baseStyle.strokeOpacity = strokePaint.getAlpha() / 255.0f; path.baseStyle.strokeWidth = strokeWidth; if (path.style != null) { if ((path.style.specifiedFlags & SPECIFIED_FILL) == 0) { path.style.fill = new SVG.Colour(fillPaint.getColor()); path.style.specifiedFlags |= SPECIFIED_FILL; }// w w w . j a v a 2s . c o m if ((path.style.specifiedFlags & SPECIFIED_FILL_OPACITY) == 0) { path.style.fillOpacity = fillPaint.getAlpha() / 255.0f; path.style.specifiedFlags |= SPECIFIED_FILL_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE) == 0) { path.style.stroke = new SVG.Colour(strokePaint.getColor()); path.style.specifiedFlags |= SPECIFIED_STROKE; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_OPACITY) == 0) { path.style.strokeOpacity = strokePaint.getAlpha() / 255.0f; path.style.specifiedFlags |= SPECIFIED_STROKE_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_WIDTH) == 0) { path.style.strokeWidth = strokeWidth; path.style.specifiedFlags |= SPECIFIED_STROKE_WIDTH; } } } } // draw SVG to Picture and create a BitmapDrawable for rendering Picture picture = markerSvg.renderToPicture(); Picture scaledPicture = new Picture(); Canvas canvas = scaledPicture.beginRecording((int) ((width + 2.0f * aiMarker.StrokeWidth()) * density), (int) ((height + 2.0f * aiMarker.StrokeWidth()) * density)); canvas.scale(density * scaleW, density * scaleH); canvas.translate(strokeWidth.floatValue(), strokeWidth.floatValue()); picture.draw(canvas); scaledPicture.endRecording(); return new PictureDrawable(scaledPicture); }
From source file:com.ywesee.amiko.MainActivity.java
/** * Converts given picture to a bitmap//from w w w . j ava2s. com * @param picture * @return */ private static Bitmap pictureDrawable2Bitmap(Picture picture) { PictureDrawable pictureDrawable = new PictureDrawable(picture); Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); return bitmap; }