Java Code Examples for org.telegram.messenger.MediaController#SearchImage

The following examples show how to use org.telegram.messenger.MediaController#SearchImage . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhotoPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate) {
    if (selectedPhotos.isEmpty()) {
        if (selectedAlbum != null) {
            if (index < 0 || index >= selectedAlbum.photos.size()) {
                return;
            }
            MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
            photoEntry.editedInfo = videoEditedInfo;
            addToSelectedPhotos(photoEntry, -1);
        } else {
            if (index < 0 || index >= searchResult.size()) {
                return;
            }
            MediaController.SearchImage searchImage = searchResult.get(index);
            searchImage.editedInfo = videoEditedInfo;
            addToSelectedPhotos(searchImage, -1);
        }
    }
    sendSelectedPhotos(notify, scheduleDate);
}
 
Example 2
Source File: ChatAttachAlertPhotoLayout.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean canScheduleMessages() {
    boolean hasTtl = false;
    for (HashMap.Entry<Object, Object> entry : selectedPhotos.entrySet()) {
        Object object = entry.getValue();
        if (object instanceof MediaController.PhotoEntry) {
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
            if (photoEntry.ttl != 0) {
                hasTtl = true;
                break;
            }
        } else if (object instanceof MediaController.SearchImage) {
            MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
            if (searchImage.ttl != 0) {
                hasTtl = true;
                break;
            }
        }
    }
    if (hasTtl) {
        return false;
    }
    return true;
}
 
Example 3
Source File: PhotoPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int setPhotoUnchecked(Object object) {
    Object key = null;
    if (object instanceof MediaController.PhotoEntry) {
        key = ((MediaController.PhotoEntry) object).imageId;
    } else if (object instanceof MediaController.SearchImage) {
        key = ((MediaController.SearchImage) object).id;
    }
    if (key == null) {
        return -1;
    }
    if (selectedPhotos.containsKey(key)) {
        selectedPhotos.remove(key);
        int position = selectedPhotosOrder.indexOf(key);
        if (position >= 0) {
            selectedPhotosOrder.remove(position);
        }
        if (allowIndices) {
            updateCheckedPhotoIndices();
        }
        return position;
    }
    return -1;
}
 
Example 4
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int setPhotoUnchecked(Object object) {
    Object key = null;
    if (object instanceof MediaController.PhotoEntry) {
        key = ((MediaController.PhotoEntry) object).imageId;
    } else if (object instanceof MediaController.SearchImage) {
        key = ((MediaController.SearchImage) object).id;
    }
    if (key == null) {
        return -1;
    }
    if (selectedPhotos.containsKey(key)) {
        selectedPhotos.remove(key);
        int position = selectedPhotosOrder.indexOf(key);
        if (position >= 0) {
            selectedPhotosOrder.remove(position);
        }
        if (allowIndices) {
            updateCheckedPhotoIndices();
        }
        return position;
    }
    return -1;
}
 
Example 5
Source File: PhotoPickerActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate) {
    if (selectedPhotos.isEmpty()) {
        if (selectedAlbum != null) {
            if (index < 0 || index >= selectedAlbum.photos.size()) {
                return;
            }
            MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
            photoEntry.editedInfo = videoEditedInfo;
            addToSelectedPhotos(photoEntry, -1);
        } else {
            if (index < 0 || index >= searchResult.size()) {
                return;
            }
            MediaController.SearchImage searchImage = searchResult.get(index);
            searchImage.editedInfo = videoEditedInfo;
            addToSelectedPhotos(searchImage, -1);
        }
    }
    sendSelectedPhotos(notify, scheduleDate);
}
 
