Giter Site home page Giter Site logo

androidpoint's Introduction

AndroidPoint

androidpoint's People

Contributors

a284628487 avatar

Stargazers

qingguogugo avatar

Watchers

James Cloos avatar  avatar

androidpoint's Issues

Android Processor

修改AndroidManifest.xml

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.processResources.doFirst { pm ->
            String manifestPath = output.processResources.manifestFile
            println "=====ManifestPath=====$manifestPath"
            // N:\xx\build\intermediates\merged_manifests\debug\AndroidManifest.xml
            def manifestContent = file(manifestPath).getText()
            def xml = new XmlParser().parseText(manifestContent)
            xml.application[0].appendNode("meta-data", ['android:name': 'channel', 'android:value': 'baidu'])
            def serialize = groovy.xml.XmlUtil.serialize(xml)
            file(manifestPath).write(serialize)
        }

        println "originalFileName: ${outputFileName}"
        outputFileName = "xxxxx.apk"
    }
}

Kotlin Coroutine & Flow

Flow

Flow.collect,每次执行 collect 都会触发flow提供者代码。

    @Test
    fun flowTest() {
        val flow = flow<String> {
            delay(1000)
            println("emit 1 ${this.hashCode()}")
            emit("${System.currentTimeMillis()}")
            delay(1000)
            println("emit 2 ${this.hashCode()}")
            emit("${System.currentTimeMillis()}")
        }
        runBlocking {
            val l = flow.take(1)
            println("------ take(1) collect 1 ------")
            l.collect()
            println("------ take(1) collect 2 ------")
            l.collect()

            println("------ collect 1 ------")
            flow.collect()
            println("------ collect 2 ------")
            flow.collect()

            println("------ Flow Collect End ------")
        }
    }

输出:

------ take(1) collect 1 ------
emit 1 398887205
------ take(1) collect 2 ------
emit 1 1121172875
------ collect 1 ------
emit 1 649734728
emit 2 649734728
------ collect 2 ------
emit 1 1595953398
emit 2 1595953398
------ Flow Collect End ------

Android Unit Test

dependencies

    testImplementation "junit:junit:4.13.2"
    testImplementation "androidx.test:core:1.3.0"
    testImplementation "androidx.test:core-ktx:1.3.0"
    testImplementation "androidx.test.ext:junit:1.1.2"
    testImplementation "androidx.test.ext:junit-ktx:1.1.2"
    testImplementation "androidx.arch.core:core-testing:2.1.0"
    testImplementation "org.robolectric:robolectric:4.3.1"

Android Hilt

Component

ActivityComponent

定义ActivityComponent模块

interface IApi {

    fun sayHello()
}

class IApiImpl @Inject constructor(@ActivityContext private val context: Context) : IApi {

    override fun sayHello() {
        Log.e("IApiImpl${this.hashCode()}", "sayHello ${context}")
    }
}

@Module
@InstallIn(ActivityComponent::class)
abstract class ApiModule {

    @Binds
    abstract fun bindApi(apiImpl: IApiImpl): IApi
}

在Activity中注入

@AndroidEntryPoint
class TestActivity: AppCompatActivity() {

    @Inject lateinit var iApi: IApi
    @Inject lateinit var iApi2: IApi
}

class Test2Activity: AppCompatActivity() {

    @Inject lateinit var iApi: IApi
}

TestActivityTest2Activity中获取到的IApi对象为不同的实例。
TestActivityiApiiApi2也是不同的实例对象。

SingletonComponent、Singleton

修改IApiImpl和ApiModule,将IApiImpl修改为单例实现。

@Singleton
class IApiImpl @Inject constructor(@ApplicationContext private val context: Context) : IApi {

    override fun sayHello() {
        Log.e("IApiImpl${this.hashCode()}", "sayHello ${context}")
    }
}

@Module
@InstallIn(SingletonComponent::class)
abstract class ApiModule {

    @Binds
    abstract fun bindApi(apiImpl: IApiImpl): IApi
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.