Skip to content

Commit

Permalink
move refreshing of "current" textviews to seperate method
Browse files Browse the repository at this point in the history
  • Loading branch information
ruleant committed Nov 12, 2013
1 parent 9b7e351 commit 01e21bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
44 changes: 44 additions & 0 deletions src/org/ruleant/ariadne/AbstractAriadneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.IBinder;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import org.ruleant.ariadne.LocationService.LocationBinder;
import org.ruleant.ariadne.lib.FormatUtils;
import org.ruleant.ariadne.lib.Navigator;

import de.keyboardsurfer.android.widget.crouton.Configuration;
Expand Down Expand Up @@ -292,6 +295,47 @@ protected final void refreshCrouton() {
}
}

/**
* Refresh current speed/bearing views.
*/
protected final void refreshCurrentViews() {
// only refresh items if activity is bound to service
// connection state is checked in getNavigator
Navigator navigator = getNavigator();

if (navigator == null) {
return;
}

Resources res = getResources();

// Get "Current" TextViews
TextView tvCurrentSpeed
= (TextView) findViewById(R.id.textView_currSpeed);
TextView tvCurrentBearing
= (TextView) findViewById(R.id.textView_currBearing);

// Define strings
String currentSpeedText = res.getString(R.string.inaccurate);
String currentBearingText = res.getString(R.string.inaccurate);

// Update current speed
if (navigator.isLocationAccurate()) {
currentSpeedText = FormatUtils.formatSpeed(
navigator.getCurrentSpeed(), this);
}

// Update current bearing
if (navigator.isBearingAccurate()) {
currentBearingText = FormatUtils.formatAngle(
FormatUtils.normalizeAngle(navigator.getCurrentBearing()));
}

// update views
tvCurrentSpeed.setText(currentSpeedText);
tvCurrentBearing.setText(currentBearingText);
}

/**
* Returns bound state to Location Service.
*
Expand Down
23 changes: 3 additions & 20 deletions src/org/ruleant/ariadne/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ final void displayDetails(final MenuItem item) {
protected final void refreshDisplay() {
super.refreshDisplay();

// refresh views with "current" info
refreshCurrentViews();

// only refresh items if activity is bound to service
// connection state is checked in getNavigator
Navigator navigator = getNavigator();
Expand All @@ -131,15 +134,9 @@ protected final void refreshDisplay() {
= (TextView) findViewById(R.id.textView_toDestDist);
TextView tvToDestinationDirection
= (TextView) findViewById(R.id.textView_toDestDir);
TextView tvCurrentSpeed
= (TextView) findViewById(R.id.textView_currSpeed);
TextView tvCurrentBearing
= (TextView) findViewById(R.id.textView_currBearing);

String toDestinationDistanceText = res.getString(R.string.unknown);
String toDestinationDirectionText = res.getString(R.string.unknown);
String currentSpeedText = res.getString(R.string.inaccurate);
String currentBearingText = res.getString(R.string.inaccurate);

nvToDestination.setMode(NavigationView.DISABLED);

Expand Down Expand Up @@ -167,23 +164,9 @@ protected final void refreshDisplay() {
nvToDestination.setDirection(direction);
}

// current speed
if (navigator.isLocationAccurate()) {
currentSpeedText = FormatUtils.formatSpeed(
navigator.getCurrentSpeed(), this);
}

// current bearing
if (navigator.isBearingAccurate()) {
currentBearingText = FormatUtils.formatAngle(
FormatUtils.normalizeAngle(navigator.getCurrentBearing()));
}

// update views
nvToDestination.invalidate();
tvToDestinationDistance.setText(toDestinationDistanceText);
tvToDestinationDirection.setText(toDestinationDirectionText);
tvCurrentSpeed.setText(currentSpeedText);
tvCurrentBearing.setText(currentBearingText);
}
}

0 comments on commit 01e21bf

Please sign in to comment.