@@ -47,7 +47,6 @@ public class BarGraph extends View {
47
47
48
48
private ArrayList <Bar > mBars = new ArrayList <>();
49
49
private final Paint mPaint = new Paint ();
50
- private Rect mRectangle = null ;
51
50
private boolean mShowBarText = true ;
52
51
private boolean mShowAxis = true ;
53
52
private int mIndexSelected = -1 ;
@@ -57,7 +56,7 @@ public class BarGraph extends View {
57
56
58
57
private int popupImageID ;
59
58
60
- private Context mContext ;
59
+ private final Context mContext ;
61
60
62
61
63
62
/**
@@ -150,8 +149,8 @@ public void onDraw(Canvas ca) {
150
149
maxValue = bar .getValue ();
151
150
}
152
151
}
153
-
154
- mRectangle = new Rect ();
152
+
153
+ Rect mRectangle = new Rect ();
155
154
156
155
int count = 0 ;
157
156
for (final Bar bar : mBars ) {
@@ -176,7 +175,7 @@ public void onDraw(Canvas ca) {
176
175
// Draw x-axis label text
177
176
if (mShowAxis ){
178
177
this .mPaint .setTextSize (AXIS_LABEL_FONT_SIZE * mContext .getResources ().getDisplayMetrics ().scaledDensity );
179
- int x = (int )(((mRectangle .left +mRectangle .right )/2 )-(this .mPaint .measureText (bar .getName ())/2 ));
178
+ int x = (int )(((mRectangle .left + mRectangle .right )/2 )-(this .mPaint .measureText (bar .getName ())/2 ));
180
179
int y = (int ) (getHeight ()-3 * mContext .getResources ().getDisplayMetrics ().scaledDensity );
181
180
canvas .drawText (bar .getName (), x , y , this .mPaint );
182
181
}
@@ -188,13 +187,13 @@ public void onDraw(Canvas ca) {
188
187
Rect r2 = new Rect ();
189
188
this .mPaint .getTextBounds (bar .getValueString (), 0 , 1 , r2 );
190
189
191
- int boundLeft = (int ) (((mRectangle .left +mRectangle .right )/2 )-(this .mPaint .measureText (bar .getValueString ())/2 )-5 * mContext .getResources ().getDisplayMetrics ().density );
190
+ int boundLeft = (int ) (((mRectangle .left + mRectangle .right )/2 )-(this .mPaint .measureText (bar .getValueString ())/2 )-5 * mContext .getResources ().getDisplayMetrics ().density );
192
191
int boundTop = (int ) (mRectangle .top +(r2 .top -r2 .bottom )-18 * mContext .getResources ().getDisplayMetrics ().density );
193
- int boundRight = (int )(((mRectangle .left +mRectangle .right )/2 )+(this .mPaint .measureText (bar .getValueString ())/2 )+5 * mContext .getResources ().getDisplayMetrics ().density );
192
+ int boundRight = (int )(((mRectangle .left + mRectangle .right )/2 )+(this .mPaint .measureText (bar .getValueString ())/2 )+5 * mContext .getResources ().getDisplayMetrics ().density );
194
193
popup .setBounds (boundLeft , boundTop , boundRight , mRectangle .top );
195
194
popup .draw (canvas );
196
195
197
- canvas .drawText (bar .getValueString (), (int )(((mRectangle .left +mRectangle .right )/2 )-(this .mPaint .measureText (bar .getValueString ()))/2 ), mRectangle .top -(mRectangle .top - boundTop )/2f +(float )Math .abs (r2 .top -r2 .bottom )/2f *0.7f , this .mPaint );
196
+ canvas .drawText (bar .getValueString (), (int )(((mRectangle .left + mRectangle .right )/2 )-(this .mPaint .measureText (bar .getValueString ()))/2 ), mRectangle .top -(mRectangle .top - boundTop )/2f +(float )Math .abs (r2 .top -r2 .bottom )/2f *0.7f , this .mPaint );
198
197
}
199
198
if (mIndexSelected == count && mListener != null ) {
200
199
this .mPaint .setColor (Color .parseColor ("#33B5E5" ));
0 commit comments