Tag: 安卓

Kotlin和Android lint检查

我真的很喜欢在Kotlin中编写android应用程序 – 但我真的很想念lint。 任何人都知道如何取回(至少部分)。 有没有一个项目,适应android java lint规则kotlin? AFAIK lint没有在字节码上运行,所以需要手动转换才能完成。 我目前的主要痛点是,当我使用一个函数<MINSDK级别时,我需要编译时错误有人能指出我正确的方向吗?

文档模板生成kotlin

之前在Android Studio中工作,如果在函数之前,我把/ **和回车,然后我自动生成的下一个文档,注释描述参数,返回值等 /** * @params a * @return */ int f(int a) { return a; } 当我开始在Android Studio中使用Kotlin时,我试图生成一个类似的模板,它生成没有返回,参数等的空白模板。 /** * */ fun f(a: Int) { return a } 我安装了Dokka并试图在Android Stuio中设置它,但是没有奏效。 如何在Android Studio中为Kotlin配置类似的模板生成?

Kotlin – 不变的参考

我正在尝试使用新的相机硬件API(android.hardware.camera2)为我的android应用程序的示例代码。 首先,我通过Android Studio的Kotlin插件的自动转换function将Java代码转换为Kotlin代码。 下面是一段转换后的代码: private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() { private fun process(result: CaptureResult) { when (mState) { STATE_PREVIEW -> { }// We have nothing to do when the camera preview is working normally. STATE_WAITING_LOCK -> { val afState = result.get(CaptureResult.CONTROL_AF_STATE) if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) { // CONTROL_AE_STATE can […]

Kotlin到Java(图书馆帮助)

我正在使用这个库来生成渐变: https : //github.com/revely-inc/co.revely.gradient 用于设置渐变animation的kotlin代码如下所示: val color1 = Color.parseColor(“#00c6ff”) val color2 = Color.parseColor(“#ff72ff”) val valueAnimator = ValueAnimator.ofFloat(0f, 360f) valueAnimator.duration = 15000 valueAnimator.repeatCount = ValueAnimator.INFINITE valueAnimator.interpolator = LinearInterpolator() RevelyGradient.sweep() .colors(intArrayOf(color1, color2, color1)) .animate(valueAnimator, { _valueAnimator, _gradientDrawable -> _gradientDrawable.angle = _valueAnimator.animatedValue as Float }) .onBackgroundOf(container) valueAnimator.start() 我到目前为止所获得的java代码: ValueAnimator valueAnimator = new ValueAnimator(); valueAnimator.ofFloat(0f, 360f); valueAnimator.setDuration(15000); valueAnimator.setRepeatCount(ValueAnimator.INFINITE); valueAnimator.setInterpolator(new […]

Kotlin的generics和抽象类

我有一个基本的抽象类: abstract class BaseFragment : Fragment(){ protected var presenter : T? = null abstract fun providePresenter() : T abstract fun getLayoutId() : Int abstract fun onCreate() override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { val root = inflater?.inflate(getLayoutId(), container, false) presenter = providePresenter() return root } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { […]

将Stripe的creatToken转换成Kotlin

我已经在Kotlin中构建了大部分的Android应用程序。 现在我正在使用条形支付库,我不能将下面的例程转换成Kotlin。 stripe.createToken( cardtoSave, new TokenCallback { public void onSuccess(Token token) { // Send token to your server } public void onError(Exception error) { // Show localized error message Toast.makeText(getContext(), error.getLocalizedString(getContext()), Toast.LENGTH_LONG ).show(); } } ) 只是不确定是否有可能…

Kotlin androidTest:测试运行完成。 空的测试套件

我正试图将我的测试从java转换为kotlin。 简单的unit testing翻译成功,如下所示: class BindingUtilsTest { @Test @Throws(Exception::class) fun testConvertBooleanToVisibility_visible() { assertEquals(BindingUtils.convertBooleanToVisibility(true), View.VISIBLE) } } 但是,当我试图运行androidTest失败,消息:“没有测试被发现”和 测试运行开始 测试运行完成。 空的测试套件。 代码工作完美,当在Java中。 相关代码: build.gradle部分: apply plugin: “com.android.application” apply plugin: “com.neenbedankt.android-apt” // for tests apply plugin: ‘kotlin-android’ // defaultConfig testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” sourceSets { test.java.srcDirs += ‘src/test/kotlin’ // tests are there androidTest.java.srcDirs += ‘src/androidTest/kotlin’ // and there } // […]

Android中的与Kotlin的AsyncTask

如何使用Kotlin在Android中进行API调用? 我听说过安科 但是我想要像Android一样使用Kotlin提供的方法,我们有Asynctask作为后台操作。

在kotlin测试

我是kotlin开发kotlin 。 在我的应用程序中,我想编写测试用例,但是我无法使用它。 Src / test / kotlin文件夹没有被创建 gradle这个 android { compileSdkVersion 27 defaultConfig { applicationId “in.getparking.getparkingattendant” minSdkVersion 23 targetSdkVersion 27 versionCode 1 versionName “1.0” multiDexEnabled true testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’ } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } sourceSets { test.java.srcDirs += ‘src/test/kotlin’ androidTest.java.srcDirs += […]

科特林匕首不注射

我最近从java移动到kotlin,并尝试实施匕首2dependency injection。 我已经添加到我的gradle apply plugin: ‘kotlin-kapt’ implementation “com.google.dagger:dagger:2.11” kapt “com.google.dagger:dagger-compiler:2.11” compileOnly ‘javax.annotation:jsr250-api:1.0’ 这是我的模块 @Module class AppModule(val context : Context) { @Provides @Singleton fun provideContext() = context } 这是我的组件 @Singleton @Component(modules = arrayOf(AppModule::class)) interface AppComponent { fun inject(application: Application) } 这是我的应用程序 class MyApplication : Application() { @Inject lateinit var context : Context lateinit var appComponent : […]