diff --git a/OsmAnd/libs/PDFjet.jar b/OsmAnd/libs/PDFjet.jar
deleted file mode 100644
index 409ed7be26..0000000000
Binary files a/OsmAnd/libs/PDFjet.jar and /dev/null differ
diff --git a/OsmAnd/res/drawable-hdpi/drawable-hdpi/ic_action_gprint_dark.png b/OsmAnd/res/drawable-hdpi/drawable-hdpi/ic_action_gprint_dark.png
deleted file mode 100644
index c7abf35b86..0000000000
Binary files a/OsmAnd/res/drawable-hdpi/drawable-hdpi/ic_action_gprint_dark.png and /dev/null differ
diff --git a/OsmAnd/res/drawable-hdpi/drawable-mdpi/ic_action_gprint_dark.png b/OsmAnd/res/drawable-hdpi/drawable-mdpi/ic_action_gprint_dark.png
deleted file mode 100644
index 1986f1e03a..0000000000
Binary files a/OsmAnd/res/drawable-hdpi/drawable-mdpi/ic_action_gprint_dark.png and /dev/null differ
diff --git a/OsmAnd/res/drawable-hdpi/drawable-xhdpi/ic_action_gprint_dark.png b/OsmAnd/res/drawable-hdpi/drawable-xhdpi/ic_action_gprint_dark.png
deleted file mode 100644
index 25cffbc822..0000000000
Binary files a/OsmAnd/res/drawable-hdpi/drawable-xhdpi/ic_action_gprint_dark.png and /dev/null differ
diff --git a/OsmAnd/res/drawable-hdpi/drawable-xxhdpi/ic_action_gprint_dark.png b/OsmAnd/res/drawable-hdpi/drawable-xxhdpi/ic_action_gprint_dark.png
deleted file mode 100644
index 822e4cc110..0000000000
Binary files a/OsmAnd/res/drawable-hdpi/drawable-xxhdpi/ic_action_gprint_dark.png and /dev/null differ
diff --git a/OsmAnd/res/layout-large/route_info_list_item.xml b/OsmAnd/res/layout-large/route_info_list_item.xml
index bd54690512..0d32ed0465 100644
--- a/OsmAnd/res/layout-large/route_info_list_item.xml
+++ b/OsmAnd/res/layout-large/route_info_list_item.xml
@@ -1,13 +1,58 @@
+
-
+
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/route_info_list_item.xml b/OsmAnd/res/layout/route_info_list_item.xml
index 245f831ec8..e503c54147 100644
--- a/OsmAnd/res/layout/route_info_list_item.xml
+++ b/OsmAnd/res/layout/route_info_list_item.xml
@@ -1,13 +1,53 @@
+
-
+
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java
index acbb56499b..1450df5b77 100644
--- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java
@@ -6,12 +6,9 @@ package net.osmand.plus.activities;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
import net.osmand.IndexConstants;
@@ -27,20 +24,10 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.util.Algorithms;
-import android.annotation.SuppressLint;
-import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.CancellationSignal;
-import android.os.ParcelFileDescriptor;
-import android.print.PageRange;
-import android.print.PrintAttributes;
-import android.print.PrintAttributes.Margins;
-import android.print.PrintDocumentAdapter;
-import android.print.PrintDocumentInfo;
-import android.print.PrintManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
@@ -53,11 +40,6 @@ import android.widget.TextView;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
-import com.pdfjet.A4;
-import com.pdfjet.CodePage;
-import com.pdfjet.Font;
-import com.pdfjet.PDF;
-import com.pdfjet.Page;
/**
*
@@ -68,9 +50,6 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
private static final int SAVE = 0;
private static final int SHARE = 1;
private static final int PRINT = 2;
- private final static float PDF_FONT_SIZE = 12f;
- private final static float PDF_DERAULT_MARGINS = 36f;
- private final static float PDF_TEXT_LEADING = 14f;
private RoutingHelper helper;
private TextView header;
private DisplayMetrics dm;
@@ -96,7 +75,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
return true;
}
if (item.getItemId() == SHARE) {
- final GPXFile gpx = getMyApplication().getRoutingHelper().generateGPXFileWithRoute();
+ final GPXFile gpx = helper.generateGPXFileWithRoute();
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
@@ -124,7 +103,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
// large screen
header.setTextSize(dm.scaledDensity * 23);
}
- setListAdapter(new RouteInfoAdapter(((OsmandApplication)getApplication()).getRoutingHelper().getRouteDirections()));
+ setListAdapter(new RouteInfoAdapter(helper.getRouteDirections()));
}
@Override
@@ -139,7 +118,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
MapRouteInfoControl.directionInfo = position - 1;
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
settings.setMapLocationToShow(loc.getLatitude(),loc.getLongitude(),
- Math.max(13, settings.getLastKnownMapZoom()), null, item.getDescriptionRoute(((OsmandApplication) getApplication())) + " " + getTimeDescription(item), null);
+ Math.max(13, settings.getLastKnownMapZoom()), null, item.getDescriptionRoutePart() + " " + getTimeDescription(item), null);
MapActivity.launchMapActivityMoveToTop(this);
}
}
@@ -159,6 +138,16 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
}
class RouteInfoAdapter extends ArrayAdapter {
+ public class CumulativeInfo {
+ public int distance;
+ public int time;
+
+ public CumulativeInfo() {
+ distance = 0;
+ time = 0;
+ }
+ }
+
RouteInfoAdapter(List list) {
super(ShowRouteInfoActivity.this, R.layout.route_info_list_item, list);
this.setNotifyOnChange(false);
@@ -176,21 +165,34 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
TextView label = (TextView) row.findViewById(R.id.description);
TextView distanceLabel = (TextView) row.findViewById(R.id.distance);
TextView timeLabel = (TextView) row.findViewById(R.id.time);
+ TextView cumulativeDistanceLabel = (TextView) row.findViewById(R.id.cumulative_distance);
+ TextView cumulativeTimeLabel = (TextView) row.findViewById(R.id.cumulative_time);
ImageView icon = (ImageView) row.findViewById(R.id.direction);
TurnPathHelper.RouteDrawable drawable = new TurnPathHelper.RouteDrawable(getResources());
drawable.setRouteType(model.getTurnType());
icon.setImageDrawable(drawable);
-
- distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, getMyApplication()));
- label.setText(model.getDescriptionRoute(((OsmandApplication) getApplication())));
- String timeText = getTimeDescription(model);
- timeLabel.setText(timeText);
+ distanceLabel.setText(OsmAndFormatter.getFormattedDistance(
+ model.distance, getMyApplication()));
+ timeLabel.setText(getTimeDescription(model));
+ label.setText(model.getDescriptionRoutePart());
+ CumulativeInfo cumulativeInfo = getRouteDirectionCumulativeInfo(position);
+ cumulativeDistanceLabel.setText(OsmAndFormatter.getFormattedDistance(
+ cumulativeInfo.distance, getMyApplication()));
+ cumulativeTimeLabel.setText(Algorithms.formatDuration(cumulativeInfo.time));
return row;
}
-
+ public CumulativeInfo getRouteDirectionCumulativeInfo(int position) {
+ CumulativeInfo cumulativeInfo = new CumulativeInfo();
+ for (int i = 0; i < position; i++) {
+ RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) getItem(i);
+ cumulativeInfo.time += routeDirectionInfo.getExpectedTime();
+ cumulativeInfo.distance += routeDirectionInfo.distance;
+ }
+ return cumulativeInfo;
+ }
}
private String getTimeDescription(RouteDirectionInfo model) {
@@ -198,275 +200,8 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
return Algorithms.formatDuration(timeInSeconds);
}
- @SuppressLint("NewApi")
- private class RouteInfoPrintDocumentAdapter extends PrintDocumentAdapter {
- List list;
- String title;
- float[] pageSize;
- float marginLeft;
- float marginRight;
- float marginTop;
- float marginBottom;
- int totalPages;
- int linesPerPage;
-
- public RouteInfoPrintDocumentAdapter(List list, String title) {
- this.title = title;
- this.list = list;
- pageSize = new float[2];
- marginLeft = 0f;
- marginRight = 0f;
- marginTop = 0f;
- marginBottom = 0f;
- totalPages = 0;
- linesPerPage = 0;
- }
-
- @Override
- public void onLayout(PrintAttributes oldAttributes,
- PrintAttributes newAttributes,
- CancellationSignal cancellationSignal,
- LayoutResultCallback callback, Bundle extras) {
-
- if (cancellationSignal.isCanceled()) {
- callback.onLayoutCancelled();
- return;
- }
-
- pageSize[0] = (float) Math.rint(newAttributes.getMediaSize()
- .getWidthMils() * 72f / 1000f);
- pageSize[1] = (float) Math.rint(newAttributes.getMediaSize()
- .getHeightMils() * 72f / 1000f);
-
- Margins margins = newAttributes.getMinMargins();
- marginLeft = (float) Math.rint(margins.getLeftMils() * 72 / 1000f);
- marginRight = (float) Math.rint(margins.getRightMils() * 72 / 1000f);
- marginTop = (float) Math.rint(margins.getTopMils() * 72 / 1000f);
- marginBottom = (float) Math.rint(margins.getBottomMils() * 72 / 1000f);
- if (marginLeft == 0f) {
- marginLeft = PDF_DERAULT_MARGINS;
- }
- if (marginRight == 0f) {
- marginRight = PDF_DERAULT_MARGINS;
- }
- if (marginTop == 0f) {
- marginTop = PDF_DERAULT_MARGINS;
- }
- if (marginBottom == 0f) {
- marginBottom = PDF_DERAULT_MARGINS;
- }
-
- linesPerPage = computeLinesPerPage();
- totalPages = computePageCount();
-
- if (totalPages > 0) {
- PrintDocumentInfo info = new PrintDocumentInfo.Builder(
- "print_output.pdf")
- .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
- .setPageCount(totalPages).build();
- callback.onLayoutFinished(info, true);
- } else {
- // Otherwise report an error to the print framework
- callback.onLayoutFailed("Page count calculation failed.");
- }
- }
-
- @Override
- public void onWrite(PageRange[] pages,
- ParcelFileDescriptor destination,
- CancellationSignal cancellationSignal,
- WriteResultCallback callback) {
- ArrayList writtenPagesArray = new ArrayList();
-
- PDF pdf = null;
- InputStream fontInputStream = null;
- try {
- pdf = new PDF(new BufferedOutputStream(new FileOutputStream(
- destination.getFileDescriptor())));
- fontInputStream = getAssets().open("fonts/Roboto-Regular.ttf");
- Font font = new Font(pdf, fontInputStream, CodePage.UNICODE, true);
- font.setSize(PDF_FONT_SIZE);
- int totalLinesCount = totalLinesCount();
- int shift = 0;
- if (!TextUtils.isEmpty(title)) {
- shift = 1;
- }
- for (int i = 0; i < totalPages; i++) {
- if (containsPage(pages, i)) {
- Page page = new Page(pdf, pageSize);
- page.setTextStart();
- page.setTextFont(font);
- page.setTextLocation(marginLeft, marginTop);
- page.setTextLeading(PDF_TEXT_LEADING);
- int startLineIndex = i * linesPerPage;
- for (int j = startLineIndex; (j < (startLineIndex + linesPerPage)) && (j < totalLinesCount); j++) {
- if ((j == 0) && (shift > 0)) {
- page.println(title);
- } else {
- RouteDirectionInfo model = list.get(j - shift);
- String distance = OsmAndFormatter.getFormattedDistance(model.distance, getMyApplication());
- String description = model.getDescriptionRoute(((OsmandApplication) getApplication()));
- String timeText = getTimeDescription(model);
- page.println(distance + " " + description + " " + timeText);
- }
- }
- page.setTextEnd();
- writtenPagesArray.add(i);
- }
- }
- } catch (Exception e) {
- callback.onWriteFailed(e.toString());
- return;
- } finally {
- if (pdf != null) {
- try {
- pdf.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- if (fontInputStream != null) {
- try {
- fontInputStream.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- PageRange[] writtenPages = computeWrittenPages(writtenPagesArray);
- callback.onWriteFinished(writtenPages);
- }
-
-
- private int computeLinesPerPage() {
- int linesPerPage = 0;
- if (pageSize[1] > 0) {
- float height = pageSize[1];
- height -= marginTop;
- height -= marginBottom;
- linesPerPage = (int)(height / PDF_FONT_SIZE + PDF_TEXT_LEADING);
- }
-
- return linesPerPage;
- }
-
- private int computePageCount() {
- int pageCount = 0;
- int totalLinesCount = totalLinesCount();
- if ((totalLinesCount > 0) && (linesPerPage > 0)) {
- pageCount = totalLinesCount / linesPerPage;
- if ((totalLinesCount % linesPerPage) != 0) {
- pageCount++;
- }
- }
-
- return pageCount;
- }
-
- private int totalLinesCount() {
- int totalLinesCount = list.size();
- if (!TextUtils.isEmpty(title)) {
- totalLinesCount++;
- }
- return totalLinesCount;
- }
-
- private boolean containsPage(PageRange[] pages, int page) {
- boolean contains = false;
- for (int i = 0; i < pages.length; i++) {
- if (pages[i].equals(PageRange.ALL_PAGES)) {
- contains = true;
- break;
- } else if ((pages[i].getStart() <= page)
- && (page <= pages[i].getEnd())) {
- contains = true;
- break;
- }
- }
-
- return contains;
- }
-
- private PageRange[] computeWrittenPages(List pages) {
- ArrayList writtenPagesList = new ArrayList();
- int pagesSize = pages.size();
- if (pagesSize > 0) {
- int start = pages.get(0);
- int end = start;
- for (int i = 1; i < pagesSize; i++) {
- int page = pages.get(i);
- if ((page - end) > 1) {
- PageRange pageRange = new PageRange(start, end);
- writtenPagesList.add(pageRange);
- start = page;
- }
- end = page;
- }
- PageRange lastPageRange = null;
- int writtenPagesListSize = writtenPagesList.size();
- if (writtenPagesListSize > 0) {
- lastPageRange = writtenPagesList.get(writtenPagesListSize - 1);
- }
- if (lastPageRange == null) {
- writtenPagesList.add(PageRange.ALL_PAGES);
- } else {
- PageRange pageRange = new PageRange(start, end);
- if (!lastPageRange.equals(pageRange)) {
- writtenPagesList.add(pageRange);
- }
- }
- } else {
- writtenPagesList.add(PageRange.ALL_PAGES);
- }
-
- PageRange[] writtenPages = new PageRange[writtenPagesList.size()];
- writtenPagesList.toArray(writtenPages);
- return writtenPages;
- }
- }
-
void print() {
- // Just live uncommented preferred printing option pdf or html
-// printViaPdf(); // for study the possibilities
- printViaHtml();
- }
-
- @SuppressLint("NewApi")
- void printViaPdf() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework
- PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
-
- // Get a print adapter instance
- PrintDocumentAdapter printAdapter = new RouteInfoPrintDocumentAdapter(
- ((OsmandApplication) getApplication()).getRoutingHelper()
- .getRouteDirections(),
- helper.getGeneralRouteInformation());
-
- // Create a print job with name and adapter instance
- String jobName = "OsmAnd route info";
- printManager.print(jobName, printAdapter,
- new PrintAttributes.Builder().build());
- } else { // just open pdf
- File file = generateRouteInfoPdf(
- ((OsmandApplication) getApplication()).getRoutingHelper()
- .getRouteDirections(),
- helper.getGeneralRouteInformation());
- if (file.exists()) {
- Uri uri = Uri.fromFile(file);
- Intent intent;
- intent = new Intent(Intent.ACTION_VIEW).setDataAndType(
- uri, "application/pdf");
- startActivity(intent);
- }
- }
- }
-
- @SuppressLint("NewApi")
- void printViaHtml() {
- File file = generateRouteInfoHtml(
- ((OsmandApplication) getApplication()).getRoutingHelper()
- .getRouteDirections(),
+ File file = generateRouteInfoHtml((RouteInfoAdapter)getListAdapter(),
helper.getGeneralRouteInformation());
if (file.exists()) {
Uri uri = Uri.fromFile(file);
@@ -482,39 +217,78 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
}
}
- private File generateRouteInfoHtml(List list, String title) {
- final String FILE_NAME = "route_info.html";
+ private File generateRouteInfoHtml(RouteInfoAdapter routeInfo, String title) {
File file = null;
+ if (routeInfo == null) {
+ return file;
+ }
+ final String FILE_NAME = "route_info.html";
StringBuilder html = new StringBuilder();
html.append("");
html.append("");
html.append("");
html.append("Route info");
html.append("");
+ html.append("");
html.append("");
html.append("");
FileOutputStream fos = null;
try {
if (!TextUtils.isEmpty(title)) {
- html.append("");
+ html.append("
");
html.append(title);
- html.append("
");
+ html.append("");
}
+ html.append("");
final String NBSP = " ";
- for (RouteDirectionInfo routeDirectionInfo : list) {
- html.append("");
- String distance = OsmAndFormatter.getFormattedDistance(routeDirectionInfo.distance, getMyApplication());
+ final String BR = "
";
+ for (int i = 0; i < routeInfo.getCount(); i++) {
+ RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo
+ .getItem(i);
+ html.append("
");
+ StringBuilder sb = new StringBuilder();
+ sb.append(OsmAndFormatter.getFormattedDistance(
+ routeDirectionInfo.distance, getMyApplication()));
+ sb.append(", ");
+ sb.append(getTimeDescription(routeDirectionInfo));
+ String distance = sb.toString().replaceAll("\\s", NBSP);
+ html.append("");
html.append(distance);
- html.append(NBSP);
- String description = routeDirectionInfo.getDescriptionRoute(((OsmandApplication) getApplication()));
- html.append(description);
- html.append(NBSP);
- String timeText = getTimeDescription(routeDirectionInfo);
- html.append(timeText);
- html.append("");
+ html.append(" | ");
+ String description = routeDirectionInfo
+ .getDescriptionRoutePart();
+ html.append("");
+ html.append(description);
+ html.append(" | ");
+ RouteInfoAdapter.CumulativeInfo cumulativeInfo = routeInfo
+ .getRouteDirectionCumulativeInfo(i);
+ html.append("");
+ sb = new StringBuilder();
+ sb.append(OsmAndFormatter.getFormattedDistance(
+ cumulativeInfo.distance, getMyApplication()));
+ sb.append(" - ");
+ sb.append(OsmAndFormatter.getFormattedDistance(
+ cumulativeInfo.distance + routeDirectionInfo.distance,
+ getMyApplication()));
+ sb.append(BR);
+ sb.append(Algorithms.formatDuration(cumulativeInfo.time));
+ sb.append(" - ");
+ sb.append(Algorithms.formatDuration(cumulativeInfo.time
+ + routeDirectionInfo.getExpectedTime()));
+ String cumulativeTimeAndDistance = sb.toString().replaceAll("\\s", NBSP);
+ html.append(cumulativeTimeAndDistance);
+ html.append(" | ");
+ html.append("
");
}
+ html.append("
");
html.append("");
html.append("");
@@ -541,73 +315,5 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
return file;
}
- private File generateRouteInfoPdf(List list, String title) {
- final String FILE_NAME = "route_info.pdf";
- File file = new File(((OsmandApplication) getApplication())
- .getAppCustomization().getExternalStorageDir(),
- IndexConstants.APP_DIR + FILE_NAME);
-
- PDF pdf = null;
- InputStream fontInputStream = null;
- try {
- pdf = new PDF(new BufferedOutputStream(new FileOutputStream(file)));
- fontInputStream = getAssets().open("fonts/Roboto-Regular.ttf");
- Font font = new Font(pdf, fontInputStream, CodePage.UNICODE, true);
- font.setSize(PDF_FONT_SIZE);
- Page page = new Page(pdf, A4.PORTRAIT);
- page.setTextStart();
- page.setTextFont(font);
- page.setTextLocation(PDF_DERAULT_MARGINS, PDF_DERAULT_MARGINS);
- page.setTextLeading(PDF_TEXT_LEADING);
- float height = page.getHeight() - 2 * PDF_DERAULT_MARGINS;
- int linesPerPage = (int)(height / PDF_FONT_SIZE + PDF_TEXT_LEADING);
- int lines = 0;
- if (!TextUtils.isEmpty(title)) {
- page.println(title);
- lines++;
- }
- for (RouteDirectionInfo routeDirectionInfo : list) {
- if (lines > linesPerPage) {
- page.setTextEnd();
- page = new Page(pdf, A4.PORTRAIT);
- page.setTextStart();
- page.setTextFont(font);
- page.setTextLocation(PDF_DERAULT_MARGINS, PDF_DERAULT_MARGINS);
- page.setTextLeading(PDF_TEXT_LEADING);
- lines = 0;
- }
- String distance = OsmAndFormatter.getFormattedDistance(
- routeDirectionInfo.distance, getMyApplication());
- String description = routeDirectionInfo
- .getDescriptionRoute(((OsmandApplication) getApplication()));
- String timeText = getTimeDescription(routeDirectionInfo);
- page.println(distance + " " + description + " " + timeText);
-
- lines++;
- }
- page.setTextEnd();
- } catch (Exception e) {
- file = null;
- } finally {
- if (pdf != null) {
- try {
- pdf.close();
- } catch (Exception e) {
- file = null;
- e.printStackTrace();
- }
- }
- if (fontInputStream != null) {
- try {
- fontInputStream.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- return file;
- }
-
}