leo


  • Home

  • Archives

Debug tools overview

Posted on 2018-11-30 | In Debug




Version

XMDebug is a debug tool to help developer

1.ScreenShot



图片名称
图片名称

2.Download

You can download from GitHub’s [releases page].

Or use Gradle:

1
2
3
4
5
6
7
8
repositories {
mavenCentral()
google()
}

dependencies {
implementation 'com.leo:debug:1.0.1'
}

3.How do I Use

3.1 App Info

You can see Activities, Services , Receivers ,Providers,Permissions colletions . Some Detail of your App like ,verson ,version code .

In Activities your can see All Activity . Press the item your can jump to the corresponding Activity .

3.1.1 Activities

3.1.2 Permissions .See the detail of Permissions

3.2 Exception Reports

You can see the bugs reports with the detail of code and the screenshot of the exception happen

3.3 Local Data

Detail of SharedPreference ,Sqlite, local Cache. You can also clean the data through this debug tools

3.4 Toast Activity Name

Switch On Show Activity Name ,You can see the toast of Activity of .



4.Start

4.1 First … emm ,you should implementation the library

4.2 In your custom application ,put the code below

 override fun onCreate() {
    super.onCreate()
    DebugCrashHandler.setCrashHandler(this)
}

these code use to capture the exceptions

4.3 put the DebugHomeActivity entrance in somewhere nobody know

GitPage

https://guobao90.github.io/2018/11/30/debug/

Author

leo, guobao9006@gmail.com

License

XMDebug is available under the MIT license. See the LICENSE file for more info.

Kotlin 常用扩展函数

Posted on 2018-09-30 | In kotlin

let run also with apply takeIf使用

let

let对对象T的扩展 ,接收的是T类型,返回的是R类型 。

  • 有自己的作用域
  • 作用域中的接收者是it
  • 返回值,返回最后一个对象
1
2
3
4
5
 val result ="Hello World".let {
println(it)
"Hello"
}
println(result)

输出结果

1
2
System.out: Hello World
System.out: Hello

使用?.let进行判断

1
2
3
4
5
6
7
private fun getInfo(jsonObject: JSONObject?): Info? {
return jsonObject?.let {
val uri = it.optString("uri")
val length = it.optString("length")
Info(uri, length)
}
}

这样写和用if判空的写法没有区别,实际上根据这段代码编译出的字节码反编译得到的java代码就是if…else…形式的。

Read more »

ConstraintLayout基础

Posted on 2018-08-30 | In 布局

ConstriantLayout

是什么?

ConstraintLayout,中文称约束布局,在2016年Google I/O大会时提出,2017年2月发布正式版,目前稳定版本为1.0.2。约束布局作为Google今后主推的布局样式,可以完全替代其他布局,降低页面布局层级,提升页面渲染性能。

使用

ConstraintLayout支持最低Android Studio版本是2.2,但是有些属性在2.2的布局编辑器上不支持编辑,如比例和baseline等约束。所以推荐使用2.3的版本,当然3.0的版本那就更好了。要使用ConstraintLayout,需要在项目中进行如下配置:
升级新版本的Android Studio 会默认添加这些依赖

Maven 依赖

implementation 'com.android.support.constraint:constraint-layout:1.1.2'

特性

  • 高级版RelativeLayout
  • 极大减少布局的嵌套,提高xml加载速度
  • 编写方式相对自由,可以实现各种复杂的样式

缺点

  • 大量增加xml行数
  • 需要定义大量的id
Read more »

kotlin 集合的扩展函数

Posted on 2018-06-30 | In kotlin

Kotlin 中使用 typealias 关键字定义类型映射,这里就定义了一个 kotlin.collections.ArrayList 与 java.util.ArrayList 的类型映射。

这意味着,所有在 Kotlin 中不加标注使用的 ArrayList 都是 kotlin.collections.ArrayList ,但这个类型并不真实存在,编译时会被转换为 java.util.ArrayList,通过 Java 代码调用 kotlin.collections.ArrayList 对象,会被自动转换为 java.util.ArrayList;而且所有 Java 中的 java.util.ArrayList 在 Kotlin 代码中都可以通过 kotlin.collections.ArrayList 调用。

