From bb2cf09de130527518debef0f7b2bd556fcbb851 Mon Sep 17 00:00:00 2001 From: Daniel Nadeau Date: Sat, 16 Nov 2013 15:56:12 +0000 Subject: [PATCH 1/5] Bar.java edited to return a value string even when value string is null --- HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java b/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java index 334f226..020230d 100644 --- a/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java +++ b/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java @@ -55,7 +55,11 @@ public void setValue(float value) { public String getValueString() { - return mValueString; + if (mValueString == null) { + return String.valueOf(mValue); + } else { + return mValueString; + } } public void setValueString(final String valueString) From 453be58c0b6512d4213f9df127a1d83bcc4d60e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Martin=C3=ADk?= Date: Sun, 17 Nov 2013 19:35:25 +0100 Subject: [PATCH 2/5] Fixed bug with bad rendering of popup background --- .../res/drawable-xhdpi/popup_black.9.png | Bin 308 -> 379 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/HoloGraphLibrary/res/drawable-xhdpi/popup_black.9.png b/HoloGraphLibrary/res/drawable-xhdpi/popup_black.9.png index 4da6a2c69dd4b4b3c3295d1990597b19c88bf20e..6b99b7a13a76c3252b081d7acc34131dfb887a88 100644 GIT binary patch literal 379 zcmeAS@N?(olHy`uVBq!ia0vp^{y^-?!3HF`*YAD+q}Y|gW!U_%O?XxI14-? zi-GdOAk4@xYmNj^kiEpy*OmP)x1f+B`-h0&CkzaX9G)(YAr-gY-ZA7lWFX=2FkSc2 zqeZLBKZ?w|G?_!If>oW>Rp6j&r+1g^ss-NlU-vGRjpB&sSSWkxVc?>>R`Po$@5|W} zcHR4@)zrsp(^}c)tIw-=)TurXh$^S`aX(TxIv+=BKI8jt>cU!X75B2wojD0r?pTJ>mwQSg$PQ)U%=J-eFtwe;pDo$FO` z0lJGH-n|^*X&->cpsr@_G+;-c%B7T3mk>Tpad%BnPeNLazo*~G)NNm=3!{dSM$Dhym hTOa+!GxF{;p8JbdXB=k~H3kL)gQu&X%Q~loCIAK+dIbOg From 33be3439d3a5cdb60e3fd0111884c5767f7ec64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Martin=C3=ADk?= Date: Sun, 17 Nov 2013 21:28:07 +0100 Subject: [PATCH 3/5] Better touch events handling - bars and pie slices remained selected when viewpager was moved Proper text and bar scaling according to device density --- .../com/echo/holographlibrary/BarGraph.java | 41 ++++++++++++------- .../com/echo/holographlibrary/PieGraph.java | 4 +- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java b/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java index 46ac314..2da1607 100644 --- a/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java +++ b/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java @@ -43,6 +43,8 @@ public class BarGraph extends View { + private final static int VALUE_FONT_SIZE = 30, AXIS_LABEL_FONT_SIZE = 15; + private ArrayList mBars = new ArrayList(); private Paint mPaint = new Paint(); private Rect mRectangle = null; @@ -52,12 +54,16 @@ public class BarGraph extends View { private Bitmap mFullImage; private boolean mShouldUpdate = false; + private Context mContext = null; + public BarGraph(Context context) { super(context); + mContext = context; } public BarGraph(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; } public void setShowBarText(boolean show){ @@ -75,7 +81,7 @@ public ArrayList getBars(){ } public void onDraw(Canvas ca) { - + if (mFullImage == null || mShouldUpdate) { mFullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(mFullImage); @@ -83,26 +89,26 @@ public void onDraw(Canvas ca) { NinePatchDrawable popup = (NinePatchDrawable)this.getResources().getDrawable(R.drawable.popup_black); float maxValue = 0; - float padding = 7; - int selectPadding = 4; - float bottomPadding = 40; + float padding = 7 * mContext.getResources().getDisplayMetrics().density; + int selectPadding = (int) (4 * mContext.getResources().getDisplayMetrics().density); + float bottomPadding = 30 * mContext.getResources().getDisplayMetrics().density; float usableHeight; if (mShowBarText) { - this.mPaint.setTextSize(40); + this.mPaint.setTextSize(VALUE_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity); Rect r3 = new Rect(); this.mPaint.getTextBounds("$", 0, 1, r3); - usableHeight = getHeight()-bottomPadding-Math.abs(r3.top-r3.bottom)-26; + usableHeight = getHeight()-bottomPadding-Math.abs(r3.top-r3.bottom)*2; } else { usableHeight = getHeight()-bottomPadding; } // Draw x-axis line mPaint.setColor(Color.BLACK); - mPaint.setStrokeWidth(2); + mPaint.setStrokeWidth(2 * mContext.getResources().getDisplayMetrics().density); mPaint.setAlpha(50); mPaint.setAntiAlias(true); - canvas.drawLine(0, getHeight()-bottomPadding+10, getWidth(), getHeight()-bottomPadding+10, mPaint); + canvas.drawLine(0, getHeight()-bottomPadding+10* mContext.getResources().getDisplayMetrics().density, getWidth(), getHeight()-bottomPadding+10* mContext.getResources().getDisplayMetrics().density, mPaint); float barWidth = (getWidth() - (padding*2)*mBars.size())/mBars.size(); @@ -136,20 +142,24 @@ public void onDraw(Canvas ca) { bar.setRegion(new Region(mRectangle.left-selectPadding, mRectangle.top-selectPadding, mRectangle.right+selectPadding, mRectangle.bottom+selectPadding)); // Draw x-axis label text - this.mPaint.setTextSize(20); + this.mPaint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity); int x = (int)(((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getName())/2)); - int y = getHeight()-5; + int y = (int) (getHeight()-3 * mContext.getResources().getDisplayMetrics().scaledDensity); canvas.drawText(bar.getName(), x, y, this.mPaint); // Draw value text if (mShowBarText){ - this.mPaint.setTextSize(40); + this.mPaint.setTextSize(VALUE_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity); this.mPaint.setColor(Color.WHITE); Rect r2 = new Rect(); this.mPaint.getTextBounds(bar.getValueString(), 0, 1, r2); - popup.setBounds((int)(((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString())/2))-14, mRectangle.top+(r2.top-r2.bottom)-32, (int)(((mRectangle.left+mRectangle.right)/2)+(this.mPaint.measureText(bar.getValueString())/2))+14, mRectangle.top); + + int boundLeft = (int) (((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString())/2)-10 * mContext.getResources().getDisplayMetrics().density); + int boundTop = (int) (mRectangle.top+(r2.top-r2.bottom)-18 * mContext.getResources().getDisplayMetrics().density); + int boundRight = (int)(((mRectangle.left+mRectangle.right)/2)+(this.mPaint.measureText(bar.getValueString())/2)+10 * mContext.getResources().getDisplayMetrics().density); + popup.setBounds(boundLeft, boundTop, boundRight, mRectangle.top); popup.draw(canvas); - canvas.drawText(bar.getValueString(), (int)(((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString()))/2), mRectangle.top-20, this.mPaint); + canvas.drawText(bar.getValueString(), (int)(((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString()))/2), mRectangle.top-VALUE_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity/2, this.mPaint); } if (mIndexSelected == count && mListener != null) { this.mPaint.setColor(Color.parseColor("#33B5E5")); @@ -185,10 +195,13 @@ public boolean onTouchEvent(MotionEvent event) { mIndexSelected = -1; } } + else if(event.getAction() == MotionEvent.ACTION_CANCEL) + mIndexSelected = -1; + count++; } - if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP){ + if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL){ mShouldUpdate = true; postInvalidate(); } diff --git a/HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java b/HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java index 9927a8d..1f9b5b6 100644 --- a/HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java +++ b/HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java @@ -147,10 +147,12 @@ public boolean onTouchEvent(MotionEvent event) { } } + else if(event.getAction() == MotionEvent.ACTION_CANCEL) + indexSelected = -1; count++; } - if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP){ + if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL){ postInvalidate(); } From 9b5ee75a71ff368b1a01b08b445b6b878e1d0189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Martin=C3=ADk?= Date: Sun, 17 Nov 2013 21:28:50 +0100 Subject: [PATCH 4/5] bitmap recycling to avoid potential memory leaks --- .../src/com/echo/holographlibrary/BarGraph.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java b/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java index 2da1607..bceda83 100644 --- a/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java +++ b/HoloGraphLibrary/src/com/echo/holographlibrary/BarGraph.java @@ -211,6 +211,15 @@ else if(event.getAction() == MotionEvent.ACTION_CANCEL) return true; } + @Override + protected void onDetachedFromWindow() + { + if(mFullImage != null) + mFullImage.recycle(); + + super.onDetachedFromWindow(); + } + public void setOnBarClickedListener(OnBarClickedListener listener) { this.mListener = listener; } From a348a5879f2b1fa8519e8acc68c56f32634e4c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Martin=C3=ADk?= Date: Sun, 17 Nov 2013 20:37:08 +0000 Subject: [PATCH 5/5] Edit to avoid conflict --- HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java b/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java index 020230d..8988d9c 100644 --- a/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java +++ b/HoloGraphLibrary/src/com/echo/holographlibrary/Bar.java @@ -55,10 +55,10 @@ public void setValue(float value) { public String getValueString() { - if (mValueString == null) { - return String.valueOf(mValue); - } else { + if (mValueString != null) { return mValueString; + } else { + return String.valueOf(mValue); } }