Search in sources :

Example 1 with ChartBuilder

use of com.ichi2.charts.ChartBuilder in project Anki-Android by Ramblurr.

the class ChartBuilder method onCreate.

// public void setRenderer(int type, int row) {
// Resources res = getResources();
// XYSeriesRenderer renderer = new XYSeriesRenderer();
// if (type <= 2) {
// switch (row) {
// case 0:
// renderer.setColor(res.getColor(R.color.statistics_due_young_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_due_mature_cards));
// break;
// case 2:
// // renderer.setColor(res.getColor(R.color.statistics_due_failed_cards));
// break;
// }
// } else if (type == 3) {
// switch (row) {
// case 0:
// // renderer.setColor(res.getColor(R.color.statistics_reps_new_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_reps_young_cards));
// break;
// case 2:
// renderer.setColor(res.getColor(R.color.statistics_reps_mature_cards));
// break;
// }
// } else {
// renderer.setColor(res.getColor(R.color.statistics_default));
// }
// mRenderer.addSeriesRenderer(renderer);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "ChartBuilder.OnCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    restorePreferences();
    Resources res = getResources();
    Stats stats = Stats.currentStats();
    if (stats != null) {
        mSeriesList = stats.getSeriesList();
        mMeta = stats.getMetaInfo();
    } else if (savedInstanceState != null) {
        int len = savedInstanceState.getInt("seriesListLen");
        mSeriesList = new double[len][];
        for (int i = 0; i < len; i++) {
            mSeriesList[i] = (double[]) savedInstanceState.getSerializable("seriesList" + i);
        }
        mMeta = (Object[]) savedInstanceState.getSerializable("meta");
    } else {
        finish();
    }
    String title = res.getString((Integer) mMeta[1]);
    boolean backwards = (Boolean) mMeta[2];
    int[] valueLabels = (int[]) mMeta[3];
    int[] barColors = (int[]) mMeta[4];
    int[] axisTitles = (int[]) mMeta[5];
    String subTitle = (String) mMeta[6];
    if (mSeriesList == null || mSeriesList[0].length < 2) {
        Log.i(AnkiDroidApp.TAG, "ChartBuilder - Data variable empty, closing chartbuilder");
        finish();
        return;
    }
    if (mFullScreen) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    View mainView = getLayoutInflater().inflate(R.layout.statistics, null);
    setContentView(mainView);
    mainView.setBackgroundColor(Color.WHITE);
    mTitle = (TextView) findViewById(R.id.statistics_title);
    if (mChartView == null) {
        if (mFullScreen) {
            mTitle.setText(title);
            mTitle.setTextColor(Color.BLACK);
        } else {
            setTitle(title);
            AnkiDroidApp.getCompat().setSubtitle(this, subTitle);
            mTitle.setVisibility(View.GONE);
        }
        for (int i = 1; i < mSeriesList.length; i++) {
            XYSeries series = new XYSeries(res.getString(valueLabels[i - 1]));
            for (int j = 0; j < mSeriesList[i].length; j++) {
                series.add(mSeriesList[0][j], mSeriesList[i][j]);
            }
            mDataset.addSeries(series);
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setColor(res.getColor(barColors[i - 1]));
            mRenderer.addSeriesRenderer(renderer);
        }
        if (mSeriesList.length == 1) {
            mRenderer.setShowLegend(false);
        }
        if (backwards) {
            mPan = new double[] { mSeriesList[0][0] - 0.5, 0.5 };
        } else {
            mPan = new double[] { -0.5, mSeriesList[0][mSeriesList[0].length - 1] + 0.5 };
        }
        mRenderer.setLegendTextSize(17);
        mRenderer.setBarSpacing(0.4);
        mRenderer.setLegendHeight(60);
        mRenderer.setAxisTitleTextSize(17);
        mRenderer.setLabelsTextSize(17);
        mRenderer.setXAxisMin(mPan[0]);
        mRenderer.setXAxisMax(mPan[1]);
        mRenderer.setYAxisMin(0);
        mRenderer.setGridColor(Color.LTGRAY);
        mRenderer.setShowGrid(true);
        mRenderer.setXTitle(res.getStringArray(R.array.due_x_axis_title)[axisTitles[0]]);
        mRenderer.setYTitle(res.getString(axisTitles[1]));
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setYLabelsColor(0, Color.BLACK);
        mRenderer.setYLabelsAngle(-90);
        mRenderer.setXLabelsColor(Color.BLACK);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.CENTER);
        mRenderer.setZoomEnabled(false, false);
        mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        mRenderer.setAntialiasing(true);
        mRenderer.setPanEnabled(true, false);
        mRenderer.setPanLimits(mPan);
        mChartView = ChartFactory.getBarChartView(this, mDataset, mRenderer, BarChart.Type.STACKED);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        mChartView.repaint();
    }
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mChartView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}
Also used : XYSeries(org.achartengine.model.XYSeries) LayoutParams(android.view.ViewGroup.LayoutParams) GestureDetector(android.view.GestureDetector) View(android.view.View) GraphicalView(org.achartengine.GraphicalView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Stats(com.ichi2.libanki.Stats) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

Resources (android.content.res.Resources)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Stats (com.ichi2.libanki.Stats)1 GraphicalView (org.achartengine.GraphicalView)1 XYSeries (org.achartengine.model.XYSeries)1 XYSeriesRenderer (org.achartengine.renderer.XYSeriesRenderer)1