Remove GMS license activity

This commit is contained in:
Suphon Thanakornpakapong committed 2021-06-20 22:43:42 +07:00
1 parent 8dde81150d
commit 40804560bb
14 files changed
+248 -37

No files matched your search

-8
View File
@@ -198,13 +198,5 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/Theme.Acknowledgements" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/Theme.Acknowledgements" />
</application>
</manifest>
-1
View File
@@ -251,7 +251,6 @@ allprojects {
}
dependencies {
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation "androidx.dynamicanimation:dynamicanimation:${ANDROID_X_VERSION}"
implementation "androidx.recyclerview:recyclerview:${ANDROID_X_VERSION}"
implementation "androidx.preference:preference-ktx:${ANDROID_X_VERSION}"
-7
View File
@@ -6,11 +6,4 @@
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
</style>
<style name="Theme.Acknowledgements" parent="Base.Theme.Acknowledgements">
<item name="android:colorBackground">#ff121212</item>
<item name="colorPrimary">#ff282828</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
</style>
</resources>
+1
View File
@@ -104,4 +104,5 @@
<string name="system_icons">System Icons</string>
<string name="accent_color">Accent Color</string>
<string name="done">Done</string>
<string name="loading">Loading…</string>
</resources>
-12
View File
@@ -17,16 +17,4 @@
<item name="android:navigationBarColor" tools:ignore="NewApi">?android:attr/colorBackground</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
</style>
<style name="Theme.Acknowledgements" parent="Base.Theme.Acknowledgements">
<item name="android:colorBackground">@color/white_50</item>
</style>
<style name="Base.Theme.Acknowledgements" parent="Theme.AppCompat.DayNight">
<item name="colorPrimary">?android:attr/colorBackground</item>
<item name="android:statusBarColor" tools:ignore="NewApi">?attr/colorPrimary</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
<item name="android:navigationBarColor" tools:ignore="NewApi">?android:attr/colorBackground</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
</style>
</resources>
@@ -17,9 +17,12 @@
package app.lawnchair.ui.preferences
import androidx.compose.runtime.State
import app.lawnchair.ui.preferences.about.licenses.License
import java.util.*
interface PreferenceInteractor {
val notificationDotsEnabled: State<Boolean>
val licenses: State<List<License>?>
fun getIconPacks(): List<IconPackInfo>
}
@@ -25,8 +25,15 @@ import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel
import app.lawnchair.ui.preferences.about.licenses.License
import com.android.launcher3.R
import com.android.launcher3.notification.NotificationListener
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.HashMap
class PreferenceViewModel(application: Application) : AndroidViewModel(application), PreferenceInteractor {
private val lawnchairNotificationListener = ComponentName(application, NotificationListener::class.java)
@@ -74,4 +81,22 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati
return iconPackList
}
override val licenses by lazy { runBlocking {
val licensesState = mutableStateOf<List<License>?>(null)
launch {
val res = application.resources
val reader = BufferedReader(InputStreamReader(res.openRawResource(R.raw.third_party_license_metadata)))
val licenses = reader.readLines().map { line ->
val parts = line.split(" ")
val startEnd = parts[0].split(":")
val start = startEnd[0].toLong()
val length = startEnd[1].toInt()
val name = parts.subList(1, parts.size).joinToString(" ")
License(name, start, length)
}.sortedBy { it.name.lowercase() }
licensesState.value = licenses
}
licensesState
} }
}
@@ -35,14 +35,16 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavGraphBuilder
import app.lawnchair.preferences.getFormattedVersionName
import app.lawnchair.ui.preferences.about.licenses.licensesGraph
import app.lawnchair.ui.preferences.components.ClickablePreference
import app.lawnchair.ui.preferences.components.NavigationActionPreference
import app.lawnchair.ui.preferences.components.PreferenceGroup
import app.lawnchair.ui.preferences.components.PreferenceLayout
import app.lawnchair.ui.preferences.preferenceGraph
import app.lawnchair.ui.preferences.subRoute
import app.lawnchair.util.Meta
import app.lawnchair.util.pageMeta
import com.android.launcher3.R
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
class TeamMember(val name: String, @StringRes val descriptionRes: Int, val photoUrl: String, val socialUrl: String)
@@ -131,9 +133,15 @@ val supportAndPr = listOf(
)
)
object AboutRoutes {
const val LICENSES = "licenses"
}
@ExperimentalAnimationApi
fun NavGraphBuilder.aboutGraph(route: String) {
preferenceGraph(route, { About() })
preferenceGraph(route, { About() }) { subRoute ->
licensesGraph(route = subRoute(AboutRoutes.LICENSES))
}
}
@ExperimentalAnimationApi
@@ -220,13 +228,9 @@ fun About() {
}
}
PreferenceGroup {
ClickablePreference(
NavigationActionPreference(
label = stringResource(id = R.string.acknowledgements),
onClick = {
val intent = Intent(context, OssLicensesMenuActivity::class.java)
OssLicensesMenuActivity.setActivityTitle(context.getString(R.string.acknowledgements))
context.startActivity(intent)
}
destination = subRoute(name = AboutRoutes.LICENSES)
)
ClickablePreference(
label = stringResource(id = R.string.translate),
@@ -0,0 +1,3 @@
package app.lawnchair.ui.preferences.about.licenses
data class License(val name: String, val start: Long, val length: Int)
@@ -0,0 +1,128 @@
package app.lawnchair.ui.preferences.about.licenses
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import app.lawnchair.ui.preferences.LocalNavController
import app.lawnchair.ui.preferences.LocalPreferenceInteractor
import app.lawnchair.ui.preferences.components.*
import app.lawnchair.ui.preferences.preferenceGraph
import app.lawnchair.ui.preferences.subRoute
import app.lawnchair.util.Meta
import app.lawnchair.util.pageMeta
import com.android.launcher3.R
fun NavGraphBuilder.licensesGraph(route: String) {
preferenceGraph(route, { Licenses() }) { subRoute ->
composable(
route = subRoute("{licenseIndex}"),
arguments = listOf(navArgument("licenseIndex") { type = NavType.IntType })
) { backStackEntry ->
LicensePage(index = backStackEntry.arguments!!.getInt("licenseIndex"))
}
}
}
@Composable
fun Licenses() {
pageMeta.provide(Meta(title = stringResource(id = R.string.acknowledgements)))
val optionalLicenses by LocalPreferenceInteractor.current.licenses
LoadingScreen(optionalLicenses) { licenses ->
PreferenceLayoutLazyColumn {
preferenceGroupItems(licenses, isFirstChild = true) { index, license ->
LicenseItem(license = license, index = index, showDivider = index != licenses.lastIndex)
}
}
}
}
@Composable
fun LicenseItem(license: License, index: Int, showDivider: Boolean) {
val navController = LocalNavController.current
val destination = subRoute(name = "$index")
PreferenceTemplate(
height = 52.dp,
showDivider = showDivider
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxSize()
.clickable { navController.navigate(route = destination) }
.padding(start = 16.dp, end = 16.dp)
) {
Text(
text = license.name,
style = MaterialTheme.typography.subtitle1,
color = MaterialTheme.colors.onBackground,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
}
@Composable
fun LicensePage(index: Int) {
val optionalLicenses by LocalPreferenceInteractor.current.licenses
val license = optionalLicenses?.get(index)
val dataState = license?.let { loadLicense(license = license) }
val data = dataState?.value
pageMeta.provide(Meta(title = license?.name ?: stringResource(id = R.string.loading)))
LoadingScreen(data) {
PreferenceLayout {
val uriHandler = LocalUriHandler.current
val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }
val pressIndicator = Modifier.pointerInput(Unit) {
detectTapGestures { pos ->
layoutResult.value?.let { layoutResult ->
val position = layoutResult.getOffsetForPosition(pos)
val annotation = it.data.getStringAnnotations(position, position).firstOrNull()
if (annotation?.tag == "URL") {
uriHandler.openUri(annotation.item)
}
}
}
}
Text(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 16.dp)
.then(pressIndicator),
text = it.data,
fontFamily = FontFamily.Monospace,
fontSize = 14.sp,
onTextLayout = {
layoutResult.value = it
}
)
}
}
}
@@ -0,0 +1,57 @@
package app.lawnchair.ui.preferences.about.licenses
import android.text.SpannableString
import android.text.style.URLSpan
import android.text.util.Linkify
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import com.android.launcher3.R
@Composable
fun loadLicense(license: License): State<LicenseData?> {
val res = LocalContext.current.resources
val licenseStringState = remember { mutableStateOf<LicenseData?>(null) }
val accentColor = MaterialTheme.colors.primary
DisposableEffect(Unit) {
val reader = res.openRawResource(R.raw.third_party_licenses)
reader.skip(license.start)
val bytes = ByteArray(license.length)
reader.read(bytes, 0, license.length)
val string = String(bytes)
val spannable = SpannableString(string)
Linkify.addLinks(spannable, Linkify.WEB_URLS)
val spans = spannable.getSpans(0, string.length, URLSpan::class.java)
val annotatedString = buildAnnotatedString {
append(string)
spans.forEach { urlSpan ->
val start = spannable.getSpanStart(urlSpan)
val end = spannable.getSpanEnd(urlSpan)
addStyle(
style = SpanStyle(
color = accentColor,
textDecoration = TextDecoration.Underline
),
start = start,
end = end
)
addStringAnnotation(
tag = "URL",
annotation = urlSpan.url,
start = start,
end = end
)
}
}
licenseStringState.value = LicenseData(license, annotatedString)
onDispose { }
}
return licenseStringState
}
data class LicenseData(val license: License, val data: AnnotatedString)
@@ -44,3 +44,10 @@ fun LoadingScreen(isLoading: Boolean, content: @Composable () -> Unit) {
}
}
}
@Composable
fun <T> LoadingScreen(obj: T?, content: @Composable (T) -> Unit) {
LoadingScreen(isLoading = obj == null) {
content(obj!!)
}
}
@@ -45,6 +45,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.currentBackStackEntryAsState
@@ -88,8 +89,10 @@ fun TopBar() = pageMeta.consume { state ->
Text(
text = state.title,
style = MaterialTheme.typography.h6,
modifier = Modifier.padding(start = 16.dp),
modifier = Modifier.padding(start = 16.dp, end = 24.dp),
color = MaterialTheme.colors.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
@@ -0,0 +1,8 @@
package app.lawnchair.util
import java.util.*
val <T> Optional<T>.value: T? get() {
if (!isPresent) return null
return get()
}