Beispiel #1
0
  void drawPieForSpecificMonth(String month) {

    DatabaseHandler db = new DatabaseHandler(this);
    List<Finance> list = db.getmonthRecords(month);
    textView1 = (TextView) this.findViewById(R.id.textView1);

    if (databaseflag == 0) {
      if (mRenderer != null) mRenderer.removeAllRenderers();
      if (mSeries != null) mSeries.clear();
    }
    if (!list.isEmpty()) {

      databaseflag = 0;
      for (int i = 0; i < list.size(); i++) {

        Finance f = list.get(i);

        mSeries.add("" + f.getCategory(), f.getExpense());

        SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();

        renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
        mRenderer.addSeriesRenderer(renderer);

        if (mChartView != null) {
          mChartView.repaint();

          textView1.setText("");
        }
      }
    } else {
      if (mChartView != null) mChartView.repaint();
      textView1.setText("Hey you have not added any data\n\t\tfor this month");
    }
  }
Beispiel #2
0
 /**
  * The graphical representation of the round chart title.
  *
  * @param canvas the canvas to paint to
  * @param x the top left x value of the view to draw to
  * @param y the top left y value of the view to draw to
  * @param width the width of the view to draw to
  * @param paint the paint
  */
 public void drawTitle(Canvas canvas, int x, int y, int width, Paint paint) {
   if (mRenderer.isShowLabels()) {
     paint.setColor(mRenderer.getLabelsColor());
     paint.setTextAlign(Align.CENTER);
     paint.setTextSize(mRenderer.getChartTitleTextSize());
     canvas.drawText(
         mRenderer.getChartTitle(), x + width / 2, y + mRenderer.getChartTitleTextSize(), paint);
   }
 }
Beispiel #3
0
 /**
  * Calculates the current legend size.
  *
  * @param renderer the renderer
  * @param defaultHeight the default height
  * @param extraHeight the added extra height
  * @return the legend size
  */
 protected int getLegendSize(DefaultRenderer renderer, int defaultHeight, float extraHeight) {
   int legendSize = renderer.getLegendHeight();
   if (renderer.isShowLegend() && legendSize == 0) {
     legendSize = defaultHeight;
   }
   if (!renderer.isShowLegend() && renderer.isShowLabels()) {
     legendSize = (int) (renderer.getLabelsTextSize() * 4 / 3 + extraHeight);
   }
   return legendSize;
 }
Beispiel #4
0
  /**
   * Draws the chart legend.
   *
   * @param canvas the canvas to paint to
   * @param renderer the series renderer
   * @param titles the titles to go to the legend
   * @param left the left X value of the area to draw to
   * @param right the right X value of the area to draw to
   * @param y the y value of the area to draw to
   * @param width the width of the area to draw to
   * @param height the height of the area to draw to
   * @param legendSize the legend size
   * @param paint the paint to be used for drawing
   * @param calculate if only calculating the legend size
   * @return the legend height
   */
  protected int drawLegend(
      Canvas canvas,
      DefaultRenderer renderer,
      String[] titles,
      int left,
      int right,
      int y,
      int width,
      int height,
      int legendSize,
      Paint paint,
      boolean calculate) {
    float size = 32;
    if (renderer.isShowLegend()) {
      float currentX = left;
      float currentY = y + height - legendSize + size;
      paint.setTextAlign(Align.LEFT);
      paint.setTextSize(renderer.getLegendTextSize());
      int sLength = Math.min(titles.length, renderer.getSeriesRendererCount());
      for (int i = 0; i < sLength; i++) {
        final float lineSize = getLegendShapeWidth(i);
        String text = titles[i];
        if (titles.length == renderer.getSeriesRendererCount()) {
          paint.setColor(renderer.getSeriesRendererAt(i).getColor());
        } else {
          paint.setColor(Color.LTGRAY);
        }
        float[] widths = new float[text.length()];
        paint.getTextWidths(text, widths);
        float sum = 0;
        for (float value : widths) {
          sum += value;
        }
        float extraSize = lineSize + 10 + sum;
        float currentWidth = currentX + extraSize;

        if (i > 0 && getExceed(currentWidth, renderer, right, width)) {
          currentX = left;
          currentY += renderer.getLegendTextSize();
          size += renderer.getLegendTextSize();
          currentWidth = currentX + extraSize;
        }
        if (getExceed(currentWidth, renderer, right, width)) {
          float maxWidth = right - currentX - lineSize - 10;
          if (isVertical(renderer)) {
            maxWidth = width - currentX - lineSize - 10;
          }
          int nr = paint.breakText(text, true, maxWidth, widths);
          text = text.substring(0, nr) + "...";
        }
        if (!calculate) {
          drawLegendShape(canvas, renderer.getSeriesRendererAt(i), currentX, currentY, i, paint);
          drawString(canvas, text, currentX + lineSize + 5, currentY + 5, paint);
        }
        currentX += extraSize;
      }
    }
    return Math.round(size + renderer.getLegendTextSize());
  }
