Repository navigation
Expand file tree
/
Copy pathindex.xml
More file actions
152 lines (133 loc) · 13.6 KB
/
Copy pathindex.xml
File metadata and controls
152 lines (133 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>minwang1</title>
<link>http://minwang1.github.io/</link>
<description>Recent content on minwang1</description>
<generator>Hugo -- gohugo.io</generator>
<language>zh-cn</language>
<lastBuildDate>Mon, 21 Mar 2022 22:01:14 +0800</lastBuildDate><atom:link href="http://minwang1.github.io/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Android dark 模式原理</title>
<link>http://minwang1.github.io/post/android-drak-theme/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/android-drak-theme/</guid>
<description>Android dark 模式原理 sRgb to lab revert l lab to sRGB float invertedL = std::min(110 - lab.L, 100.0f);
if (invertedL &lt; lab.L) {// 反转后的明度低于原明度,则使用反转后的明度lab.L = invertedL;// 使用 rgb 格式返回return LabToSRGB(lab, SkColorGetA(color));} else {// 直接返回原颜色return color;} 其他应用启动本应用ActivityStack如何处理 例如当前启动配置为A,当前栈情况 A-B,应用home进入后台,通过负一屏启动应用A。 如果不做任何处理,启动后栈情况:A-B-A。而预期栈情况仍热为A-B,即用户上一次操作状况。
解决方法: 通过splashActivity做中转。 1.创建一个空的SplashActivity,theme为透明,配置为启动activity。 2.在splashActivity中做转发处理,如果当前activity栈中有其他activity,则退出splashActivity,top activity会resume,如果没有其他activity,则启动 mainactivity。
统计启动时间 adb shell am start -S -R 10 -W com.example.app/.MainActivity
-S表示每次启动前先强行停止 -R表示重复测试次数。
application attachBaseContext开始计算时间,activity onWindowFocusChanged大致为用户可见,可计算启动结束时间。</description>
</item>
<item>
<title>Android字体小结</title>
<link>http://minwang1.github.io/post/android-font/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/android-font/</guid>
<description>字体小结: font family/typeface可以设置字体类别: 有衬:serif :字符有装饰适合打印显示 无衬:sans-serif :字符无饰适合显示屏显示 等宽:monospace:字符的宽度相等适合代码显示 fontStyle可设置字体粗细、倾斜 样式 字重 italic light 300 Regular 400 medium 500 bold 700 android 默认fontFamily 英文字符 roboto 中文字符 思源雅黑 Android 英文默认使用roboto字体,robot字体不包含cjk(汉字)字符,如果显示汉字字符,会使用对应的思源雅黑字体。
思源雅黑Android中没有medium样式,所以如果代码中仅仅设置了sans-serif-medium,英文字符能正常显示,中文字符不能正常显示需要通过指定fontweight:500替代显示</description>
</item>
<item>
<title>Android常用性能分析</title>
<link>http://minwang1.github.io/post/performance-analyze/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/performance-analyze/</guid>
<description>perfetto 工具 (替代systrace) 加载:perfetto 会生成.perfetto-trace文件 加载.perfetto-trace文件需要使用网站 https://ui.perfetto.dev/#!/ 网站抓取:打开网站,选择record new trace选项,经行配置后可抓取,需要Android 10以上设备,并且厂商设备支持 adb抓取:用网站抓取的步骤,正确的选择设备版本,不同版本使用的命令不同,点击startRecording后会出现recording command。 将recordingcommand粘贴到shell中执行。 手机上抓取:手机进入开发者模式,找到系统跟踪选项,点击清除已保存跟踪路径,会弹出对话框显示文件生成保存路径。打开显示快捷设置图块。 然后可以再下拉菜单中开启、关闭抓取了。 分析 操作和分析和systrace类似
查看掉帧进程 常看进程中线程阻塞/耗时情况 如果是阻塞,可继续分析是否被其他进程block 了解大概耗时代码位置,接着用CPU Profiler分析具体那些地方耗时过长 CPU Profiler AS 3.0之后版本支持,替代Android Monitor tools
使用 点击 View &gt; Tool Windows &gt; Android Profiler(也可以点击底部工具栏中的Profiler)。 点击+号,添加目标进程,点击cpu选项,选择record java method,进行问题复现,点击stopRecording 对相关结果分析,可通过topdown等tab,快速定位 特殊场景
启动性能分析 可通过adb shell am start -W pakageName/activityClassPath 命令,查看冷启动耗时 可以注意到AS CPU Profiler只能检测启动中的进程,这时候需要通过插桩方式,在设备中生成trace,再将tarce拉取到AS中分析 具体步骤为:
application 中 onCreate()方法加入 Debug.startMethodTracing(&ldquo;sample-name&rdquo;); 在启动绘制结束地方,activity中onWindownFocusChange()中可添加Debug.stopMethodTracing(); 复现问题后,系统将在getExternalFilesDir() 目录下生成 .</description>
</item>
<item>
<title>Emoji二三事</title>
<link>http://minwang1.github.io/post/emoji/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/emoji/</guid>
<description>Emoji二三事 进行文本处理时常常会遇到以下emoji相关的问题:
emoji无法显示 带emoji文本的省略(Elipze)问题 自定义emoji 以下逐个讨论。
要弄清楚emoji问题,首先要了解emoji的组成 目前字符编码标准
1 Byte = 8 bite = 8b = 8位 = 8比特
1 char = 2 Byte = 2B = 2字节 = 1字符
编码 宽度 范围 特点 1.ASCII 8 bit 0~127 定义字符少只能显示英文 2.Unicode 2 Byte 0~2^16 特殊编码方式,Unicode的实现方式称为Unicode转换格式(Unicode Transformation Format,简称为UTF) 3.Utf-8 1 Byte Unicode 一种,分平面显示:兼容ascii平面,拉丁文平面,其他文本平面,辅助平面 3.Utf-16 2 Byte Unicode 一种,分平面显示:兼容ascii平面,拉丁文平面,其他文本平面,辅助平面 UTF-16 编码实现方式:</description>
</item>
<item>
<title>EventBus原理</title>
<link>http://minwang1.github.io/post/eventbus/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/eventbus/</guid>
<description>#EventBus
优缺点 优点
跨组件事件通信功能
轻量,快速,代码优化
使用简单缺点
过于“低耦合”,造成代码几个混乱,难以测试和追踪。
无法进程IPC, 配置了Android:process的service无法使用eventBus通信。 ### 使用方法1. Define events:
public static class MessageEvent { /* Additional fields if needed */ } Prepare subscribers: Declare and annotate your subscribing method, optionally specify a thread mode:
@Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(MessageEvent event) {/* Do something */}; Register and unregister your subscriber. For example on Android, activities and fragments should usually register according to their life cycle:</description>
</item>
<item>
<title>gitCheatSheet</title>
<link>http://minwang1.github.io/post/gitcheatsheet/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/gitcheatsheet/</guid>
<description>git command cheat sheet HEAD指向当前操作的地方 相对引用:~Num 是num笔提交的引用,^指向1比提交引用。^ == ~1 HEAD~1 指向HEAD之前一笔提交,HEAD~2指向HEAD之前2笔提交 HEAD^2 比较特殊,指向HEAD最近的父合并节点的第二个合并提交。 git describe &lt;ref&gt; 命令用来描述离你最近的锚点 (tag), 它输出的结果是这样的:&lt;tag&gt;_&lt;numCommits&gt;_g&lt;hash&gt;
git tag &lt;tagName&gt; &lt;ref&gt; 在ref位置添加一个锚点
git rebase &lt;targetBranch&gt; 将当前分支合并到目标分支上,并且切换到合并后的分支上。
git rebase -i 交互式rebase,可以合并多比提交
git reset &lt;ref&gt; 本地仓库代码回退到&lt;ref&gt;指定的提交地方
git revert &lt;ref&gt; 删除到&lt;ref&gt;提交,会产生一个删除代码的提交
==================远程操作=========================
&lt;remote&gt; 远程仓库名称,默认origin
git push &lt;remote&gt; &lt;place&gt;
git push origin master</description>
</item>
<item>
<title>Java8流式编程</title>
<link>http://minwang1.github.io/post/streaming-programming/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/streaming-programming/</guid>
<description>流式编程 背景 利用流,我们无需迭代集合中的元素,就可以提取和操作它们。这些管道通常被组合在一起,在流上形成一条操作管道
java7 过渡到 java8,直接向接口添加新方法会破坏所有老的接口实现类。Java 8 采用的解决方案是:在接口中添加被 default(默认)修饰的方法。
default Streamstream()https://github.com/LingCoder/OnJava8/blob/master/docs/book/14-Streams.md
相关API 流的生成 Stream.of()/Colleaction.stream()/Colleaction.iterator()创建流 Random 子方法生成随机流 BaseStream 相关子类方法生成流 正则表达式匹配后结果生成流 中间操作 流中获取对象,将对象作为一个流从后端输出。
peek()允许你无修改地查看流中的元素。 示例peek(e -&gt; System.out.println(&ldquo;Filtered value: &quot; + e))* sorted() 元素排序。示例sorted(Comparator.reverseOrder())* distinct() 移除重复元素,类似Set的功能。示例list.stream().distinct(); filter(Predicate) 根据Predicate给的函数条件过滤元素。 示例filter(e -&gt; e &gt; 2); 应用到元素
map(Function) 将函数操作应用在输入流元素中,将返回元素集合传递到输出流中,可改变返回元素的类型。 示例map(e -&gt; e + 2);
mapToInt(ToIntFunction):操作同上,但结果是 IntStream。
mapToLong(ToLongFunction):操作同上,但结果是 LongStream。
mapToDouble(ToDoubleFunction):操作同上,但结果是 DoubleStream。
flatMap(Function) Function功能是产生一个流,flatMap用于组合返回的流,扁平化为元素。 例子Stream.</description>
</item>
<item>
<title>LifeCycle原理</title>
<link>http://minwang1.github.io/post/about-lifecycle/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/about-lifecycle/</guid>
<description>1.what lifeCycle use for ? Lifecycles是一个持有组件生命周期状态(Activity、Fragment)信息的类,用来解决生命周期管理问题的组件。 通过监听生命周期的方式(Handling Lifecycles with Lifecycle-Aware Components),并允许其他对象观察此状态。
在Android框架中生命周期是由系统管理的,应用必须要遵循,否则可能会导致内存泄漏等严重问题。 此外,无法保证组件会在 Activity 或 Fragment 停止之前启动。在我们需要执行长时间运行的操作(如 onStart() 中的某种配置检查)时尤其如此。这可能会导致出现一种竞争条件,在这种条件下,onStop() 方法会在 onStart() 之前结束, 这使得组件留存的时间比所需的时间要长。
所以需要Lifecycle这个组件来帮助我们管理生命周期。 Lifecycle 是一个类,用于存储有关组件(如 Activity 或 Fragment)的生命周期状态的信息,并允许其他对象观察此状态。
lifeCycle中有如下状态图,以将状态看作图中的节点,将事件看作这些节点之间的边。
2.LifeCycle 组件的使用方法 如何让一个对象有activity生命周期? 实现LifecycleOwner接口,表示类有生命周期。 注册LifecycleObserver到LifecycleOwner中。 class MyActivity extends AppCompatActivity { private MyLocationListener myLocationListener; public void onCreate(...) { myLocationListener = new MyLocationListener(this, getLifecycle(), location -&gt; { // update UI }); Util.</description>
</item>
<item>
<title>设计模式-动态代理</title>
<link>http://minwang1.github.io/post/dynamic-proxy/</link>
<pubDate>Mon, 21 Mar 2022 22:01:14 +0800</pubDate>
<guid>http://minwang1.github.io/post/dynamic-proxy/</guid>
<description>使用代码 范例 public class ProxyTest { @Test public void startTest() { //创建被代理对象, 实现了sayHello接口 Hello toBeProxy = () -&gt; System.out.println(&#34;say hello&#34;); //创建handler对象 //创建代理对象 Hello hello = (Hello) Proxy.newProxyInstance(Hello.class.getClassLoader(), new Class[]{ Hello.class}, new HelloHandler(toBeProxy)); //执行代理对象的sayHello方法 hello.sayHello(); } interface Hello { void sayHello(); } public class HelloHandler implements InvocationHandler { private Object target; public HelloHandler(Object target) { this.</description>
</item>
</channel>
</rss>