Skip to content

Commit 254a16f

Browse files
committed
Fixed issue concerning Activity attribute 'screenSize|orientation' (issue PhilJay#15, PhilJay#114, PhilJay#153).
1 parent 2297afc commit 254a16f

File tree

7 files changed

+60
-39
lines changed

7 files changed

+60
-39
lines changed

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
7777
// mChart.setDrawBarShadow(true);
7878

7979
mChart.setUnit(" €");
80-
80+
8181
// mChart.setDrawXLabels(false);
8282

8383
mChart.setDrawGridBackground(false);
@@ -265,7 +265,7 @@ private void setData(int count, float range) {
265265

266266
for (int i = 0; i < count; i++) {
267267
float mult = (range + 1);
268-
float val = (float) (Math.random() * mult) - 50;
268+
float val = (float) (Math.random() * mult);
269269
yVals1.add(new BarEntry(val, i));
270270
}
271271

MPChartExample/src/com/xxmassdeveloper/mpchartexample/MyMarkerView.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,45 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.content.Context;
5+
import android.view.View;
6+
import android.view.View.OnClickListener;
57
import android.widget.TextView;
8+
import android.widget.Toast;
69

710
import com.github.mikephil.charting.data.CandleEntry;
811
import com.github.mikephil.charting.data.Entry;
912
import com.github.mikephil.charting.utils.MarkerView;
1013
import com.github.mikephil.charting.utils.Utils;
1114

12-
public class MyMarkerView extends MarkerView {
15+
public class MyMarkerView extends MarkerView implements OnClickListener {
1316

1417
private TextView tvContent;
1518

1619
public MyMarkerView(Context context, int layoutResource) {
1720
super(context, layoutResource);
1821

1922
tvContent = (TextView) findViewById(R.id.tvContent);
23+
setOnClickListener(this);
2024
}
2125

2226
// callbacks everytime the MarkerView is redrawn, can be used to update the
2327
// content
2428
@Override
2529
public void refreshContent(Entry e, int dataSetIndex) {
26-
27-
if(e instanceof CandleEntry) {
28-
30+
31+
if (e instanceof CandleEntry) {
32+
2933
CandleEntry ce = (CandleEntry) e;
30-
34+
3135
tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
3236
} else {
33-
37+
3438
tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
3539
}
3640
}
41+
42+
@Override
43+
public void onClick(View v) {
44+
Toast.makeText(getContext(), "Marker clicked!", Toast.LENGTH_SHORT).show();
45+
}
3746
}

MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ protected boolean isOffContentBottom(float p) {
10401040

10411041
@Override
10421042
public boolean onTouchEvent(MotionEvent event) {
1043+
super.onTouchEvent(event);
10431044

10441045
if (mListener == null || mDataNotSet)
10451046
return false;

MPChartLib/src/com/github/mikephil/charting/charts/Chart.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ protected void onDraw(Canvas canvas) {
488488

489489
if (mDrawBitmap == null || mDrawCanvas == null) {
490490

491-
// use RGB_565 for best performance
492491
mDrawBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
493492
Bitmap.Config.ARGB_4444);
494493
mDrawCanvas = new Canvas(mDrawBitmap);
@@ -2238,6 +2237,15 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
22382237

22392238
@Override
22402239
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
2240+
2241+
// create a new bitmap with the new dimensions
2242+
mDrawBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
2243+
mDrawCanvas = new Canvas(mDrawBitmap);
2244+
2245+
// prepare content rect and matrices
2246+
prepareContentRect();
2247+
prepare();
2248+
22412249
super.onSizeChanged(w, h, oldw, oldh);
22422250
}
22432251

MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,16 @@ protected void calcMinMax(boolean fixedValues) {
176176
@Override
177177
protected void calculateOffsets() {
178178

179-
// setup offsets for legend
180-
if (mDrawLegend) {
179+
float legendRight = 0f, legendBottom = 0f;
181180

182-
float legendRight = 0f, legendBottom = 0f;
181+
if (mDrawLegend) {
183182

184183
if (mLegend == null)
185184
return;
186185

187-
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART
186+
if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART
188187
|| mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART_CENTER) {
189-
188+
190189
// this is the space between the legend and the chart
191190
float spacing = Utils.convertDpToPixel(13f);
192191

@@ -202,21 +201,23 @@ protected void calculateOffsets() {
202201

203202
legendBottom = mLegendLabelPaint.getTextSize() * 4f;
204203
}
205-
204+
206205
mLegend.setOffsetBottom(legendBottom);
207206
mLegend.setOffsetRight(legendRight);
207+
}
208208

209-
float min = Utils.convertDpToPixel(11f);
209+
float min = Utils.convertDpToPixel(11f);
210210

211-
mLegend.setOffsetTop(min);
212-
mLegend.setOffsetLeft(min);
211+
mLegend.setOffsetTop(min);
212+
mLegend.setOffsetLeft(min);
213213

214-
mOffsetTop = min;
215-
mOffsetRight = Math.max(min, legendRight);
216-
mOffsetBottom = Math.max(min, legendBottom);
214+
mOffsetLeft = min;
215+
mOffsetTop = min;
216+
mOffsetRight = Math.max(min, legendRight);
217+
mOffsetBottom = Math.max(min, legendBottom);
218+
219+
applyCalculatedOffsets();
217220

218-
applyCalculatedOffsets();
219-
}
220221
}
221222

222223
/**

MPChartLib/src/com/github/mikephil/charting/charts/RadarChart.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ public void prepare() {
109109
@Override
110110
protected void calculateOffsets() {
111111

112+
float legendRight = 0f, legendBottom = 0f;
113+
112114
// setup offsets for legend
113115
if (mDrawLegend) {
114116

115-
float legendRight = 0f, legendBottom = 0f;
116-
117117
if (mLegend == null)
118118
return;
119119

@@ -124,7 +124,8 @@ protected void calculateOffsets() {
124124
float spacing = Utils.convertDpToPixel(8f);
125125

126126
legendRight = mLegend.getMaximumEntryLength(mLegendLabelPaint)
127-
+ mLegend.getFormSize() + mLegend.getFormToTextSpace() + spacing + mXLabels.mLabelWidth;
127+
+ mLegend.getFormSize() + mLegend.getFormToTextSpace() + spacing
128+
+ mXLabels.mLabelWidth;
128129

129130
mLegendLabelPaint.setTextAlign(Align.LEFT);
130131

@@ -137,23 +138,24 @@ protected void calculateOffsets() {
137138

138139
mLegend.setOffsetBottom(legendBottom);
139140
mLegend.setOffsetRight(legendRight);
141+
}
140142

141-
// all required offsets are calculated, now find largest and apply
142-
float min = Utils.convertDpToPixel(11f);
143+
// all required offsets are calculated, now find largest and apply
144+
float min = Utils.convertDpToPixel(11f);
143145

144-
mOffsetBottom = Math.max(mXLabels.mLabelWidth, min);
145-
mOffsetTop = Math.max(mXLabels.mLabelWidth, min);
146-
mOffsetRight = Math.max(legendRight, min);
147-
mOffsetLeft = Math.max(mXLabels.mLabelWidth, min);
146+
mOffsetBottom = Math.max(mXLabels.mLabelWidth, min);
147+
mOffsetTop = Math.max(mXLabels.mLabelWidth, min);
148+
mOffsetRight = Math.max(legendRight, min);
149+
mOffsetLeft = Math.max(mXLabels.mLabelWidth, min);
148150

149-
mOffsetBottom = Math.max(mOffsetBottom, legendBottom);
150-
mOffsetRight = Math.max(mOffsetRight, legendRight / 3f * 2f);
151+
mOffsetBottom = Math.max(mOffsetBottom, legendBottom);
152+
mOffsetRight = Math.max(mOffsetRight, legendRight / 3f * 2f);
151153

152-
mLegend.setOffsetTop(min);
153-
mLegend.setOffsetLeft(min);
154+
mLegend.setOffsetTop(min);
155+
mLegend.setOffsetLeft(min);
156+
157+
applyCalculatedOffsets();
154158

155-
applyCalculatedOffsets();
156-
}
157159
}
158160

159161
@Override

MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public boolean onSingleTapUp(MotionEvent e) {
436436
mChart.highlightTouch(h);
437437
}
438438

439-
return true;
439+
return super.onSingleTapUp(e);
440440
}
441441

442442
@Override

0 commit comments

Comments
 (0)