org.telegram.messenger.Utilities Java Examples
The following examples show how to use
org.telegram.messenger.Utilities.
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: ConnectionsManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override protected void onPostExecute(final NativeByteBuffer result) { Utilities.stageQueue.postRunnable(() -> { if (result != null) { native_applyDnsConfig(currentAccount, result.address, UserConfig.getInstance(currentAccount).getClientPhone()); } else { if (BuildVars.LOGS_ENABLED) FileLog.d("failed to get azure result"); } currentTask = null; }); }
Example #2
Source File: CountrySelectActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<Country> resultArray = new ArrayList<>(); String n = query.substring(0, 1); ArrayList<Country> arr = countries.get(n.toUpperCase()); if (arr != null) { for (Country c : arr) { if (c.name.toLowerCase().startsWith(query)) { resultArray.add(c); } } } updateSearchResults(resultArray); }); }
Example #3
Source File: ConnectionsManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override protected void onPostExecute(final NativeByteBuffer result) { Utilities.stageQueue.postRunnable(() -> { if (result != null) { currentTask = null; native_applyDnsConfig(currentAccount, result.address, UserConfig.getInstance(currentAccount).getClientPhone()); } else { if (BuildVars.LOGS_ENABLED) { FileLog.d("failed to get dns txt result"); FileLog.d("start azure task"); } AzureLoadTask task = new AzureLoadTask(currentAccount); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null); currentTask = task; } }); }
Example #4
Source File: EncryptedFileInputStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { if (currentMode == MODE_CBC && fileOffset == 0) { byte[] temp = new byte[32]; super.read(temp, 0, 32); Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); fileOffset += 32; skip((temp[0] & 0xff) - 32); } int result = super.read(b, off, len); if (currentMode == MODE_CBC) { Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); } else if (currentMode == MODE_CTR) { Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset); } fileOffset += len; return result; }
Example #5
Source File: EncryptedFileDataSource.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException { if (readLength == 0) { return 0; } else if (bytesRemaining == 0) { return C.RESULT_END_OF_INPUT; } else { int bytesRead; try { bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength)); Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset); fileOffset += bytesRead; } catch (IOException e) { throw new EncryptedFileDataSourceException(e); } if (bytesRead > 0) { bytesRemaining -= bytesRead; if (listener != null) { listener.onBytesTransferred(this, dataSpec, false, bytesRead); } } return bytesRead; } }
Example #6
Source File: VoIPService.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void upgradeToGroupCall(List<Integer> usersToAdd){ if(upgrading) return; groupUsersToAdd=usersToAdd; if(!isOutgoing){ controller.requestCallUpgrade(); return; } upgrading=true; groupCallEncryptionKey=new byte[256]; Utilities.random.nextBytes(groupCallEncryptionKey); groupCallEncryptionKey[0]&=0x7F; byte[] authKeyHash = Utilities.computeSHA1(groupCallEncryptionKey); byte[] authKeyId = new byte[8]; System.arraycopy(authKeyHash, authKeyHash.length - 8, authKeyId, 0, 8); groupCallKeyFingerprint=Utilities.bytesToLong(authKeyId); controller.sendGroupCallKey(groupCallEncryptionKey); }
Example #7
Source File: AlertsCreator.java From Telegram with GNU General Public License v2.0 | 6 votes |
public static void showFloodWaitAlert(String error, final BaseFragment fragment) { if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) { return; } int time = Utilities.parseInt(error); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); fragment.showDialog(builder.create(), true, null); }
Example #8
Source File: LanguageSelectActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<LocaleController.LocaleInfo> resultArray = new ArrayList<>(); for (int a = 0; a < sortedLanguages.size(); a++) { LocaleController.LocaleInfo c = sortedLanguages.get(a); if (c.name.toLowerCase().startsWith(query) || c.nameEnglish.toLowerCase().startsWith(query)) resultArray.add(c); } updateSearchResults(resultArray); }); }
Example #9
Source File: CountrySelectActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<Country> resultArray = new ArrayList<>(); String n = query.substring(0, 1); ArrayList<Country> arr = countries.get(n.toUpperCase()); if (arr != null) { for (Country c : arr) { if (c.name.toLowerCase().startsWith(query)) { resultArray.add(c); } } } updateSearchResults(resultArray); }); }
Example #10
Source File: VoIPActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void updateKeyView() { if (VoIPService.getSharedInstance() == null) return; IdenticonDrawable img = new IdenticonDrawable(); img.setColors(new int[]{0x00FFFFFF, 0xFFFFFFFF, 0x99FFFFFF, 0x33FFFFFF}); TLRPC.EncryptedChat encryptedChat = new TLRPC.TL_encryptedChat(); try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); buf.write(VoIPService.getSharedInstance().getEncryptionKey()); buf.write(VoIPService.getSharedInstance().getGA()); encryptedChat.auth_key = buf.toByteArray(); } catch (Exception checkedExceptionsAreBad) { } byte[] sha256 = Utilities.computeSHA256(encryptedChat.auth_key, 0, encryptedChat.auth_key.length); String[] emoji = EncryptionKeyEmojifier.emojifyForCall(sha256); //keyEmojiText.setText(Emoji.replaceEmoji(TextUtils.join(" ", emoji), keyEmojiText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(32), false)); emojiWrap.setContentDescription(LocaleController.getString("EncryptionKey", R.string.EncryptionKey) + ", " + TextUtils.join(", ", emoji)); for (int i = 0; i < 4; i++) { Drawable drawable = Emoji.getEmojiDrawable(emoji[i]); if (drawable != null) { drawable.setBounds(0, 0, AndroidUtilities.dp(22), AndroidUtilities.dp(22)); keyEmojiViews[i].setImageDrawable(drawable); } } }
Example #11
Source File: CacheControlActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private long getDirectorySize(File dir, int documentsMusicType) { if (dir == null || canceled) { return 0; } long size = 0; if (dir.isDirectory()) { size = Utilities.getDirSize(dir.getAbsolutePath(), documentsMusicType); } else if (dir.isFile()) { size += dir.length(); } return size; }
Example #12
Source File: PhotoPaintView.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private PhotoFace getRandomFaceWithVacantAnchor(int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) { if (anchor < 0 || anchor > 3 || faces.isEmpty()) { return null; } int count = faces.size(); int randomIndex = Utilities.random.nextInt(count); int remaining = count; PhotoFace selectedFace = null; for (int i = randomIndex; remaining > 0; i = (i + 1) % count, remaining--) { PhotoFace face = faces.get(i); if (!isFaceAnchorOccupied(face, anchor, documentId, maskCoords)) { return face; } } return selectedFace; }
Example #13
Source File: AlertsCreator.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static void showFloodWaitAlert(String error, final BaseFragment fragment) { if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) { return; } int time = Utilities.parseInt(error); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); fragment.showDialog(builder.create(), true, null); }
Example #14
Source File: ConnectionsManager.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override protected void onPostExecute(final NativeByteBuffer result) { Utilities.stageQueue.postRunnable(() -> { currentTask = null; if (result != null) { native_applyDnsConfig(currentAccount, result.address, AccountInstance.getInstance(currentAccount).getUserConfig().getClientPhone(), responseDate); } else { if (BuildVars.LOGS_ENABLED) { FileLog.d("failed to get google result"); FileLog.d("start mozilla task"); } MozillaDnsLoadTask task = new MozillaDnsLoadTask(currentAccount); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null); currentTask = task; } }); }
Example #15
Source File: ConnectionsManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override protected void onPostExecute(final NativeByteBuffer result) { Utilities.stageQueue.postRunnable(() -> { if (result != null) { currentTask = null; native_applyDnsConfig(currentAccount, result.address, UserConfig.getInstance(currentAccount).getClientPhone()); } else { if (BuildVars.LOGS_ENABLED) { FileLog.d("failed to get dns txt result"); FileLog.d("start azure task"); } AzureLoadTask task = new AzureLoadTask(currentAccount); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null); currentTask = task; } }); }
Example #16
Source File: CountrySelectActivity.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<Country> resultArray = new ArrayList<>(); String n = query.substring(0, 1); ArrayList<Country> arr = countries.get(n.toUpperCase()); if (arr != null) { for (Country c : arr) { if (c.name.toLowerCase().startsWith(query)) { resultArray.add(c); } } } updateSearchResults(resultArray); }); }
Example #17
Source File: EncryptedFileInputStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { if (currentMode == MODE_CBC && fileOffset == 0) { byte[] temp = new byte[32]; super.read(temp, 0, 32); Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); fileOffset += 32; skip((temp[0] & 0xff) - 32); } int result = super.read(b, off, len); if (currentMode == MODE_CBC) { Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); } else if (currentMode == MODE_CTR) { Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset); } fileOffset += len; return result; }
Example #18
Source File: ThemeEditorView.java From Telegram with GNU General Public License v2.0 | 6 votes |
public void searchDialogs(final String query) { if (query != null && query.equals(lastSearchText)) { return; } lastSearchText = query; if (searchRunnable != null) { Utilities.searchQueue.cancelRunnable(searchRunnable); searchRunnable = null; } if (query == null || query.length() == 0) { searchResult.clear(); topBeforeSwitch = getCurrentTop(); lastSearchId = -1; notifyDataSetChanged(); } else { final int searchId = ++lastSearchId; searchRunnable = () -> searchDialogsInternal(query, searchId); Utilities.searchQueue.postRunnable(searchRunnable, 300); } }
Example #19
Source File: LanguageSelectActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<LocaleController.LocaleInfo> resultArray = new ArrayList<>(); for (int a = 0; a < sortedLanguages.size(); a++) { LocaleController.LocaleInfo c = sortedLanguages.get(a); if (c.name.toLowerCase().startsWith(query) || c.nameEnglish.toLowerCase().startsWith(query)) resultArray.add(c); } updateSearchResults(resultArray); }); }
Example #20
Source File: PhotoPaintView.java From Telegram with GNU General Public License v2.0 | 6 votes |
private PhotoFace getRandomFaceWithVacantAnchor(int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) { if (anchor < 0 || anchor > 3 || faces.isEmpty()) { return null; } int count = faces.size(); int randomIndex = Utilities.random.nextInt(count); int remaining = count; PhotoFace selectedFace = null; for (int i = randomIndex; remaining > 0; i = (i + 1) % count, remaining--) { PhotoFace face = faces.get(i); if (!isFaceAnchorOccupied(face, anchor, documentId, maskCoords)) { return face; } } return selectedFace; }
Example #21
Source File: ConnectionsManager.java From Telegram with GNU General Public License v2.0 | 6 votes |
public static void onUnparsedMessageReceived(long address, final int currentAccount) { try { NativeByteBuffer buff = NativeByteBuffer.wrap(address); buff.reused = true; int constructor = buff.readInt32(true); final TLObject message = TLClassStore.Instance().TLdeserialize(buff, constructor, true); if (message instanceof TLRPC.Updates) { if (BuildVars.LOGS_ENABLED) { FileLog.d("java received " + message); } KeepAliveJob.finishJob(); Utilities.stageQueue.postRunnable(() -> AccountInstance.getInstance(currentAccount).getMessagesController().processUpdates((TLRPC.Updates) message, false)); } else { if (BuildVars.LOGS_ENABLED) { FileLog.d(String.format("java received unknown constructor 0x%x", constructor)); } } } catch (Exception e) { FileLog.e(e); } }
Example #22
Source File: EncryptedFileInputStream.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { if (currentMode == MODE_CBC && fileOffset == 0) { byte[] temp = new byte[32]; super.read(temp, 0, 32); Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); fileOffset += 32; skip((temp[0] & 0xff) - 32); } int result = super.read(b, off, len); if (currentMode == MODE_CBC) { Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0); } else if (currentMode == MODE_CTR) { Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset); } fileOffset += len; return result; }
Example #23
Source File: CountrySelectActivity.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void processSearch(final String query) { Utilities.searchQueue.postRunnable(() -> { String q = query.trim().toLowerCase(); if (q.length() == 0) { updateSearchResults(new ArrayList<>()); return; } ArrayList<Country> resultArray = new ArrayList<>(); String n = query.substring(0, 1); ArrayList<Country> arr = countries.get(n.toUpperCase()); if (arr != null) { for (Country c : arr) { if (c.name.toLowerCase().startsWith(query)) { resultArray.add(c); } } } updateSearchResults(resultArray); }); }
Example #24
Source File: EncryptedFileDataSource.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException { if (readLength == 0) { return 0; } else if (bytesRemaining == 0) { return C.RESULT_END_OF_INPUT; } else { int bytesRead; try { bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength)); Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset); fileOffset += bytesRead; } catch (IOException e) { throw new EncryptedFileDataSourceException(e); } if (bytesRead > 0) { bytesRemaining -= bytesRead; bytesTransferred(bytesRead); } return bytesRead; } }
Example #25
Source File: EncryptedFileDataSource.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException { if (readLength == 0) { return 0; } else if (bytesRemaining == 0) { return C.RESULT_END_OF_INPUT; } else { int bytesRead; try { bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength)); Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset); fileOffset += bytesRead; } catch (IOException e) { throw new EncryptedFileDataSourceException(e); } if (bytesRead > 0) { bytesRemaining -= bytesRead; bytesTransferred(bytesRead); } return bytesRead; } }
Example #26
Source File: BaseLocationAdapter.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public void searchDelayed(final String query, final Location coordinate) { if (query == null || query.length() == 0) { places.clear(); searchInProgress = false; notifyDataSetChanged(); } else { if (searchRunnable != null) { Utilities.searchQueue.cancelRunnable(searchRunnable); searchRunnable = null; } searchInProgress = true; Utilities.searchQueue.postRunnable(searchRunnable = () -> AndroidUtilities.runOnUIThread(() -> { searchRunnable = null; lastSearchLocation = null; searchPlacesWithQuery(query, coordinate, true); }), 400); } }
Example #27
Source File: ChatUsersActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public void searchUsers(final String query) { if (searchRunnable != null) { Utilities.searchQueue.cancelRunnable(searchRunnable); searchRunnable = null; } if (TextUtils.isEmpty(query)) { searchResult.clear(); searchResultMap.clear(); searchResultNames.clear(); searchAdapterHelper.mergeResults(null); searchAdapterHelper.queryServerSearch(null, type != 0, false, true, false, false, ChatObject.isChannel(currentChat) ? chatId : 0, false, type, 0); notifyDataSetChanged(); } else { Utilities.searchQueue.postRunnable(searchRunnable = () -> processSearch(query), 300); } }
Example #28
Source File: InstantCameraView.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void saveLastCameraBitmap() { Bitmap bitmap = textureView.getBitmap(); if (bitmap != null && bitmap.getPixel(0, 0) != 0) { lastBitmap = Bitmap.createScaledBitmap(textureView.getBitmap(), 80, 80, true); if (lastBitmap != null) { Utilities.blurBitmap(lastBitmap, 7, 1, lastBitmap.getWidth(), lastBitmap.getHeight(), lastBitmap.getRowBytes()); try { File file = new File(ApplicationLoader.getFilesDirFixed(), "icthumb.jpg"); FileOutputStream stream = new FileOutputStream(file); lastBitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); } catch (Throwable ignore) { } } } }
Example #29
Source File: AlertsCreator.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static void showFloodWaitAlert(String error, final BaseFragment fragment) { if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) { return; } int time = Utilities.parseInt(error); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); fragment.showDialog(builder.create(), true, null); }
Example #30
Source File: ConnectionsManager.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public static void onUnparsedMessageReceived(long address, final int currentAccount) { try { NativeByteBuffer buff = NativeByteBuffer.wrap(address); buff.reused = true; int constructor = buff.readInt32(true); final TLObject message = TLClassStore.Instance().TLdeserialize(buff, constructor, true); if (message instanceof TLRPC.Updates) { if (BuildVars.LOGS_ENABLED) { FileLog.d("java received " + message); } KeepAliveJob.finishJob(); Utilities.stageQueue.postRunnable(() -> AccountInstance.getInstance(currentAccount).getMessagesController().processUpdates((TLRPC.Updates) message, false)); } else { if (BuildVars.LOGS_ENABLED) { FileLog.d(String.format("java received unknown constructor 0x%x", constructor)); } } } catch (Exception e) { FileLog.e(e); } }