コード例 #1
0
  private ViewGroup getViewForMessage(int num, boolean applyOffset) {
    if (NotificationsController.getInstance().popupMessages.size() == 1
        && (num < 0 || num >= NotificationsController.getInstance().popupMessages.size())) {
      return null;
    }
    if (num == -1) {
      num = NotificationsController.getInstance().popupMessages.size() - 1;
    } else if (num == NotificationsController.getInstance().popupMessages.size()) {
      num = 0;
    }
    ViewGroup view;
    MessageObject messageObject = NotificationsController.getInstance().popupMessages.get(num);
    if (messageObject.type == 1 || messageObject.type == 4) {
      if (imageViews.size() > 0) {
        view = imageViews.get(0);
        imageViews.remove(0);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_image_layout, null));
        view.setTag(2);

        view.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });
      }

      TextView messageText = (TextView) view.findViewById(R.id.message_text);
      BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
      imageView.setAspectFit(true);

      if (messageObject.type == 1) {
        TLRPC.PhotoSize currentPhotoObject =
            FileLoader.getClosestPhotoSizeWithSize(
                messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
        TLRPC.PhotoSize thumb =
            FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
        boolean photoSet = false;
        if (currentPhotoObject != null) {
          boolean photoExist = true;
          if (messageObject.type == 1) {
            File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
            if (!cacheFile.exists()) {
              photoExist = false;
            }
          }
          if (photoExist
              || MediaController.getInstance()
                  .canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
            imageView.setImage(
                currentPhotoObject.location, "100_100", thumb.location, currentPhotoObject.size);
            photoSet = true;
          } else {
            if (thumb != null) {
              imageView.setImage(thumb.location, null, (Drawable) null);
              photoSet = true;
            }
          }
        }
        if (!photoSet) {
          imageView.setVisibility(View.GONE);
          messageText.setVisibility(View.VISIBLE);
          messageText.setTextSize(
              TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
          messageText.setText(messageObject.messageText);
        } else {
          imageView.setVisibility(View.VISIBLE);
          messageText.setVisibility(View.GONE);
        }
      } else if (messageObject.type == 4) {
        messageText.setVisibility(View.GONE);
        messageText.setText(messageObject.messageText);
        imageView.setVisibility(View.VISIBLE);
        double lat = messageObject.messageOwner.media.geo.lat;
        double lon = messageObject.messageOwner.media.geo._long;
        String currentUrl =
            String.format(
                Locale.US,
                "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false",
                lat,
                lon,
                Math.min(2, (int) Math.ceil(AndroidUtilities.density)),
                lat,
                lon);
        imageView.setImage(currentUrl, null, null);
      }
    } else if (messageObject.type == 2) {
      PopupAudioView cell;
      if (audioViews.size() > 0) {
        view = audioViews.get(0);
        audioViews.remove(0);
        cell = (PopupAudioView) view.findViewWithTag(300);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_audio_layout, null));
        view.setTag(3);

        view.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });

        ViewGroup audioContainer = (ViewGroup) view.findViewById(R.id.audio_container);
        cell = new PopupAudioView(this);
        cell.setTag(300);
        audioContainer.addView(cell);
      }

      cell.setMessageObject(messageObject);
      if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
        cell.downloadAudioIfNeed();
      }
    } else {
      if (textViews.size() > 0) {
        view = textViews.get(0);
        textViews.remove(0);
      } else {
        view = new FrameLayoutAnimationListener(this);
        view.addView(getLayoutInflater().inflate(R.layout.popup_text_layout, null));
        view.setTag(1);

        View textContainer = view.findViewById(R.id.text_container);
        textContainer.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                openCurrentMessage();
              }
            });
      }
      TextView messageText = (TextView) view.findViewById(R.id.message_text);
      messageText.setTag(301);
      messageText.setTextSize(
          TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
      messageText.setText(messageObject.messageText);
    }
    if (view.getParent() == null) {
      messageContainer.addView(view);
    }
    view.setVisibility(View.VISIBLE);

    if (applyOffset) {
      int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
      FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
      layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
      layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
      layoutParams.width = widht;
      if (num == currentMessageNum) {
        layoutParams.leftMargin = 0;
      } else if (num == currentMessageNum - 1) {
        layoutParams.leftMargin = -widht;
      } else if (num == currentMessageNum + 1) {
        layoutParams.leftMargin = widht;
      }
      view.setLayoutParams(layoutParams);
      view.invalidate();
    }

    return view;
  }
コード例 #2
0
 @Override
 public void didReceivedNotification(int id, Object... args) {
   if (id == NotificationCenter.appDidLogout) {
     onFinish();
     finish();
   } else if (id == NotificationCenter.pushMessagesUpdated) {
     getNewMessage();
   } else if (id == NotificationCenter.updateInterfaces) {
     if (currentMessageObject == null) {
       return;
     }
     int updateMask = (Integer) args[0];
     if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0
         || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
       updateSubtitle();
     }
     if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
       checkAndUpdateAvatar();
     }
     if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
       CharSequence printString =
           MessagesController.getInstance()
               .printingStrings
               .get(currentMessageObject.getDialogId());
       if (lastPrintString != null && printString == null
           || lastPrintString == null && printString != null
           || lastPrintString != null
               && printString != null
               && !lastPrintString.equals(printString)) {
         updateSubtitle();
       }
     }
   } else if (id == NotificationCenter.audioDidReset) {
     Integer mid = (Integer) args[0];
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 3) {
           PopupAudioView cell = (PopupAudioView) view.findViewWithTag(300);
           if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
             cell.updateButtonState();
             break;
           }
         }
       }
     }
   } else if (id == NotificationCenter.audioProgressDidChanged) {
     Integer mid = (Integer) args[0];
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 3) {
           PopupAudioView cell = (PopupAudioView) view.findViewWithTag(300);
           if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
             cell.updateProgress();
             break;
           }
         }
       }
     }
   } else if (id == NotificationCenter.emojiDidLoaded) {
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 1) {
           TextView textView = (TextView) view.findViewWithTag(301);
           if (textView != null) {
             textView.invalidate();
           }
         }
       }
     }
   } else if (id == NotificationCenter.contactsDidLoaded) {
     updateSubtitle();
   }
 }