Kotlin 中使用 typealias 关键字定义类型映射,这里就定义了一个 kotlin.collections.ArrayList 与 java.util.ArrayList 的类型映射。

Kotlin 原生支持大量操作符
Arrays.asList(array) listof 底层

####总数操作
any
如果至少有一个元素符合给出的判断条件,则返回true。

1
2
3
list = listOf(1, 2, 3, 4, 5, 6)
assertTrue(list.any { it % 2 == 0 })
assertFalse(list.any { it > 10 })

all
如果全部的元素符合给出的判断条件,则返回true。

1
2
assertTrue(list.all { it < 10 })
assertFalse(list.all { it % 2 == 0 })

count
返回符合给出判断条件的元素总数。

1
assertEquals(3, list.count { it % 2 == 0 })

fold
在一个初始值的基础上从第一项到最后一项通过一个函数累计所有的元素。

1
assertEquals(25, list.fold(4) { total, next -> total + next })

foldRight
与fold一样,但是顺序是从最后一项到第一项。

1
assertEquals(25, list.foldRight(4) { total, next -> total + next })

forEach
遍历所有元素,并执行给定的操作。

1
2
3
4
5
list.forEach { println(it) }
forEachIndexed
与forEach,但是我们同时可以得到元素的index。
list.forEachIndexed { index, value
-> println("position $index contains a $value") }

max
返回最大的一项,如果没有则返回null。

1
assertEquals(6, list.max())

maxBy
根据给定的函数返回最大的一项,如果没有则返回null。

1
2
// The element whose negative is greater
assertEquals(1, list.maxBy { -it })

min
返回最小的一项,如果没有则返回null。

1
assertEquals(1, list.min())
Read more »

MVP- architecture翻译

Posted on 2017-12-11 | In MVP

MVP- architecture翻译

原文地址 :https://github.com/googlesamples/android-architecture/tree/todo-mvp-clean/
翻译 : leo

总结

MVP clean architecture 是基于Clean Architecture.的准则的观点

基于MVP sample。添加了 domain layer 介于 presentation 和 repositories。同时也将整个app 分为三个层次处理

如下图所示
mvp 层次图

  • MVP: model view Presenter 设计准则
  • Domain : 处理所有的业务逻辑,注意是所有的业务逻辑。domain层是以presentation layer 层的use cases 或者 interactors 开始的。
  • Repository: 获取数据,以及数据的存储
Read more »

魔图的产品介绍

Posted on 2017-11-30 | In 魔图

产品介绍

基于千万车轮车主用户大数据分析综合评分,用户打分形成的最终推荐指数。竖轴表示推荐指数,横轴表示价格区间。通过展示的图形筛选出自己心仪的车型。展示各个车型的各项评分,车型以及竞品的对比关系。

基础类的构建

  1. 基础的画布类,定义画布的基础参数。主要就是画布的四个边界点的坐标
  2. 选中车型的类,保存选中车型的数据状态
  3. 数据处理类,将魔图的真实数据,转换成在画布上可以使用的数据
事件处理类
  1. 点击事件,滑动,放大,双击
  2. 缩放 使用Android系统提供的ScaleGestureDetector
  3. 手势识别 GestureDetectorCompat 通过这个类可以识别很多手势
  4. 滑动,方法都是通过手势产生的偏移对画布进行重新设置。滑动需要判断是否操作最大画布的边距。
  5. fling 惯性 ScrollerCompat 26.1.0 废弃了使用 OverScroller
  6. 点击 通过手势的识别

数据处理

  1. 圆圈放大的倍率计算分成了几部分处理。
  2. 车型展示的圆圈大小进行分级。便于显示管理处置。 对所有的圆的类型根据等级分成9级,按照2的倍数,排序圆圈

代码构建

d8f64ebb0799e21afcf2e6b128463509.png
代码的分层框架

Read more »

guobao

6 posts
5 categories
1 tags
© 2019 guobao
Powered by Hexo
|
Theme — NexT.Muse v5.1.4