org.telegram.messenger.NotificationsController Java Examples
The following examples show how to use
org.telegram.messenger.NotificationsController.
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: DrawerUserCell.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (UserConfig.getActivatedAccountsCount() <= 1 || !NotificationsController.getInstance(accountNumber).showBadgeNumber) { return; } int counter = NotificationsController.getInstance(accountNumber).getTotalUnreadCount(); if (counter <= 0) { return; } String text = String.format("%d", counter); int countTop = AndroidUtilities.dp(12.5f); int textWidth = (int) Math.ceil(Theme.chat_livePaint.measureText(text)); int countWidth = Math.max(AndroidUtilities.dp(12), textWidth); int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(25); int x = countLeft - AndroidUtilities.dp(5.5f); rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(11), countTop + AndroidUtilities.dp(23)); canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, Theme.dialogs_countPaint); canvas.drawText(text, rect.left + (rect.width() - textWidth) / 2 - AndroidUtilities.dp(0.5f), countTop + AndroidUtilities.dp(16), Theme.dialogs_countTextPaint); }
Example #2
Source File: DrawerUserCell.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (UserConfig.getActivatedAccountsCount() <= 1 || !NotificationsController.getInstance(accountNumber).showBadgeNumber) { return; } int counter = NotificationsController.getInstance(accountNumber).getTotalUnreadCount(); if (counter <= 0) { return; } String text = String.format("%d", counter); int countTop = AndroidUtilities.dp(12.5f); int textWidth = (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(text)); int countWidth = Math.max(AndroidUtilities.dp(10), textWidth); int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(25); int x = countLeft - AndroidUtilities.dp(5.5f); rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(14), countTop + AndroidUtilities.dp(23)); canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, Theme.dialogs_countPaint); canvas.drawText(text, rect.left + (rect.width() - textWidth) / 2, countTop + AndroidUtilities.dp(16), Theme.dialogs_countTextPaint); }
Example #3
Source File: DrawerUserCell.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (UserConfig.getActivatedAccountsCount() <= 1 || !NotificationsController.getInstance(accountNumber).showBadgeNumber) { return; } int counter = NotificationsController.getInstance(accountNumber).getTotalUnreadCount(); if (counter <= 0) { return; } String text = String.format("%d", counter); int countTop = AndroidUtilities.dp(12.5f); int textWidth = (int) Math.ceil(Theme.chat_livePaint.measureText(text)); int countWidth = Math.max(AndroidUtilities.dp(12), textWidth); int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(25); int x = countLeft - AndroidUtilities.dp(5.5f); rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(11), countTop + AndroidUtilities.dp(23)); canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, Theme.dialogs_countPaint); canvas.drawText(text, rect.left + (rect.width() - textWidth) / 2 - AndroidUtilities.dp(0.5f), countTop + AndroidUtilities.dp(16), Theme.dialogs_countTextPaint); }
Example #4
Source File: DrawerUserCell.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (UserConfig.getActivatedAccountsCount() <= 1 || !NotificationsController.getInstance(accountNumber).showBadgeNumber) { return; } int counter = NotificationsController.getInstance(accountNumber).getTotalUnreadCount(); if (counter <= 0) { return; } String text = String.format("%d", counter); int countTop = AndroidUtilities.dp(12.5f); int textWidth = (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(text)); int countWidth = Math.max(AndroidUtilities.dp(10), textWidth); int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(25); int x = countLeft - AndroidUtilities.dp(5.5f); rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(14), countTop + AndroidUtilities.dp(23)); canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, Theme.dialogs_countPaint); canvas.drawText(text, rect.left + (rect.width() - textWidth) / 2, countTop + AndroidUtilities.dp(16), Theme.dialogs_countTextPaint); }
Example #5
Source File: VoIPService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(){ super.onCreate(); if(callIShouldHavePutIntoIntent!=null && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ NotificationsController.checkOtherNotificationsChannel(); Notification.Builder bldr=new Notification.Builder(this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) .setSmallIcon(R.drawable.notification) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setShowWhen(false); startForeground(ID_ONGOING_CALL_NOTIFICATION, bldr.build()); } }
Example #6
Source File: AlertsCreator.java From Telegram with GNU General Public License v2.0 | 5 votes |
public static Dialog createMuteAlert(Context context, final long dialog_id) { if (context == null) { return null; } BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true); CharSequence[] items = new CharSequence[]{ LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), LocaleController.getString("MuteDisable", R.string.MuteDisable) }; builder.setItems(items, (dialogInterface, i) -> { int setting; if (i == 0) { setting = NotificationsController.SETTING_MUTE_HOUR; } else if (i == 1) { setting = NotificationsController.SETTING_MUTE_8_HOURS; } else if (i == 2) { setting = NotificationsController.SETTING_MUTE_2_DAYS; } else { setting = NotificationsController.SETTING_MUTE_FOREVER; } NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting); } ); return builder.create(); }
Example #7
Source File: PopupNotificationActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void handleIntent(Intent intent) { isReply = intent != null && intent.getBooleanExtra("force", false); popupMessages.clear(); if (isReply) { int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount; popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages); } else { for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { if (UserConfig.getInstance(a).isClientActivated()) { popupMessages.addAll(NotificationsController.getInstance(a).popupMessages); } } } KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) { getWindow().addFlags( WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } else { getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } if (currentMessageObject == null) { currentMessageNum = 0; } getNewMessage(); }
Example #8
Source File: NotificationsCustomSettingsActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
public void searchDialogs(final String query) { if (searchRunnable != null) { Utilities.searchQueue.cancelRunnable(searchRunnable); searchRunnable = null; } if (query == null) { searchResult.clear(); searchResultNames.clear(); searchAdapterHelper.mergeResults(null); searchAdapterHelper.queryServerSearch(null, true, currentType != NotificationsController.TYPE_PRIVATE, true, false, false, 0, false, 0, 0); notifyDataSetChanged(); } else { Utilities.searchQueue.postRunnable(searchRunnable = () -> processSearch(query), 300); } }
Example #9
Source File: VoIPService.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(){ super.onCreate(); if(callIShouldHavePutIntoIntent!=null && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ NotificationsController.checkOtherNotificationsChannel(); Notification.Builder bldr=new Notification.Builder(this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) .setSmallIcon(R.drawable.notification) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setShowWhen(false); startForeground(ID_ONGOING_CALL_NOTIFICATION, bldr.build()); } }
Example #10
Source File: AlertsCreator.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static Dialog createMuteAlert(Context context, final long dialog_id) { if (context == null) { return null; } BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true); CharSequence[] items = new CharSequence[]{ LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), LocaleController.getString("MuteDisable", R.string.MuteDisable) }; builder.setItems(items, (dialogInterface, i) -> { int setting; if (i == 0) { setting = NotificationsController.SETTING_MUTE_HOUR; } else if (i == 1) { setting = NotificationsController.SETTING_MUTE_8_HOURS; } else if (i == 2) { setting = NotificationsController.SETTING_MUTE_2_DAYS; } else { setting = NotificationsController.SETTING_MUTE_FOREVER; } NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting); } ); return builder.create(); }
Example #11
Source File: PopupNotificationActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void handleIntent(Intent intent) { isReply = intent != null && intent.getBooleanExtra("force", false); popupMessages.clear(); if (isReply) { int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount; popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages); } else { for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { if (UserConfig.getInstance(a).isClientActivated()) { popupMessages.addAll(NotificationsController.getInstance(a).popupMessages); } } } KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) { getWindow().addFlags( WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } else { getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } if (currentMessageObject == null) { currentMessageNum = 0; } getNewMessage(); }
Example #12
Source File: NotificationsCustomSettingsActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public void searchDialogs(final String query) { if (searchRunnable != null) { Utilities.searchQueue.cancelRunnable(searchRunnable); searchRunnable = null; } if (query == null) { searchResult.clear(); searchResultNames.clear(); searchAdapterHelper.mergeResults(null); searchAdapterHelper.queryServerSearch(null, true, currentType != NotificationsController.TYPE_PRIVATE, true, false, false, 0, false, 0, 0); notifyDataSetChanged(); } else { Utilities.searchQueue.postRunnable(searchRunnable = () -> processSearch(query), 300); } }
Example #13
Source File: VoIPService.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(){ super.onCreate(); if(callIShouldHavePutIntoIntent!=null && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ NotificationsController.checkOtherNotificationsChannel(); Notification.Builder bldr=new Notification.Builder(this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) .setSmallIcon(R.drawable.notification) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setShowWhen(false); startForeground(ID_ONGOING_CALL_NOTIFICATION, bldr.build()); } }
Example #14
Source File: PopupNotificationActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void handleIntent(Intent intent) { isReply = intent != null && intent.getBooleanExtra("force", false); popupMessages.clear(); if (isReply) { int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount; popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages); } else { for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { if (UserConfig.getInstance(a).isClientActivated()) { popupMessages.addAll(NotificationsController.getInstance(a).popupMessages); } } } KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) { getWindow().addFlags( WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } else { getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } if (currentMessageObject == null) { currentMessageNum = 0; } getNewMessage(); }
Example #15
Source File: PopupNotificationActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void handleIntent(Intent intent) { isReply = intent != null && intent.getBooleanExtra("force", false); popupMessages.clear(); if (isReply) { int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount; popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages); } else { for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { if (UserConfig.getInstance(a).isClientActivated()) { popupMessages.addAll(NotificationsController.getInstance(a).popupMessages); } } } KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) { getWindow().addFlags( WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } else { getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } if (currentMessageObject == null) { currentMessageNum = 0; } getNewMessage(); }
Example #16
Source File: VoIPService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(){ super.onCreate(); if(callIShouldHavePutIntoIntent!=null && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ NotificationsController.checkOtherNotificationsChannel(); Notification.Builder bldr=new Notification.Builder(this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) .setSmallIcon(R.drawable.notification) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setShowWhen(false); startForeground(ID_ONGOING_CALL_NOTIFICATION, bldr.build()); } }
Example #17
Source File: AlertsCreator.java From Telegram with GNU General Public License v2.0 | 4 votes |
public static Dialog createPopupSelectDialog(Activity parentActivity, final int globalType, final Runnable onSelect) { SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); final int[] selected = new int[1]; if (globalType == NotificationsController.TYPE_PRIVATE) { selected[0] = preferences.getInt("popupAll", 0); } else if (globalType == NotificationsController.TYPE_GROUP) { selected[0] = preferences.getInt("popupGroup", 0); } else { selected[0] = preferences.getInt("popupChannel", 0); } String[] descriptions = new String[]{ LocaleController.getString("NoPopup", R.string.NoPopup), LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn), LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff), LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) }; final LinearLayout linearLayout = new LinearLayout(parentActivity); linearLayout.setOrientation(LinearLayout.VERTICAL); AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); for (int a = 0; a < descriptions.length; a++) { RadioColorCell cell = new RadioColorCell(parentActivity); cell.setTag(a); cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); cell.setTextAndValue(descriptions[a], selected[0] == a); linearLayout.addView(cell); cell.setOnClickListener(v -> { selected[0] = (Integer) v.getTag(); final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); SharedPreferences.Editor editor = preferences1.edit(); if (globalType == NotificationsController.TYPE_PRIVATE) { editor.putInt("popupAll", selected[0]); } else if (globalType == NotificationsController.TYPE_GROUP) { editor.putInt("popupGroup", selected[0]); } else { editor.putInt("popupChannel", selected[0]); } editor.commit(); builder.getDismissRunnable().run(); if (onSelect != null) { onSelect.run(); } }); } builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null); return builder.create(); }
Example #18
Source File: ProfileNotificationsActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public boolean onFragmentCreate() { rowCount = 0; if (addingException) { avatarRow = rowCount++; avatarSectionRow = rowCount++; customRow = -1; customInfoRow = -1; } else { avatarRow = -1; avatarSectionRow = -1; customRow = rowCount++; customInfoRow = rowCount++; } generalRow = rowCount++; if (addingException) { enableRow = rowCount++; } else { enableRow = -1; } if ((int) dialog_id != 0) { previewRow = rowCount++; } else { previewRow = -1; } soundRow = rowCount++; vibrateRow = rowCount++; if ((int) dialog_id < 0) { smartRow = rowCount++; } else { smartRow = -1; } if (Build.VERSION.SDK_INT >= 21) { priorityRow = rowCount++; } else { priorityRow = -1; } priorityInfoRow = rowCount++; boolean isChannel; int lower_id = (int) dialog_id; if (lower_id < 0) { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); isChannel = ChatObject.isChannel(chat) && !chat.megagroup; } else { isChannel = false; } if (lower_id != 0 && !isChannel) { popupRow = rowCount++; popupEnabledRow = rowCount++; popupDisabledRow = rowCount++; popupInfoRow = rowCount++; } else { popupRow = -1; popupEnabledRow = -1; popupDisabledRow = -1; popupInfoRow = -1; } if (lower_id > 0) { callsRow = rowCount++; callsVibrateRow = rowCount++; ringtoneRow = rowCount++; ringtoneInfoRow = rowCount++; } else { callsRow = -1; callsVibrateRow = -1; ringtoneRow = -1; ringtoneInfoRow = -1; } ledRow = rowCount++; colorRow = rowCount++; ledInfoRow = rowCount++; SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); customEnabled = preferences.getBoolean("custom_" + dialog_id, false) || addingException; boolean hasOverride = preferences.contains("notify2_" + dialog_id); int value = preferences.getInt("notify2_" + dialog_id, 0); if (value == 0) { if (hasOverride) { notificationsEnabled = true; } else { notificationsEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(dialog_id); } } else if (value == 1) { notificationsEnabled = true; } else if (value == 2) { notificationsEnabled = false; } else { notificationsEnabled = false; } NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.notificationsSettingsUpdated); return super.onFragmentCreate(); }
Example #19
Source File: VoIPBaseService.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
protected void showNotification(String name, TLRPC.FileLocation photo, Class<? extends Activity> activity) { Intent intent = new Intent(this, activity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setContentText(name) .setSmallIcon(R.drawable.notification) .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent endIntent = new Intent(this, VoIPActionsReceiver.class); endIntent.setAction(getPackageName() + ".END_CALL"); builder.addAction(R.drawable.ic_call_end_white_24dp, LocaleController.getString("VoipEndCall", R.string.VoipEndCall), PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setPriority(Notification.PRIORITY_MAX); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { builder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(0xff2ca5e0); } if (Build.VERSION.SDK_INT >= 26) { NotificationsController.checkOtherNotificationsChannel(); builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL); } if (photo!= null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photo, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photo, true).toString(), options); if (bitmap != null) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { FileLog.e(e); } } } ongoingCallNotification = builder.getNotification(); startForeground(ID_ONGOING_CALL_NOTIFICATION, ongoingCallNotification); }
Example #20
Source File: BaseFragment.java From Telegram with GNU General Public License v2.0 | 4 votes |
protected NotificationsController getNotificationsController() { return getAccountInstance().getNotificationsController(); }
Example #21
Source File: AlertsCreator.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static Dialog createMuteAlert(Context context, final long dialog_id) { if (context == null) { return null; } BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications)); CharSequence[] items = new CharSequence[]{ LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), LocaleController.getString("MuteDisable", R.string.MuteDisable) }; builder.setItems(items, (dialogInterface, i) -> { int untilTime = ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime(); if (i == 0) { untilTime += 60 * 60; } else if (i == 1) { untilTime += 60 * 60 * 8; } else if (i == 2) { untilTime += 60 * 60 * 48; } else if (i == 3) { untilTime = Integer.MAX_VALUE; } SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); SharedPreferences.Editor editor = preferences.edit(); long flags; if (i == 3) { editor.putInt("notify2_" + dialog_id, 2); flags = 1; } else { editor.putInt("notify2_" + dialog_id, 3); editor.putInt("notifyuntil_" + dialog_id, untilTime); flags = ((long) untilTime << 32) | 1; } NotificationsController.getInstance(UserConfig.selectedAccount).removeNotificationsForDialog(dialog_id); MessagesStorage.getInstance(UserConfig.selectedAccount).setDialogFlags(dialog_id, flags); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance(UserConfig.selectedAccount).dialogs_dict.get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); dialog.notify_settings.mute_until = untilTime; } NotificationsController.getInstance(UserConfig.selectedAccount).updateServerNotificationsSettings(dialog_id); } ); return builder.create(); }
Example #22
Source File: VoIPBaseService.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
protected void showNotification(String name, TLRPC.FileLocation photo, Class<? extends Activity> activity) { Intent intent = new Intent(this, activity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setContentText(name) .setSmallIcon(R.drawable.notification) .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent endIntent = new Intent(this, VoIPActionsReceiver.class); endIntent.setAction(getPackageName() + ".END_CALL"); builder.addAction(R.drawable.ic_call_end_white_24dp, LocaleController.getString("VoipEndCall", R.string.VoipEndCall), PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setPriority(Notification.PRIORITY_MAX); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { builder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(0xff2ca5e0); } if (Build.VERSION.SDK_INT >= 26) { NotificationsController.checkOtherNotificationsChannel(); builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL); } if (photo!= null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photo, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photo, true).toString(), options); if (bitmap != null) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { FileLog.e(e); } } } ongoingCallNotification = builder.getNotification(); startForeground(ID_ONGOING_CALL_NOTIFICATION, ongoingCallNotification); }
Example #23
Source File: NotificationsCustomSettingsActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; if (ringtone != null) { Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone); if (rng != null) { if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { name = LocaleController.getString("SoundDefault", R.string.SoundDefault); } else { name = rng.getTitle(getParentActivity()); } rng.stop(); } } SharedPreferences preferences = getNotificationsSettings(); SharedPreferences.Editor editor = preferences.edit(); if (currentType == NotificationsController.TYPE_PRIVATE) { if (name != null && ringtone != null) { editor.putString("GlobalSound", name); editor.putString("GlobalSoundPath", ringtone.toString()); } else { editor.putString("GlobalSound", "NoSound"); editor.putString("GlobalSoundPath", "NoSound"); } } else if (currentType == NotificationsController.TYPE_GROUP) { if (name != null && ringtone != null) { editor.putString("GroupSound", name); editor.putString("GroupSoundPath", ringtone.toString()); } else { editor.putString("GroupSound", "NoSound"); editor.putString("GroupSoundPath", "NoSound"); } } else if (currentType == NotificationsController.TYPE_CHANNEL) { if (name != null && ringtone != null) { editor.putString("ChannelSound", name); editor.putString("ChannelSoundPath", ringtone.toString()); } else { editor.putString("ChannelSound", "NoSound"); editor.putString("ChannelSoundPath", "NoSound"); } } editor.commit(); getNotificationsController().updateServerNotificationsSettings(currentType); RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(requestCode); if (holder != null) { adapter.onBindViewHolder(holder, requestCode); } } }
Example #24
Source File: NotificationsCustomSettingsActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void updateRows(boolean notify) { rowCount = 0; if (currentType != -1) { alertRow = rowCount++; alertSection2Row = rowCount++; messageSectionRow = rowCount++; previewRow = rowCount++; messageLedRow = rowCount++; messageVibrateRow = rowCount++; if (currentType == NotificationsController.TYPE_CHANNEL) { messagePopupNotificationRow = -1; } else { messagePopupNotificationRow = rowCount++; } messageSoundRow = rowCount++; if (Build.VERSION.SDK_INT >= 21) { messagePriorityRow = rowCount++; } else { messagePriorityRow = -1; } groupSection2Row = rowCount++; exceptionsAddRow = rowCount++; } else { alertRow = -1; alertSection2Row = -1; messageSectionRow = -1; previewRow = -1; messageLedRow = -1; messageVibrateRow = -1; messagePopupNotificationRow = -1; messageSoundRow = -1; messagePriorityRow = -1; groupSection2Row = -1; exceptionsAddRow = -1; } if (exceptions != null && !exceptions.isEmpty()) { exceptionsStartRow = rowCount; rowCount += exceptions.size(); exceptionsEndRow = rowCount; } else { exceptionsStartRow = -1; exceptionsEndRow = -1; } if (currentType != -1 || exceptions != null && !exceptions.isEmpty()) { exceptionsSection2Row = rowCount++; } else { exceptionsSection2Row = -1; } if (exceptions != null && !exceptions.isEmpty()) { deleteAllRow = rowCount++; deleteAllSectionRow = rowCount++; } else { deleteAllRow = -1; deleteAllSectionRow = -1; } if (notify && adapter != null) { adapter.notifyDataSetChanged(); } }
Example #25
Source File: ProfileNotificationsActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public boolean onFragmentCreate() { rowCount = 0; if (addingException) { avatarRow = rowCount++; avatarSectionRow = rowCount++; customRow = -1; customInfoRow = -1; } else { avatarRow = -1; avatarSectionRow = -1; customRow = rowCount++; customInfoRow = rowCount++; } generalRow = rowCount++; if (addingException) { enableRow = rowCount++; } else { enableRow = -1; } if ((int) dialog_id != 0) { previewRow = rowCount++; } else { previewRow = -1; } soundRow = rowCount++; vibrateRow = rowCount++; if ((int) dialog_id < 0) { smartRow = rowCount++; } else { smartRow = -1; } if (Build.VERSION.SDK_INT >= 21) { priorityRow = rowCount++; } else { priorityRow = -1; } priorityInfoRow = rowCount++; boolean isChannel; int lower_id = (int) dialog_id; if (lower_id < 0) { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); isChannel = ChatObject.isChannel(chat) && !chat.megagroup; } else { isChannel = false; } if (lower_id != 0 && !isChannel) { popupRow = rowCount++; popupEnabledRow = rowCount++; popupDisabledRow = rowCount++; popupInfoRow = rowCount++; } else { popupRow = -1; popupEnabledRow = -1; popupDisabledRow = -1; popupInfoRow = -1; } if (lower_id > 0) { callsRow = rowCount++; callsVibrateRow = rowCount++; ringtoneRow = rowCount++; ringtoneInfoRow = rowCount++; } else { callsRow = -1; callsVibrateRow = -1; ringtoneRow = -1; ringtoneInfoRow = -1; } ledRow = rowCount++; colorRow = rowCount++; ledInfoRow = rowCount++; SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); customEnabled = preferences.getBoolean("custom_" + dialog_id, false) || addingException; boolean hasOverride = preferences.contains("notify2_" + dialog_id); int value = preferences.getInt("notify2_" + dialog_id, 0); if (value == 0) { if (hasOverride) { notificationsEnabled = true; } else { notificationsEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(dialog_id); } } else if (value == 1) { notificationsEnabled = true; } else if (value == 2) { notificationsEnabled = false; } else { notificationsEnabled = false; } NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.notificationsSettingsUpdated); return super.onFragmentCreate(); }
Example #26
Source File: VoIPBaseService.java From Telegram with GNU General Public License v2.0 | 4 votes |
protected void showNotification(String name, TLRPC.FileLocation photo, Class<? extends Activity> activity) { Intent intent = new Intent(this, activity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setContentText(name) .setSmallIcon(R.drawable.notification) .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent endIntent = new Intent(this, VoIPActionsReceiver.class); endIntent.setAction(getPackageName() + ".END_CALL"); builder.addAction(R.drawable.ic_call_end_white_24dp, LocaleController.getString("VoipEndCall", R.string.VoipEndCall), PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setPriority(Notification.PRIORITY_MAX); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { builder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(0xff2ca5e0); } if (Build.VERSION.SDK_INT >= 26) { NotificationsController.checkOtherNotificationsChannel(); builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL); } if (photo!= null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photo, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photo, true).toString(), options); if (bitmap != null) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { FileLog.e(e); } } } ongoingCallNotification = builder.getNotification(); startForeground(ID_ONGOING_CALL_NOTIFICATION, ongoingCallNotification); }
Example #27
Source File: AlertsCreator.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public static Dialog createPopupSelectDialog(Activity parentActivity, final int globalType, final Runnable onSelect) { SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); final int[] selected = new int[1]; if (globalType == NotificationsController.TYPE_PRIVATE) { selected[0] = preferences.getInt("popupAll", 0); } else if (globalType == NotificationsController.TYPE_GROUP) { selected[0] = preferences.getInt("popupGroup", 0); } else { selected[0] = preferences.getInt("popupChannel", 0); } String[] descriptions = new String[]{ LocaleController.getString("NoPopup", R.string.NoPopup), LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn), LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff), LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) }; final LinearLayout linearLayout = new LinearLayout(parentActivity); linearLayout.setOrientation(LinearLayout.VERTICAL); AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); for (int a = 0; a < descriptions.length; a++) { RadioColorCell cell = new RadioColorCell(parentActivity); cell.setTag(a); cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); cell.setTextAndValue(descriptions[a], selected[0] == a); linearLayout.addView(cell); cell.setOnClickListener(v -> { selected[0] = (Integer) v.getTag(); final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); SharedPreferences.Editor editor = preferences1.edit(); if (globalType == NotificationsController.TYPE_PRIVATE) { editor.putInt("popupAll", selected[0]); } else if (globalType == NotificationsController.TYPE_GROUP) { editor.putInt("popupGroup", selected[0]); } else { editor.putInt("popupChannel", selected[0]); } editor.commit(); builder.getDismissRunnable().run(); if (onSelect != null) { onSelect.run(); } }); } builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null); return builder.create(); }
Example #28
Source File: AlertsCreator.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static Dialog createMuteAlert(Context context, final long dialog_id) { if (context == null) { return null; } BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications)); CharSequence[] items = new CharSequence[]{ LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), LocaleController.getString("MuteDisable", R.string.MuteDisable) }; builder.setItems(items, (dialogInterface, i) -> { int untilTime = ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime(); if (i == 0) { untilTime += 60 * 60; } else if (i == 1) { untilTime += 60 * 60 * 8; } else if (i == 2) { untilTime += 60 * 60 * 48; } else if (i == 3) { untilTime = Integer.MAX_VALUE; } SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); SharedPreferences.Editor editor = preferences.edit(); long flags; if (i == 3) { editor.putInt("notify2_" + dialog_id, 2); flags = 1; } else { editor.putInt("notify2_" + dialog_id, 3); editor.putInt("notifyuntil_" + dialog_id, untilTime); flags = ((long) untilTime << 32) | 1; } NotificationsController.getInstance(UserConfig.selectedAccount).removeNotificationsForDialog(dialog_id); MessagesStorage.getInstance(UserConfig.selectedAccount).setDialogFlags(dialog_id, flags); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance(UserConfig.selectedAccount).dialogs_dict.get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); dialog.notify_settings.mute_until = untilTime; } NotificationsController.getInstance(UserConfig.selectedAccount).updateServerNotificationsSettings(dialog_id); } ); return builder.create(); }
Example #29
Source File: BaseFragment.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
protected NotificationsController getNotificationsController() { return getAccountInstance().getNotificationsController(); }
Example #30
Source File: VoIPBaseService.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
protected void showNotification(String name, TLRPC.FileLocation photo, Class<? extends Activity> activity) { Intent intent = new Intent(this, activity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(LocaleController.getString("VoipOutgoingCall", R.string.VoipOutgoingCall)) .setContentText(name) .setSmallIcon(R.drawable.notification) .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Intent endIntent = new Intent(this, VoIPActionsReceiver.class); endIntent.setAction(getPackageName() + ".END_CALL"); builder.addAction(R.drawable.ic_call_end_white_24dp, LocaleController.getString("VoipEndCall", R.string.VoipEndCall), PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setPriority(Notification.PRIORITY_MAX); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { builder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(0xff2ca5e0); } if (Build.VERSION.SDK_INT >= 26) { NotificationsController.checkOtherNotificationsChannel(); builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL); } if (photo!= null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photo, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photo, true).toString(), options); if (bitmap != null) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { FileLog.e(e); } } } ongoingCallNotification = builder.getNotification(); startForeground(ID_ONGOING_CALL_NOTIFICATION, ongoingCallNotification); }