mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Implement device volume control actions
using the intent data `launcher:volumeUp` and `launcher:volumeDown`. Related: #68
This commit is contained in:
parent
0957f5bff1
commit
9942b021a8
5 changed files with 75 additions and 16 deletions
|
@ -8,6 +8,7 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.*
|
||||
import android.media.AudioManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
|
@ -30,6 +31,7 @@ import com.finnmglas.launcher.settings.intendedSettingsPause
|
|||
import com.finnmglas.launcher.tutorial.TutorialActivity
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
/* Preferences (global, initialised when app is started) */
|
||||
lateinit var launcherPreferences: SharedPreferences
|
||||
|
||||
|
@ -154,8 +156,10 @@ fun View.fadeRotateIn(duration: Long = 500L) {
|
|||
}
|
||||
)
|
||||
combined.addAnimation(
|
||||
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
||||
RotateAnimation(
|
||||
0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||
0.5f, Animation.RELATIVE_TO_SELF, 0.5f
|
||||
).also {
|
||||
it.duration = duration * 2
|
||||
it.interpolator = DecelerateInterpolator()
|
||||
}
|
||||
|
@ -173,8 +177,10 @@ fun View.fadeRotateOut(duration: Long = 500L) {
|
|||
}
|
||||
)
|
||||
combined.addAnimation(
|
||||
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
||||
RotateAnimation(
|
||||
0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||
0.5f, Animation.RELATIVE_TO_SELF, 0.5f
|
||||
).also {
|
||||
it.duration = duration
|
||||
it.interpolator = AccelerateInterpolator()
|
||||
}
|
||||
|
@ -202,13 +208,17 @@ private fun getIntent(packageName: String, context: Context): Intent? {
|
|||
return intent
|
||||
}
|
||||
|
||||
fun launch(data: String, activity: Activity,
|
||||
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out) {
|
||||
fun launch(
|
||||
data: String, activity: Activity,
|
||||
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out
|
||||
) {
|
||||
|
||||
if (data.startsWith("launcher:")) // [type]:[info]
|
||||
when(data.split(":")[1]) {
|
||||
"settings" -> openSettings(activity)
|
||||
"choose" -> openAppsList(activity)
|
||||
"volumeUp" -> audioVolumeUp(activity)
|
||||
"volumeDown" -> audioVolumeDown(activity)
|
||||
"tutorial" -> openTutorial(activity)
|
||||
}
|
||||
else launchApp(data, activity) // app
|
||||
|
@ -216,6 +226,28 @@ fun launch(data: String, activity: Activity,
|
|||
activity.overridePendingTransition(animationIn, animationOut)
|
||||
}
|
||||
|
||||
fun audioVolumeUp(activity: Activity) {
|
||||
val audioManager =
|
||||
activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
audioManager.adjustStreamVolume(
|
||||
AudioManager.STREAM_MUSIC,
|
||||
AudioManager.ADJUST_RAISE,
|
||||
AudioManager.FLAG_SHOW_UI
|
||||
)
|
||||
}
|
||||
|
||||
fun audioVolumeDown(activity: Activity) {
|
||||
val audioManager =
|
||||
activity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
audioManager.adjustStreamVolume(
|
||||
AudioManager.STREAM_MUSIC,
|
||||
AudioManager.ADJUST_LOWER,
|
||||
AudioManager.FLAG_SHOW_UI
|
||||
)
|
||||
}
|
||||
|
||||
fun launchApp(packageName: String, context: Context) {
|
||||
val intent = getIntent(packageName, context)
|
||||
|
||||
|
@ -224,7 +256,8 @@ fun launchApp(packageName: String, context: Context) {
|
|||
} else {
|
||||
if (isInstalled(packageName, context)){
|
||||
|
||||
AlertDialog.Builder(context,
|
||||
AlertDialog.Builder(
|
||||
context,
|
||||
R.style.AlertDialogCustom
|
||||
)
|
||||
.setTitle(context.getString(R.string.alert_cant_open_title))
|
||||
|
@ -240,7 +273,11 @@ fun launchApp(packageName: String, context: Context) {
|
|||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.show()
|
||||
} else {
|
||||
Toast.makeText( context, context.getString(R.string.toast_cant_open_message), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.toast_cant_open_message),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -399,14 +436,18 @@ fun setWindowFlags(window: Window) {
|
|||
|
||||
// Display notification bar
|
||||
if (launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
)
|
||||
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
|
||||
// Screen Timeout
|
||||
if (launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
)
|
||||
else window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,14 @@ class OtherRecyclerAdapter(val activity: Activity):
|
|||
OtherInfo(activity.getString(R.string.list_other_list),
|
||||
"launcher:choose",
|
||||
activity.getString(R.string.fas_bars)))
|
||||
othersList.add(
|
||||
OtherInfo(activity.getString(R.string.list_other_volume_up),
|
||||
"launcher:volumeUp",
|
||||
activity.getString(R.string.fas_plus)))
|
||||
othersList.add(
|
||||
OtherInfo(activity.getString(R.string.list_other_volume_down),
|
||||
"launcher:volumeDown",
|
||||
activity.getString(R.string.fas_minus)))
|
||||
}
|
||||
|
||||
/* */
|
||||
|
|
|
@ -104,6 +104,10 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
|||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_settings)
|
||||
"choose" ->
|
||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_bars)
|
||||
"volumeUp" ->
|
||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_plus)
|
||||
"volumeDown" ->
|
||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_minus)
|
||||
}
|
||||
} else {
|
||||
// Set image icon (by packageName)
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
<string name="fas_trash" translatable="false"></string>
|
||||
<string name="fas_times" translatable="false"></string> <!-- 'close' -->
|
||||
<string name="fas_three_dots" translatable="false"></string> <!-- 'ellipsis-v' -->
|
||||
<string name="fas_volume_down" translatable="false"></string>
|
||||
<string name="fas_volume_up" translatable="false"></string>
|
||||
<string name="fas_plus" translatable="false"></string>
|
||||
<string name="fas_minus" translatable="false"></string>
|
||||
|
||||
<string name="fas_angle_double_left" translatable="false"></string>
|
||||
<string name="fas_angle_double_right" translatable="false"></string>
|
||||
|
|
|
@ -144,6 +144,8 @@
|
|||
|
||||
<string name="list_other_settings">Launcher Settings</string>
|
||||
<string name="list_other_list">Launcher AppsList</string>
|
||||
<string name="list_other_volume_up">Increase Volume</string>
|
||||
<string name="list_other_volume_down">Decrease Volume</string>
|
||||
|
||||
<!--
|
||||
-
|
||||
|
|
Loading…
Add table
Reference in a new issue