Example 6
Source File: PhotoPickerPhotoCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setImage(MediaController.SearchImage searchImage) {
    Drawable thumb = getResources().getDrawable(R.drawable.nophotos);
    if (searchImage.thumbPhotoSize != null) {
        photoImage.setImage(searchImage.thumbPhotoSize.location, null, thumb);
    } else if (searchImage.photoSize != null) {
        photoImage.setImage(searchImage.photoSize.location, "80_80", thumb);
    } else if (searchImage.thumbPath != null) {
        photoImage.setImage(searchImage.thumbPath, null, thumb);
    } else if (searchImage.thumbUrl != null && searchImage.thumbUrl.length() > 0) {
        photoImage.setImage(searchImage.thumbUrl, null, thumb);
    } else if (searchImage.document != null && searchImage.document.thumb != null) {
        photoImage.setImage(searchImage.document.thumb.location, null, thumb);
    } else {
        photoImage.setImageDrawable(thumb);
    }
}
 
Example 7
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
    int count = listView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view.getTag() == null) {
            continue;
        }
        PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
        int num = (Integer) view.getTag();
        if (selectedAlbum != null) {
            if (num < 0 || num >= selectedAlbum.photos.size()) {
                continue;
            }
        } else {
            ArrayList<MediaController.SearchImage> array;
            if (searchResult.isEmpty() && lastSearchString == null) {
                array = recentImages;
            } else {
                array = searchResult;
            }
            if (num < 0 || num >= array.size()) {
                continue;
            }
        }
        if (num == index) {
            cell.showCheck(true);
            break;
        }
    }
}
 
Example 8
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private PhotoPickerPhotoCell getCellForIndex(int index) {
    int count = listView.getChildCount();

    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view instanceof PhotoPickerPhotoCell) {
            PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
            int num = (Integer) cell.photoImage.getTag();
            if (selectedAlbum != null) {
                if (num < 0 || num >= selectedAlbum.photos.size()) {
                    continue;
                }
            } else {
                ArrayList<MediaController.SearchImage> array;
                if (searchResult.isEmpty() && lastSearchString == null) {
                    array = recentImages;
                } else {
                    array = searchResult;
                }
                if (num < 0 || num >= array.size()) {
                    continue;
                }
            }
            if (num == index) {
                return cell;
            }
        }
    }
    return null;
}
 
Example 9
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public PhotoPickerActivity(int type, MediaController.AlbumEntry selectedAlbum, HashMap<Object, Object> selectedPhotos, ArrayList<Object> selectedPhotosOrder, ArrayList<MediaController.SearchImage> recentImages, boolean onlyOnePhoto, boolean allowCaption, ChatActivity chatActivity) {
    super();
    this.selectedAlbum = selectedAlbum;
    this.selectedPhotos = selectedPhotos;
    this.selectedPhotosOrder = selectedPhotosOrder;
    this.type = type;
    this.recentImages = recentImages;
    this.singlePhoto = onlyOnePhoto;
    this.chatActivity = chatActivity;
    this.allowCaption = allowCaption;
}
 
Example 10
Source File: PhotoAlbumPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void applyCaption() {
    if (commentTextView.length() <= 0) {
        return;
    }
    int imageId = (Integer) selectedPhotosOrder.get(0);
    Object entry = selectedPhotos.get(imageId);
    if (entry instanceof MediaController.PhotoEntry) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry;
        photoEntry.caption = commentTextView.getText().toString();
    } else if (entry instanceof MediaController.SearchImage) {
        MediaController.SearchImage searchImage = (MediaController.SearchImage) entry;
        searchImage.caption = commentTextView.getText().toString();
    }
}
 
Example 11
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
    int count = listView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view.getTag() == null) {
            continue;
        }
        PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
        int num = (Integer) view.getTag();
        if (selectedAlbum != null) {
            if (num < 0 || num >= selectedAlbum.photos.size()) {
                continue;
            }
        } else {
            ArrayList<MediaController.SearchImage> array;
            if (searchResult.isEmpty() && lastSearchString == null) {
                array = recentImages;
            } else {
                array = searchResult;
            }
            if (num < 0 || num >= array.size()) {
                continue;
            }
        }
        if (num == index) {
            cell.showCheck(true);
            break;
        }
    }
}
 
