コード例 #1
0
ファイル: Plot.java プロジェクト: HiroshiFuu/androidplot
  private void init(Context context, AttributeSet attrs, int defStyle) {
    PixelUtils.init(getContext());
    layoutManager = new LayoutManager();
    titleWidget =
        new TextLabelWidget(
            layoutManager,
            new Size(25, SizeLayoutType.ABSOLUTE, 100, SizeLayoutType.ABSOLUTE),
            TextOrientationType.HORIZONTAL);
    titleWidget.position(
        0,
        XLayoutStyle.RELATIVE_TO_CENTER,
        0,
        YLayoutStyle.ABSOLUTE_FROM_TOP,
        AnchorPosition.TOP_MIDDLE);

    // initialize attr defaults:
    titleWidget.getLabelPaint().setTextSize(PixelUtils.spToPix(DEFAULT_TITLE_WIDGET_TEXT_SIZE_SP));

    onPreInit();
    // make sure the title widget is always the topmost widget:
    layoutManager.moveToTop(titleWidget);
    if (context != null && attrs != null) {
      loadAttrs(attrs, defStyle);
    }

    layoutManager.onPostInit();
    if (renderMode == RenderMode.USE_BACKGROUND_THREAD) {
      renderThread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {

                  keepRunning = true;
                  while (keepRunning) {
                    isIdle = false;
                    synchronized (pingPong) {
                      Canvas c = pingPong.getCanvas();
                      renderOnCanvas(c);
                      pingPong.swap();
                    }
                    synchronized (renderSynch) {
                      postInvalidate();
                      // prevent this thread from becoming an orphan
                      // after the view is destroyed
                      if (keepRunning) {
                        try {
                          renderSynch.wait();
                        } catch (InterruptedException e) {
                          keepRunning = false;
                        }
                      }
                    }
                  }
                }
              });
    }
  }