Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Mute button To Live #546

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.0'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ class LiveRideActivity : Activity(), ServiceConnection, LiveRideOverlay.Locator
map = CycleMapView(this, this.javaClass.name, null).apply {
overlayPushBottom(RouteOverlay(this,false))
overlayPushTop(WaymarkOverlay(this))

overlayPushTop(LockScreenOnOverlay(this))
overlayPushTop(RotateMapOverlay(this))
overlayPushTop(MuteButtonOverlay(this))

overlayPushTop(LiveRideOverlay(this@LiveRideActivity, this@LiveRideActivity))
lockOnLocation()
hideLocationButton()
shiftAttribution()
}

Log.e("we are here ", "we are here")

RelativeLayout(this).apply {
addView(map,
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ internal class LiveRideStart(context: Context, tts: TextToSpeech?) : LiveRideSta
journey.setActiveSegmentIndex(0)
Log.d("importantTest", "LiveRideStart Update: ${journey.activeSegment()!!.toString()}")
notify(journey.activeSegment()!!, true)


return HuntForSegment(this)


}

override fun isStopped(): Boolean { return false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.drawable.Icon
import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
Expand All @@ -20,18 +21,25 @@ import net.cyclestreets.routing.Journey
import net.cyclestreets.routing.Segment
import net.cyclestreets.util.Logging
import net.cyclestreets.view.R
import net.cyclestreets.views.overlay.MuteButtonOverlay
import org.osmdroid.util.GeoPoint
import java.util.*
import org.osmdroid.views.MapView

private val TAG = Logging.getTag(LiveRideState::class.java)
private const val NOTIFICATION_ID = 1


internal abstract class LiveRideState(protected val context: Context,
val tts: TextToSpeech?,
private val title: String) {
init {
Log.d(TAG, "New State: " + this.javaClass.simpleName)


}

private val sharedPreferences: SharedPreferences by lazy{
context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE)
}

protected constructor(context: Context, tts: TextToSpeech?):
Expand Down Expand Up @@ -66,14 +74,20 @@ internal abstract class LiveRideState(protected val context: Context,

// checked
protected fun notify(text: String, directionIcon: Int, important: Boolean = false) {
notification(text, text, directionIcon)
speak(text, important)



notification(text, text, directionIcon)
speak(text, important)

}

@JvmOverloads
protected fun notify(text: String, ticker: String = text, important: Boolean = false) {
notification(text, ticker)
speak(text, important)

notification(text, ticker)
speak(text, important)

}

protected fun notifyAndSetServiceForeground(service: Service, text: String) {
Expand Down Expand Up @@ -120,11 +134,28 @@ internal abstract class LiveRideState(protected val context: Context,
return context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}


companion object {
private const val LOCK_PREF = "muteButton"
}



private fun speak(words: String, important: Boolean = false) {
if (important) {
tts?.speak(speechify(words), TextToSpeech.QUEUE_FLUSH, null, UUID.randomUUID().toString())
} else {
tts?.speak(speechify(words), TextToSpeech.QUEUE_ADD, null, UUID.randomUUID().toString())
//mute = false
val muteAudio: Boolean = sharedPreferences.getBoolean("MuteAudio", false)

if(!muteAudio){
Log.i("Is it mute: " , muteAudio.toString())
if (important) {
tts?.speak(speechify(words), TextToSpeech.QUEUE_FLUSH, null, UUID.randomUUID().toString())
} else {
tts?.speak(speechify(words), TextToSpeech.QUEUE_ADD, null, UUID.randomUUID().toString())
}
} else {
Log.i("Is it mute: " , muteAudio.toString())
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class CycleMapView extends FrameLayout
private IGeoPoint centreOn_ = null;
private IGeoPoint foundPlace;
private boolean paused_ = false;
public boolean muteAudio;

public CycleMapView(final Context context, final String name, final Fragment fragment) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package net.cyclestreets.views.overlay


import android.content.Context
import android.content.SharedPreferences

import android.graphics.drawable.Drawable

import android.speech.tts.TextToSpeech

import android.view.LayoutInflater

import android.widget.Toast
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial.Icon.gmd_volume_mute
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial.Icon.gmd_volume_off
import net.cyclestreets.iconics.IconicsHelper.materialIcon
import net.cyclestreets.util.Theme.highlightColor
import net.cyclestreets.util.Theme.lowlightColor
import net.cyclestreets.view.R
import net.cyclestreets.views.CycleMapView

import org.osmdroid.views.overlay.Overlay



private var isAudioOn: Boolean = true


class MuteButtonOverlay(private val mapView: CycleMapView) : Overlay(), PauseResumeListener {

companion object {
private const val LOCK_PREF = "muteButton"
}

private val audioMuteButton: FloatingActionButton
private val onIcon: Drawable
private val offIcon: Drawable
private var muteAudio: Boolean = false
private lateinit var tts: TextToSpeech


init {
val context = mapView.context


onIcon = materialIcon(context, gmd_volume_mute, highlightColor(context))
offIcon = materialIcon(context, gmd_volume_off, lowlightColor(context))

val liveRideButtonView = LayoutInflater.from(context).inflate(R.layout.mutebutton, null)
audioMuteButton = liveRideButtonView.findViewById<FloatingActionButton>(R.id.mute_button).apply {
setOnClickListener { setMuteAudioState() }

}



val sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE)

muteAudio= sharedPreferences.getBoolean("MuteAudio", false)

if (muteAudio){
audioMuteButton.setImageDrawable(offIcon);
} else {
audioMuteButton.setImageDrawable(onIcon);
}


mapView.addView(liveRideButtonView)
}


private fun setMuteAudioState() {

val context = mapView.context

val sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()

muteAudio= sharedPreferences.getBoolean("MuteAudio", false)

if(muteAudio){
audioMuteButton.setImageDrawable(onIcon);

editor.putBoolean("MuteAudio", false)
editor.commit()


} else {
audioMuteButton.setImageDrawable(offIcon);
editor.putBoolean("MuteAudio", true)
editor.commit()
Toast.makeText(mapView.context, "Audio will mute after playing current directions.", Toast.LENGTH_LONG).show()

}

}



override fun onResume(prefs: SharedPreferences) {

val context = mapView.context
val sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE)

muteAudio= sharedPreferences.getBoolean("MuteAudio", false)

if (muteAudio){
audioMuteButton.setImageDrawable(offIcon);
} else {
audioMuteButton.setImageDrawable(onIcon);
}


}

override fun onPause(prefs: SharedPreferences.Editor) {


}

}
21 changes: 21 additions & 0 deletions libraries/cyclestreets-view/src/main/res/layout/mutebutton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/mute_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginTop="178dp"
android:layout_marginEnd="16dp"
app:fabSize="normal"
app:borderWidth="12dp"
app:backgroundTint="@android:color/background_light" />



</androidx.coordinatorlayout.widget.CoordinatorLayout>
2 changes: 1 addition & 1 deletion libraries/cyclestreets-view/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<color name="cs_primary_material_light">@color/material_grey_100</color>

<color name="cs_white">#ffffff</color>

<color name="black">#000000</color>
</resources>