Commits

Daniel Nadeau committed 104a390 Merge

Merged in yous/holographlibrary/patch (pull request #39)

Minor adjustments and improve readability

Comments (0)

Files changed (5)

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

 
 public class BarGraph extends View {
 
-    private final static int VALUE_FONT_SIZE = 30;
-    private final static int AXIS_LABEL_FONT_SIZE = 15;
-    private final static float LABEL_PADDING_MULTIPLIER = 1.6f; //how much space to leave between labels when shrunken. Increase for less space.
-    private final static int ORIENTATION_HORIZONTAL = 0;
-    private final static int ORIENTATION_VERTICAL = 1;
+    private static final int VALUE_FONT_SIZE = 30;
+    private static final int AXIS_LABEL_FONT_SIZE = 15;
+    // How much space to leave between labels when shrunken. Increase for less space.
+    private static final float LABEL_PADDING_MULTIPLIER = 1.6f;
+    private static final int ORIENTATION_HORIZONTAL = 0;
+    private static final int ORIENTATION_VERTICAL = 1;
 
     private final int mOrientation;
     private ArrayList<Bar> mBars = new ArrayList<Bar>();
         final Resources resources = getContext().getResources();
 
         canvas.drawColor(Color.TRANSPARENT);
-        NinePatchDrawable popup = (NinePatchDrawable) this.getResources().getDrawable(R.drawable.popup_black);
+        NinePatchDrawable popup = (NinePatchDrawable) resources.getDrawable(R.drawable.popup_black);
 
         float maxValue = 0;
-        float padding = 7 * getContext().getResources().getDisplayMetrics().density;
+        float padding = 7 * resources.getDisplayMetrics().density;
         float bottomPadding = 30 * resources.getDisplayMetrics().density;
 
         float usableHeight;
         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 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 x-axis label text
             if (mShowAxis) {
                 this.mPaint.setColor(bar.getLabelColor());
-                this.mPaint.setTextSize(AXIS_LABEL_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
+                this.mPaint.setTextSize(AXIS_LABEL_FONT_SIZE
+                        * resources.getDisplayMetrics().scaledDensity);
                 float textWidth = this.mPaint.measureText(bar.getName());
+                // Decrease text size to fit and not overlap with other labels.
                 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());
                 }
 
             // Draw value text
             if (mShowBarText) {
-                this.mPaint.setTextSize(VALUE_FONT_SIZE * resources.getDisplayMetrics().scaledDensity);
+                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);
+                        - (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)
+                // Limit popup width to bar width
+                if (boundLeft < mBoundsRect.left) {
+                    boundLeft = mBoundsRect.left - ((int) padding / 2);
+                }
+                if (boundRight > mBoundsRect.right) {
                     boundRight = mBoundsRect.right + ((int) padding / 2);
+                }
 
                 popup.setBounds(boundLeft, boundTop, boundRight, mBoundsRect.top);
                 popup.draw(canvas);
 
+                // Check cache to see if we've done this calculation before
                 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)
+                    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()));

HoloGraphLibrary/src/com/echo/holographlibrary/Line.java

     private boolean mShowPoints = true;
     // 6 has been the default prior to the addition of custom stroke widths
     private int mStrokeWidth = 6;
-    // since this is a new addition, it has to default to false to be backwards compatible
+    // Since this is a new addition, it has to default to false to be backwards compatible
     private boolean mUseDips = false;
 
 

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

     private int mSelectedIndex = -1;
     private OnPointClickedListener mListener;
     private Bitmap mFullImage;
-    // since this is a new addition, it has to default to false to be backwards compatible
+    // Since this is a new addition, it has to default to false to be backwards compatible
     private boolean mUseDips;
     private Path mPath = new Path();
     private PorterDuffXfermode mXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
                 mPaint.setColor(mFillColor);
                 mPaint.setStrokeWidth(mStrokeWidth);
                 for (int i = 10; i - getWidth() < getHeight(); i = i + mStrokeSpacing) {
-                    mCanvas.drawLine(i, getHeight() - bottomPadding, 0, getHeight() - bottomPadding - i, mPaint);
+                    mCanvas.drawLine(
+                            i, getHeight() - bottomPadding,
+                            0, getHeight() - bottomPadding - i, mPaint);
                 }
 
                 // Erase lines above the line
         mPaint.setColor(mAxisColor);
         mPaint.setStrokeWidth(2 * getResources().getDisplayMetrics().density);
         mPaint.setAntiAlias(true);
-        mCanvas.drawLine(sidePadding, getHeight() - bottomPadding, getWidth() - sidePadding, getHeight() - bottomPadding, mPaint);
+        mCanvas.drawLine(
+                sidePadding, getHeight() - bottomPadding,
+                getWidth() - sidePadding, getHeight() - bottomPadding, mPaint);
         mPaint.reset();
 
         // Draw lines

HoloGraphLibrary/src/com/echo/holographlibrary/LinePoint.java

 
 public class LinePoint {
 
-    final private Path mPath = new Path();
-    final private Region mRegion = new Region();
+    private final Path mPath = new Path();
+    private final Region mRegion = new Region();
     private float mX;
     private float mY;
     private int mColor = 0xFF000000;

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

             mRectF.set(midX - radius, midY - radius, midX + radius, midY + radius);
             p.arcTo(mRectF,
                     currentAngle + mPadding, currentSweep - mPadding);
-            mRectF.set(midX - innerRadius, midY - innerRadius, midX + innerRadius, midY + innerRadius);
+            mRectF.set(midX - innerRadius, midY - innerRadius,
+                    midX + innerRadius, midY + innerRadius);
             p.arcTo(mRectF,
-                    (currentAngle + mPadding) + (currentSweep - mPadding), -(currentSweep - mPadding));
+                    (currentAngle + mPadding) + (currentSweep - mPadding),
+                    -(currentSweep - mPadding));
             p.close();
 
             // Create selection region