kotlin

How to use FunSpec.overriding? in KotlinPoet

夙愿已清 提交于 2021-02-11 13:34:36
问题 Submitted by Fleshgrinder on GitHub. The FunSpec class has the very handy overriding method, however, it is unclear how this can be used while generating code. Minimal example: FileSpec.builder("com.fleshgrinder", "KotlinPoet").apply { val className = ClassName("com.fleshgrinder", "KotlinPoet") addType(TypeSpec.classBuilder(className).apply { addFunction(FunSpec.builder("toString").apply { addModifiers(KModifier.OVERRIDE) addStatement("""return "KotlinPoet"""") }.build()) }.build()) }.build()

Need help to parse mealtype on glucometer android BLE

佐手、 提交于 2021-02-11 13:20:56
问题 Need help to parse mealtype on glucometer android BLE. https://github.com/oesmith/gatt-xml/blob/master/org.bluetooth.characteristic.glucose_measurement_context.xml Here's my data: [27, 5, 0, -28, 7, 8, 24, 17, 18, 41, -29, 1, 102, -80, -8, 0, 0] I also found this one: C3: Field exists if the key of bit 1 of the Flags field is set to 1 Here's my enum public static Meal from(final int code) { switch (code) { case 1: return PREPRANDIAL; case 2: return POSTPRANDIAL; case 3: return FASTING; case 4

Hide status bar when sharing text android

泄露秘密 提交于 2021-02-11 12:44:57
问题 I have an app that i use this line to hide the status bar in all activities/dialogs this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); The problem comes when i share text with fun shareText(body: String) { val txtIntent = Intent(Intent.ACTION_SEND) txtIntent.type = "text/plain" intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK txtIntent.putExtra(Intent.EXTRA_TEXT, body) startActivity(Intent.createChooser(txtIntent, getString(R.string

Save image to specific directory in gallery android

十年热恋 提交于 2021-02-11 12:40:08
问题 I want to save image to a specific director in the gallery. The below code works fine but the image is storing into "Pictures" folder val bitmap: Bitmap = (iv_full_image.getDrawable() as BitmapDrawable).getBitmap() MediaStore.Images.Media.insertImage(getContentResolver(),bitmap, "photo" , "myImg") how do I store the image to a folder called "MyImages" in gallery. and is there any other way to store image to the gallery because it's saying insertImage(ContentResolver!, Bitmap!, String!, String

Save image to specific directory in gallery android

拟墨画扇 提交于 2021-02-11 12:39:18
问题 I want to save image to a specific director in the gallery. The below code works fine but the image is storing into "Pictures" folder val bitmap: Bitmap = (iv_full_image.getDrawable() as BitmapDrawable).getBitmap() MediaStore.Images.Media.insertImage(getContentResolver(),bitmap, "photo" , "myImg") how do I store the image to a folder called "MyImages" in gallery. and is there any other way to store image to the gallery because it's saying insertImage(ContentResolver!, Bitmap!, String!, String

CameraX Multiple Back Cameras

人走茶凉 提交于 2021-02-11 12:38:05
问题 I'm trying to implement a custom camera app using CameraX. Seeing as a lot of new devices have multiple back cameras now, I also want to include that. So basically, the user can select which camera to use. I've tried the following using the addCameraFilter option: val cameraSelector = CameraSelector.Builder() .requireLensFacing(when (camera.cameraSettings?.lensFacing?.let { LensFacing.valueOf(it) }) { LensFacing.Back -> CameraSelector.LENS_FACING_BACK else -> CameraSelector.LENS_FACING_FRONT

Null check on more than one variable

与世无争的帅哥 提交于 2021-02-11 12:32:38
问题 is it possible to reformat this piece of code in Kotlin, that it gets a bit smaller? The function should return A and B as a Pair, if both are unequal to null. Else it should return null. My first idea was like this: private fun <A, B> zip(a: A?, b: B?): Pair<A, B>? = if (a != null && b != null) a to b else null Then I decided to use the Elvis Operator. So it now looks like this: private fun <A, B> zip(a: A?, b: B?): Pair<A, B>? { a ?: return null b ?: return null return a to b } But what I

Kotlin DateTimeParseException

此生再无相见时 提交于 2021-02-11 12:32:24
问题 Getting date from https://api.spacexdata.com/v3/launches This date have format: 2006-03-25T10:30:00+12:00. I want convert it to "dd, mm, yyyy", but always getting error: "java.time.format.DateTimeParseException: Text '2006-03-25T10:30:00+12:00' could not be parsed, unparsed text found at index 10" my code: val formatter = DateTimeFormatter.ofPattern("dd, mm, yyyy", Locale.US) val myDate = LocalDate.parse(launchDate, formatter) var launchDateConverted: String= myDate.toString() i getting data

Observing MediatorLiveData Issue

穿精又带淫゛_ 提交于 2021-02-11 12:32:23
问题 I have the following LiveData variables in my ViewModel (simplified example): val currentUser : LiveData<UserObject> val allSites : LiveData<ArrayList<SiteObject>> val filterSitesForUser : LiveData<Boolean> val orderSitesByField : LiveData<String> val orderSitesDirection : LiveData<Query.Direction> val searchFilterSitesText : LiveData<String> I'm trying to use MediatorLiveData to have one 'stream' of data connecting to my RecyclerView . I therefore also have the following code in the

Callbacks between java and kotlin

二次信任 提交于 2021-02-11 12:23:59
问题 Initially, I had API calls in an adapter class which is in Java, I moved the API calls from the adapter to a presenter(Kotlin file). Adapter(java file) requests to do an API call, from adapter, code moves to presenter (kotlin file) presenter does the actual API call when the response comes or error, adapter methods need to be called. I implemented callbacks/interface, to do this Interface: interface ServiceOrderAdapterInterface { fun flOrderOfflineAcceptSuccess(flOrder: FlOrder) fun