Beispiel #5
0
 /**
  * Builds a category renderer to use the provided colors.
  *
  * @param colors the colors
  * @return the category renderer
  */
 public DefaultRenderer buildCategoryRenderer(int[] colors) {
   DefaultRenderer renderer = new DefaultRenderer();
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   renderer.setMargins(new int[] {20, 30, 15, 0});
   for (int color : colors) {
     SimpleSeriesRenderer r = new SimpleSeriesRenderer();
     r.setColor(color);
     renderer.addSeriesRenderer(r);
   }
   return renderer;
 }
 /**
  * Creates a new graphical view.
  *
  * @param view the graphical view
  * @param chart the chart to be drawn
  */
 public TouchHandler(GraphicalView view, AbstractChart chart) {
   graphicalView = view;
   zoomR = graphicalView.getZoomRectangle();
   if (chart instanceof XYChart) {
     mRenderer = ((XYChart) chart).getRenderer();
   } else {
     mRenderer = ((RoundChart) chart).getRenderer();
   }
   if (mRenderer.isPanEnabled()) {
     mPan = new Pan(chart);
   }
   if (mRenderer.isZoomEnabled()) {
     mPinchZoom = new Zoom(chart, true, 1);
   }
 }
Beispiel #7
0
 /** Apply the tool. */
 public void apply() {
   if (mChart instanceof XYChart) {
     if (((XYChart) mChart).getDataset() == null) {
       return;
     }
     int scales = mRenderer.getScalesCount();
     if (mRenderer.isInitialRangeSet()) {
       for (int i = 0; i < scales; i++) {
         if (mRenderer.isInitialRangeSet(i)) {
           mRenderer.setRange(mRenderer.getInitialRange(i), i);
         }
       }
     } else {
       XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
       double[] range = null;
       int length = series.length;
       if (length > 0) {
         for (int i = 0; i < scales; i++) {
           range =
               new double[] {
                 MathHelper.NULL_VALUE,
                 -MathHelper.NULL_VALUE,
                 MathHelper.NULL_VALUE,
                 -MathHelper.NULL_VALUE
               };
           for (int j = 0; j < length; j++) {
             if (i == series[j].getScaleNumber()) {
               range[0] = Math.min(range[0], series[j].getMinX());
               range[1] = Math.max(range[1], series[j].getMaxX());
               range[2] = Math.min(range[2], series[j].getMinY());
               range[3] = Math.max(range[3], series[j].getMaxY());
             }
           }
           double marginX = Math.abs(range[1] - range[0]) / 40;
           double marginY = Math.abs(range[3] - range[2]) / 40;
           mRenderer.setRange(
               new double[] {
                 range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY
               },
               i);
         }
       }
     }
   } else {
     DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
     renderer.setScale(renderer.getOriginalScale());
   }
 }
  public GraphicalView getView(Context context) {
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] {12, 14, 11, 10, 19});
    values.add(new double[] {10, 9, 14, 20, 11});
    List<String[]> titles = new ArrayList<String[]>();
    titles.add(new String[] {"P1", "P2", "P3", "P4", "P5"});
    titles.add(new String[] {"Project1", "Project2", "Project3", "Project4", "Project5"});
    int[] colors = new int[] {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN};

    DefaultRenderer renderer = buildCategoryRenderer(colors);
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.rgb(222, 222, 200));
    renderer.setLabelsColor(Color.GRAY);

    return ChartFactory.getDoughnutChartView(
        context, buildMultipleCategoryDataset("Project budget", titles, values), renderer);
  }
