Android Open Source - gpsplayer Globals






From Project

Back to project page gpsplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project gpsplayer 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 heigvd.iict.gpsplayer;
/*from   ww w. ja va2 s  .c  o m*/
import android.content.Context;
import android.content.Intent;

import java.io.File;

import de.greenrobot.event.EventBus;
import heigvd.iict.gpsplayer.background.RunTrackService;
import heigvd.iict.gpsplayer.data.Track;
import heigvd.iict.gpsplayer.events.ServiceStateChangedEvent;

public class Globals {
    private static Globals instance = null;

    public static Globals getInstance(Context context) {
        if (instance == null) {
            instance = new Globals(context.getApplicationContext());
        } else {
            if (instance.context != context.getApplicationContext()) {
                // I think this should not happen since the application is simple enough that it
                // runs in a single process (no contentprovider or broadcastreceiver).
                // If we extend the application and need to handle multiple contexts, we should
                // have a per-context Globals instance
                throw new IllegalStateException("Globals already instanciated with a different context");
            }
        }
        return instance;
    }

    private final static String TAG = "Globals";
    private Context context;
    private Track currentTrack = null;

    public final EventBus eventBus = new EventBus();

    public Globals(Context context) {
        this.context = context;
    }

    public void setCurrentTrack(Track track) {
        stopService();
        currentTrack = track;
    }

    public Track getCurrentTrack () {
        return currentTrack;
    }

    public boolean isCurrentTrack(File f) {
        return currentTrack != null && Utils.fileEquals(f, currentTrack.file);
    }

    private boolean serviceRunning = false;

    // This should only be call from the service
    public void setServiceRunning(boolean running) {
        serviceRunning = running;
        eventBus.post(new ServiceStateChangedEvent());
    }

    public void startService() {
        final Intent intent = new Intent(context, RunTrackService.class);
        context.startService(intent);
        setServiceRunning(true);

    }

    public void stopService() {
        context.stopService(new Intent(context, RunTrackService.class));
        setServiceRunning(false);
    }

    public boolean isRunning() {
        return serviceRunning;
    }
}




Java Source Code List

heigvd.iict.gpsplayer.ApplicationTest.java
heigvd.iict.gpsplayer.Globals.java
heigvd.iict.gpsplayer.Utils.java
heigvd.iict.gpsplayer.background.RunTrackService.java
heigvd.iict.gpsplayer.data.TrackPoint.java
heigvd.iict.gpsplayer.data.Track.java
heigvd.iict.gpsplayer.events.LocationSentEvent.java
heigvd.iict.gpsplayer.events.ServiceStateChangedEvent.java
heigvd.iict.gpsplayer.io.GpxLoader.java
heigvd.iict.gpsplayer.ui.FilesListActivity.java
heigvd.iict.gpsplayer.ui.ImportTrackActivity.java
heigvd.iict.gpsplayer.ui.StartStopFragment.java
heigvd.iict.gpsplayer.ui.TrackViewActivity.java
heigvd.iict.gpsplayer.ui.fragments.DeleteTrackDialogFragment.java
heigvd.iict.gpsplayer.ui.fragments.FilenameDialogFragment.java