Example 12
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updatePhotoAtIndex(int index) {
    PhotoPickerPhotoCell cell = getCellForIndex(index);
    if (cell != null) {
        if (selectedAlbum != null) {
            cell.photoImage.setOrientation(0, true);
            MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
            if (photoEntry.thumbPath != null) {
                cell.photoImage.setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
            } else if (photoEntry.path != null) {
                cell.photoImage.setOrientation(photoEntry.orientation, true);
                if (photoEntry.isVideo) {
                    cell.photoImage.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
                } else {
                    cell.photoImage.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
                }
            } else {
                cell.photoImage.setImageResource(R.drawable.nophotos);
            }
        } else {
            ArrayList<MediaController.SearchImage> array;
            if (searchResult.isEmpty() && lastSearchString == null) {
                array = recentImages;
            } else {
                array = searchResult;
            }
            cell.setImage(array.get(index));
        }
    }
}
 
Example 13
Source File: PhotoAlbumPickerActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void applyCaption() {
    if (commentTextView.length() <= 0) {
        return;
    }
    int imageId = (Integer) selectedPhotosOrder.get(0);
    Object entry = selectedPhotos.get(imageId);
    if (entry instanceof MediaController.PhotoEntry) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry;
        photoEntry.caption = commentTextView.getText().toString();
    } else if (entry instanceof MediaController.SearchImage) {
        MediaController.SearchImage searchImage = (MediaController.SearchImage) entry;
        searchImage.caption = commentTextView.getText().toString();
    }
}
 
Example 14
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private PhotoPickerPhotoCell getCellForIndex(int index) {
    int count = listView.getChildCount();

    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view instanceof PhotoPickerPhotoCell) {
            PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
            int num = (Integer) cell.photoImage.getTag();
            if (selectedAlbum != null) {
                if (num < 0 || num >= selectedAlbum.photos.size()) {
                    continue;
                }
            } else {
                ArrayList<MediaController.SearchImage> array;
                if (searchResult.isEmpty() && lastSearchString == null) {
                    array = recentImages;
                } else {
                    array = searchResult;
                }
                if (num < 0 || num >= array.size()) {
                    continue;
                }
            }
            if (num == index) {
                return cell;
            }
        }
    }
    return null;
}
 
Example 15
Source File: PhotoPickerActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private int addToSelectedPhotos(Object object, int index) {
    Object key = null;
    if (object instanceof MediaController.PhotoEntry) {
        key = ((MediaController.PhotoEntry) object).imageId;
    } else if (object instanceof MediaController.SearchImage) {
        key = ((MediaController.SearchImage) object).id;
    }
    if (key == null) {
        return -1;
    }
    if (selectedPhotos.containsKey(key)) {
        selectedPhotos.remove(key);
        int position = selectedPhotosOrder.indexOf(key);
        if (position >= 0) {
            selectedPhotosOrder.remove(position);
        }
        if (allowIndices) {
            updateCheckedPhotoIndices();
        }
        if (index >= 0) {
            if (object instanceof MediaController.PhotoEntry) {
                ((MediaController.PhotoEntry) object).reset();
            } else if (object instanceof MediaController.SearchImage) {
                ((MediaController.SearchImage) object).reset();
            }
            provider.updatePhotoAtIndex(index);
        }
        return position;
    } else {
        selectedPhotos.put(key, object);
        selectedPhotosOrder.add(key);
        return -1;
    }
}
 
Example 16
Source File: PhotoPickerActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void applyCaption() {
    if (commentTextView == null || commentTextView.length() <= 0) {
        return;
    }
    Object imageId = selectedPhotosOrder.get(0);
    Object entry = selectedPhotos.get(imageId);
    if (entry instanceof MediaController.PhotoEntry) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry;
        photoEntry.caption = commentTextView.getText().toString();
    } else if (entry instanceof MediaController.SearchImage) {
        MediaController.SearchImage searchImage = (MediaController.SearchImage) entry;
        searchImage.caption = commentTextView.getText().toString();
    }
}
 
