Exemplo n.º 1
1
 @Override
 public void setPressed(boolean pressed) {
   if (imageView.getImageReceiver().getPressed() != pressed) {
     imageView.getImageReceiver().setPressed(pressed);
     imageView.invalidate();
   }
   super.setPressed(pressed);
 }
Exemplo n.º 2
0
  public StickerCell(Context context) {
    super(context);

    imageView = new BackupImageView(context);
    imageView.setAspectFit(true);
    addView(imageView, LayoutHelper.createFrame(66, 66, Gravity.CENTER_HORIZONTAL, 0, 5, 0, 0));
  }
 private void checkAndUpdateAvatar() {
   TLRPC.FileLocation newPhoto = null;
   AvatarDrawable avatarDrawable = null;
   if (currentChat != null) {
     TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
     if (chat == null) {
       return;
     }
     currentChat = chat;
     if (currentChat.photo != null) {
       newPhoto = currentChat.photo.photo_small;
     }
     avatarDrawable = new AvatarDrawable(currentChat);
   } else if (currentUser != null) {
     TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
     if (user == null) {
       return;
     }
     currentUser = user;
     if (currentUser.photo != null) {
       newPhoto = currentUser.photo.photo_small;
     }
     avatarDrawable = new AvatarDrawable(currentUser);
   }
   if (avatarImageView != null) {
     avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
   }
 }
 @Override
 protected void onDestroy() {
   super.onDestroy();
   onFinish();
   if (wakeLock.isHeld()) {
     wakeLock.release();
   }
   if (avatarImageView != null) {
     avatarImageView.setImageDrawable(null);
   }
 }
Exemplo n.º 5
0
 public void setSticker(TLRPC.Document document, int side) {
   if (document != null && document.thumb != null) {
     imageView.setImage(document.thumb.location, null, "webp", null);
   }
   if (side == -1) {
     setBackgroundResource(theme.StickerCell_bg_1_R);
     setPadding(AndroidUtilities.dp(7), 0, 0, 0);
   } else if (side == 0) {
     setBackgroundResource(theme.StickerCell_bg_2_R);
     setPadding(0, 0, 0, 0);
   } else if (side == 1) {
     setBackgroundResource(theme.StickerCell_bg_3_R);
     setPadding(0, 0, AndroidUtilities.dp(7), 0);
   } else if (side == 2) {
     setBackgroundResource(theme.StickerCell_bg_4_R);
     setPadding(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3), 0);
   }
   if (getBackground() != null) {
     getBackground().setAlpha(230);
   }
 }
