kotlin

Java String class replaceAll method missing

橙三吉。 提交于 2020-12-30 04:49:47
问题 I'm having a very weird issue right now, the replaceAll method is missing from the String object. JDK version: 1.8.0 Android Studio version: 3.1.3 Kotlin version: 1.2 It hasn't been removed, so whats going on here?? 回答1: You can do this with just replace in Kotlin: "foo and foo".replace("foo", "bar") // "bar and bar" Note that the call above replaces the literal strings, if you need a Regex as the first parameter you can do either of the following: "foo and bar".replace("[abcd]".toRegex(), "x

Java String class replaceAll method missing

ぃ、小莉子 提交于 2020-12-30 04:49:27
问题 I'm having a very weird issue right now, the replaceAll method is missing from the String object. JDK version: 1.8.0 Android Studio version: 3.1.3 Kotlin version: 1.2 It hasn't been removed, so whats going on here?? 回答1: You can do this with just replace in Kotlin: "foo and foo".replace("foo", "bar") // "bar and bar" Note that the call above replaces the literal strings, if you need a Regex as the first parameter you can do either of the following: "foo and bar".replace("[abcd]".toRegex(), "x

Not able to add iOS custom framework to a KMM (Kotlin Multi Platform) module (cinteropXXXIosArm64 FAILED module not found)

不想你离开。 提交于 2020-12-30 03:36:10
问题 I'm developing an iOS app, which makes use of a Kotlin Native share module. This Kotlin Native shared module, makes use of a self-developed iOS framework. This had worked very well in the past, but now I'm trying to upgrade my project for the last release of Kotlin Native (1.4.10 at this moment), Android Studio, and so on, and I'm not able to import my custom iOS framework dependency. The folder structure of the iOS framework is the following: Following the guide at https://kotlinlang.org

Not able to add iOS custom framework to a KMM (Kotlin Multi Platform) module (cinteropXXXIosArm64 FAILED module not found)

不羁岁月 提交于 2020-12-30 03:34:05
问题 I'm developing an iOS app, which makes use of a Kotlin Native share module. This Kotlin Native shared module, makes use of a self-developed iOS framework. This had worked very well in the past, but now I'm trying to upgrade my project for the last release of Kotlin Native (1.4.10 at this moment), Android Studio, and so on, and I'm not able to import my custom iOS framework dependency. The folder structure of the iOS framework is the following: Following the guide at https://kotlinlang.org

How to crop image rectangle in camera preview on CameraX

孤人 提交于 2020-12-29 13:13:38
问题 I have a custom camera app which has a centered rectangle view, as you can see below: When I take a picture I want to ignore everything outside the rectangle. And this is my XML layout: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height=

Multiple click listeners on buttons

烂漫一生 提交于 2020-12-29 12:07:02
问题 I want to know how to add multiple click events to buttons defined in XML, as previously, in Java, we implemented View.onClickListener interface and did the rest of the work in onClick method. Example: @Override public void onClick(View v) { switch (v.getId()) { case R.id.oneButton: // do your code break; case R.id.twoButton: // do your code break; case R.id.threeButton: // do your code break; default: break; } } I'm making a basic calculator app with the new Kotlin but it seems Kotlin has no

Multiple click listeners on buttons

女生的网名这么多〃 提交于 2020-12-29 11:57:30
问题 I want to know how to add multiple click events to buttons defined in XML, as previously, in Java, we implemented View.onClickListener interface and did the rest of the work in onClick method. Example: @Override public void onClick(View v) { switch (v.getId()) { case R.id.oneButton: // do your code break; case R.id.twoButton: // do your code break; case R.id.threeButton: // do your code break; default: break; } } I'm making a basic calculator app with the new Kotlin but it seems Kotlin has no

Room TypeConverter with constructer

北战南征 提交于 2020-12-29 06:35:48
问题 I have Room TypeConverter and I need to inject parameter to it's constructor class RoomConverters(moshi Moshi) { @TypeConverter fun fromUserActionLog(data: UserActionLogModel): String { return moshi.adapter(UserActionLogModel::class.java).toJson(data) } @TypeConverter fun toUserActionLog(json: String): UserActionLogModel { return moshi.adapter(UserActionLogModel::class.java).fromJson(json)} } } But when I can not annotate TypeConverter to database object with contructor; @Database(entities =

Room TypeConverter with constructer

南楼画角 提交于 2020-12-29 06:33:50
问题 I have Room TypeConverter and I need to inject parameter to it's constructor class RoomConverters(moshi Moshi) { @TypeConverter fun fromUserActionLog(data: UserActionLogModel): String { return moshi.adapter(UserActionLogModel::class.java).toJson(data) } @TypeConverter fun toUserActionLog(json: String): UserActionLogModel { return moshi.adapter(UserActionLogModel::class.java).fromJson(json)} } } But when I can not annotate TypeConverter to database object with contructor; @Database(entities =

When to use coroutineScope vs supervisorScope?

不羁岁月 提交于 2020-12-29 05:31:25
问题 Can someone explain what exactly is the difference between these two? When do you use one over the other? Thanks in advance. 回答1: The best way to explain the difference is to explain the mechanism of coroutineScope . Consider this code: suspend fun main() = println(compute()) suspend fun compute(): String = coroutineScope { val color = async { delay(60_000); "purple" } val height = async<Double> { delay(100); throw HttpException() } "A %s box %.1f inches tall".format(color.await(), height