1. sbgapps
  2. HoloGraphLibrary

Commits

StephaneBg  committed 4b79b6c

Improved performances by removing object allocations.

  • Participants
  • Parent commits 7fc65f9
  • Branches master

Comments (0)

Files changed (7)

File HoloGraphLibrary/res/values/attrs.xml

View file
     </declare-styleable>
 
     <declare-styleable name="BarGraph">
+        <attr name="axisColor" format="color"/>
         <attr name="orientation" format="enum">
             <enum name="horizontal" value="0"/>
             <enum name="vertical" value="1"/>

File HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java

View file
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.graphics.RectF;
 import android.graphics.Region;
 import android.graphics.drawable.NinePatchDrawable;
 import android.util.AttributeSet;
     private boolean mShowAxis = true;
     private int mSelectedIndex = -1;
     private OnBarClickedListener mListener;
-    private Bitmap mFullImage;
-    private boolean mShouldUpdate = false;
+    private int mAxisColor;
 
     public BarGraph(Context context) {
         this(context, null);
     }
-    
+
     public BarGraph(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
 
         TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BarGraph);
         mOrientation = a.getInt(R.styleable.BarGraph_orientation, ORIENTATION_VERTICAL);
+        mAxisColor = a.getColor(R.styleable.BarGraph_axisColor, Color.LTGRAY);
     }
 
