本文整理汇总了Java中com.larvalabs.svgandroid.SVGParser类的典型用法代码示例。如果您正苦于以下问题:Java SVGParser类的具体用法?Java SVGParser怎么用?Java SVGParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SVGParser类属于com.larvalabs.svgandroid包,在下文中一共展示了SVGParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBitmapSvg
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
private Bitmap getBitmapSvg(Params params, String fileName, int densityIndex) {
try {
FileInputStream inputStream = new FileInputStream(mContext.getFilesDir() + MainActivity.ICONS_PATH + fileName);
SVG svg = SVGParser.getSVGFromInputStream(inputStream);
// Icon size relative to current processed density
int fSize = ICONS_SIZE[densityIndex];
Bitmap bitmap = Bitmap.createBitmap(fSize, fSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(svg.getPicture(), new Rect(0, 0, fSize, fSize));
Bitmap finalBitmap = createTintedBitmap(bitmap, params.desiredColor);
bitmap.recycle();
return finalBitmap;
} catch (IOException | SVGParseException e) {
e.printStackTrace();
return null;
}
}
示例2: init
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
private void init() {
// Setup the paint.
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.WHITE);
mPaint.setStrokeWidth(10);
mPaint.setPathEffect(new DashPathEffect(new float[] { 50f, 50f }, 100f));
// Setup the bitmap and path.
mPlaneBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.plane);
// Make sure the plane is not shown before the animation.
mPlaneCoordinate[0] = -mPlaneBitmap.getWidth();
mPlaneCoordinate[1] = -mPlaneBitmap.getHeight();
mPath = SVGParser.parsePath(PATH);
}
示例3: updateForMode
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public void updateForMode(final AssetManager manager) {
synchronized (gfxLock) {
try {
final Type type = Model.getInstance().getType();
if (type != null) {
vertushka = SVGParser.getSVGFromAsset(manager, "svg/" + type.getResource());
}
resize();
}
catch (Exception ex) {
throw new Error("Can't load svg", ex);
}
finally {
refresh();
}
}
}
示例4: setButtonData
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
private final void setButtonData(ImageButton button, int bWidth, int bHeight,
int svgResId, SVG touched) {
SVG svg = SVGParser.getSVGFromResource(getResources(), svgResId);
button.setBackgroundDrawable(new SVGPictureDrawable(svg));
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[]{android.R.attr.state_pressed}, new SVGPictureDrawable(touched));
button.setImageDrawable(sld);
LayoutParams lp = button.getLayoutParams();
lp.height = bHeight;
lp.width = bWidth;
button.setLayoutParams(lp);
button.setPadding(0,0,0,0);
button.setScaleType(ScaleType.FIT_XY);
}
示例5: onCreate
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_svg_android_sample);
mMatrix = new Matrix();
mImageView = (ImageView) findViewById(R.id.image);
checkLayer(mImageView);
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.cute_fox);
mImageView.setImageDrawable(svg.createPictureDrawable());
mImageView.setImageMatrix(mMatrix);
final ScaleGestureDetector detector = new ScaleGestureDetector(this,
this);
mImageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return detector.onTouchEvent(event);
}
});
}
开发者ID:android-opensource-library-56,项目名称:android-opensource-library-56,代码行数:24,代码来源:SvgAndroidSampleActivity.java
示例6: SVGTileProvider
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public SVGTileProvider(File file, float dpi) throws IOException {
mScale = Math.round(dpi + .3f); // Make it look nice on N7 (1.3 dpi)
mDimension = BASE_TILE_SIZE * mScale;
mPool = new TileGeneratorPool(POOL_MAX_SIZE);
mSvgFile = readFile(file);
RectF limits = SVGParser.getSVGFromInputStream(new ByteArrayInputStream(mSvgFile)).getLimits();
mBaseMatrix = new Matrix();
mBaseMatrix.setPolyToPoly(
new float[]{
0, 0,
limits.width(), 0,
limits.width(), limits.height()
}, 0,
new float[]{
40.95635986328125f, 98.94217824936158f,
40.95730018615723f, 98.94123077396628f,
40.95791244506836f, 98.94186019897214f
}, 0, 3);
}
示例7: getDrawable
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public static Drawable getDrawable(String name, String svgSource) {
if (cache.get(name) != null) {
return cache.get(name);
} else {
SVG svg = SVGParser.getSVGFromString(svgSource);
Drawable d = svg.createPictureDrawable();
cache.put(name, d);
return d;
}
}
示例8: onCreate
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundColor(Color.WHITE);
// Parse the SVG file, using svg-android
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.d("MainActivity", "disabling hw acceleration");
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.x);
imageView.setImageDrawable(svg.createPictureDrawable());
}
示例9: doInBackground
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
@Override
protected SVG doInBackground(String... params) {
try {
FileInputStream inputStream = new FileInputStream(params[0]);
SVG svg = SVGParser.getSVGFromInputStream(inputStream, Color.BLACK, Color.DKGRAY);
inputStream.close();
return svg;
} catch (IOException | SVGParseException e) {
Log.e("SVG", params[0]);
e.printStackTrace();
return null;
}
}
示例10: getDrawableForSvg
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public static Drawable getDrawableForSvg(Context context, String fileName) {
try {
FileInputStream inputStream = new FileInputStream(context.getFilesDir() + MainActivity.ICONS_PATH + fileName);
SVG svg = SVGParser.getSVGFromInputStream(inputStream, Color.BLACK, Color.DKGRAY);
return svg.createPictureDrawable();
} catch (IOException | SVGParseException e) {
e.printStackTrace();
return null;
}
}
示例11: PdDroidPatchView
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public PdDroidPatchView(Activity activity, PdPatch patch, PdDroidPartyConfig config) {
super(activity);
this.patch = patch;
this.config = config;
// disable graphic acceleration to have SVG properly rendered
// not needed prior to API level 17
// not possible prior to API level 11
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
setSoftwareMode();
}
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
this.setId(R.id.patch_view);
paint.setColor(backgroundColor);
paint.setAntiAlias(true);
res = activity.getResources();
// if there is a splash image, use it
splash_res = res.getIdentifier("splash", "raw", activity.getPackageName());
if (splash_res != 0) {
// Get a drawable from the parsed SVG and set it as the drawable for the ImageView
background = SVGParser.getSVGFromResource(res, splash_res).getPicture();
} else {
loadBackground();
}
}
示例12: surfaceCreated
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
@Override
public void surfaceCreated(final SurfaceHolder surfaceHolder) {
try {
strelka = SVGParser.getSVGFromAsset(getContext().getAssets(), "svg/strelka.svg");
updateForMode(getContext().getAssets());
}
catch (Exception ex) {
throw new Error("Can't load svg", ex);
}
}
示例13: updateButtons
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
private final void updateButtons() {
boolean largeButtons = settings.getBoolean("largeButtons", false);
Resources r = getResources();
int bWidth = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
int bHeight = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics()));
if (largeButtons) {
if (custom1ButtonActions.isEnabled() &&
custom2ButtonActions.isEnabled() &&
custom3ButtonActions.isEnabled()) {
Configuration config = getResources().getConfiguration();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
bWidth = bWidth * 6 / 5;
bHeight = bHeight * 6 / 5;
} else {
bWidth = bWidth * 5 / 4;
bHeight = bHeight * 5 / 4;
}
} else {
bWidth = bWidth * 3 / 2;
bHeight = bHeight * 3 / 2;
}
}
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.touch);
setButtonData(custom1Button, bWidth, bHeight, custom1ButtonActions.getIcon(), svg);
setButtonData(custom2Button, bWidth, bHeight, custom2ButtonActions.getIcon(), svg);
setButtonData(custom3Button, bWidth, bHeight, custom3ButtonActions.getIcon(), svg);
setButtonData(modeButton, bWidth, bHeight, R.raw.mode, svg);
setButtonData(undoButton, bWidth, bHeight, R.raw.left, svg);
setButtonData(redoButton, bWidth, bHeight, R.raw.right, svg);
}
示例14: setClef
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
public void setClef(Clef clef) {
_clef = clef;
SVG svg = SVGParser.getSVGFromResource(getResources(), clef._svgResource);
_clefPic = svg.getPicture();
int scaledWidth = _clefPic.getWidth() * _clef._height / _clefPic.getHeight();
_clefRect = new Rect(_clefLeft, _clef._top,
_clefLeft + scaledWidth, _clef._top + _clef._height);
}
示例15: syncMapTiles
import com.larvalabs.svgandroid.SVGParser; //导入依赖的package包/类
/**
* Synchronise the map overlay files either from the local assets (if available) or from a remote url.
*
* @param collection Set of tiles containing a local filename and remote url.
* @throws IOException
*/
private void syncMapTiles(Collection<Tile> collection) throws IOException, SVGParseException {
//keep track of used files, unused files are removed
ArrayList<String> usedTiles = Lists.newArrayList();
for(Tile tile : collection){
final String filename = tile.filename;
final String url = tile.url;
usedTiles.add(filename);
if (!MapUtils.hasTile(mContext, filename)) {
// copy or download the tile if it is not stored yet
if (MapUtils.hasTileAsset(mContext, filename)) {
// file already exists as an asset, copy it
MapUtils.copyTileAsset(mContext, filename);
} else {
// download the file
File tileFile = MapUtils.getTileFile(mContext, filename);
BasicHttpClient httpClient = new BasicHttpClient();
httpClient.setRequestLogger(mQuietLogger);
HttpResponse httpResponse = httpClient.get(url, null);
writeFile(httpResponse.getBody(), tileFile);
// ensure the file is valid SVG
InputStream is = new FileInputStream(tileFile);
SVG svg = SVGParser.getSVGFromInputStream(is);
is.close();
}
}
}
MapUtils.removeUnusedTiles(mContext, usedTiles);
}