Nextrek
@ 785
Nextrek / Android / SmartCharging / SmartCharging / app / src / main / java / it / fedeloper / smartcharging / Controller / MapActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 |
package it.fedeloper.smartcharging.Controller; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.app.Activity; import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.app.Service; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RatingBar; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.rey.material.widget.ProgressView; import it.fedeloper.smartcharging.*; import it.fedeloper.smartcharging.Manager.MyLocation; import it.fedeloper.smartcharging.Manager.PrefsManager; import it.fedeloper.smartcharging.Manager.Utils; import it.fedeloper.smartcharging.Service.EndPoint; import it.fedeloper.smartcharging.Service.HttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.text.ParseException; import java.util.HashMap; public class MapActivity extends FragmentActivity { public static HashMap<Integer, Bitmap> mapCacheImage = new HashMap<Integer, Bitmap>(); static Context c; static Activity a; public int inLoading = 0; public int nextToLoad = -1; public int currentLoad = -1; public Marker nearest = null; HashMap<Marker, JSONObject> ms = new HashMap<>(); HashMap<Integer, JSONObject> mapCacheInfo = new HashMap<Integer, JSONObject>(); public static HashMap<Integer, JSONObject> mapCacheRecensioni = new HashMap<Integer, JSONObject>(); Geocoder geoCoder; private GoogleMap map; private LocationManager locationManager; private Double lat; private Double lon; private TextView txt; private LatLng mylocation; private Paint paint = new Paint(); private Rect bounds = new Rect(); private int idlocale = -1; private Fragment full; private int typelocale = -1; private boolean isInFront; private static LinearLayout localeContainer; private static TextView noLocalMsg; private static LinearLayout smallInfo; private static Button otherInfo; private static View animationRefer; private static boolean expanded = false; private TextView emailLocaleTextView; private TextView numLocaleTextView; private TextView sitoLocaleTextView; private TextView cariLocaleTextView; private Button reviewButton; private ProgressView loadingImage; private ProgressView loadingAll; @Override public void onBackPressed() { backPress(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { backPress(); return true; } return super.onKeyDown(keyCode, event); } @Override public void onResume() { super.onResume(); isInFront = true; runOnUiThread(new Runnable() { @Override public void run() { if(!mapCacheRecensioni.containsKey(idlocale) && mapCacheInfo.containsKey(idlocale)) { getInfoById(idlocale); if (expanded) { closeFullInfo(); } } } }); } @Override public void onPause() { super.onPause(); isInFront = false; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); initView(); if (MyLocation.isGpsEnabled(this,false)) { loadingAll.setVisibility(View.VISIBLE); noLocalMsg.setText(R.string.ricerca_gps); } else { loadingAll.setVisibility(View.GONE); noLocalMsg.setText(R.string.seleziona_locale); } final EditText addressView = (EditText) findViewById(R.id.editText6); addressView.setImeOptions(EditorInfo.IME_ACTION_DONE); setListenerToRootView(); addressView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { searchAddress(v.getText().toString()); View view = MapActivity.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } view.clearFocus(); return true; } return false; } }); addressView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { otherInfo.setVisibility(View.GONE); } else { otherInfo.setVisibility(View.VISIBLE); } } }); Bundle b; b = getIntent().getExtras(); if (b.getBoolean("fast") == false) { typelocale = b.getInt("tipologia"); } geoCoder = new Geocoder(this); a = this; txt = ((TextView) findViewById(R.id.editText9)); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView); ((ScrollMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).setListener(new ScrollMapFragment.OnTouchListener() { @Override public void onTouch() { scroll.requestDisallowInterceptTouchEvent(true); } }); c = getApplicationContext(); MyLocation.LocationResult locationResult = new MyLocation.LocationResult() { @Override public void gotLocation(Location location) { if(location==null) return; runOnUiThread(new Runnable() { public void run() { loadingAll.setVisibility(View.VISIBLE); noLocalMsg.setText(R.string.ricerca_locali); } }); final LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); lat = location.getLatitude(); lon = location.getLongitude(); final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 13); runOnUiThread(new Runnable() { public void run() { map.animateCamera(cameraUpdate); map.addMarker(new MarkerOptions().title("me").position(latLng)); } }); mylocation = latLng; putLocalsOnMap(); runOnUiThread(new Runnable() { public void run() { map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker arg0) { markerClick(arg0); showLocaleContainer(); return true; } }); } }); } }; MyLocation.getLocation(this, locationResult); map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(41.902285, 12.496975), 5.0f)); } boolean isOpened = false; private boolean firstLocal=true; public void setListenerToRootView(){ final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight(); if (heightDiff > 100 ) { isOpened = true; }else if(isOpened == true){ (findViewById(R.id.editText6)).clearFocus(); isOpened = false; } } }); } private void initView(){ loadingImage= (ProgressView) findViewById(R.id.loadingImage); loadingAll= (ProgressView) findViewById(R.id.loadingAll); reviewButton = (Button) findViewById(R.id.button12); if(!PrefsManager.isLogged(this)) reviewButton.setVisibility(View.GONE); otherInfo = (Button)findViewById(R.id.button11); otherInfo.setVisibility(View.VISIBLE); //smallInfo = (LinearLayout)findViewById(R.id.smallinfo); animationRefer=findViewById(R.id.descrizione); noLocalMsg =(TextView) findViewById(R.id.no_locali_message); RelativeLayout mapContainer = (RelativeLayout) findViewById(R.id.map_container); ViewGroup.LayoutParams mapLayoutParams = mapContainer.getLayoutParams(); mapLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT; mapLayoutParams.height = getWindowManager().getDefaultDisplay().getHeight() /2; // - 100 - (clickRecensioneButton.getHeight() / 2); mapContainer.setLayoutParams(mapLayoutParams); localeContainer = (LinearLayout) findViewById(R.id.locale_container); hideLocaleContainer(); sitoLocaleTextView = (TextView) findViewById(R.id.sito_locale); sitoLocaleTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try{ String url = sitoLocaleTextView.getText().toString(); Intent i = new Intent(Intent.ACTION_VIEW); if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" + url; i.setData(Uri.parse(url)); startActivity(i); } catch (ActivityNotFoundException e){} } }); cariLocaleTextView = (TextView) findViewById(R.id.cari_locale); numLocaleTextView = (TextView) findViewById(R.id.num_locale); numLocaleTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", numLocaleTextView.getText().toString(), null)); startActivity(intent); } }); emailLocaleTextView = (TextView) findViewById(R.id.email_locale); emailLocaleTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", emailLocaleTextView.getText().toString(), null)); startActivity(Intent.createChooser(emailIntent, "Invia email...")); } }); } private void searchAddress(final String searchText){ new Thread(new Runnable() { public void run() { JSONObject obj = new JSONObject(); try { try { runOnUiThread(new Runnable() { public void run() { hideLocaleContainer(); } }); URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?address=" + searchText + "&sensor=true"); String nullFragment = null; URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), nullFragment); System.out.println("URI " + uri.toString() + " is OK"); JSONObject resp = HttpClient.SendHttpPostAsync(uri.toString(), obj); Log.e("0", resp.getJSONArray("results").getJSONObject(0).toString()); Log.e("0", resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").toString()); Log.e("0", resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location").toString()); JSONObject o = resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location"); Double lat = o.getDouble("lat"); Double lng = o.getDouble("lng"); final LatLng latLng = new LatLng(lat, lng); if (latLng != null) { final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 13); runOnUiThread(new Runnable() { public void run() { map.animateCamera(cameraUpdate); map.addMarker(new MarkerOptions().title("me").position(latLng)); } }); mylocation = latLng; putLocalsOnMap(); runOnUiThread(new Runnable() { public void run() { map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker arg0) { markerClick(arg0); showLocaleContainer(); return true; } }); } }); } else { AlertDialog.Builder adb = new AlertDialog.Builder(c); adb.setTitle("Google Map"); adb.setMessage("Inserisci un indirizzo corretto"); adb.setPositiveButton("chiudi", null); adb.show(); } } catch (MalformedURLException e) { System.out.println("URL " + txt.getText().toString() + " is a malformed URL"); } catch (URISyntaxException e) { System.out.println("URI " + txt.getText().toString() + " is a malformed URL"); } } catch (JSONException e) { e.printStackTrace(); } } }).start(); } private void showLocaleContainer() { otherInfo.setVisibility(View.VISIBLE); localeContainer.setVisibility(View.VISIBLE); noLocalMsg.setVisibility(View.GONE); } private void hideLocaleContainer() { otherInfo.setVisibility(View.GONE); localeContainer.setVisibility(View.GONE); noLocalMsg.setVisibility(View.VISIBLE); } private void backPress() { if (expanded) { closeFullInfo(); } else{ finish(); } } public static float calculateDistanceFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; int meterConversion = 1609; return new Float(dist * meterConversion).floatValue(); } private void putLocalsOnMap() { new Thread(new Runnable() { public void run() { JSONObject obj = new JSONObject(); try { obj.put("tipologia", typelocale); obj.put("lat", lat); obj.put("lon", lon); obj.put("distance", 1000000000); JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/get_list_locali.php", obj); JSONArray arr = resp.getJSONArray("locals"); for (int i = 0; i < arr.length(); i++) { runOnUiThread(new Runnable() { @Override public void run() { //showLocaleContainer(); }}); JSONObject jdata = arr.getJSONObject(i); mapCacheInfo.put(jdata.getInt("id"), jdata); LatLng latLng = new LatLng(jdata.getDouble("lat"), jdata.getDouble("lon")); String nome = ""; // jdata.getString("nomelocale"); Eliminato nome locale addMarkerAsync(latLng, nome, jdata); } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } if (arr.length() > 0) { boolean a = false; while (a == false) { try { markerClick(nearest); a = true; } catch (Exception e) { Log.e("erroreeeee", nearest.toString()); } } } else { runOnUiThread(new Runnable() { @Override public void run() { if(MapActivity.this == null) return; AlertDialog.Builder dlgAlert = new AlertDialog.Builder(MapActivity.this); dlgAlert.setMessage(R.string.no_locals); dlgAlert.setTitle(getString(R.string.no_locals_title)); dlgAlert.setPositiveButton("OK", null); dlgAlert.setCancelable(false); dlgAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); dlgAlert.create().show(); } }); } } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { if (isInFront) putLocalsOnMap(); } } }).start(); } private boolean animationOffEnded=false; public void getInfoById(final int id) { // if (id != idlocale) { // runOnUiThread(new Runnable() { // @Override // public void run() { // findViewById(R.id.profile_image).setVisibility(View.INVISIBLE); // } // }); // } if (expanded && full != null && id != idlocale) { backPress(); } if ( Utils.isNetworkConnected(c)) { // loadingAll.setVisibility(View.GONE); // noLocalMsg.setVisibility(View.GONE); new Thread(new Runnable() { public void run() { if (mapCacheInfo.containsKey(id)) { runOnUiThread(new Runnable() { @Override public void run() { final JSONObject resp = mapCacheInfo.get(id); runOnUiThread(new Runnable() { @Override public void run() { localeContainer.animate() .translationY(0) .alpha(0.0f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); loadingAll.setVisibility(View.GONE); noLocalMsg.setVisibility(View.GONE); localeContainer.setVisibility(View.VISIBLE); localeContainer.setAlpha(1.0f); try { ((TextView) findViewById(R.id.nome_locale)).setText(resp.getString("nomelocale")); ((TextView) findViewById(R.id.tipologia)).setText(Utils.getTipologiaFromId(c,Integer.parseInt(resp.getString("tipologia")))); ((TextView) findViewById(R.id.descrizione)).setText(resp.getString("descrizione")); ((TextView) findViewById(R.id.via_locale)).setText(resp.getString("indirizzo")); ((RatingBar) findViewById(R.id.ratingBar)).setRating(resp.getLong("stelle")); String sito = resp.getString("sito"); String em = resp.getString("email"); if (em.length()>0) emailLocaleTextView.setVisibility(View.VISIBLE); else emailLocaleTextView.setVisibility(View.GONE); if (sito.length()>0) sitoLocaleTextView.setVisibility(View.VISIBLE); else sitoLocaleTextView.setVisibility(View.GONE); sitoLocaleTextView.setText(sito); emailLocaleTextView.setText(em); numLocaleTextView.setText(resp.getString("telefono")); cariLocaleTextView.setText(getString(R.string.punti_di_ricarica) + resp.getString("n_punti_ricarica")); } catch (JSONException e) { e.printStackTrace(); } } }); otherInfo.animate() .translationY(0) .alpha(0.0f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); otherInfo.setVisibility(View.VISIBLE); otherInfo.setAlpha(1.0f); } }); } }); idlocale = id; } }); } } }).start(); //getting recensione new Thread(new Runnable() { public void run() { if (mapCacheRecensioni.containsKey(id)) { runOnUiThread(new Runnable() { @Override public void run() { try { if( mapCacheRecensioni.get(id).getJSONObject("comment")!=null) reviewButton.setText(R.string.modifica_recensione); else reviewButton.setText(R.string.scrivirecensione_btn); } catch (JSONException e) { e.printStackTrace(); reviewButton.setText(R.string.scrivirecensione_btn); } } }); } else { try { JSONObject obj = new JSONObject(); obj.put("id_local", id); obj.put("id_user", PrefsManager.getId(c)); final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT +"/get_commento.php", obj); if (resp.getInt("return") == 0) { mapCacheRecensioni.put(id, resp); if (currentLoad == id) { runOnUiThread(new Runnable() { @Override public void run() { try { if( mapCacheRecensioni.get(id).getJSONObject("comment")!=null) reviewButton.setText(R.string.modifica_recensione); else reviewButton.setText(R.string.scrivirecensione_btn); } catch (JSONException e) { e.printStackTrace(); reviewButton.setText(R.string.scrivirecensione_btn); } } }); } } } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { Utils.toast(c,R.string.internet_problem); } } } }).start(); //getting avatar image new Thread(new Runnable() { public void run() { // if (mapCacheImage.containsKey(id)) { // // runOnUiThread(new Runnable() { // @Override // public void run() { // // loadingImage.setVisibility(View.GONE); // findViewById(R.id.profile_image).animate() // .translationY(0) // .alpha(0.0f) // .setListener(new AnimatorListenerAdapter() { // @Override // public void onAnimationEnd(Animator animation) { // super.onAnimationEnd(animation); // findViewById(R.id.profile_image).setVisibility(View.VISIBLE); // findViewById(R.id.profile_image).setAlpha(1.0f); // ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(mapCacheImage.get(id)); // } // }); // // // } // }); // } else { runOnUiThread(new Runnable() { @Override public void run() { findViewById(R.id.profile_image).setVisibility(View.INVISIBLE); loadingImage.setVisibility(View.VISIBLE); } }); JSONObject obj = new JSONObject(); try { obj.put("id", id); final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/get_immagini.php", obj); final JSONArray jArray = resp.getJSONArray("imgs"); if(jArray.length()>0){ final String filename = (String) jArray.get(0); final Bitmap imgweb = Utils.getBitmapFromURL(filename); runOnUiThread(new Runnable() { @Override public void run() { findViewById(R.id.profile_image).setVisibility(View.VISIBLE); loadingImage.setVisibility(View.GONE); ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(imgweb); } }); } else { runOnUiThread(new Runnable() { @Override public void run() { findViewById(R.id.profile_image).setVisibility(View.VISIBLE); loadingImage.setVisibility(View.GONE); ((ImageView) findViewById(R.id.profile_image)).setImageResource(R.drawable.placeholder); } }); } // JSONObject obj = new JSONObject(); // obj.put("user_id", mapCachelocals.get(id).getInt("id_utente_owner")); // final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/get_avatar.php", obj); // // if (resp.getInt("return") == 0) { // String filename = resp.getString("avatar"); // final Bitmap bitm = Utils.getBitmapFromURL(filename); // mapCacheImage.put(id, bitm); // if (currentLoad == id) { // runOnUiThread(new Runnable() { // @Override // public void run() { // findViewById(R.id.profile_image).setVisibility(View.VISIBLE); // loadingImage.setVisibility(View.GONE); // ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(bitm); // } // }); // } // } } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { Utils.toast(c, R.string.internet_problem); } // } } }).start(); } //getting info of local } public void markerClick(final Marker arg0) { final JSONObject j = ms.get(arg0); try { getInfoById(j.getInt("id")); } catch (Exception e) { e.printStackTrace(); } } private BitmapDescriptor GetCustomBitmapDescriptor(String text) { Bitmap baseBitmap = BitmapFactory.decodeResource(c.getResources(), R.drawable.base); Bitmap bitmap =baseBitmap.copy(Bitmap.Config.ARGB_8888, true); float x = bitmap.getWidth() / 2.0f-bounds.width()/2; float y = (bitmap.getHeight()); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(bitmap); return (icon); } public void addMarkerAsync(LatLng l, String n, JSONObject j) { Runnable addMarker = new AddMarker(map, new MarkerOptions() .position(l) .title(n) .icon(GetCustomBitmapDescriptor(n)), j); a.runOnUiThread(addMarker); } public void showOtherLocalInfo(View v) { if (!expanded){ openFullInfo(); } else { closeFullInfo(); } /* Intent i = new Intent(MapActivity.this, FullInfoActivity.class); i.putExtra("nome", ((TextView) findViewById(R.id.textView11)).getText().toString()); i.putExtra("tipologia", ((TextView) findViewById(R.id.textView12)).getText().toString()); i.putExtra("descrizione", ((TextView) findViewById(R.id.textView13)).getText().toString()); i.putExtra("indirizzo", ((TextView) findViewById(R.id.textView22)).getText().toString()); i.putExtra("stelle", ((RatingBar) findViewById(R.id.ratingBar)).getRating()); i.putExtra("idlocale",idlocale); startActivity(i); overridePendingTransition(R.anim.slideup,R.anim.slidedown); */ } private void openFullInfo() { otherInfo.setText(R.string.nascondi); expanded=true; // if (mapCacheFragment.containsKey(idlocale) && mapCacheFragment.get(idlocale) != full) { // FragmentManager fragmentManager = getFragmentManager(); // FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); // // fragmentTransaction.add(R.id.fullInfo, mapCacheFragment.get(idlocale), "HELLO"); // fragmentTransaction.commit(); // full = mapCacheFragment.get(idlocale); // // } else { if ( Utils.isNetworkConnected(c)) { Bundle b = new Bundle(); b.putInt("idlocale", idlocale); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FullInfoFragment hello = new FullInfoFragment(); hello.setArguments(b); fragmentTransaction.add(R.id.fullInfo, hello, "HELLO"); fragmentTransaction.commit(); full = hello; // mapCacheFragment.put(idlocale, hello); } // } } private void closeFullInfo() { expanded=false; runOnUiThread(new Runnable() { @Override public void run() { otherInfo.setText(R.string.local_detail_button); } }); ObjectAnimator objectAnimator = ObjectAnimator.ofInt(( a.findViewById(R.id.scrollView)), "scrollY", ( a.findViewById(R.id.scrollView)).getBottom(), 0).setDuration(500); objectAnimator.start(); // final Handler handler = new Handler(); // handler.postDelayed(new Runnable() { // @Override // public void run() { getFragmentManager().beginTransaction().remove(full).commit(); // FragmentManager fragmentManager = getFragmentManager(); // FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); // // fragmentTransaction.remove(full); // fragmentTransaction.commit(); //Do something after 100ms // } // }, 500); } public void clickRecensione(View v) { Intent i = new Intent(MapActivity.this, RecensioneActivity.class); i.putExtra("nome", ((TextView) findViewById(R.id.nome_locale)).getText().toString()); i.putExtra("tipologia", ((TextView) findViewById(R.id.tipologia)).getText().toString()); i.putExtra("idlocale", idlocale); i.putExtra("json", mapCacheRecensioni.get(idlocale).toString()); // mapCacheRecensioni.remove(idlocale); startActivity(i); } private class AddMarker implements Runnable { JSONObject j; private GoogleMap map; private MarkerOptions options; public AddMarker(GoogleMap map, MarkerOptions options, JSONObject jo) { this.j = jo; this.map = map; this.options = options; } @Override public void run() { Marker m = map.addMarker(options); if (nearest == null) { nearest = m; } else if (calculateDistanceFrom(nearest.getPosition().latitude, nearest.getPosition().longitude, mylocation.latitude, mylocation.longitude) > calculateDistanceFrom(m.getPosition().latitude, m.getPosition().longitude, mylocation.latitude, mylocation.longitude)) { nearest = m; } ms.put(m, j); } } } |
Commits for Nextrek/Android/SmartCharging/SmartCharging/app/src/main/java/it/fedeloper/smartcharging/Controller/MapActivity.java
Revision | Author | Commited | Message |
---|---|---|---|
785 Diff | FFontana | Sat 26 Sep, 2015 14:15:20 +0000 | |
776 Diff | FFontana | Wed 23 Sep, 2015 15:00:55 +0000 | |
765 Diff | MStefanelli | Tue 22 Sep, 2015 10:03:07 +0000 | me |
762 Diff | FFontana | Fri 18 Sep, 2015 16:18:57 +0000 | |
748 Diff | FFontana | Wed 16 Sep, 2015 15:31:34 +0000 | |
703 Diff | FFontana | Mon 07 Sep, 2015 15:22:49 +0000 | |
696 Diff | FFontana | Mon 07 Sep, 2015 10:52:07 +0000 | |
686 Diff | FFontana | Fri 04 Sep, 2015 14:59:51 +0000 | |
677 Diff | MStefanelli | Fri 04 Sep, 2015 14:14:38 +0000 | me |
676 | FFontana | Fri 04 Sep, 2015 13:55:52 +0000 |