Пример #1
0
  private void regenInRunnable() {
    Bitmap bmp = mRegenBitmap != null ? mRegenBitmap : mCachedBitmap;
    int count = -1;
    try {
      synchronized (bmp) {
        bmp.eraseColor(mBkColor);
        count = drawShapes(new Canvas(bmp), mCanvasRegen, false);

        if (bmp == mRegenBitmap) {
          if (mCachedBitmap != null) {
            mCachedBitmap.recycle();
          }
          mCachedBitmap = mRegenBitmap;
        }
      }
      if (!mCoreView.isStopping()) {
        postInvalidate();
      }
    } catch (Exception e) {
      Log.w(TAG, "Fail to draw on the cached bitmap", e);
    }
    mRegenBitmap = null;
    mRegenning = false;
    if (count >= 0 && !mCoreView.isStopping()) {
      mViewAdapter.onFirstRegen();
    }
  }
Пример #2
0
 // ! 放大镜视图(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);
 }
Пример #3
0
  @Override
  public void tearDown() {
    if (mViewAdapter == null) {
      return;
    }

    ViewUtil.onRemoveView(this);
    mViewAdapter.stop(null);

    if (mImageCache != null) {
      synchronized (mImageCache) {
        mImageCache.clear();
      }
      mImageCache = null;
    }
    if (mRegenBitmap != null) {
      synchronized (mRegenBitmap) {
        mRegenBitmap.recycle();
      }
      mRegenBitmap = null;
    }
    if (mCachedBitmap != null) {
      synchronized (mCachedBitmap) {
        mCachedBitmap.recycle();
      }
      mCachedBitmap = null;
    }
    synchronized (GiCoreView.class) {
      mCoreView.destoryView(mViewAdapter);
      mViewAdapter.delete();
      mViewAdapter = null;
      mCoreView.delete();
      mCoreView = null;
    }
    if (mCanvasOnDraw != null) {
      mCanvasOnDraw.delete();
      mCanvasOnDraw = null;
    }
    if (mCanvasRegen != null) {
      mCanvasRegen.delete();
      mCanvasRegen = null;
    }
    if (mGestureListener != null) {
      mGestureListener.release();
      mGestureListener = null;
    }
    mGestureDetector = null;
    mMainView = null;
  }
Пример #4
0
 @Override
 public int findShapeByImageID(String name) {
   int doc = acquireFrontDoc();
   int ret = mView.coreView().findShapeByImageID(doc, name);
   GiCoreView.releaseDoc(doc);
   return ret;
 }
Пример #5
0
  @Override
  public Bitmap extentSnapshot(int spaceAround, boolean transparent) {
    final GiCoreView v = mView.coreView();
    int doc, gs;

    synchronized (v) {
      doc = v.acquireFrontDoc();
      gs = v.acquireGraphics(mView.viewAdapter());
    }
    try {
      return extentSnapshot(doc, gs, spaceAround, transparent);
    } finally {
      GiCoreView.releaseDoc(doc);
      v.releaseGraphics(gs);
    }
  }
Пример #6
0
 @Override
 public boolean hasImageShape() {
   int doc = acquireFrontDoc();
   boolean ret = mView.coreView().hasImageShape(doc);
   GiCoreView.releaseDoc(doc);
   return ret;
 }
Пример #7
0
 @Override
 protected void onDraw(Canvas canvas) {
   if (mCanvasAdapter.beginPaint(canvas)) {
     canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
     mCoreView.dynDraw(mViewAdapter, mCanvasAdapter);
     mCanvasAdapter.endPaint();
   }
 }
Пример #8
0
 @Override
 public boolean onPause() {
   if (mViewAdapter != null) {
     mViewAdapter.hideContextActions();
     return mCoreView.onPause(BaseViewAdapter.getTick());
   }
   return false;
 }
Пример #9
0
 // ! 构造绘图视图,允许在Activity的onCreate(Bundle)或onRestoreInstanceState(Bundle)中调用
 public StdGraphView(Context context, Bundle savedInstanceState) {
   super(context);
   mImageCache = new ImageCache();
   createAdapter(context, savedInstanceState);
   mCoreView = GiCoreView.createView(mViewAdapter);
   initView(context);
   ViewUtil.onAddView(this);
 }
Пример #10
0
 @Override
 public void clearCachedData() {
   mCoreView.clearCachedData();
   if (mCachedBitmap != null) {
     mCachedBitmap.recycle();
     mCachedBitmap = null;
   }
 }
Пример #11
0
  @Override
  public boolean saveToFile(String vgfile) {
    if (mView == null || vgfile == null) return false;

    int doc = acquireFrontDoc();
    boolean ret = saveToFile(vgfile, doc);
    GiCoreView.releaseDoc(doc);
    return ret;
  }
Пример #12
0
  @Override
  public Bitmap snapshot(boolean transparent) {
    final GiCoreView v = mView.coreView();
    int doc, gs;

    synchronized (v) {
      doc = v.acquireFrontDoc();
      gs = v.acquireGraphics(mView.viewAdapter());
    }
    try {
      final LogHelper log = new LogHelper();
      final Bitmap bitmap = mView.snapshot(doc, gs, transparent);
      log.r(bitmap != null ? bitmap.getByteCount() : 0);
      return bitmap;
    } finally {
      GiCoreView.releaseDoc(doc);
      v.releaseGraphics(gs);
    }
  }
