kotlin

【44】kotlin 协程 异步下载图片4 解决线程安全问题

半城伤御伤魂 提交于 2020-07-26 16:02:47
我们的图片地址 是写死的。。但是为了防止出现线程安全问题 我们在async新建 ContextContinuation.kt package com.yzdzy.kotlin.chapter7.async import kotlin.coroutines.Continuation import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext /** * Created by benny on 5/29/17. */ class ContextContinuation(override val context: CoroutineContext = EmptyCoroutineContext): Continuation<Unit> { override fun resumeWith(result: Result<Unit>) { } } 里面不做操作 修改 BaseCoroutines.kt package com.yzdzy.kotlin.chapter7.basic import cn.kotliner.coroutine.common.HttpError import cn.kotliner.coroutine.common.HttpException

2D Array in Kotlin

孤街浪徒 提交于 2020-07-26 07:54:45
问题 How do you make a 2D Int array in Kotlin? I'm trying to convert this code to Kotlin: int[][] states = new int[][] { new int[]{-android.R.attr.state_pressed}, // not pressed new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { foregroundColor, accentColor, accentColor }; ColorStateList myList = new ColorStateList(states, colors); Here is one attempt I tried, where the first 2D array didn't work, but I got the 1D array to work: //This doesn't work: var states:

2D Array in Kotlin

大憨熊 提交于 2020-07-26 07:54:36
问题 How do you make a 2D Int array in Kotlin? I'm trying to convert this code to Kotlin: int[][] states = new int[][] { new int[]{-android.R.attr.state_pressed}, // not pressed new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { foregroundColor, accentColor, accentColor }; ColorStateList myList = new ColorStateList(states, colors); Here is one attempt I tried, where the first 2D array didn't work, but I got the 1D array to work: //This doesn't work: var states:

2D Array in Kotlin

荒凉一梦 提交于 2020-07-26 07:54:29
问题 How do you make a 2D Int array in Kotlin? I'm trying to convert this code to Kotlin: int[][] states = new int[][] { new int[]{-android.R.attr.state_pressed}, // not pressed new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { foregroundColor, accentColor, accentColor }; ColorStateList myList = new ColorStateList(states, colors); Here is one attempt I tried, where the first 2D array didn't work, but I got the 1D array to work: //This doesn't work: var states:

【40】kotlin 协程 异步下载图片3

我们两清 提交于 2020-07-26 05:51:11
改为异步 新建async包 新建AsyncTask.kt package com.yzdzy.kotlin.chapter7.async import java.util.concurrent.Executors //线程池 private val pool by lazy { Executors.newCachedThreadPool() } class AsyncTask(val block: () -> Unit) { fun execute() = pool.execute(block) } 修改BaseCoroutines.kt package com.yzdzy.kotlin.chapter7.basic import cn.kotliner.coroutine.common.HttpError import cn.kotliner.coroutine.common.HttpException import cn.kotliner.coroutine.common.HttpService import cn.kotliner.coroutine.common.log import cn.kotliner.coroutine.ui.LOGO_URL import com.yzdzy.kotlin.chapter7.async.AsyncTask import java

【56】kotlin搭建mvp。

丶灬走出姿态 提交于 2020-07-25 18:17:22
首先搭建Base. BaseView package com.anguo.baselibary.presenter.view interface BaseView { fun showLoading() fun hideLoading() fun onError() } BasePresenter package com.anguo.baselibary.presenter import com.anguo.baselibary.presenter.view.BaseView open class BasePresenter<T:BaseView> { lateinit var mView:T } 实际运行模块 为用户中心 RegisterView package com.anguo.user.present.view import com.anguo.baselibary.presenter.view.BaseView interface RegisterView:BaseView { fun onRegisterResult(result:Boolean){ } } RegisterPersenter package com.anguo.user.present import com.anguo.baselibary.presenter.BasePresenter import

【47】kotlin IO操作

北城余情 提交于 2020-07-25 18:00:38
File Stream Reader Writer的扩展方法 使用use扩展关闭资源 小文件,一次性读写操作 java code package com.yzdzy.kotlin.chapter8.io; import java.io.*; public class IO { public static void main(String[] args) { BufferedReader bufferedReader = null; try { bufferedReader=new BufferedReader(new FileReader(new File("build.gradle"))); String line; while ((line=bufferedReader.readLine())!=null){ System.out.println(line); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } } kt

【55】Kotlin android Anko 神兵利器2

狂风中的少年 提交于 2020-07-25 11:20:08
还是建议去官网学习 https://github.com/JetBrains/anko 总共分为了四个模块 Anko是 Kotlin 库,可以使Android应用程序的开发变得更快,更轻松。它使您的代码干净且易于阅读,并且使您无需理会Android SDK for Java的粗糙之处。 Anko包含以下几个部分: Anko Commons :一个轻量级的库,其中包含用于意图,对话框,日志记录等的帮助程序; Anko Layouts :一种快速且类型安全的方式来编写动态Android布局; Anko SQLite :Android SQLite的查询DSL和解析器集合; Anko Coroutines :基于 kotlinx.coroutines 库的实用程序。 基于Gradle的项目 Anko具有元依赖性,可将所有可用功能(包括Commons,Layouts,SQLite)立即插入您的项目中: dependencies { implementation "org.jetbrains.anko:anko:$anko_version" } 确保 $anko_version 在项目级别的gradle文件中已结算: ext.anko_version='0.10.8' 如果仅需要某些功能,则可以引用Anko的任何部件: dependencies { // Anko Commons

【51】 kotlin 编写kts脚本

一曲冷凌霜 提交于 2020-07-24 23:01:02
添加依赖支持 implementation "org.jetbrains.kotlin:kotlin-script-runtime:$kotlin_version" 新建文件HelloWord.kts 内容 println("Hello world") 编译运行 import java.io.File println("Hello world") //打印当前文件的所有文件 File(".").list().forEach(::println) //运行原理 会编译成一个类,然后实例化 来源: oschina 链接: https://my.oschina.net/u/4303372/blog/4321553