Merge pull request #70 from finnmglas/feature/volume-key-actions

Feature/volume key actions
This commit is contained in:
Finn M Glas 2020-10-12 18:27:15 +02:00 committed by GitHub
commit 229a0b14e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 160 additions and 25 deletions

View file

@ -8,11 +8,14 @@ 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
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
@ -22,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
@ -30,6 +34,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 +159,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 +180,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 +211,19 @@ 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)
"nextTrack" -> audioNextTrack(activity)
"previousTrack" -> audioPreviousTrack(activity)
"tutorial" -> openTutorial(activity) "tutorial" -> openTutorial(activity)
} }
else launchApp(data, activity) // app else launchApp(data, activity) // app
@ -216,6 +231,62 @@ fun launch(data: String, activity: Activity,
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) {
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 +295,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 +312,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 +332,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 +378,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 +475,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)
} }

View file

@ -12,6 +12,7 @@ import com.finnmglas.launcher.dominantColor
import com.finnmglas.launcher.list.forApp import com.finnmglas.launcher.list.forApp
import com.finnmglas.launcher.list.intention import com.finnmglas.launcher.list.intention
import com.finnmglas.launcher.openSoftKeyboard import com.finnmglas.launcher.openSoftKeyboard
import kotlinx.android.synthetic.main.list.*
import kotlinx.android.synthetic.main.list_apps.* import kotlinx.android.synthetic.main.list_apps.*
@ -68,6 +69,8 @@ class ListFragmentApps : Fragment(), UIObject {
} }
}) })
openSoftKeyboard(context!!, list_apps_searchview) when (intention) {
"view" -> openSoftKeyboard(context!!, list_apps_searchview)
}
} }
} }

View file

@ -2,6 +2,7 @@ package com.finnmglas.launcher.list.other
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Build
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -66,9 +67,33 @@ 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)))
if (Build.VERSION.SDK_INT >= 19) { // requires Android KitKat +
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)

View file

@ -104,6 +104,14 @@ 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)
"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)

View file

@ -9,11 +9,11 @@
<com.finnmglas.launcher.libraries.FontAwesome <com.finnmglas.launcher.libraries.FontAwesome
android:id="@+id/list_other_row_icon" android:id="@+id/list_other_row_icon"
android:layout_width="40sp" android:layout_width="35sp"
android:layout_height="40sp" android:layout_height="35sp"
android:gravity="center" android:gravity="center"
android:text="" android:text=""
android:textSize="35sp" android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

View file

@ -122,8 +122,12 @@
<string name="list_apps_search_hint">Anwendungen suchen</string> <string name="list_apps_search_hint">Anwendungen suchen</string>
<string name="list_other_settings">Launcher Einstellungen</string> <string name="list_other_settings">App Einstellungen</string>
<string name="list_other_list">Launcher Apps Liste</string> <string name="list_other_list">Alle Anwendungen</string>
<string name="list_other_volume_up">Musik: Lauter</string>
<string name="list_other_volume_down">Musik: Leiser</string>
<string name="list_other_track_next">Musik: Weiter</string>
<string name="list_other_track_previous">Musik: Zurück</string>
<!-- <!--
- -

View file

@ -123,7 +123,11 @@
<string name="list_apps_search_hint">rechercher des applications</string> <string name="list_apps_search_hint">rechercher des applications</string>
<string name="list_other_settings">Launcher Réglages</string> <string name="list_other_settings">Launcher Réglages</string>
<string name="list_other_list">Launcher Liste des apps</string> <string name="list_other_list">Applications</string>
<string name="list_other_volume_up">Musique: plus fort</string>
<string name="list_other_volume_down">Musique: plus calme</string>
<string name="list_other_track_next">Musique: suivant</string>
<string name="list_other_track_previous">Musique: dernier</string>
<!-- <!--
- -

View file

@ -14,6 +14,13 @@
<string name="fas_times" translatable="false">&#xf00d;</string> <!-- 'close' --> <string name="fas_times" translatable="false">&#xf00d;</string> <!-- 'close' -->
<string name="fas_three_dots" translatable="false">&#xf142;</string> <!-- 'ellipsis-v' --> <string name="fas_three_dots" translatable="false">&#xf142;</string> <!-- 'ellipsis-v' -->
<string name="fas_volume_down" translatable="false">&#xf027;</string>
<string name="fas_volume_up" translatable="false">&#xf028;</string>
<string name="fas_plus" translatable="false">&#xf067;</string>
<string name="fas_minus" translatable="false">&#xf068;</string>
<string name="fas_back" translatable="false">&#xf048;</string>
<string name="fas_forward" translatable="false">&#xf051;</string>
<string name="fas_angle_double_left" translatable="false">&#xf100;</string> <string name="fas_angle_double_left" translatable="false">&#xf100;</string>
<string name="fas_angle_double_right" translatable="false">&#xf101;</string> <string name="fas_angle_double_right" translatable="false">&#xf101;</string>
<string name="fas_angle_double_up" translatable="false">&#xf102;</string> <string name="fas_angle_double_up" translatable="false">&#xf102;</string>

View file

@ -143,7 +143,11 @@
<string name="list_apps_search_hint">Search Applications</string> <string name="list_apps_search_hint">Search Applications</string>
<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">All Applications</string>
<string name="list_other_volume_up">Music: Louder</string>
<string name="list_other_volume_down">Music: Quieter</string>
<string name="list_other_track_next">Music: Next</string>
<string name="list_other_track_previous">Music: Previous</string>
<!-- <!--
- -