This commit is contained in:
jens 2021-09-26 19:54:17 +02:00
parent e63d97be0c
commit e3598cc475
5 changed files with 92 additions and 18 deletions

View File

@ -621,7 +621,19 @@ public class Actions
} }
} }
public void useDownloadedWebpage(String result) public static void setDND(Context context, int desiredDndMode)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
Miscellaneous.logEvent("i", context.getResources().getString(R.string.soundSettings), "Changing DND to " + String.valueOf(desiredDndMode), 4);
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.setInterruptionFilter(desiredDndMode);
}
else
Miscellaneous.logEvent("w", context.getResources().getString(R.string.soundSettings), "Cannot change DND to " + String.valueOf(desiredDndMode) + ". This Android version is too and doesn\'t have that feature, yet.", 4);
}
public void useDownloadedWebpage(String result)
{ {
// Toast.makeText(context, "Result: " + result, Toast.LENGTH_LONG).show(); // Toast.makeText(context, "Result: " + result, Toast.LENGTH_LONG).show();
} }

View File

@ -128,23 +128,42 @@ public class ActivityManageProfile extends Activity
spinnerSoundMode.setSelection(0); spinnerSoundMode.setSelection(0);
spinnerDndMode.setSelection(0); spinnerDndMode.setSelection(0);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
{
// Disable DND controls
checkBoxChangeDnd.setEnabled(false);
spinnerDndMode.setEnabled(false);
}
// Scale SeekBars to the system's maximum volume values // Scale SeekBars to the system's maximum volume values
AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE); AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE);
seekBarVolumeMusic.setMax(am.getStreamMaxVolume(AudioManager.STREAM_MUSIC)); seekBarVolumeMusic.setMax(am.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seekBarVolumeNotifications.setMax(am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION)); seekBarVolumeNotifications.setMax(am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION));
seekBarVolumeAlarms.setMax(am.getStreamMaxVolume(AudioManager.STREAM_ALARM)); seekBarVolumeAlarms.setMax(am.getStreamMaxVolume(AudioManager.STREAM_ALARM));
soundModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[] { getResources().getString(R.string.soundModeSilent), getResources().getString(R.string.soundModeVibrate), getResources().getString(R.string.soundModeNormal) }); soundModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[]
{
getResources().getString(R.string.soundModeSilent),
getResources().getString(R.string.soundModeVibrate),
getResources().getString(R.string.soundModeNormal)
});
spinnerSoundMode.setAdapter(soundModeAdapter); spinnerSoundMode.setAdapter(soundModeAdapter);
dndModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[] { getResources().getString(R.string.dndOff), getResources().getString(R.string.dndPriority), getResources().getString(R.string.dndAlarms), getResources().getString(R.string.dndNothing) }); dndModeAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, new String[]
{
getResources().getString(R.string.dndOff),
getResources().getString(R.string.dndPriority),
getResources().getString(R.string.dndNothing),
getResources().getString(R.string.dndAlarms)
});
spinnerDndMode.setAdapter(dndModeAdapter); spinnerDndMode.setAdapter(dndModeAdapter);
/* /*
Order in spinner: 1, 2, 4, 3
NotificationManager.INTERRUPTION_FILTER_UNKNOWN -> Returned when the value is unavailable for any reason. NotificationManager.INTERRUPTION_FILTER_UNKNOWN -> Returned when the value is unavailable for any reason.
NotificationManager.INTERRUPTION_FILTER_ALL -> Normal interruption filter - no notifications are suppressed. -> essentially turn off DND NotificationManager.INTERRUPTION_FILTER_ALL -> 1 -> Normal interruption filter - no notifications are suppressed. -> essentially turn off DND
NotificationManager.INTERRUPTION_FILTER_PRIORITY -> Priority interruption filter - all notifications are suppressed except those that match the priority criteria. NotificationManager.INTERRUPTION_FILTER_PRIORITY -> 2 -> Priority interruption filter - all notifications are suppressed except those that match the priority criteria.
NotificationManager.INTERRUPTION_FILTER_ALARMS -> Alarms only interruption filter - all notifications except those of category NotificationManager.INTERRUPTION_FILTER_ALARMS -> 4 -> Alarms only interruption filter - all notifications except those of category
NotificationManager.INTERRUPTION_FILTER_NONE -> No interruptions filter - all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted. NotificationManager.INTERRUPTION_FILTER_NONE -> 3 -> No interruptions filter - all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted.
*/ */
checkBoxChangeSoundMode.setOnCheckedChangeListener(new OnCheckedChangeListener() checkBoxChangeSoundMode.setOnCheckedChangeListener(new OnCheckedChangeListener()
@ -351,6 +370,7 @@ public class ActivityManageProfile extends Activity
{ {
etName.setText(ActivityMainProfiles.profileToEdit.getName()); etName.setText(ActivityMainProfiles.profileToEdit.getName());
checkBoxChangeSoundMode.setChecked(ActivityMainProfiles.profileToEdit.getChangeSoundMode()); checkBoxChangeSoundMode.setChecked(ActivityMainProfiles.profileToEdit.getChangeSoundMode());
checkBoxChangeDnd.setChecked(ActivityMainProfiles.profileToEdit.getChangeDndMode());
checkBoxChangeVolumeMusicVideoGameMedia.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeMusicVideoGameMedia()); checkBoxChangeVolumeMusicVideoGameMedia.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeMusicVideoGameMedia());
checkBoxChangeVolumeNotifications.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeNotifications()); checkBoxChangeVolumeNotifications.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeNotifications());
checkBoxChangeVolumeAlarms.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeAlarms()); checkBoxChangeVolumeAlarms.setChecked(ActivityMainProfiles.profileToEdit.getChangeVolumeAlarms());
@ -362,6 +382,7 @@ public class ActivityManageProfile extends Activity
checkBoxChangeVibrateWhenRinging.setChecked(ActivityMainProfiles.profileToEdit.getChangeVibrateWhenRinging()); checkBoxChangeVibrateWhenRinging.setChecked(ActivityMainProfiles.profileToEdit.getChangeVibrateWhenRinging());
spinnerSoundMode.setSelection(ActivityMainProfiles.profileToEdit.getSoundMode()); spinnerSoundMode.setSelection(ActivityMainProfiles.profileToEdit.getSoundMode());
spinnerDndMode.setSelection(ActivityMainProfiles.profileToEdit.getDndMode()-1);
seekBarVolumeMusic.setProgress(ActivityMainProfiles.profileToEdit.getVolumeMusic()); seekBarVolumeMusic.setProgress(ActivityMainProfiles.profileToEdit.getVolumeMusic());
seekBarVolumeNotifications.setProgress(ActivityMainProfiles.profileToEdit.getVolumeNotifications()); seekBarVolumeNotifications.setProgress(ActivityMainProfiles.profileToEdit.getVolumeNotifications());
seekBarVolumeAlarms.setProgress(ActivityMainProfiles.profileToEdit.getVolumeAlarms()); seekBarVolumeAlarms.setProgress(ActivityMainProfiles.profileToEdit.getVolumeAlarms());
@ -383,6 +404,7 @@ public class ActivityManageProfile extends Activity
ActivityMainProfiles.profileToEdit.setName(etName.getText().toString()); ActivityMainProfiles.profileToEdit.setName(etName.getText().toString());
ActivityMainProfiles.profileToEdit.setChangeSoundMode(checkBoxChangeSoundMode.isChecked()); ActivityMainProfiles.profileToEdit.setChangeSoundMode(checkBoxChangeSoundMode.isChecked());
ActivityMainProfiles.profileToEdit.setChangeDndMode(checkBoxChangeDnd.isChecked());
ActivityMainProfiles.profileToEdit.setChangeVolumeMusicVideoGameMedia(checkBoxChangeVolumeMusicVideoGameMedia.isChecked()); ActivityMainProfiles.profileToEdit.setChangeVolumeMusicVideoGameMedia(checkBoxChangeVolumeMusicVideoGameMedia.isChecked());
ActivityMainProfiles.profileToEdit.setChangeVolumeNotifications(checkBoxChangeVolumeNotifications.isChecked()); ActivityMainProfiles.profileToEdit.setChangeVolumeNotifications(checkBoxChangeVolumeNotifications.isChecked());
ActivityMainProfiles.profileToEdit.setChangeVolumeAlarms(checkBoxChangeVolumeAlarms.isChecked()); ActivityMainProfiles.profileToEdit.setChangeVolumeAlarms(checkBoxChangeVolumeAlarms.isChecked());
@ -398,6 +420,7 @@ public class ActivityManageProfile extends Activity
ActivityMainProfiles.profileToEdit.setHapticFeedback(checkBoxHapticFeedback.isChecked()); ActivityMainProfiles.profileToEdit.setHapticFeedback(checkBoxHapticFeedback.isChecked());
ActivityMainProfiles.profileToEdit.setVibrateWhenRinging(checkBoxVibrateWhenRinging.isChecked()); ActivityMainProfiles.profileToEdit.setVibrateWhenRinging(checkBoxVibrateWhenRinging.isChecked());
ActivityMainProfiles.profileToEdit.setSoundMode(spinnerSoundMode.getSelectedItemPosition()); ActivityMainProfiles.profileToEdit.setSoundMode(spinnerSoundMode.getSelectedItemPosition());
ActivityMainProfiles.profileToEdit.setDndMode(spinnerDndMode.getSelectedItemPosition()+1);
ActivityMainProfiles.profileToEdit.setVolumeMusic(seekBarVolumeMusic.getProgress()); ActivityMainProfiles.profileToEdit.setVolumeMusic(seekBarVolumeMusic.getProgress());
ActivityMainProfiles.profileToEdit.setVolumeNotifications(seekBarVolumeNotifications.getProgress()); ActivityMainProfiles.profileToEdit.setVolumeNotifications(seekBarVolumeNotifications.getProgress());
ActivityMainProfiles.profileToEdit.setVolumeAlarms(seekBarVolumeAlarms.getProgress()); ActivityMainProfiles.profileToEdit.setVolumeAlarms(seekBarVolumeAlarms.getProgress());
@ -425,21 +448,23 @@ public class ActivityManageProfile extends Activity
} }
if(!checkBoxChangeSoundMode.isChecked() if(!checkBoxChangeSoundMode.isChecked()
& &&
!checkBoxChangeDnd.isChecked()
&&
!checkBoxChangeVolumeMusicVideoGameMedia.isChecked() !checkBoxChangeVolumeMusicVideoGameMedia.isChecked()
& &&
!checkBoxChangeVolumeNotifications.isChecked() !checkBoxChangeVolumeNotifications.isChecked()
& &&
!checkBoxChangeVolumeAlarms.isChecked() !checkBoxChangeVolumeAlarms.isChecked()
& &&
!checkBoxChangeIncomingCallsRingtone.isChecked() !checkBoxChangeIncomingCallsRingtone.isChecked()
& &&
!checkBoxChangeNotificationRingtone.isChecked() !checkBoxChangeNotificationRingtone.isChecked()
& &&
!checkBoxChangeAudibleSelection.isChecked() !checkBoxChangeAudibleSelection.isChecked()
& &&
!checkBoxChangeScreenLockUnlockSound.isChecked() !checkBoxChangeScreenLockUnlockSound.isChecked()
& &&
!checkBoxChangeHapticFeedback.isChecked() !checkBoxChangeHapticFeedback.isChecked()
) )
{ {

View File

@ -698,8 +698,8 @@ public class Miscellaneous extends Service
*/ */
public static boolean isPhoneRooted() public static boolean isPhoneRooted()
{ {
if(true) // if(true)
return true; // return true;
// get from build info // get from build info
String buildTags = Build.TAGS; String buildTags = Build.TAGS;

View File

@ -24,6 +24,9 @@ public class Profile implements Comparable<Profile>
protected boolean changeSoundMode; protected boolean changeSoundMode;
protected int soundMode; protected int soundMode;
protected boolean changeDndMode;
protected int dndMode;
boolean changeVolumeMusicVideoGameMedia; boolean changeVolumeMusicVideoGameMedia;
protected int volumeMusic; protected int volumeMusic;
@ -81,6 +84,26 @@ public class Profile implements Comparable<Profile>
return soundMode; return soundMode;
} }
public boolean getChangeDndMode()
{
return changeDndMode;
}
public void setChangeDndMode(boolean changeDndMode)
{
this.changeDndMode = changeDndMode;
}
public int getDndMode()
{
return dndMode;
}
public void setDndMode(int dndMode)
{
this.dndMode = dndMode;
}
public void setChangeVolumeMusicVideoGameMedia(boolean changeVolumeMusicVideoGameMedia) public void setChangeVolumeMusicVideoGameMedia(boolean changeVolumeMusicVideoGameMedia)
{ {
this.changeVolumeMusicVideoGameMedia = changeVolumeMusicVideoGameMedia; this.changeVolumeMusicVideoGameMedia = changeVolumeMusicVideoGameMedia;
@ -450,6 +473,9 @@ public class Profile implements Comparable<Profile>
if(changeSoundMode) if(changeSoundMode)
Actions.setSound(context, soundMode); Actions.setSound(context, soundMode);
if(changeDndMode)
Actions.setDND(context, dndMode);
if(changeVolumeMusicVideoGameMedia) if(changeVolumeMusicVideoGameMedia)
am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND); am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND);

View File

@ -206,6 +206,13 @@ public class XmlFileInterface
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getHapticFeedback())); serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getHapticFeedback()));
serializer.endTag(null, "hapticFeedback"); serializer.endTag(null, "hapticFeedback");
serializer.startTag(null, "changeDndMode");
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeDndMode()));
serializer.endTag(null, "changeDndMode");//
serializer.startTag(null, "dndMode");
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getDndMode()));
serializer.endTag(null, "dndMode");
serializer.endTag(null, "Profile"); serializer.endTag(null, "Profile");
} }
serializer.endTag(null, "ProfileCollection"); serializer.endTag(null, "ProfileCollection");
@ -607,6 +614,10 @@ public class XmlFileInterface
newProfile.setChangeSoundMode(Boolean.parseBoolean(readTag(parser, "changeSoundMode"))); newProfile.setChangeSoundMode(Boolean.parseBoolean(readTag(parser, "changeSoundMode")));
else if (name.equals("soundMode")) else if (name.equals("soundMode"))
newProfile.setSoundMode(Integer.parseInt(readTag(parser, "soundMode"))); newProfile.setSoundMode(Integer.parseInt(readTag(parser, "soundMode")));
else if (name.equals("changeDndMode"))
newProfile.setChangeDndMode(Boolean.parseBoolean(readTag(parser, "changeDndMode")));
else if (name.equals("dndMode"))
newProfile.setDndMode(Integer.parseInt(readTag(parser, "dndMode")));
else if (name.equals("changeVolumeMusicVideoGameMedia")) else if (name.equals("changeVolumeMusicVideoGameMedia"))
newProfile.setChangeVolumeMusicVideoGameMedia(Boolean.parseBoolean(readTag(parser, "changeVolumeMusicVideoGameMedia"))); newProfile.setChangeVolumeMusicVideoGameMedia(Boolean.parseBoolean(readTag(parser, "changeVolumeMusicVideoGameMedia")));
else if (name.equals("volumeMusic")) else if (name.equals("volumeMusic"))