Java Code Examples for org.telegram.tgnet.TLRPC#TL_document
The following examples show how to use
org.telegram.tgnet.TLRPC#TL_document .
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: BlockingUpdateView.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void show(int account, TLRPC.TL_help_appUpdate update) { pressCount = 0; appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } if (getVisibility() != VISIBLE) { setVisibility(VISIBLE); } SpannableStringBuilder builder = new SpannableStringBuilder(update.text); MessageObject.addEntitiesToText(builder, update.entities, false, 0, false, false, false); textView.setText(builder); if (update.document instanceof TLRPC.TL_document) { acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase() + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size))); } else { acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase()); } NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidLoaded); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidFailedLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged); }
Example 2
Source File: BlockingUpdateView.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void show(int account, TLRPC.TL_help_appUpdate update) { pressCount = 0; appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } if (getVisibility() != VISIBLE) { setVisibility(VISIBLE); } SpannableStringBuilder builder = new SpannableStringBuilder(update.text); MessageObject.addEntitiesToText(builder, update.entities, false, 0, false, false, false); textView.setText(builder); if (update.document instanceof TLRPC.TL_document) { acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase() + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size))); } else { acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase()); } NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidLoaded); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidFailedLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged); }
Example 3
Source File: FileStreamLoadOperation.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public long open(DataSpec dataSpec) throws IOException { uri = dataSpec.uri; currentAccount = Utilities.parseInt(uri.getQueryParameter("account")); parentObject = FileLoader.getInstance(currentAccount).getParentObject(Utilities.parseInt(uri.getQueryParameter("rid"))); document = new TLRPC.TL_document(); document.access_hash = Utilities.parseLong(uri.getQueryParameter("hash")); document.id = Utilities.parseLong(uri.getQueryParameter("id")); document.size = Utilities.parseInt(uri.getQueryParameter("size")); document.dc_id = Utilities.parseInt(uri.getQueryParameter("dc")); document.mime_type = uri.getQueryParameter("mime"); document.file_reference = Utilities.hexToBytes(uri.getQueryParameter("reference")); TLRPC.TL_documentAttributeFilename filename = new TLRPC.TL_documentAttributeFilename(); filename.file_name = uri.getQueryParameter("name"); document.attributes.add(filename); if (document.mime_type.startsWith("video")) { document.attributes.add(new TLRPC.TL_documentAttributeVideo()); } else if (document.mime_type.startsWith("audio")) { document.attributes.add(new TLRPC.TL_documentAttributeAudio()); } loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, parentObject, currentOffset = (int) dataSpec.position, false); bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? document.size - dataSpec.position : dataSpec.length; if (bytesRemaining < 0) { throw new EOFException(); } opened = true; transferStarted(dataSpec); if (loadOperation != null) { file = new RandomAccessFile(loadOperation.getCurrentFile(), "r"); file.seek(currentOffset); } return bytesRemaining; }
Example 4
Source File: FileStreamLoadOperation.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public long open(DataSpec dataSpec) throws IOException { uri = dataSpec.uri; this.dataSpec = dataSpec; currentAccount = Utilities.parseInt(uri.getQueryParameter("account")); document = new TLRPC.TL_document(); document.access_hash = Utilities.parseLong(uri.getQueryParameter("hash")); document.id = Utilities.parseLong(uri.getQueryParameter("id")); document.size = Utilities.parseInt(uri.getQueryParameter("size")); document.dc_id = Utilities.parseInt(uri.getQueryParameter("dc")); document.mime_type = uri.getQueryParameter("mime"); TLRPC.TL_documentAttributeFilename filename = new TLRPC.TL_documentAttributeFilename(); filename.file_name = uri.getQueryParameter("name"); document.attributes.add(filename); if (document.mime_type.startsWith("video")) { document.attributes.add(new TLRPC.TL_documentAttributeVideo()); } else if (document.mime_type.startsWith("audio")) { document.attributes.add(new TLRPC.TL_documentAttributeAudio()); } loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, currentOffset = (int) dataSpec.position); bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? document.size - dataSpec.position : dataSpec.length; if (bytesRemaining < 0) { throw new EOFException(); } opened = true; if (listener != null) { listener.onTransferStart(this, dataSpec, false); } file = new RandomAccessFile(loadOperation.getCurrentFile(), "r"); file.seek(currentOffset); return bytesRemaining; }
Example 5
Source File: FileStreamLoadOperation.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public long open(DataSpec dataSpec) throws IOException { uri = dataSpec.uri; currentAccount = Utilities.parseInt(uri.getQueryParameter("account")); parentObject = FileLoader.getInstance(currentAccount).getParentObject(Utilities.parseInt(uri.getQueryParameter("rid"))); document = new TLRPC.TL_document(); document.access_hash = Utilities.parseLong(uri.getQueryParameter("hash")); document.id = Utilities.parseLong(uri.getQueryParameter("id")); document.size = Utilities.parseInt(uri.getQueryParameter("size")); document.dc_id = Utilities.parseInt(uri.getQueryParameter("dc")); document.mime_type = uri.getQueryParameter("mime"); document.file_reference = Utilities.hexToBytes(uri.getQueryParameter("reference")); TLRPC.TL_documentAttributeFilename filename = new TLRPC.TL_documentAttributeFilename(); filename.file_name = uri.getQueryParameter("name"); document.attributes.add(filename); if (document.mime_type.startsWith("video")) { document.attributes.add(new TLRPC.TL_documentAttributeVideo()); } else if (document.mime_type.startsWith("audio")) { document.attributes.add(new TLRPC.TL_documentAttributeAudio()); } loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, parentObject, currentOffset = (int) dataSpec.position, false); bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? document.size - dataSpec.position : dataSpec.length; if (bytesRemaining < 0) { throw new EOFException(); } opened = true; transferStarted(dataSpec); if (loadOperation != null) { file = new RandomAccessFile(loadOperation.getCurrentFile(), "r"); file.seek(currentOffset); } return bytesRemaining; }
Example 6
Source File: MediaController.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void stopRecordingInternal(final int send, boolean notify, int scheduleDate) { if (send != 0) { final TLRPC.TL_document audioToSend = recordingAudio; final File recordingAudioFileToSend = recordingAudioFile; fileEncodingQueue.postRunnable(() -> { stopRecord(); AndroidUtilities.runOnUIThread(() -> { audioToSend.date = ConnectionsManager.getInstance(recordingCurrentAccount).getCurrentTime(); audioToSend.size = (int) recordingAudioFileToSend.length(); TLRPC.TL_documentAttributeAudio attributeAudio = new TLRPC.TL_documentAttributeAudio(); attributeAudio.voice = true; attributeAudio.waveform = getWaveform2(recordSamples, recordSamples.length); if (attributeAudio.waveform != null) { attributeAudio.flags |= 4; } long duration = recordTimeCount; attributeAudio.duration = (int) (recordTimeCount / 1000); audioToSend.attributes.add(attributeAudio); if (duration > 700) { if (send == 1) { SendMessagesHelper.getInstance(recordingCurrentAccount).sendMessage(audioToSend, null, recordingAudioFileToSend.getAbsolutePath(), recordDialogId, recordReplyingMessageObject, null, null, null, null, notify, scheduleDate, 0, null); } NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioDidSent, recordingGuid, send == 2 ? audioToSend : null, send == 2 ? recordingAudioFileToSend.getAbsolutePath() : null); } else { NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioRecordTooShort, recordingGuid, false, (int) duration); recordingAudioFileToSend.delete(); } requestAudioFocus(false); }); }); } else { if (recordingAudioFile != null) { recordingAudioFile.delete(); } requestAudioFocus(false); } try { if (audioRecorder != null) { audioRecorder.release(); audioRecorder = null; } } catch (Exception e) { FileLog.e(e); } recordingAudio = null; recordingAudioFile = null; }
Example 7
Source File: AndroidUtilities.java From Telegram with GNU General Public License v2.0 | 4 votes |
public static void openForView(TLObject media, Activity activity) { if (media == null || activity == null) { return; } String fileName = FileLoader.getAttachFileName(media); File f = FileLoader.getPathToAttach(media, true); if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (media instanceof TLRPC.TL_document) { realMimeType = ((TLRPC.TL_document) media).mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }
Example 8
Source File: FileLoadOperation.java From Telegram with GNU General Public License v2.0 | 4 votes |
public FileLoadOperation(TLRPC.Document documentLocation, Object parent) { try { parentObject = parent; if (documentLocation instanceof TLRPC.TL_documentEncrypted) { location = new TLRPC.TL_inputEncryptedFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; iv = new byte[32]; System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length); key = documentLocation.key; } else if (documentLocation instanceof TLRPC.TL_document) { location = new TLRPC.TL_inputDocumentFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; location.file_reference = documentLocation.file_reference; location.thumb_size = ""; if (location.file_reference == null) { location.file_reference = new byte[0]; } initialDatacenterId = datacenterId = documentLocation.dc_id; allowDisordererFileSave = true; for (int a = 0, N = documentLocation.attributes.size(); a < N; a++) { if (documentLocation.attributes.get(a) instanceof TLRPC.TL_documentAttributeVideo) { supportsPreloading = true; break; } } } ungzip = "application/x-tgsticker".equals(documentLocation.mime_type) || "application/x-tgwallpattern".equals(documentLocation.mime_type); totalBytesCount = documentLocation.size; if (key != null) { int toAdd = 0; if (totalBytesCount % 16 != 0) { bytesCountPadding = 16 - totalBytesCount % 16; totalBytesCount += bytesCountPadding; } } ext = FileLoader.getDocumentFileName(documentLocation); int idx; if (ext == null || (idx = ext.lastIndexOf('.')) == -1) { ext = ""; } else { ext = ext.substring(idx); } if ("audio/ogg".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeAudio; } else if (FileLoader.isVideoMimeType(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeVideo; } else { currentType = ConnectionsManager.FileTypeFile; } if (ext.length() <= 1) { ext = FileLoader.getExtensionByMimeType(documentLocation.mime_type); } } catch (Exception e) { FileLog.e(e); onFail(true, 0); } }
Example 9
Source File: MediaController.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void stopRecordingInternal(final int send, boolean notify, int scheduleDate) { if (send != 0) { final TLRPC.TL_document audioToSend = recordingAudio; final File recordingAudioFileToSend = recordingAudioFile; fileEncodingQueue.postRunnable(() -> { stopRecord(); AndroidUtilities.runOnUIThread(() -> { audioToSend.date = ConnectionsManager.getInstance(recordingCurrentAccount).getCurrentTime(); audioToSend.size = (int) recordingAudioFileToSend.length(); TLRPC.TL_documentAttributeAudio attributeAudio = new TLRPC.TL_documentAttributeAudio(); attributeAudio.voice = true; attributeAudio.waveform = getWaveform2(recordSamples, recordSamples.length); if (attributeAudio.waveform != null) { attributeAudio.flags |= 4; } long duration = recordTimeCount; attributeAudio.duration = (int) (recordTimeCount / 1000); audioToSend.attributes.add(attributeAudio); if (duration > 700) { if (send == 1) { SendMessagesHelper.getInstance(recordingCurrentAccount).sendMessage(audioToSend, null, recordingAudioFileToSend.getAbsolutePath(), recordDialogId, recordReplyingMessageObject, null, null, null, null, notify, scheduleDate, 0, null); } NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioDidSent, recordingGuid, send == 2 ? audioToSend : null, send == 2 ? recordingAudioFileToSend.getAbsolutePath() : null); } else { NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioRecordTooShort, recordingGuid, false, (int) duration); recordingAudioFileToSend.delete(); } requestAudioFocus(false); }); }); } else { if (recordingAudioFile != null) { recordingAudioFile.delete(); } requestAudioFocus(false); } try { if (audioRecorder != null) { audioRecorder.release(); audioRecorder = null; } } catch (Exception e) { FileLog.e(e); } recordingAudio = null; recordingAudioFile = null; }
Example 10
Source File: UpdateAppAlertDialog.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) { super(activity, 0); appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } parentActivity = activity; setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground)); setTopHeight(175); setMessage(appUpdate.text); if (appUpdate.document instanceof TLRPC.TL_document) { setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size)); } setDismissDialogByButtons(false); setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram)); setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) -> { if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) { return; } if (appUpdate.document instanceof TLRPC.TL_document) { if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) { FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", 1, 1); showProgress(true); } } else if (appUpdate.url != null) { Browser.openUrl(getContext(), appUpdate.url); dialog.dismiss(); } }); setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) -> { if (appUpdate.document instanceof TLRPC.TL_document) { FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document); } dialog.dismiss(); }); radialProgressView = new FrameLayout(parentActivity) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int width = right - left; int height = bottom - top; int w = AndroidUtilities.dp(24); int l = (width - w) / 2; int t = (height - w) / 2 + AndroidUtilities.dp(2); radialProgress.setProgressRect(l, t, l + w, t + w); } @Override protected void onDraw(Canvas canvas) { radialProgress.draw(canvas); } }; radialProgressView.setWillNotDraw(false); radialProgressView.setAlpha(0.0f); radialProgressView.setScaleX(0.1f); radialProgressView.setScaleY(0.1f); radialProgressView.setVisibility(View.INVISIBLE); radialProgress = new RadialProgress(radialProgressView); radialProgress.setStrokeWidth(AndroidUtilities.dp(2)); radialProgress.setBackground(null, true, false); radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton)); }
Example 11
Source File: BlockingUpdateView.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public void show(int account, TLRPC.TL_help_appUpdate update, boolean check) { pressCount = 0; appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } if (getVisibility() != VISIBLE) { setVisibility(VISIBLE); } SpannableStringBuilder builder = new SpannableStringBuilder(update.text); MessageObject.addEntitiesToText(builder, update.entities, false, false, false, false); textView.setText(builder); if (update.document instanceof TLRPC.TL_document) { acceptTextView.setText(LocaleController.getString("Update", R.string.Update) + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size))); } else { acceptTextView.setText(LocaleController.getString("Update", R.string.Update)); } NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidFailToLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged); if (check) { TLRPC.TL_help_getAppUpdate req = new TLRPC.TL_help_getAppUpdate(); try { req.source = ApplicationLoader.applicationContext.getPackageManager().getInstallerPackageName(ApplicationLoader.applicationContext.getPackageName()); } catch (Exception ignore) { } if (req.source == null) { req.source = ""; } ConnectionsManager.getInstance(accountNum).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (response instanceof TLRPC.TL_help_appUpdate) { final TLRPC.TL_help_appUpdate res = (TLRPC.TL_help_appUpdate) response; if (!res.can_not_skip) { setVisibility(GONE); UserConfig.getInstance(0).pendingAppUpdate = null; UserConfig.getInstance(0).saveConfig(false); } } })); } }
Example 12
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public static void openForView(TLObject media, Activity activity) { if (media == null || activity == null) { return; } String fileName = FileLoader.getAttachFileName(media); File f = FileLoader.getPathToAttach(media, true); if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (media instanceof TLRPC.TL_document) { realMimeType = ((TLRPC.TL_document) media).mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }
Example 13
Source File: FileLoadOperation.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public FileLoadOperation(TLRPC.Document documentLocation, Object parent) { try { parentObject = parent; if (documentLocation instanceof TLRPC.TL_documentEncrypted) { location = new TLRPC.TL_inputEncryptedFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; iv = new byte[32]; System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length); key = documentLocation.key; } else if (documentLocation instanceof TLRPC.TL_document) { location = new TLRPC.TL_inputDocumentFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; location.file_reference = documentLocation.file_reference; location.thumb_size = ""; if (location.file_reference == null) { location.file_reference = new byte[0]; } initialDatacenterId = datacenterId = documentLocation.dc_id; allowDisordererFileSave = true; for (int a = 0, N = documentLocation.attributes.size(); a < N; a++) { if (documentLocation.attributes.get(a) instanceof TLRPC.TL_documentAttributeVideo) { supportsPreloading = true; break; } } } ungzip = "application/x-tgsticker".equals(documentLocation.mime_type) || "application/x-tgwallpattern".equals(documentLocation.mime_type); totalBytesCount = documentLocation.size; if (key != null) { int toAdd = 0; if (totalBytesCount % 16 != 0) { bytesCountPadding = 16 - totalBytesCount % 16; totalBytesCount += bytesCountPadding; } } ext = FileLoader.getDocumentFileName(documentLocation); int idx; if (ext == null || (idx = ext.lastIndexOf('.')) == -1) { ext = ""; } else { ext = ext.substring(idx); } if ("audio/ogg".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeAudio; } else if (FileLoader.isVideoMimeType(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeVideo; } else { currentType = ConnectionsManager.FileTypeFile; } if (ext.length() <= 1) { ext = FileLoader.getExtensionByMimeType(documentLocation.mime_type); } } catch (Exception e) { FileLog.e(e); onFail(true, 0); } }
Example 14
Source File: FileLoadOperation.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public FileLoadOperation(TLRPC.Document documentLocation) { try { if (documentLocation instanceof TLRPC.TL_documentEncrypted) { location = new TLRPC.TL_inputEncryptedFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; iv = new byte[32]; System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length); key = documentLocation.key; } else if (documentLocation instanceof TLRPC.TL_document) { location = new TLRPC.TL_inputDocumentFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; allowDisordererFileSave = true; } totalBytesCount = documentLocation.size; if (key != null) { int toAdd = 0; if (totalBytesCount % 16 != 0) { bytesCountPadding = 16 - totalBytesCount % 16; totalBytesCount += bytesCountPadding; } } ext = FileLoader.getDocumentFileName(documentLocation); int idx; if (ext == null || (idx = ext.lastIndexOf('.')) == -1) { ext = ""; } else { ext = ext.substring(idx); } if ("audio/ogg".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeAudio; } else if ("video/mp4".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeVideo; } else { currentType = ConnectionsManager.FileTypeFile; } if (ext.length() <= 1) { if (documentLocation.mime_type != null) { switch (documentLocation.mime_type) { case "video/mp4": ext = ".mp4"; break; case "audio/ogg": ext = ".ogg"; break; default: ext = ""; break; } } else { ext = ""; } } } catch (Exception e) { FileLog.e(e); onFail(true, 0); } }
Example 15
Source File: UpdateAppAlertDialog.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) { super(activity, 0); appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } parentActivity = activity; setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground)); setTopHeight(175); setMessage(appUpdate.text); if (appUpdate.document instanceof TLRPC.TL_document) { setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size)); } setDismissDialogByButtons(false); setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram)); setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) -> { if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) { return; } if (appUpdate.document instanceof TLRPC.TL_document) { if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) { FileLoader.getInstance(accountNum).loadFile(appUpdate.document, true, 1); showProgress(true); } } else if (appUpdate.url != null) { Browser.openUrl(getContext(), appUpdate.url); dialog.dismiss(); } }); setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) -> { if (appUpdate.document instanceof TLRPC.TL_document) { FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document); } dialog.dismiss(); }); radialProgressView = new FrameLayout(parentActivity) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int width = right - left; int height = bottom - top; int w = AndroidUtilities.dp(24); int l = (width - w) / 2; int t = (height - w) / 2 + AndroidUtilities.dp(2); radialProgress.setProgressRect(l, t, l + w, t + w); } @Override protected void onDraw(Canvas canvas) { radialProgress.draw(canvas); } }; radialProgressView.setWillNotDraw(false); radialProgressView.setAlpha(0.0f); radialProgressView.setScaleX(0.1f); radialProgressView.setScaleY(0.1f); radialProgressView.setVisibility(View.INVISIBLE); radialProgress = new RadialProgress(radialProgressView); radialProgress.setStrokeWidth(AndroidUtilities.dp(2)); radialProgress.setBackground(null, true, false); radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton)); }
Example 16
Source File: BlockingUpdateView.java From Telegram with GNU General Public License v2.0 | 4 votes |
public void show(int account, TLRPC.TL_help_appUpdate update, boolean check) { pressCount = 0; appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } if (getVisibility() != VISIBLE) { setVisibility(VISIBLE); } SpannableStringBuilder builder = new SpannableStringBuilder(update.text); MessageObject.addEntitiesToText(builder, update.entities, false, false, false, false); textView.setText(builder); if (update.document instanceof TLRPC.TL_document) { acceptTextView.setText(LocaleController.getString("Update", R.string.Update) + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size))); } else { acceptTextView.setText(LocaleController.getString("Update", R.string.Update)); } NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidFailToLoad); NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged); if (check) { TLRPC.TL_help_getAppUpdate req = new TLRPC.TL_help_getAppUpdate(); try { req.source = ApplicationLoader.applicationContext.getPackageManager().getInstallerPackageName(ApplicationLoader.applicationContext.getPackageName()); } catch (Exception ignore) { } if (req.source == null) { req.source = ""; } ConnectionsManager.getInstance(accountNum).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (response instanceof TLRPC.TL_help_appUpdate) { final TLRPC.TL_help_appUpdate res = (TLRPC.TL_help_appUpdate) response; if (!res.can_not_skip) { setVisibility(GONE); UserConfig.getInstance(0).pendingAppUpdate = null; UserConfig.getInstance(0).saveConfig(false); } } })); } }
Example 17
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static void openForView(TLObject media, Activity activity) throws Exception { if (media == null || activity == null) { return; } String fileName = FileLoader.getAttachFileName(media); File f = FileLoader.getPathToAttach(media, true); if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (media instanceof TLRPC.TL_document) { realMimeType = ((TLRPC.TL_document) media).mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }
Example 18
Source File: FileLoadOperation.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public FileLoadOperation(TLRPC.Document documentLocation) { try { if (documentLocation instanceof TLRPC.TL_documentEncrypted) { location = new TLRPC.TL_inputEncryptedFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; iv = new byte[32]; System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length); key = documentLocation.key; } else if (documentLocation instanceof TLRPC.TL_document) { location = new TLRPC.TL_inputDocumentFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; initialDatacenterId = datacenterId = documentLocation.dc_id; allowDisordererFileSave = true; } totalBytesCount = documentLocation.size; if (key != null) { int toAdd = 0; if (totalBytesCount % 16 != 0) { bytesCountPadding = 16 - totalBytesCount % 16; totalBytesCount += bytesCountPadding; } } ext = FileLoader.getDocumentFileName(documentLocation); int idx; if (ext == null || (idx = ext.lastIndexOf('.')) == -1) { ext = ""; } else { ext = ext.substring(idx); } if ("audio/ogg".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeAudio; } else if ("video/mp4".equals(documentLocation.mime_type)) { currentType = ConnectionsManager.FileTypeVideo; } else { currentType = ConnectionsManager.FileTypeFile; } if (ext.length() <= 1) { if (documentLocation.mime_type != null) { switch (documentLocation.mime_type) { case "video/mp4": ext = ".mp4"; break; case "audio/ogg": ext = ".ogg"; break; default: ext = ""; break; } } else { ext = ""; } } } catch (Exception e) { FileLog.e(e); onFail(true, 0); } }
Example 19
Source File: UpdateAppAlertDialog.java From Telegram with GNU General Public License v2.0 | 4 votes |
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) { super(activity, 0); appUpdate = update; accountNum = account; if (update.document instanceof TLRPC.TL_document) { fileName = FileLoader.getAttachFileName(update.document); } parentActivity = activity; setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground)); setTopHeight(175); setMessage(appUpdate.text); if (appUpdate.document instanceof TLRPC.TL_document) { setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size)); } setDismissDialogByButtons(false); setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram)); setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) -> { if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) { return; } if (appUpdate.document instanceof TLRPC.TL_document) { if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) { FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", 1, 1); showProgress(true); } } else if (appUpdate.url != null) { Browser.openUrl(getContext(), appUpdate.url); dialog.dismiss(); } }); setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) -> { if (appUpdate.document instanceof TLRPC.TL_document) { FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document); } dialog.dismiss(); }); radialProgressView = new FrameLayout(parentActivity) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int width = right - left; int height = bottom - top; int w = AndroidUtilities.dp(24); int l = (width - w) / 2; int t = (height - w) / 2 + AndroidUtilities.dp(2); radialProgress.setProgressRect(l, t, l + w, t + w); } @Override protected void onDraw(Canvas canvas) { radialProgress.draw(canvas); } }; radialProgressView.setWillNotDraw(false); radialProgressView.setAlpha(0.0f); radialProgressView.setScaleX(0.1f); radialProgressView.setScaleY(0.1f); radialProgressView.setVisibility(View.INVISIBLE); radialProgress = new RadialProgress(radialProgressView); radialProgress.setStrokeWidth(AndroidUtilities.dp(2)); radialProgress.setBackground(null, true, false); radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton)); }
Example 20
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static void openForView(TLObject media, Activity activity) throws Exception { if (media == null || activity == null) { return; } String fileName = FileLoader.getAttachFileName(media); File f = FileLoader.getPathToAttach(media, true); if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (media instanceof TLRPC.TL_document) { realMimeType = ((TLRPC.TL_document) media).mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }