Android Open Source - egotrip Common G P S Service Functions






From Project

Back to project page egotrip.

License

The source code is released under:

Apache License

If you think the Android project egotrip 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 net.myegotrip.egotrip;
//  www.  j a v  a2 s.c om
import net.myegotrip.egotrip.utils.GuiUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.EditText;

/**
 * common service functions used im ultiple activities
 * 
 * @author gryphius
 * 
 */
public class CommonGPSServiceFunctions {
  public static final String TAG = "EGOTRIP-CommonFuncs";

  public static void startRecording(GPSService service, Activity act) {
    Log.d(TAG, "startRecording, act=" + act.getTitle() + " serv=" + service);

    // check time since last update in current trip
    int hours = 0;

    DbTools dbtools = service.getDbTools();
    long lastInsert = dbtools.getLatestLocationTimeStamp();
    long timeSinceLastUpdate = System.currentTimeMillis() - lastInsert;
    if (lastInsert > 0) {
      hours = (int) (timeSinceLastUpdate / 1000 / 3600);
    }
    final SharedPreferences prefs = PreferenceManager
        .getDefaultSharedPreferences(act);
    String tripname = prefs.getString("custom_trip", "default");

    if (tripname.trim().equals("")) {
      tripname = "default";
    }
    
    if (tripname != null && hours > 48
        && dbtools.getTrip(tripname).size() > 0) {
      AlertDialog.Builder alert = new AlertDialog.Builder(act);

      alert.setTitle(R.string.name);
      alert.setMessage("The last location was recorded "
          + hours
          + " hours ago. If this is a new trip, please enter the name (or cancel to abort insert)");

      // Set an EditText view to get user input
      final EditText input = new EditText(act);
      input.setText(tripname);
      alert.setView(input);

      alert.setPositiveButton(R.string.ok,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,
                int whichButton) {
              String value = input.getText().toString();

              SharedPreferences.Editor ed = prefs.edit();
              ed.putString("custom_trip", value);
              // apply is API level 9 only :(
              ed.commit();

            }
          });
      alert.setNegativeButton(R.string.cancel, null);
      alert.show();

    }

    if (service != null) {
      service.startRecording();
      if (!service.checkIfGpsIsTurnedOn()) {
        new GuiUtils(act).buildAlertMessageNoGps();
      }
    }
  }

  public static void stopRecording(GPSService service) {
    if (service != null)
      service.stopRecording();
  }

  public static void forcelocationupdate(GPSService service, Activity act) {
    if (service != null) {
      service.forcelocationupdate();
    }
  }

}




Java Source Code List

net.myegotrip.egotrip.CommonGPSServiceFunctions.java
net.myegotrip.egotrip.ControlHandler.java
net.myegotrip.egotrip.ControlWindow.java
net.myegotrip.egotrip.DbListener.java
net.myegotrip.egotrip.DbTools.java
net.myegotrip.egotrip.DownloadProgressHandler.java
net.myegotrip.egotrip.FallbackDefaults.java
net.myegotrip.egotrip.GPSService.java
net.myegotrip.egotrip.Installation.java
net.myegotrip.egotrip.LocationUpdate.java
net.myegotrip.egotrip.MapViewActivity.java
net.myegotrip.egotrip.PrefActivity.java
net.myegotrip.egotrip.ReleaseConfig.java
net.myegotrip.egotrip.StartupActivity.java
net.myegotrip.egotrip.TaskDoneListener.java
net.myegotrip.egotrip.Tools.java
net.myegotrip.egotrip.TripManager.java
net.myegotrip.egotrip.help.HelpActivity.java
net.myegotrip.egotrip.help.TopicActivity.java
net.myegotrip.egotrip.image.ImageHandler.java
net.myegotrip.egotrip.map.MockLocationProvider.java
net.myegotrip.egotrip.map.PlacemarkOverlay.java
net.myegotrip.egotrip.map.Placemark.java
net.myegotrip.egotrip.map.RouteOverlay.java
net.myegotrip.egotrip.map.RoutePoint.java
net.myegotrip.egotrip.map.Trip.java
net.myegotrip.egotrip.metadata.EgotripMetadata.java
net.myegotrip.egotrip.metadata.GenericMetadata.java
net.myegotrip.egotrip.metadata.Icon.java
net.myegotrip.egotrip.metadata.Image.java
net.myegotrip.egotrip.metadata.MetadataManager.java
net.myegotrip.egotrip.metadata.Text.java
net.myegotrip.egotrip.net.BetaUpdateManager.java
net.myegotrip.egotrip.net.ProtocolConstants.java
net.myegotrip.egotrip.net.ServerReply.java
net.myegotrip.egotrip.net.Uploader.java
net.myegotrip.egotrip.profile.ProfileActivity.java
net.myegotrip.egotrip.profile.ProfilePrefActivity.java
net.myegotrip.egotrip.profile.ProfileView.java
net.myegotrip.egotrip.utils.DebugActivity.java
net.myegotrip.egotrip.utils.Debug.java
net.myegotrip.egotrip.utils.GuiUtils.java
net.myegotrip.egotrip.utils.IconItem.java
net.myegotrip.egotrip.utils.TwoDScrollView.java
net.myegotrip.egotrip.utils.XYScaleGestureDetector.java