Android Open Source - ShareManager Shares Graphics Builder






From Project

Back to project page ShareManager.

License

The source code is released under:

Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Red...

If you think the Android project ShareManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package share.manager.utils;
//from  w w w  .  ja  v a2  s. co  m
import java.util.ArrayList;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

import share.manager.stock.R;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;

public class SharesGraphicsBuilder {

  private static int[] COLORS = new int[] { Color.argb(100, 48, 55, 255),
      Color.argb(100, 36, 99, 4), Color.argb(100, 250, 133, 50),
      Color.argb(100, 255, 51, 51), Color.argb(100, 252, 189, 0),
      Color.argb(100, 108, 1, 122) };
  private CategorySeries mSeries = new CategorySeries("");
  private DefaultRenderer mRenderer = new DefaultRenderer();
  private GraphicalView mChartView;
  private Activity context;
  private View view;

  public SharesGraphicsBuilder(final Activity context,
      ArrayList<Integer> stockValues, ArrayList<String> names, View view) {
    this.context = context;
    this.view = view;
    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(Color.argb(0, 50, 50, 50));
    mRenderer.setChartTitleTextSize(25);
    mRenderer.setLabelsTextSize(20);
    mRenderer.setLegendTextSize(25);
    mRenderer.setStartAngle(90);
    mRenderer.setPanEnabled(false);

    for (int i = 0; i < stockValues.size(); i++) {
      mSeries.add(names.get(i) + " " + stockValues.get(i) + "%",
          stockValues.get(i));
      SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
      renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
      mRenderer.addSeriesRenderer(renderer);
    }

    LinearLayout layout = (LinearLayout) this.view
        .findViewById(R.id.chart_mine);
    mChartView = ChartFactory.getPieChartView(this.context, mSeries, mRenderer);
    layout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT));

    mChartView.repaint();
  }

  public void repaintGraph(ArrayList<Integer> stockValues,
      ArrayList<String> names) {
    mRenderer.removeAllRenderers();
    mSeries.clear();
    for (int i = 0; i < stockValues.size(); i++) {
      mSeries.add(names.get(i) + " " + stockValues.get(i) + "%",
          stockValues.get(i));
      SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
      renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
      mRenderer.addSeriesRenderer(renderer);
    }
    LinearLayout layout = (LinearLayout) this.view
        .findViewById(R.id.chart_mine);
    layout.removeAllViews();
    mChartView = ChartFactory.getPieChartView(this.context, mSeries, mRenderer);
    layout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT));
    mChartView.repaint();
  }
}




Java Source Code List

share.manager.adapters.CompanyAdapter.java
share.manager.adapters.DialogAdapter.java
share.manager.adapters.MainPagerAdapter.java
share.manager.adapters.SharesAdapter.java
share.manager.connection.ConnectionRunnable.java
share.manager.connection.ConnectionThread.java
share.manager.fragments.MineFragment.java
share.manager.fragments.PortfolioFragment.java
share.manager.fragments.SharesFragment.java
share.manager.listeners.ShareTabListener.java
share.manager.listeners.SwipeListener.java
share.manager.stock.CompanyActivity.java
share.manager.stock.MainActivity.java
share.manager.stock.ResultsActivity.java
share.manager.stock.SettingsActivity.java
share.manager.stock.ShareManager.java
share.manager.utils.CompanyGraphicsBuilder.java
share.manager.utils.FileHandler.java
share.manager.utils.GraphType.java
share.manager.utils.RESTFunction.java
share.manager.utils.ShareUtils.java
share.manager.utils.SharesGraphicsBuilder.java