00-面试查漏补缺

View绘制流程图

起点:ViewRootImpl

ViewRootImpl中有一个巨长的方法performTraversals,其中会依次调用三个函数

  • performMeasure
  • performLayout
  • performDraw

通过ViewRootImplsetView方法,ViewRootImpl对象会拥有一个mView对象

阅读更多

19-RecyclerView

RecyclerView

  • flexible:
  • limited: 有限屏幕中显示
  • large: 大量内容

RecyclerView的优势

  • Linear, Grid, Staggered Grid三种布局
  • itemAnimator接口
  • 强制实现ViewHolder
  • 解耦设计
  • 性能更好

listView的局限

  • 只能纵向列表

  • 没有动画api

  • api设计太个性了,和其他view设计的重复

  • 性能不好

  • 三个帮手

    • LayoutManager: 负责布局Views
    • ItemAnimator: 负责给View加动画
    • Adaptor: 提供views
阅读更多

20-Android多线程

Thread.yield()

  • 暂时把时间片让出去,变成可运行状态(ready)

handler

Looper

  • ThreadLocal的
  • 相当于一个线程里的大循环
  • 在大循环里循环从messageQueue中拿消息
  • 拿到消息后执行消息

Handler

阅读更多

18-Java多线程

Thread, Runnable, callable

  • 基础

ThreadFactory

1
2
3
public interface ThreadFactory {
Thread newThread(Runnable r);
}
  • 实现一个工厂,生成thread,方便对同类thread进行统一的初始化操作

Executor

阅读更多

21-RxJava

Single

static <T> Single.just(T t)

  • 生成一个Singled对象
    • return onAssembly(new SingleJust(t))
    • onAssembly是一个钩子函数,一般情况下不做任何操作,就是调用一个Function<T, R>.apply()

Observer

  • 有后续的onNext
  • 有周期的Observer.interval()每隔一段时间onNext一次

Disposable

阅读更多

06-OKHTTP

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
final Dispatcher dispatcher; // 线程控制
final @Nullable Proxy proxy; // 代理服务器,java.net
final List<Protocol> protocols;
final List<ConnectionSpec> connectionSpecs;
final List<Interceptor> interceptors;
final List<Interceptor> networkInterceptors;
final EventListener.Factory eventListenerFactory;
final ProxySelector proxySelector;
final CookieJar cookieJar;
final @Nullable Cache cache;
final @Nullable InternalCache internalCache;
final SocketFactory socketFactory;
final SSLSocketFactory sslSocketFactory;
final CertificateChainCleaner certificateChainCleaner;
final HostnameVerifier hostnameVerifier;
final CertificatePinner certificatePinner;
final Authenticator proxyAuthenticator;
final Authenticator authenticator;
final ConnectionPool connectionPool;
final Dns dns;
final boolean followSslRedirects;
final boolean followRedirects;
final boolean retryOnConnectionFailure;
final int callTimeout;
final int connectTimeout;
final int readTimeout;
final int writeTimeout;
final int pingInterval;

websocket

wikipedia:

  • 利用tcp提供全双工通信 WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
  • 运行在80/443端口上 WebSocket is designed to work over HTTP ports 443 and 80 as well as to support HTTP proxies and intermediaries

Dispatcher - 线程控制

使用Deque控制任务

阅读更多

05-Retrofit

HOST验证

在上节https的ca证书验证时,如果某个恶意网站直接获取整个ca证书,发给其他用户骗取信任怎么办。这个时候就需要host验证,即证书的host主机与发送证书的主机host是否是同一个域名。

fiddler如何抓包

fiddler是一个中间人,通过系统代理,浏览器/应用将请求发送至fiddler,fiddler自签一个证书与浏览器/应用使用,且需要用户向操作系统安装根证书。fiddler拿到数据包后再与服务器交互。

retrofit源码阅读

retrofit的使用

阅读更多

04-登录授权 Https TCP/IP

登录授权

Basic

在header中
Authorization: Basic username:password(Base64ed, encrypted)

Bearer

在header中
Authorization: Bearer bearer_token

这里的bearer_token就类似于github的Personal access tokens,在请求中持有token的请求,可以根据token的权限对第三方账号中的数据进行获取、修改

阅读更多