Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0677677 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Add MessageFormats to Spa"

parents 91618c20 e0724be6
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -33,4 +33,3 @@ rootProject.name = "SpaLib"
include ':spa'
include ':gallery'
include ':testutils'
include ':tests'
+39 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ android {
    defaultConfig {
        minSdk MIN_SDK
        targetSdk TARGET_SDK

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    sourceSets {
@@ -37,6 +39,13 @@ android {
            res.srcDirs = ["res"]
            manifest.srcFile "AndroidManifest.xml"
        }
        androidTest {
            kotlin {
                srcDir "../tests/src"
            }
            res.srcDirs = ["../tests/res"]
            manifest.srcFile "../tests/AndroidManifest.xml"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
@@ -52,6 +61,11 @@ android {
    composeOptions {
        kotlinCompilerExtensionVersion jetpack_compose_compiler_version
    }
    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }
}

dependencies {
@@ -72,4 +86,29 @@ dependencies {
    api "com.google.android.material:material:1.7.0-alpha03"
    debugApi "androidx.compose.ui:ui-tooling:$jetpack_compose_version"
    implementation "com.airbnb.android:lottie-compose:5.2.0"

    androidTestImplementation project(":testutils")
    androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.28.1"
}

task coverageReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."

    sourceDirectories.from = files("src")
    classDirectories.from = fileTree(
            dir: "$buildDir/tmp/kotlin-classes/debug",
            excludes: [
                    "com/android/settingslib/spa/debug/**",

                    // Excludes files forked from AndroidX.
                    "com/android/settingslib/spa/widget/scaffold/CustomizedAppBar*",
                    "com/android/settingslib/spa/widget/scaffold/TopAppBarColors*",

                    // Excludes files forked from Accompanist.
                    "com/android/settingslib/spa/framework/compose/DrawablePainter*",
                    "com/android/settingslib/spa/framework/compose/Pager*",
            ],
    )
    executionData.from = fileTree(dir: "$buildDir/outputs/code_coverage/debugAndroidTest/connected")
}
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa.framework.util

import android.content.Context
import android.content.res.Resources
import android.icu.text.MessageFormat
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import java.util.Locale

@RequiresApi(Build.VERSION_CODES.N)
fun Context.formatString(@StringRes resId: Int, vararg arguments: Pair<String, Any>): String =
    resources.formatString(resId, *arguments)

@RequiresApi(Build.VERSION_CODES.N)
fun Resources.formatString(@StringRes resId: Int, vararg arguments: Pair<String, Any>): String =
    MessageFormat(getString(resId), Locale.getDefault(Locale.Category.FORMAT))
        .format(mapOf(*arguments))
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.settingslib.spa.tests">
    package="com.android.settingslib.spa.test">

    <uses-sdk android:minSdkVersion="21"/>

@@ -26,6 +26,6 @@
    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:label="Tests for SpaLib"
        android:targetPackage="com.android.settingslib.spa.tests">
        android:targetPackage="com.android.settingslib.spa.test">
    </instrumentation>
</manifest>
+0 −88
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

plugins {
    id 'com.android.library'
    id 'kotlin-android'
}

android {
    namespace 'com.android.settingslib.spa.tests'
    compileSdk TARGET_SDK
    buildToolsVersion = BUILD_TOOLS_VERSION

    defaultConfig {
        minSdk MIN_SDK
        targetSdk TARGET_SDK

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    sourceSets {
        main {
            res.srcDirs = ["res"]
        }
        androidTest {
            kotlin {
                srcDir "src"
            }
            manifest.srcFile "AndroidManifest.xml"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs = ["-Xjvm-default=all"]
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion jetpack_compose_compiler_version
    }
    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }
}

dependencies {
    androidTestImplementation project(":spa")
    androidTestImplementation project(":testutils")
    androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.28.1"
}

task coverageReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."

    sourceDirectories.from = files("../spa/src")
    classDirectories.from = fileTree(
            dir: "../spa/build/tmp/kotlin-classes/debug",
            excludes: [
                    "com/android/settingslib/spa/debug/**",

                    // Excludes files forked from Accompanist.
                    "com/android/settingslib/spa/framework/compose/DrawablePainter*",
                    "com/android/settingslib/spa/framework/compose/Pager*",
            ],
    )
    executionData.from = fileTree(dir: "$buildDir/outputs/code_coverage/debugAndroidTest/connected")
}
Loading