Skip to content

Commit

Permalink
Refactoring - applied IDEA code style settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed Apr 20, 2014
1 parent 67cc8c8 commit 82f77f0
Show file tree
Hide file tree
Showing 54 changed files with 1,427 additions and 2,363 deletions.
13 changes: 4 additions & 9 deletions gpslogger/src/main/java/com/mendhak/gpslogger/Faqtivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@
import android.webkit.WebView;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class Faqtivity extends Activity
{
public class Faqtivity extends Activity {

WebView browser;
private static final org.slf4j.Logger tracer = LoggerFactory.getLogger(Faqtivity.class.getSimpleName());

/**
* Event raised when the form is created for the first time
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
public void onCreate(Bundle savedInstanceState) {

tracer.debug("Faqtivity.onCreate");

Expand All @@ -49,7 +45,7 @@ public void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_faq);

browser = (WebView)findViewById(R.id.faqwebview);
browser = (WebView) findViewById(R.id.faqwebview);
WebSettings settings = browser.getSettings();
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
Expand All @@ -76,7 +72,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}



@Override
protected void onStop() {
super.onStop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

import java.util.Iterator;

class GeneralLocationListener implements LocationListener, GpsStatus.Listener, GpsStatus.NmeaListener
{
class GeneralLocationListener implements LocationListener, GpsStatus.Listener, GpsStatus.NmeaListener {

private static GpsLoggingService loggingService;
private static final org.slf4j.Logger tracer = LoggerFactory.getLogger(GeneralLocationListener.class.getSimpleName());
Expand All @@ -40,22 +39,18 @@ class GeneralLocationListener implements LocationListener, GpsStatus.Listener, G
private String ageOfDgpsData;
private String dgpsId;

GeneralLocationListener(GpsLoggingService activity)
{
GeneralLocationListener(GpsLoggingService activity) {
tracer.debug("GeneralLocationListener constructor");
loggingService = activity;
}

/**
* Event raised when a new fix is received.
*/
public void onLocationChanged(Location loc)
{
public void onLocationChanged(Location loc) {

try
{
if (loc != null)
{
try {
if (loc != null) {
tracer.debug("GeneralLocationListener.onLocationChanged");
Bundle b = new Bundle();
b.putString("HDOP", this.latestHdop);
Expand All @@ -68,57 +63,47 @@ public void onLocationChanged(Location loc)
loggingService.OnLocationChanged(loc);

this.latestHdop = "";
this.latestPdop="";
this.latestVdop="";
this.latestPdop = "";
this.latestVdop = "";
}

}
catch (Exception ex)
{
} catch (Exception ex) {
tracer.error("GeneralLocationListener.onLocationChanged", ex);
loggingService.SetStatus(ex.getMessage());
}

}

public void onProviderDisabled(String provider)
{
public void onProviderDisabled(String provider) {
tracer.info("Provider disabled: " + provider);
loggingService.RestartGpsManagers();
}

public void onProviderEnabled(String provider)
{
public void onProviderEnabled(String provider) {

tracer.info("Provider enabled: " + provider);
loggingService.RestartGpsManagers();
}

public void onStatusChanged(String provider, int status, Bundle extras)
{
if (status == LocationProvider.OUT_OF_SERVICE)
{
public void onStatusChanged(String provider, int status, Bundle extras) {
if (status == LocationProvider.OUT_OF_SERVICE) {
tracer.debug(provider + " is out of service");
loggingService.StopManagerAndResetAlarm();
}

if (status == LocationProvider.AVAILABLE)
{
if (status == LocationProvider.AVAILABLE) {
tracer.debug(provider + " is available");
}

if (status == LocationProvider.TEMPORARILY_UNAVAILABLE)
{
if (status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
tracer.debug(provider + " is temporarily unavailable");
loggingService.StopManagerAndResetAlarm();
}
}

public void onGpsStatusChanged(int event)
{
public void onGpsStatusChanged(int event) {

switch (event)
{
switch (event) {
case GpsStatus.GPS_EVENT_FIRST_FIX:
tracer.debug("GPS Event First Fix");
loggingService.SetStatus(loggingService.getString(R.string.fix_obtained));
Expand All @@ -133,8 +118,7 @@ public void onGpsStatusChanged(int event)
Iterator<GpsSatellite> it = status.getSatellites().iterator();
int count = 0;

while (it.hasNext() && count <= maxSatellites)
{
while (it.hasNext() && count <= maxSatellites) {
it.next();
count++;
}
Expand Down Expand Up @@ -162,37 +146,37 @@ public void onNmeaReceived(long timestamp, String nmeaSentence) {

String[] nmeaParts = nmeaSentence.split(",");

if(nmeaParts[0].equalsIgnoreCase("$GPGSA")){
if (nmeaParts[0].equalsIgnoreCase("$GPGSA")) {

if(!Utilities.IsNullOrEmpty(nmeaParts[15])){
if (!Utilities.IsNullOrEmpty(nmeaParts[15])) {
this.latestPdop = nmeaParts[15];
}

if(!Utilities.IsNullOrEmpty(nmeaParts[16])){
if (!Utilities.IsNullOrEmpty(nmeaParts[16])) {
this.latestHdop = nmeaParts[16];
}

if(!Utilities.IsNullOrEmpty(nmeaParts[17]) && !nmeaParts[17].startsWith("*")){
if (!Utilities.IsNullOrEmpty(nmeaParts[17]) && !nmeaParts[17].startsWith("*")) {

this.latestVdop = nmeaParts[17].split("\\*")[0];
}
}


if(nmeaParts[0].equalsIgnoreCase("$GPGGA")){
if(!Utilities.IsNullOrEmpty(nmeaParts[8])){
if (nmeaParts[0].equalsIgnoreCase("$GPGGA")) {
if (!Utilities.IsNullOrEmpty(nmeaParts[8])) {
this.latestHdop = nmeaParts[8];
}

if(!Utilities.IsNullOrEmpty(nmeaParts[11])){
if (!Utilities.IsNullOrEmpty(nmeaParts[11])) {
this.geoIdHeight = nmeaParts[11];
}

if(!Utilities.IsNullOrEmpty(nmeaParts[13])){
if (!Utilities.IsNullOrEmpty(nmeaParts[13])) {
this.ageOfDgpsData = nmeaParts[13];
}

if(!Utilities.IsNullOrEmpty(nmeaParts[14]) && !nmeaParts[14].startsWith("*")){
if (!Utilities.IsNullOrEmpty(nmeaParts[14]) && !nmeaParts[14].startsWith("*")) {
this.dgpsId = nmeaParts[14].split("\\*")[0];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.*;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import com.mendhak.gpslogger.common.AppSettings;
Expand All @@ -42,6 +46,7 @@
import com.mendhak.gpslogger.senders.AlarmReceiver;
import com.mendhak.gpslogger.senders.FileSenderFactory;
import org.slf4j.LoggerFactory;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -207,14 +212,11 @@ public void SetupAutoSendTimers() {
}


protected void ForceAutoSendNow()
{
protected void ForceAutoSendNow() {

tracer.debug(".");
if (AppSettings.isAutoSendEnabled() && Session.getCurrentFileName() != null && Session.getCurrentFileName().length() > 0)
{
if (IsMainFormVisible())
{
if (AppSettings.isAutoSendEnabled() && Session.getCurrentFileName() != null && Session.getCurrentFileName().length() > 0) {
if (IsMainFormVisible()) {
SetStatus(R.string.autosend_sending);
}

Expand Down Expand Up @@ -481,9 +483,9 @@ private void StartGpsManager() {
}

private void startAbsoluteTimer() {
if(AppSettings.getAbsoluteTimeout() >= 1){
if (AppSettings.getAbsoluteTimeout() >= 1) {
tracer.debug("Starting absolute timer");
handler.postDelayed(stopManagerRunnable, AppSettings.getAbsoluteTimeout()*1000);
handler.postDelayed(stopManagerRunnable, AppSettings.getAbsoluteTimeout() * 1000);
}
}

Expand All @@ -495,7 +497,7 @@ public void run() {
}
};

private void stopAbsoluteTimer(){
private void stopAbsoluteTimer() {
tracer.debug("Stopping absolute timer");
handler.removeCallbacks(stopManagerRunnable);
}
Expand Down Expand Up @@ -648,18 +650,18 @@ void OnLocationChanged(Location loc) {
if (AppSettings.getMinimumAccuracyInMeters() > 0) {
if (AppSettings.getMinimumAccuracyInMeters() < Math.abs(loc.getAccuracy())) {

if(this.firstRetryTimeStamp == 0){
if (this.firstRetryTimeStamp == 0) {
this.firstRetryTimeStamp = System.currentTimeMillis();
}

if(currentTimeStamp - this.firstRetryTimeStamp <= AppSettings.getRetryInterval()*1000){
if (currentTimeStamp - this.firstRetryTimeStamp <= AppSettings.getRetryInterval() * 1000) {
tracer.warn("Only accuracy of " + String.valueOf(Math.floor(loc.getAccuracy())) + " m. Point discarded.");
SetStatus("Inaccurate point discarded.");
//return and keep trying
return;
}

if (currentTimeStamp - this.firstRetryTimeStamp > AppSettings.getRetryInterval()*1000) {
if (currentTimeStamp - this.firstRetryTimeStamp > AppSettings.getRetryInterval() * 1000) {
tracer.warn("Only accuracy of " + String.valueOf(Math.floor(loc.getAccuracy())) + " m and timeout reached");
SetStatus("Inaccurate points discarded and retries timed out.");
//Give up for now
Expand Down Expand Up @@ -812,7 +814,7 @@ private boolean IsMainFormVisible() {

public void OnNmeaSentence(long timestamp, String nmeaSentence) {

if(AppSettings.shouldLogToNmea()) {
if (AppSettings.shouldLogToNmea()) {
NmeaFileLogger nmeaLogger = new NmeaFileLogger(Session.getCurrentFileName());
nmeaLogger.Write(timestamp, nmeaSentence);
}
Expand Down
33 changes: 13 additions & 20 deletions gpslogger/src/main/java/com/mendhak/gpslogger/GpsMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ protected void onCreate(Bundle savedInstanceState) {
}




@Override
protected void onStart() {
super.onStart();
Expand Down Expand Up @@ -164,7 +162,6 @@ private void SetUpNavigationDrawer() {
}



/**
* Handles drawer item selection
*/
Expand Down Expand Up @@ -306,10 +303,10 @@ private void enableDisableMenuItems() {

if (mnuOnePoint != null) {
mnuOnePoint.setEnabled(!Session.isStarted());
mnuOnePoint.setIcon( (Session.isStarted() ? R.drawable.singlepoint_disabled : R.drawable.singlepoint ) );
mnuOnePoint.setIcon((Session.isStarted() ? R.drawable.singlepoint_disabled : R.drawable.singlepoint));
}

if(mnuAutoSendNow != null){
if (mnuAutoSendNow != null) {
mnuAutoSendNow.setEnabled(Session.isStarted());
}

Expand Down Expand Up @@ -378,21 +375,17 @@ public boolean onOptionsItemSelected(MenuItem item) {

}

private void ForceAutoSendNow()
{
private void ForceAutoSendNow() {
tracer.debug("Auto send now");

if (AppSettings.isAutoSendEnabled())
{
if (AppSettings.isAutoSendEnabled()) {

Utilities.ShowProgress(this, getString(R.string.autosend_sending),
getString(R.string.please_wait));
loggingService.ForceAutoSendNow();
Utilities.ShowProgress(this, getString(R.string.autosend_sending),
getString(R.string.please_wait));
loggingService.ForceAutoSendNow();


}
else
{
} else {
Intent pref = new Intent().setClass(this, UploadSettingsActivity.class);
startActivity(pref);
}
Expand Down Expand Up @@ -551,7 +544,7 @@ private void ShowFileListDialog(final Intent settingsIntent, final IFileSender s

Arrays.sort(enumeratedFiles, new Comparator<File>() {
public int compare(File f1, File f2) {
if(f1 != null && f2 != null){
if (f1 != null && f2 != null) {
return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
}
return -1;
Expand Down Expand Up @@ -732,20 +725,20 @@ private void StopAndUnbindServiceIfRequired() {
tracer.debug(".");
if (Session.isBoundToService()) {

try{
try {
unbindService(gpsServiceConnection);
Session.setBoundToService(false);
}catch (Exception e){
} catch (Exception e) {
tracer.error("Could not unbind service", e);
}
}

if (!Session.isStarted()) {
tracer.debug("Stopping the service");
//serviceIntent = new Intent(this, GpsLoggingService.class);
try{
try {
stopService(serviceIntent);
} catch(Exception e){
} catch (Exception e) {
tracer.error("Could not stop the service", e);
}

Expand Down
Loading

0 comments on commit 82f77f0

Please sign in to comment.