Java Code Examples for org.telegram.messenger.MessagesController#getNotificationsSettings()

The following examples show how to use org.telegram.messenger.MessagesController#getNotificationsSettings() . 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: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void updateServerNotificationsSettings(boolean group) {
    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
    req.settings = new TLRPC.TL_inputPeerNotifySettings();
    req.settings.flags = 5;
    if (!group) {
        req.peer = new TLRPC.TL_inputNotifyUsers();
        req.settings.mute_until = preferences.getBoolean("EnableAll", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewAll", true);
    } else {
        req.peer = new TLRPC.TL_inputNotifyChats();
        req.settings.mute_until = preferences.getBoolean("EnableGroup", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewGroup", true);
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {

    });
}
 
Example 2
Source File: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void updateServerNotificationsSettings(boolean group) {
    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
    req.settings = new TLRPC.TL_inputPeerNotifySettings();
    req.settings.flags = 5;
    if (!group) {
        req.peer = new TLRPC.TL_inputNotifyUsers();
        req.settings.mute_until = preferences.getBoolean("EnableAll", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewAll", true);
    } else {
        req.peer = new TLRPC.TL_inputNotifyChats();
        req.settings.mute_until = preferences.getBoolean("EnableGroup", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewGroup", true);
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {

    });
}
 
Example 3
Source File: VoIPHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showRateAlert(Context context, TLRPC.TL_messageActionPhoneCall call){
	SharedPreferences prefs=MessagesController.getNotificationsSettings(UserConfig.selectedAccount); // always called from chat UI
	Set<String> hashes=prefs.getStringSet("calls_access_hashes", (Set<String>)Collections.EMPTY_SET);
	for(String hash:hashes){
		String[] d=hash.split(" ");
		if(d.length<2)
			continue;
		if(d[0].equals(call.call_id+"")){
			try{
				long accessHash=Long.parseLong(d[1]);
				showRateAlert(context, null, call.call_id, accessHash, UserConfig.selectedAccount);
			}catch(Exception x){}
			return;
		}
	}
}
 
Example 4
Source File: VoIPHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean canRateCall(TLRPC.TL_messageActionPhoneCall call){
	if(!(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) && !(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)){
		SharedPreferences prefs=MessagesController.getNotificationsSettings(UserConfig.selectedAccount); // always called from chat UI
		Set<String> hashes=prefs.getStringSet("calls_access_hashes", (Set<String>)Collections.EMPTY_SET);
		for(String hash:hashes){
			String[] d=hash.split(" ");
			if(d.length<2)
				continue;
			if(d[0].equals(call.call_id+"")){
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: VoIPHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static boolean canRateCall(TLRPC.TL_messageActionPhoneCall call) {
	if (!(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) && !(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)) {
		SharedPreferences prefs = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); // always called from chat UI
		Set<String> hashes = prefs.getStringSet("calls_access_hashes", (Set<String>) Collections.EMPTY_SET);
		for (String hash : hashes) {
			String[] d = hash.split(" ");
			if (d.length < 2)
				continue;
			if (d[0].equals(call.call_id + "")) {
				return true;
			}
		}
	}
	return false;
}
 
Example 6
Source File: VoIPHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static boolean canRateCall(TLRPC.TL_messageActionPhoneCall call) {
	if (!(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) && !(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)) {
		SharedPreferences prefs = MessagesController.getNotificationsSettings(UserConfig.selectedAccount); // always called from chat UI
		Set<String> hashes = prefs.getStringSet("calls_access_hashes", (Set<String>) Collections.EMPTY_SET);
		for (String hash : hashes) {
			String[] d = hash.split(" ");
			if (d.length < 2)
				continue;
			if (d[0].equals(call.call_id + "")) {
				return true;
			}
		}
	}
	return false;
}
 
Example 7
Source File: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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 (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            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 (requestCode == groupSoundRow) {
            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 (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        if (requestCode == messageSoundRow || requestCode == groupSoundRow) {
            updateServerNotificationsSettings(requestCode == groupSoundRow);
        }
        adapter.notifyItemChanged(requestCode);
    }
}
 
Example 8
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
protected void startRingtoneAndVibration(int chatID){
	SharedPreferences prefs = MessagesController.getNotificationsSettings(currentAccount);
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	boolean needRing=am.getRingerMode()!=AudioManager.RINGER_MODE_SILENT;
	/*if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
		try{
			int mode=Settings.Global.getInt(getContentResolver(), "zen_mode");
			if(needRing)
				needRing=mode==0;
		}catch(Exception ignore){}
	}*/
	if(needRing){
		if(!USE_CONNECTION_SERVICE){
			am.requestAudioFocus(this, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN);
		}
		ringtonePlayer=new MediaPlayer();
		ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
			@Override
			public void onPrepared(MediaPlayer mediaPlayer){
				ringtonePlayer.start();
			}
		});
		ringtonePlayer.setLooping(true);
		ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
		try{
			String notificationUri;
			if(prefs.getBoolean("custom_"+chatID, false))
				notificationUri=prefs.getString("ringtone_path_"+chatID, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			else
				notificationUri=prefs.getString("CallsRingtonePath", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			ringtonePlayer.setDataSource(this, Uri.parse(notificationUri));
			ringtonePlayer.prepareAsync();
		}catch(Exception e){
			FileLog.e(e);
			if(ringtonePlayer!=null){
				ringtonePlayer.release();
				ringtonePlayer=null;
			}
		}
		int vibrate;
		if(prefs.getBoolean("custom_"+chatID, false))
			vibrate=prefs.getInt("calls_vibrate_"+chatID, 0);
		else
			vibrate=prefs.getInt("vibrate_calls", 0);
		if((vibrate!=2 && vibrate!=4 && (am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE || am.getRingerMode()==AudioManager.RINGER_MODE_NORMAL)) ||
				(vibrate==4 && am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE)){
			vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
			long duration=700;
			if(vibrate==1)
				duration/=2;
			else if(vibrate==3)
				duration*=2;
			vibrator.vibrate(new long[]{0, duration, 500}, 0);
		}
	}
}
 
Example 9
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected void startRingtoneAndVibration(int chatID){
	SharedPreferences prefs = MessagesController.getNotificationsSettings(currentAccount);
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	boolean needRing=am.getRingerMode()!=AudioManager.RINGER_MODE_SILENT;
	/*if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
		try{
			int mode=Settings.Global.getInt(getContentResolver(), "zen_mode");
			if(needRing)
				needRing=mode==0;
		}catch(Exception ignore){}
	}*/
	if(needRing){
		if(!USE_CONNECTION_SERVICE){
			am.requestAudioFocus(this, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN);
		}
		ringtonePlayer=new MediaPlayer();
		ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
			@Override
			public void onPrepared(MediaPlayer mediaPlayer){
				ringtonePlayer.start();
			}
		});
		ringtonePlayer.setLooping(true);
		ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
		try{
			String notificationUri;
			if(prefs.getBoolean("custom_"+chatID, false))
				notificationUri=prefs.getString("ringtone_path_"+chatID, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			else
				notificationUri=prefs.getString("CallsRingtonePath", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			ringtonePlayer.setDataSource(this, Uri.parse(notificationUri));
			ringtonePlayer.prepareAsync();
		}catch(Exception e){
			FileLog.e(e);
			if(ringtonePlayer!=null){
				ringtonePlayer.release();
				ringtonePlayer=null;
			}
		}
		int vibrate;
		if(prefs.getBoolean("custom_"+chatID, false))
			vibrate=prefs.getInt("calls_vibrate_"+chatID, 0);
		else
			vibrate=prefs.getInt("vibrate_calls", 0);
		if((vibrate!=2 && vibrate!=4 && (am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE || am.getRingerMode()==AudioManager.RINGER_MODE_NORMAL)) ||
				(vibrate==4 && am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE)){
			vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
			long duration=700;
			if(vibrate==1)
				duration/=2;
			else if(vibrate==3)
				duration*=2;
			vibrator.vibrate(new long[]{0, duration, 500}, 0);
		}
	}
}
 
Example 10
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static Dialog createPopupSelectDialog(Activity parentActivity, final BaseFragment parentFragment, final boolean globalGroup, final boolean globalAll, final Runnable onSelect)
{
    SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
    final int selected[] = new int[1];
    if (globalAll)
    {
        selected[0] = preferences.getInt("popupAll", 0);
    }
    else if (globalGroup)
    {
        selected[0] = preferences.getInt("popupGroup", 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);

    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();
            editor.putInt(globalGroup ? "popupGroup" : "popupAll", selected[0]);
            editor.commit();
            if (parentFragment != null)
            {
                parentFragment.dismissCurrentDialig();
            }
            if (onSelect != null)
            {
                onSelect.run();
            }
        });
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
 
Example 11
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
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 12
Source File: ProfileNotificationsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
Example 13
Source File: ProfileNotificationsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}
 
Example 14
Source File: MentionsAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void processFoundUser(TLRPC.User user) {
    contextUsernameReqid = 0;
    locationProvider.stop();
    if (user != null && user.bot && user.bot_inline_placeholder != null) {
        foundContextBot = user;
        if (parentFragment != null) {
            TLRPC.Chat chat = parentFragment.getCurrentChat();
            if (chat != null) {
                inlineMediaEnabled = ChatObject.canSendStickers(chat);
                if (!inlineMediaEnabled) {
                    notifyDataSetChanged();
                    delegate.needChangePanelVisibility(true);
                    return;
                }
            }
        }
        if (foundContextBot.bot_inline_geo) {
            SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
            boolean allowGeo = preferences.getBoolean("inlinegeo_" + foundContextBot.id, false);
            if (!allowGeo && parentFragment != null && parentFragment.getParentActivity() != null) {
                final TLRPC.User foundContextBotFinal = foundContextBot;
                AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                builder.setTitle(LocaleController.getString("ShareYouLocationTitle", R.string.ShareYouLocationTitle));
                builder.setMessage(LocaleController.getString("ShareYouLocationInline", R.string.ShareYouLocationInline));
                final boolean[] buttonClicked = new boolean[1];
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                    buttonClicked[0] = true;
                    if (foundContextBotFinal != null) {
                        SharedPreferences preferences1 = MessagesController.getNotificationsSettings(currentAccount);
                        preferences1.edit().putBoolean("inlinegeo_" + foundContextBotFinal.id, true).commit();
                        checkLocationPermissionsOrStart();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> {
                    buttonClicked[0] = true;
                    onLocationUnavailable();
                });
                parentFragment.showDialog(builder.create(), dialog -> {
                    if (!buttonClicked[0]) {
                        onLocationUnavailable();
                    }
                });
            } else {
                checkLocationPermissionsOrStart();
            }
        }
    } else {
        foundContextBot = null;
        inlineMediaEnabled = true;
    }
    if (foundContextBot == null) {
        noUserName = true;
    } else {
        if (delegate != null) {
            delegate.onContextSearch(true);
        }
        searchForContextBotResults(true, foundContextBot, searchingContextQuery, "");
    }
}
 
Example 15
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected void startRingtoneAndVibration(int chatID){
	SharedPreferences prefs = MessagesController.getNotificationsSettings(currentAccount);
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	boolean needRing=am.getRingerMode()!=AudioManager.RINGER_MODE_SILENT;
	if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
		try{
			int mode=Settings.Global.getInt(getContentResolver(), "zen_mode");
			if(needRing)
				needRing=mode==0;
		}catch(Exception ignore){}
	}
	if(needRing){
		if(!USE_CONNECTION_SERVICE){
			am.requestAudioFocus(this, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN);
		}
		ringtonePlayer=new MediaPlayer();
		ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
			@Override
			public void onPrepared(MediaPlayer mediaPlayer){
				ringtonePlayer.start();
			}
		});
		ringtonePlayer.setLooping(true);
		ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
		try{
			String notificationUri;
			if(prefs.getBoolean("custom_"+chatID, false))
				notificationUri=prefs.getString("ringtone_path_"+chatID, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			else
				notificationUri=prefs.getString("CallsRingtonePath", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
			ringtonePlayer.setDataSource(this, Uri.parse(notificationUri));
			ringtonePlayer.prepareAsync();
		}catch(Exception e){
			FileLog.e(e);
			if(ringtonePlayer!=null){
				ringtonePlayer.release();
				ringtonePlayer=null;
			}
		}
		int vibrate;
		if(prefs.getBoolean("custom_"+chatID, false))
			vibrate=prefs.getInt("calls_vibrate_"+chatID, 0);
		else
			vibrate=prefs.getInt("vibrate_calls", 0);
		if((vibrate!=2 && vibrate!=4 && (am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE || am.getRingerMode()==AudioManager.RINGER_MODE_NORMAL)) ||
				(vibrate==4 && am.getRingerMode()==AudioManager.RINGER_MODE_VIBRATE)){
			vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
			long duration=700;
			if(vibrate==1)
				duration/=2;
			else if(vibrate==3)
				duration*=2;
			vibrator.vibrate(new long[]{0, duration, 500}, 0);
		}
	}
}
 
Example 16
Source File: MentionsAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void processFoundUser(TLRPC.User user) {
    contextUsernameReqid = 0;
    locationProvider.stop();
    if (user != null && user.bot && user.bot_inline_placeholder != null) {
        foundContextBot = user;
        if (parentFragment != null) {
            TLRPC.Chat chat = parentFragment.getCurrentChat();
            if (chat != null) {
                inlineMediaEnabled = ChatObject.canSendStickers(chat);
                if (!inlineMediaEnabled) {
                    notifyDataSetChanged();
                    delegate.needChangePanelVisibility(true);
                    return;
                }
            }
        }
        if (foundContextBot.bot_inline_geo) {
            SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
            boolean allowGeo = preferences.getBoolean("inlinegeo_" + foundContextBot.id, false);
            if (!allowGeo && parentFragment != null && parentFragment.getParentActivity() != null) {
                final TLRPC.User foundContextBotFinal = foundContextBot;
                AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                builder.setTitle(LocaleController.getString("ShareYouLocationTitle", R.string.ShareYouLocationTitle));
                builder.setMessage(LocaleController.getString("ShareYouLocationInline", R.string.ShareYouLocationInline));
                final boolean[] buttonClicked = new boolean[1];
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                    buttonClicked[0] = true;
                    if (foundContextBotFinal != null) {
                        SharedPreferences preferences1 = MessagesController.getNotificationsSettings(currentAccount);
                        preferences1.edit().putBoolean("inlinegeo_" + foundContextBotFinal.id, true).commit();
                        checkLocationPermissionsOrStart();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> {
                    buttonClicked[0] = true;
                    onLocationUnavailable();
                });
                parentFragment.showDialog(builder.create(), dialog -> {
                    if (!buttonClicked[0]) {
                        onLocationUnavailable();
                    }
                });
            } else {
                checkLocationPermissionsOrStart();
            }
        }
    } else {
        foundContextBot = null;
        inlineMediaEnabled = true;
    }
    if (foundContextBot == null) {
        noUserName = true;
    } else {
        if (delegate != null) {
            delegate.onContextSearch(true);
        }
        searchForContextBotResults(true, foundContextBot, searchingContextQuery, "");
    }
}
 
Example 17
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static Dialog createPopupSelectDialog(Activity parentActivity, final BaseFragment parentFragment, final boolean globalGroup, final boolean globalAll, final Runnable onSelect)
{
    SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
    final int selected[] = new int[1];
    if (globalAll)
    {
        selected[0] = preferences.getInt("popupAll", 0);
    }
    else if (globalGroup)
    {
        selected[0] = preferences.getInt("popupGroup", 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);

    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();
            editor.putInt(globalGroup ? "popupGroup" : "popupAll", selected[0]);
            editor.commit();
            if (parentFragment != null)
            {
                parentFragment.dismissCurrentDialig();
            }
            if (onSelect != null)
            {
                onSelect.run();
            }
        });
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    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: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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 (requestCode == callsRingtoneRow) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            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 (requestCode == groupSoundRow) {
            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 (requestCode == callsRingtoneRow) {
            if (name != null && ringtone != null) {
                editor.putString("CallsRingtone", name);
                editor.putString("CallsRingtonePath", ringtone.toString());
            } else {
                editor.putString("CallsRingtone", "NoSound");
                editor.putString("CallsRingtonePath", "NoSound");
            }
        }
        editor.commit();
        if (requestCode == messageSoundRow || requestCode == groupSoundRow) {
            updateServerNotificationsSettings(requestCode == groupSoundRow);
        }
        adapter.notifyItemChanged(requestCode);
    }
}
 
Example 19
Source File: MentionsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void processFoundUser(TLRPC.User user)
{
    contextUsernameReqid = 0;
    locationProvider.stop();
    if (user != null && user.bot && user.bot_inline_placeholder != null)
    {
        foundContextBot = user;
        if (parentFragment != null)
        {
            TLRPC.Chat chat = parentFragment.getCurrentChat();
            if (chat != null)
            {
                inlineMediaEnabled = ChatObject.canSendStickers(chat);
                if (!inlineMediaEnabled)
                {
                    notifyDataSetChanged();
                    delegate.needChangePanelVisibility(true);
                    return;
                }
            }
        }
        if (foundContextBot.bot_inline_geo)
        {
            SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
            boolean allowGeo = preferences.getBoolean("inlinegeo_" + foundContextBot.id, false);
            if (!allowGeo && parentFragment != null && parentFragment.getParentActivity() != null)
            {
                final TLRPC.User foundContextBotFinal = foundContextBot;
                AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                builder.setTitle(LocaleController.getString("ShareYouLocationTitle", R.string.ShareYouLocationTitle));
                builder.setMessage(LocaleController.getString("ShareYouLocationInline", R.string.ShareYouLocationInline));
                final boolean buttonClicked[] = new boolean[1];
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
                {
                    buttonClicked[0] = true;
                    if (foundContextBotFinal != null)
                    {
                        SharedPreferences preferences1 = MessagesController.getNotificationsSettings(currentAccount);
                        preferences1.edit().putBoolean("inlinegeo_" + foundContextBotFinal.id, true).commit();
                        checkLocationPermissionsOrStart();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) ->
                {
                    buttonClicked[0] = true;
                    onLocationUnavailable();
                });
                parentFragment.showDialog(builder.create(), dialog ->
                {
                    if (!buttonClicked[0])
                    {
                        onLocationUnavailable();
                    }
                });
            }
            else
            {
                checkLocationPermissionsOrStart();
            }
        }
    }
    else
    {
        foundContextBot = null;
        inlineMediaEnabled = true;
    }
    if (foundContextBot == null)
    {
        noUserName = true;
    }
    else
    {
        if (delegate != null)
        {
            delegate.onContextSearch(true);
        }
        searchForContextBotResults(true, foundContextBot, searchingContextQuery, "");
    }
}
 
Example 20
Source File: ProfileNotificationsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (requestCode == 13) {
                    if (ringtone.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
                        name = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                } else {
                    if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                        name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                    } else {
                        name = rng.getTitle(getParentActivity());
                    }
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        } else if (requestCode == 13) {
            if (name != null) {
                editor.putString("ringtone_" + dialog_id, name);
                editor.putString("ringtone_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("ringtone_" + dialog_id, "NoSound");
                editor.putString("ringtone_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        if (adapter != null) {
            adapter.notifyItemChanged(requestCode == 13 ? ringtoneRow : soundRow);
        }
    }
}