org.telegram.messenger.DownloadController Java Examples

The following examples show how to use org.telegram.messenger.DownloadController. 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: SharedAudioCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public SharedAudioCell(Context context) {
    super(context);
    setFocusable(true);

    radialProgress = new RadialProgress2(this);
    radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    setWillNotDraw(false);

    checkBox = new CheckBox2(context, 21);
    checkBox.setVisibility(INVISIBLE);
    checkBox.setColor(null, Theme.key_windowBackgroundWhite, Theme.key_checkboxCheck);
    checkBox.setDrawUnchecked(false);
    checkBox.setDrawBackgroundAsArc(3);
    addView(checkBox, LayoutHelper.createFrame(24, 24, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 38, 32, LocaleController.isRTL ? 39 : 0, 0));
}
 
Example #2
Source File: ContextLinkCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public ContextLinkCell(Context context, boolean needsCheckBox) {
    super(context);

    linkImageView = new ImageReceiver(this);
    linkImageView.setLayerNum(1);
    linkImageView.setUseSharedAnimationQueue(true);
    letterDrawable = new LetterDrawable();
    radialProgress = new RadialProgress2(this);
    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    setFocusable(true);

    if (needsCheckBox) {
        backgroundPaint = new Paint();
        backgroundPaint.setColor(Theme.getColor(Theme.key_sharedMedia_photoPlaceholder));

        checkBox = new CheckBox2(context, 21);
        checkBox.setVisibility(INVISIBLE);
        checkBox.setColor(null, Theme.key_sharedMedia_photoPlaceholder, Theme.key_checkboxCheck);
        checkBox.setDrawUnchecked(false);
        checkBox.setDrawBackgroundAsArc(1);
        addView(checkBox, LayoutHelper.createFrame(24, 24, Gravity.RIGHT | Gravity.TOP, 0, 1, 1, 0));
    }
    setWillNotDraw(false);
}
 
Example #3
Source File: SharedAudioCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public SharedAudioCell(Context context) {
    super(context);
    setFocusable(true);

    radialProgress = new RadialProgress2(this);
    radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    setWillNotDraw(false);

    checkBox = new CheckBox2(context, 21);
    checkBox.setVisibility(INVISIBLE);
    checkBox.setColor(null, Theme.key_windowBackgroundWhite, Theme.key_checkboxCheck);
    checkBox.setDrawUnchecked(false);
    checkBox.setDrawBackgroundAsArc(3);
    addView(checkBox, LayoutHelper.createFrame(24, 24, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 38, 32, LocaleController.isRTL ? 39 : 0, 0));
}
 
Example #4
Source File: DataAutoDownloadActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void updatePresetChoseView(SlideChooseView slideChooseView) {
    String[] presetsStr = new String[presets.size()];
    for (int i = 0; i < presets.size(); i++) {
        DownloadController.Preset preset = presets.get(i);
        if (preset == lowPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadLow", R.string.AutoDownloadLow);
        } else if (preset == mediumPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadMedium", R.string.AutoDownloadMedium);
        } else if (preset == highPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadHigh", R.string.AutoDownloadHigh);
        } else {
            presetsStr[i] = LocaleController.getString("AutoDownloadCustom", R.string.AutoDownloadCustom);
        }

    }
    slideChooseView.setOptions(selectedPreset, presetsStr);
}
 
Example #5
Source File: VoIPHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static int getDataSavingDefault() {
	boolean low = DownloadController.getInstance(0).lowPreset.lessCallData,
			medium = DownloadController.getInstance(0).mediumPreset.lessCallData,
			high = DownloadController.getInstance(0).highPreset.lessCallData;
	if (!low && !medium && !high) {
		return TgVoip.DATA_SAVING_NEVER;
	} else if (low && !medium && !high) {
		return TgVoip.DATA_SAVING_ROAMING;
	} else if (low && medium && !high) {
		return TgVoip.DATA_SAVING_MOBILE;
	} else if (low && medium && high) {
		return TgVoip.DATA_SAVING_ALWAYS;
	}
	if (BuildVars.LOGS_ENABLED)
		FileLog.w("Invalid call data saving preset configuration: " + low + "/" + medium + "/" + high);
	return TgVoip.DATA_SAVING_NEVER;
}
 