Exemplo n.º 6
0
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      int viewType = getItemViewType(i);
      if (viewType == 0) {
        PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
        if (view == null) {
          view = new PhotoPickerPhotoCell(mContext);
          cell = (PhotoPickerPhotoCell) view;
          cell.checkFrame.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  int index = (Integer) ((View) v.getParent()).getTag();
                  if (selectedAlbum != null) {
                    MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
                    if (selectedPhotos.containsKey(photoEntry.imageId)) {
                      selectedPhotos.remove(photoEntry.imageId);
                      photoEntry.imagePath = null;
                      photoEntry.thumbPath = null;
                      updatePhotoAtIndex(index);
                    } else {
                      selectedPhotos.put(photoEntry.imageId, photoEntry);
                    }
                    ((PhotoPickerPhotoCell) v.getParent())
                        .checkBox.setChecked(selectedPhotos.containsKey(photoEntry.imageId), true);
                  } else {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                    MediaController.SearchImage photoEntry;
                    if (searchResult.isEmpty() && lastSearchString == null) {
                      photoEntry = recentImages.get((Integer) ((View) v.getParent()).getTag());
                    } else {
                      photoEntry = searchResult.get((Integer) ((View) v.getParent()).getTag());
                    }
                    if (selectedWebPhotos.containsKey(photoEntry.id)) {
                      selectedWebPhotos.remove(photoEntry.id);
                      photoEntry.imagePath = null;
                      photoEntry.thumbPath = null;
                      updatePhotoAtIndex(index);
                    } else {
                      selectedWebPhotos.put(photoEntry.id, photoEntry);
                    }
                    ((PhotoPickerPhotoCell) v.getParent())
                        .checkBox.setChecked(selectedWebPhotos.containsKey(photoEntry.id), true);
                  }
                  pickerBottomLayout.updateSelectedCount(
                      selectedPhotos.size() + selectedWebPhotos.size(), true);
                  delegate.selectedPhotosChanged();
                }
              });
          cell.checkFrame.setVisibility(singlePhoto ? View.GONE : View.VISIBLE);
        }
        cell.itemWidth = itemWidth;
        BackupImageView imageView = ((PhotoPickerPhotoCell) view).photoImage;
        imageView.setTag(i);
        view.setTag(i);
        boolean showing;
        imageView.setOrientation(0, true);

        if (selectedAlbum != null) {
          MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(i);
          if (photoEntry.thumbPath != null) {
            imageView.setImage(
                photoEntry.thumbPath,
                null,
                mContext.getResources().getDrawable(R.drawable.nophotos));
          } else if (photoEntry.path != null) {
            imageView.setOrientation(photoEntry.orientation, true);
            if (photoEntry.isVideo) {
              imageView.setImage(
                  "vthumb://" + photoEntry.imageId + ":" + photoEntry.path,
                  null,
                  mContext.getResources().getDrawable(R.drawable.nophotos));
            } else {
              imageView.setImage(
                  "thumb://" + photoEntry.imageId + ":" + photoEntry.path,
                  null,
                  mContext.getResources().getDrawable(R.drawable.nophotos));
            }
          } else {
            imageView.setImageResource(R.drawable.nophotos);
          }
          cell.checkBox.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
          showing = PhotoViewer.getInstance().isShowingImage(photoEntry.path);
        } else {
          MediaController.SearchImage photoEntry;
          if (searchResult.isEmpty() && lastSearchString == null) {
            photoEntry = recentImages.get(i);
          } else {
            photoEntry = searchResult.get(i);
          }
          if (photoEntry.thumbPath != null) {
            imageView.setImage(
                photoEntry.thumbPath,
                null,
                mContext.getResources().getDrawable(R.drawable.nophotos));
          } else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
            imageView.setImage(
                photoEntry.thumbUrl,
                null,
                mContext.getResources().getDrawable(R.drawable.nophotos));
          } else {
            imageView.setImageResource(R.drawable.nophotos);
          }
          cell.checkBox.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
          showing = PhotoViewer.getInstance().isShowingImage(photoEntry.thumbUrl);
        }
        imageView.getImageReceiver().setVisible(!showing, true);
        cell.checkBox.setVisibility(singlePhoto || showing ? View.GONE : View.VISIBLE);
      } else if (viewType == 1) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.media_loading_layout, viewGroup, false);
        }
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.width = itemWidth;
        params.height = itemWidth;
        view.setLayoutParams(params);
      }
      return view;
    }
  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;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    classGuid = ConnectionsManager.getInstance().generateClassGuid();
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.pushMessagesUpdated);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    typingDotsDrawable = new TypingDotsDrawable();
    recordStatusDrawable = new RecordStatusDrawable();

    SizeNotifierRelativeLayout contentView = new SizeNotifierRelativeLayout(this);
    setContentView(contentView);
    contentView.setBackgroundColor(0x99000000);

    RelativeLayout relativeLayout = new RelativeLayout(this);
    contentView.addView(relativeLayout);
    RelativeLayout.LayoutParams layoutParams3 =
        (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.MATCH_PARENT;
    relativeLayout.setLayoutParams(layoutParams3);

    RelativeLayout popupContainer = new RelativeLayout(this);
    popupContainer.setBackgroundColor(0xffffffff);
    relativeLayout.addView(popupContainer);
    layoutParams3 = (RelativeLayout.LayoutParams) popupContainer.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = AndroidUtilities.dp(240);
    layoutParams3.leftMargin = AndroidUtilities.dp(12);
    layoutParams3.rightMargin = AndroidUtilities.dp(12);
    layoutParams3.addRule(RelativeLayout.CENTER_IN_PARENT);
    popupContainer.setLayoutParams(layoutParams3);

    if (chatActivityEnterView != null) {
      chatActivityEnterView.onDestroy();
    }
    chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false);
    popupContainer.addView(chatActivityEnterView);
    layoutParams3 = (RelativeLayout.LayoutParams) chatActivityEnterView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    chatActivityEnterView.setLayoutParams(layoutParams3);
    chatActivityEnterView.setDelegate(
        new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
          @Override
          public void onMessageSend(String message) {
            if (currentMessageObject == null) {
              return;
            }
            if (currentMessageNum >= 0
                && currentMessageNum < NotificationsController.getInstance().popupMessages.size()) {
              NotificationsController.getInstance().popupMessages.remove(currentMessageNum);
            }
            MessagesController.getInstance()
                .markDialogAsRead(
                    currentMessageObject.getDialogId(),
                    currentMessageObject.getId(),
                    Math.max(0, currentMessageObject.getId()),
                    0,
                    currentMessageObject.messageOwner.date,
                    true,
                    true);
            currentMessageObject = null;
            getNewMessage();
          }

          @Override
          public void onTextChanged(CharSequence text, boolean big) {}

          @Override
          public void needSendTyping() {
            if (currentMessageObject != null) {
              MessagesController.getInstance()
                  .sendTyping(currentMessageObject.getDialogId(), 0, classGuid);
            }
          }

          @Override
          public void onAttachButtonHidden() {}

          @Override
          public void onAttachButtonShow() {}

          @Override
          public void onWindowSizeChanged(int size) {}
        });

    messageContainer = new FrameLayoutTouch(this);
    popupContainer.addView(messageContainer, 0);

    actionBar = new ActionBar(this);
    actionBar.setOccupyStatusBar(false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setBackgroundColor(0xff54759e);
    actionBar.setItemsBackground(R.drawable.bar_selector);
    popupContainer.addView(actionBar);
    ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    actionBar.setLayoutParams(layoutParams);

    ActionBarMenu menu = actionBar.createMenu();
    View view = menu.addItemResource(2, R.layout.popup_count_layout);
    countText = (TextView) view.findViewById(R.id.count_text);

    avatarContainer = new FrameLayoutFixed(this);
    avatarContainer.setBackgroundResource(R.drawable.bar_selector);
    avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
    actionBar.addView(avatarContainer);
    FrameLayout.LayoutParams layoutParams2 =
        (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
    layoutParams2.height = LayoutHelper.MATCH_PARENT;
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.rightMargin = AndroidUtilities.dp(48);
    layoutParams2.leftMargin = AndroidUtilities.dp(60);
    layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
    avatarContainer.setLayoutParams(layoutParams2);

    avatarImageView = new BackupImageView(this);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
    avatarContainer.addView(avatarImageView);
    layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
    layoutParams2.width = AndroidUtilities.dp(42);
    layoutParams2.height = AndroidUtilities.dp(42);
    layoutParams2.topMargin = AndroidUtilities.dp(3);
    avatarImageView.setLayoutParams(layoutParams2);

    nameTextView = new TextView(this);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity(Gravity.LEFT);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    avatarContainer.addView(nameTextView);
    layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(22);
    layoutParams2.gravity = Gravity.BOTTOM;
    nameTextView.setLayoutParams(layoutParams2);

    onlineTextView = new TextView(this);
    onlineTextView.setTextColor(0xffd7e8f7);
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setLines(1);
    onlineTextView.setMaxLines(1);
    onlineTextView.setSingleLine(true);
    onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
    onlineTextView.setGravity(Gravity.LEFT);
    avatarContainer.addView(onlineTextView);
    layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.leftMargin = AndroidUtilities.dp(54);
    layoutParams2.bottomMargin = AndroidUtilities.dp(4);
    layoutParams2.gravity = Gravity.BOTTOM;
    onlineTextView.setLayoutParams(layoutParams2);

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              onFinish();
              finish();
            } else if (id == 1) {
              openCurrentMessage();
            } else if (id == 2) {
              switchToNextMessage();
            }
          }
        });

    PowerManager pm =
        (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
    wakeLock.setReferenceCounted(false);

    handleIntent(getIntent());
  }