You don't really need to understand these classes to use the library, so I'll describe them just briefly here: I'll provide more examples illustrating the use of these classes later in the article.Ĭlasses GraphFunction, GraphPoints, and ScreenPoint are not only very simple, they are also internal to the library and have only package access. The example in Figure 1 uses points to describe the line graph and labels for the axis at the bottom, showing one-letter abbreviations for the months. Less formal introductions to lambda expressions are provided in a section of the latest version of the Java Tutorial in the JavaWorld article " Java programming with lambda expressions," and in a couple of articles by Brian Goetz, " State of the lambda" and " State of the lambda: Libraries edition." GraphLib classesĬlasses Point and Label are relatively simple: Point encapsulates a pair of double values representing a point in the x,y-plane, and Label encapsulates a double value and a string, where the double value represents a point on an axis and the string is used to label that point. Lambda expressions, also known as closures, function literals, or simply lambdas, describe a set of features defined in Java Specification Request (JSR) 335. The difference is that Function does not use any Java 8 features other than the annotation Removing this annotation is the only change necessary to make the Function interface compatible with earlier versions of Java. Note that this interface is roughly equivalent to Java 8's DoubleUnaryOperator, found in package. GraphLib's functional interfaceĪs shown in Listing 1, interface Function has only one abstract method and is, therefore, a functional interface. Note that I used Java 8 features such as functional interfaces and lambda expressions to develop and test the library, but it's relatively straightforward to modify these features for earlier versions of Java. Two of the remaining classes have very simple functionality, and the remainder are not hard to pick up.īelow I will describe the GraphLib interface and each of its eight classes. Three of those classes are internal to the library and have only package access, so you will not need to understand them in order to use GraphLib. GraphLib consists of one interface and eight classes. Get the source code for the open source Android graphing library introduced in this article. In fact, it's much simpler and easier to use. It's not the same graph library that my student used for his application. In this article I'll use my open source library, GraphLib, to demonstrate the basics of graphing mathematical functions in Android. (Although the data values shown in the line graph are hypothetical, they are realistic pertaining to the author of this article.) John I. It shows the goal weight as a green straight line near the bottom. The figure uses a red line-graph to show average monthly weights for the year 2017. Figure 1 illustrates how such an application might look on an Android phone. A key feature of the winning app, "Diabetes and Me," was the ability to graph daily sugar levels.Īs another example, consider a weight-tracking application that plots progress against a goal weight. I saw this for myself several years ago, when a former student of mine won first place in a student mobile app competition sponsored by the Charleston Defense Contractors Association. Graphs and data plots are wonderful tools for illustrating relationships, depicting data trends, and tracking goals in your Android applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |