Android Open Source - SDCardTrac Graph View Style






From Project

Back to project page SDCardTrac.

License

The source code is released under:

GNU General Public License

If you think the Android project SDCardTrac 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

/**
 * This file is part of GraphView./*from w ww. j a  v  a  2 s .  c o  m*/
 *
 * GraphView is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GraphView is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GraphView.  If not, see <http://www.gnu.org/licenses/lgpl.html>.
 *
 * Copyright Jonas Gehring
 */

package com.jjoe64.graphview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Paint.Align;
import android.view.ContextThemeWrapper;

/**
 * Styles for the GraphView
 * Important: Use {@link com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle} for series-specify styling
 *
 */
public class GraphViewStyle {
  private int verticalLabelsColor;
  private int horizontalLabelsColor;
  private int gridColor;
  private GridStyle gridStyle = GridStyle.BOTH;
  private float textSize;
  private int verticalLabelsWidth;
  private int numVerticalLabels;
  private int numHorizontalLabels;
  private int legendWidth;
  private int legendBorder;
  private int legendSpacing;
  private int legendMarginBottom;
  private Align verticalLabelsAlign;

  public GraphViewStyle() {
    setDefaults();
  }

  public GraphViewStyle(int vLabelsColor, int hLabelsColor, int gridColor) {
    setDefaults();
    this.verticalLabelsColor = vLabelsColor;
    this.horizontalLabelsColor = hLabelsColor;
    this.gridColor = gridColor;
  }

  public int getGridColor() {
    return gridColor;
  }
  
  public GridStyle getGridStyle() {
    return gridStyle;
  }

  public int getHorizontalLabelsColor() {
    return horizontalLabelsColor;
  }

  public int getLegendBorder() {
    return legendBorder;
  }

  public int getLegendSpacing() {
    return legendSpacing;
  }

  public int getLegendWidth() {
    return legendWidth;
  }

  public int getLegendMarginBottom() {
    return legendMarginBottom;
  }

  public int getNumHorizontalLabels() {
    return numHorizontalLabels;
  }

  public int getNumVerticalLabels() {
    return numVerticalLabels;
  }

  public float getTextSize() {
    return textSize;
  }

  public Align getVerticalLabelsAlign() {
    return verticalLabelsAlign;
  }

  public int getVerticalLabelsColor() {
    return verticalLabelsColor;
  }

  public int getVerticalLabelsWidth() {
    return verticalLabelsWidth;
  }

  private void setDefaults() {
    verticalLabelsColor = Color.WHITE;
    horizontalLabelsColor = Color.WHITE;
    gridColor = Color.DKGRAY;
    textSize = 30f;
    legendWidth = 120;
    legendBorder = 10;
    legendSpacing = 10;
    legendMarginBottom = 0;
    verticalLabelsAlign = Align.LEFT;
  }

  public void setGridStyle(GridStyle style) {
    gridStyle = style;
  }
  
  public void setGridColor(int c) {
    gridColor = c;
  }

  public void setHorizontalLabelsColor(int c) {
    horizontalLabelsColor = c;
  }

  public void setLegendBorder(int legendBorder) {
    this.legendBorder = legendBorder;
  }

  public void setLegendSpacing(int legendSpacing) {
    this.legendSpacing = legendSpacing;
  }

  public void setLegendWidth(int legendWidth) {
    this.legendWidth = legendWidth;
  }

  public void setLegendMarginBottom(int legendMarginBottom) {
    this.legendMarginBottom = legendMarginBottom;
  }

  /**
   * @param numHorizontalLabels 0 = auto
   */
  public void setNumHorizontalLabels(int numHorizontalLabels) {
    this.numHorizontalLabels = numHorizontalLabels;
  }

  /**
   * @param numVerticalLabels 0 = auto
   */
  public void setNumVerticalLabels(int numVerticalLabels) {
    this.numVerticalLabels = numVerticalLabels;
  }

  public void setTextSize(float textSize) {
    this.textSize = textSize;
  }

  public void setVerticalLabelsAlign(Align verticalLabelsAlign) {
    this.verticalLabelsAlign = verticalLabelsAlign;
  }

  public void setVerticalLabelsColor(int c) {
    verticalLabelsColor = c;
  }

  /**
   * @param verticalLabelsWidth 0 = auto
   */
  public void setVerticalLabelsWidth(int verticalLabelsWidth) {
    this.verticalLabelsWidth = verticalLabelsWidth;
  }

  /**
   * tries to get the theme's font color and use it for labels
   * @param context must be instance of ContextThemeWrapper
   */
  public void useTextColorFromTheme(Context context) {
    if (context instanceof ContextThemeWrapper) {
      TypedArray array = ((ContextThemeWrapper) context).getTheme().obtainStyledAttributes(new int[] {android.R.attr.textColorPrimary});
      int color = array.getColor(0, getVerticalLabelsColor());
      array.recycle();

      setVerticalLabelsColor(color);
      setHorizontalLabelsColor(color);
    }
  }

    /**
     * Definition which lines will be drawn in the background
     */
  public enum GridStyle {
    BOTH, VERTICAL, HORIZONTAL
  }
}




Java Source Code List

com.jjoe64.graphview.BarGraphView.java
com.jjoe64.graphview.CustomLabelFormatter.java
com.jjoe64.graphview.GraphViewDataInterface.java
com.jjoe64.graphview.GraphViewSeries.java
com.jjoe64.graphview.GraphViewStyle.java
com.jjoe64.graphview.GraphView.java
com.jjoe64.graphview.LineGraphView.java
com.jjoe64.graphview.ValueDependentColor.java
com.jjoe64.graphview.compatible.RealScaleGestureDetector.java
com.jjoe64.graphview.compatible.ScaleGestureDetector.java
com.nma.util.sdcardtrac.AlarmHelper.java
com.nma.util.sdcardtrac.BitcoinIntegration.java
com.nma.util.sdcardtrac.ChangeLogFragment.java
com.nma.util.sdcardtrac.DatabaseLoader.java
com.nma.util.sdcardtrac.DatabaseManager.java
com.nma.util.sdcardtrac.DeleteDataPreference.java
com.nma.util.sdcardtrac.DeltaCompute.java
com.nma.util.sdcardtrac.FileObserverService.java
com.nma.util.sdcardtrac.GraphActivity.java
com.nma.util.sdcardtrac.GraphFragment.java
com.nma.util.sdcardtrac.GraphTabListener.java
com.nma.util.sdcardtrac.HelpFragment.java
com.nma.util.sdcardtrac.MyExpandableListAdapter.java
com.nma.util.sdcardtrac.SQLiteHelper.java
com.nma.util.sdcardtrac.SearchableActivity.java
com.nma.util.sdcardtrac.SettingsActivity.java
com.nma.util.sdcardtrac.StorageHelper.java
com.nma.util.sdcardtrac.UsageFileObserver.java