Advertisement
Guest User

Untitled

a guest
May 25th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.97 KB | None | 0 0
  1. 05-25 13:29:21.803 28323-28323/com.directions.sample E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.directions.sample, PID: 28323
  3. java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$ClientKey;
  4. at com.google.android.gms.location.places.Places.<clinit>(Unknown Source)
  5. at com.directions.sample.MainActivity.onCreate(MainActivity.java:82)
  6. at android.app.Activity.performCreate(Activity.java:6020)
  7. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  8. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
  9. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
  10. at android.app.ActivityThread.access$800(ActivityThread.java:151)
  11. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
  12. at android.os.Handler.dispatchMessage(Handler.java:102)
  13. at android.os.Looper.loop(Looper.java:135)
  14. at android.app.ActivityThread.main(ActivityThread.java:5349)
  15. at java.lang.reflect.Method.invoke(Native Method)
  16. at java.lang.reflect.Method.invoke(Method.java:372)
  17. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
  18. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
  19. Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.api.Api$ClientKey" on path: DexPathList[[dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-support-annotations-23.0.0_dce1b180338ee5b7f0d560a72d6ece564c930260-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-internal_impl-23.0.0_e563526b068240eaa2466792641b30b0bba8631b-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.google.android.gms-play-services-maps-8.4.0_a87c5f84ccf710cb62e50e28d52cfc5932835203-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.google.android.gms-play-services-location-7.5.0_40aae27f7fd79f3001c5626f62bd016fef58f395-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-8.4.0_7b8ca9cf8c54c5f895e7067674dc001bb136aff3-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.google.android.gms-play-services-base-8.4.0_b8c62d7d657614a1707ab02e2db502e8526f59b6-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.android.support-support-v4-23.0.0_08d86aebe6d28c11fd81f85e81f70774134a0327-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.android.support-cardview-v7-21.0.2_1968c93982049023e9eb640b7ef547afe9a7dbc2-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-com.android.support-appcompat-v7-22.2.0_0ea38953cc259983e0f6128f0adf70b262bef0de-classes.dex", dex file "/data/data/com.directions.sample/files/instant-run/dex/slice-butterknife-6.1.0_068de846ed6cc9f08619bd94efce35ab0d0902df-classes.dex"],nativeLibraryDirectories=[/vendor/lib, /system/lib, /vendor/lib, /system/lib]]
  20. at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  21. at com.android.tools.fd.runtim
  22.  
  23. public class MainActivity extends AppCompatActivity implements RoutingListener, GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks {
  24. protected GoogleMap map;
  25. protected LatLng start;
  26. protected LatLng end;
  27. @InjectView(R.id.start)
  28. AutoCompleteTextView starting;
  29. @InjectView(R.id.destination)
  30. AutoCompleteTextView destination;
  31. @InjectView(R.id.send)
  32. ImageView send;
  33. private static final String LOG_TAG = "MyActivity";
  34. protected GoogleApiClient mGoogleApiClient;
  35. private PlaceAutoCompleteAdapter mAdapter;
  36. private ProgressDialog progressDialog;
  37. private List<Polyline> polylines;
  38. private static final int[] COLORS = new int[]{R.color.primary_dark,R.color.primary,R.color.primary_light,R.color.accent,R.color.primary_dark_material_light};
  39.  
  40.  
  41. private static final LatLngBounds BOUNDS_JAMAICA= new LatLngBounds(new LatLng(-57.965341647205726, 144.9987719580531),
  42. new LatLng(72.77492067739843, -9.998857788741589));
  43.  
  44. /**
  45. * This activity loads a map and then displays the route and pushpins on it.
  46. */
  47. @Override
  48. public void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.activity_main);
  51. ButterKnife.inject(this);
  52. getSupportActionBar().setDisplayShowHomeEnabled(true);
  53.  
  54. polylines = new ArrayList<>();
  55. mGoogleApiClient = new GoogleApiClient.Builder(this)
  56. .addApi(Places.GEO_DATA_API)
  57. .addConnectionCallbacks(this)
  58. .addOnConnectionFailedListener(this)
  59. .build();
  60. MapsInitializer.initialize(this);
  61. mGoogleApiClient.connect();
  62.  
  63. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  64.  
  65. if (mapFragment == null) {
  66. mapFragment = SupportMapFragment.newInstance();
  67. getSupportFragmentManager().beginTransaction().replace(R.id.map, mapFragment).commit();
  68. }
  69. map = mapFragment.getMap();
  70.  
  71. mAdapter = new PlaceAutoCompleteAdapter(this, android.R.layout.simple_list_item_1,
  72. mGoogleApiClient, BOUNDS_JAMAICA, null);
  73.  
  74.  
  75. /*
  76. * Updates the bounds being used by the auto complete adapter based on the position of the
  77. * map.
  78. * */
  79. map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
  80. @Override
  81. public void onCameraChange(CameraPosition position) {
  82. LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
  83. mAdapter.setBounds(bounds);
  84. }
  85. });
  86.  
  87.  
  88. CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(18.013610, -77.498803));
  89. CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
  90.  
  91. map.moveCamera(center);
  92. map.animateCamera(zoom);
  93.  
  94. LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  95.  
  96. locationManager.requestLocationUpdates(
  97. LocationManager.NETWORK_PROVIDER, 5000, 0,
  98. new LocationListener() {
  99. @Override
  100. public void onLocationChanged(Location location) {
  101.  
  102. CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(),location.getLongitude()));
  103. CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
  104.  
  105. map.moveCamera(center);
  106. map.animateCamera(zoom);
  107. }
  108.  
  109. @Override
  110. public void onStatusChanged(String provider, int status, Bundle extras) {
  111.  
  112. }
  113.  
  114. @Override
  115. public void onProviderEnabled(String provider) {
  116.  
  117. }
  118.  
  119. @Override
  120. public void onProviderDisabled(String provider) {
  121.  
  122. }
  123. });
  124.  
  125.  
  126. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
  127. 3000, 0, new LocationListener() {
  128. @Override
  129. public void onLocationChanged(Location location) {
  130. CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(),location.getLongitude()));
  131. CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
  132.  
  133. map.moveCamera(center);
  134. map.animateCamera(zoom);
  135.  
  136. }
  137.  
  138. @Override
  139. public void onStatusChanged(String provider, int status, Bundle extras) {
  140.  
  141. }
  142.  
  143. @Override
  144. public void onProviderEnabled(String provider) {
  145.  
  146. }
  147.  
  148. @Override
  149. public void onProviderDisabled(String provider) {
  150.  
  151. }
  152. });
  153.  
  154.  
  155.  
  156. /*
  157. * Adds auto complete adapter to both auto complete
  158. * text views.
  159. * */
  160. starting.setAdapter(mAdapter);
  161. destination.setAdapter(mAdapter);
  162.  
  163.  
  164. /*
  165. * Sets the start and destination points based on the values selected
  166. * from the autocomplete text views.
  167. * */
  168.  
  169. starting.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  170. @Override
  171. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  172.  
  173. final PlaceAutoCompleteAdapter.PlaceAutocomplete item = mAdapter.getItem(position);
  174. final String placeId = String.valueOf(item.placeId);
  175. Log.i(LOG_TAG, "Autocomplete item selected: " + item.description);
  176.  
  177. /*
  178. Issue a request to the Places Geo Data API to retrieve a Place object with additional
  179. details about the place.
  180. */
  181. PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
  182. .getPlaceById(mGoogleApiClient, placeId);
  183. placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
  184. @Override
  185. public void onResult(PlaceBuffer places) {
  186. if (!places.getStatus().isSuccess()) {
  187. // Request did not complete successfully
  188. Log.e(LOG_TAG, "Place query did not complete. Error: " + places.getStatus().toString());
  189. places.release();
  190. return;
  191. }
  192. // Get the Place object from the buffer.
  193. final Place place = places.get(0);
  194.  
  195. start=place.getLatLng();
  196. }
  197. });
  198.  
  199. }
  200. });
  201. destination.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  202. @Override
  203. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  204.  
  205. final PlaceAutoCompleteAdapter.PlaceAutocomplete item = mAdapter.getItem(position);
  206. final String placeId = String.valueOf(item.placeId);
  207. Log.i(LOG_TAG, "Autocomplete item selected: " + item.description);
  208.  
  209. /*
  210. Issue a request to the Places Geo Data API to retrieve a Place object with additional
  211. details about the place.
  212. */
  213. PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
  214. .getPlaceById(mGoogleApiClient, placeId);
  215. placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
  216. @Override
  217. public void onResult(PlaceBuffer places) {
  218. if (!places.getStatus().isSuccess()) {
  219. // Request did not complete successfully
  220. Log.e(LOG_TAG, "Place query did not complete. Error: " + places.getStatus().toString());
  221. places.release();
  222. return;
  223. }
  224. // Get the Place object from the buffer.
  225. final Place place = places.get(0);
  226.  
  227. end=place.getLatLng();
  228. }
  229. });
  230.  
  231. }
  232. });
  233.  
  234. /*
  235. These text watchers set the start and end points to null because once there's
  236. * a change after a value has been selected from the dropdown
  237. * then the value has to reselected from dropdown to get
  238. * the correct location.
  239. * */
  240. starting.addTextChangedListener(new TextWatcher() {
  241. @Override
  242. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  243.  
  244. }
  245.  
  246. @Override
  247. public void onTextChanged(CharSequence s, int startNum, int before, int count) {
  248. if (start != null) {
  249. start = null;
  250. }
  251. }
  252.  
  253. @Override
  254. public void afterTextChanged(Editable s) {
  255.  
  256. }
  257. });
  258.  
  259. destination.addTextChangedListener(new TextWatcher() {
  260. @Override
  261. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  262.  
  263. }
  264.  
  265. @Override
  266. public void onTextChanged(CharSequence s, int start, int before, int count) {
  267.  
  268.  
  269. if(end!=null)
  270. {
  271. end=null;
  272. }
  273. }
  274.  
  275. @Override
  276. public void afterTextChanged(Editable s) {
  277.  
  278. }
  279. });
  280.  
  281. }
  282.  
  283. @OnClick(R.id.send)
  284. public void sendRequest()
  285. {
  286. if(Util.Operations.isOnline(this))
  287. {
  288. route();
  289. }
  290. else
  291. {
  292. Toast.makeText(this,"No internet connectivity",Toast.LENGTH_SHORT).show();
  293. }
  294. }
  295.  
  296. public void route()
  297. {
  298. if(start==null || end==null)
  299. {
  300. if(start==null)
  301. {
  302. if(starting.getText().length()>0)
  303. {
  304. starting.setError("Choose location from dropdown.");
  305. }
  306. else
  307. {
  308. Toast.makeText(this,"Please choose a starting point.",Toast.LENGTH_SHORT).show();
  309. }
  310. }
  311. if(end==null)
  312. {
  313. if(destination.getText().length()>0)
  314. {
  315. destination.setError("Choose location from dropdown.");
  316. }
  317. else
  318. {
  319. Toast.makeText(this,"Please choose a destination.",Toast.LENGTH_SHORT).show();
  320. }
  321. }
  322. }
  323. else
  324. {
  325. progressDialog = ProgressDialog.show(this, "Please wait.",
  326. "Fetching route information.", true);
  327. Routing routing = new Routing.Builder()
  328. .travelMode(AbstractRouting.TravelMode.DRIVING)
  329. .withListener(this)
  330. .alternativeRoutes(true)
  331. .waypoints(start, end)
  332. .build();
  333. routing.execute();
  334. }
  335. }
  336.  
  337.  
  338. @Override
  339. public void onRoutingFailure(RouteException e) {
  340. // The Routing request failed
  341. progressDialog.dismiss();
  342. if(e != null) {
  343. Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
  344. }else {
  345. Toast.makeText(this, "Something went wrong, Try again", Toast.LENGTH_SHORT).show();
  346. }
  347. }
  348.  
  349. @Override
  350. public void onRoutingStart() {
  351. // The Routing Request starts
  352. }
  353.  
  354. @Override
  355. public void onRoutingSuccess(List<Route> route, int shortestRouteIndex)
  356. {
  357. progressDialog.dismiss();
  358. CameraUpdate center = CameraUpdateFactory.newLatLng(start);
  359. CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
  360.  
  361. map.moveCamera(center);
  362.  
  363.  
  364. if(polylines.size()>0) {
  365. for (Polyline poly : polylines) {
  366. poly.remove();
  367. }
  368. }
  369.  
  370. polylines = new ArrayList<>();
  371. //add route(s) to the map.
  372. for (int i = 0; i <route.size(); i++) {
  373.  
  374. //In case of more than 5 alternative routes
  375. int colorIndex = i % COLORS.length;
  376.  
  377. PolylineOptions polyOptions = new PolylineOptions();
  378. polyOptions.color(getResources().getColor(COLORS[colorIndex]));
  379. polyOptions.width(10 + i * 3);
  380. polyOptions.addAll(route.get(i).getPoints());
  381. Polyline polyline = map.addPolyline(polyOptions);
  382. polylines.add(polyline);
  383.  
  384. Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
  385. }
  386.  
  387. // Start marker
  388. MarkerOptions options = new MarkerOptions();
  389. options.position(start);
  390. options.icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue));
  391. map.addMarker(options);
  392.  
  393. // End marker
  394. options = new MarkerOptions();
  395. options.position(end);
  396. options.icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green));
  397. map.addMarker(options);
  398.  
  399. }
  400.  
  401. @Override
  402. public void onRoutingCancelled() {
  403. Log.i(LOG_TAG, "Routing was cancelled.");
  404. }
  405.  
  406. @Override
  407. public void onConnectionFailed(ConnectionResult connectionResult) {
  408.  
  409. Log.v(LOG_TAG,connectionResult.toString());
  410. }
  411.  
  412. @Override
  413. public void onConnected(Bundle bundle) {
  414. }
  415.  
  416. @Override
  417. public void onConnectionSuspended(int i) {
  418.  
  419. }
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement