Android Open Source - AndroidGraph Sine Wave






From Project

Back to project page AndroidGraph.

License

The source code is released under:

MIT License

If you think the Android project AndroidGraph listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nimble.android_graph.Graph;
/*from  w w w .java 2  s .c  o m*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.SystemClock;
import android.util.AttributeSet;

import com.nimble.android_graph.Graph_Base.Point;

/**
 * Example graph. Displays a real time sine wave.
 * Created by Michael Leith on 18/07/2014.
 */
public class SineWave extends LineGraph {

    double t = 0.1;

    long prevTime = 0;

    public SineWave(Context context)
    {
        super(context);
        dataAdjusted = true;
        useGrid = false;
        Line line = new Line();

        axisColour = Color.parseColor("#000000");
        labelColour = Color.parseColor("#000000");

        line.setColour(Color.parseColor("#33b5e5"));
        line.setShadow(Color.parseColor("#0099cc"));
        line.distBetweenPoints = 2f;
        addLine(line);

        prevTime = SystemClock.elapsedRealtime();
    }

    public SineWave(Context context, String xLabel, String yLabel)
    {
        this(context);
        setLabels(xLabel, yLabel);
    }

    public SineWave(Context context, AttributeSet attrs)
    {
        this(context);
        setLabels("Time", "Current");
        setWillNotDraw(false);
        this.start();
    }

    public SineWave(Context context, String xLabel, String yLabel, boolean useShadow)
    {
        this(context, xLabel, yLabel);
        lines.get(0).setUseShadow(useShadow);
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        float y = 50* (float) Math.sin(t) + 80;

        addPointToLine(0, new Point(lines.get(0).getNextX(), y));
        t +=0.1;

        super.onDraw(canvas);
        long currentTime = SystemClock.elapsedRealtime();

        paint.setColor(axisColour);
        canvas.drawText(Float.toString ( 1000f / (float) (currentTime - prevTime) ), 500, 100, paint);
        prevTime = currentTime;
    }
}




Java Source Code List

Nimble.com.androidgraph.ApplicationTest.java
com.nimble.android_graph.Activities.FragmentList.java
com.nimble.android_graph.Activities.GraphActivity.java
com.nimble.android_graph.Activities.GraphFragment.java
com.nimble.android_graph.Activities.GroupsFragment.java
com.nimble.android_graph.Graph.CurveGraph.java
com.nimble.android_graph.Graph.LineGraph.java
com.nimble.android_graph.Graph.Line.java
com.nimble.android_graph.Graph.ScatterGraph.java
com.nimble.android_graph.Graph.SineWave.java
com.nimble.android_graph.Graph_Base.Coord2d.java
com.nimble.android_graph.Graph_Base.GraphDataSettings.java
com.nimble.android_graph.Graph_Base.GraphDrawBackground.java
com.nimble.android_graph.Graph_Base.GraphRelateToScreen.java
com.nimble.android_graph.Graph_Base.GraphThreading.java
com.nimble.android_graph.Graph_Base.GraphTouchEvent.java
com.nimble.android_graph.Graph_Base.GraphViewDimensions.java
com.nimble.android_graph.Graph_Base.GraphView.java
com.nimble.android_graph.Graph_Base.Point.java
com.nimble.android_graph.Graph_Base.Range2d.java
com.nimble.android_graph.Graph.sine_scatter.java
com.nimble.android_graph.generics.Methods.java
com.nimble.android_graph.generics.ViewManipulators.java
com.nimble.android_graph.generics.testingSuite.java