Beispiel #9
0
 /**
  * Draws the chart background.
  *
  * @param renderer the chart renderer
  * @param canvas the canvas to paint to
  * @param x the top left x value of the view to draw to
  * @param y the top left y value of the view to draw to
  * @param width the width of the view to draw to
  * @param height the height of the view to draw to
  * @param paint the paint used for drawing
  * @param newColor if a new color is to be used
  * @param color the color to be used
  */
 protected void drawBackground(
     DefaultRenderer renderer,
     Canvas canvas,
     int x,
     int y,
     int width,
     int height,
     Paint paint,
     boolean newColor,
     int color) {
   if (renderer.isApplyBackgroundColor() || newColor) {
     if (newColor) {
       paint.setColor(color);
     } else {
       paint.setColor(renderer.getBackgroundColor());
     }
     paint.setStyle(Style.FILL);
     canvas.drawRect(x, y, x + width, y + height, paint);
   }
 }
 private View createPieChart() {
   String[] code = new String[] {"eclair", "froyo"};
   double[] distribution = {20.0, 40.0};
   int[] color = {Color.WHITE, getResources().getColor(R.color.button_signup_color)};
   CategorySeries distributionSeries = new CategorySeries("Top Blocked Number");
   for (int i = 0; i < distribution.length; i++) {
     distributionSeries.add(code[i], distribution[i]);
   }
   DefaultRenderer defaultRenderer = new DefaultRenderer();
   for (int i = 0; i < distribution.length; i++) {
     SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
     seriesRenderer.setColor(color[i]);
     seriesRenderer.setShowLegendItem(false);
     defaultRenderer.addSeriesRenderer(seriesRenderer);
   }
   defaultRenderer.setDisplayValues(false);
   defaultRenderer.setShowLabels(false);
   defaultRenderer.setPanEnabled(false);
   defaultRenderer.setZoomEnabled(false);
   /*defaultRenderer.setChartTitle("Top Blocked Number");
   defaultRenderer.setChartTitleTextSize(20F);
   defaultRenderer.setDisplayValues(true);
   */
   return ChartFactory.getPieChartView(
       getActivity().getApplicationContext(), distributionSeries, defaultRenderer);
 }
Beispiel #11
0
  @Override
  protected void onResume() {
    super.onResume();

    if (mChartView == null) {
      LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
      mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
      mRenderer.setClickEnabled(true);

      mChartView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
              if (seriesSelection == null) {
                mChartView.repaint();
              } else {
                for (int i = 0; i < mSeries.getItemCount(); i++) {
                  mRenderer
                      .getSeriesRendererAt(i)
                      .setHighlighted(i == seriesSelection.getPointIndex());
                  getcategoryofclicked = mSeries.getCategory(seriesSelection.getPointIndex());
                }
                mChartView.repaint();

                Intent intent = new Intent(getApplicationContext(), PieChartDetails.class);
                intent.putExtra("selectedCategory", getcategoryofclicked);
                intent.putExtra("selectedDate", mdate);

                startActivity(intent);
              }
              return true;
            }
          });

      layout.addView(
          mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
      if (mSeries.getItemCount() == 0)
        textView1.setText("Hey you have not added any data\n\t\tPlease add some");
    } else {
      mChartView.repaint();
    }
  }
 protected DefaultRenderer BuildCategoryRenderer(int[] colors) {
   DefaultRenderer _Renderer = new DefaultRenderer();
   _Renderer.setZoomButtonsVisible(true);
   _Renderer.setLabelsTextSize(15);
   _Renderer.setLegendTextSize(15);
   _Renderer.setLabelsColor(Color.BLUE);
   _Renderer.setMargins(new int[] {20, 30, 15, 10});
   int _Color = 0;
   for (int i = 0; i < mModelCategoryTotal.size(); i++) {
     SimpleSeriesRenderer _R = new SimpleSeriesRenderer();
     _R.setColor(colors[_Color]);
     _Renderer.addSeriesRenderer(_R);
     _Color++;
     if (_Color > colors.length) {
       _Color = 0;
     }
   }
   return _Renderer;
 }
