From ab0878dd442597d62d3e824542529a38d06d95b8 Mon Sep 17 00:00:00 2001 From: Dmitry Olyenyov Date: Tue, 23 Oct 2012 15:51:05 +0600 Subject: [PATCH] Share location via QR-Code using ZXing Barcode Scanner --- OsmAnd/res/values-ru/strings.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../plus/activities/MapActivityActions.java | 43 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index a723d0f836..c5169c0810 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,5 +1,6 @@ + Приложение \'Сканнер штрих-кодов\' не найдено. Искать на Маркете? Рассчитать неоптимальный (возможно) маршрут на длинные дистанции Загрузите или обновите локальные данные. \nЧтобы получить дополнительную информацию о карте, выделите её в списке. Удерживайте карту, если вы хотите удалить или деактивировать. diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 2d042359be..bb2a92a899 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 1. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + ZXing Barcode Scanner application not installed. Search in Market? Select a road color scheme: Road color scheme Show destination direction diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 9cfe1da619..b6fea4f7b5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -89,7 +89,9 @@ public class MapActivityActions implements DialogProvider { private static final String GPS_STATUS_COMPONENT = "com.eclipsim.gpsstatus2"; //$NON-NLS-1$ private static final String GPS_STATUS_ACTIVITY = "com.eclipsim.gpsstatus2.GPSStatus"; //$NON-NLS-1$ - + private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$ + private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$ + private static final String KEY_LONGITUDE = "longitude"; private static final String KEY_LATITUDE = "latitude"; private static final String KEY_NAME = "name"; @@ -353,7 +355,7 @@ public class MapActivityActions implements DialogProvider { AlertDialog.Builder builder = new Builder(mapActivity); builder.setTitle(R.string.send_location_way_choose_title); builder.setItems(new String[]{ - "Email", "SMS", "Clipboard", "geo:" + "Email", "SMS", "Clipboard", "geo:", "QR-Code" }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -386,6 +388,43 @@ public class MapActivityActions implements DialogProvider { Uri location = Uri.parse(simpleGeo); Intent mapIntent = new Intent(Intent.ACTION_VIEW, location); mapActivity.startActivity(mapIntent); + } else if(which == 4){ + Bundle bundle = new Bundle(); + bundle.putFloat("LAT", (float) latitude); + bundle.putFloat("LONG", (float)longitude); + + Intent intent = new Intent(); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setAction(ZXING_BARCODE_SCANNER_ACTIVITY); + ResolveInfo resolved = mapActivity.getPackageManager().resolveActivity(intent, + PackageManager.MATCH_DEFAULT_ONLY); + + if (resolved != null) { + intent.putExtra("ENCODE_TYPE", "LOCATION_TYPE"); + intent.putExtra("ENCODE_DATA", bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + mapActivity.startActivity(intent); + } else { + if (Version.isGooglePlayEnabled(mapActivity)) { + AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity); + builder.setMessage(getString(R.string.zxing_barcode_scanner_not_found)); + builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + ZXING_BARCODE_SCANNER_COMPONENT)); + try { + mapActivity.startActivity(intent); + } catch (ActivityNotFoundException e) { + } + } + }); + builder.setNegativeButton(getString(R.string.default_buttons_no), null); + builder.show(); + } else { + Toast.makeText(mapActivity, R.string.zxing_barcode_scanner_not_found, Toast.LENGTH_LONG).show(); + } + } } }