Example #6
Source File: VoIPHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static int getDataSavingDefault() {
	boolean low = DownloadController.getInstance(0).lowPreset.lessCallData,
			medium = DownloadController.getInstance(0).mediumPreset.lessCallData,
			high = DownloadController.getInstance(0).highPreset.lessCallData;
	if (!low && !medium && !high) {
		return TgVoip.DATA_SAVING_NEVER;
	} else if (low && !medium && !high) {
		return TgVoip.DATA_SAVING_ROAMING;
	} else if (low && medium && !high) {
		return TgVoip.DATA_SAVING_MOBILE;
	} else if (low && medium && high) {
		return TgVoip.DATA_SAVING_ALWAYS;
	}
	if (BuildVars.LOGS_ENABLED)
		FileLog.w("Invalid call data saving preset configuration: " + low + "/" + medium + "/" + high);
	return TgVoip.DATA_SAVING_NEVER;
}
 
Example #7
Source File: DataAutoDownloadActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void updatePresetChoseView(SlideChooseView slideChooseView) {
    String[] presetsStr = new String[presets.size()];
    for (int i = 0; i < presets.size(); i++) {
        DownloadController.Preset preset = presets.get(i);
        if (preset == lowPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadLow", R.string.AutoDownloadLow);
        } else if (preset == mediumPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadMedium", R.string.AutoDownloadMedium);
        } else if (preset == highPreset) {
            presetsStr[i] = LocaleController.getString("AutoDownloadHigh", R.string.AutoDownloadHigh);
        } else {
            presetsStr[i] = LocaleController.getString("AutoDownloadCustom", R.string.AutoDownloadCustom);
        }

    }
    slideChooseView.setOptions(selectedPreset, presetsStr);
}
 
Example #8
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void checkFileExist() {
    if (parentMessageObject != null && parentMessageObject.messageOwner.media != null) {
        String fileName = null;
        File cacheFile;
        if (TextUtils.isEmpty(parentMessageObject.messageOwner.attachPath) || !(new File(parentMessageObject.messageOwner.attachPath).exists())) {
            cacheFile = FileLoader.getPathToMessage(parentMessageObject.messageOwner);
            if (!cacheFile.exists()) {
                fileName = FileLoader.getAttachFileName(parentMessageObject.getDocument());
            }
        }
        loaded = false;
        if (fileName == null) {
            progressVisible = false;
            loading = false;
            loaded = true;
            DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
        } else {
            DownloadController.getInstance(parentMessageObject.currentAccount).addLoadingFileObserver(fileName, this);
            loading = FileLoader.getInstance(parentMessageObject.currentAccount).isLoadingFile(fileName);
            if (loading) {
                progressVisible = true;
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                setProgress(progress, false);
            } else {
                progressVisible = false;
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressVisible = false;
        setProgress(0, false);
        DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
    }
    parentView.invalidate();
}
 
Example #9
Source File: SharedPhotoVideoCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
    if (messageObject.isVideo()) {
        videoInfoContainer.setVisibility(VISIBLE);
        videoTextView.setText(AndroidUtilities.formatShortDuration(messageObject.getDuration()));
        TLRPC.Document document = messageObject.getDocument();
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 50);
        TLRPC.PhotoSize qualityThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        if (thumb == qualityThumb) {
            qualityThumb = null;
        }
        if (thumb != null) {
            imageView.setImage(ImageLocation.getForDocument(qualityThumb, document), "100_100", ImageLocation.getForDocument(thumb, document), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        } else {
            imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
        videoInfoContainer.setVisibility(INVISIBLE);
        TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 320);
        TLRPC.PhotoSize currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 50);
        if (messageObject.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject)) {
            if (currentPhotoObject == currentPhotoObjectThumb) {
                currentPhotoObjectThumb = null;
            }
            imageView.getImageReceiver().setImage(ImageLocation.getForObject(currentPhotoObject, messageObject.photoThumbsObject), "100_100", ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", currentPhotoObject.size, null, messageObject, messageObject.shouldEncryptPhotoOrVideo() ? 2 : 1);
        } else {
            imageView.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        }
    } else {
        videoInfoContainer.setVisibility(INVISIBLE);
        imageView.setImageResource(R.drawable.photo_placeholder_in);
    }
}
 
Example #10
Source File: SharedDocumentCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        loaded = false;
        if (message.attachPathExists || message.mediaExists) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            String fileName = FileLoader.getAttachFileName(message.getDocument());
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, message, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}
 
Example #11
Source File: PatternCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public PatternCell(Context context, int maxSize, PatternCellDelegate patternCellDelegate) {
    super(context);
    setRoundRadius(AndroidUtilities.dp(6));
    maxWallpaperSize = maxSize;
    delegate = patternCellDelegate;

    radialProgress = new RadialProgress2(this);
    radialProgress.setProgressRect(AndroidUtilities.dp(30), AndroidUtilities.dp(30), AndroidUtilities.dp(70), AndroidUtilities.dp(70));

    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
}
 