Beispiel #13
0
  /**
   * Draws a text label.
   *
   * @param canvas the canvas
   * @param labelText the label text
   * @param renderer the renderer
   * @param prevLabelsBounds the previous rendered label bounds
   * @param centerX the round chart center on X axis
   * @param centerY the round chart center on Y axis
   * @param shortRadius the short radius for the round chart
   * @param longRadius the long radius for the round chart
   * @param currentAngle the current angle
   * @param angle the label extra angle
   * @param left the left side
   * @param right the right side
   * @param color the label color
   * @param paint the paint
   * @param line if a line to the label should be drawn
   */
  protected void drawLabel(
      Canvas canvas,
      String labelText,
      DefaultRenderer renderer,
      List<RectF> prevLabelsBounds,
      int centerX,
      int centerY,
      float shortRadius,
      float longRadius,
      float currentAngle,
      float angle,
      int left,
      int right,
      int color,
      Paint paint,
      boolean line) {
    if (renderer.isShowLabels()) {
      paint.setColor(color);
      double rAngle = Math.toRadians(90 - (currentAngle + angle / 2));
      double sinValue = Math.sin(rAngle);
      double cosValue = Math.cos(rAngle);
      int x1 = Math.round(centerX + (float) (shortRadius * sinValue));
      int y1 = Math.round(centerY + (float) (shortRadius * cosValue));
      int x2 = Math.round(centerX + (float) (longRadius * sinValue));
      int y2 = Math.round(centerY + (float) (longRadius * cosValue));

      float size = renderer.getLabelsTextSize();
      float extra = Math.max(size / 2, 10);
      paint.setTextAlign(Align.LEFT);
      if (x1 > x2) {
        extra = -extra;
        paint.setTextAlign(Align.RIGHT);
      }
      float xLabel = x2 + extra;
      float yLabel = y2;
      float width = right - xLabel;
      if (x1 > x2) {
        width = xLabel - left;
      }
      labelText = getFitText(labelText, width, paint);
      float widthLabel = paint.measureText(labelText);
      boolean okBounds = false;
      while (!okBounds && line) {
        boolean intersects = false;
        int length = prevLabelsBounds.size();
        for (int j = 0; j < length && !intersects; j++) {
          RectF prevLabelBounds = prevLabelsBounds.get(j);
          if (prevLabelBounds.intersects(xLabel, yLabel, xLabel + widthLabel, yLabel + size)) {
            intersects = true;
            yLabel = Math.max(yLabel, prevLabelBounds.bottom);
          }
        }
        okBounds = !intersects;
      }

      if (line) {
        y2 = (int) (yLabel - size / 2);
        canvas.drawLine(x1, y1, x2, y2, paint);
        canvas.drawLine(x2, y2, x2 + extra, y2, paint);
      } else {
        paint.setTextAlign(Align.CENTER);
      }
      canvas.drawText(labelText, xLabel, yLabel, paint);
      if (line) {
        prevLabelsBounds.add(new RectF(xLabel, yLabel, xLabel + widthLabel, yLabel + size));
      }
    }
  }
  /**
   * Handles the touch event.
   *
   * @param event the touch event
   */
  public boolean handleTouch(MotionEvent event) {
    int action = event.getAction();
    if (mRenderer != null && action == MotionEvent.ACTION_MOVE) {
      if (oldX >= 0 || oldY >= 0) {
        float newX = event.getX(0);
        float newY = event.getY(0);
        if (event.getPointerCount() > 1
            && (oldX2 >= 0 || oldY2 >= 0)
            && mRenderer.isZoomEnabled()) {
          float newX2 = event.getX(1);
          float newY2 = event.getY(1);
          float newDeltaX = Math.abs(newX - newX2);
          float newDeltaY = Math.abs(newY - newY2);
          float oldDeltaX = Math.abs(oldX - oldX2);
          float oldDeltaY = Math.abs(oldY - oldY2);
          float zoomRate = 1;

          float tan1 = Math.abs(newY - oldY) / Math.abs(newX - oldX);
          float tan2 = Math.abs(newY2 - oldY2) / Math.abs(newX2 - oldX2);
          if (tan1 <= 0.25 && tan2 <= 0.25) {
            // horizontal pinch zoom, |deltaY| / |deltaX| is [0 ~ 0.25], 0.25 is
            // the approximate value of tan(PI / 12)
            zoomRate = newDeltaX / oldDeltaX;
            applyZoom(zoomRate, Zoom.ZOOM_AXIS_X);
          } else if (tan1 >= 3.73 && tan2 >= 3.73) {
            // pinch zoom vertically, |deltaY| / |deltaX| is [3.73 ~ infinity],
            // 3.732 is the approximate value of tan(PI / 2 - PI / 12)
            zoomRate = newDeltaY / oldDeltaY;
            applyZoom(zoomRate, Zoom.ZOOM_AXIS_Y);
          } else {
            // pinch zoom diagonally
            if (Math.abs(newX - oldX) >= Math.abs(newY - oldY)) {
              zoomRate = newDeltaX / oldDeltaX;
            } else {
              zoomRate = newDeltaY / oldDeltaY;
            }
            applyZoom(zoomRate, Zoom.ZOOM_AXIS_XY);
          }
          oldX2 = newX2;
          oldY2 = newY2;
        } else if (mRenderer.isPanEnabled()) {
          mPan.apply(oldX, oldY, newX, newY);
          oldX2 = 0;
          oldY2 = 0;
        }
        oldX = newX;
        oldY = newY;
        graphicalView.repaint();
        return true;
      }
    } else if (action == MotionEvent.ACTION_DOWN) {
      oldX = event.getX(0);
      oldY = event.getY(0);
      if (mRenderer != null && mRenderer.isZoomEnabled() && zoomR.contains(oldX, oldY)) {
        if (oldX < zoomR.left + zoomR.width() / 3) {
          graphicalView.zoomIn();
        } else if (oldX < zoomR.left + zoomR.width() * 2 / 3) {
          graphicalView.zoomOut();
        } else {
          graphicalView.zoomReset();
        }
        return true;
      }
    } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
      oldX = 0;
      oldY = 0;
      oldX2 = 0;
      oldY2 = 0;
      if (action == MotionEvent.ACTION_POINTER_UP) {
        oldX = -1;
        oldY = -1;
      }
    }
    return !mRenderer.isClickEnabled();
  }
