kotlin

how to use poll(2) or select(2) service call to watch a pseudo file for changes with Kotlin

这一生的挚爱 提交于 2021-01-07 02:42:10
问题 I am working with a DragonBoard 410C using Android 5.1 and Kotlin to experiment with the GPIO pins on the 40 pin low power connector. The library I'm using is using the sysfs interface for interacting with the GPIO pins which requires opening various pseudo files in /sys/class/gpio/ directory tree and reading and writing values to those files, see accessing GPIO low power connector on DragonBoard 410C running Android My understanding is that I can provision a GPIO pin as Input and Edge

Access view on content_main.xml from a fragment?

橙三吉。 提交于 2021-01-07 01:28:02
问题 In my app I use NavController with Fragments. In some fragments I need to access views on MainActivity layout. I do that in this way: val fab: FloatingActionButton = requireActivity().findViewById(R.id.fab) This works properly as expected. However, one view does not want to be called and the findViewById() returns null. The layout structure is like this. In activity_main.xml <androidx.drawerlayout.widget.DrawerLayout <androidx.coordinatorlayout.widget.CoordinatorLayout ....> <FrameLayout

Android material button taking color primary instead of color accent

跟風遠走 提交于 2021-01-07 01:21:34
问题 I have my layout button as - <com.google.android.material.button.MaterialButton android:id="@+id/save_button" style="@style/buttonView" android:text="Save" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> In my styles.xml , I have - <style name="buttonView" parent="Theme.MyTheme"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginStart">16dp</item> <item

How To Use Async/Await/Coroutines In OnCompleteListener Firebase

穿精又带淫゛_ 提交于 2021-01-05 12:01:59
问题 I am building a client application which uses Firebase for two things: User Authentication Using a realtime database I have managed to set up everything correctly on my client and on my backend server (using Firebase's Admin SDK) and am able to correctly authenticate users and allow them to read/write to the database. I am also using Retrofit2 to send requests from the client to the backend. As part of allowing users access to the database, it is needed to send the user's token to the backend

阿里开源新一代单元测试 Mock 工具!

自作多情 提交于 2021-01-05 11:29:02
TestableMock 是基于源码和字节码增强的Java单元测试辅助工具,包含以下功能: 访问被测类私有成员:使单元测试能直接调用和访问被测类的私有成员,解决私有成员初始化和私有方法测试的问题 快速Mock任意调用:使被测类的任意方法调用快速替换为Mock方法,实现"指哪换哪",解决传统Mock工具使用繁琐的问题 辅助测试void方法:利用Mock校验器对方法的内部逻辑进行检查,解决无返回值方法难以实施单元测试的问题 访问私有成员字段和方法 如今关于私有方法是否应该做单元测试的争论正逐渐消停,开发者的普遍实践已经给出事实答案。通过公有方法间接测私有方法在很多情况下难以进行,开发者们更愿意通过修改方法可见性的办法来让原本私有的方法在测试用例中变得可测。 此外,在单元测试中时常会需要对被测对象进行特定的成员字段初始化,但有时由于被测类的构造方法限制,使得无法便捷的对这些字段进行赋值。那么,能否在不破坏被测类型封装的情况下,允许单元测试用例内的代码直接访问被测类的私有方法和成员字段呢?TestableMock提供了两种简单的解决方案。 方法一:使用`@EnablePrivateAccess`注解 只需为测试类添加 @EnablePrivateAccess 注解,即可在测试用例中获得以下增强能力: 调用被测类的私有方法(包括静态方法) 读取被测类的私有字段(包括静态字段)

SceneForm sceneview always black in fragment

我怕爱的太早我们不能终老 提交于 2021-01-05 11:28:12
问题 I am trying to render a 3d model on sceneview but i am getting black screen no matter what i do . what i am trying to do is to load a 3d model like in ARFragment but with more sceneview like features. here is the code for my layout <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

SceneForm sceneview always black in fragment

£可爱£侵袭症+ 提交于 2021-01-05 11:26:07
问题 I am trying to render a 3d model on sceneview but i am getting black screen no matter what i do . what i am trying to do is to load a 3d model like in ARFragment but with more sceneview like features. here is the code for my layout <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

Kotlin Coroutine Scope : Is return@runBlocking an issue if used in Controller Endpoint

自作多情 提交于 2021-01-05 08:59:25
问题 Purpose: I want to code an Endpoint which consume another Endpoint taking advantage of light Coroutines assuming I am coding a light assyncronous EndPoint client. My background: first time trying to use Kotlin Coroutine. I have studied last days and search around. I found numerous article explaining how use Coroutine in Android and I found few others explaining how use Coroutine in a main function. Unfortunatelly I didn't find articles explaining how code a Controller endpoint with coroutines

Proper way to operate collections in StateFlow

旧巷老猫 提交于 2021-01-05 08:56:55
问题 I'm creating MutableStateFlow like this: val intSet = MutableStateFlow(HashSet<Int>()) And in some moment later I want to update collection in this flow: intSet.value.add(0) And this doesn't seem to work (the collection updates, but observers are not notified). The way that I found it working: val list = HashSet<Int>(intSet.value) list.add(0) intSet.value = list But it creates copy of the collection, so it doesn't look proper for me. Is there any simpler way to update collection in StateFlow?

Proper way to operate collections in StateFlow

▼魔方 西西 提交于 2021-01-05 08:56:39
问题 I'm creating MutableStateFlow like this: val intSet = MutableStateFlow(HashSet<Int>()) And in some moment later I want to update collection in this flow: intSet.value.add(0) And this doesn't seem to work (the collection updates, but observers are not notified). The way that I found it working: val list = HashSet<Int>(intSet.value) list.add(0) intSet.value = list But it creates copy of the collection, so it doesn't look proper for me. Is there any simpler way to update collection in StateFlow?