Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream' into trunk
Browse files Browse the repository at this point in the history
// Conflicts:
//	lawnchair/src/app/lawnchair/LawnchairLauncher.kt
  • Loading branch information
Goooler committed Sep 14, 2024
2 parents 1ac55b5 + 4030308 commit 7ad7964
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation "androidx.preference:preference-ktx:1.2.1"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2'
implementation 'com.github.ChickenHook:RestrictionBypass:2.2'
implementation 'dev.rikka.tools.refine:runtime:4.4.0'
Expand Down
12 changes: 12 additions & 0 deletions lawnchair/res/drawable/ic_firefox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group>
<path
android:pathData="m98.9 37.7c-2.1-5.1-6.4-10.6-9.8-12.3 2.5 4.6 4.1 9.6 5 14.7v0.1c-5.5-13.7-14.9-19.2-22.5-31.3q-0.6-0.9-1.2-1.8-0.3-0.5-0.5-1-0.5-1-0.7-2 0 0-0.1-0.1 0 0-0.1 0 0 0 0 0 0 0-0.1 0 0 0 0 0c-10.8 6.3-15.3 17.4-16.5 24.5-3.3 0.2-6.6 1-9.7 2.5-0.2 0.1-0.5 0.4-0.6 0.7-0.1 0.3-0.1 0.6 0.1 0.9q0.2 0.5 0.7 0.7c0.3 0.1 0.6 0.1 0.9-0.1 2.7-1.2 5.5-2 8.4-2.2h0.3q0.6 0 1.2 0 3.6-0.1 7 0.9 0.2 0.1 0.4 0.2 0.6 0.1 1.1 0.4 0.4 0.1 0.8 0.3 0.4 0.1 0.7 0.2 0.5 0.2 1 0.5 0.2 0.1 0.4 0.2 0.5 0.3 1 0.5 0.3 0.2 0.6 0.4c3.5 2.2 6.5 5.2 8.5 8.8-3.4-2.4-7.6-3.4-11.7-2.8 17.5 8.7 12.8 38.8-11.5 37.7-2.2-0.1-4.3-0.5-6.4-1.2q-0.7-0.3-1.4-0.6-0.4-0.2-0.8-0.4c-6-3.1-10.9-8.9-11.5-15.9 0 0 2.2-8.4 16.1-8.4 1.5 0 5.8-4.2 5.9-5.4 0-0.4-8.5-3.7-11.8-7-1.8-1.7-2.6-2.6-3.4-3.2q-0.6-0.5-1.2-0.9c-1.2-3.9-1.2-8-0.2-11.9-4.5 2.1-8.5 5.2-11.7 9-2-2.4-1.9-10.5-1.8-12.2q-0.8 0.4-1.6 0.9c-1.7 1.2-3.3 2.6-4.7 4.1q-2.5 2.5-4.6 5.4c-3.1 4.5-5.4 9.5-6.6 14.8q-0.4 2.2-0.7 4.5-0.1 0.5-0.2 1.1-0.2 1.4-0.3 2.8 0 0 0 0.1 0 0.8-0.1 1.6v0.3c0.1 12.2 4.8 24 13 32.9 8.3 9 19.6 14.5 31.7 15.5 12.1 1.1 24.2-2.5 33.8-9.9 9.7-7.5 16.2-18.3 18.4-30.3q0.1-0.9 0.2-1.9c1-8.2-0.1-16.7-3.2-24.4z"
android:fillColor="#ff5a32"/>
</group>
</vector>
12 changes: 12 additions & 0 deletions lawnchair/res/drawable/ic_firefox_tinted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group>
<path
android:pathData="m98.9 37.7c-2.1-5.1-6.4-10.6-9.8-12.3 2.5 4.6 4.1 9.6 5 14.7v0.1c-5.5-13.7-14.9-19.2-22.5-31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="#000000"/>
</group>
</vector>
14 changes: 14 additions & 0 deletions lawnchair/res/drawable/ic_iceraven.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="m31.6 25.8l2-2.4q0 0 0.1 0l2.1-2.2q0 0 0.1-0.1l2.3-2q0 0 0 0l2.5-1.8q0 0 0-0.1l2.6-1.5q0.1-0.1 0.1-0.1l2.7-1.3q0 0 0.1-0.1l2.8-1q0-0.1 0.1-0.1l2.8-0.8q0.1 0 0.1 0l2.9-0.7q0.1 0 0.1 0l3-0.3q0 0 0.1 0l2.9-0.1q0.1 0 0.1 0l3 0.2q0 0 0.1 0l2.9 0.4q0.1 0 0.1 0l2.9 0.7q0.1 0 0.1 0l2.9 0.9q0 0.1 0 0.1l2.8 1.1q0 0 0.1 0.1l2.6 1.4q0.1 0 0.1 0l2.6 1.7q0 0 0 0l2.5 1.9q0 0 0 0l2.3 2.1q0 0 0 0l2.1 2.3q0 0 0.1 0l1.9 2.4q0 0.1 0 0.1l1.8 2.6q0 0 0 0l1.4 2.6q0.1 0.1 0.1 0.1l1.2 2.7q0 0.1 0.1 0.1l1 2.8q0 0 0 0.1l0.9 2.9q0 0 0 0.1l0.6 2.9q0 0 0 0.1l0.4 2.9q0 0.1 0 0.1l0.2 3q0 0.1 0 0.1l-0.1 3q0 0.1 0 0.1l-0.2 3q0 0-0.1 0.1l-0.5 2.9q0 0.1 0 0.1l-0.7 2.9q0 0 0 0.1l-0.9 2.8q-0.1 0.1-0.1 0.1l-1.1 2.8q0 0 0 0.1l-1.4 2.6q0 0.1 0 0.1l-1.6 2.5q0 0.1 0 0.1l-1.7 2.4q-0.1 0-0.1 0.1l-1.9 2.2c-0.4 0.5-1.1 0.5-1.5 0.1-0.5-0.4-0.5-1.1-0.1-1.6l1.9-2.3-0.1 0.1 1.8-2.4-0.1 0.1 1.5-2.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8 6.4-12.2 12-20 13.8-2.2 0.6-4.4 0.8-6.7 0.8q-2.5 0-5.1-0.3l-7.2-1.1c3.6 3.1 12.4 7.2 17 8.1 3.9 0.7 9.6 0.8 13.1 0.8 19.3 0 33.4-13.6 39.2-32.8 3.7-12 0.8-25.8-1.3-35.5l-0.1 10.8-6-12.1z"
android:strokeLineJoin="miter"
android:fillColor="#055493"/>
</vector>
14 changes: 14 additions & 0 deletions lawnchair/res/drawable/ic_iceraven_tinted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="m31.6 25.8l2-2.4q0 0 0.1 0l2.1-2.2q0 0 0.1-0.1l2.3-2q0 0 0 0l2.5-1.8q0 0 0-0.1l2.6-1.5q0.1-0.1 0.1-0.1l2.7-1.3q0 0 0.1-0.1l2.8-1q0-0.1 0.1-0.1l2.8-0.8q0.1 0 0.1 0l2.9-0.7q0.1 0 0.1 0l3-0.3q0 0 0.1 0l2.9-0.1q0.1 0 0.1 0l3 0.2q0 0 0.1 0l2.9 0.4q0.1 0 0.1 0l2.9 0.7q0.1 0 0.1 0l2.9 0.9q0 0.1 0 0.1l2.8 1.1q0 0 0.1 0.1l2.6 1.4q0.1 0 0.1 0l2.6 1.7q0 0 0 0l2.5 1.9q0 0 0 0l2.3 2.1q0 0 0 0l2.1 2.3q0 0 0.1 0l1.9 2.4q0 0.1 0 0.1l1.8 2.6q0 0 0 0l1.4 2.6q0.1 0.1 0.1 0.1l1.2 2.7q0 0.1 0.1 0.1l1 2.8q0 0 0 0.1l0.9 2.9q0 0 0 0.1l0.6 2.9q0 0 0 0.1l0.4 2.9q0 0.1 0 0.1l0.2 3q0 0.1 0 0.1l-0.1 3q0 0.1 0 0.1l-0.2 3q0 0-0.1 0.1l-0.5 2.9q0 0.1 0 0.1l-0.7 2.9q0 0 0 0.1l-0.9 2.8q-0.1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 4.3 0 0 5.4-9.4 7.3-17.2-6.7 5.7-12.9 9.2-18.6 10.5-3.6 0.8-6.9 1.3-9.9 1.3q-5.7 0-9.9-2.1c-3.2-6.9-3.9-13-1.9-18.3 0.9-2.4 2.3-4.6 4-6.7l11-16.4zm44.7 24.2c3.2 10.9 4.8 16.5-0.2 28.9-5.8 14.2-15 18-22.7 18.6-5.8 6.4-12.2 12-20 13.8-2.2 0.6-4.4 0.8-6.7 0.8q-2.5 0-5.1-0.3l-7.2-1.1c3.6 3.1 12.4 7.2 17 8.1 3.9 0.7 9.6 0.8 13.1 0.8 19.3 0 33.4-13.6 39.2-32.8 3.7-12 0.8-25.8-1.3-35.5l-0.1 10.8-6-12.1z"
android:strokeLineJoin="miter"
android:fillColor="#000000"/>
</vector>
3 changes: 3 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@
<string name="search_provider_youtube" translatable="false">YouTube</string>
<string name="search_provider_pixel_search" translatable="false">Pixel Search</string>
<string name="search_provider_yandex" translatable="false">Yandex</string>
<string name="search_provider_firefox" translatable="false">Firefox</string>
<string name="search_provider_iceraven" translatable="false">Iceraven</string>
<string name="search_provider_mull" translatable="false">Mull</string>