Example 17
Source File: PhotoPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void applyCaption() {
    if (commentTextView == null || commentTextView.length() <= 0) {
        return;
    }
    Object imageId = selectedPhotosOrder.get(0);
    Object entry = selectedPhotos.get(imageId);
    if (entry instanceof MediaController.PhotoEntry) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry;
        photoEntry.caption = commentTextView.getText().toString();
    } else if (entry instanceof MediaController.SearchImage) {
        MediaController.SearchImage searchImage = (MediaController.SearchImage) entry;
        searchImage.caption = commentTextView.getText().toString();
    }
}
 
Example 18
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isPhotoChecked(int index) {
    if (selectedAlbum != null) {
        return !(index < 0 || index >= selectedAlbum.photos.size()) && selectedPhotos.containsKey(selectedAlbum.photos.get(index).imageId);
    } else {
        ArrayList<MediaController.SearchImage> array;
        if (searchResult.isEmpty() && lastSearchString == null) {
            array = recentImages;
        } else {
            array = searchResult;
        }
        return !(index < 0 || index >= array.size()) && selectedPhotos.containsKey(array.get(index).id);
    }
}
 
Example 19
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updatePhotoAtIndex(int index) {
    PhotoPickerPhotoCell cell = getCellForIndex(index);
    if (cell != null) {
        if (selectedAlbum != null) {
            cell.photoImage.setOrientation(0, true);
            MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
            if (photoEntry.thumbPath != null) {
                cell.photoImage.setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
            } else if (photoEntry.path != null) {
                cell.photoImage.setOrientation(photoEntry.orientation, true);
                if (photoEntry.isVideo) {
                    cell.photoImage.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
                } else {
                    cell.photoImage.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
                }
            } else {
                cell.photoImage.setImageResource(R.drawable.nophotos);
            }
        } else {
            ArrayList<MediaController.SearchImage> array;
            if (searchResult.isEmpty() && lastSearchString == null) {
                array = recentImages;
            } else {
                array = searchResult;
            }
            cell.setImage(array.get(index));
        }
    }
}
 
Example 20
Source File: PhotoAlbumPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void sendSelectedPhotos(HashMap<Object, Object> photos, ArrayList<Object> order, boolean notify, int scheduleDate) {
    if (photos.isEmpty() || delegate == null || sendPressed) {
        return;
    }
    sendPressed = true;

    ArrayList<SendMessagesHelper.SendingMediaInfo> media = new ArrayList<>();
    for (int a = 0; a < order.size(); a++) {
        Object object = photos.get(order.get(a));
        SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
        media.add(info);
        if (object instanceof MediaController.PhotoEntry) {
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
            if (photoEntry.imagePath != null) {
                info.path = photoEntry.imagePath;
            } else {
                info.path = photoEntry.path;
            }
            info.thumbPath = photoEntry.thumbPath;
            info.videoEditedInfo = photoEntry.editedInfo;
            info.isVideo = photoEntry.isVideo;
            info.caption = photoEntry.caption != null ? photoEntry.caption.toString() : null;
            info.entities = photoEntry.entities;
            info.masks = photoEntry.stickers;
            info.ttl = photoEntry.ttl;
        } else if (object instanceof MediaController.SearchImage) {
            MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
            if (searchImage.imagePath != null) {
                info.path = searchImage.imagePath;
            } else {
                info.searchImage = searchImage;
            }
            info.thumbPath = searchImage.thumbPath;
            info.videoEditedInfo = searchImage.editedInfo;
            info.caption = searchImage.caption != null ? searchImage.caption.toString() : null;
            info.entities = searchImage.entities;
            info.masks = searchImage.stickers;
            info.ttl = searchImage.ttl;
            if (searchImage.inlineResult != null && searchImage.type == 1) {
                info.inlineResult = searchImage.inlineResult;
                info.params = searchImage.params;
            }

            searchImage.date = (int) (System.currentTimeMillis() / 1000);
        }
    }

    delegate.didSelectPhotos(media, notify, scheduleDate);
}