Android Open Source - iLitIt_Android Observable Linked List






From Project

Back to project page iLitIt_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project iLitIt_Android 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 de.unifreiburg.es.iLitIt;
/*from w  ww.  j a v  a  2s  .c  o  m*/
import android.util.Log;

import java.util.LinkedList;

/**
 * Created by phil on 11/19/14.
 */
public class ObservableLinkedList<E> extends LinkedList<E> {

    private final LinkedList<Observer> observers = new LinkedList<Observer>();

    public void register(ObservableLinkedList.Observer<E> o) {
        observers.add(o);
        String klass = o.getClass().getSimpleName();

        if ((klass.contains("Runnable") || klass.contains("DelayedObserver")) && o.getClass().getDeclaringClass()!=null)
            klass = o.getClass().getDeclaringClass().getName();

        Log.d(ObservableLinkedList.class.getName(),
                "new observer registered: " + klass);
    }
    public void unregister(ObservableLinkedList.Observer<E> o)
    {
        observers.remove(o);
    }

    @Override
    public void clear() {
        super.clear();
        fireEvent(null);
    }

    @Override
    public boolean add(E object) {
        boolean b = super.add(object);
        fireEvent(object);
        return b;
    }

    @Override
    public boolean remove(Object object) {
        boolean b = super.remove(object);
        fireEvent((E) object);
        return b;
    }

    public void fireEvent(E object) {
        Log.d(ObservableLinkedList.class.getName(),
                "fired event from Thread " + Thread.currentThread().getName());

        for (Observer o : observers)
            o.listChanged(this, object);
    }

    public interface Observer<E> {
        public void listChanged(ObservableLinkedList<E> list, E object);
    }
}




Java Source Code List

de.unifreiburg.es.iLitIt.CigAnnotationWriter.java
de.unifreiburg.es.iLitIt.CigIntentBroadcaster.java
de.unifreiburg.es.iLitIt.CigaretteEvent.java
de.unifreiburg.es.iLitIt.DelayedObserver.java
de.unifreiburg.es.iLitIt.HeatMapFragment.java
de.unifreiburg.es.iLitIt.HomescreenFragment.java
de.unifreiburg.es.iLitIt.JournalFragment.java
de.unifreiburg.es.iLitIt.LighterBluetoothService.java
de.unifreiburg.es.iLitIt.MainActivity.java
de.unifreiburg.es.iLitIt.ObservableLinkedList.java
de.unifreiburg.es.iLitIt.SettingsFragment.java
de.unifreiburg.es.iLitIt.StatsHelper.java