Skip to content

Commit

Permalink
Merge branch 'master' into refactor_detailsactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
ruleant committed Nov 10, 2013
2 parents ecc6069 + 14042a7 commit b0b5fea
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 53 deletions.
9 changes: 9 additions & 0 deletions .idea/dictionaries/dieter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ariadne.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/r" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/r" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/aidl" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
Expand Down
7 changes: 7 additions & 0 deletions res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
android:text="@string/version"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textview_buildtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/build"
android:padding="2dp" />

<TextView
android:id="@+id/textview_description"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="refresh">Refresh</string>
<string name="provider_no_support">Provider is not supported.</string>
<string name="version">Version</string>
<string name="build">Built on :</string>
<string name="loc_updated_recent">Location recently updated.</string>
<string name="loc_updated_not_recent">Location NOT recently updated.</string>
<string name="inaccurate">Inaccurate</string>
Expand Down
22 changes: 14 additions & 8 deletions src/org/ruleant/ariadne/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView;

import org.ruleant.ariadne.lib.DebugLevel;
Expand All @@ -52,15 +53,11 @@ protected final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
Resources res = getResources();

DateFormat formatter = SimpleDateFormat.getDateInstance();

// Display time when in debug mode
DebugLevel debug = new DebugLevel(this);
if (debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_LOW)) {
formatter = SimpleDateFormat.getDateTimeInstance();
}

DateFormat formatter = SimpleDateFormat.getDateTimeInstance();
String versionInfo = res.getString(R.string.app_name);
String buildTime = "";
PackageInfo packageInfo;