Example #12
Source File: DataSettingsActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public boolean isRowEnabled(int position) {
    if (position == resetDownloadRow) {
        DownloadController controller = DownloadController.getInstance(currentAccount);
        return !controller.lowPreset.equals(controller.getCurrentRoamingPreset()) || controller.lowPreset.isEnabled() != controller.roamingPreset.enabled ||
                !controller.mediumPreset.equals(controller.getCurrentMobilePreset()) || controller.mediumPreset.isEnabled() != controller.mobilePreset.enabled ||
                !controller.highPreset.equals(controller.getCurrentWiFiPreset()) || controller.highPreset.isEnabled() != controller.wifiPreset.enabled;
    }
    return position == mobileRow || position == roamingRow || position == wifiRow || position == storageUsageRow || position == useLessDataForCallsRow || position == dataUsageRow || position == proxyRow ||
            position == enableCacheStreamRow || position == enableStreamRow || position == enableAllStreamRow || position == enableMkvRow || position == quickRepliesRow || position == autoplayVideoRow || position == autoplayGifsRow;
}
 
Example #13
Source File: DataAutoDownloadActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public DataAutoDownloadActivity(int type) {
    super();
    currentType = type;

    lowPreset = DownloadController.getInstance(currentAccount).lowPreset;
    mediumPreset = DownloadController.getInstance(currentAccount).mediumPreset;
    highPreset = DownloadController.getInstance(currentAccount).highPreset;

    if (currentType == 0) {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentMobilePreset;
        typePreset = DownloadController.getInstance(currentAccount).mobilePreset;
        defaultPreset = mediumPreset;
        key = "mobilePreset";
        key2 = "currentMobilePreset";
    } else if (currentType == 1) {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentWifiPreset;
        typePreset = DownloadController.getInstance(currentAccount).wifiPreset;
        defaultPreset = highPreset;
        key = "wifiPreset";
        key2 = "currentWifiPreset";
    } else {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentRoamingPreset;
        typePreset = DownloadController.getInstance(currentAccount).roamingPreset;
        defaultPreset = lowPreset;
        key = "roamingPreset";
        key2 = "currentRoamingPreset";
    }
}
 
Example #14
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public OtherDocumentPlaceholderDrawable(Context context, View view, MessageObject messageObject) {
    docPaint.setTextSize(AndroidUtilities.dp(14));
    namePaint.setTextSize(AndroidUtilities.dp(19));
    sizePaint.setTextSize(AndroidUtilities.dp(15));
    buttonPaint.setTextSize(AndroidUtilities.dp(15));
    percentPaint.setTextSize(AndroidUtilities.dp(15));
    openPaint.setTextSize(AndroidUtilities.dp(15));
    progressPaint.setStrokeWidth(AndroidUtilities.dp(2));

    parentView = view;
    parentMessageObject = messageObject;
    TAG = DownloadController.getInstance(messageObject.currentAccount).generateObserverTag();

    TLRPC.Document document = messageObject.getDocument();
    if (document != null) {
        fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (TextUtils.isEmpty(fileName)) {
            fileName = "name";
        }
        int idx;
        ext = (idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toUpperCase();
        int w = (int) Math.ceil(docPaint.measureText(ext));
        if (w > AndroidUtilities.dp(40)) {
            ext = TextUtils.ellipsize(ext, docPaint, AndroidUtilities.dp(40), TextUtils.TruncateAt.END).toString();
        }
        thumbDrawable = context.getResources().getDrawable(AndroidUtilities.getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type, true)).mutate();
        fileSize = AndroidUtilities.formatFileSize(document.size);
        w = (int) Math.ceil(namePaint.measureText(fileName));
        if (w > AndroidUtilities.dp(320)) {
            fileName = TextUtils.ellipsize(fileName, namePaint, AndroidUtilities.dp(320), TextUtils.TruncateAt.END).toString();
        }
    }
    checkFileExist();
}
 
Example #15
Source File: PopupAudioView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public PopupAudioView(Context context) {
    super(context);
    timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
    timePaint.setTextSize(AndroidUtilities.dp(16));

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();

    seekBar = new SeekBar(this);
    seekBar.setDelegate(this);
    progressView = new ProgressView();
}
 
Example #16
Source File: ContextLinkCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (drawLinkImageView) {
        linkImageView.onDetachedFromWindow();
    }
    radialProgress.onDetachedFromWindow();
    DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
}
 
