Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Yunitsky <yunik@mapswithme.com>2015-09-03 17:11:03 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:03:47 +0300
commitfff08d3465655a84461d979e5144b41d9e03e40d (patch)
tree98cb032c2a0e91c7f0fbcd0e53910efc0a305468 /android
parent50dd22b914017671de5a0b288515fc876fc951a6 (diff)
[android] Missing routing data dialog fix.
Diffstat (limited to 'android')
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp14
-rw-r--r--android/src/com/mapswithme/maps/Framework.java2
-rw-r--r--android/src/com/mapswithme/maps/MwmActivity.java10
-rw-r--r--android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java109
-rw-r--r--android/src/com/mapswithme/maps/widget/RoutingLayout.java2
5 files changed, 94 insertions, 43 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index 320b7eca0f..bab42c41eb 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -1017,8 +1017,8 @@ extern "C"
JNIEnv * env = jni::GetEnv();
// cache methodID - it cannot change after class is loaded.
// http://developer.android.com/training/articles/perf-jni.html#jclass_jmethodID_and_jfieldID more details here
- // TODO pass & process second vector of absentRoutes
- static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(), "onRoutingEvent", "(I[Lcom/mapswithme/maps/MapStorage$Index;)V");
+ static jmethodID const methodId = jni::GetJavaMethodID(env, *obj.get(), "onRoutingEvent",
+ "(I[Lcom/mapswithme/maps/MapStorage$Index;[Lcom/mapswithme/maps/MapStorage$Index;)V");
ASSERT(methodId, ());
jobjectArray const countriesJava = env->NewObjectArray(absentCountries.size(), g_indexClazz, 0);
@@ -1029,7 +1029,15 @@ extern "C"
env->DeleteLocalRef(country);
}
- env->CallVoidMethod(*obj.get(), methodId, errorCode, countriesJava);
+ jobjectArray const routesJava = env->NewObjectArray(absentRoutes.size(), g_indexClazz, 0);
+ for (size_t i = 0; i < absentRoutes.size(); i++)
+ {
+ jobject route = storage::ToJava(absentRoutes[i]);
+ env->SetObjectArrayElement(routesJava, i, route);
+ env->DeleteLocalRef(route);
+ }
+
+ env->CallVoidMethod(*obj.get(), methodId, errorCode, countriesJava, routesJava);
env->DeleteLocalRef(countriesJava);
}
diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java
index 4a4763fc8e..c8e19e4d48 100644
--- a/android/src/com/mapswithme/maps/Framework.java
+++ b/android/src/com/mapswithme/maps/Framework.java
@@ -46,7 +46,7 @@ public class Framework
@SuppressWarnings("unused")
public interface RoutingListener
{
- void onRoutingEvent(int errorCode, Index[] missingCountries);
+ void onRoutingEvent(int resultCode, Index[] missingCountries, Index[] missingRoutes);
}
@SuppressWarnings("unused")
diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java
index e33b7a09dc..1c634f9a3b 100644
--- a/android/src/com/mapswithme/maps/MwmActivity.java
+++ b/android/src/com/mapswithme/maps/MwmActivity.java
@@ -81,9 +81,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
BasePlacePageAnimationController.OnVisibilityChangedListener,
OnClickListener,
Framework.RoutingListener,
+ Framework.RoutingProgressListener,
MapFragment.MapRenderingListener,
CustomNavigateUpListener,
- Framework.RoutingProgressListener,
ChooseBookmarkCategoryFragment.Listener
{
public static final String EXTRA_TASK = "map_task";
@@ -1340,7 +1340,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
@Override
- public void onRoutingEvent(final int resultCode, final Index[] missingCountries)
+ public void onRoutingEvent(final int resultCode, final Index[] missingCountries, final Index[] missingRoutes)
{
runOnUiThread(new Runnable()
{
@@ -1355,6 +1355,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
final Bundle args = new Bundle();
args.putInt(RoutingErrorDialogFragment.EXTRA_RESULT_CODE, resultCode);
args.putSerializable(RoutingErrorDialogFragment.EXTRA_MISSING_COUNTRIES, missingCountries);
+ args.putSerializable(RoutingErrorDialogFragment.EXTRA_MISSING_ROUTES, missingRoutes);
final RoutingErrorDialogFragment fragment = (RoutingErrorDialogFragment) Fragment.instantiate(MwmActivity.this, RoutingErrorDialogFragment.class.getName());
fragment.setArguments(args);
fragment.setListener(new RoutingErrorDialogFragment.RoutingDialogListener()
@@ -1363,7 +1364,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
public void onDownload()
{
mLayoutRouting.setState(RoutingLayout.State.HIDDEN, false);
- ActiveCountryTree.downloadMapsForIndex(missingCountries, StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING);
+ if (missingCountries != null && missingCountries.length != 0)
+ ActiveCountryTree.downloadMapsForIndex(missingCountries, StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING);
+ if (missingRoutes != null && missingRoutes.length != 0)
+ ActiveCountryTree.downloadMapsForIndex(missingRoutes, StorageOptions.MAP_OPTION_CAR_ROUTING);
showDownloader(true);
}
diff --git a/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java b/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java
index f8d411cd63..791e050f28 100644
--- a/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java
+++ b/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java
@@ -33,12 +33,14 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment
{
public static final String EXTRA_RESULT_CODE = "ResultCode";
public static final String EXTRA_MISSING_COUNTRIES = "MissingCountries";
+ public static final String EXTRA_MISSING_ROUTES = "MissingRoutes";
private static final String GROUP_NAME = "GroupName";
private static final String GROUP_SIZE = "GroupSize";
private static final String COUNTRY_NAME = "CountryName";
private MapStorage.Index[] mMissingCountries;
+ private MapStorage.Index[] mMissingRoutes;
private int mResultCode;
public interface RoutingDialogListener
@@ -68,13 +70,15 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(titleMessage.first)
.setCancelable(true);
- if (mMissingCountries != null && mMissingCountries.length != 0)
+ if (hasIndex(mMissingCountries) || hasIndex(mMissingRoutes))
{
- if (mMissingCountries.length == 1)
- builder.setView(buildSingleMapView(titleMessage.second));
+ View view;
+ if (hasSingleIndex(mMissingCountries) && !hasIndex(mMissingRoutes))
+ view = buildSingleMapView(titleMessage.second, mMissingCountries[0], StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING);
else
- builder.setView(buildMultipleMapView(titleMessage.second));
+ view = buildMultipleMapView(titleMessage.second);
+ builder.setView(view);
builder
.setPositiveButton(R.string.download, new Dialog.OnClickListener()
{
@@ -125,14 +129,26 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment
{
final Bundle args = getArguments();
mMissingCountries = (MapStorage.Index[]) args.getSerializable(EXTRA_MISSING_COUNTRIES);
+ mMissingRoutes = (MapStorage.Index[]) args.getSerializable(EXTRA_MISSING_ROUTES);
mResultCode = args.getInt(EXTRA_RESULT_CODE);
}
- private View buildSingleMapView(String message)
+ private boolean hasIndex(MapStorage.Index[] indexes)
{
- @SuppressLint("InflateParams") final View countryView = getActivity().getLayoutInflater().inflate(R.layout.dialog_download_single_item, null);
- ((TextView) countryView.findViewById(R.id.tv__title)).setText(MapStorage.INSTANCE.countryName(mMissingCountries[0]));
- final String size = StringUtils.getFileSizeString(MapStorage.INSTANCE.countryRemoteSizeInBytes(mMissingCountries[0], StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING));
+ return indexes != null && indexes.length != 0;
+ }
+
+ private boolean hasSingleIndex(MapStorage.Index[] indexes)
+ {
+ return indexes != null && indexes.length == 1;
+ }
+
+ private View buildSingleMapView(String message, MapStorage.Index index, int option)
+ {
+ @SuppressLint("InflateParams") final View countryView = getActivity().getLayoutInflater().
+ inflate(R.layout.dialog_download_single_item, null);
+ ((TextView) countryView.findViewById(R.id.tv__title)).setText(MapStorage.INSTANCE.countryName(index));
+ final String size = StringUtils.getFileSizeString(MapStorage.INSTANCE.countryRemoteSizeInBytes(index, option));
UiUtils.setTextAndShow(((TextView) countryView.findViewById(R.id.tv__size)), size);
UiUtils.setTextAndShow(((TextView) countryView.findViewById(R.id.tv__message)), message);
return countryView;
@@ -140,7 +156,8 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment
private View buildMultipleMapView(String message)
{
- @SuppressLint("InflateParams") final View countriesView = getActivity().getLayoutInflater().inflate(R.layout.dialog_download_multiple_items, null);
+ @SuppressLint("InflateParams") final View countriesView = getActivity().getLayoutInflater().
+ inflate(R.layout.dialog_download_multiple_items, null);
UiUtils.setTextAndShow(((TextView) countriesView.findViewById(R.id.tv__message)), message);
final ExpandableListView listView = (ExpandableListView) countriesView.findViewById(R.id.elv__items);
@@ -168,46 +185,68 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment
private ExpandableListAdapter buildAdapter()
{
final List<Map<String, String>> groupData = new ArrayList<>();
+ final List<List<Map<String, String>>> childData = new ArrayList<>();
+ List<Map<String, String>> countries = null;
+ if (hasIndex(mMissingCountries))
+ {
+ final Map<String, String> countriesGroup = new HashMap<>();
+ countriesGroup.put(GROUP_NAME, getString(R.string.maps) + " (" + mMissingCountries.length + ") ");
+ countriesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(getCountrySizesBytes(mMissingCountries, StorageOptions.MAP_OPTION_MAP_ONLY)));
+ groupData.add(countriesGroup);
+
+ countries = getCountryNames(mMissingCountries);
+ childData.add(countries);
+ }
+ if (hasIndex(mMissingRoutes))
+ {
+ final Map<String, String> routesGroup = new HashMap<>();
+ long size = 0;
+ int routesCount = mMissingRoutes.length;
+ final List<Map<String, String>> routes = getCountryNames(mMissingRoutes);
+ if (countries != null)
+ {
+ routes.addAll(countries);
+ size += getCountrySizesBytes(mMissingCountries, StorageOptions.MAP_OPTION_CAR_ROUTING);
+ routesCount += mMissingCountries.length;
+ }
+ size += getCountrySizesBytes(mMissingRoutes, StorageOptions.MAP_OPTION_CAR_ROUTING);
- final Map<String, String> countriesGroup = new HashMap<>();
- countriesGroup.put(GROUP_NAME, getString(R.string.maps) + " (" + mMissingCountries.length + ") ");
- countriesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(getCountriesSizeInBytes(StorageOptions.MAP_OPTION_MAP_ONLY)));
- groupData.add(countriesGroup);
+ routesGroup.put(GROUP_NAME, getString(R.string.dialog_routing_routes_size) + " (" + routesCount + ") ");
+ routesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(size));
+ groupData.add(routesGroup);
- final Map<String, String> routesGroup = new HashMap<>();
- routesGroup.put(GROUP_NAME, getString(R.string.dialog_routing_routes_size) + " (" + mMissingCountries.length + ") ");
- routesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(getCountriesSizeInBytes(StorageOptions.MAP_OPTION_CAR_ROUTING)));
- groupData.add(routesGroup);
+ childData.add(routes);
+ }
- final List<List<Map<String, String>>> childData = new ArrayList<>();
+ return new DisabledChildSimpleExpandableListAdapter(getActivity(),
+ groupData,
+ R.layout.item_country_group_dialog_expanded,
+ R.layout.item_country_group_dialog,
+ new String[]{GROUP_NAME, GROUP_SIZE},
+ new int[]{R.id.tv__title, R.id.tv__size},
+ childData,
+ R.layout.item_country_dialog,
+ new String[]{COUNTRY_NAME},
+ new int[]{R.id.tv__title}
+ );
+ }
+ private List<Map<String, String>> getCountryNames(MapStorage.Index[] indexes)
+ {
final List<Map<String, String>> countries = new ArrayList<>();
- for (MapStorage.Index index : mMissingCountries)
+ for (MapStorage.Index index : indexes)
{
final Map<String, String> countryData = new HashMap<>();
countryData.put(COUNTRY_NAME, MapStorage.INSTANCE.countryName(index));
countries.add(countryData);
}
- childData.add(countries);
- childData.add(countries);
-
- return new DisabledChildSimpleExpandableListAdapter(getActivity(),
- groupData,
- R.layout.item_country_group_dialog_expanded,
- R.layout.item_country_group_dialog,
- new String[]{GROUP_NAME, GROUP_SIZE},
- new int[]{R.id.tv__title, R.id.tv__size},
- childData,
- R.layout.item_country_dialog,
- new String[]{COUNTRY_NAME},
- new int[]{R.id.tv__title}
- );
+ return countries;
}
- private long getCountriesSizeInBytes(int option)
+ private long getCountrySizesBytes(MapStorage.Index[] indexes, int option)
{
long total = 0;
- for (MapStorage.Index index : mMissingCountries)
+ for (MapStorage.Index index : indexes)
total += MapStorage.INSTANCE.countryRemoteSizeInBytes(index, option);
return total;
}
diff --git a/android/src/com/mapswithme/maps/widget/RoutingLayout.java b/android/src/com/mapswithme/maps/widget/RoutingLayout.java
index eb344672fe..84a8161f38 100644
--- a/android/src/com/mapswithme/maps/widget/RoutingLayout.java
+++ b/android/src/com/mapswithme/maps/widget/RoutingLayout.java
@@ -397,7 +397,7 @@ public class RoutingLayout extends FrameLayout implements View.OnClickListener
{
Context context = getContext();
if (context instanceof Framework.RoutingListener)
- ((Framework.RoutingListener) context).onRoutingEvent(RoutingResultCodesProcessor.NO_POSITION, null);
+ ((Framework.RoutingListener) context).onRoutingEvent(RoutingResultCodesProcessor.NO_POSITION, null, null);
}
@Override