Android Open Source - gpsplayer Start Stop Fragment






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.ui;
//  ww  w. j  a  va  2  s.c  o m
import android.app.Activity;
import android.os.Bundle;
import android.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import heigvd.iict.gpsplayer.Globals;
import heigvd.iict.gpsplayer.R;
import heigvd.iict.gpsplayer.events.ServiceStateChangedEvent;


// Fragment containing start/stop/reset controls
public class StartStopFragment extends Fragment {
    private final static String TAG = "StartStopFragment";

    private Globals mGlobals;
    private Button mStartBtn;
    private Button mStopBtn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View v = inflater.inflate(R.layout.fragment_start_stop, container, false);

        mStartBtn = (Button)v.findViewById(R.id.btn_start);
        mStartBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "Start clicked");
                mGlobals.startService();
                refreshButtons();
            }
        });

        mStopBtn = (Button)v.findViewById(R.id.btn_stop);
        mStopBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "Stop clicked");
                mGlobals.stopService();
                refreshButtons();
            }
        });

        return v;
    }

    public void onEvent(final ServiceStateChangedEvent event) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
               refreshButtons();
            }
        });
    }

    private void refreshButtons() {
        final boolean running = mGlobals.isRunning();
        mStartBtn.setEnabled(!running);
        mStopBtn.setEnabled(running);
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshButtons();
        mGlobals.eventBus.register(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        mGlobals.eventBus.unregister(this);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mGlobals = Globals.getInstance(getActivity());
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

}




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