Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9a60689
First commit for abbreviations using MAS snapshot
Mar 26, 2018
a64b521
Updated by removing custom comparator
Apr 4, 2018
7ff4fc9
Merge remote-tracking branch 'origin/master' into devota-abbreviations
Apr 12, 2018
4a39697
Merge remote-tracking branch 'origin/master' into devota-abbreviations
Apr 13, 2018
297ded2
Merge remote-tracking branch 'origin/master' into devota-abbreviations
Apr 13, 2018
a6a86f4
Added InstructionBuilder without implementation
Apr 13, 2018
da17d64
Added text as filler for banner shields and continued work on combini…
Apr 16, 2018
59f6556
Continued abbreviation work
Apr 18, 2018
ffc8d81
Continued working on abbreviations but having issues sorting list of …
Apr 18, 2018
5f6db50
Merge branch 'master' into devota-abbreviations
Apr 18, 2018
9bd0911
Merge branch 'master' into devota-abbreviations
Apr 20, 2018
3c25ab7
Merge branch 'master' into devota-abbreviations
Apr 23, 2018
c1890f5
First commit with InstructionBuilder fixed up
Apr 25, 2018
91bafc7
Cleanup
Apr 25, 2018
9cf38b3
Refactored to separate concerns
Apr 25, 2018
5fff99c
Merge branch 'master' into devota-abbreviations
Apr 25, 2018
21a57b5
Added startIndex to Node constructor for consistency
Apr 25, 2018
2c23887
Cleanup
Apr 25, 2018
183c2d9
Removed snapshots
Apr 25, 2018
01707cd
Added private modifiers
Apr 25, 2018
ef73dd9
Removed logging
Apr 25, 2018
8de18f2
Fixed checkstyle issue
Apr 26, 2018
eb97a3a
Merge branch 'master' into devota-abbreviations
Apr 30, 2018
95a724b
Refactored to separate concerns even further
Apr 30, 2018
73cc170
Fixed bug where navigation froze when text never fit TextView
Apr 30, 2018
dc32393
Cleared shieldUrls to prevent re-using images in subsequent instructions
Apr 30, 2018
62560b1
Renamed variables and reduced passing of global variables
May 1, 2018
30a525d
Fixed typo in bug fix
May 1, 2018
321fecf
Limited secondary text to one line
May 1, 2018
c256485
Added AbbreviationCoordinatorTest along with helper classes/methods
May 7, 2018
412317a
Merge branch 'master' into devota-abbreviations
May 7, 2018
9ea777f
Added test files
May 8, 2018
7ef6e69
Refactoring to reduce use of global variables and increase modularity…
May 8, 2018
cccccf5
Changed InstructionLoader to not be a singleton
May 8, 2018
2732823
Added tests for InstructionLoader
May 9, 2018
ef3220b
Refactored so to not add unnecessary parameter
May 9, 2018
a14bf82
Cleanup
May 9, 2018
9ad6125
Merge branch 'master' into devota-abbreviations
May 15, 2018
ed3e959
Merge branch 'master' into devota-abbreviations
May 16, 2018
50e8adf
Extracted booleans into variables
May 16, 2018
bf34537
Refactored for clarity
May 16, 2018
8858ac2
Fixed checkstyle issues
May 16, 2018
387ee2d
Merge branch 'master' into devota-abbreviations
May 16, 2018
49d7da3
Merge branch 'master' into devota-abbreviations
May 17, 2018
1edda00
Made changes according to PR comments
May 17, 2018
a45401b
Merge branch 'master' into devota-abbreviations
May 17, 2018
b7d53a5
Updated test names
May 17, 2018
4a8427b
Cleanup from PR comments
May 18, 2018
13dd699
Refactored name
May 18, 2018
2698e05
Renamed ImageLoader to ImageCoordinator
May 18, 2018
7de31c7
Fixed bug
May 18, 2018
c288365
Merge branch 'master' into devota-abbreviations
May 18, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera;
import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionLoader;
import com.mapbox.services.android.navigation.ui.v5.instruction.ImageCoordinator;
import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.ui.v5.summary.SummaryBottomSheet;
Expand Down Expand Up @@ -181,7 +181,7 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
public void onDestroy() {
mapView.onDestroy();
navigationViewModel.onDestroy(isChangingConfigurations());
InstructionLoader.getInstance().shutdown();
ImageCoordinator.getInstance().shutdown();
if (camera != null) {
camera.onDestroy();
}
Expand Down Expand Up @@ -404,7 +404,7 @@ public MapboxMap getMapboxMap() {
}

private void initializeView() {
InstructionLoader.getInstance().initialize(getContext());
ImageCoordinator.getInstance().initialize(getContext());
inflate(getContext(), R.layout.navigation_view_layout, this);
bind();
initializeNavigationViewModel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import android.widget.TextView;

import com.mapbox.api.directions.v5.models.BannerComponents;
import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionLoader.BannerComponentNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* This class allows text to be constructed to fit a given TextView, given specified
* BannerComponents containing abbreviation information and given a list of BannerComponentNodes,
* constructed by InstructionLoader.
*/
class AbbreviationCoordinator {
private static final String SINGLE_SPACE = " ";
private Map<Integer, List<Integer>> abbreviations;
private TextViewUtils textViewUtils;

AbbreviationCoordinator(TextViewUtils textViewUtils) {
this.abbreviations = new HashMap<>();
this.textViewUtils = textViewUtils;
}

AbbreviationCoordinator() {
this(new TextViewUtils());
}

/**
* Adds the given BannerComponents object to the list of abbreviations so that when the list of
* BannerComponentNodes is completed, text can be abbreviated properly to fit the specified
* TextView.
*
* @param bannerComponents object holding the abbreviation information
* @param index in the list of BannerComponentNodes
*/
void addPriorityInfo(BannerComponents bannerComponents, int index) {
Integer abbreviationPriority = bannerComponents.abbreviationPriority();
if (abbreviations.get(abbreviationPriority) == null) {
abbreviations.put(abbreviationPriority, new ArrayList<Integer>());
}
abbreviations.get(abbreviationPriority).add(index);
}

/**
* Using the abbreviations HashMap which should already be populated, abbreviates the text in the
* bannerComponentNodes until the text fits the given TextView.
*
* @param bannerComponentNodes containing the text to construct
* @param textView to check the text fits
* @return the properly abbreviated string that will fit in the TextView
*/
String abbreviateBannerText(List<BannerComponentNode> bannerComponentNodes, TextView textView) {
String bannerText = join(bannerComponentNodes);

if (abbreviations.isEmpty()) {
return bannerText;
}

bannerText = abbreviateUntilTextFits(textView, bannerText, bannerComponentNodes);

abbreviations.clear();
return bannerText;
}

private String abbreviateUntilTextFits(TextView textView, String startingText,
List<BannerComponentNode> bannerComponentNodes) {
int currAbbreviationPriority = 0;
int maxAbbreviationPriority = Collections.max(abbreviations.keySet());
String bannerText = startingText;

while (shouldKeepAbbreviating(textView, bannerText, currAbbreviationPriority, maxAbbreviationPriority)) {
List<Integer> indices = abbreviations.get(currAbbreviationPriority++);

boolean abbreviationPriorityExists = abbreviateAtAbbreviationPriority(bannerComponentNodes, indices);

if (abbreviationPriorityExists) {
bannerText = join(bannerComponentNodes);
}
}

return bannerText;
}

private boolean shouldKeepAbbreviating(TextView textView, String bannerText,
int currAbbreviationPriority, int maxAbbreviationPriority) {
return !textViewUtils.textFits(textView, bannerText) && currAbbreviationPriority <= maxAbbreviationPriority;
}

private boolean abbreviateAtAbbreviationPriority(List<BannerComponentNode> bannerComponentNodes,
List<Integer> indices) {
if (indices == null) {
return false;
}

for (Integer index : indices) {
abbreviate(bannerComponentNodes.get(index));
}

return true;
}

private void abbreviate(BannerComponentNode bannerComponentNode) {
((AbbreviationNode) bannerComponentNode).setAbbreviate(true);
}

private String join(List<BannerComponentNode> tokens) {
StringBuilder stringBuilder = new StringBuilder();
Iterator<BannerComponentNode> iterator = tokens.iterator();
BannerComponentNode bannerComponentNode;

if (iterator.hasNext()) {
bannerComponentNode = iterator.next();
bannerComponentNode.setStartIndex(stringBuilder.length());
stringBuilder.append(bannerComponentNode);

while (iterator.hasNext()) {
stringBuilder.append(SINGLE_SPACE);
bannerComponentNode = iterator.next();
bannerComponentNode.setStartIndex(stringBuilder.length());
stringBuilder.append(bannerComponentNode);
}
}

return stringBuilder.toString();
}

/**
* Class used by InstructionLoader to determine that a BannerComponent contains an abbreviation
*/
static class AbbreviationNode extends BannerComponentNode {
boolean abbreviate;

AbbreviationNode(BannerComponents bannerComponents, int startIndex) {
super(bannerComponents, startIndex);
}

@Override
public String toString() {
return abbreviate ? bannerComponents.abbreviation() : bannerComponents.text();
}

void setAbbreviate(boolean abbreviate) {
this.abbreviate = abbreviate;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mapbox.services.android.navigation.ui.v5.instruction;

import com.mapbox.api.directions.v5.models.BannerComponents;

class BannerShield {
private String url;
private String text;
private int nodeIndex;
private int startIndex = -1;

BannerShield(BannerComponents bannerComponents, int nodeIndex) {
this.url = bannerComponents.imageBaseUrl();
this.nodeIndex = nodeIndex;
this.text = bannerComponents.text();
}

String getUrl() {
return url;
}

public String getText() {
return text;
}

public int getNodeIndex() {
return nodeIndex;
}

public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}

public int getStartIndex() {
return startIndex;
}

int getEndIndex() {
return startIndex + text.length();
}
}

This file was deleted.

Loading