예제 #1
0
  @Override
  protected synchronized void onSizeChanged(int w, int h, int oldw, int oldh) {

    // update pixel conversion values
    PixelUtils.init(getContext());

    // disable hardware acceleration if it's not explicitly supported
    // by the current Plot implementation. this check only applies to
    // honeycomb and later environments.
    if (Build.VERSION.SDK_INT >= 11) {
      if (!isHwAccelerationSupported() && isHardwareAccelerated()) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
      }
    }

    // pingPong is only used in background rendering mode.
    if (renderMode == RenderMode.USE_BACKGROUND_THREAD) {
      pingPong.resize(h, w);
    }

    RectF cRect = new RectF(0, 0, w, h);
    RectF mRect = boxModel.getMarginatedRect(cRect);
    RectF pRect = boxModel.getPaddedRect(mRect);

    layout(new DisplayDimensions(cRect, mRect, pRect));
    super.onSizeChanged(w, h, oldw, oldh);
    if (renderThread != null && !renderThread.isAlive()) {
      renderThread.start();
    }
  }
예제 #2
0
 /**
  * Called whenever the plot needs to be drawn via the Handler, which invokes invalidate(). Should
  * never be called directly; use {@link #redraw()} instead.
  *
  * @param canvas
  */
 @Override
 protected void onDraw(Canvas canvas) {
   if (renderMode == RenderMode.USE_BACKGROUND_THREAD) {
     synchronized (pingPong) {
       Bitmap bmp = pingPong.getBitmap();
       if (bmp != null) {
         canvas.drawBitmap(bmp, 0, 0, null);
       }
     }
   } else if (renderMode == RenderMode.USE_MAIN_THREAD) {
     renderOnCanvas(canvas);
   } else {
     throw new IllegalArgumentException("Unsupported Render Mode: " + renderMode);
   }
 }