Skip to content

Commit 2dbb2d7

Browse files
author
Nick Fellows
committed
Merged in nick (pull request halfhp#55)
XYGraphWidget Refactor
2 parents 0a2c4d5 + 60e0637 commit 2dbb2d7

119 files changed

Lines changed: 3896 additions & 3587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
11
# Androidplot
2-
A library for creating dynamic and static charts in Android apps. It’s designed from the ground up for Android, compatible with all versions of Android from 1.6 onward and is used by over [1,000 apps](http://www.appbrain.com/stats/libraries/details/androidplot/androidplot) on Google Play.
2+
3+
![image](docs/images/preview.png)
4+
5+
A library for creating dynamic and static charts in Android apps. It’s designed from the ground up for Android,
6+
compatible with all versions of Android from 1.6 onward and is **used by over
7+
[1,000 apps](http://www.appbrain.com/stats/libraries/details/androidplot/androidplot) on Google Play**.
38

49
**Supports:**
10+
511
* Line Charts
612
* Scatter Charts
713
* Bar Charts
814
* Pie Charts
915
* Step Charts
10-
* (NEW) Candlestick Charts
11-
12-
##### Website http://androidplot.com
13-
##### Bitbucket Repo: (Primary) https://bitbucket.org/androidplot/androidplot
14-
##### Github Repo: https://github.com/halfhp/androidplot
15-
16-
![image](http://androidplot.com/wp-content/uploads/2012/11/simplexyscreen.png)
17-
18-
## Demo App
19-
[Play Store Listing](https://play.google.com/store/apps/details?id=com.androidplot.demos&hl=en)
20-
21-
[Source Code](https://bitbucket.org/androidplot/androidplot/src/1538c5dfa56aed0d2cfdcbc7cdc6173e605543cd/demoapp/?at=master)
22-
23-
## Usage
24-
To use the library in your gradle project add the following to your `build.gradle`:
16+
* Candlestick Charts
2517

26-
```groovy
27-
dependencies {
28-
compile 'com.androidplot:androidplot-core:0.9.8'
29-
}
30-
```
18+
**Links:**
3119

32-
#### Quickstart
33-
http://androidplot.com/docs/quickstart
20+
* [Main Website](http://androidplot.com)
21+
* [Bitbucket Repo (primary)](https://bitbucket.org/androidplot/androidplot)
22+
* [Github Repo](https://github.com/halfhp/androidplot)
23+
* [Demo App (Google Play Store)](https://play.google.com/store/apps/details?id=com.androidplot.demos&hl=en)
24+
* [Demo App Soure Code](https://bitbucket.org/androidplot/androidplot/src/1538c5dfa56aed0d2cfdcbc7cdc6173e605543cd/demoapp/?at=master)
25+
* [Bug Tracker (Jira)](https://androidplot.jira.com)
26+
* [Contributing Source Code](http://androidplot.com/docs/working-with-androidplot-source/)
3427

35-
#### Documentation
36-
http://androidplot.com/docs/
28+
# Usage
3729

38-
## Bugs
39-
We use Jira as our issue tracker - report bugs on https://androidplot.jira.com
30+
* **[Quickstart](docs/quickstart.md)**
31+
* [Androidplot 1.0 full documentation](docs/index.md)
32+
* [Documentation for older releases](http://androidplot.com/docs/)
4033

41-
## Help
34+
# Help
4235
Technical questions should be posted using the [androidplot tag](http://stackoverflow.com/questions/tagged/androidplot) on Stack Overflow. For everything else use the [Google Groups forum](https://groups.google.com/d/forum/androidplot).
4336

44-
## Contribute
45-
http://androidplot.com/docs/working-with-androidplot-source/
37+
# License
38+
Androidplot has been made available under the Apache 2.0 license:
4639

47-
## License
48-
Copyright 2015 AndroidPlot.com
40+
Copyright 2016 Androidplot.com
4941

5042
Licensed under the Apache License, Version 2.0 (the "License");
5143
you may not use this file except in compliance with the License.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016 AndroidPlot.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.androidplot;
18+
19+
import android.graphics.Paint;
20+
21+
public interface LineLabelFormatter {
22+
23+
24+
/**
25+
*
26+
* @param value The value being rendered by this formatter.
27+
* @return Paint instance that should be used to render the specified value.
28+
*/
29+
Paint getPaint(Number value);
30+
}

androidplot-core/src/main/java/com/androidplot/Plot.java

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
import com.androidplot.exception.PlotRenderException;
2828
import com.androidplot.ui.*;
2929
import com.androidplot.ui.Formatter;
30-
import com.androidplot.ui.TextOrientationType;
30+
import com.androidplot.ui.TextOrientation;
3131
import com.androidplot.ui.widget.TextLabelWidget;
3232
import com.androidplot.ui.SeriesRenderer;
3333
import com.androidplot.util.AttrUtils;
3434
import com.androidplot.util.Configurator;
3535
import com.androidplot.util.DisplayDimensions;
3636
import com.androidplot.util.PixelUtils;
37-
import com.androidplot.ui.XLayoutStyle;
38-
import com.androidplot.ui.YLayoutStyle;
37+
import com.androidplot.ui.HorizontalPositioning;
38+
import com.androidplot.ui.VerticalPositioning;
3939

4040
import java.lang.reflect.Field;
4141
import java.util.*;
@@ -44,7 +44,7 @@
4444
* Base class for all Plot implementations.
4545
*/
4646
public abstract class Plot<SeriesType extends Series, FormatterType extends Formatter, RendererType extends SeriesRenderer>
47-
extends View implements Resizable{
47+
extends View implements Resizable {
4848
private static final String TAG = Plot.class.getName();
4949
private static final String XML_ATTR_PREFIX = "androidplot";
5050
private static final String BASE_PACKAGE = "com.androidplot.";
@@ -70,6 +70,18 @@ public SeriesRegistry<SeriesType, FormatterType> getSeriesRegistry() {
7070
return seriesRegistry;
7171
}
7272

73+
public TextLabelWidget getTitle() {
74+
return title;
75+
}
76+
77+
public void setTitle(TextLabelWidget title) {
78+
this.title = title;
79+
}
80+
81+
public void setTitle(String title) {
82+
getTitle().setText(title);
83+
}
84+
7385
public enum BorderStyle {
7486
ROUNDED,
7587
SQUARE,
@@ -131,7 +143,7 @@ public enum RenderMode {
131143
private Paint borderPaint;
132144
private Paint backgroundPaint;
133145
private LayoutManager layoutManager;
134-
private TextLabelWidget titleWidget;
146+
private TextLabelWidget title;
135147
private DisplayDimensions displayDims = new DisplayDimensions();
136148
private RenderMode renderMode = RenderMode.USE_MAIN_THREAD;
137149
private final BufferedCanvas pingPong = new BufferedCanvas();
@@ -167,7 +179,7 @@ public enum RenderMode {
167179
* Any rendering that utilizes a buffer from this class should synchronize rendering on the instance of this class
168180
* that is being used.
169181
*/
170-
private class BufferedCanvas {
182+
private static class BufferedCanvas {
171183
private volatile Bitmap bgBuffer; // all drawing is done on this buffer.
172184
private volatile Bitmap fgBuffer;
173185
private Canvas canvas = new Canvas();
@@ -192,6 +204,14 @@ public synchronized void resize(int h, int w) {
192204
}
193205
}
194206

207+
public void recycle() {
208+
bgBuffer.recycle();
209+
bgBuffer = null;
210+
211+
fgBuffer.recycle();
212+
fgBuffer = null;
213+
System.gc();
214+
}
195215

196216
/**
197217
* Get a Canvas for drawing. Actual drawing should be synchronized on the instance
@@ -235,7 +255,7 @@ public Plot(Context context, String title, RenderMode mode) {
235255
super(context);
236256
this.renderMode = mode;
237257
init(null, null, 0);
238-
setTitle(title);
258+
getTitle().setText(title);
239259
}
240260

241261

@@ -321,20 +341,20 @@ protected void onAfterConfig() {
321341
private void init(Context context, AttributeSet attrs, int defStyle) {
322342
PixelUtils.init(getContext());
323343
layoutManager = new LayoutManager();
324-
titleWidget = new TextLabelWidget(layoutManager, new Size(25,
325-
SizeLayoutType.ABSOLUTE, 100,
326-
SizeLayoutType.ABSOLUTE),
327-
TextOrientationType.HORIZONTAL);
328-
titleWidget.position(0, XLayoutStyle.RELATIVE_TO_CENTER, 0,
329-
YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.TOP_MIDDLE);
344+
title = new TextLabelWidget(layoutManager, new Size(25,
345+
SizeMode.ABSOLUTE, 100,
346+
SizeMode.ABSOLUTE),
347+
TextOrientation.HORIZONTAL);
348+
title.position(0, HorizontalPositioning.RELATIVE_TO_CENTER, 0,
349+
VerticalPositioning.ABSOLUTE_FROM_TOP, Anchor.TOP_MIDDLE);
330350

331351
// initialize attr defaults:
332-
titleWidget.getLabelPaint().setTextSize(
352+
title.getLabelPaint().setTextSize(
333353
PixelUtils.spToPix(DEFAULT_TITLE_WIDGET_TEXT_SIZE_SP));
334354

335355
onPreInit();
336356
// make sure the title widget is always the topmost widget:
337-
layoutManager.moveToTop(titleWidget);
357+
layoutManager.moveToTop(title);
338358
if(context != null && attrs != null) {
339359
loadAttrs(attrs, defStyle);
340360
}
@@ -368,6 +388,7 @@ public void run() {
368388
}
369389
}
370390
}
391+
pingPong.recycle();
371392
}
372393
});
373394
}
@@ -404,13 +425,13 @@ private void processBaseAttrs(TypedArray attrs) {
404425
R.styleable.Plot_paddingBottom, R.styleable.Plot_paddingLeft, R.styleable.Plot_paddingRight);
405426

406427
// title
407-
setTitle(attrs.getString(R.styleable.Plot_label));
408-
getTitleWidget().getLabelPaint().setTextSize(
409-
attrs.getDimension(R.styleable.Plot_labelTextSize,
428+
getTitle().setText(attrs.getString(R.styleable.Plot_title));
429+
getTitle().getLabelPaint().setTextSize(
430+
attrs.getDimension(R.styleable.Plot_titleTextSize,
410431
PixelUtils.spToPix(DEFAULT_TITLE_WIDGET_TEXT_SIZE_SP)));
411432

412-
getTitleWidget().getLabelPaint().setColor(attrs.getColor(
413-
R.styleable.Plot_labelTextColor, getTitleWidget().getLabelPaint().getColor()));
433+
getTitle().getLabelPaint().setColor(attrs.getColor(
434+
R.styleable.Plot_titleTextColor, getTitle().getLabelPaint().getColor()));
414435

415436
getBackgroundPaint().setColor(
416437
attrs.getColor(R.styleable.Plot_backgroundColor, getBackgroundPaint().getColor()));
@@ -878,22 +899,6 @@ protected void drawRect(Canvas canvas, RectF dims, Paint paint) {
878899
}
879900
}
880901

881-
/**
882-
*
883-
* @return The displayed title of this Plot.
884-
*/
885-
public String getTitle() {
886-
return getTitleWidget().getText();
887-
}
888-
889-
/**
890-
*
891-
* @param title The title to display on this Plot.
892-
*/
893-
public void setTitle(String title) {
894-
titleWidget.setText(title);
895-
}
896-
897902
public LayoutManager getLayoutManager() {
898903
return layoutManager;
899904
}
@@ -902,14 +907,6 @@ public void setLayoutManager(LayoutManager layoutManager) {
902907
this.layoutManager = layoutManager;
903908
}
904909

905-
public TextLabelWidget getTitleWidget() {
906-
return titleWidget;
907-
}
908-
909-
public void setTitleWidget(TextLabelWidget titleWidget) {
910-
this.titleWidget = titleWidget;
911-
}
912-
913910
public Paint getBackgroundPaint() {
914911
return backgroundPaint;
915912
}

androidplot-core/src/main/java/com/androidplot/PlotListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface PlotListener {
3131
* @param source
3232
* @param canvas
3333
*/
34-
public void onBeforeDraw(Plot source, Canvas canvas);
34+
void onBeforeDraw(Plot source, Canvas canvas);
3535

3636
/**
3737
* Fired immediately after the Plot "source" is drawn onto canvas.
@@ -41,5 +41,5 @@ public interface PlotListener {
4141
* @param source
4242
* @param canvas
4343
*/
44-
public void onAfterDraw(Plot source, Canvas canvas);
44+
void onAfterDraw(Plot source, Canvas canvas);
4545
}

androidplot-core/src/main/java/com/androidplot/Series.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public interface Series {
2525
*
2626
* @return The title of this Series.
2727
*/
28-
public String getTitle();
28+
String getTitle();
2929

3030
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2016 AndroidPlot.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.androidplot;
18+
19+
import android.graphics.Color;
20+
import android.graphics.Paint;
21+
import com.androidplot.util.PixelUtils;
22+
23+
/**
24+
* A basic implementation of a {@link LineLabelFormatter}.
25+
*/
26+
public class SimpleLineLabelFormatter implements LineLabelFormatter {
27+
28+
private static final int DEFAULT_TEXT_SIZE_SP = 12;
29+
private static final int DEFAULT_STROKE_SIZE_DP = 2;
30+
private Paint paint;
31+
32+
public SimpleLineLabelFormatter() {
33+
this(new Paint());
34+
getPaint().setColor(Color.WHITE);
35+
getPaint().setTextSize(PixelUtils.spToPix(DEFAULT_TEXT_SIZE_SP));
36+
getPaint().setStrokeWidth(PixelUtils.dpToPix(DEFAULT_STROKE_SIZE_DP));
37+
}
38+
39+
public SimpleLineLabelFormatter(int color) {
40+
this();
41+
getPaint().setColor(color);
42+
}
43+
44+
public SimpleLineLabelFormatter(Paint paint) {
45+
this.paint = paint;
46+
}
47+
48+
public Paint getPaint() {
49+
return paint;
50+
}
51+
52+
public void setPaint(Paint paint) {
53+
this.paint = paint;
54+
}
55+
56+
@Override
57+
public Paint getPaint(Number value) {
58+
return getPaint();
59+
}
60+
}

0 commit comments

Comments
 (0)