<string name="search_provider_sponsored_description">%1$s and Lawnchair have a revenue share agreement.\n\nSearching with %1$s helps support Lawnchair.</string>

Expand Down
1 change: 1 addition & 0 deletions lawnchair/src/app/lawnchair/LawnchairLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class LawnchairLauncher : QuickstepLauncher() {

override fun onDestroy() {
super.onDestroy()
// Only actually closes if required, safe to call if not enabled
SmartspacerClient.close()
}

Expand Down
25 changes: 25 additions & 0 deletions lawnchair/src/app/lawnchair/qsb/providers/Firefox.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app.lawnchair.qsb.providers

import android.content.Intent
import app.lawnchair.qsb.ThemingMethod
import com.android.launcher3.R

data object Firefox : QsbSearchProvider(
id = "Firefox",
name = R.string.search_provider_firefox,
icon = R.drawable.ic_firefox,
themedIcon = R.drawable.ic_firefox_tinted,
themingMethod = ThemingMethod.TINT,
packageName = "org.mozilla.firefox",
action = "org.mozilla.fenix.OPEN_TAB",
className = "org.mozilla.fenix.IntentReceiverActivity",
website = "https://play.google.com/store/apps/details?id=org.mozilla.firefox",
type = QsbSearchProviderType.APP,
supportVoiceIntent = false,
) {

override fun handleCreateVoiceIntent(): Intent =
Intent(action)
.addFlags(INTENT_FLAGS)
.setClassName(packageName, "org.chromium.chrome.browser.VoiceSearchActivity")
}
25 changes: 25 additions & 0 deletions lawnchair/src/app/lawnchair/qsb/providers/Iceraven.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app.lawnchair.qsb.providers

import android.content.Intent
import app.lawnchair.qsb.ThemingMethod
import com.android.launcher3.R

data object Iceraven : QsbSearchProvider(
id = "Iceraven",
name = R.string.search_provider_iceraven,
icon = R.drawable.ic_iceraven,
themedIcon = R.drawable.ic_iceraven_tinted,
themingMethod = ThemingMethod.TINT,
packageName = "io.github.forkmaintainers.iceraven",
action = "org.mozilla.fenix.OPEN_TAB",
className = "org.mozilla.fenix.IntentReceiverActivity",
website = "github.com/fork-maintainers/iceraven-browser/releases/latest",
type = QsbSearchProviderType.APP,
supportVoiceIntent = true,
) {

override fun handleCreateVoiceIntent(): Intent =
Intent(action)
.addFlags(INTENT_FLAGS)
.setClassName(packageName, "org.chromium.chrome.browser.VoiceSearchActivity")
}
25 changes: 25 additions & 0 deletions lawnchair/src/app/lawnchair/qsb/providers/Mull.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app.lawnchair.qsb.providers

import android.content.Intent
import app.lawnchair.qsb.ThemingMethod
import com.android.launcher3.R

data object Mull : QsbSearchProvider(
id = "Mull",
name = R.string.search_provider_mull,
icon = R.drawable.ic_mull,
themedIcon = R.drawable.ic_mull_tinted,
themingMethod = ThemingMethod.TINT,
packageName = "us.spotco.fennec_dos",
action = "org.mozilla.fenix.OPEN_TAB",
className = "org.mozilla.fenix.IntentReceiverActivity",
website = "gitlab.com/divested-mobile/mull-fenix",
type = QsbSearchProviderType.APP,
supportVoiceIntent = true,
) {

override fun handleCreateVoiceIntent(): Intent =
Intent(action)
.addFlags(INTENT_FLAGS)
.setClassName(packageName, "org.chromium.chrome.browser.VoiceSearchActivity")
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ sealed class QsbSearchProvider(
Bing,
Brave,
Yandex,
Firefox,
Iceraven,
Startpage,
Mull,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.io.IOException
import java.io.InputStream
import java.security.MessageDigest
import java.util.Locale
import java.util.UUID
import okio.ByteString

class SearchTargetFactory(
Expand Down Expand Up @@ -93,7 +94,8 @@ class SearchTargetFactory(
): SearchTargetCompat {
val result = calculation.result
val equation = calculation.equation
val id = "calculator:$result"
val uuid = UUID.randomUUID().toString()
val id = "calculator:$uuid"
val action = SearchActionCompat.Builder(id, result)
.setIcon(
Icon.createWithResource(context, R.drawable.calculator)
Expand Down
16 changes: 13 additions & 3 deletions lawnchair/src/app/lawnchair/search/algorithms/data/Calculation.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app.lawnchair.search.algorithms.data

import app.lawnchair.search.algorithms.data.calculator.Expressions
import java.math.BigDecimal
import java.math.MathContext

data class Calculation(
val equation: String,
Expand All @@ -12,9 +14,17 @@ fun calculateEquationFromString(
query: String,
): Calculation {
return try {
val result = Expressions()
.eval(query)
.toString()
val evaluatedValue = Expressions().eval(query)
val roundedValue = evaluatedValue.round(MathContext.DECIMAL64)
val formattedValue = roundedValue.stripTrailingZeros()
val absoluteValue = formattedValue.abs()
val threshold = BigDecimal("9999999999999999")

val result = if (absoluteValue > threshold) {
formattedValue.toString()
} else {
formattedValue.toPlainString()
}

Calculation(
equation = query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Expressions {
private val evaluator = Evaluator()

init {
define("pi", Math.PI)
define("e", Math.E)
define("pi", BigDecimal(Math.PI).setScale(33, RoundingMode.HALF_EVEN))
define("e", BigDecimal(Math.E).setScale(33, RoundingMode.HALF_EVEN))

evaluator.addFunction("abs") { arguments ->
if (arguments.size != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.Locale
import kotlin.math.pow

internal class Evaluator : ExprVisitor<BigDecimal> {
internal var mathContext: MathContext = MathContext.DECIMAL64
internal var mathContext: MathContext = MathContext.DECIMAL128

private val variables: LinkedHashMap<String, BigDecimal> = linkedMapOf()
private val functions: MutableMap<String, Function> = mutableMapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ fun SliderPreference(

fun getSteps(valueRange: ClosedFloatingPointRange<Float>, step: Float): Int {
if (step == 0f) return 0
val start = valueRange.start
val end = valueRange.endInclusive
val steps = ((end - start) / step).toInt()
require(start + step * steps == end) {
val start = valueRange.start.toBigDecimal()
val end = valueRange.endInclusive.toBigDecimal()
val decimalSteps = (end - start) / step.toBigDecimal()
val steps = decimalSteps.toInt()
require(decimalSteps.compareTo(steps.toBigDecimal()) == 0) {
"value range must be a multiple of step"
}
return steps - 1
Expand Down
Loading

0 comments on commit 7ad7964

Please sign in to comment.