Beispiel #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pie_chart);
    // getActionBar().setDisplayHomeAsUpEnabled(true);

    final Context mContext = this;
    mRenderer.setApplyBackgroundColor(true);
    // mRenderer.setBackgroundColor(Color.argb(100, 80, 80, 50));
    mRenderer.setChartTitleTextSize(15);
    mRenderer.setLabelsTextSize(20);
    mRenderer.setLabelsColor(color.black);
    mRenderer.setDisplayValues(true);
    mRenderer.setLabelsColor(Color.BLACK);
    mRenderer.setLegendTextSize(20);
    mRenderer.setShowLabels(true);
    mRenderer.setMargins(new int[] {20, 30, 15, 0});
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(180);

    Calendar d = new GregorianCalendar();

    int yr = d.get(Calendar.YEAR);

    if (yr > 99) {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.MONTH) + "/20" + (yr % 100);
    } else {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.DAY_OF_MONTH) + "/19" + (yr % 100);
    }
    System.out.println("date is " + mdate);
    drawPieForSpecificDate();
    editText_specificDate = (EditText) this.findViewById(R.id.editText_specificDate);
    editText_specificDate.setCursorVisible(false);
    editText_specificDate.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // custom dialog
            flag = 1;

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog datePickerDialog =
                new DatePickerDialog(mContext, PieChart_lower.this, year, month, day);

            datePickerDialog.show();
            flag = 1;
          }
        }); // button_specificDate setListener

    if (flag == 1) drawPieForSpecificDate();

    Button button_specificMonth = (Button) this.findViewById(R.id.button_specificMonth);
    alert = new AlertDialog.Builder(this);

    button_specificMonth.setVisibility(View.GONE);
  }
    private void drawChart() {
      DefaultRenderer render = new DefaultRenderer();

      CategorySeries incomeSeries = getDataSet();

      for (int i = 0; i < incomeSeries.getItemCount(); i++) {
        SimpleSeriesRenderer incomeSeriesRenderer = new SimpleSeriesRenderer();
        incomeSeriesRenderer.setColor(GraphsHelper.getColorCode(i));
        render.addSeriesRenderer(incomeSeriesRenderer);
      }

      render.setInScroll(true);
      render.setPanEnabled(true);
      render.setClickEnabled(false);
      render.setChartTitleTextSize(26);
      render.setShowLabels(true);
      render.setShowLegend(true);
      render.setShowGrid(true);
      render.setBackgroundColor(Color.BLACK);
      render.setLabelsTextSize(26);
      render.setLabelsColor(Color.BLACK);
      render.setLegendTextSize(26);
      render.setZoomButtonsVisible(true);

      GraphicalView chartView;

      chartView = ChartFactory.getPieChartView(getActivity(), getDataSet(), render);

      LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.dashboard_chart_layout);
      layout.removeAllViews();
      layout.addView(
          chartView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
    }
Beispiel #17
0
  /** Apply the zoom. */
  public void apply(int zoom_axis) {
    if (mChart instanceof XYChart) {
      int scales = mRenderer.getScalesCount();
      for (int i = 0; i < scales; i++) {
        double[] range = getRange(i);
        checkRange(range, i);
        double[] limits = mRenderer.getZoomLimits();

        double centerX = (range[0] + range[1]) / 2;
        double centerY = (range[2] + range[3]) / 2;
        double newWidth = range[1] - range[0];
        double newHeight = range[3] - range[2];
        double newXMin = centerX - newWidth / 2;
        double newXMax = centerX + newWidth / 2;
        double newYMin = centerY - newHeight / 2;
        double newYMax = centerY + newHeight / 2;

        // if already reached last zoom, then it will always set to reached
        if (i == 0) {
          limitsReachedX = limits != null && (newXMin <= limits[0] || newXMax >= limits[1]);
          limitsReachedY = limits != null && (newYMin <= limits[2] || newYMax >= limits[3]);
        }

        if (mZoomIn) {
          if (mRenderer.isZoomXEnabled()
              && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
            if (limitsReachedX && mZoomRate < 1) {
              // ignore pinch zoom out once reached X limit
            } else {
              newWidth /= mZoomRate;
            }
          }

          if (mRenderer.isZoomYEnabled()
              && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
            if (limitsReachedY && mZoomRate < 1) {
            } else {
              newHeight /= mZoomRate;
            }
          }
        } else {
          if (mRenderer.isZoomXEnabled()
              && !limitsReachedX
              && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
            newWidth *= mZoomRate;
          }

          if (mRenderer.isZoomYEnabled()
              && !limitsReachedY
              && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
            newHeight *= mZoomRate;
          }
        }
        if (mRenderer.isZoomXEnabled() && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
          newXMin = centerX - newWidth / 2;
          newXMax = centerX + newWidth / 2;
          setXRange(newXMin, newXMax, i);
        }
        if (mRenderer.isZoomYEnabled() && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
          newYMin = centerY - newHeight / 2;
          newYMax = centerY + newHeight / 2;
          setYRange(newYMin, newYMax, i);
        }
      }
    } else {
      DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
      if (mZoomIn) {
        renderer.setScale(renderer.getScale() * mZoomRate);
      } else {
        renderer.setScale(renderer.getScale() / mZoomRate);
      }
    }
    notifyZoomListeners(new ZoomEvent(mZoomIn, mZoomRate));
  }
