Skip to content

Commit 40d95e7

Browse files
committed
* New wearable demo app (work in progress)
* Added more styleable attrs for XYPlot's domain and range label widgets * Added getWidth() and getHeight() methods to RectRegion * Added an XY scatter plot example to the demo app * Uprev to 0.9.5
1 parent 26bbcfc commit 40d95e7

File tree

21 files changed

+705
-39
lines changed

21 files changed

+705
-39
lines changed

androidplot-core/src/main/java/com/androidplot/util/AttrUtils.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,19 @@ private static void configureSizeMetric(TypedArray attrs, SizeMetric model, int
117117
getSizeLayoutType(attrs, typeAttr, model.getLayoutType());
118118

119119
model.set(value, sizeLayoutType);
120-
121-
/*if(attrs != null && attrs.hasValue(valueAttr)) {
122-
final int valueType = attrs.peekValue(valueAttr).type;
123-
124-
final SizeLayoutType sizeLayoutType =
125-
getSizeLayoutType(attrs, typeAttr, model.getLayoutType());
126-
127-
if (valueType == TypedValue.TYPE_DIMENSION) {
128-
model.set(attrs.getDimension(valueAttr, model.getValue()), sizeLayoutType);
129-
} else if (valueType == TypedValue.TYPE_FLOAT) {
130-
model.set(attrs.getFloat(valueAttr, model.getValue()), sizeLayoutType);
131-
} else {
132-
throw new IllegalArgumentException("Invalid size metric value type - must be float or dimension.");
133-
}
134-
}*/
135120
}
136121

137122
private static SizeLayoutType getSizeLayoutType(TypedArray attrs, int attr, SizeLayoutType defaultValue) {
138123
return SizeLayoutType.values()[attrs.getInt(attr, defaultValue.ordinal())];
139124
}
140125

