コード例 #1
0
 public void updateButtonState(boolean animated) {
   if (currentMessageObject == null) {
     return;
   }
   if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
     MediaController.getInstance()
         .addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this);
     buttonState = 4;
     radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
     Float progress =
         ImageLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath);
     if (progress == null
         && SendMessagesHelper.getInstance().isSendingMessage(currentMessageObject.getId())) {
       progress = 1.0f;
     }
     radialProgress.setProgress(progress != null ? progress : 0, false);
   } else {
     File cacheFile = null;
     if (currentMessageObject.messageOwner.attachPath != null
         && currentMessageObject.messageOwner.attachPath.length() > 0) {
       cacheFile = new File(currentMessageObject.messageOwner.attachPath);
       if (!cacheFile.exists()) {
         cacheFile = null;
       }
     }
     if (cacheFile == null) {
       cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
     }
     if (cacheFile.exists()) {
       MediaController.getInstance().removeLoadingFileObserver(this);
       boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
       if (!playing || playing && MediaController.getInstance().isAudioPaused()) {
         buttonState = 0;
       } else {
         buttonState = 1;
       }
       radialProgress.setProgress(0, animated);
       radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
     } else {
       String fileName = currentMessageObject.getFileName();
       MediaController.getInstance().addLoadingFileObserver(fileName, this);
       if (!FileLoader.getInstance().isLoadingFile(fileName)) {
         buttonState = 2;
         radialProgress.setProgress(0, animated);
         radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
       } else {
         buttonState = 3;
         Float progress = ImageLoader.getInstance().getFileProgress(fileName);
         if (progress != null) {
           radialProgress.setProgress(progress, animated);
         } else {
           radialProgress.setProgress(0, animated);
         }
         radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
       }
     }
   }
   updateProgress();
 }
コード例 #2
0
 @Override
 public View getView(int i, View view, ViewGroup viewGroup) {
   int type = getItemViewType(i);
   if (type == 0) {
     if (view == null) {
       LayoutInflater li =
           (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       view = li.inflate(R.layout.settings_wallpapers_my_row, viewGroup, false);
     }
     View parentView = view.findViewById(R.id.parent);
     ImageView imageView = (ImageView) view.findViewById(R.id.image);
     View selection = view.findViewById(R.id.selection);
     if (i == 0) {
       if (selectedBackground == -1 || selectedColor != 0 || selectedBackground == 1000001) {
         imageView.setBackgroundColor(0x5A475866);
       } else {
         imageView.setBackgroundColor(0x5A000000);
       }
       imageView.setImageResource(R.drawable.ic_gallery_background);
       if (selectedBackground == -1) {
         selection.setVisibility(View.VISIBLE);
       } else {
         selection.setVisibility(View.INVISIBLE);
       }
     } else {
       imageView.setImageBitmap(null);
       TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
       imageView.setBackgroundColor(0xff000000 | wallPaper.bg_color);
       if (wallPaper.id == selectedBackground) {
         selection.setVisibility(View.VISIBLE);
       } else {
         selection.setVisibility(View.INVISIBLE);
       }
     }
   } else if (type == 1) {
     if (view == null) {
       LayoutInflater li =
           (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       view = li.inflate(R.layout.settings_wallpapers_other_row, viewGroup, false);
     }
     BackupImageView image = (BackupImageView) view.findViewById(R.id.image);
     View selection = view.findViewById(R.id.selection);
     TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
     TLRPC.PhotoSize size =
         FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100));
     if (size != null && size.location != null) {
       image.setImage(size.location, "100_100", 0);
     }
     if (wallPaper.id == selectedBackground) {
       selection.setVisibility(View.VISIBLE);
     } else {
       selection.setVisibility(View.INVISIBLE);
     }
   }
   return view;
 }
コード例 #3
0
 private void didPressedButton() {
   if (buttonState == 0) {
     if (musicDelegate != null) {
       if (musicDelegate.needPlayMusic(currentMessageObject)) {
         buttonState = 1;
         radialProgress.setBackground(getDrawableForCurrentState(), false, false);
         invalidate();
       }
     }
   } else if (buttonState == 1) {
     boolean result = MediaController.getInstance().pauseAudio(currentMessageObject);
     if (result) {
       buttonState = 0;
       radialProgress.setBackground(getDrawableForCurrentState(), false, false);
       invalidate();
     }
   } else if (buttonState == 2) {
     radialProgress.setProgress(0, false);
     FileLoader.getInstance()
         .loadFile(currentMessageObject.messageOwner.media.document, true, false);
     buttonState = 3;
     radialProgress.setBackground(getDrawableForCurrentState(), true, false);
     invalidate();
   } else if (buttonState == 3) {
     FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document);
     buttonState = 2;
     radialProgress.setBackground(getDrawableForCurrentState(), false, false);
     invalidate();
   } else if (buttonState == 4) {
     if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
       if (delegate != null) {
         delegate.didPressedCancelSendButton(this);
       }
     }
   }
 }