Пример #13
0
  @Override
  public String getContent() {
    final LogHelper log = new LogHelper();
    int doc = acquireFrontDoc();
    final StringCallback c = new StringCallback();

    mView.coreView().getContent(doc, c);
    GiCoreView.releaseDoc(doc);
    mView.coreView().freeContent();

    return log.r(c.toString());
  }
Пример #14
0
 @Override
 protected void onDraw(Canvas canvas) {
   mDrawCount++;
   mCoreView.onSize(mViewAdapter, getWidth(), getHeight());
   if (mCachedBitmap != null) {
     drawShapes(canvas, mCanvasOnDraw, true);
     mViewAdapter.fireDynDrawEnded();
   } else if (!regen(false)) {
     // 首次onDraw,但视图太大无法创建缓存位图
     canvas.drawColor(mBkColor);
     drawShapes(canvas, mCanvasOnDraw, true);
   }
 }
Пример #15
0
  private int drawShapes(
      Longs docs, int gs, Longs shapes, Canvas canvas, CanvasAdapter adapter, boolean dyndraw) {
    int n = 0;

    if (adapter.beginPaint(canvas)) {
      if (mCachedBitmap == null || !dyndraw) {
        if (this.getBackground() != null) {
          this.getBackground().draw(canvas);
        }
        n = mCoreView.drawAll(docs, gs, adapter);
      } else if (mCachedBitmap != null) {
        synchronized (mCachedBitmap) {
          canvas.drawBitmap(mCachedBitmap, 0, 0, null);
          n++;
        }
      }
      if (dyndraw) {
        mCoreView.dynDraw(shapes, gs, adapter);
      }
      adapter.endPaint();
    }

    return n;
  }
Пример #16
0
    @Override
    public void regenAppend(int sid, int playh) {
      if (mCoreView != null && !mCoreView.isPlaying()) {
        recordForRegenAll(true, mCoreView.getChangeCount());
      }
      if (mCachedBitmap != null && !mRegenning) {
        int docd = mCoreView.acquireFrontDoc(playh);
        int gs = mCoreView.acquireGraphics(mViewAdapter);

        synchronized (mCachedBitmap) {
          if (mCanvasOnDraw.beginPaint(new Canvas(mCachedBitmap))) {
            mCoreView.drawAppend(docd, gs, mCanvasOnDraw, sid);
            mCanvasOnDraw.endPaint();
          }
        }
        GiCoreView.releaseDoc(docd);
        mCoreView.releaseGraphics(gs);
      }
      postInvalidate();
    }
Пример #17
0
  protected void initView(Context context) {
    mGestureListener = new GestureListener(mCoreView, mViewAdapter, this);
    mGestureDetector = new GestureDetector(context, mGestureListener);
    ResourceUtil.setContextImages(context);

    final DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
    GiCoreView.setScreenDpi(dm.densityDpi, dm.density);
    if (mCanvasRegen != null) {
      // 避免路径太大不能渲染
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    this.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent e) {
            if (mCoreView == null || !mGestureEnable) {
              return false;
            }
            if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
              activateView();
            }

            boolean ret;

            if (mCoreView.isCommand("splines")) {
              ret = mGestureListener.onTouchDrag(v, e.getActionMasked(), e.getX(0), e.getY(0));
            } else {
              ret = mGestureListener.onTouch(v, e) || mGestureDetector.onTouchEvent(e);
              if (mGestureListener.getLastGesture() == GiGestureType.kGiGestureTap) {
                v.performClick();
              }
            }
            return ret;
          }
        });
  }
Пример #18
0
  private int drawShapes(Canvas canvas, CanvasAdapter adapter, boolean dyndraw) {
    int gs;
    final Longs docs = new Longs();
    final Longs shapes = new Longs();

    synchronized (mCoreView) {
      if (mCachedBitmap == null || !dyndraw) {
        mCoreView.acquireFrontDocs(docs);
      }
      gs = mCoreView.acquireGraphics(mViewAdapter);
      mCoreView.acquireDynamicShapesArray(shapes);
    }
    try {
      return drawShapes(docs, gs, shapes, canvas, adapter, dyndraw);
    } finally {
      GiCoreView.releaseDocs(docs);
      GiCoreView.releaseShapesArray(shapes);
      shapes.delete();
      mCoreView.releaseGraphics(gs);
    }
  }
Пример #19
0
 static {
   System.loadLibrary("touchvg");
   Log.i(TAG, "TouchVG V1.1." + JARVERSION + "." + GiCoreView.getVersion());
 }
Пример #20
0
 public int cmdViewHandle() {
   final GiCoreView v = mView != null ? mView.coreView() : null;
   return v != null ? v.viewAdapterHandle() : 0;
 }
Пример #21
0
 @Override
 public String getVersion() {
   return String.format(Locale.US, "1.1.%d.%d", JARVERSION, GiCoreView.getVersion());
 }
Пример #22
0
 @Override
 public void setBackgroundColor(int color) {
   mBkColor = color;
   mCoreView.setBkColor(mViewAdapter, color);
   regen(false);
 }
Пример #23
0
 @Override
 public boolean onResume() {
   return mCoreView.onResume(BaseViewAdapter.getTick());
 }
Пример #24
0
 @Override
 public int cmdViewHandle() {
   return mCoreView != null ? mCoreView.viewAdapterHandle() : 0;
 }