-    public void setShowBarText(boolean show){
+    public void setShowBarText(boolean show) {
         mShowBarText = show;
     }
-    
-    public void setShowAxis(boolean show){
+
+    public void setShowAxis(boolean show) {
         mShowAxis = show;
     }
-    
-    public void setBars(ArrayList<Bar> points){
+
+    public void setBars(ArrayList<Bar> points) {
         this.mBars = points;
-        mShouldUpdate = true;
         postInvalidate();
     }
-    
-    public ArrayList<Bar> getBars(){
+
+    public ArrayList<Bar> getBars() {
         return this.mBars;
     }
 
-    public void onDraw(Canvas ca) {
-    	
-        if (mFullImage == null || mShouldUpdate) {
-            final Resources resources = getContext().getResources();
-
-            mFullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
-            Canvas canvas = new Canvas(mFullImage);
-            canvas.drawColor(Color.TRANSPARENT);
-            NinePatchDrawable popup = (NinePatchDrawable)this.getResources().getDrawable(R.drawable.popup_black);
-            
-            float maxValue = 0;
-            float padding = 7 * getContext().getResources().getDisplayMetrics().density;
-            float bottomPadding = 30 * resources.getDisplayMetrics().density;
-            
-            float usableHeight;
-            if (mShowBarText) {
-                this.mPaint.setTextSize(VALUE_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
-                this.mPaint.getTextBounds("$", 0, 1, mTextRect);
-                usableHeight = getHeight()-bottomPadding-Math.abs(mTextRect.top-mTextRect.bottom)
-                        -24 * resources.getDisplayMetrics().density;
-            } else {
-                usableHeight = getHeight()-bottomPadding;
+    public void setAxisColor(int axisColor) {
+        mAxisColor = axisColor;
+    }
+
+    public void onDraw(Canvas canvas) {
+        final Resources resources = getContext().getResources();
+
+        canvas.drawColor(Color.TRANSPARENT);
+        NinePatchDrawable popup = (NinePatchDrawable) this.getResources().getDrawable(R.drawable.popup_black);
+
+        float maxValue = 0;
+        float padding = 7 * getContext().getResources().getDisplayMetrics().density;
+        float bottomPadding = 30 * resources.getDisplayMetrics().density;
+
+        float usableHeight;
+        if (mShowBarText) {
+            this.mPaint.setTextSize(VALUE_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
+            this.mPaint.getTextBounds("$", 0, 1, mTextRect);
+            usableHeight = getHeight() - bottomPadding - Math.abs(mTextRect.top - mTextRect.bottom)
+                    - 24 * resources.getDisplayMetrics().density;
+        } else {
+            usableHeight = getHeight() - bottomPadding;
+        }
+
+        // Draw x-axis line
+        if (mShowAxis) {
+            mPaint.setColor(mAxisColor);
+            mPaint.setStrokeWidth(2 * resources.getDisplayMetrics().density);
+            mPaint.setAntiAlias(true);
+            canvas.drawLine(0,
+                    getHeight() - bottomPadding + 10 * resources.getDisplayMetrics().density,
+                    getWidth(),
+                    getHeight() - bottomPadding + 10 * resources.getDisplayMetrics().density, mPaint);
+        }
+        float barWidth = (getWidth() - (padding * 2) * mBars.size()) / mBars.size();
+
+        // Maximum y value = sum of all values.
+        for (final Bar bar : mBars) {
+            if (bar.getValue() > maxValue) {
+                maxValue = bar.getValue();
             }
-             
-            // Draw x-axis line
-            if (mShowAxis){
-                mPaint.setColor(Color.BLACK);
-                mPaint.setStrokeWidth(2 * resources.getDisplayMetrics().density);
-                mPaint.setAlpha(50);
-                mPaint.setAntiAlias(true);
-                canvas.drawLine(0,
-                        getHeight()-bottomPadding+10* resources.getDisplayMetrics().density,
-                        getWidth(),
-                        getHeight()-bottomPadding+10* resources.getDisplayMetrics().density, mPaint);
+        }
+        if (maxValue == 0) {
+            maxValue = 1;
+        }
+
+        int count = 0;
+        SparseArray<Float> valueTextSizes = new SparseArray<Float>();
+        for (final Bar bar : mBars) {
+            // Set bar bounds
+            int left = (int) ((padding * 2) * count + padding + barWidth * count);
+            int top = (int) (getHeight() - bottomPadding - (usableHeight * (bar.getValue() / maxValue)));
+            int right = (int) ((padding * 2) * count + padding + barWidth * (count + 1));
+            int bottom = (int) (getHeight() - bottomPadding);
+            mBoundsRect.set(left, top, right, bottom);
+
+            // Draw bar
+            if (count == mSelectedIndex && null != mListener) {
+                this.mPaint.setColor(bar.getSelectedColor());
+            } else {
+                this.mPaint.setColor(bar.getColor());
             }
-            float barWidth = (getWidth() - (padding*2)*mBars.size())/mBars.size();
+            canvas.drawRect(mBoundsRect, this.mPaint);
 
-            // Maximum y value = sum of all values.
-            for (final Bar bar : mBars) {
-                if (bar.getValue() > maxValue) {
-                    maxValue = bar.getValue();
+            // Create selection region
+            Path p = bar.getPath();
+            p.reset();
+            p.addRect(mBoundsRect.left,
+                    mBoundsRect.top,
+                    mBoundsRect.right,
+                    mBoundsRect.bottom,
+                    Path.Direction.CW);
+            bar.getRegion().set(mBoundsRect.left,
+                    mBoundsRect.top,
+                    mBoundsRect.right,
+                    mBoundsRect.bottom);
+
+            // Draw x-axis label text
+            if (mShowAxis) {
+                this.mPaint.setColor(bar.getLabelColor());
+                this.mPaint.setTextSize(AXIS_LABEL_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
+                float textWidth = this.mPaint.measureText(bar.getName());
+                while (right - left + (padding * LABEL_PADDING_MULTIPLIER) < textWidth) {
+                    //decrease text size to fit and not overlap with other labels.
+                    this.mPaint.setTextSize(this.mPaint.getTextSize() - 1);
+                    textWidth = this.mPaint.measureText(bar.getName());
                 }
+                int x = (int) (((mBoundsRect.left + mBoundsRect.right) / 2) - (textWidth / 2));
+                int y = (int) (getHeight() - 3 * resources.getDisplayMetrics().scaledDensity);
+                canvas.drawText(bar.getName(), x, y, this.mPaint);
             }
-            if (maxValue == 0) {
-                maxValue = 1;
-            }
-            
-            int count = 0;
-            SparseArray<Float> valueTextSizes = new SparseArray<Float>();
-            for (final Bar bar : mBars) {
-                // Set bar bounds
-                int left = (int)((padding*2)*count + padding + barWidth*count);
-                int top = (int)(getHeight()-bottomPadding-(usableHeight*(bar.getValue()/maxValue)));
-                int right = (int)((padding*2)*count + padding + barWidth*(count+1));
-                int bottom = (int)(getHeight()-bottomPadding);
-                mBoundsRect.set(left, top, right, bottom);
-
-                // Draw bar
-                if(count == mSelectedIndex && null != mListener) {
-                    this.mPaint.setColor(bar.getSelectedColor());
-                }
-                else {
-                    this.mPaint.setColor(bar.getColor());
-                }
-                canvas.drawRect(mBoundsRect, this.mPaint);
-
-                // Create selection region
-                bar.getPath().reset();
-                bar.getPath().addRect(new RectF(mBoundsRect.left,
-                                mBoundsRect.top,
-                                mBoundsRect.right,
-                                mBoundsRect.bottom),
-                        Path.Direction.CW
-                );
-                bar.getRegion().set(mBoundsRect.left,
-                        mBoundsRect.top,
-                        mBoundsRect.right,
-                        mBoundsRect.bottom);
-
-                // Draw x-axis label text
-                if (mShowAxis){
-                    this.mPaint.setColor(bar.getLabelColor());
-                    this.mPaint.setTextSize(AXIS_LABEL_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
-                    float textWidth = this.mPaint.measureText(bar.getName());
-                    while (right - left + (padding *LABEL_PADDING_MULTIPLIER)< textWidth) {
-                        //decrease text size to fit and not overlap with other labels.
-                        this.mPaint.setTextSize(this.mPaint.getTextSize() -  1);
-                        textWidth = this.mPaint.measureText(bar.getName());
-                    }
-                    int x = (int)(((mBoundsRect.left+ mBoundsRect.right)/2)-(textWidth/2));
-                    int y = (int) (getHeight()-3 * resources.getDisplayMetrics().scaledDensity);
-                    canvas.drawText(bar.getName(), x, y, this.mPaint);
-                }
 
-                // Draw value text
-                if (mShowBarText){
-                    this.mPaint.setTextSize(VALUE_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
-                    this.mPaint.setColor(Color.WHITE);
-                    this.mPaint.getTextBounds(bar.getValueString(), 0, 1, mTextRect);
-                    
-                    int boundLeft = (int) (((mBoundsRect.left+ mBoundsRect.right)/2)
-                            -(this.mPaint.measureText(bar.getValueString())/2)-10 * resources.getDisplayMetrics().density);
-                    int boundTop = (int) (mBoundsRect.top+(mTextRect.top-mTextRect.bottom)
-                            -18 * resources.getDisplayMetrics().density);
-                    int boundRight = (int)(((mBoundsRect.left+ mBoundsRect.right)/2)
-                            +(this.mPaint.measureText(bar.getValueString())/2)
-                            +10 * resources.getDisplayMetrics().density);
-
-                    if (boundLeft < mBoundsRect.left) boundLeft = mBoundsRect.left - ((int)padding /2);//limit popup width to bar width
-                    if (boundRight > mBoundsRect.right)boundRight = mBoundsRect.right + ((int) padding /2);
-
-                    popup.setBounds(boundLeft, boundTop, boundRight, mBoundsRect.top);
-                    popup.draw(canvas);
-
-                    if (0 > valueTextSizes.indexOfKey(bar.getValueString().length())) {
-                        //check cache to see if we've done this calculation before
-                        while (this.mPaint.measureText(bar.getValueString()) > boundRight - boundLeft)
-                            this.mPaint.setTextSize(this.mPaint.getTextSize() - (float)1);
-                        valueTextSizes.put(bar.getValueString().length(), mPaint.getTextSize());
-                    }
-                    else {
-                        this.mPaint.setTextSize(valueTextSizes.get(bar.getValueString().length()));
-                    }
-                    canvas.drawText(bar.getValueString(),
-                            (int) (((mBoundsRect.left + mBoundsRect.right) / 2)
-                                    - (this.mPaint.measureText(bar.getValueString())) / 2),
-                            mBoundsRect.top - (mBoundsRect.top - boundTop) / 2f
-                                    + (float) Math.abs(mTextRect.top - mTextRect.bottom) / 2f * 0.7f,
-                            this.mPaint
-                    );
+            // Draw value text
+            if (mShowBarText) {
+                this.mPaint.setTextSize(VALUE_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
+                this.mPaint.setColor(Color.WHITE);
+                this.mPaint.getTextBounds(bar.getValueString(), 0, 1, mTextRect);
+
+                int boundLeft = (int) (((mBoundsRect.left + mBoundsRect.right) / 2)
+                        - (this.mPaint.measureText(bar.getValueString()) / 2) - 10 * resources.getDisplayMetrics().density);
+                int boundTop = (int) (mBoundsRect.top + (mTextRect.top - mTextRect.bottom)
+                        - 18 * resources.getDisplayMetrics().density);
+                int boundRight = (int) (((mBoundsRect.left + mBoundsRect.right) / 2)
+                        + (this.mPaint.measureText(bar.getValueString()) / 2)
+                        + 10 * resources.getDisplayMetrics().density);
+
+                if (boundLeft < mBoundsRect.left)
+                    boundLeft = mBoundsRect.left - ((int) padding / 2);//limit popup width to bar width
+                if (boundRight > mBoundsRect.right)
+                    boundRight = mBoundsRect.right + ((int) padding / 2);
+
+                popup.setBounds(boundLeft, boundTop, boundRight, mBoundsRect.top);
+                popup.draw(canvas);
+
+                if (0 > valueTextSizes.indexOfKey(bar.getValueString().length())) {
+                    //check cache to see if we've done this calculation before
+                    while (this.mPaint.measureText(bar.getValueString()) > boundRight - boundLeft)
+                        this.mPaint.setTextSize(this.mPaint.getTextSize() - (float) 1);
+                    valueTextSizes.put(bar.getValueString().length(), mPaint.getTextSize());
+                } else {
+                    this.mPaint.setTextSize(valueTextSizes.get(bar.getValueString().length()));
                 }
-                count++;
+                canvas.drawText(bar.getValueString(),
+                        (int) (((mBoundsRect.left + mBoundsRect.right) / 2)
+                                - (this.mPaint.measureText(bar.getValueString())) / 2),
+                        mBoundsRect.top - (mBoundsRect.top - boundTop) / 2f
+                                + (float) Math.abs(mTextRect.top - mTextRect.bottom) / 2f * 0.7f,
+                        this.mPaint
+                );
             }
-            mShouldUpdate = false;
+            count++;
         }
-        
-        ca.drawBitmap(mFullImage, 0, 0, null);
     }
 
     @Override
         Point point = new Point();
         point.x = (int) event.getX();
         point.y = (int) event.getY();
-        
+
         int count = 0;
-        for (Bar bar : mBars){
+        for (Bar bar : mBars) {
             Region r = new Region();
             r.setPath(bar.getPath(), bar.getRegion());
             switch (event.getAction()) {
                 case MotionEvent.ACTION_DOWN:
                     if (r.contains(point.x, point.y)) {
                         mSelectedIndex = count;
-                        mShouldUpdate = true;
                         postInvalidate();
                     }
                     break;
                 case MotionEvent.ACTION_UP:
-                    if (r.contains(point.x, point.y) && null != mListener){
-                        if (mSelectedIndex > -1){
+                    if (r.contains(point.x, point.y) && null != mListener) {
+                        if (mSelectedIndex > -1) {
                             mListener.onClick(mSelectedIndex);
                         }
                         mSelectedIndex = -1;
                     }
-                    mShouldUpdate = true;
                     postInvalidate();
                     break;
                 case MotionEvent.ACTION_CANCEL:
         }
         return true;
     }
-    
-    @Override
-    protected void onDetachedFromWindow() {
-    	if(mFullImage != null)
-    		mFullImage.recycle();
-    	
-    	super.onDetachedFromWindow();
-    }
-    
+
     public void setOnBarClickedListener(OnBarClickedListener listener) {
         this.mListener = listener;
     }
-    
+
     public interface OnBarClickedListener {
         abstract void onClick(int index);
     }

File HoloGraphLibrary/src/com/echo/holographlibrary/LineGraph.java

View file
 
 import android.content.Context;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.Path.Direction;
 import android.graphics.Point;
-import android.graphics.PorterDuffXfermode;
 import android.graphics.Region;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 
 public class LineGraph extends View {
 
-	private static final int DEFAULT_PADDING = 10;
+    private static final int DEFAULT_PADDING = 10;
     private final int dipPadding;
     private final int mFillColor;
     private final float mStrokeWidth;
     private final int mStrokeSpacing;
-	private ArrayList<Line> lines = new ArrayList<Line>();
-	private Paint paint = new Paint();
-	private float minY = 0, minX = 0;
-	private float maxY = 0, maxX = 0;
-	private double rangeYRatio = 0;
-	private double rangeXRatio = 0;
-	private boolean isMaxXUserSet = false;
-	private int lineToFill = -1;
-	private int indexSelected = -1;
-	private OnPointClickedListener listener;
-	private Bitmap fullImage;
-	private boolean shouldUpdate = false;
-	// since this is a new addition, it has to default to false to be backwards compatible
-	private boolean isUsingDips;
+    private ArrayList<Line> lines = new ArrayList<Line>();
+    private Paint mPaint = new Paint();
+    private float minY = 0, minX = 0;
+    private float maxY = 0, maxX = 0;
+    private double rangeYRatio = 0;
+    private double rangeXRatio = 0;
+    private boolean isMaxXUserSet = false;
+    private int lineToFill = -1;
+    private int mSelectedIndex = -1;
+    private OnPointClickedListener mListener;
+    // since this is a new addition, it has to default to false to be backwards compatible
+    private boolean isUsingDips;
     private Path mPath = new Path();
 
-	public LineGraph(Context context){
-		this(context, null);
-	}
-	
-	public LineGraph(Context context, AttributeSet attrs) {
-		this(context, attrs, 0);
-	}
+    public LineGraph(Context context) {
+        this(context, null);
+    }
+
+    public LineGraph(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
 
     public LineGraph(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
     }
 
     public boolean isUsingDips() {
-		return isUsingDips;
-	}
-
-	public void setUsingDips(boolean treatSizesAsDips) {
-		this.isUsingDips = treatSizesAsDips;
-	}
-
-	public void removeAllLines(){
-		while (lines.size() > 0){
-			lines.remove(0);
-		}
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	
-	public void addLine(Line line) {
-		lines.add(line);
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	public void addPointToLine(int lineIndex, double x, double y){
-		addPointToLine(lineIndex, (float) x, (float) y);
-	}
-	public void addPointToLine(int lineIndex, float x, float y){
-		LinePoint p = new LinePoint(x, y);
-
-		addPointToLine(lineIndex, p);
-	}
-	
-	public double getRangeYRatio(){
-		return rangeYRatio;
-	}
-	
-	public void setRangeYRatio(double rr){
-		this.rangeYRatio = rr;
-	}
-	public double getRangeXRatio(){
-		return rangeXRatio;
-	}
-	
-	public void setRangeXRatio(double rr){
-		this.rangeXRatio = rr;
-	}
-	public void addPointToLine(int lineIndex, LinePoint point){
-		Line line = getLine(lineIndex);
-		line.addPoint(point);
-		lines.set(lineIndex, line);
-		resetLimits();
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	
-	public void addPointsToLine(int lineIndex, LinePoint[] points){
-		Line line = getLine(lineIndex);
-		for(LinePoint point : points){
-			line.addPoint(point);
-		}
-		lines.set(lineIndex, line);
-		resetLimits();
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	
-	public void removeAllPointsAfter(int lineIndex, double x){
-		removeAllPointsBetween(lineIndex, x, getMaxX());
-	}
-	public void removeAllPointsBefore(int lineIndex, double x){
-		removeAllPointsBetween(lineIndex, getMinX(), x);
-	}
-	
-	public void removeAllPointsBetween(int lineIndex, double startX, double finishX){
-		Line line = getLine(lineIndex);
-		LinePoint[] pts = new LinePoint[line.getPoints().size()];
-		pts = line.getPoints().toArray(pts);
-		for(LinePoint point : pts){
-			if(point.getX() >= startX && point.getX() <= finishX)
-				line.removePoint(point);
-		}
-		lines.set(lineIndex, line);
-		resetLimits();
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	public void removePointsFromLine(int lineIndex, LinePoint[] points){
-		Line line = getLine(lineIndex);
-		for(LinePoint point : points){
-			line.removePoint(point);
-		}
-		lines.set(lineIndex, line);
-		resetLimits();
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	public void removePointFromLine(int lineIndex, float x, float y){
-		LinePoint p = null;
-		Line line = getLine(lineIndex);
-		p = line.getPoint(x, y);
-		removePointFromLine(lineIndex, p);
-	}
-	public void removePointFromLine(int lineIndex, LinePoint point){
-		Line line = getLine(lineIndex);
-		line.removePoint(point);
-		lines.set(lineIndex, line);
-		resetLimits();
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	
-	public void resetYLimits(){
-		float range = getMaxY() - getMinY();
-		setRangeY(getMinY()-range*getRangeYRatio(), getMaxY()+range*getRangeYRatio());
-	}
-	public void resetXLimits(){
-		float range = getMaxX() - getMinX();
-		setRangeX(getMinX()-range*getRangeXRatio(), getMaxX()+range*getRangeXRatio());
-	}
-	public void resetLimits() {
-		resetYLimits();
-		resetXLimits();
-	}
-	public ArrayList<Line> getLines() {
-		return lines;
-	}
-	public void setLineToFill(int indexOfLine) {
-		this.lineToFill = indexOfLine;
-		shouldUpdate = true;
-		postInvalidate();
-	}
-	public int getLineToFill(){
-		return lineToFill;
-	}
-	public void setLines(ArrayList<Line> lines) {
-		this.lines = lines;
-	}
-	public Line getLine(int index) {
-		return lines.get(index);
-	}
-	public int getSize(){
-		return lines.size();
-	}
-	
-	public void setRangeY(float min, float max) {
-		minY = min;
-		maxY = max;
-	}
-	private void setRangeY(double min, double max){
-		minY = (float)min;
-		maxY = (float)max;
-	}
-	public void setRangeX(float min, float max) {
-		minX = min;
-		maxX = max;
-		isMaxXUserSet = true;
-	}
-	private void setRangeX(double min, double max){
-		minX = (float)min;
-		maxX = (float)max;
-	}
-	public float getMaxY(){
-		float max = lines.get(0).getPoint(0).getY();
-		for (Line line : lines){
-			for (LinePoint point : line.getPoints()){
-				max = point.getY() > max ? point.getY() : max;
-			}
-		}
-		maxY = max;
-		return maxY;	
-	}
-
-	public float getMinY(){
-		float min = lines.get(0).getPoint(0).getY();
-		for (Line line : lines){
-			for (LinePoint point : line.getPoints()){
-				min = point.getY() < min ? point.getY() : min;
-			}
-		}
-		minY = min;
-		return minY;
-	}
-	public float getMinLimY(){
-		return minY;
-	}
-	public float getMaxLimY(){
-		return maxY;
-	}
-	public float getMinLimX(){
-		return minX;
-	}
-	public float getMaxLimX(){
-		if (isMaxXUserSet) {
-			return maxX;
-		}
-		else {
-			return getMaxX();
-		}
-	}
-	public float getMaxX(){
-		float max = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
-		for (Line line : lines){
-			for (LinePoint point : line.getPoints()){
-				max = point.getX() > max ? point.getX() : max;
-			}
-		}
-		maxX = max;
-		return maxX;
-		
-	}
-	public float getMinX(){
-		float min = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
-		for (Line line : lines){
-			for (LinePoint point : line.getPoints()){
-				min = point.getX() < min ? point.getX() : min;
-			}
-		}
-		minX = min;
-		return minX;
-	}
-
-	public void onDraw(Canvas ca) {
-		if (fullImage == null || shouldUpdate) {
-			fullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
-			Canvas canvas = new Canvas(fullImage);
-			
-			paint.reset();
-
-			float bottomPadding = 10, topPadding = 10;
-			float sidePadding = 10;
-			if (isUsingDips) {
-				bottomPadding = dipPadding;
-				topPadding = dipPadding;
-				sidePadding = dipPadding;
-			}
-			float usableHeight = getHeight() - bottomPadding - topPadding;
-			float usableWidth = getWidth() - 2*sidePadding;
-
-			float maxY = getMaxLimY();
-			float minY = getMinLimY();
-			float maxX = getMaxLimX();
-			float minX = getMinLimX();
-
-	        
-			int lineCount = 0;
-			for (Line line : lines){
-				int count = 0;
-				float lastXPixels = 0, newYPixels = 0;
-				float lastYPixels = 0, newXPixels = 0;
-				
-				if (lineCount == lineToFill){
-					paint.setColor(mFillColor);
-					paint.setStrokeWidth(mStrokeWidth);
-					for (int i = 10; i-getWidth() < getHeight(); i = i+mStrokeSpacing){
-						canvas.drawLine(i, getHeight()-bottomPadding, 0, getHeight()-bottomPadding-i, paint);
-					}
-					
-					paint.reset();
-                    mPath.reset();
-
-					paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
-					for (LinePoint p : line.getPoints()){
-						float yPercent = (p.getY()-minY)/(maxY - minY);
-						float xPercent = (p.getX()-minX)/(maxX - minX);
-						if (count == 0){
-							lastXPixels = sidePadding + (xPercent*usableWidth);
-							lastYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-                            mPath.moveTo(lastXPixels, lastYPixels);
-						} else {
-							newXPixels = sidePadding + (xPercent*usableWidth);
-							newYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-                            mPath.lineTo(newXPixels, newYPixels);
-                            mPath.moveTo(lastXPixels, lastYPixels);
-                            mPath.lineTo(newXPixels, newYPixels);
-                            mPath.lineTo(newXPixels, 0);
-                            mPath.lineTo(lastXPixels, 0);
-                            mPath.close();
-							canvas.drawPath(mPath, paint);
-							lastXPixels = newXPixels;
-							lastYPixels = newYPixels;
-						}
-						count++;
-					}
-
-                    mPath.reset();
-                    mPath.moveTo(0, getHeight()-bottomPadding);
-                    mPath.lineTo(sidePadding, getHeight()-bottomPadding);
-					mPath.lineTo(sidePadding, 0);
-					mPath.lineTo(0, 0);
-					mPath.close();
-					canvas.drawPath(mPath, paint);
-					
-					mPath.reset();
-					mPath.moveTo(getWidth(), getHeight()-bottomPadding);
-					mPath.lineTo(getWidth()-sidePadding, getHeight()-bottomPadding);
-					mPath.lineTo(getWidth()-sidePadding, 0);
-					mPath.lineTo(getWidth(), 0);
-					mPath.close();
-					
-					canvas.drawPath(mPath, paint);
-				}
-				
-				lineCount++;
-			}
-			
-			paint.reset();
-			
-			paint.setColor(Color.BLACK);
-			paint.setAlpha(50);
-			paint.setAntiAlias(true);
-			canvas.drawLine(sidePadding, getHeight() - bottomPadding, getWidth()-sidePadding, getHeight()-bottomPadding, paint);
-			paint.setAlpha(255);
-			
-			for (Line line : lines){
-				int count = 0;
-				float lastXPixels = 0, newYPixels = 0;
-				float lastYPixels = 0, newXPixels = 0;
-				
-				paint.setColor(line.getColor());
-				paint.setStrokeWidth(getStrokeWidth(line));
-				
-				for (LinePoint p : line.getPoints()){
-					float yPercent = (p.getY()-minY)/(maxY - minY);
-					float xPercent = (p.getX()-minX)/(maxX - minX);
-					if (count == 0){
-						lastXPixels = sidePadding + (xPercent*usableWidth);
-						lastYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-					} else {
-						newXPixels = sidePadding + (xPercent*usableWidth);
-						newYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-						canvas.drawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, paint);
-						lastXPixels = newXPixels;
-						lastYPixels = newYPixels;
-					}
-					count++;
-				}
-			}
-			
-			
-			int pointCount = 0;
-			
-			for (Line line : lines){
-
-				paint.setColor(line.getColor());
-				paint.setStrokeWidth(getStrokeWidth(line));
-				paint.setStrokeCap(Paint.Cap.ROUND);
-				
-				if (line.isShowingPoints()){
-					for (LinePoint p : line.getPoints()){
-						float yPercent = (p.getY()-minY)/(maxY - minY);
-						float xPercent = (p.getX()-minX)/(maxX - minX);
-						float xPixels = sidePadding + (xPercent*usableWidth);
-						float yPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-
-						int outerRadius;
-						if (line.isUsingDips()) {
-							outerRadius = getPixelForDip(line.getStrokeWidth() + 4);
-						}
-						else {
-							outerRadius = line.getStrokeWidth() + 4;
-						}
-						int innerRadius = outerRadius / 2;
-
-						paint.setColor(p.getColor());
-						canvas.drawCircle(xPixels, yPixels, outerRadius, paint);
-						paint.setColor(Color.WHITE);
-						canvas.drawCircle(xPixels, yPixels, innerRadius, paint);
-						
-                        p.getPath().reset();
-                        p.getPath().addCircle(xPixels, yPixels, 30, Direction.CW);
-						p.getRegion().set((int) (xPixels - 30), (int) (yPixels - 30), (int) (xPixels + 30), (int) (yPixels + 30));
-						
-						if (indexSelected == pointCount && listener != null){
-                            paint.setColor(p.getSelectedColor());
-							canvas.drawPath(p.getPath(), paint);
-							paint.setAlpha(255);
-						}
-						
-						pointCount++;
-					}
-				}
-			}
-
-			shouldUpdate = false;
-		}
-		
-		ca.drawBitmap(fullImage, 0, 0, null);
-	}
-
-	private int getStrokeWidth(Line line) {
-		int strokeWidth;
-		if (line.isUsingDips()) {
-			strokeWidth = getPixelForDip(line.getStrokeWidth());
-		}
-		else {
-			strokeWidth = line.getStrokeWidth();
-		}
-		return strokeWidth;
-	}
-
-	private int getPixelForDip(int dipValue) {
-		return (int) TypedValue.applyDimension(
-				TypedValue.COMPLEX_UNIT_DIP,
-				dipValue,
-				getResources().getDisplayMetrics());
-	}
-
-	@Override
-	public boolean onTouchEvent(MotionEvent event) {
-
-	    Point point = new Point();
-	    point.x = (int) event.getX();
-	    point.y = (int) event.getY();
-	    
-	    int count = 0;
-	    int lineCount = 0;
-	    int pointCount;
-	    
-	    Region r = new Region();
-	    for (Line line : lines){
-	    	pointCount = 0;
-	    	for (LinePoint p : line.getPoints()){
-	    		
-	    		if (p.getPath() != null && p.getRegion() != null){
-	    			r.setPath(p.getPath(), p.getRegion());
-			    	if (r.contains(point.x, point.y) && event.getAction() == MotionEvent.ACTION_DOWN){
-			    		indexSelected = count;
-			    	} else if (event.getAction() == MotionEvent.ACTION_UP){
-			    		if (r.contains(point.x, point.y) && listener != null){
-			    			listener.onClick(lineCount, pointCount);
-			    		}
-			    		indexSelected = -1;
-			    	}
-	    		}
-		    	
-		    	pointCount++;
-			    count++;
-	    	}
-	    	lineCount++;
-	    }
-	    
-	    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP){
-	    	shouldUpdate = true;
-	    	postInvalidate();
-	    }
-
-	    return true;
-	}
-	
-	public void setOnPointClickedListener(OnPointClickedListener listener) {
-		this.listener = listener;
-	}
-	
-	public interface OnPointClickedListener {
-		abstract void onClick(int lineIndex, int pointIndex);
-	}
+        return isUsingDips;
+    }
+
+    public void setUsingDips(boolean treatSizesAsDips) {
+        this.isUsingDips = treatSizesAsDips;
+    }
+
+    public void removeAllLines() {
+        while (lines.size() > 0) {
+            lines.remove(0);
+        }
+        postInvalidate();
+    }
+
+    public void addLine(Line line) {
+        lines.add(line);
+        postInvalidate();
+    }
+
+    public void addPointToLine(int lineIndex, double x, double y) {
+        addPointToLine(lineIndex, (float) x, (float) y);
+    }
+
+    public void addPointToLine(int lineIndex, float x, float y) {
+        LinePoint p = new LinePoint(x, y);
+
+        addPointToLine(lineIndex, p);
+    }
+
+    public double getRangeYRatio() {
+        return rangeYRatio;
+    }
+
+    public void setRangeYRatio(double rr) {
+        this.rangeYRatio = rr;
+    }
+
+    public double getRangeXRatio() {
+        return rangeXRatio;
+    }
+
+    public void setRangeXRatio(double rr) {
+        this.rangeXRatio = rr;
+    }
+
+    public void addPointToLine(int lineIndex, LinePoint point) {
+        Line line = getLine(lineIndex);
+        line.addPoint(point);
+        lines.set(lineIndex, line);
+        resetLimits();
+        postInvalidate();
+    }
+
+    public void addPointsToLine(int lineIndex, LinePoint[] points) {
+        Line line = getLine(lineIndex);
+        for (LinePoint point : points) {
+            line.addPoint(point);
+        }
+        lines.set(lineIndex, line);
+        resetLimits();
+        postInvalidate();
+    }
+
+    public void removeAllPointsAfter(int lineIndex, double x) {
+        removeAllPointsBetween(lineIndex, x, getMaxX());
+    }
+
+    public void removeAllPointsBefore(int lineIndex, double x) {
+        removeAllPointsBetween(lineIndex, getMinX(), x);
+    }
+
+    public void removeAllPointsBetween(int lineIndex, double startX, double finishX) {
+        Line line = getLine(lineIndex);
+        LinePoint[] pts = new LinePoint[line.getPoints().size()];
+        pts = line.getPoints().toArray(pts);
+        for (LinePoint point : pts) {
+            if (point.getX() >= startX && point.getX() <= finishX)
+                line.removePoint(point);
+        }
+        lines.set(lineIndex, line);
+        resetLimits();
+        postInvalidate();
+    }
+
+    public void removePointsFromLine(int lineIndex, LinePoint[] points) {
+        Line line = getLine(lineIndex);
+        for (LinePoint point : points) {
+            line.removePoint(point);
+        }
+        lines.set(lineIndex, line);
+        resetLimits();
+        postInvalidate();
+    }
+
+    public void removePointFromLine(int lineIndex, float x, float y) {
+        LinePoint p = null;
+        Line line = getLine(lineIndex);
+        p = line.getPoint(x, y);
+        removePointFromLine(lineIndex, p);
+    }
+
+    public void removePointFromLine(int lineIndex, LinePoint point) {
+        Line line = getLine(lineIndex);
+        line.removePoint(point);
+        lines.set(lineIndex, line);
+        resetLimits();
+        postInvalidate();
+    }
+
+    public void resetYLimits() {
+        float range = getMaxY() - getMinY();
+        setRangeY(getMinY() - range * getRangeYRatio(), getMaxY() + range * getRangeYRatio());
+    }
+
+    public void resetXLimits() {
+        float range = getMaxX() - getMinX();
+        setRangeX(getMinX() - range * getRangeXRatio(), getMaxX() + range * getRangeXRatio());
+    }
+
+    public void resetLimits() {
+        resetYLimits();
+        resetXLimits();
+    }
+
+    public ArrayList<Line> getLines() {
+        return lines;
+    }
+
+    public void setLineToFill(int indexOfLine) {
+        this.lineToFill = indexOfLine;
+        postInvalidate();
+    }
+
+    public int getLineToFill() {
+        return lineToFill;
+    }
+
+    public void setLines(ArrayList<Line> lines) {
+        this.lines = lines;
+    }
+
+    public Line getLine(int index) {
+        return lines.get(index);
+    }
+
+    public int getSize() {
+        return lines.size();
+    }
+
+    public void setRangeY(float min, float max) {
+        minY = min;
+        maxY = max;
+    }
+
+    private void setRangeY(double min, double max) {
+        minY = (float) min;
+        maxY = (float) max;
+    }
+
+    public void setRangeX(float min, float max) {
+        minX = min;
+        maxX = max;
+        isMaxXUserSet = true;
+    }
+
+    private void setRangeX(double min, double max) {
+        minX = (float) min;
+        maxX = (float) max;
+    }
+
+    public float getMaxY() {
+        float max = lines.get(0).getPoint(0).getY();
+        for (Line line : lines) {
+            for (LinePoint point : line.getPoints()) {
+                max = point.getY() > max ? point.getY() : max;
+            }
+        }
+        maxY = max;
+        return maxY;
+    }
+
+    public float getMinY() {
+        float min = lines.get(0).getPoint(0).getY();
+        for (Line line : lines) {
+            for (LinePoint point : line.getPoints()) {
+                min = point.getY() < min ? point.getY() : min;
+            }
+        }
+        minY = min;
+        return minY;
+    }
+
+    public float getMinLimY() {
+        return minY;
+    }
+
+    public float getMaxLimY() {
+        return maxY;
+    }
+
+    public float getMinLimX() {
+        return minX;
+    }
+
+    public float getMaxLimX() {
+        if (isMaxXUserSet) {
+            return maxX;
+        } else {
+            return getMaxX();
+        }
+    }
+
+    public float getMaxX() {
+        float max = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
+        for (Line line : lines) {
+            for (LinePoint point : line.getPoints()) {
+                max = point.getX() > max ? point.getX() : max;
+            }
+        }
+        maxX = max;
+        return maxX;
+
+    }
+
+    public float getMinX() {
+        float min = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
+        for (Line line : lines) {
+            for (LinePoint point : line.getPoints()) {
+                min = point.getX() < min ? point.getX() : min;
+            }
+        }
+        minX = min;
+        return minX;
+    }
+
+    public void onDraw(Canvas canvas) {
+        canvas.drawColor(Color.TRANSPARENT);
+        mPaint.reset();
+
+        float bottomPadding = 10, topPadding = 10;
+        float sidePadding = 10;
+        if (isUsingDips) {
+            bottomPadding = dipPadding;
+            topPadding = dipPadding;
+            sidePadding = dipPadding;
+        }
+        float usableHeight = getHeight() - bottomPadding - topPadding;
+        float usableWidth = getWidth() - 2 * sidePadding;
+
+        float maxY = getMaxLimY();
+        float minY = getMinLimY();
+        float maxX = getMaxLimX();
+        float minX = getMinLimX();
+
+
+        int lineCount = 0;
+        for (Line line : lines) {
+            int count = 0;
+            float lastXPixels = 0, newYPixels = 0;
+            float lastYPixels = 0, newXPixels = 0;
+
+            if (lineCount == lineToFill) {
+                mPaint.setColor(mFillColor);
+                mPaint.setStrokeWidth(mStrokeWidth);
+                for (int i = 10; i - getWidth() < getHeight(); i = i + mStrokeSpacing) {
+                    canvas.drawLine(i, getHeight() - bottomPadding, 0, getHeight() - bottomPadding - i, mPaint);
+                }
+
+                mPaint.reset();
+                mPath.reset();
+
+                //mPaint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
+                for (LinePoint p : line.getPoints()) {
+                    float yPercent = (p.getY() - minY) / (maxY - minY);
+                    float xPercent = (p.getX() - minX) / (maxX - minX);
+                    if (count == 0) {
+                        lastXPixels = sidePadding + (xPercent * usableWidth);
+                        lastYPixels = getHeight() - bottomPadding - (usableHeight * yPercent);
+                        mPath.moveTo(lastXPixels, lastYPixels);
+                    } else {
+                        newXPixels = sidePadding + (xPercent * usableWidth);
+                        newYPixels = getHeight() - bottomPadding - (usableHeight * yPercent);
+                        mPath.lineTo(newXPixels, newYPixels);
+                        mPath.moveTo(lastXPixels, lastYPixels);
+                        mPath.lineTo(newXPixels, newYPixels);
+                        mPath.lineTo(newXPixels, 0);
+                        mPath.lineTo(lastXPixels, 0);
+                        mPath.close();
+                        canvas.drawPath(mPath, mPaint);
+                        lastXPixels = newXPixels;
+                        lastYPixels = newYPixels;
+                    }
+                    count++;
+                }
+
+                mPath.reset();
+                mPath.moveTo(0, getHeight() - bottomPadding);
+                mPath.lineTo(sidePadding, getHeight() - bottomPadding);
+                mPath.lineTo(sidePadding, 0);
+                mPath.lineTo(0, 0);
+                mPath.close();
+                canvas.drawPath(mPath, mPaint);
+
+                mPath.reset();
+                mPath.moveTo(getWidth(), getHeight() - bottomPadding);
+                mPath.lineTo(getWidth() - sidePadding, getHeight() - bottomPadding);
+                mPath.lineTo(getWidth() - sidePadding, 0);
+                mPath.lineTo(getWidth(), 0);
+                mPath.close();
+
+                canvas.drawPath(mPath, mPaint);
+            }
+            lineCount++;
+        }
+
+        // Draw x-axis
+        mPaint.reset();
+        mPaint.setColor(Color.BLACK);
+        mPaint.setAlpha(50);
+        mPaint.setAntiAlias(true);
+        canvas.drawLine(sidePadding, getHeight() - bottomPadding, getWidth() - sidePadding, getHeight() - bottomPadding, mPaint);
+        mPaint.setAlpha(255);
+
+        for (Line line : lines) {
+            int count = 0;
+            float lastXPixels = 0, newYPixels = 0;
+            float lastYPixels = 0, newXPixels = 0;
+
+            mPaint.setColor(line.getColor());
+            mPaint.setStrokeWidth(getStrokeWidth(line));
+
+            for (LinePoint p : line.getPoints()) {
+                float yPercent = (p.getY() - minY) / (maxY - minY);
+                float xPercent = (p.getX() - minX) / (maxX - minX);
+                if (count == 0) {
+                    lastXPixels = sidePadding + (xPercent * usableWidth);
+                    lastYPixels = getHeight() - bottomPadding - (usableHeight * yPercent);
+                } else {
+                    newXPixels = sidePadding + (xPercent * usableWidth);
+                    newYPixels = getHeight() - bottomPadding - (usableHeight * yPercent);
+                    canvas.drawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, mPaint);
+                    lastXPixels = newXPixels;
+                    lastYPixels = newYPixels;
+                }
+                count++;
+            }
+        }
+
+
+        int pointCount = 0;
+
+        for (Line line : lines) {
+
+            mPaint.setColor(line.getColor());
+            mPaint.setStrokeWidth(getStrokeWidth(line));
+            mPaint.setStrokeCap(Paint.Cap.ROUND);
+
+            if (line.isShowingPoints()) {
+                for (LinePoint p : line.getPoints()) {
+                    float yPercent = (p.getY() - minY) / (maxY - minY);
+                    float xPercent = (p.getX() - minX) / (maxX - minX);
+                    float xPixels = sidePadding + (xPercent * usableWidth);
+                    float yPixels = getHeight() - bottomPadding - (usableHeight * yPercent);
+
+                    int outerRadius;
+                    if (line.isUsingDips()) {
+                        outerRadius = getPixelForDip(line.getStrokeWidth() + 4);
+                    } else {
+                        outerRadius = line.getStrokeWidth() + 4;
+                    }
+                    int innerRadius = outerRadius / 2;
+
+                    mPaint.setColor(p.getColor());
+                    canvas.drawCircle(xPixels, yPixels, outerRadius, mPaint);
+                    mPaint.setColor(Color.WHITE);
+                    canvas.drawCircle(xPixels, yPixels, innerRadius, mPaint);
+
+                    p.getPath().reset();
+                    p.getPath().addCircle(xPixels, yPixels, 30, Direction.CW);
+                    p.getRegion().set((int) (xPixels - 30), (int) (yPixels - 30), (int) (xPixels + 30), (int) (yPixels + 30));
+
+                    if (mSelectedIndex == pointCount && mListener != null) {
+                        mPaint.setColor(p.getSelectedColor());
+                        canvas.drawPath(p.getPath(), mPaint);
+                        mPaint.setAlpha(255);
+                    }
+                    pointCount++;
+                }
+            }
+        }
+    }
+
+    private int getStrokeWidth(Line line) {
+        int strokeWidth;
+        if (line.isUsingDips()) {
+            strokeWidth = getPixelForDip(line.getStrokeWidth());
+        } else {
+            strokeWidth = line.getStrokeWidth();
+        }
+        return strokeWidth;
+    }
+
+    private int getPixelForDip(int dipValue) {
+        return (int) TypedValue.applyDimension(
+                TypedValue.COMPLEX_UNIT_DIP,
+                dipValue,
+                getResources().getDisplayMetrics());
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+
+        Point point = new Point();
+        point.x = (int) event.getX();
+        point.y = (int) event.getY();
+
+        int count = 0;
+        int lineCount = 0;
+        int pointCount;
+
+        Region r = new Region();
+        for (Line line : lines) {
+            pointCount = 0;
+            for (LinePoint p : line.getPoints()) {
+                r.setPath(p.getPath(), p.getRegion());
+
+                switch (event.getAction()) {
+                    default:
+                        break;
+                    case MotionEvent.ACTION_DOWN:
+                        if (r.contains(point.x, point.y)) {
+                            mSelectedIndex = count;
+                            postInvalidate();
+                        }
+                        break;
+                    case MotionEvent.ACTION_UP:
+                        if (r.contains(point.x, point.y) && mListener != null) {
+                            if (mSelectedIndex > -1) {
+                                mListener.onClick(lineCount, pointCount);
+                            }
+                            mSelectedIndex = -1;
+                            postInvalidate();
+                        }
+                        break;
+                }
+                pointCount++;
+                count++;
+            }
+            lineCount++;
+        }
+        return true;
+    }
+
+    public void setOnPointClickedListener(OnPointClickedListener listener) {
+        this.mListener = listener;
+    }
+
+    public interface OnPointClickedListener {
+        abstract void onClick(int lineIndex, int pointIndex);
+    }
 }

File HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java

View file
 
 	@Override
 	public boolean onTouchEvent(MotionEvent event) {
-
 		if (mDrawCompleted) {
-
 			Point point = new Point();
 			point.x = (int) event.getX();
 			point.y = (int) event.getY();

File HoloGraphLibrarySample/res/layout/fragment_linegraph.xml

View file
         android:layout_margin="@dimen/default_margin"
         app:strokeColor="@color/transparent_orange"
         app:strokeWidth="1dip"
-        app:strokeSpacing="10dip"/>
+        app:strokeSpacing="10dip"
+        app:useDip="true"/>
 	
 </LinearLayout>

File HoloGraphLibrarySample/res/layout/fragment_piegraph.xml

View file
             android:layout_width="0dip"
             android:layout_height="wrap_content"
             android:progress="128"
-            android:max="255"
+            android:max="240"
             android:id="@+id/seekBarRatio"
             android:layout_weight="1"/>
     </LinearLayout>

File HoloGraphLibrarySample/src/com/echo/holographlibrarysample/BarFragment.java

View file
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Toast;
 
 import com.echo.holographlibrary.Bar;
 import com.echo.holographlibrary.BarGraph;
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         final View v = inflater.inflate(R.layout.fragment_bargraph, container, false);
         final Resources resources = getResources();
-        ArrayList<Bar> points = new ArrayList<Bar>();
-        Bar d = new Bar();
-        d.setColor(resources.getColor(R.color.green_light));
-        d.setSelectedColor(resources.getColor(R.color.transparent_orange));
-        d.setName("Test1");
-        d.setValue(1000);
-        d.setValueString("$1,000");
-        Bar d2 = new Bar();
-        d2.setColor(resources.getColor(R.color.orange));
-        d2.setName("Test2");
-        d2.setValue(2000);
-        d2.setValueString("$2,000");
-        points.add(d);
-        points.add(d2);
+        ArrayList<Bar> aBars = new ArrayList<Bar>();
+        Bar bar = new Bar();
+        bar.setColor(resources.getColor(R.color.green_light));
+        bar.setSelectedColor(resources.getColor(R.color.transparent_orange));
+        bar.setName("Test1");
+        bar.setValue(1000);
+        bar.setValueString("$1,000");
+        aBars.add(bar);
+        bar = new Bar();
+        bar.setColor(resources.getColor(R.color.orange));
+        bar.setName("Test2");
+        bar.setValue(2000);
+        bar.setValueString("$2,000");
+        aBars.add(bar);
 
-        BarGraph g = (BarGraph) v.findViewById(R.id.bargraph);
-        g.setBars(points);
+        BarGraph barGraph = (BarGraph) v.findViewById(R.id.bargraph);
+        barGraph.setBars(aBars);
 
-        g.setOnBarClickedListener(new OnBarClickedListener() {
+        barGraph.setOnBarClickedListener(new OnBarClickedListener() {
 
             @Override
             public void onClick(int index) {
-
+                Toast.makeText(getActivity(),
+                        "Bar " + index + " clicked",
+                        Toast.LENGTH_SHORT)
+                        .show();
             }
-
         });
 
         return v;