diff --git a/app/src/main/java/de/felixnuesse/timedsilence/MainActivity.kt b/app/src/main/java/de/felixnuesse/timedsilence/MainActivity.kt index 0bc2dd1..196b7ff 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/MainActivity.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/MainActivity.kt @@ -103,7 +103,7 @@ class MainActivity : AppCompatActivity(), TimerInterface { supportActionBar?.setDisplayShowTitleEnabled(false) mTrigger = Trigger(this) - mVolumeHandler = VolumeHandler(this) + mVolumeHandler = VolumeHandler(this, "MainActivity") button_check = getString(R.string.timecheck_stopped) diff --git a/app/src/main/java/de/felixnuesse/timedsilence/handler/volume/VolumeHandler.kt b/app/src/main/java/de/felixnuesse/timedsilence/handler/volume/VolumeHandler.kt index 6acc8a0..5f123f9 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/handler/volume/VolumeHandler.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/handler/volume/VolumeHandler.kt @@ -43,7 +43,7 @@ import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SET import de.felixnuesse.timedsilence.util.PermissionManager import de.felixnuesse.timedsilence.extensions.TAG -class VolumeHandler(private var mContext: Context) { +class VolumeHandler(private var mContext: Context, private var mInstanceContext: String) { private var mPreferencesManager = PreferencesManager(mContext) private var volumeState = VolumeState(PreferencesManager(mContext).getDefaultUnsetVolume()) @@ -77,7 +77,7 @@ class VolumeHandler(private var mContext: Context) { } private fun applySilent() { - Log.e(TAG(), "VolumeHandler: Apply: Silent!") + Log.e(TAG(), "VolumeHandler - $mInstanceContext: Apply: Silent!") val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager @@ -94,7 +94,7 @@ class VolumeHandler(private var mContext: Context) { if(mPreferencesManager.changeRingerVolume()){ - Log.d(TAG(), "VolumeHandler: Setting Ringer! This might be not what you want!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Ringer! This might be not what you want!") setStreamToPercent( manager, AudioManager.STREAM_RING, @@ -113,7 +113,7 @@ class VolumeHandler(private var mContext: Context) { } private fun applyLoud() { - Log.d(TAG(), "VolumeHandler: Apply: Loud!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Loud!") val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager val mNotificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager? @@ -132,9 +132,9 @@ class VolumeHandler(private var mContext: Context) { setMediaVolume(mediaVolume, manager) } - Log.d(TAG(), "VolumeHandler: STREAM_MEDIA: $mediaVolume") - Log.d(TAG(), "VolumeHandler: STREAM_ALARM: $alarmVolume") - Log.d(TAG(), "VolumeHandler: STREAM_NOTIFICATION: $notifcationVolume") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_MEDIA: $mediaVolume") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_ALARM: $alarmVolume") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_NOTIFICATION: $notifcationVolume") setStreamToPercent( @@ -149,8 +149,8 @@ class VolumeHandler(private var mContext: Context) { ) if(mPreferencesManager.changeRingerVolume()){ - Log.d(TAG(), "VolumeHandler: STREAM_RING: $ringerVolume") - Log.d(TAG(), "VolumeHandler: Setting Ringer! This might be not what you want!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_RING: $ringerVolume") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Ringer! This might be not what you want!") setStreamToPercent( manager, AudioManager.STREAM_RING, @@ -161,7 +161,7 @@ class VolumeHandler(private var mContext: Context) { } private fun applyVibrate() { - Log.d(TAG(), "VolumeHandler: Apply: Vibrate!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Vibrate!") val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager val mNotificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager? @@ -190,7 +190,7 @@ class VolumeHandler(private var mContext: Context) { ) if(mPreferencesManager.changeRingerVolume()){ - Log.d(TAG(), "VolumeHandler: Silencing Ringer! This might be not what you want!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Silencing Ringer! This might be not what you want!") setStreamToPercent( manager, AudioManager.STREAM_RING, @@ -208,11 +208,11 @@ class VolumeHandler(private var mContext: Context) { private fun setMediaVolume(percentage: Int, manager: AudioManager){ - Log.d(TAG(), "VolumeHandler: Setting Audio Volume!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Audio Volume!") val ignoreCheckWhenConnected = mPreferencesManager.checkIfHeadsetIsConnected() if(HeadsetHandler.headphonesConnected(mContext) && ignoreCheckWhenConnected){ - Log.d(TAG(), "VolumeHandler: Found headset, skipping...") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Found headset, skipping...") return } @@ -221,11 +221,11 @@ class VolumeHandler(private var mContext: Context) { AudioManager.STREAM_MUSIC, percentage ) - Log.d(TAG(), "VolumeHandler: Mediavolume set.") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Mediavolume set.") } fun isButtonClickAudible(): Boolean{ - Log.d(TAG(), "VolumeHandler: Check if Buttonclicks are audible") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Check if Buttonclicks are audible") val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager if(0>=manager.getStreamVolume(AudioManager.STREAM_RING)){ return false @@ -235,29 +235,29 @@ class VolumeHandler(private var mContext: Context) { fun applyVolume(){ if(!PermissionManager(mContext).grantedDoNotDisturbAndNotify()){ - Log.d(TAG(), "VolumeHandler: VolumeSetting: Do not disturb not granted! Not changing Volume!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: VolumeSetting: Do not disturb not granted! Not changing Volume!") return } - Log.d(TAG(), "VolumeHandler: VolumeSetting: ${getVolume()}") - LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(getVolume())} - ${volumeState.getReason()}") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: VolumeSetting: ${getVolume()}") + LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(getVolume())} - ${volumeState.getReason()}") when (getVolume()) { TIME_SETTING_SILENT -> { applySilent() - LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_SILENT)} - ${volumeState.getReason()}") + LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_SILENT)} - ${volumeState.getReason()}") } TIME_SETTING_VIBRATE -> { applyVibrate() - LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_VIBRATE)} - ${volumeState.getReason()}") + LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_VIBRATE)} - ${volumeState.getReason()}") } TIME_SETTING_LOUD -> { applyLoud() - LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_LOUD)} - ${volumeState.getReason()}") + LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_LOUD)} - ${volumeState.getReason()}") } else -> { - Log.d(TAG(), "VolumeHandler: Apply: Nothing, because no volume was selecteds!") - LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","Nothing, because no volume was selected!") + Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Nothing, because no volume was selecteds!") + LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","Nothing, because no volume was selected!") } } } diff --git a/app/src/main/java/de/felixnuesse/timedsilence/receiver/AlarmBroadcastReciever.kt b/app/src/main/java/de/felixnuesse/timedsilence/receiver/AlarmBroadcastReciever.kt index eee41e3..b3dc331 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/receiver/AlarmBroadcastReciever.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/receiver/AlarmBroadcastReciever.kt @@ -57,7 +57,7 @@ class AlarmBroadcastReciever : BroadcastReceiver() { if (intent?.getStringExtra(Constants.BROADCAST_INTENT_ACTION).equals(Constants.BROADCAST_INTENT_ACTION_UPDATE_VOLUME)) { Log.d(TAG(), "Alarmintent: Content is to \"check the time\"") - VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) + VolumeHandler(context, "AlarmBroadcastReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) Trigger(context).createAlarmIntime() } diff --git a/app/src/main/java/de/felixnuesse/timedsilence/receiver/BluetoothBroadcastReciever.kt b/app/src/main/java/de/felixnuesse/timedsilence/receiver/BluetoothBroadcastReciever.kt index 5da2cf1..8495bc1 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/receiver/BluetoothBroadcastReciever.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/receiver/BluetoothBroadcastReciever.kt @@ -33,7 +33,7 @@ class BluetoothBroadcastReciever : BroadcastReceiver(){ HeadsetHandler.getPairedDevicesWithDatabaseState(context).forEach { if(address == it.address) { - val volumeHandler = VolumeHandler(context) + val volumeHandler = VolumeHandler(context, "BluetoothBroadcastReciever") volumeHandler.ignoreMusicPlaying(true) val state = VolumeState(it.volumeState) @@ -72,7 +72,7 @@ class BluetoothBroadcastReciever : BroadcastReceiver(){ } if(Trigger(context).checkIfNextAlarmExists()){ - var volumeHandler = VolumeHandler(context) + var volumeHandler = VolumeHandler(context, "BluetoothBroadcastReciever") // is this what we want? Override existing playing content? // yes, but only if the device we are loosing are headphones. // Todo: Check if headphones disconnected! diff --git a/app/src/main/java/de/felixnuesse/timedsilence/receiver/BootReciever.kt b/app/src/main/java/de/felixnuesse/timedsilence/receiver/BootReciever.kt index 16b546c..3586a38 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/receiver/BootReciever.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/receiver/BootReciever.kt @@ -15,7 +15,7 @@ class BootReciever : BroadcastReceiver(){ override fun onReceive(context: Context, intent: Intent) { if(intent.action==Intent.ACTION_BOOT_COMPLETED){ Log.e(TAG(), "BootReciever: Started Device!") - VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) + VolumeHandler(context, "BootReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) val prefs = PreferencesManager(context) diff --git a/app/src/main/java/de/felixnuesse/timedsilence/receiver/NoisyBroadcastReciever.kt b/app/src/main/java/de/felixnuesse/timedsilence/receiver/NoisyBroadcastReciever.kt index 5d97d41..659a6b4 100644 --- a/app/src/main/java/de/felixnuesse/timedsilence/receiver/NoisyBroadcastReciever.kt +++ b/app/src/main/java/de/felixnuesse/timedsilence/receiver/NoisyBroadcastReciever.kt @@ -14,7 +14,7 @@ class NoisyBroadcastReciever : BroadcastReceiver(){ override fun onReceive(context: Context, intent: Intent) { if (intent.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) { Log.e(TAG(), "NoisyBroadcastReciever: Becoming Noisy! Checking Volume Again!") - VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) + VolumeHandler(context, "NoisyBroadcastReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis())) } }