Example #17
Source File: DataAutoDownloadActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    if (wereAnyChanges) {
        DownloadController.getInstance(currentAccount).savePresetToServer(currentType);
        wereAnyChanges = false;
    }
}
 
Example #18
Source File: SharedPhotoVideoCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
    if (messageObject.isVideo()) {
        videoInfoContainer.setVisibility(VISIBLE);
        videoTextView.setText(AndroidUtilities.formatShortDuration(messageObject.getDuration()));
        TLRPC.Document document = messageObject.getDocument();
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 50);
        TLRPC.PhotoSize qualityThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        if (thumb == qualityThumb) {
            qualityThumb = null;
        }
        if (thumb != null) {
            imageView.setImage(ImageLocation.getForDocument(qualityThumb, document), "100_100", ImageLocation.getForDocument(thumb, document), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        } else {
            imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
        videoInfoContainer.setVisibility(INVISIBLE);
        TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 320);
        TLRPC.PhotoSize currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 50);
        if (messageObject.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject)) {
            if (currentPhotoObject == currentPhotoObjectThumb) {
                currentPhotoObjectThumb = null;
            }
            imageView.getImageReceiver().setImage(ImageLocation.getForObject(currentPhotoObject, messageObject.photoThumbsObject), "100_100", ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", currentPhotoObject.size, null, messageObject, messageObject.shouldEncryptPhotoOrVideo() ? 2 : 1);
        } else {
            imageView.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, messageObject.photoThumbsObject), "b", ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, null, 0, messageObject);
        }
    } else {
        videoInfoContainer.setVisibility(INVISIBLE);
        imageView.setImageResource(R.drawable.photo_placeholder_in);
    }
}
 
Example #19
Source File: ThemePreviewActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad);
    if (screenType == SCREEN_TYPE_ACCENT_COLOR) {
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
    }
    if (screenType != SCREEN_TYPE_PREVIEW || accent != null) {
        if (SharedConfig.getDevicePerfomanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW) {
            int w = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
            int h = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
            imageFilter = (int) (w / AndroidUtilities.density) + "_" + (int) (h / AndroidUtilities.density) + "_f";
        } else {
            imageFilter = (int) (1080 / AndroidUtilities.density) + "_" + (int) (1920 / AndroidUtilities.density) + "_f";
        }
        maxWallpaperSize = Math.min(1920, Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y));

        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersNeedReload);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoad);
        TAG = DownloadController.getInstance(currentAccount).generateObserverTag();

        if (patterns == null) {
            patterns = new ArrayList<>();
            MessagesStorage.getInstance(currentAccount).getWallpapers();
        }
    } else {
        isMotion = Theme.isWallpaperMotion();
    }

    return super.onFragmentCreate();
}
 
Example #20
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public OtherDocumentPlaceholderDrawable(Context context, View view, MessageObject messageObject) {
    docPaint.setTextSize(AndroidUtilities.dp(14));
    namePaint.setTextSize(AndroidUtilities.dp(19));
    sizePaint.setTextSize(AndroidUtilities.dp(15));
    buttonPaint.setTextSize(AndroidUtilities.dp(15));
    percentPaint.setTextSize(AndroidUtilities.dp(15));
    openPaint.setTextSize(AndroidUtilities.dp(15));
    progressPaint.setStrokeWidth(AndroidUtilities.dp(2));

    parentView = view;
    parentMessageObject = messageObject;
    TAG = DownloadController.getInstance(messageObject.currentAccount).generateObserverTag();

    TLRPC.Document document = messageObject.getDocument();
    if (document != null) {
        fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (TextUtils.isEmpty(fileName)) {
            fileName = "name";
        }
        int idx;
        ext = (idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toUpperCase();
        int w = (int) Math.ceil(docPaint.measureText(ext));
        if (w > AndroidUtilities.dp(40)) {
            ext = TextUtils.ellipsize(ext, docPaint, AndroidUtilities.dp(40), TextUtils.TruncateAt.END).toString();
        }
        thumbDrawable = context.getResources().getDrawable(AndroidUtilities.getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type, true)).mutate();
        fileSize = AndroidUtilities.formatFileSize(document.size);
        w = (int) Math.ceil(namePaint.measureText(fileName));
        if (w > AndroidUtilities.dp(320)) {
            fileName = TextUtils.ellipsize(fileName, namePaint, AndroidUtilities.dp(320), TextUtils.TruncateAt.END).toString();
        }
    }
    checkFileExist();
}
 
Example #21
Source File: AudioPlayerCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public AudioPlayerCell(Context context) {
    super(context);

    radialProgress = new RadialProgress2(this);
    radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);
    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    setFocusable(true);
}
 
