Android Open Source - SurgeTracker Surge Collection






From Project

Back to project page SurgeTracker.

License

The source code is released under:

MIT License

If you think the Android project SurgeTracker 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.bklimt.surgetracker.model;
/*from w  w w.j  a  va 2s  .co  m*/
import com.bklimt.surgetracker.backbone.Collection;
import com.bklimt.surgetracker.backbone.CollectionListener;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewDataInterface;

import java.util.Comparator;
import java.util.logging.Logger;

import bolts.Continuation;
import bolts.Task;

public class SurgeCollection extends Collection<Surge> {
    private Logger log = Logger.getLogger(getClass().getName());

    public SurgeCollection() {
        setComparator(new Comparator<Surge>() {
            @Override
            public int compare(Surge lhs, Surge rhs) {
                return rhs.getStart().compareTo(lhs.getStart());
            }
        });

        addListener(new CollectionListener<Collection<Surge>, Surge>() {
            @Override
            public void onAdd(Collection<Surge> collection, Surge item, int position) {
                updatePrevious();
            }

            @Override
            public void onRemove(Collection<Surge> collection, Surge item) {
                updatePrevious();
            }

            @Override
            public void onChanged(Surge model, String key, Object oldValue, Object newValue) {
                updatePrevious();
            }
        });
    }

    private void updatePrevious() {
        synchronized (lock) {
            Surge previous = null;
            for (int i = size() - 1; i >= 0; --i) {
                Surge current = get(i);
                current.setPrevious(previous);
                previous = current;
            }
        }
    }

    public GraphViewDataInterface[] getDurationGraphViewData() {
        synchronized (lock) {
            int size = size();
            final GraphViewDataInterface[] data = new GraphViewDataInterface[size];
            for (int i = 0; i < size; ++i) {
                Surge surge = get((size - i) - 1);
                long time = surge.getStart().getTime();
                double duration = surge.getDurationSeconds();
                data[i] = new GraphView.GraphViewData(time, duration);
            }
            return data;
        }
    }

    public GraphViewDataInterface[] getFrequencyGraphViewData() {
        synchronized (lock) {
            int size = size();
            final GraphViewDataInterface[] data = new GraphViewDataInterface[size];
            for (int i = 0; i < size; ++i) {
                Surge surge = get((size - i) - 1);
                long time = surge.getStart().getTime();
                double frequency = -surge.getSecondsSincePrevious();
                data[i] = new GraphView.GraphViewData(time, frequency);
            }
            return data;
        }
    }

    /*
    public SurgeCollection(JSONArray array) {
        for (int i = 0; i < array.length(); ++i) {
            add(new Surge(array.optJSONObject(i)));
        }
    }
    */
}




Java Source Code List

com.bklimt.surgetracker.ApplicationTest.java
com.bklimt.surgetracker.SurgeTrackerApplication.java
com.bklimt.surgetracker.TimerThread.java
com.bklimt.surgetracker.backbone.CollectionListener.java
com.bklimt.surgetracker.backbone.Collection.java
com.bklimt.surgetracker.backbone.ModelListener.java
com.bklimt.surgetracker.backbone.Model.java
com.bklimt.surgetracker.backbone.Visitor.java
com.bklimt.surgetracker.model.AggregateCollection.java
com.bklimt.surgetracker.model.Aggregate.java
com.bklimt.surgetracker.model.RootViewModel.java
com.bklimt.surgetracker.model.SurgeCollection.java
com.bklimt.surgetracker.model.SurgeParseObject.java
com.bklimt.surgetracker.model.Surge.java
com.bklimt.surgetracker.view.AggregateListAdapter.java
com.bklimt.surgetracker.view.AggregateListFragment.java
com.bklimt.surgetracker.view.MainActivity.java
com.bklimt.surgetracker.view.SurgeDeletionDialogFragment.java
com.bklimt.surgetracker.view.SurgeDurationDialogFragment.java
com.bklimt.surgetracker.view.SurgeGraphFragment.java
com.bklimt.surgetracker.view.SurgeListAdapter.java
com.bklimt.surgetracker.view.SurgeListFragment.java
com.bklimt.surgetracker.view.SurgeStartDialogFragment.java