Beispiel #18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_room_detail);

    Bundle Title = getIntent().getExtras();
    if (Title != null) {
      mPlace = Title.getString(Constants.PLACE);
    }

    mRoomNameView = (TextView) findViewById(R.id.detail_roomname);
    mSeatnumbnerView = (TextView) findViewById(R.id.detail_seatnumber);
    mDescriptionView = (TextView) findViewById(R.id.detail_description);
    mImageView = (ImageView) findViewById(R.id.detailed_image);
    mHistoryButton = (Button) findViewById(R.id.history_button);

    mPersistanceManager = new PersistanceManager(this);
    r = mPersistanceManager.getCurrentRoom();

    mRoomNameView.setText(r.getName());
    mSeatnumbnerView.setText(r.getNumberOfSeat());
    mDescriptionView.setText(r.getDescription());

    // set the achartengine pie chart parameters, including color, lable size as well as items shown
    // options
    double taken = Double.parseDouble(r.getFullness());
    double notTaken = 100 - taken;
    double[] PIECHARTVALUES = new double[] {taken, notTaken};

    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
    mRenderer.setChartTitleTextSize(20);
    mRenderer.setLabelsTextSize(50);
    mRenderer.setShowLegend(false);
    mRenderer.setShowTickMarks(false);
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(90);

    // show the percentage
    for (int i = 0; i < PIECHARTVALUES.length; i++) {
      mSeries.add(NAME_LIST[i] + " " + PIECHARTVALUES[i] + "%", PIECHARTVALUES[i]);
      SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
      renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
      mRenderer.addSeriesRenderer(renderer);
    }

    if (mChartView != null) {
      mChartView.repaint();
    }

    // load the pie chart layout with the parameters in mRenderer and mSeries we set before.
    LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
    mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
    mRenderer.setClickEnabled(true);
    mRenderer.setSelectableBuffer(10);

    layout.addView(
        mChartView,
        new AbsListView.LayoutParams(
            AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));

    if (!r.getImage().equals("")) {
      Ion.with(mImageView)
          .load(r.getImage())
          .setCallback(
              new FutureCallback<ImageView>() {
                @Override
                public void onCompleted(Exception e, ImageView result) {
                  if (e == null) {
                    // yay

                  } else {
                    // log the error information , helping to check. Then keep running app without
                    // image
                    Log.d(TAG, "image failed to load " + e.toString());
                  }
                }
              });
    }

    // set the extre before going to history activity, helping to save which building and which room
    // to load.
    mHistoryButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(), HistoryActivity.class);
            intent.putExtra(Constants.ROOM, r.getName());
            intent.putExtra(Constants.PLACE, mPlace);
            startActivity(intent);
          }
        });
  }