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

Port Personality Provider from Lawnchair Legacy #4848

Open
wants to merge 9 commits into
base: 14-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
51 changes: 51 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,56 @@
<string name="smartspace_widget">At a Glance</string>
<string name="smartspace_widget_description">What to show</string>

<!-- Personality provider -->
<string name="personality_provider">Contextual messages</string>
<string-array name="smartspace_personality_greetings_morning">
<item>Good morning!</item>
<item>Have a great day!</item>
<item>It’s a beautiful day outside!</item>
<item>Rise and shine!</item>
<item>Top of the morning to you!</item>
<item>Ready to start the day?</item>
</string-array>
<string-array name="smartspace_personality_greetings_morning_subtitles">
<item>Wishing you a pleasant start to your day.</item>
<item>May your day be filled with joy and success.</item>
<item>Don\'t forget to enjoy the sunshine and fresh air.</item>
<item>Time to wake up and make things happen!</item>
<item>A cheerful greeting for a cheerful morning.</item>
<item>Let\'s make today amazing!</item>
</string-array>
<string-array name="smartspace_personality_greetings_evening">
<item>What’s up?</item>
<item>Good evening!</item>
<item>How did your day go?</item>
<item>How was your day?</item>
<item>Evening! How are you?</item>
<item>Hope you had a good day!</item>
</string-array>
<string-array name="smartspace_personality_greetings_evening_subtitles">
<item>Just checking in to see how your evening is going.</item>
<item>Curious to hear about your day\'s adventures.</item>
<item>Hoping your day was productive and fulfilling.</item>
<item>A friendly greeting for a wonderful evening.</item>
<item>Time to unwind and enjoy the rest of your day.</item>
</string-array>
<string-array name="smartspace_personality_greetings_night">
<item>Sleep well!</item>
<item>See you tomorrow!</item>
<item>Good night!</item>
<item>Don’t stay up too late!</item>
<item>Night night!</item>
<item>Sweet dreams!</item>
</string-array>
<string-array name="smartspace_personality_greetings_night_subtitles">
<item>May you have a restful sleep.</item>
<item>Looking forward to seeing you again tomorrow.</item>
<item>Wishing you a peaceful and pleasant night.</item>
<item>Remember to sleep for your health.</item>
<item>A cozy goodnight message for a sweet slumber.</item>
<item>May your dreams be filled with wonder and joy.</item>
</string-array>
Comment on lines +346 to +394
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help this is so robotic

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used old lawnchair, but this just shows greetings, right?
In my app I use ones from crdroid: https://raw.githubusercontent.com/crdroidandroid/android_packages_apps_Launcher3/14.0/res/values/cr_strings.xml (those starting with quickspace_grt_). I think bananadroid had some nice ones too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will look into it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bad idea, but how about a small ML model to provide greetings?


<!-- Data and time format settings -->
<string name="smartspace_calendar">Calendar</string>
<string name="smartspace_date_and_time">Date &amp; time</string>
Expand All @@ -357,6 +407,7 @@
<string name="smartspace_weather">Weather</string>
<string name="smartspace_battery_status">Battery status</string>
<string name="smartspace_now_playing">Now Playing</string>
<string name="smartspace_personality_provider">Greetings</string>

<!-- Smartspacer strings -->
<string name="maximum_number_of_targets">Maximum number of targets</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
defaultValue = true,
)

val smartspacePersonalityProvider = preference(
key = booleanPreferencesKey("enable_smartspace_personality_provider"),
defaultValue = false,
)

val smartspaceShowDate = preference(
key = booleanPreferencesKey("smartspace_show_date"),
defaultValue = context.resources.getBoolean(R.bool.config_default_smartspace_show_date),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package app.lawnchair.smartspace.model

object SmartspaceScores {
const val SCORE_WEATHER = 0f
const val SCORE_BATTERY = 1f
const val SCORE_MEDIA = 2f
const val SCORE_CALENDAR = 3f
const val SCORE_PERSONALITY = 1f
const val SCORE_BATTERY = 2f
const val SCORE_MEDIA = 3f

// Critical Information that must be displayed before anything else.
validcube marked this conversation as resolved.
Show resolved Hide resolved
const val SCORE_LOW_BATTERY = 10f
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package app.lawnchair.smartspace.provider

import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import app.lawnchair.smartspace.model.SmartspaceAction
import app.lawnchair.smartspace.model.SmartspaceScores
import app.lawnchair.smartspace.model.SmartspaceTarget
import app.lawnchair.util.broadcastReceiverFlow
import com.android.launcher3.R
import java.util.Calendar
import kotlin.math.abs
import kotlin.random.Random
import kotlinx.coroutines.flow.map

class PersonalityProvider(context: Context) : SmartspaceDataSource(
context,
R.string.smartspace_personality_provider,
{ smartspacePersonalityProvider },
) {
private val morningStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_morning)
private val eveningStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_evening)
private val nightStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night)
validcube marked this conversation as resolved.
Show resolved Hide resolved
private val morningSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night_subtitles)
private val eveningSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_evening_subtitles)
private val nightSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night_subtitles)

override val internalTargets = broadcastReceiverFlow(
context,
IntentFilter().apply {
addAction(Intent.ACTION_DATE_CHANGED)
addAction(Intent.ACTION_TIME_CHANGED)
addAction(Intent.ACTION_TIMEZONE_CHANGED)

// Difficulty testing? I know you do, uncomment this.
// addAction(Intent.ACTION_SCREEN_ON)
},
).map {
val time = Calendar.getInstance()
listOfNotNull(getSmartspaceTarget(time))
}

private fun getSmartspaceTarget(time: Calendar): SmartspaceTarget? {
val randomIndex = abs(Random(time.dayOfYear).nextInt())

val title = when {
isMorning(time) -> morningStrings[randomIndex % morningStrings.size]
isEvening(time) -> eveningStrings[randomIndex % eveningStrings.size]
isNight(time) -> nightStrings[randomIndex % nightStrings.size]
else -> return null
}

val subtitle = when {
isMorning(time) -> morningSubtitleStrings[randomIndex % morningSubtitleStrings.size]
isEvening(time) -> eveningSubtitleStrings[randomIndex % eveningSubtitleStrings.size]
isNight(time) -> nightSubtitleStrings[randomIndex % nightSubtitleStrings.size]
else -> return null
}

/* TODO: We really need target's expiration time which isn't supported on new Smartspace
* ImplRef: LawnchairSmartspaceController.kt @ 10-dev */
return SmartspaceTarget(
id = "personalityGreeting",
headerAction = SmartspaceAction(
id = "personalityGreetingAction",
title = title,
subtitle = subtitle,
),
score = SmartspaceScores.SCORE_PERSONALITY,
featureType = SmartspaceTarget.FeatureType.FEATURE_REMINDER,
)
}

private fun isMorning(time: Calendar) = time.hourOfDay in 5 until 9
private fun isEvening(time: Calendar) = time.hourOfDay in 19 until 21
private fun isNight(time: Calendar) = time.hourOfDay in 22 until 24 || time.hourOfDay in 0 until 4

private val Calendar.dayOfYear: Int get() = get(Calendar.DAY_OF_YEAR)
private val Calendar.hourOfDay: Int get() = get(Calendar.HOUR_OF_DAY)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SmartspaceProvider private constructor(context: Context) {
SmartspaceWidgetReader(context),
BatteryStatusProvider(context),
NowPlayingProvider(context),
PersonalityProvider(context),
)

private val state = dataSources
Expand Down
Loading