コード例 #4
0
ファイル: ChatActionCell.java プロジェクト: thaidn/securegram
 public void setMessageObject(MessageObject messageObject) {
   if (currentMessageObject == messageObject) {
     return;
   }
   currentMessageObject = messageObject;
   previousWidth = 0;
   if (currentMessageObject.type == MessageObject.Type.MSG_ACTION) {
     int id = 0;
     if (messageObject.messageOwner.to_id != null) {
       if (messageObject.messageOwner.to_id.chat_id != 0) {
         id = messageObject.messageOwner.to_id.chat_id;
       } else {
         id = messageObject.messageOwner.to_id.user_id;
         if (id == UserConfig.getClientUserId()) {
           id = messageObject.messageOwner.from_id;
         }
       }
     }
     avatarDrawable.setInfo(id, null, null, false);
     if (currentMessageObject.messageOwner.action
         instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
       imageReceiver.setImage(
           currentMessageObject.messageOwner.action.newUserPhoto.photo_small,
           "50_50",
           avatarDrawable,
           null,
           false);
     } else {
       TLRPC.PhotoSize photo =
           FileLoader.getClosestPhotoSizeWithSize(
               currentMessageObject.photoThumbs, AndroidUtilities.dp(64));
       if (photo != null) {
         imageReceiver.setImage(photo.location, "50_50", avatarDrawable, null, false);
       } else {
         imageReceiver.setImageBitmap(avatarDrawable);
       }
     }
     imageReceiver.setVisible(
         !PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
   } else {
     imageReceiver.setImageBitmap((Bitmap) null);
   }
   requestLayout();
 }
コード例 #5
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;
  }
コード例 #6
0
 private void processSelectedBackground() {
   TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
   if (selectedBackground != -1
       && selectedBackground != 1000001
       && wallPaper != null
       && wallPaper instanceof TLRPC.TL_wallPaper) {
     int width = AndroidUtilities.displaySize.x;
     int height = AndroidUtilities.displaySize.y;
     if (width > height) {
       int temp = width;
       width = height;
       height = temp;
     }
     TLRPC.PhotoSize size =
         FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
     String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
     File f =
         new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
     if (!f.exists()) {
       progressBar.setProgress(0);
       loadingFile = fileName;
       loadingFileObject = f;
       doneButton.setEnabled(false);
       progressBar.setVisibility(View.VISIBLE);
       loadingSize = size;
       selectedColor = 0;
       FileLoader.getInstance().loadFile(size, true);
       backgroundImage.setBackgroundColor(0);
     } else {
       if (loadingFile != null) {
         FileLoader.getInstance().cancelLoadFile(loadingSize);
       }
       loadingFileObject = null;
       loadingFile = null;
       loadingSize = null;
       backgroundImage.setImageURI(Uri.fromFile(f));
       backgroundImage.setBackgroundColor(0);
       selectedColor = 0;
       doneButton.setEnabled(true);
       progressBar.setVisibility(View.GONE);
     }
   } else {
     if (loadingFile != null) {
       FileLoader.getInstance().cancelLoadFile(loadingSize);
     }
     if (selectedBackground == 1000001) {
       backgroundImage.setImageResource(R.drawable.background_hd);
       backgroundImage.setBackgroundColor(0);
       selectedColor = 0;
     } else if (selectedBackground == -1) {
       File toFile =
           new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
       if (!toFile.exists()) {
         toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
       }
       if (toFile.exists()) {
         backgroundImage.setImageURI(Uri.fromFile(toFile));
       } else {
         selectedBackground = 1000001;
         processSelectedBackground();
       }
     } else {
       if (wallPaper == null) {
         return;
       }
       if (wallPaper instanceof TLRPC.TL_wallPaperSolid) {
         backgroundImage.setImageBitmap(null);
         selectedColor = 0xff000000 | wallPaper.bg_color;
         backgroundImage.setBackgroundColor(selectedColor);
       }
     }
     loadingFileObject = null;
     loadingFile = null;
     loadingSize = null;
     doneButton.setEnabled(true);
     progressBar.setVisibility(View.GONE);
   }
 }