141-
public static void configureWidget(TypedArray attrs, Widget widget, int xLayoutStyleAttr, int xLayoutValueAttr,
142-
int yLayoutStyleAttr, int yLayoutValueAttr, int anchorPositionAttr,
143-
int visibilityAttr) {
126+
public static void configureWidget(TypedArray attrs, Widget widget, int heightSizeLayoutTypeAttr, int heightAttr,
127+
int widthSizeLayoutTypeAttr, int widthAttr, int xLayoutStyleAttr,
128+
int xLayoutValueAttr, int yLayoutStyleAttr, int yLayoutValueAttr,
129+
int anchorPositionAttr, int visibilityAttr) {
144130
if(attrs != null) {
131+
configureSize(attrs, widget.getSize(), heightSizeLayoutTypeAttr,
132+
heightAttr, widthSizeLayoutTypeAttr, widthAttr);
145133
configurePositionMetrics(attrs, widget.getPositionMetrics(), xLayoutStyleAttr, xLayoutValueAttr,
146134
yLayoutStyleAttr, yLayoutValueAttr, anchorPositionAttr);
147135
widget.setVisible(attrs.getBoolean(visibilityAttr, widget.isVisible()));

androidplot-core/src/main/java/com/androidplot/xy/RectRegion.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
/**
2828
* RectRegion is just a rectangle with additional methods for determining
29-
* intersections with other RectRegion instances.
29+
* intersections with other RectRegion instances. RectRegion operates on
30+
* "native units" which are simply whatever unit type is passed into it by the user.
3031
*/
3132
public class RectRegion {
3233

@@ -138,6 +139,31 @@ public static List<RectRegion> regionsWithin(List<RectRegion> regions, Number mi
138139
return intersectingRegions;
139140
}
140141

142+
/**
143+
*
144+
* @return Width of this region, in native units
145+
*/
146+
public Number getWidth() {
147+
return distanceBetween(getMinX(), getMaxX());
148+
}
149+
150+
/**
151+
*
152+
* @return Height of this region, in native units
153+
*/
154+
public Number getHeight() {
155+
return distanceBetween(getMinY(), getMaxY());
156+
}
157+
158+
/**
159+
* Calculate the distance between two points in a single dimension.
160+
* @param x
161+
* @param y
162+
* @return
163+
*/
164+
private Number distanceBetween(Number x, Number y) {
165+
return Math.abs(x.doubleValue() - y.doubleValue());
166+
}
141167

142168
public Number getMinX() {
143169
return xLineRegion.getMinVal();

androidplot-core/src/main/java/com/androidplot/xy/XYPlot.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ protected void processAttrs(TypedArray attrs) {
281281
setRangeLabel(rangeLabelAttr);
282282
}
283283

284+
285+
// domainLabel size & position
286+
AttrUtils.configureWidget(attrs, getDomainLabelWidget(),
287+
R.styleable.xy_XYPlot_domainLabelHeightSizeLayoutType, R.styleable.xy_XYPlot_domainLabelHeight,
288+
R.styleable.xy_XYPlot_domainLabelWidthSizeLayoutType, R.styleable.xy_XYPlot_domainLabelWidth,
289+
R.styleable.xy_XYPlot_domainLabelLayoutStyleX, R.styleable.xy_XYPlot_domainLabelPositionX,
290+
R.styleable.xy_XYPlot_domainLabelLayoutStyleY, R.styleable.xy_XYPlot_domainLabelPositionY,
291+
R.styleable.xy_XYPlot_domainLabelAnchorPosition, R.styleable.xy_XYPlot_domainLabelVisible);
292+
293+
// rangeLabel size & position
294+
AttrUtils.configureWidget(attrs, getRangeLabelWidget(),
295+
R.styleable.xy_XYPlot_rangeLabelHeightSizeLayoutType, R.styleable.xy_XYPlot_rangeLabelHeight,
296+
R.styleable.xy_XYPlot_rangeLabelWidthSizeLayoutType, R.styleable.xy_XYPlot_rangeLabelWidth,
297+
R.styleable.xy_XYPlot_rangeLabelLayoutStyleX, R.styleable.xy_XYPlot_rangeLabelPositionX,
298+
R.styleable.xy_XYPlot_rangeLabelLayoutStyleY, R.styleable.xy_XYPlot_rangeLabelPositionY,
299+
R.styleable.xy_XYPlot_rangeLabelAnchorPosition, R.styleable.xy_XYPlot_rangeLabelVisible);
300+
284301
// domainLabelPaint
285302
AttrUtils.configureTextPaint(attrs, getDomainLabelWidget().getLabelPaint(),
286303
R.styleable.xy_XYPlot_domainLabelTextColor, R.styleable.xy_XYPlot_domainLabelTextSize);
@@ -319,7 +336,7 @@ protected void processAttrs(TypedArray attrs) {
319336
R.styleable.xy_XYPlot_domainOriginTickLabelTextSize);
320337

321338
// rangeOriginTickLabelPaint
322-
AttrUtils.configureTextPaint(attrs, getGraphWidget().getDomainOriginTickLabelPaint(),
339+
AttrUtils.configureTextPaint(attrs, getGraphWidget().getRangeOriginTickLabelPaint(),
323340
R.styleable.xy_XYPlot_rangeOriginTickLabelTextColor,
324341
R.styleable.xy_XYPlot_rangeOriginTickLabelTextSize);
325342

@@ -333,19 +350,13 @@ protected void processAttrs(TypedArray attrs) {
333350
R.styleable.xy_XYPlot_legendIconHeightSizeLayoutType, R.styleable.xy_XYPlot_legendIconHeight,
334351
R.styleable.xy_XYPlot_legendIconWidthSizeLayoutType, R.styleable.xy_XYPlot_legendIconWidth);
335352

336-
// legendSize
337-
AttrUtils.configureSize(attrs, getLegendWidget().getSize(),
338-
R.styleable.xy_XYPlot_legendHeightSizeLayoutType, R.styleable.xy_XYPlot_legendHeight,
339-
R.styleable.xy_XYPlot_legendWidthSizeLayoutType, R.styleable.xy_XYPlot_legendWidth);
340-
341-
// legendPosition
353+
// legend size & position
342354
AttrUtils.configureWidget(attrs, getLegendWidget(),
343-
R.styleable.xy_XYPlot_legendLayoutStyleX,
344-
R.styleable.xy_XYPlot_legendPositionX,
345-
R.styleable.xy_XYPlot_legendLayoutStyleY,
346-
R.styleable.xy_XYPlot_legendPositionY,
347-
R.styleable.xy_XYPlot_legendAnchorPosition,
348-
R.styleable.xy_XYPlot_legendVisible);
355+
R.styleable.xy_XYPlot_legendHeightSizeLayoutType, R.styleable.xy_XYPlot_legendHeight,
356+
R.styleable.xy_XYPlot_legendWidthSizeLayoutType, R.styleable.xy_XYPlot_legendWidth,
357+
R.styleable.xy_XYPlot_legendLayoutStyleX, R.styleable.xy_XYPlot_legendPositionX,
358+
R.styleable.xy_XYPlot_legendLayoutStyleY, R.styleable.xy_XYPlot_legendPositionY,
359+
R.styleable.xy_XYPlot_legendAnchorPosition, R.styleable.xy_XYPlot_legendVisible);
349360

350361
AttrUtils.configureLinePaint(attrs, getGraphWidget().getDomainGridLinePaint(),
351362
R.styleable.xy_XYPlot_graphDomainLineColor, R.styleable.xy_XYPlot_graphDomainLineThickness);

androidplot-core/src/main/res/values/attrs.xml

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@
2424

2525
<!-- values must match the ordinal of its corresponding
2626
element in the AnchorPosition enum. -->
27+
<attr name="domainLabelAnchorPosition" format="enum">
28+
<enum name="top_middle" value="0"/>
29+
<enum name="left_top" value="1"/>
30+
<enum name="left_middle" value="2"/>
31+
<enum name="left_bottom" value="3"/>
32+
<enum name="right_top" value="4"/>
33+
<enum name="right_middle" value="5"/>
34+
<enum name="right_bottom" value="6"/>
35+
<enum name="bottom_middle" value="7"/>
36+
<enum name="center" value="8"/>
37+
</attr>
38+
39+
<attr name="rangeLabelAnchorPosition" format="enum">
40+
<enum name="top_middle" value="0"/>
41+
<enum name="left_top" value="1"/>
42+
<enum name="left_middle" value="2"/>
43+
<enum name="left_bottom" value="3"/>
44+
<enum name="right_top" value="4"/>
45+
<enum name="right_middle" value="5"/>
46+
<enum name="right_bottom" value="6"/>
47+
<enum name="bottom_middle" value="7"/>
48+
<enum name="center" value="8"/>
49+
</attr>
50+
2751
<attr name="legendAnchorPosition" format="enum">
2852
<enum name="top_middle" value="0"/>
2953
<enum name="left_top" value="1"/>
@@ -36,6 +60,30 @@
3660
<enum name="center" value="8"/>
3761
</attr>
3862

63+
<attr name="domainLabelHeightSizeLayoutType" format="enum">
64+
<enum name="absolute" value="0"/>
65+
<enum name="relative" value="1"/>
66+
<enum name="fill" value="2"/>
67+
</attr>
68+
69+
<attr name="domainLabelWidthSizeLayoutType" format="enum">
70+
<enum name="absolute" value="0"/>
71+
<enum name="relative" value="1"/>
72+
<enum name="fill" value="2"/>
73+
</attr>
74+
75+
<attr name="rangeLabelHeightSizeLayoutType" format="enum">
76+
<enum name="absolute" value="0"/>
77+
<enum name="relative" value="1"/>
78+
<enum name="fill" value="2"/>
79+
</attr>
80+
81+
<attr name="rangeLabelWidthSizeLayoutType" format="enum">
82+
<enum name="absolute" value="0"/>
83+
<enum name="relative" value="1"/>
84+
<enum name="fill" value="2"/>
85+
</attr>
86+
3987
<attr name="legendHeightSizeLayoutType" format="enum">
4088
<enum name="absolute" value="0"/>
4189
<enum name="relative" value="1"/>
@@ -60,6 +108,42 @@
60108
<enum name="fill" value="2"/>
61109
</attr>
62110

111+
<attr name="domainLabelLayoutStyleX" format="enum">
112+
<enum name="absolute_from_left" value="0"/>
113+
<enum name="absolute_from_right" value="1"/>
114+
<enum name="absolute_from_center" value="2"/>
115+
<enum name="relative_from_left" value="3"/>
116+
<enum name="relative_from_right" value="4"/>
117+
<enum name="relative_from_center" value="5"/>
118+
</attr>
119+
120+
<attr name="domainLabelLayoutStyleY" format="enum">
121+
<enum name="absolute_from_top" value="0"/>
122+
<enum name="absolute_from_bottom" value="1"/>
123+
<enum name="absolute_from_center" value="2"/>
124+
<enum name="relative_from_top" value="3"/>
125+
<enum name="relative_from_bottom" value="4"/>
126+
<enum name="relative_from_center" value="5"/>
127+
</attr>
128+
129+
<attr name="rangeLabelLayoutStyleX" format="enum">
130+
<enum name="absolute_from_left" value="0"/>
131+
<enum name="absolute_from_right" value="1"/>
132+
<enum name="absolute_from_center" value="2"/>
133+
<enum name="relative_from_left" value="3"/>
134+
<enum name="relative_from_right" value="4"/>
135+
<enum name="relative_from_center" value="5"/>
136+
</attr>
137+
138+
<attr name="rangeLabelLayoutStyleY" format="enum">
139+
<enum name="absolute_from_top" value="0"/>
140+
<enum name="absolute_from_bottom" value="1"/>
141+
<enum name="absolute_from_center" value="2"/>
142+
<enum name="relative_from_top" value="3"/>
143+
<enum name="relative_from_bottom" value="4"/>
144+
<enum name="relative_from_center" value="5"/>
145+
</attr>
146+
63147
<attr name="legendLayoutStyleX" format="enum">
64148
<enum name="absolute_from_left" value="0"/>
65149
<enum name="absolute_from_right" value="1"/>
@@ -91,12 +175,36 @@
91175

92176
<!-- XYPlot -->
93177
<declare-styleable name="xy.XYPlot" parent="@style/Plot">
178+
179+
<!-- domain label -->
94180
<attr name="domainLabel" format="string"/>
95181
<attr name="domainLabelTextColor" format="color"/>
96182
<attr name="domainLabelTextSize" format="dimension"/>
183+
<attr name="domainLabelHeightSizeLayoutType"/>
184+
<attr name="domainLabelWidthSizeLayoutType"/>
185+
<attr name="domainLabelHeight" format="dimension|float"/>
186+
<attr name="domainLabelWidth" format="dimension|float"/>
187+
<attr name="domainLabelLayoutStyleX"/>
188+
<attr name="domainLabelLayoutStyleY"/>
189+
<attr name="domainLabelPositionX" format="dimension|float"/>
190+
<attr name="domainLabelPositionY" format="dimension|float"/>
191+
<attr name="domainLabelAnchorPosition"/>
192+
<attr name="domainLabelVisible" format="boolean"/>
193+
194+
<!-- range label -->
97195
<attr name="rangeLabel" format="string"/>
98196
<attr name="rangeLabelTextColor" format="color"/>
99197
<attr name="rangeLabelTextSize" format="dimension"/>
198+
<attr name="rangeLabelHeightSizeLayoutType"/>
199+
<attr name="rangeLabelWidthSizeLayoutType"/>
200+
<attr name="rangeLabelHeight" format="dimension|float"/>
201+
<attr name="rangeLabelWidth" format="dimension|float"/>
202+
<attr name="rangeLabelLayoutStyleX"/>
203+
<attr name="rangeLabelLayoutStyleY"/>
204+
<attr name="rangeLabelPositionX" format="dimension|float"/>
205+
<attr name="rangeLabelPositionY" format="dimension|float"/>
206+
<attr name="rangeLabelAnchorPosition"/>
207+
<attr name="rangeLabelVisible" format="boolean"/>
100208

101209
<!-- graph widget margin / padding -->
102210
<attr name="graphMarginTop" format="dimension"/>
@@ -132,21 +240,23 @@
132240
<attr name="rangeOriginTickLabelTextColor" format="color"/>
133241
<attr name="domainOriginTickLabelTextColor" format="color"/>
134242
<attr name="gridBackgroundColor" format="color"/>
243+
244+
<!-- legend widget -->
135245
<attr name="legendHeightSizeLayoutType"/>
136246
<attr name="legendWidthSizeLayoutType"/>
137247
<attr name="legendHeight" format="dimension|float"/>
138248
<attr name="legendWidth" format="dimension|float"/>
249+
<attr name="legendLayoutStyleX"/>
250+
<attr name="legendLayoutStyleY"/>
251+
<attr name="legendPositionX" format="dimension|float"/>
252+
<attr name="legendPositionY" format="dimension|float"/>
253+
<attr name="legendAnchorPosition"/>
139254
<attr name="legendTextSize" format="dimension"/>
140255
<attr name="legendTextColor" format="color"/>
141256
<attr name="legendIconHeightSizeLayoutType"/>
142257
<attr name="legendIconWidthSizeLayoutType"/>
143258
<attr name="legendIconHeight" format="dimension|float"/>
144259
<attr name="legendIconWidth" format="dimension|float"/>
145-
<attr name="legendPositionX" format="dimension|float"/>
146-
<attr name="legendPositionY" format="dimension|float"/>
147-
<attr name="legendLayoutStyleX"/>
148-
<attr name="legendLayoutStyleY"/>
149-
<attr name="legendAnchorPosition"/>
150260
<attr name="legendVisible" format="boolean"/>
151261
</declare-styleable>
152262

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ ext {
1010
theCompileSdkVersion = 23
1111
theTargetSdkVersion = 23
1212
theMinSdkVersion = 4
13-
theVersionName = '0.9.4'
14-
theVersionCode = 10
13+
theVersionName = '0.9.5'
14+
theVersionCode = 11
1515
}
1616

1717
buildscript {

demoapp-wearable/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

demoapp-wearable/build.gradle

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2015 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+
buildscript {
18+
repositories {
19+
jcenter()
20+
}
21+
dependencies {
22+
classpath 'com.android.tools.build:gradle:1.2.3'
23+
}
24+
}
25+
apply plugin: 'com.android.application'
26+
27+
repositories {
28+
jcenter()
29+
}
30+
31+
android {
32+
compileSdkVersion 23
33+
buildToolsVersion "23.0.2"
34+
35+
defaultConfig {
36+
applicationId "com.androidplot.demo.wearable"
37+
minSdkVersion 20
38+
targetSdkVersion 23
39+
versionCode 1
40+
versionName "1.0"
41+
}
42+
43+
compileOptions {
44+
sourceCompatibility JavaVersion.VERSION_1_6
45+
targetCompatibility JavaVersion.VERSION_1_6
46+
}
47+
buildTypes {
48+
release {
49+
minifyEnabled false
50+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
51+
}
52+
}
53+
}
54+
55+
dependencies {
56+
compile project(':androidplot-core')
57+
compile 'com.google.android.support:wearable:1.3.0'
58+
compile 'com.google.android.gms:play-services-wearable:8.3.0'
59+
}

0 commit comments

Comments
 (0)