try {
Expand All @@ -69,7 +66,8 @@ protected final void onCreate(final Bundle savedInstanceState) {
versionInfo += " v" + packageInfo.versionName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Date date = new Date(packageInfo.lastUpdateTime);
versionInfo += " (" + formatter.format(date) + ")";
buildTime = res.getString(R.string.build)
+ " " + formatter.format(date);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
Expand All @@ -79,6 +77,14 @@ protected final void onCreate(final Bundle savedInstanceState) {
TextView tvVersion = (TextView) findViewById(R.id.textview_version);
tvVersion.setText(versionInfo);

// Build time text view
TextView tvBuildTime = (TextView) findViewById(R.id.textview_buildtime);
if (debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_LOW)) {
tvBuildTime.setText(buildTime);
} else {
tvBuildTime.setVisibility(View.INVISIBLE);
}

// Version text view
TextView tvWebsite = (TextView) findViewById(R.id.textview_website);
// enable HTML links
Expand Down
10 changes: 5 additions & 5 deletions src/org/ruleant/ariadne/AbstractAriadneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*
* @author Dieter Adriaenssens <ruleant@users.sourceforge.net>
*/
public abstract class AbstractAriadneActivity extends Activity {
abstract class AbstractAriadneActivity extends Activity {
/**
* Interface to LocationService instance.
*/
Expand Down Expand Up @@ -141,7 +141,7 @@ protected final void onDestroy() {
*
* @param item MenuItem object that was clicked
*/
public final void storeLocation(final MenuItem item) {
final void storeLocation(final MenuItem item) {
if (mBound && mService.getLocation() == null) {
Toast.makeText(
this,
Expand Down Expand Up @@ -184,7 +184,7 @@ public void onClick(final DialogInterface dialog,
*
* @param item MenuItem object that was clicked
*/
public final void refresh(final MenuItem item) {
final void refresh(final MenuItem item) {
if (mBound) {
mService.updateLocationProvider();
mService.updateLocation();
Expand All @@ -197,7 +197,7 @@ public final void refresh(final MenuItem item) {
*
* @param item MenuItem object that was clicked
*/
public final void displayAbout(final MenuItem item) {
final void displayAbout(final MenuItem item) {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
}
Expand All @@ -207,7 +207,7 @@ public final void displayAbout(final MenuItem item) {
*
* @param item MenuItem object that was clicked
*/
public final void displaySettings(final MenuItem item) {
final void displaySettings(final MenuItem item) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
Expand Down
5 changes: 0 additions & 5 deletions src/org/ruleant/ariadne/DetailsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
* @author Dieter Adriaenssens <ruleant@users.sourceforge.net>
*/
public class DetailsActivity extends AbstractAriadneActivity {
/**
* Rotation of the direction pointer image.
*/
private static final int POINTER_ROT = 90;

@Override
protected final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
14 changes: 3 additions & 11 deletions src/org/ruleant/ariadne/LocationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ public final boolean onUnbind(final Intent intent) {
* Retrieve Location Provider.
*
* Define best location provider based on certain criteria
*
* @return String
*/
public final String updateLocationProvider() {
public final void updateLocationProvider() {
// Retrieve a list of location providers that have fine accuracy,
// no monetary cost, etc
// TODO define criteria in settings
Expand All @@ -227,8 +225,6 @@ public final String updateLocationProvider() {
if (mLocationManager != null) {
mProviderName = mLocationManager.getBestProvider(criteria, true);
}

return mProviderName;
}

/**
Expand Down Expand Up @@ -341,18 +337,14 @@ public final boolean isSetLocationProvider() {
* Update Location.
*
* Force location update, using getLastKnownLocation()
*
* @return Location
*/
public final AriadneLocation updateLocation() {
public final void updateLocation() {
if (mLocationManager == null || !isSetLocationProvider()) {
return null;
return;
}
// update location using getLastKnownLocation,
// don't wait for listener update
setLocation(mLocationManager.getLastKnownLocation(mProviderName));

return getLocation();
}

/**
Expand Down
33 changes: 27 additions & 6 deletions src/org/ruleant/ariadne/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.widget.TextView;

import org.ruleant.ariadne.lib.AriadneLocation;
import org.ruleant.ariadne.lib.DebugLevel;
import org.ruleant.ariadne.lib.FormatUtils;
import org.ruleant.ariadne.lib.Navigator;

Expand All @@ -48,9 +49,14 @@ protected final void onCreate(final Bundle savedInstanceState) {
public final boolean onCreateOptionsMenu(final Menu menu) {
boolean superResult = super.onCreateOptionsMenu(menu);

// Inflate the menu;
// this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
DebugLevel debug = new DebugLevel(this);

// don't add details button when debugging is disabled
if (debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_LOW)) {
// Inflate the menu;
// this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
}

return superResult;
}
Expand All @@ -69,12 +75,26 @@ public final boolean onOptionsItemSelected(final MenuItem item) {
}
}

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
MenuItem miDetails = menu.findItem(R.id.menu_details);
DebugLevel debug = new DebugLevel(this);

if (miDetails != null) {
// hide details button when debugging is disabled
miDetails.setVisible(
debug.checkDebugLevel(DebugLevel.DEBUG_LEVEL_LOW));
}

return super.onPrepareOptionsMenu(menu);
}

/**
* Called when the user clicks the About menu item.
*
* @param item MenuItem object that was clicked
*/
public final void displayDetails(final MenuItem item) {
final void displayDetails(final MenuItem item) {
Intent intent = new Intent(this, DetailsActivity.class);
startActivity(intent);
}
Expand Down Expand Up @@ -141,8 +161,9 @@ protected final void refreshDisplay() {
nvToDestination.setMode(NavigationView.INACCURATE);
}

toDestinationDirectionText = FormatUtils.formatAngle(
FormatUtils.normalizeAngle(direction));
toDestinationDirectionText
= FormatUtils.formatAngle(FormatUtils.normalizeAngle(
navigator.getAbsoluteDirection()));
nvToDestination.setDirection(direction);
}

Expand Down
30 changes: 22 additions & 8 deletions src/org/ruleant/ariadne/NavigationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public class NavigationView extends ImageView {
*/
private static final double D_80PCT = 0.8;

/**
* arrow side angle.
*/
private static final double ARROW_ANGLE = 25.0;

/**
* Constructor.
*
Expand Down Expand Up @@ -186,14 +191,23 @@ public final void onDraw(final Canvas canvas) {
double radius = getHeight() / 2;
double arrowLength = radius * D_80PCT;
double arrowLengthTail = radius * D_20PCT;
double direction = getDirection();

long[] startCoordinate = polarToCartesian(
FormatUtils.inverseAngle(direction), arrowLengthTail);
long[] endCoordinate = polarToCartesian(direction, arrowLength);

canvas.drawLine(startCoordinate[X], startCoordinate[Y],
endCoordinate[X], endCoordinate[Y], mPaint);
double directionArrowPoint = getDirection();
double directionArrowTail
= FormatUtils.inverseAngle(directionArrowPoint);

long[] arrowPointCoordinate
= polarToCartesian(directionArrowPoint, arrowLength);
long[] tailRightCoordinate = polarToCartesian(
directionArrowTail - ARROW_ANGLE, arrowLengthTail);
long[] tailLeftCoordinate = polarToCartesian(
directionArrowTail + ARROW_ANGLE, arrowLengthTail);

canvas.drawLine(tailRightCoordinate[X], tailRightCoordinate[Y],
arrowPointCoordinate[X], arrowPointCoordinate[Y], mPaint);
canvas.drawLine(tailLeftCoordinate[X], tailLeftCoordinate[Y],
arrowPointCoordinate[X], arrowPointCoordinate[Y], mPaint);
canvas.drawLine(tailLeftCoordinate[X], tailLeftCoordinate[Y],
tailRightCoordinate[X], tailRightCoordinate[Y], mPaint);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/org/ruleant/ariadne/lib/StoredLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ public final void save() {

/**
* Restore stored location from Shared Preferences.
*
* @return location retrieved from Preferences
*/
public final Location restore() {
public final void restore() {
Location location = new Location("");

// check if a location stored. the saved parameter is set to true
Expand All @@ -258,11 +256,11 @@ public final Location restore() {
mHasLocation
= Boolean.parseBoolean(mPrefs.getString(SAVED, "false"));
if (!mHasLocation) {
return null;
return;
}
} catch (Exception e) {
e.printStackTrace();
return null;
return;
}

// retrieve longitude and latitude,
Expand All @@ -276,7 +274,7 @@ public final Location restore() {
);
} catch (Exception e) {
e.printStackTrace();
return null;
return;
}

// retrieve altitude, if defined
Expand Down Expand Up @@ -338,7 +336,5 @@ public final Location restore() {

// set retrieved location
setLocation(location);

return getLocation();
}
}

0 comments on commit b0b5fea

Please sign in to comment.