Subversion Repository Public Repository

Nextrek

Diff Revisions 747 vs 748 for /Android/SmartCharging/SmartCharging/app/src/main/java/it/fedeloper/smartcharging/Controller/MapActivity.java

Diff revisions: vs.
  @@ -1,6 +1,8 @@
1 1 package it.fedeloper.smartcharging.Controller;
2 2
3 3
4 + import android.animation.Animator;
5 + import android.animation.AnimatorListenerAdapter;
4 6 import android.animation.ObjectAnimator;
5 7 import android.app.Activity;
6 8 import android.app.AlertDialog;
  @@ -50,6 +52,7 @@
50 52 import com.google.android.gms.maps.model.LatLng;
51 53 import com.google.android.gms.maps.model.Marker;
52 54 import com.google.android.gms.maps.model.MarkerOptions;
55 + import com.rey.material.widget.ProgressView;
53 56
54 57 import it.fedeloper.smartcharging.*;
55 58 import it.fedeloper.smartcharging.Manager.MyLocation;
  @@ -110,6 +113,8 @@
110 113 private TextView cariLocaleTextView;
111 114 private Button reviewButton;
112 115
116 + private ProgressView loadingImage;
117 + private ProgressView loadingAll;
113 118
114 119 @Override
115 120 public void onBackPressed() {
  @@ -145,6 +150,7 @@
145 150 initView();
146 151
147 152
153 +
148 154 final EditText addressView = (EditText) findViewById(R.id.editText6);
149 155 addressView.setImeOptions(EditorInfo.IME_ACTION_DONE);
150 156 setListenerToRootView();
  @@ -243,7 +249,7 @@
243 249 map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(41.902285, 12.496975), 5.0f));
244 250 }
245 251 boolean isOpened = false;
246 -
252 + private boolean firstLocal=true;
247 253 public void setListenerToRootView(){
248 254 final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
249 255 activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  @@ -262,6 +268,10 @@
262 268 }
263 269 private void initView(){
264 270
271 +
272 + loadingImage= (ProgressView) findViewById(R.id.loadingImage);
273 + loadingAll= (ProgressView) findViewById(R.id.loadingAll);
274 +
265 275 reviewButton = (Button) findViewById(R.id.button12);
266 276 if(!PrefsManager.isLogged(this))
267 277 reviewButton.setVisibility(View.GONE);
  @@ -518,6 +528,8 @@
518 528 }).start();
519 529 }
520 530
531 + private boolean animationOffEnded=false;
532 +
521 533 public void getInfoById(final int id) {
522 534 // if (id != idlocale) {
523 535 // runOnUiThread(new Runnable() {
  @@ -535,52 +547,200 @@
535 547 //getting info of local
536 548 new Thread(new Runnable() {
537 549 public void run() {
538 - JSONObject obj = new JSONObject();
539 - if (inLoading <= 0) {
540 - inLoading = 0;
541 - try {
542 - inLoading++;
543 - currentLoad = id;
544 - obj.put("id", id);
545 - final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/get_info_full_locale.php", obj);
546 550
547 - if (resp == null && isInFront) {
548 - getInfoById(id);
549 - } else {
550 -
551 - mapCacheInfo.put(id, resp);
551 + if (mapCacheInfo.containsKey(id)) {
552 + runOnUiThread(new Runnable() {
553 + @Override
554 + public void run() {
555 + final JSONObject resp = mapCacheInfo.get(id);
556 + final String[] tipi = getResources().getStringArray(R.array.type_array);
552 557 runOnUiThread(new Runnable() {
553 558 @Override
554 559 public void run() {
555 - try {
556 - String[] tipi = getResources().getStringArray(R.array.type_array);
557 - ((TextView) findViewById(R.id.nome_locale)).setText(resp.getString("nomelocale"));
558 - ((TextView) findViewById(R.id.tipologia)).setText(tipi[Integer.parseInt(resp.getString("tipologia"))]);
559 - ((TextView) findViewById(R.id.descrizione)).setText(resp.getString("descrizione"));
560 - ((TextView) findViewById(R.id.via_locale)).setText(resp.getString("indirizzo"));
561 - ((RatingBar) findViewById(R.id.ratingBar)).setRating(resp.getLong("stelle"));
562 - sitoLocaleTextView.setText(resp.getString("sito"));
563 - emailLocaleTextView.setText(resp.getString("email"));
564 - numLocaleTextView.setText(resp.getString("telefono"));
565 - cariLocaleTextView.setText(getString(R.string.punti_di_ricarica)+resp.getString("n_punti_ricarica"));
566 - idlocale = id;
567 - } catch (JSONException e) {
568 - e.printStackTrace();
569 - }
560 +
561 + localeContainer.animate()
562 + .translationY(0)
563 + .alpha(0.0f)
564 + .setListener(new AnimatorListenerAdapter() {
565 + @Override
566 + public void onAnimationEnd(Animator animation) {
567 + super.onAnimationEnd(animation);
568 + localeContainer.setVisibility(View.VISIBLE);
569 + localeContainer.setAlpha(1.0f);
570 + try {
571 + ((TextView) findViewById(R.id.nome_locale)).setText(resp.getString("nomelocale"));
572 + ((TextView) findViewById(R.id.tipologia)).setText(tipi[Integer.parseInt(resp.getString("tipologia"))]);
573 + ((TextView) findViewById(R.id.descrizione)).setText(resp.getString("descrizione"));
574 + ((TextView) findViewById(R.id.via_locale)).setText(resp.getString("indirizzo"));
575 + ((RatingBar) findViewById(R.id.ratingBar)).setRating(resp.getLong("stelle"));
576 + sitoLocaleTextView.setText(resp.getString("sito"));
577 + emailLocaleTextView.setText(resp.getString("email"));
578 + numLocaleTextView.setText(resp.getString("telefono"));
579 + cariLocaleTextView.setText(getString(R.string.punti_di_ricarica) + resp.getString("n_punti_ricarica"));
580 +
581 +
582 + } catch (JSONException e) {
583 + e.printStackTrace();
584 + }
585 +
586 +
587 + }
588 + });
589 + otherInfo.animate()
590 + .translationY(0)
591 + .alpha(0.0f)
592 + .setListener(new AnimatorListenerAdapter() {
593 + @Override
594 + public void onAnimationEnd(Animator animation) {
595 + super.onAnimationEnd(animation);
596 + otherInfo.setVisibility(View.VISIBLE);
597 + otherInfo.setAlpha(1.0f);
598 + }
599 + });
570 600 }
571 601 });
602 +
603 + idlocale = id;
572 604 }
573 - } catch (JSONException e) {
574 - e.printStackTrace();
605 + });
606 + }else
607 + {
608 + if (firstLocal==false)
609 + {
610 + runOnUiThread(new Runnable() {
611 + @Override
612 + public void run() {
613 + animationOffEnded=false;
614 + localeContainer.animate()
615 + .translationY(0)
616 + .alpha(0.0f)
617 + .setListener(new AnimatorListenerAdapter() {
618 + @Override
619 + public void onAnimationEnd(Animator animation) {
620 + super.onAnimationEnd(animation);
621 + localeContainer.setVisibility(View.VISIBLE);
622 + animationOffEnded=true;
623 + }
624 + });
625 + otherInfo.animate()
626 + .translationY(0)
627 + .alpha(0.0f)
628 + .setListener(new AnimatorListenerAdapter() {
629 + @Override
630 + public void onAnimationEnd(Animator animation) {
631 + super.onAnimationEnd(animation);
632 + otherInfo.setVisibility(View.INVISIBLE);
633 + }
634 + });
635 + }
636 + });
637 + }else
638 + {
639 + runOnUiThread(new Runnable() {
640 + @Override
641 + public void run() {
642 + loadingAll.setVisibility(View.VISIBLE);
643 + }
644 + });
645 +
646 + }
647 +
648 +
649 + JSONObject obj = new JSONObject();
650 + if (inLoading <= 0) {
651 + inLoading = 0;
652 + try {
653 + inLoading++;
654 + currentLoad = id;
655 + obj.put("id", id);
656 + final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/get_info_full_locale.php", obj);
657 +
658 + if (resp == null && isInFront) {
659 + getInfoById(id);
660 + } else {
661 +
662 + mapCacheInfo.put(id, resp);
663 + if (firstLocal==false)
664 + {
665 + while (animationOffEnded==false)
666 + {
667 + try {
668 + Thread.sleep(100);
669 + } catch (InterruptedException e) {
670 + e.printStackTrace();
671 + }
672 + }
673 + }else
674 + {
675 + firstLocal=false;
676 + }
677 +
678 + runOnUiThread(new Runnable() {
679 + @Override
680 + public void run() {
681 + try {
682 +
683 + loadingAll.setVisibility(View.GONE);
684 +
685 + String[] tipi = getResources().getStringArray(R.array.type_array);
686 + ((TextView) findViewById(R.id.nome_locale)).setText(resp.getString("nomelocale"));
687 + ((TextView) findViewById(R.id.tipologia)).setText(tipi[Integer.parseInt(resp.getString("tipologia"))]);
688 + ((TextView) findViewById(R.id.descrizione)).setText(resp.getString("descrizione"));
689 + ((TextView) findViewById(R.id.via_locale)).setText(resp.getString("indirizzo"));
690 + ((RatingBar) findViewById(R.id.ratingBar)).setRating(resp.getLong("stelle"));
691 + sitoLocaleTextView.setText(resp.getString("sito"));
692 + emailLocaleTextView.setText(resp.getString("email"));
693 + numLocaleTextView.setText(resp.getString("telefono"));
694 + cariLocaleTextView.setText(getString(R.string.punti_di_ricarica)+resp.getString("n_punti_ricarica"));
695 + idlocale = id;
696 + } catch (JSONException e) {
697 + e.printStackTrace();
698 + }
699 + }
700 + });
701 + }
702 + } catch (JSONException e) {
703 + e.printStackTrace();
704 + }
705 +
706 +
707 + runOnUiThread(new Runnable() {
708 + @Override
709 + public void run() {
710 +
711 + localeContainer.animate()
712 + .translationY(0)
713 + .alpha(1.0f)
714 + .setListener(new AnimatorListenerAdapter() {
715 + @Override
716 + public void onAnimationEnd(Animator animation) {
717 + super.onAnimationEnd(animation);
718 + localeContainer.setVisibility(View.VISIBLE);
719 + }
720 + });
721 + otherInfo.animate()
722 + .translationY(0)
723 + .alpha(1.0f)
724 + .setListener(new AnimatorListenerAdapter() {
725 + @Override
726 + public void onAnimationEnd(Animator animation) {
727 + super.onAnimationEnd(animation);
728 + otherInfo.setVisibility(View.VISIBLE);
729 + }
730 + });
731 + }
732 + });
733 +
734 + inLoading--;
735 + if (nextToLoad != -1)
736 + getInfoById(nextToLoad);
737 + nextToLoad = -1;
738 + } else {
739 + if (nextToLoad != currentLoad)
740 + nextToLoad = id;
575 741 }
576 - inLoading--;
577 - if (nextToLoad != -1)
578 - getInfoById(nextToLoad);
579 - nextToLoad = -1;
580 - } else {
581 - if (nextToLoad != currentLoad)
582 - nextToLoad = id;
583 742 }
743 +
584 744 }
585 745 }).start();
586 746
  @@ -659,12 +819,34 @@
659 819 @Override
660 820 public void run() {
661 821
662 - findViewById(R.id.profile_image).setVisibility(View.VISIBLE);
822 + loadingImage.setVisibility(View.GONE);
823 + findViewById(R.id.profile_image).animate()
824 + .translationY(0)
825 + .alpha(0.0f)
826 + .setListener(new AnimatorListenerAdapter() {
827 + @Override
828 + public void onAnimationEnd(Animator animation) {
829 + super.onAnimationEnd(animation);
830 + findViewById(R.id.profile_image).setVisibility(View.VISIBLE);
831 + findViewById(R.id.profile_image).setAlpha(1.0f);
832 + ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(mapCacheImage.get(id));
833 + }
834 + });
835 +
663 836
664 - ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(mapCacheImage.get(id));
665 837 }
666 838 });
667 839 } else {
840 +
841 + runOnUiThread(new Runnable() {
842 + @Override
843 + public void run() {
844 +
845 + findViewById(R.id.profile_image).setVisibility(View.INVISIBLE);
846 + loadingImage.setVisibility(View.VISIBLE);
847 + }
848 + });
849 +
668 850 try {
669 851
670 852 JSONObject obj = new JSONObject();
  @@ -682,7 +864,7 @@
682 864 @Override
683 865 public void run() {
684 866 findViewById(R.id.profile_image).setVisibility(View.VISIBLE);
685 -
867 + loadingImage.setVisibility(View.GONE);
686 868 ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(bitm);
687 869 }
688 870 });