Skip to content

Commit

Permalink
Merge pull request #15 from Steve-Mr/dev
Browse files Browse the repository at this point in the history
细节改进,但细节仍然不行
  • Loading branch information
Steve-Mr authored Jun 12, 2023
2 parents 47dd528 + 20f57a1 commit 823a352
Show file tree
Hide file tree
Showing 36 changed files with 197 additions and 163 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
minSdk 31
targetSdk 33
versionCode 3
versionName "2.0_alpha"
versionName "2.0_beta"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
android:exported="true">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
<action android:name="com.maary.liveinpeace.ACTION_FOREGROUND_SERVICE_STATE"/>
</intent-filter>
</service>

Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/main/java/com/maary/liveinpeace/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Constants {
const val SHARED_PREF = "com.maary.liveinpeace.pref"
// 图标类型的 SharedPref 项目名称
const val PREF_ICON = "icon_type"
const val PREF_NOTIFY_TEXT_SIZE = "notification_text_size"
const val PREF_WATCHING_CONNECTING_TIME = "watching_connecting"
// 设置通知 id
const val ID_NOTIFICATION_SETTINGS = 3
Expand All @@ -30,6 +31,9 @@ class Constants {
const val ACTION_NAME_SETTINGS = "com.maary.liveinpeace.receiver.SettingsReceiver"
// 静音广播名称
const val BROADCAST_ACTION_MUTE = "com.maary.liveinpeace.MUTE_MEDIA"
// 前台服务状态改变广播
const val BROADCAST_ACTION_FOREGROUND = "com.maary.liveinpeace.ACTION_FOREGROUND_SERVICE_STATE"
const val BROADCAST_FOREGROUND_INTENT_EXTRA = "isForegroundServiceRunning"
// 当音量操作动作太过频繁后等待时间
const val REQUESTING_WAIT_MILLIS = 500
// 不同通知频道 ID
Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/com/maary/liveinpeace/DeviceTimer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.maary.liveinpeace

import android.annotation.SuppressLint
import android.app.Notification
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat

class DeviceTimer(private val context: Context, private val deviceName: String) {
private val handler = Handler(Looper.getMainLooper())

@SuppressLint("MissingPermission")
private val runnable = Runnable {
with(NotificationManagerCompat.from(context)) {
notify(Constants.ID_NOTIFICATION_ALERT, createTimerNotification(context = context, deviceName = deviceName))
}
}

fun start() {
handler.postDelayed(runnable, Constants.ALERT_TIME)
Log.v("MUTE_TIMER", "TIMER_STARTED")
}

fun stop() {
handler.removeCallbacks(runnable)

}

private fun createTimerNotification(context: Context, deviceName: String) : Notification {
return NotificationCompat.Builder(context, Constants.CHANNEL_ID_ALERT)
.setContentTitle(context.getString(R.string.alert))
.setContentText(String.format(
context.resources.getString(R.string.device_connected_too_long),
deviceName
))
.setSmallIcon(R.drawable.ic_headphone)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setGroupSummary(false)
.setGroup(Constants.ID_NOTIFICATION_GROUP_ALERTS)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.util.Log
import com.maary.liveinpeace.Constants

class MuteMediaReceiver: BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
if (p1?.action == Constants.BROADCAST_ACTION_MUTE){
Log.v("MUTE_", "TRIGGERED")
val audioManager = p0?.getSystemService(Context.AUDIO_SERVICE) as AudioManager
// audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0)
do {
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0)
// Thread.sleep(FADE_STEP_MILLIS)
} while (audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) > 0)
}
}
Expand Down
Loading

0 comments on commit 823a352

Please sign in to comment.