mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Implement audio track control actions
Play next / previous tracks through launcher actions.
This commit is contained in:
parent
9942b021a8
commit
4959d54f8b
5 changed files with 56 additions and 1 deletions
|
@ -12,8 +12,10 @@ import android.media.AudioManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.SystemClock
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
|
import android.view.KeyEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
@ -23,6 +25,7 @@ import android.widget.Button
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import com.finnmglas.launcher.list.ListActivity
|
import com.finnmglas.launcher.list.ListActivity
|
||||||
import com.finnmglas.launcher.list.apps.AppInfo
|
import com.finnmglas.launcher.list.apps.AppInfo
|
||||||
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
||||||
|
@ -219,6 +222,8 @@ fun launch(
|
||||||
"choose" -> openAppsList(activity)
|
"choose" -> openAppsList(activity)
|
||||||
"volumeUp" -> audioVolumeUp(activity)
|
"volumeUp" -> audioVolumeUp(activity)
|
||||||
"volumeDown" -> audioVolumeDown(activity)
|
"volumeDown" -> audioVolumeDown(activity)
|
||||||
|
"nextTrack" -> audioNextTrack(activity)
|
||||||
|
"previousTrack" -> audioPreviousTrack(activity)
|
||||||
"tutorial" -> openTutorial(activity)
|
"tutorial" -> openTutorial(activity)
|
||||||
}
|
}
|
||||||
else launchApp(data, activity) // app
|
else launchApp(data, activity) // app
|
||||||
|
@ -226,6 +231,38 @@ fun launch(
|
||||||
activity.overridePendingTransition(animationIn, animationOut)
|
activity.overridePendingTransition(animationIn, animationOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Media player actions */
|
||||||
|
|
||||||
|
fun audioNextTrack(activity: Activity) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 19) { // requires Android KitKat +
|
||||||
|
val mAudioManager = activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
|
||||||
|
val eventTime: Long = SystemClock.uptimeMillis()
|
||||||
|
|
||||||
|
val downEvent =
|
||||||
|
KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
|
||||||
|
mAudioManager.dispatchMediaKeyEvent(downEvent)
|
||||||
|
|
||||||
|
val upEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
|
||||||
|
mAudioManager.dispatchMediaKeyEvent(upEvent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun audioPreviousTrack(activity: Activity) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 19) { // requires Android KitKat +
|
||||||
|
val mAudioManager = activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
|
||||||
|
val eventTime: Long = SystemClock.uptimeMillis()
|
||||||
|
|
||||||
|
val downEvent =
|
||||||
|
KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0)
|
||||||
|
mAudioManager.dispatchMediaKeyEvent(downEvent)
|
||||||
|
|
||||||
|
val upEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0)
|
||||||
|
mAudioManager.dispatchMediaKeyEvent(upEvent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun audioVolumeUp(activity: Activity) {
|
fun audioVolumeUp(activity: Activity) {
|
||||||
val audioManager =
|
val audioManager =
|
||||||
activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
@ -248,6 +285,8 @@ fun audioVolumeDown(activity: Activity) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
fun launchApp(packageName: String, context: Context) {
|
fun launchApp(packageName: String, context: Context) {
|
||||||
val intent = getIntent(packageName, context)
|
val intent = getIntent(packageName, context)
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,16 @@ class OtherRecyclerAdapter(val activity: Activity):
|
||||||
OtherInfo(activity.getString(R.string.list_other_volume_down),
|
OtherInfo(activity.getString(R.string.list_other_volume_down),
|
||||||
"launcher:volumeDown",
|
"launcher:volumeDown",
|
||||||
activity.getString(R.string.fas_minus)))
|
activity.getString(R.string.fas_minus)))
|
||||||
|
othersList.add(
|
||||||
|
OtherInfo(activity.getString(R.string.list_other_track_next),
|
||||||
|
"launcher:nextTrack",
|
||||||
|
activity.getString(R.string.fas_forward)))
|
||||||
|
othersList.add(
|
||||||
|
OtherInfo(activity.getString(R.string.list_other_track_previous),
|
||||||
|
"launcher:previousTrack",
|
||||||
|
activity.getString(R.string.fas_back)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
|
||||||
private fun returnChoiceIntent(forAction: String, value: String) {
|
private fun returnChoiceIntent(forAction: String, value: String) {
|
||||||
val returnIntent = Intent()
|
val returnIntent = Intent()
|
||||||
returnIntent.putExtra("value", value)
|
returnIntent.putExtra("value", value)
|
||||||
|
|
|
@ -108,6 +108,10 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
||||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_plus)
|
viewHolder.fontAwesome.text = activity.getString(R.string.fas_plus)
|
||||||
"volumeDown" ->
|
"volumeDown" ->
|
||||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_minus)
|
viewHolder.fontAwesome.text = activity.getString(R.string.fas_minus)
|
||||||
|
"nextTrack" ->
|
||||||
|
viewHolder.fontAwesome.text = activity.getString(R.string.fas_forward)
|
||||||
|
"previousTrack" ->
|
||||||
|
viewHolder.fontAwesome.text = activity.getString(R.string.fas_back)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Set image icon (by packageName)
|
// Set image icon (by packageName)
|
||||||
|
|
|
@ -13,10 +13,13 @@
|
||||||
<string name="fas_trash" translatable="false"></string>
|
<string name="fas_trash" translatable="false"></string>
|
||||||
<string name="fas_times" translatable="false"></string> <!-- 'close' -->
|
<string name="fas_times" translatable="false"></string> <!-- 'close' -->
|
||||||
<string name="fas_three_dots" translatable="false"></string> <!-- 'ellipsis-v' -->
|
<string name="fas_three_dots" translatable="false"></string> <!-- 'ellipsis-v' -->
|
||||||
|
|
||||||
<string name="fas_volume_down" translatable="false"></string>
|
<string name="fas_volume_down" translatable="false"></string>
|
||||||
<string name="fas_volume_up" translatable="false"></string>
|
<string name="fas_volume_up" translatable="false"></string>
|
||||||
<string name="fas_plus" translatable="false"></string>
|
<string name="fas_plus" translatable="false"></string>
|
||||||
<string name="fas_minus" translatable="false"></string>
|
<string name="fas_minus" translatable="false"></string>
|
||||||
|
<string name="fas_back" translatable="false"></string>
|
||||||
|
<string name="fas_forward" translatable="false"></string>
|
||||||
|
|
||||||
<string name="fas_angle_double_left" translatable="false"></string>
|
<string name="fas_angle_double_left" translatable="false"></string>
|
||||||
<string name="fas_angle_double_right" translatable="false"></string>
|
<string name="fas_angle_double_right" translatable="false"></string>
|
||||||
|
|
|
@ -146,6 +146,8 @@
|
||||||
<string name="list_other_list">Launcher AppsList</string>
|
<string name="list_other_list">Launcher AppsList</string>
|
||||||
<string name="list_other_volume_up">Increase Volume</string>
|
<string name="list_other_volume_up">Increase Volume</string>
|
||||||
<string name="list_other_volume_down">Decrease Volume</string>
|
<string name="list_other_volume_down">Decrease Volume</string>
|
||||||
|
<string name="list_other_track_next">Music: Next Track</string>
|
||||||
|
<string name="list_other_track_previous">Music: Previous Track</string>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
-
|
-
|
||||||
|
|
Loading…
Add table
Reference in a new issue