From 016f4acd3b33a808262fcf3642b479c595a2a1ce Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 8 Mar 2014 15:50:07 +0100 Subject: [PATCH] Fix navigate action menu & put read time out for tiles --- .../src/net/osmand/map/MapTileDownloader.java | 6 +- .../osmand/router/RoutingConfiguration.java | 1 + .../plus/activities/SettingsBaseActivity.java | 26 +----- .../activities/actions/NavigateAction.java | 91 +++++++++++-------- 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java index 6d931e3349..bbc1148438 100644 --- a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java +++ b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java @@ -27,7 +27,8 @@ public class MapTileDownloader { public static int TILE_DOWNLOAD_THREADS = 4; public static int TILE_DOWNLOAD_SECONDS_TO_WORK = 25; public static final long TIMEOUT_AFTER_EXCEEDING_LIMIT_ERRORS = 15000; - public static final int TILE_DOWNLOAD_MAX_ERRORS_PER_TIMEOUT = 25; + public static final int TILE_DOWNLOAD_MAX_ERRORS_PER_TIMEOUT = 50; + private static final int CONNECTION_TIMEOUT = 10000; private static MapTileDownloader downloader = null; @@ -187,7 +188,8 @@ public class MapTileDownloader { URL url = new URL(request.url); URLConnection connection = url.openConnection(); connection.setRequestProperty("User-Agent", USER_AGENT); //$NON-NLS-1$ - connection.setConnectTimeout(35000); + connection.setConnectTimeout(CONNECTION_TIMEOUT); + connection.setReadTimeout(CONNECTION_TIMEOUT); BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream(), 8 * 1024); FileOutputStream stream = null; try { diff --git a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java index e9cae01794..fe8da2f45a 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java @@ -170,6 +170,7 @@ public class RoutingConfiguration { } } } + is.close(); return config; } diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index 300663bf9d..6ff167ead4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -282,30 +282,6 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im } } getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - // getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - // ActionBar.TabListener tl = new ActionBar.TabListener() { - // - // @Override - // public void onTabSelected(Tab tab, android.support.v4.app.FragmentTransaction ft) { - // osmandSettings.APPLICATION_MODE.set(modes.get(tab.getPosition())); - // createUI(); - // updateAllSettings(); - // - // } - // - // @Override - // public void onTabUnselected(Tab tab, android.support.v4.app.FragmentTransaction ft) { - // } - // - // @Override - // public void onTabReselected(Tab tab, android.support.v4.app.FragmentTransaction ft) { - // } - // - // }; - // for (ApplicationMode a : modes) { - // Tab t = getSupportActionBar().newTab().setText(a.toHumanString(getMyApplication())).setTabListener(tl); - // getSupportActionBar().addTab(t); - // } List s = new ArrayList(); for (ApplicationMode a : modes) { s.add(a.toHumanString(getMyApplication())); @@ -348,7 +324,7 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im protected void profileDialog() { Builder b = new AlertDialog.Builder(this); final Set selected = new LinkedHashSet(); - View v = NavigateAction.prepareAppModeView(this, selected, false, null, false, + View v = NavigateAction.prepareAppModeView(this, selected, false, null, true, new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java index a2f401f3e3..308f879235 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java @@ -397,6 +397,7 @@ public class NavigateAction { ViewGroup parent, final boolean singleSelection, final View.OnClickListener onClickListener) { LinearLayout ll = (LinearLayout) a.getLayoutInflater().inflate(R.layout.mode_toggles, parent); final ToggleButton[] buttons = createToggles(values, ll, a); + final boolean[] selectionChangeLoop = new boolean[] {false}; for (int i = 0; i < buttons.length; i++) { if (buttons[i] != null) { final int ind = i; @@ -406,51 +407,69 @@ public class NavigateAction { b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (singleSelection) { - if (isChecked) { - selected.clear(); - for (int j = 0; j < buttons.length; j++) { - if (buttons[j] != null) { - if (ind == j) { - selected.add(values.get(j)); - } - if (buttons[j].isChecked() != (ind == j)) { - buttons[j].setChecked(ind == j); - } - } - } - } else { - // revert state - boolean revert = true; - for (int j = 0; j < buttons.length; j++) { - if (buttons[j] != null) { - if (buttons[j].isChecked()) { - revert = false; - break; - } - } - } - if (revert) { - buttons[ind].setChecked(true); - } - } - } else { - if (isChecked) { - selected.add(buttonAppMode); - } else { - selected.remove(buttonAppMode); - } + if (selectionChangeLoop[0]) { + return; } - if(onClickListener != null) { - onClickListener.onClick(null); + selectionChangeLoop[0] = true; + try { + handleSelection(values, selected, singleSelection, buttons, ind, buttonAppMode, isChecked); + if (onClickListener != null) { + onClickListener.onClick(null); + } + } finally { + selectionChangeLoop[0] = false; } } + + }); } } return ll; } + private static void handleSelection(final List values, + final Set selected, final boolean singleSelection, + final ToggleButton[] buttons, final int ind, final ApplicationMode buttonAppMode, + boolean isChecked) { + if (singleSelection) { + if (isChecked) { + selected.clear(); + for (int j = 0; j < buttons.length; j++) { + if (buttons[j] != null) { + boolean selectedState = ind == j; + if (selectedState) { + selected.add(values.get(j)); + } + if (buttons[j].isChecked() != selectedState) { + buttons[j].setChecked(selectedState); + } + } + } + } else { + // revert state + boolean revert = true; + for (int j = 0; j < buttons.length; j++) { + if (buttons[j] != null) { + if (buttons[j].isChecked()) { + revert = false; + break; + } + } + } + if (revert) { + buttons[ind].setChecked(true); + } + } + } else { + if (isChecked) { + selected.add(buttonAppMode); + } else { + selected.remove(buttonAppMode); + } + } + } + private Spinner setupFromSpinner(final Location mapView, String name, View view, DirectionDialogStyle style) { String currentLocation = mapActivity.getString(R.string.route_descr_current_location); ArrayList fromActions = new ArrayList();