Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions app/src/main/assets/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@
toastr.options.timeOut = 2000;

// set data
function setData(airport, info, metar, taf, airep, tfr, sua, mets, performance, winds, layer) {
function setData(airport, nameEdit, isStatic, info, metar, taf, airep, tfr, sua, mets, performance, winds, layer) {
$("#airportName").text(airport);
$("#nameEdit").val(nameEdit);
if (isStatic) {
$("#nameEditDiv").hide();
} else {
$("#nameEditDiv").show();
$("#nameEdit").focus();
}
$("#airportInfo").html(info);
$("#airportMetar").html(metar);
$("#airportTaf").html(taf);
Expand All @@ -69,15 +76,19 @@
<body>
<div class="container-fluid">
<div class="btn-group btn-group-justified" id="buttonGroup">
<a href="javascript:doAction('->D');" class="btn btn-success">->D</a>
<a href="javascript:doAction('+Plan');" class="btn btn-primary">+Plan</a>
<a href="javascript:doRenameAction('->D');" class="btn btn-success">->D</a>
<a href="javascript:doRenameAction('+Plan');" class="btn btn-primary">+Plan</a>
<a href="javascript:doAction('Plate');" class="btn btn-primary">Plate</a>
<a href="javascript:doAction('A/FD');" class="btn btn-primary">A/FD</a>
<a href="javascript:doAction('X');" class="btn btn-danger">X</a>
</div>
<div style="margin-left : 5px">
<h4><span class="label label-success" id='airportName'></span></h4>
<div id='nameEditDiv'>
<input id='nameEdit' type="text" autofocus onfocus="this.select();" onmouseup="return false;"/>
<a href="javascript:doRenameAction('Rename');" class="btn btn-success">Name</a>
</div>
<hr>
<h4><div id='airportNameDiv'><span class="label label-success" id='airportName'></span></div></h4>
<div id='airportInfo'></div>
<div id='airportMetar'></div>
<div id='airportTaf'></div>
Expand Down
49 changes: 41 additions & 8 deletions app/src/main/java/com/ds/avare/LocationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ public void onCreate(Bundle savedInstanceState) {
public Object callback(Object o, Object o1) {

String param = (String) o;
String airport = (String) o;
String[] parts = param.split("`");
String action = parts[0], newName = parts.length>1 ? parts[1] : "";

mAlertDialogDestination.dismiss();

Expand All @@ -427,7 +428,7 @@ public Object callback(Object o, Object o1) {
return null;
}

if (param.equals("A/FD")) {
if (action.equals("A/FD")) {
/*
* A/FD
*/
Expand All @@ -436,7 +437,7 @@ public Object callback(Object o, Object o1) {
((MainActivity) LocationActivity.this.getParent()).showAfdTab();
}
mAirportPressed = null;
} else if (param.equals("Plate")) {
} else if (action.equals("Plate")) {
/*
* Plate
*/
Expand All @@ -446,14 +447,19 @@ public Object callback(Object o, Object o1) {
((MainActivity) LocationActivity.this.getParent()).showPlatesTab();
}
mAirportPressed = null;
} else if (param.equals("+Plan")) {
String type = Destination.BASE;
} else if (action.equals("+Plan")) {
/*
* +Plan
*/
if (mAirportPressed.contains("&")) {
type = Destination.GPS;
String decoratedName = (newName.isEmpty() && newName != mAirportPressed)
? mAirportPressed : newName + "@" + mAirportPressed;
planTo(decoratedName, Destination.GPS);
} else {
planTo(mAirportPressed, Destination.BASE);
}
planTo(mAirportPressed, type);
mAirportPressed = null;
} else if (param.equals("->D")) {
} else if (action.equals("->D")) {

/*
* On click, find destination that was pressed on in view
Expand All @@ -464,8 +470,12 @@ public Object callback(Object o, Object o1) {
String type = Destination.BASE;
if (dest.contains("&")) {
type = Destination.GPS;
dest = (newName.isEmpty() && newName != mAirportPressed)
? dest : newName + "@" + dest;
}
goTo(dest, type);
} else if (action.equals("Rename")) {
rename(newName);
}
return null;
}
Expand Down Expand Up @@ -982,6 +992,29 @@ public void onClick(View v) {
}
}

/** finds the pressed destination in the plan and renames it to the @newName */
public void rename(String newName) {
if (!newName.isEmpty()
&& mAirportPressed!=null
&& !newName.equals(mAirportPressed)
&& mAirportPressed.contains("&"))
{
String[] latLon = mAirportPressed.split("&");
double lat = Double.parseDouble(latLon[0]),
lon = Double.parseDouble(latLon[1]);
Plan plan = mService.getPlan();
if (plan != null) {
Destination destToRename = plan.findDestinationByLocation(lon, lat);
if (destToRename != null) {
destToRename.setID(newName+"@"+mAirportPressed);
mToast.setText(getString(R.string.LabelChanged)+" "+newName);
mToast.show();

}
}
}
}

private void setTrackState(boolean bState)
{
URI fileURI = mService.setTracks(bState);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/ds/avare/place/Destination.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,13 @@ public String getID() {
return(mName);
}

/**
* @return
*/
public void setID(String name) {
mName = name.toUpperCase(Locale.getDefault());;
}

/**
* @return
*/
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/ds/avare/place/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ public int findNextNotPassed() {
return 0;
}

/*
* Find a destination using lat/lon coordinates
*/
public Destination findDestinationByLocation(double lonToFind, double latToFind) {
/*
*
*/
for (int id = 0; id < getDestinationNumber(); id++) {
Location loc = mDestination[id].getLocation();
double lon = loc.getLongitude();
double lat = loc.getLatitude();
if (Helper.isSameGPSLocation(lon, lat, lonToFind, latToFind))
return mDestination[id];
}
return null;
}

/*
* If passed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public void handleMessage(Message msg) {
mWebView.loadUrl("javascript:plan_clear()");
String func = "javascript:setData('" +
Helper.formatJsArgs(data.airport) + "','" +
Helper.formatJsArgs(data.airport) + "'," + // nameEdit
Helper.formatJsArgs(data.airport.contains("&") ? "false" : "true") + ",'" + // isStatic
"<font color=\"yellow\">Position " + "</font>" + Helper.formatJsArgs(data.info) + "','" +
Helper.formatJsArgs(metar) + "','" +
Helper.formatJsArgs(taf) + "','" +
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Redistribution and use in source and binary forms, with or without modification,
<string name="NightModeSummary">&quot;Select to reduce white light during night operation (requires restart)&quot;</string>
<string name="Delete">&quot;Delete&quot;</string>
<string name="Label">&quot;Label&quot;</string>
<string name="LabelChanged">&quot;Label changed to&quot;</string>
<string name="Create">&quot;Create&quot;</string>
<string name="Plan">&quot;Plan&quot;</string>
<string name="PlusPlan">&quot;+Plan&quot;</string>
Expand Down