Exemplo n.º 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();
 }
Exemplo n.º 2
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (currentMessageObject == null) {
      return;
    }

    if (currentMessageObject.isOutOwner()) {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color);
    } else {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color_2);
    }
    radialProgress.draw(canvas);

    canvas.save();
    canvas.translate(timeX + titleX, AndroidUtilities.dp(12) + namesOffset);
    titleLayout.draw(canvas);
    canvas.restore();

    canvas.save();
    if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
      canvas.translate(seekBarX, seekBarY);
      seekBar.draw(canvas);
    } else {
      canvas.translate(timeX + authorX, AndroidUtilities.dp(32) + namesOffset);
      authorLayout.draw(canvas);
    }
    canvas.restore();

    canvas.save();
    canvas.translate(timeX, AndroidUtilities.dp(52) + namesOffset);
    timeLayout.draw(canvas);
    canvas.restore();
  }
Exemplo n.º 3
0
  public void updateProgress() {
    if (currentMessageObject == null) {
      return;
    }

    if (!seekBar.isDragging()) {
      seekBar.setProgress(currentMessageObject.audioProgress);
    }

    int duration = 0;
    int currentProgress = 0;
    for (TLRPC.DocumentAttribute attribute :
        currentMessageObject.messageOwner.media.document.attributes) {
      if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
        duration = attribute.duration;
        break;
      }
    }
    if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
      currentProgress = currentMessageObject.audioProgressSec;
    }
    String timeString =
        String.format(
            "%d:%02d / %d:%02d",
            currentProgress / 60, currentProgress % 60, duration / 60, duration % 60);
    if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
      lastTimeString = timeString;
      int timeWidth = (int) Math.ceil(timePaint.measureText(timeString));
      timeLayout =
          new StaticLayout(
              timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
    invalidate();
  }
Exemplo n.º 4
0
 @Override
 public void onSeekBarDrag(float progress) {
   if (currentMessageObject == null) {
     return;
   }
   currentMessageObject.audioProgress = progress;
   MediaController.getInstance().seekToProgress(currentMessageObject, progress);
 }
 @Override
 public boolean onFragmentCreate() {
   loading = true;
   MediaController.loadGalleryPhotosAlbums(classGuid);
   NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
   NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
   NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
   return super.onFragmentCreate();
 }
Exemplo n.º 6
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);
       }
     }
   }
 }
Exemplo n.º 7
0
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   MediaController.getInstance().removeLoadingFileObserver(this);
 }
Exemplo n.º 8
0
 public void onRevealAnimationEnd(boolean open) {
   if (open && Build.VERSION.SDK_INT <= 19 && MediaController.allPhotosAlbumEntry == null) {
     MediaController.loadGalleryPhotosAlbums(0);
   }
 }
Exemplo n.º 9
0
  public ChatAttachView(Context context) {
    super(context);

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
    if (MediaController.allPhotosAlbumEntry == null) {
      if (Build.VERSION.SDK_INT >= 21) {
        MediaController.loadGalleryPhotosAlbums(0);
      }
      loading = true;
    }

    views[8] = attachPhotoRecyclerView = new RecyclerListView(context);
    attachPhotoRecyclerView.setVerticalScrollBarEnabled(true);
    attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context));
    attachPhotoRecyclerView.setClipToPadding(false);
    attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
    attachPhotoRecyclerView.setItemAnimator(null);
    attachPhotoRecyclerView.setLayoutAnimation(null);
    if (Build.VERSION.SDK_INT >= 9) {
      attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    }
    addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoLayoutManager =
        new LinearLayoutManager(context) {
          @Override
          public boolean supportsPredictiveItemAnimations() {
            return false;
          }
        };
    attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager);
    photoAttachAdapter.setDelegate(
        new PhotoAttachAdapter.PhotoAttachAdapterDelegate() {
          @Override
          public void selectedPhotosChanged() {
            updatePhotosButton();
          }
        });
    attachPhotoRecyclerView.setOnItemClickListener(
        new RecyclerListView.OnItemClickListener() {
          @SuppressWarnings("unchecked")
          @Override
          public void onItemClick(View view, int position) {
            if (baseFragment == null || baseFragment.getParentActivity() == null) {
              return;
            }
            ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos;
            if (position < 0 || position >= arrayList.size()) {
              return;
            }
            PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
            PhotoViewer.getInstance()
                .openPhotoForSelect(arrayList, position, 0, ChatAttachView.this, baseFragment);
            AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
          }
        });

    views[9] = progressView = new EmptyTextProgressView(context);
    if (Build.VERSION.SDK_INT >= 23
        && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
      progressView.setText(
          LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
      progressView.setTextSize(16);
    } else {
      progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
      progressView.setTextSize(20);
    }
    addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoRecyclerView.setEmptyView(progressView);

    views[10] = lineView = new View(getContext());
    lineView.setBackgroundColor(0xffd2d2d2);
    addView(
        lineView,
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT));
    CharSequence[] items =
        new CharSequence[] {
          LocaleController.getString("ChatCamera", R.string.ChatCamera),
          LocaleController.getString("ChatGallery", R.string.ChatGallery),
          LocaleController.getString("ChatVideo", R.string.ChatVideo),
          LocaleController.getString("AttachAudio", R.string.AttachAudio),
          LocaleController.getString("ChatDocument", R.string.ChatDocument),
          LocaleController.getString("AttachContact", R.string.AttachContact),
          LocaleController.getString("ChatLocation", R.string.ChatLocation),
          ""
        };
    int itemIcons[] =
        new int[] {
          R.drawable.attach_camera_states,
          R.drawable.attach_gallery_states,
          R.drawable.attach_video_states,
          R.drawable.attach_audio_states,
          R.drawable.attach_file_states,
          R.drawable.attach_contact_states,
          R.drawable.attach_location_states,
          R.drawable.attach_hide_states,
        };
    for (int a = 0; a < 8; a++) {
      AttachButton attachButton = new AttachButton(context);
      attachButton.setTextAndIcon(items[a], itemIcons[a]);
      addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP));
      attachButton.setTag(a);
      views[a] = attachButton;
      if (a == 7) {
        sendPhotosButton = attachButton;
        sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
      }
      attachButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (delegate != null) {
                delegate.didPressedButton((Integer) v.getTag());
              }
            }
          });
    }
    setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    if (loading) {
      progressView.showProgress();
    } else {
      progressView.showTextView();
    }
  }