diff options
author | Torsten Keil <github@torsten-keil.net> | 2012-02-21 21:50:41 +0100 |
---|---|---|
committer | Torsten Keil <github@torsten-keil.net> | 2012-02-22 00:09:27 +0100 |
commit | f60a64ef2349a1f9fe6933f028f50e146ec958fd (patch) | |
tree | 37556ea43fd35d0bdffdb415ea45ad9016db3325 /main/src/cgeo | |
parent | 009c9575e84379612a710955436f703c7a27bdbc (diff) | |
download | cgeo-f60a64ef2349a1f9fe6933f028f50e146ec958fd.zip cgeo-f60a64ef2349a1f9fe6933f028f50e146ec958fd.tar.gz cgeo-f60a64ef2349a1f9fe6933f028f50e146ec958fd.tar.bz2 |
Implementation for #1155 - the second default navigation tool is
introduced
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 23 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 15 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java | 49 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoinit.java | 44 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeopopup.java | 23 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeowaypoint.java | 27 |
6 files changed, 175 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 528b2e2..abb096b 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -65,6 +65,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.ViewParent; @@ -262,6 +263,15 @@ public class CacheDetailActivity extends AbstractActivity { // nothing, we lost the window } + ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation); + defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + startDefaultNavigation2(); + return true; + } + }); + // initialize ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); viewPagerAdapter = new ViewPagerAdapter(); @@ -840,6 +850,19 @@ public class CacheDetailActivity extends AbstractActivity { } /** + * Tries to navigate to the {@link cgCache} of this activity. + */ + private void startDefaultNavigation2() { + if (cache == null || cache.getCoords() == null) { + showToast(res.getString(R.string.err_location_unknown)); + return; + } + + //TODO: previously this used also the search argument "search". check if still needed + NavigationAppFactory.startDefaultNavigationApplication2(geolocation, this, cache, null, null); + } + + /** * Wrapper for the referenced method in the xml-layout. */ public void startDefaultNavigation(@SuppressWarnings("unused") View view) { diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 4f9a240..af1ad0a 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -76,6 +76,7 @@ public final class Settings { private static final String KEY_LAST_DETAILS_PAGE = "lastdetailspage"; private static final String KEY_DEBUG_INFORMATIONS = "debuginfos"; private static final String KEY_DEFAULT_NAVIGATION_TOOL = "defaultNavigationTool"; + private static final String KEY_DEFAULT_NAVIGATION_TOOL_2 = "defaultNavigationTool2"; private final static int unitsMetric = 1; private final static int unitsImperial = 2; @@ -999,4 +1000,18 @@ public final class Settings { } }); } + + public static int getDefaultNavigationTool2() { + return sharedPrefs.getInt(KEY_DEFAULT_NAVIGATION_TOOL_2, 0); + } + + public static void setDefaultNavigationTool2(final int defaultNavigationTool) { + editSharedSettings(new PrefRunnable() { + + @Override + public void edit(Editor edit) { + edit.putInt(KEY_DEFAULT_NAVIGATION_TOOL_2, defaultNavigationTool); + } + }); + } } diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 53240bc..e2a1fc1 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -90,7 +90,7 @@ public final class NavigationAppFactory extends AbstractAppFactory { /** * Specialized way to handle selection of navigation tool.<br /> * A dialog is created for tool selection and the selected tool is started afterwards. - * + * * @param geo * @param activity * @param cache @@ -103,7 +103,7 @@ public final class NavigationAppFactory extends AbstractAppFactory { * should be <code>false</code> only when called from within the internal map * @param showDefaultNavigation * should be <code>false</code> by default - * + * * @see #showNavigationMenu(cgGeo, Activity, cgCache, cgWaypoint, Geopoint) */ public static void showNavigationMenu(final cgGeo geo, final Activity activity, @@ -297,8 +297,31 @@ public final class NavigationAppFactory extends AbstractAppFactory { } /** + * Starts the second default navigation tool if correctly set and installed or the compass app as default fallback. + * + * @param geo + * @param activity + * @param cache + * @param search + * @param waypoint + * @param destination + */ + public static void startDefaultNavigationApplication2(final cgGeo geo, Activity activity, cgCache cache, + cgWaypoint waypoint, final Geopoint destination) { + final NavigationApp app = getDefaultNavigationApplication2(activity); + + if (app != null) { + try { + app.invoke(geo, activity, cache, waypoint, destination); + } catch (Exception e) { + Log.e(Settings.tag, "NavigationAppFactory.startDefaultNavigationApplication2: " + e.toString()); + } + } + } + + /** * Returns the default navigation tool if correctly set and installed or the compass app as default fallback - * + * * @param activity * @return never <code>null</code> */ @@ -316,4 +339,24 @@ public final class NavigationAppFactory extends AbstractAppFactory { return NavigationAppsEnum.COMPASS.app; } + /** + * Returns the second default navigation tool if correctly set and installed or the compass app as default fallback + * + * @param activity + * @return never <code>null</code> + */ + public static NavigationApp getDefaultNavigationApplication2(Activity activity) { + final int defaultNavigationTool = Settings.getDefaultNavigationTool2(); + + final List<NavigationAppsEnum> installedNavigationApps = getInstalledNavigationApps(activity); + + for (NavigationAppsEnum navigationApp : installedNavigationApps) { + if (navigationApp.id == defaultNavigationTool) { + return navigationApp.app; + } + } + // second default navigation tool wasn't set already or couldn't be found (not installed any more for example) + return NavigationAppsEnum.COMPASS.app; + } + } diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 5a601ac..0839f46 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -619,6 +619,50 @@ public class cgeoinit extends AbstractActivity { } }); + // 2nd Default navigation tool settings + Spinner defaultNavigationTool2Selector = (Spinner) findViewById(R.id.default_navigation_tool_2); + // final List<NavigationAppsEnum> apps = NavigationAppFactory.getInstalledNavigationApps(this); + ArrayAdapter<NavigationAppsEnum> navi2Adapter = new ArrayAdapter<NavigationAppsEnum>(this, android.R.layout.simple_spinner_item, apps) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView textView = (TextView) super.getView(position, convertView, parent); + textView.setText(getItem(position).app.getName()); + return textView; + } + + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + TextView textView = (TextView) super.getDropDownView(position, convertView, parent); + textView.setText(getItem(position).app.getName()); + return textView; + } + }; + navi2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + defaultNavigationTool2Selector.setAdapter(navi2Adapter); + int defaultNavigationTool2 = Settings.getDefaultNavigationTool2(); + int ordinal2 = 0; + for (int i = 0; i < apps.size(); i++) { + if (apps.get(i).id == defaultNavigationTool2) { + ordinal2 = i; + break; + } + } + defaultNavigationTool2Selector.setSelection(ordinal2); + defaultNavigationTool2Selector.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + NavigationAppsEnum item = (NavigationAppsEnum) parent.getItemAtPosition(position); + if (item != null) { + Settings.setDefaultNavigationTool2(item.id); + } + } + + @Override + public void onNothingSelected(AdapterView<?> arg0) { + // noop + } + }); + refreshBackupLabel(); } diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index e7bf143..1a2d26e 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -26,6 +26,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; @@ -128,6 +129,16 @@ public class cgeopopup extends AbstractActivity { finish(); return; } + + ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation); + defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + startDefaultNavigation2(); + return true; + } + }); + } @Override @@ -632,6 +643,18 @@ public class cgeopopup extends AbstractActivity { finish(); } + /** + * Tries to navigate to the {@link cgCache} of this activity. + */ + private void startDefaultNavigation2() { + if (cache == null || cache.getCoords() == null) { + showToast(res.getString(R.string.cache_coordinates_no)); + return; + } + NavigationAppFactory.startDefaultNavigationApplication2(geo, this, cache, null, null); + finish(); + } + @Override public void goManual(View view) { super.goManual(view); diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java index 84eac46..7fbf14a 100644 --- a/main/src/cgeo/geocaching/cgeowaypoint.java +++ b/main/src/cgeo/geocaching/cgeowaypoint.java @@ -18,6 +18,7 @@ import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.View.OnLongClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; @@ -54,7 +55,7 @@ public class cgeowaypoint extends AbstractActivity { } else { final TextView identification = (TextView) findViewById(R.id.identification); final TextView coords = (TextView) findViewById(R.id.coordinates); - final ImageView compass = (ImageView) findViewById(R.id.compass); + final ImageView defaultNavigation = (ImageView) findViewById(R.id.defaultNavigation); final View separator = findViewById(R.id.separator); final View headline = findViewById(R.id.headline); @@ -76,11 +77,11 @@ public class cgeowaypoint extends AbstractActivity { if (waypoint.getCoords() != null) { coords.setText(Html.fromHtml(waypoint.getCoords().toString()), TextView.BufferType.SPANNABLE); - compass.setVisibility(View.VISIBLE); + defaultNavigation.setVisibility(View.VISIBLE); separator.setVisibility(View.VISIBLE); } else { coords.setText(res.getString(R.string.waypoint_unknown_coordinates)); - compass.setVisibility(View.GONE); + defaultNavigation.setVisibility(View.GONE); separator.setVisibility(View.GONE); } registerNavigationMenu(coords); @@ -163,6 +164,15 @@ public class cgeowaypoint extends AbstractActivity { waitDialog.setCancelable(true); (new loadWaypoint()).start(); + + ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation); + defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + startDefaultNavigation2(); + return true; + } + }); } @Override @@ -341,6 +351,17 @@ public class cgeowaypoint extends AbstractActivity { NavigationAppFactory.startDefaultNavigationApplication(geo, this, null, waypoint, null); } + /** + * Tries to navigate to the {@link cgCache} of this activity. + */ + private void startDefaultNavigation2() { + if (!navigationPossible()) { + return; + } + + NavigationAppFactory.startDefaultNavigationApplication2(geo, this, null, waypoint, null); + } + private boolean navigationPossible() { if (waypoint == null || waypoint.getCoords() == null) { showToast(res.getString(R.string.err_location_unknown)); |