@Override public int insertImageFromFile(String filename) { final BaseViewAdapter adapter = internalAdapter(); if (adapter == null || filename == null) return 0; String name = filename.substring(filename.lastIndexOf('/') + 1).toLowerCase(Locale.US); Drawable d; if (name.endsWith(".svg")) { d = mView.getImageCache().addSVGFile(filename, name); } else { d = mView.getImageCache().addBitmapFile(getContext().getResources(), filename, name); } if (d != null) { final String destPath = adapter.getRecordPath(); if (destPath != null) { ImageCache.copyFileTo(filename, destPath); } synchronized (mView.coreView()) { int w = ImageCache.getWidth(d); int h = ImageCache.getHeight(d); return mView.coreView().addImageShape(name, w, h); } } return 0; }
@Override public int insertBitmapFromResource(String name) { int id = ResourceUtil.getDrawableIDFromName(getContext(), name); name = ImageCache.BITMAP_PREFIX + name; final Drawable d = mView.getImageCache().addBitmap(getContext().getResources(), id, name); synchronized (mView.coreView()) { return d == null ? 0 : mView.coreView().addImageShape(name, ImageCache.getWidth(d), ImageCache.getHeight(d)); } }
// ! 放大镜视图(mainView有效)或临时视图(mainView=nil)的构造函数 public StdGraphView(Context context, BaseGraphView mainView) { super(context); mImageCache = mainView != null ? mainView.getImageCache() : new ImageCache(); createAdapter(context, null); mMainView = mainView; if (mainView != null) { mCoreView = GiCoreView.createMagnifierView(mViewAdapter, mainView.coreView(), mainView.viewAdapter()); } else { mCoreView = GiCoreView.createView(mViewAdapter, GiCoreView.kNoCmdType); } initView(context); }
@Override public int insertSVGFromResource(String name, int xc, int yc) { int id = ResourceUtil.getResIDFromName(getContext(), "raw", name); name = ImageCache.SVG_PREFIX + name; final Drawable d = mView.getImageCache().addSVG(getContext().getResources(), id, name); synchronized (mView.coreView()) { return d == null ? 0 : mView .coreView() .addImageShape(name, xc, yc, ImageCache.getWidth(d), ImageCache.getHeight(d)); } }
@Override public void setImagePath(String path) { mView.getImageCache().setImagePath(path); }
@Override public String getImagePath() { return mView.getImageCache().getImagePath(); }