Example #22
Source File: SharedDocumentCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        loaded = false;
        if (message.attachPathExists || message.mediaExists) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            String fileName = FileLoader.getAttachFileName(message.getDocument());
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, message, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}
 
Example #23
Source File: PatternCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public PatternCell(Context context, int maxSize, PatternCellDelegate patternCellDelegate) {
    super(context);
    setRoundRadius(AndroidUtilities.dp(6));
    maxWallpaperSize = maxSize;
    delegate = patternCellDelegate;

    radialProgress = new RadialProgress2(this);
    radialProgress.setProgressRect(AndroidUtilities.dp(30), AndroidUtilities.dp(30), AndroidUtilities.dp(70), AndroidUtilities.dp(70));

    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
}
 
Example #24
Source File: ThemePreviewActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad);
    if (screenType == SCREEN_TYPE_ACCENT_COLOR) {
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
    }
    if (screenType != SCREEN_TYPE_PREVIEW || accent != null) {
        if (SharedConfig.getDevicePerfomanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW) {
            int w = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
            int h = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
            imageFilter = (int) (w / AndroidUtilities.density) + "_" + (int) (h / AndroidUtilities.density) + "_f";
        } else {
            imageFilter = (int) (1080 / AndroidUtilities.density) + "_" + (int) (1920 / AndroidUtilities.density) + "_f";
        }
        maxWallpaperSize = Math.min(1920, Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y));

        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersNeedReload);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoad);
        TAG = DownloadController.getInstance(currentAccount).generateObserverTag();

        if (patterns == null) {
            patterns = new ArrayList<>();
            MessagesStorage.getInstance(currentAccount).getWallpapers();
        }
    } else {
        isMotion = Theme.isWallpaperMotion();
    }

    return super.onFragmentCreate();
}
 
Example #25
Source File: DataAutoDownloadActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public DataAutoDownloadActivity(int type) {
    super();
    currentType = type;

    lowPreset = DownloadController.getInstance(currentAccount).lowPreset;
    mediumPreset = DownloadController.getInstance(currentAccount).mediumPreset;
    highPreset = DownloadController.getInstance(currentAccount).highPreset;

    if (currentType == 0) {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentMobilePreset;
        typePreset = DownloadController.getInstance(currentAccount).mobilePreset;
        defaultPreset = mediumPreset;
        key = "mobilePreset";
        key2 = "currentMobilePreset";
    } else if (currentType == 1) {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentWifiPreset;
        typePreset = DownloadController.getInstance(currentAccount).wifiPreset;
        defaultPreset = highPreset;
        key = "wifiPreset";
        key2 = "currentWifiPreset";
    } else {
        currentPresetNum = DownloadController.getInstance(currentAccount).currentRoamingPreset;
        typePreset = DownloadController.getInstance(currentAccount).roamingPreset;
        defaultPreset = lowPreset;
        key = "roamingPreset";
        key2 = "currentRoamingPreset";
    }
}
 
Example #26
Source File: PopupAudioView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void updateButtonState() {
    String fileName = currentMessageObject.getFileName();
    File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
    if (cacheFile.exists()) {
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        boolean playing = MediaController.getInstance().isPlayingMessage(currentMessageObject);
        if (!playing || playing && MediaController.getInstance().isMessagePaused()) {
            buttonState = 0;
        } else {
            buttonState = 1;
        }
        progressView.setProgress(0);
    } else {
        DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, this);
        if (!FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
            buttonState = 2;
            progressView.setProgress(0);
        } else {
            buttonState = 3;
            Float progress = ImageLoader.getInstance().getFileProgress(fileName);
            if (progress != null) {
                progressView.setProgress(progress);
            } else {
                progressView.setProgress(0);
            }
        }
    }
    updateProgress();
}
 
Example #27
Source File: ContextLinkCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (drawLinkImageView) {
        linkImageView.onDetachedFromWindow();
    }
    radialProgress.onDetachedFromWindow();
    DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
}
 
Example #28
Source File: AudioPlayerCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public AudioPlayerCell(Context context) {
    super(context);

    radialProgress = new RadialProgress2(this);
    radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);
    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
    setFocusable(true);
}
 
Example #29
Source File: ContextLinkCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (drawLinkImageView) {
        linkImageView.onDetachedFromWindow();
    }
    DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
}
 
Example #30
Source File: ContextLinkCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public ContextLinkCell(Context context) {
    super(context);

    linkImageView = new ImageReceiver(this);
    letterDrawable = new LetterDrawable();
    radialProgress = new RadialProgress(this);
    TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
}