mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +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.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
|
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
|
||||||
|
@ -30,6 +31,7 @@ import com.finnmglas.launcher.settings.intendedSettingsPause
|
||||||
import com.finnmglas.launcher.tutorial.TutorialActivity
|
import com.finnmglas.launcher.tutorial.TutorialActivity
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
/* Preferences (global, initialised when app is started) */
|
/* Preferences (global, initialised when app is started) */
|
||||||
lateinit var launcherPreferences: SharedPreferences
|
lateinit var launcherPreferences: SharedPreferences
|
||||||
|
|
||||||
|
@ -154,8 +156,10 @@ fun View.fadeRotateIn(duration: Long = 500L) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
combined.addAnimation(
|
combined.addAnimation(
|
||||||
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
RotateAnimation(
|
||||||
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||||
|
0.5f, Animation.RELATIVE_TO_SELF, 0.5f
|
||||||
|
).also {
|
||||||
it.duration = duration * 2
|
it.duration = duration * 2
|
||||||
it.interpolator = DecelerateInterpolator()
|
it.interpolator = DecelerateInterpolator()
|
||||||
}
|
}
|
||||||
|
@ -173,8 +177,10 @@ fun View.fadeRotateOut(duration: Long = 500L) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
combined.addAnimation(
|
combined.addAnimation(
|
||||||
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
RotateAnimation(
|
||||||
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||||
|
0.5f, Animation.RELATIVE_TO_SELF, 0.5f
|
||||||
|
).also {
|
||||||
it.duration = duration
|
it.duration = duration
|
||||||
it.interpolator = AccelerateInterpolator()
|
it.interpolator = AccelerateInterpolator()
|
||||||
}
|
}
|
||||||
|
@ -202,13 +208,17 @@ private fun getIntent(packageName: String, context: Context): Intent? {
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launch(data: String, activity: Activity,
|
fun launch(
|
||||||
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out) {
|
data: String, activity: Activity,
|
||||||
|
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out
|
||||||
|
) {
|
||||||
|
|
||||||
if (data.startsWith("launcher:")) // [type]:[info]
|
if (data.startsWith("launcher:")) // [type]:[info]
|
||||||
when(data.split(":")[1]) {
|
when(data.split(":")[1]) {
|
||||||
"settings" -> openSettings(activity)
|
"settings" -> openSettings(activity)
|
||||||
"choose" -> openAppsList(activity)
|
"choose" -> openAppsList(activity)
|
||||||
|
"volumeUp" -> audioVolumeUp(activity)
|
||||||
|
"volumeDown" -> audioVolumeDown(activity)
|
||||||
"tutorial" -> openTutorial(activity)
|
"tutorial" -> openTutorial(activity)
|
||||||
}
|
}
|
||||||
else launchApp(data, activity) // app
|
else launchApp(data, activity) // app
|
||||||
|
@ -216,6 +226,28 @@ fun launch(data: String, activity: Activity,
|
||||||
activity.overridePendingTransition(animationIn, animationOut)
|
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) {
|
fun launchApp(packageName: String, context: Context) {
|
||||||
val intent = getIntent(packageName, context)
|
val intent = getIntent(packageName, context)
|
||||||
|
|
||||||
|
@ -224,7 +256,8 @@ fun launchApp(packageName: String, context: Context) {
|
||||||
} else {
|
} else {
|
||||||
if (isInstalled(packageName, context)){
|
if (isInstalled(packageName, context)){
|
||||||
|
|
||||||
AlertDialog.Builder(context,
|
AlertDialog.Builder(
|
||||||
|
context,
|
||||||
R.style.AlertDialogCustom
|
R.style.AlertDialogCustom
|
||||||
)
|
)
|
||||||
.setTitle(context.getString(R.string.alert_cant_open_title))
|
.setTitle(context.getString(R.string.alert_cant_open_title))
|
||||||
|
@ -240,12 +273,16 @@ fun launchApp(packageName: String, context: Context) {
|
||||||
.setIcon(android.R.drawable.ic_dialog_info)
|
.setIcon(android.R.drawable.ic_dialog_info)
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openNewTabWindow(urls: String, context : Context) {
|
fun openNewTabWindow(urls: String, context: Context) {
|
||||||
val uris = Uri.parse(urls)
|
val uris = Uri.parse(urls)
|
||||||
val intents = Intent(Intent.ACTION_VIEW, uris)
|
val intents = Intent(Intent.ACTION_VIEW, uris)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
|
@ -256,11 +293,11 @@ fun openNewTabWindow(urls: String, context : Context) {
|
||||||
|
|
||||||
/* Settings related functions */
|
/* Settings related functions */
|
||||||
|
|
||||||
fun getSavedTheme(context : Context) : String {
|
fun getSavedTheme(context: Context) : String {
|
||||||
return launcherPreferences.getString(PREF_THEME, "finn").toString()
|
return launcherPreferences.getString(PREF_THEME, "finn").toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveTheme(themeName : String) : String {
|
fun saveTheme(themeName: String) : String {
|
||||||
launcherPreferences.edit()
|
launcherPreferences.edit()
|
||||||
.putString(PREF_THEME, themeName)
|
.putString(PREF_THEME, themeName)
|
||||||
.apply()
|
.apply()
|
||||||
|
@ -302,7 +339,7 @@ fun resetToDarkTheme(activity: Activity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun openAppSettings(pkg :String, context:Context) {
|
fun openAppSettings(pkg: String, context: Context) {
|
||||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
intent.data = Uri.parse("package:$pkg")
|
intent.data = Uri.parse("package:$pkg")
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
|
@ -399,14 +436,18 @@ fun setWindowFlags(window: Window) {
|
||||||
|
|
||||||
// Display notification bar
|
// Display notification bar
|
||||||
if (launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
|
if (launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
|
)
|
||||||
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
|
||||||
// Screen Timeout
|
// Screen Timeout
|
||||||
if (launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
if (launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||||
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||||
|
)
|
||||||
else window.clearFlags(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),
|
OtherInfo(activity.getString(R.string.list_other_list),
|
||||||
"launcher:choose",
|
"launcher:choose",
|
||||||
activity.getString(R.string.fas_bars)))
|
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)
|
viewHolder.fontAwesome.text = activity.getString(R.string.fas_settings)
|
||||||
"choose" ->
|
"choose" ->
|
||||||
viewHolder.fontAwesome.text = activity.getString(R.string.fas_bars)
|
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 {
|
} else {
|
||||||
// Set image icon (by packageName)
|
// Set image icon (by packageName)
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
<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_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_left" translatable="false"></string>
|
||||||
<string name="fas_angle_double_right" 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_settings">Launcher Settings</string>
|
||||||
<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_down">Decrease Volume</string>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
-
|
-
|
||||||
|
|
Loading…
Add table
Reference in a new issue