{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/45739430","id":45739430,"diff_hunk":"@@ -0,0 +1,718 @@\n+package com.mapswithme.maps.routing;\n+\n+import android.content.DialogInterface;\n+import android.support.annotation.DimenRes;\n+import android.support.annotation.IntRange;\n+import android.support.annotation.NonNull;\n+import android.support.annotation.Nullable;\n+import android.support.v4.app.FragmentActivity;\n+import android.support.v7.app.AlertDialog;\n+import android.text.TextUtils;\n+import android.util.Log;\n+import android.widget.Button;\n+import com.mapswithme.country.ActiveCountryTree;\n+import com.mapswithme.country.StorageOptions;\n+import com.mapswithme.maps.*;\n+import com.mapswithme.maps.bookmarks.data.MapObject;\n+import com.mapswithme.maps.location.LocationHelper;\n+import com.mapswithme.util.Config;\n+import com.mapswithme.util.Utils;\n+import com.mapswithme.util.concurrency.UiThread;\n+import com.mapswithme.util.statistics.AlohaHelper;\n+import com.mapswithme.util.statistics.Statistics;\n+\n+import java.util.Calendar;\n+import java.util.Locale;\n+import java.util.concurrent.TimeUnit;\n+\n+@android.support.annotation.UiThread\n+public class RoutingController\n+{\n+  public static final int NO_SLOT = 0;\n+\n+  private static final String TAG = \"RCSTATE\";\n+\n+  private enum State\n+  {\n+    NONE,\n+    PREPARE,\n+    NAVIGATION\n+  }\n+\n+  enum BuildState\n+  {\n+    NONE,\n+    BUILDING,\n+    BUILT,\n+    ERROR\n+  }\n+\n+  public interface Container\n+  {\n+    FragmentActivity getActivity();\n+    void showSearch();\n+    void showRoutePlan(boolean show, @Nullable Runnable completionListener);\n+    void showNavigation(boolean show);\n+    void showDownloader(boolean openDownloadedList);\n+    void updateMenu();\n+    void updatePoints();\n+\n+    /**\n+     * @param progress progress to be displayed.\n+     * @param router selected router type. One of {@link Framework#ROUTER_TYPE_VEHICLE} and {@link Framework#ROUTER_TYPE_PEDESTRIAN}.\n+     * */\n+    void updateBuildProgress(@IntRange(from = 0, to = 100) int progress, int router);\n+  }\n+\n+  private static final RoutingController sInstance = new RoutingController();\n+\n+  private Container mContainer;\n+  private Button mStartButton;\n+\n+  private BuildState mBuildState = BuildState.NONE;\n+  private State mState = State.NONE;\n+  private int mWaitingPoiPickSlot = NO_SLOT;\n+\n+  private MapObject mStartPoint;\n+  private MapObject mEndPoint;\n+\n+  private int mLastBuildProgress;\n+  private int mLastRouterType = Framework.nativeGetLastUsedRouter();\n+  private RoutingInfo mCachedRoutingInfo;\n+\n+  @SuppressWarnings(\"FieldCanBeLocal\")\n+  private final Framework.RoutingListener mRoutingListener = new Framework.RoutingListener()\n+  {\n+    @Override\n+    public void onRoutingEvent(final int resultCode, final MapStorage.Index[] missingCountries, final MapStorage.Index[] missingRoutes)\n+    {\n+      Log.d(TAG, \"onRoutingEvent(resultCode: \" + resultCode + \")\");\n+\n+      UiThread.run(new Runnable()\n+      {\n+        @Override\n+        public void run()\n+        {\n+          if (resultCode == ResultCodesHelper.NO_ERROR)\n+          {\n+            mCachedRoutingInfo = Framework.nativeGetRouteFollowingInfo();\n+            setBuildState(BuildState.BUILT);\n+            mLastBuildProgress = 100;\n+            updatePlan();\n+            return;\n+          }\n+\n+          mCachedRoutingInfo = null;\n+\n+          if (mContainer == null)\n+            return;\n+\n+          setBuildState(BuildState.ERROR);\n+          mLastBuildProgress = 0;\n+          updateProgress();\n+\n+          RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(resultCode, missingCountries, missingRoutes);\n+          fragment.setListener(new RoutingErrorDialogFragment.Listener()\n+          {\n+            @Override\n+            public void onDownload()\n+            {\n+              cancel();\n+\n+              if (missingCountries != null && missingCountries.length != 0)\n+                ActiveCountryTree.downloadMapsForIndex(missingCountries, StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING);\n+              if (missingRoutes != null && missingRoutes.length != 0)\n+                ActiveCountryTree.downloadMapsForIndex(missingRoutes, StorageOptions.MAP_OPTION_CAR_ROUTING);\n+\n+              if (mContainer != null)\n+                mContainer.showDownloader(true);\n+            }\n+\n+            @Override\n+            public void onOk()\n+            {\n+              if (ResultCodesHelper.isDownloadable(resultCode))\n+              {\n+                cancel();\n+\n+                if (mContainer != null)\n+                  mContainer.showDownloader(false);\n+              }\n+            }\n+          });\n+\n+          fragment.show(mContainer.getActivity().getSupportFragmentManager(), fragment.getClass().getSimpleName());\n+        }\n+      });\n+    }\n+  };\n+\n+  @SuppressWarnings(\"FieldCanBeLocal\")\n+  private final Framework.RoutingProgressListener mRoutingProgressListener = new Framework.RoutingProgressListener()\n+  {\n+    @Override\n+    public void onRouteBuildingProgress(final float progress)\n+    {\n+      UiThread.run(new Runnable()\n+      {\n+        @Override\n+        public void run()\n+        {\n+          mLastBuildProgress = (int) progress;\n+          updateProgress();\n+        }\n+      });\n+    }\n+  };\n+\n+  private RoutingController()\n+  {\n+    Framework.nativeSetRoutingListener(mRoutingListener);\n+    Framework.nativeSetRouteProgressListener(mRoutingProgressListener);\n+  }\n+\n+  public static RoutingController get()\n+  {\n+    return sInstance;\n+  }\n+\n+  private void setState(State newState)\n+  {\n+    Log.d(TAG, \"[S] State: \" + mState + \" -> \" + newState + \", BuildState: \" + mBuildState);\n+    mState = newState;\n+\n+    if (mContainer != null)\n+      mContainer.updateMenu();\n+  }\n+\n+  private void setBuildState(BuildState newState)\n+  {\n+    Log.d(TAG, \"[B] State: \" + mState + \", BuildState: \" + mBuildState + \" -> \" + newState);","path":"android/src/com/mapswithme/maps/routing/RoutingController.java","position":190,"original_position":190,"commit_id":"8b95165d362a5864e3c9343ae877a1fbc8b4cfaa","original_commit_id":"797622b4bdb366dcaa8914342db929adf0695f23","user":{"login":"yunikkk","id":2265924,"avatar_url":"https://avatars.githubusercontent.com/u/2265924?v=3","gravatar_id":"","url":"https://api.github.com/users/yunikkk","html_url":"https://github.com/yunikkk","followers_url":"https://api.github.com/users/yunikkk/followers","following_url":"https://api.github.com/users/yunikkk/following{/other_user}","gists_url":"https://api.github.com/users/yunikkk/gists{/gist_id}","starred_url":"https://api.github.com/users/yunikkk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yunikkk/subscriptions","organizations_url":"https://api.github.com/users/yunikkk/orgs","repos_url":"https://api.github.com/users/yunikkk/repos","events_url":"https://api.github.com/users/yunikkk/events{/privacy}","received_events_url":"https://api.github.com/users/yunikkk/received_events","type":"User","site_admin":false},"body":"Логи","created_at":"2015-11-24T14:14:36Z","updated_at":"2015-11-24T14:14:36Z","html_url":"https://github.com/mapsme/omim/pull/93#discussion_r45739430","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/93","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/45739430"},"html":{"href":"https://github.com/mapsme/omim/pull/93#discussion_r45739430"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/93"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/93","id":46506112,"html_url":"https://github.com/mapsme/omim/pull/93","diff_url":"https://github.com/mapsme/omim/pull/93.diff","patch_url":"https://github.com/mapsme/omim/pull/93.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/93","number":93,"state":"open","locked":false,"title":"[android] Point to point.","user":{"login":"trashkalmar","id":5173794,"avatar_url":"https://avatars.githubusercontent.com/u/5173794?v=3","gravatar_id":"","url":"https://api.github.com/users/trashkalmar","html_url":"https://github.com/trashkalmar","followers_url":"https://api.github.com/users/trashkalmar/followers","following_url":"https://api.github.com/users/trashkalmar/following{/other_user}","gists_url":"https://api.github.com/users/trashkalmar/gists{/gist_id}","starred_url":"https://api.github.com/users/trashkalmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trashkalmar/subscriptions","organizations_url":"https://api.github.com/users/trashkalmar/orgs","repos_url":"https://api.github.com/users/trashkalmar/repos","events_url":"https://api.github.com/users/trashkalmar/events{/privacy}","received_events_url":"https://api.github.com/users/trashkalmar/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-01T10:15:01Z","updated_at":"2015-11-24T14:14:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bbb8311ed33fdf05d382ef93735fae4de777cb7a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/93/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/93/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/93/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/8b95165d362a5864e3c9343ae877a1fbc8b4cfaa","head":{"label":"trashkalmar:point2point","ref":"point2point","sha":"8b95165d362a5864e3c9343ae877a1fbc8b4cfaa","user":{"login":"trashkalmar","id":5173794,"avatar_url":"https://avatars.githubusercontent.com/u/5173794?v=3","gravatar_id":"","url":"https://api.github.com/users/trashkalmar","html_url":"https://github.com/trashkalmar","followers_url":"https://api.github.com/users/trashkalmar/followers","following_url":"https://api.github.com/users/trashkalmar/following{/other_user}","gists_url":"https://api.github.com/users/trashkalmar/gists{/gist_id}","starred_url":"https://api.github.com/users/trashkalmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trashkalmar/subscriptions","organizations_url":"https://api.github.com/users/trashkalmar/orgs","repos_url":"https://api.github.com/users/trashkalmar/repos","events_url":"https://api.github.com/users/trashkalmar/events{/privacy}","received_events_url":"https://api.github.com/users/trashkalmar/received_events","type":"User","site_admin":false},"repo":{"id":43429123,"name":"omim","full_name":"trashkalmar/omim","owner":{"login":"trashkalmar","id":5173794,"avatar_url":"https://avatars.githubusercontent.com/u/5173794?v=3","gravatar_id":"","url":"https://api.github.com/users/trashkalmar","html_url":"https://github.com/trashkalmar","followers_url":"https://api.github.com/users/trashkalmar/followers","following_url":"https://api.github.com/users/trashkalmar/following{/other_user}","gists_url":"https://api.github.com/users/trashkalmar/gists{/gist_id}","starred_url":"https://api.github.com/users/trashkalmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trashkalmar/subscriptions","organizations_url":"https://api.github.com/users/trashkalmar/orgs","repos_url":"https://api.github.com/users/trashkalmar/repos","events_url":"https://api.github.com/users/trashkalmar/events{/privacy}","received_events_url":"https://api.github.com/users/trashkalmar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/trashkalmar/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/trashkalmar/omim","forks_url":"https://api.github.com/repos/trashkalmar/omim/forks","keys_url":"https://api.github.com/repos/trashkalmar/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/trashkalmar/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/trashkalmar/omim/teams","hooks_url":"https://api.github.com/repos/trashkalmar/omim/hooks","issue_events_url":"https://api.github.com/repos/trashkalmar/omim/issues/events{/number}","events_url":"https://api.github.com/repos/trashkalmar/omim/events","assignees_url":"https://api.github.com/repos/trashkalmar/omim/assignees{/user}","branches_url":"https://api.github.com/repos/trashkalmar/omim/branches{/branch}","tags_url":"https://api.github.com/repos/trashkalmar/omim/tags","blobs_url":"https://api.github.com/repos/trashkalmar/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/trashkalmar/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/trashkalmar/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/trashkalmar/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/trashkalmar/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/trashkalmar/omim/languages","stargazers_url":"https://api.github.com/repos/trashkalmar/omim/stargazers","contributors_url":"https://api.github.com/repos/trashkalmar/omim/contributors","subscribers_url":"https://api.github.com/repos/trashkalmar/omim/subscribers","subscription_url":"https://api.github.com/repos/trashkalmar/omim/subscription","commits_url":"https://api.github.com/repos/trashkalmar/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/trashkalmar/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/trashkalmar/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/trashkalmar/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/trashkalmar/omim/contents/{+path}","compare_url":"https://api.github.com/repos/trashkalmar/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/trashkalmar/omim/merges","archive_url":"https://api.github.com/repos/trashkalmar/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/trashkalmar/omim/downloads","issues_url":"https://api.github.com/repos/trashkalmar/omim/issues{/number}","pulls_url":"https://api.github.com/repos/trashkalmar/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/trashkalmar/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/trashkalmar/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/trashkalmar/omim/labels{/name}","releases_url":"https://api.github.com/repos/trashkalmar/omim/releases{/id}","created_at":"2015-09-30T11:28:06Z","updated_at":"2015-09-30T11:30:16Z","pushed_at":"2015-11-24T14:01:51Z","git_url":"git://github.com/trashkalmar/omim.git","ssh_url":"git@github.com:trashkalmar/omim.git","clone_url":"https://github.com/trashkalmar/omim.git","svn_url":"https://github.com/trashkalmar/omim","homepage":null,"size":1857043,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:master","ref":"master","sha":"1dc50b4ce518ba250fc3bacea447e82b23b6f3dd","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","created_at":"2015-09-20T02:57:13Z","updated_at":"2015-11-24T11:32:02Z","pushed_at":"2015-11-24T14:11:54Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":1900306,"stargazers_count":1493,"watchers_count":1493,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":177,"mirror_url":null,"open_issues_count":64,"forks":177,"open_issues":64,"watchers":1493,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/93"},"html":{"href":"https://github.com/mapsme/omim/pull/93"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/93"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/93/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/93/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/93/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/8b95165d362a5864e3c9343ae877a1fbc8b4cfaa"}}}}