安卓重要知识点

339 阅读20分钟

View绘制流程

安卓的绘制是在每个View的绘制方法(onDraw)里发生的,一个绘制view里写了什么代码,他就会绘制出什么内容,而自定义绘制就是通过重写绘制方法,插入你自己的绘制代码来实现的.绘制方法不止一个方法,其中最常用的是onDraw(),这个方法他负责view的主体绘制.例如TextView的文字,imageView里面的图像都是在onDraw()里绘制的.具体执行绘制的是onDraw()的canvas参数.比如你写一行canvas.drawCicle(),你的view就会在内部画一个圆显示给用户看.

Canvas:

canvas的绘制

把要的图形图案直接绘制在canvas中.让view显示出来

画弧形
public void drawArc(@NonNull RectF oval, float startAngle, float sweepAngle, 
boolean useCenter, @NonNull Paint paint)
public void drawArc(float left, float top, float right, float bottom, float startAngle, 
float sweepAngle, boolean useCenter, @NonNull Paint paint)

画颜色(通常用于画背景色和半透明遮罩)
public void drawARGB(int a, int r, int g, int b)
public void drawRGB(int r, int g, int b)
public void drawColor(@ColorInt int color)
public void drawColor(@ColorLong long color)
public void drawColor(@ColorInt int color, @NonNull PorterDuff.Mode mode)
public void drawColor(@ColorInt int color, @NonNull BlendMode mode)
public void drawColor(@ColorLong long color, @NonNull BlendMode mode)

画图片
public void drawPicture(@NonNull Picture picture)
public void drawPicture(@NonNull Picture picture, @NonNull RectF dst)
public void drawPicture(@NonNull Picture picture, @NonNull Rect dst)
画图片
public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint)
public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull RectF dst,
            @Nullable Paint paint)
public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst,
            @Nullable Paint paint)
已废弃:
public void drawBitmap(@NonNull int[] colors, int offset, int stride, float x, float y,
            int width, int height, boolean hasAlpha, @Nullable Paint paint)
已废弃:
public void drawBitmap(@NonNull int[] colors, int offset, int stride, int x, int y,
            int width, int height, boolean hasAlpha, @Nullable Paint paint)

public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint)
public void drawBitmapMesh(@NonNull Bitmap bitmap, int meshWidth, int meshHeight,
            @NonNull float[] verts, int vertOffset, @Nullable int[] colors, int colorOffset,
            @Nullable Paint paint)
画圆
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
画线
public void drawLine(float startX, float startY, float stopX, float stopY,
            @NonNull Paint paint)
public void drawLines(@Size(multiple = 4) @NonNull float[] pts, int offset, int count,
            @NonNull Paint paint)
public void drawLines(@Size(multiple = 4) @NonNull float[] pts, @NonNull Paint paint)
画椭圆
public void drawOval(@NonNull RectF oval, @NonNull Paint paint)
public void drawOval(float left, float top, float right, float bottom, @NonNull Paint paint)

画Paint
public void drawPaint(@NonNull Paint paint)

画Path
public void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst, @Nullable Paint paint)
public void drawPatch(@NonNull NinePatch patch, @NonNull RectF dst, @Nullable Paint paint)
public void drawPath(@NonNull Path path, @NonNull Paint paint)

画点
public void drawPoint(float x, float y, @NonNull Paint paint)
public void drawPoints(@Size(multiple = 2) float[] pts, int offset, int count,
            @NonNull Paint paint)
public void drawPoints(@Size(multiple = 2) @NonNull float[] pts, @NonNull Paint paint)

画posText
已废弃
public void drawPosText(@NonNull char[] text, int index, int count,
            @NonNull @Size(multiple = 2) float[] pos,
            @NonNull Paint paint)
已废弃
public void drawPosText(@NonNull String text, @NonNull @Size(multiple = 2) float[] pos,
            @NonNull Paint paint)

画矩形
public void drawRect(@NonNull RectF rect, @NonNull Paint paint)
public void drawRect(@NonNull Rect r, @NonNull Paint paint)
public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint)

画圆角矩形
public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
            @NonNull Paint paint)
public void drawDoubleRoundRect(@NonNull RectF outer, float outerRx, float outerRy,
            @NonNull RectF inner, float innerRx, float innerRy, @NonNull Paint paint)
public void drawDoubleRoundRect(@NonNull RectF outer, @NonNull float[] outerRadii,
            @NonNull RectF inner, @NonNull float[] innerRadii, @NonNull Paint paint)

画文本
public void drawText(@NonNull char[] text, int index, int count, float x, float y,
            @NonNull Paint paint)
public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint)
public void drawText(@NonNull String text, int start, int end, float x, float y,
            @NonNull Paint paint)
public void drawText(@NonNull CharSequence text, int start, int end, float x, float y,
            @NonNull Paint paint)
public void drawTextOnPath(@NonNull char[] text, int index, int count, @NonNull Path path,
            float hOffset, float vOffset, @NonNull Paint paint)
public void drawTextOnPath(@NonNull String text, @NonNull Path path, float hOffset,
            float vOffset, @NonNull Paint paint)
public void drawTextRun(@NonNull char[] text, int index, int count, int contextIndex,
            int contextCount, float x, float y, boolean isRtl, @NonNull Paint paint)
public void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
            int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint)
public void drawTextRun(@NonNull MeasuredText text, int start, int end, int contextStart,
            int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint)

画xxx
public void drawVertices(@NonNull VertexMode mode, int vertexCount, @NonNull float[] verts,
            int vertOffset, @Nullable float[] texs, int texOffset, @Nullable int[] colors,
            int colorOffset, @Nullable short[] indices, int indexOffset, int indexCount,
            @NonNull Paint paint)

画xxx
public void drawRenderNode(@NonNull RenderNode renderNode)

范围裁切

通过裁切把绘制限制在某个范围内,然后当你绘制的时候,超出范围的会被切掉.这些方法全部以clip打头.

裁切矩形
已废弃
public boolean clipRect(@NonNull RectF rect, @NonNull Region.Op op)
已废弃
public boolean clipRect(@NonNull Rect rect, @NonNull Region.Op op)
不推荐使用,或者不让使用
public boolean clipRectUnion(@NonNull Rect rect)
public boolean clipRect(@NonNull RectF rect)
public boolean clipOutRect(@NonNull RectF rect)
public boolean clipRect(@NonNull Rect rect)
public boolean clipOutRect(@NonNull Rect rect)
已废弃
public boolean clipRect(float left, float top, float right, float bottom,
            @NonNull Region.Op op)
public boolean clipRect(float left, float top, float right, float bottom)
public boolean clipOutRect(float left, float top, float right, float bottom)
public boolean clipRect(int left, int top, int right, int bottom)
public boolean clipOutRect(int left, int top, int right, int bottom)
裁切路径Path
已废弃
public boolean clipPath(@NonNull Path path, @NonNull Region.Op op)
public boolean clipPath(@NonNull Path path)
public boolean clipOutPath(@NonNull Path path)
裁切Region
public boolean clipRegion(@NonNull Region region, @NonNull Region.Op op)
public boolean clipRegion(@NonNull Region region)


几何变换

绘制内容的几何变换就是对内容进行放大缩小,平移旋转,错切(水平错切,垂直错切)等.我们可以想想把绘制内容的四个边相互拉扯,这些拉扯所对应的形变都是几何变换.3D绘制的模拟就是根据这个来做的.比如说一个页面向上翻起来的效果,就是对应的底部两个顶点的横向拉伸以及高度的压缩

绘制顺序

安卓里的绘制是按顺序的,先绘制的内容会被后绘制的内容盖住,绘制的方法不只有一个,而是好几个,onDraw方法只是用来负责主体内容绘制的,另外还有一些方法,有负责绘制背景的,有负责前景的,有负责整体内容绘制的.他们在绘制过程中都处于一个不同的位置,也就是不同的绘制步骤,如果你对遮盖关系有特殊要求,那么你就需要对绘制的步骤有一定的了解.然后在实际使用中你就知道自己应该选择哪一个绘制方法来重写.从而达到你想要的绘制效果.

自定义绘制总结

方式:重写绘制方法(最常用:onDraw())
关键:Canvas
	canvas的绘制方法:最主要的是使用drawXXX()打头的一系列方法(关键参数paint-用来说明颜色及各种风格信息)
    canvas的辅助类方法:范围裁切(clipXXX())和几何变换(Matrix)
    

Paint:

的api大致分为以下四类

  • 颜色
  • 效果
  • drawText()相关
  • 初始化

颜色

直接设置颜色-setColor

public void setColor(@ColorInt int color)
public void setColor(@ColorLong long color)
public void setARGB(int a, int r, int g, int b)
public void setAlpha(int a)

设置着色器setShader

当设置着色器(Shader)之后,Paint在绘制图形和文字时就不使用setColor/setARGB()设置的颜色了,而是使用Shader方案中的颜色.

我们要使用Shader的几个子类

1.LinearGradient线性渐变

//设置两个点和两种颜色,以这两个点为端点,使用两种颜色的渐变来绘制颜色
Shader shadere = new LinearGradient(100,100,500,500,Color.parseColor("#E91E63"),Color.parseColor("#E91E63"),Shader.TileMode.CLAMP);
paint.setShader(shader);
canvas.draw.Circle(300,300,200,paint)
设置了 Shader 之后,绘制出了渐变颜色的圆。(其他形状以及文字都可以这样设置颜色

tile:端点范围之外的着色规则,类型是 TileMode。TileMode 一共有 3 个值可选: CLAMP, MIRROR 和 REPEAT。CLAMP 会在端点之外延续端点处的颜色;MIRROR 是镜像模式;REPEAT 是重复模式.eg:

CLAMP:

MIRROR:

REPEAT

2.辐射渐变

RadialGradient 辐射渐变

辐射渐变很好理解,就是从中心向周围辐射状的渐变。

Shader shader = new RadialGradient(300, 300, 200, Color.parseColor("#E91E63"),
        Color.parseColor("#2196F3"), Shader.TileMode.CLAMP);
paint.setShader(shader);
canvas.drawCircle(300, 300, 200, paint);

3.扫描渐变

SweepGradient 扫描渐变

从开始到结束,体现在一个原型里面用直线从半径扫过去的一个渐变


//参数,扫描中心,扫描起始颜色
Shader shader = new SweepGradient(300, 300, Color.parseColor("#E91E63"),Color.parseColor("#2196F3"));
paint.setShader(shader);
canvas.drawCircle(300, 300, 200, paint);

4.BitmapShader bitmap着色器

用 Bitmap 来着色。其实也就是用 Bitmap 的像素来作为图形或文字的填充。

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
canvas.drawCircle(300, 300, 200, paint);

5.ComposeShader 混合着色器

所谓混合,就是把两个 Shader 一起使用

// 第一个 Shader:头像的 Bitmap
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
Shader shader1 = new BitmapShader(bitmap1, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

// 第二个 Shader:从上到下的线性渐变(由透明到黑色)
Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.batman_logo);
Shader shader2 = new BitmapShader(bitmap2, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

// ComposeShader:结合两个 Shader
Shader shader = new ComposeShader(shader1, shader2, PorterDuff.Mode.SRC_OVER);
paint.setShader(shader);
canvas.drawCircle(300, 300, 300, paint);

注意:PorterDuff.Mode参数是两个 Shader 的叠加模式,即 shaderA 和 shaderB 应该怎样共同绘制。它的类型是 PorterDuff.Mode

PorterDuff Mode共两类17个模式

1.Alpha合成

2.混合

paint的效果

1.设置是否开启抗锯齿

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

2.设置图形是线条风格还是填充风格

paint.setStyle(Paint.Style.FILL); // FILL 模式,填充
canvas.drawCircle(300, 300, 200, paint);
paint.setStyle(Paint.Style.STROKE); // STROKE 模式,画线
canvas.drawCircle(300, 300, 200, paint);
paint.setStyle(Paint.Style.FILL_AND_STROKE); // FILL_AND_STROKE 模式,填充 + 画线
canvas.drawCircle(300, 300, 200, paint);

3.设置线条宽度

paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1);
canvas.drawCircle(150, 125, 100, paint);

4.设置线头形状

setStrokeCap(Paint.Cap cap)
设置线头的形状。线头形状有三种:BUTT 平头、ROUND 圆头、SQUARE 方头。默认为 BUTT。

5.设置拐角的形状

setStrokeJoin(Paint.Join join)
//设置拐角的形状。有三个值可以选择:MITER 尖角、 BEVEL 平角和 ROUND 圆角。默认为 MITER。

6.设置是否开启双线性过滤

paint.setFilterBitmap(true);//加上这一行,在放大绘制 Bitmap 的时候就会使用双线性过滤了。
图像在放大绘制的时候,默认使用的是最近邻插值过滤,这种算法简单,但会出现马赛克现象;而如果开启了双线性过滤,就可以让结果图像显得更加平滑。

6.设置图形轮廓的效果

PathEffect pathEffect = new DashPathEffect(new float[]{10, 5}, 10);
paint.setPathEffect(pathEffect);
canvas.drawCircle(300, 300, 200, paint);
使用 PathEffect 来给图形的轮廓设置效果。对 Canvas 所有的图形绘制有效,也就是 drawLine() drawCircle() drawPath() 这些方法。

  1. 6 种 PathEffect PathEffect 分为两类,单一效果的 CornerPathEffect DiscretePathEffect DashPathEffect PathDashPathEffect ,和组合效果的 SumPathEffect ComposePathEffect。
  • 把所有拐角变成圆角(CornerPathEffect)
PathEffect pathEffect = new CornerPathEffect(20);//20是圆角的半径
paint.setPathEffect(pathEffect);
canvas.drawPath(path, paint);

  • 把线条进行随机的偏离,让轮廓变得乱七八糟。(DiscretePathEffect)
PathEffect pathEffect = new DiscretePathEffect(20, 5);//乱七八糟的方式和程度由参数决定
paint.setPathEffect(pathEffect);
canvas.drawPath(path, paint);

DiscretePathEffect 具体的做法是,把绘制改为使用定长的线段来拼接,并且在拼接的时候对路径进行随机偏离。它的构造方法
DiscretePathEffect(float segmentLength, float deviation) 的两个参数中, segmentLength 是用来拼接的每个线段的长度, deviation 是偏离量。这两个值设置得不一样,显示效果也会不一样,具体的你自己多试几次就明白了,这里不再贴更多的图。

  • 使用虚线来绘制线条
PathEffect pathEffect = new DashPathEffect(new float[]{20, 10, 5, 10}, 0);
paint.setPathEffect(pathEffect);
canvas.drawPath(path, paint);

它的构造方法 DashPathEffect(float[] intervals, float phase) 中, 第一个参数 intervals 是一个数组,它指定了虚线的格式:数组中元素必须为偶数(最少是 2 个),按照「画线长度、空白长度、画线长度、空白长度」……的顺序排列,例如上面代码中的 20, 5, 10, 5 就表示虚线是按照「画 20 像素、空 5 像素、画 10 像素、空 5 像素」的模式来绘制;第二个参数 phase 是虚线的偏移量

  • 使用一个 Path 来绘制「虚线」
Path dashPath = ...; // 使用一个三角形来做 dash
PathEffect pathEffect = new PathDashPathEffect(dashPath, 40, 0,
        PathDashPathEffectStyle.TRANSLATE);
paint.setPathEffect(pathEffect);
canvas.drawPath(path, paint);

PathDashPathEffect(Path shape, float advance, float phase, PathDashPathEffect.Style style) 中, shape 参数是用来绘制的 Path ; advance 是两个相邻的 shape 段之间的间隔,不过注意,这个间隔是两个 shape 段的起点的间隔,而不是前一个的终点和后一个的起点的距离; phase 和 DashPathEffect 中一样,是虚线的偏移;最后一个参数 style,是用来指定拐弯改变的时候 shape 的转换方式。style 的类型为 PathDashPathEffect.Style ,是一个 enum ,具体有三个值:

TRANSLATE:位移
ROTATE:旋转
MORPH:变体

  • SumPathEffect
PathEffect dashEffect = new DashPathEffect(new float[]{20, 10}, 0);
PathEffect discreteEffect = new DiscretePathEffect(20, 5); 
pathEffect = new SumPathEffect(dashEffect, discreteEffect);
canvas.drawPath(path, paint);

这是一个组合效果类的 PathEffect 。它的行为特别简单,就是分别按照两种 PathEffect 分别对目标进行绘制。

  • ComposePathEffect
PathEffect dashEffect = new DashPathEffect(new float[]{20, 10}, 0);
PathEffect discreteEffect = new DiscretePathEffect(20, 5); 
pathEffect = new ComposePathEffect(dashEffect, discreteEffect);
canvas.drawPath(path, paint);

这也是一个组合效果类的 PathEffect 。不过它是先对目标 Path 使用一个 PathEffect,然后再对这个改变后的 Path 使用另一个 PathEffect。


ComposePathEffect(PathEffect outerpe, PathEffect innerpe) 中的两个 PathEffect 参数, innerpe 是先应用的, outerpe 是后应用的。所以上面的代码就是「先偏离,再变虚线」。而如果把两个参数调换,就成了「先变虚线,再偏离」。至于具体的视觉效果……我就不贴图了,你自己试试看吧!

在它之后绘制的内容下面加一层阴影

paint.setShadowLayer(10, 0, 0, Color.RED);
canvas.drawText(text, 80, 300, paint);

为之后的绘制设置 MaskFilter

上一个方法 setShadowLayer() 是设置的在绘制层下方的附加效果;而这个 MaskFilter 和它相反,设置的是在绘制层上方的附加效果。 MaskFilter 有两种: BlurMaskFilter 和 EmbossMaskFilter。 1.BlurMaskFilter模糊效果的MarkFilter

paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));
canvas.drawBitmap(bitmap, 100, 100, paint);

它的构造方法
BlurMaskFilter(float radius, BlurMaskFilter.Blur style) 中, radius 参数是模糊的范围, style 是模糊的类型。一共有四种:

NORMAL: 内外都模糊绘制
SOLID: 内部正常绘制,外部模糊
INNER: 内部模糊,外部不绘制
OUTER: 内部不绘制,外部模糊(什么鬼?)

2.EmbossMaskFilter浮雕效果的MaskFilter

paint.setMaskFilter(new EmbossMaskFilter(new float[]{0, 1, 1}, 0.2f, 8, 10));
canvas.drawBitmap(bitmap, 100, 100, paint);

它的构造方法
EmbossMaskFilter(float[] direction, float ambient, float specular, float blurRadius) 的参数里, direction 是一个 3 个元素的数组,指定了光源的方向; ambient 是环境光的强度,数值范围是 01; specular 是炫光的系数; blurRadius 是应用光线的范围。

设置单一颜色过滤(略)

设置绘制内容和view已有内容的混合计算方式(略)

事件分发流程-onTouchevent及onClick的先后调用流程

www.cnblogs.com/net168/p/41… www.jianshu.com/p/a4f82b7a4…

handlerlooper机制及线程间通讯基本原理

blog.csdn.net/luoyingxing…

属性动画原理及使用

mvp开发模式,mvvm等

安卓anr的原因及解决方式

安卓的内存泄漏基本原因及解决方法

四种引用类型介绍

内存泄漏原因

内存泄漏解决方式

kotlin的使用

开发文档创建,流程图创建,类图创建

视频播放器集成(niceVideoPlayer,igkPlayer)及腾讯直播SDK集成

IM即时通信基本原理流处理相关操作.底层通讯协议等.

自己封装的音频播放器.

TypeRender的东西的封装

数据加密(DES,AES,RSA)等

自己的接口加密问题使用

(key-value)转json->随机生成16位的AES密钥key->用json和key进行AES加密生成data->将AES密钥key用RSA加密->将data和加密后的key发送到服务器.

对称加密

DES AES

DES因为密钥太短容易被破解被抛弃了,所以现在主流对称加密是AES.
AES对称加密过程是:  明文->加密算法+密钥->密文->解密算法+密钥->明文

非对称加密

RSA

RSA非对称加密过程是:明文->加密算法+加密密钥(私钥)->密文->加密算法+解密密钥(私钥)->明文

什么是base64

base64作用就是把你的二进制(非文本)数据转化成文本数据,字符串;
base64是用64(a-z,A-Z,+,/)个字符的字符串的形式表示二进制数据,这样做的话会使数据变大,因为是用(原数据)中的六个位(原大小8位)对应一个base64中的字符,
作用一:把二进制数据转换文本数据
作用二:把人眼很容易识别到的字符串转换成人们很难看懂的字符.

变种 base58

用在比特币或者其他币的地址上面..他为了避免人们混淆部分字符串(比如0和O)或者是+/ 等都去掉了.所以剩余了58

变种 URL Encoding

将URL中的字符使用%进行编码
目的是消除歧义,避免解析错误.

压缩和解压缩

压缩: 把数据换一种方式来存储,以减少存储空间.

解压缩:把压缩后的数据还原成原先的形式,以便使用. 常见压缩算法:

  1. DEFLATE
  2. JPEG
  3. MP3 图片的编解码 图片的编码:是把内存中的图像数据写成jpe,png等文件的编码格式,只不过有的进行原数据直接转换,有的进行压缩编码

图片的解码:把JPG,PNG等文件中的数据解析成标准图像数据

序列化

序列化就是把内存中的对象转换成具体的格式,方便存储和传输.序列化可以选择序列化成json,xml,protoBuffer等格式. 序列化严格来说不是编码,因为编码本质是吧A格式变成B格式.而序列化做的事情是吧内存中的数据由内存中转换成到硬盘中,其数据本身的明文没有变化.

hash

1.定义

把任意数据转换成指定大小范围(通常很小)的数据.比如说班上200个学员我们把每一个学员都进行编号,(001,002,003....等)那么这个编号就是每一个学员的hash

2.作用

摘要,数据指纹,hash不可逆,不可以根据hash得到原文.

3.经典算法

MD5,SHA1,SHA256.等.

4.本质

把一个很大范围的东西,转换成一个很小的东西,作为这个大东西的唯一标识.转换的算法碰撞率越小越好,也就是说两个不同的东西经过转换需要保证得到的唯一标识不相同.
比如说我们要保证两个视频文件经过算法后得到的hash结果是不同的.

实际用途:

1.数据完整性验证

验证下载后的数据是否与原数据一致

2.快速查找

hashMap  key是hash值,value是真正的大块数据.

3.隐私保护

把用户密码数据hash之后存到库里面,这样做的好处是,当别人攻破网站把密码数据下载后无法得知具体的用户密码从而保护用户隐私安全.

4.彩虹表

彩虹表是一个MD5与原文的对应表,可以让人根据MD5查询出原文来

5.对策

为了让数据更加安全,通常网站会采用加盐处理

加盐就是在对原文进行hash,通常是md5前加一个前缀或者后缀,或者指定操作,然后再进行hash.存储.

字符集

1.含义:

一个由整数向现实世界中的文字符号的map

2.分支:

  • ASCII:128个字符,1字节
  • ISO-8859-1:对ASCII进行扩充,1字节(字符更多)
  • Unicode:13万个字符,多字节.他们的字符集一致,但是编码可能不一致.
    • UTF-8:Unicode的编码分支
    • UTF-16:Unicode的编码分支
  • GBK/GB2312/GB18030:中国自研标准,多字节,字符集+编码

登录和授权

概念:

  • 登录,是一个身份认证的过程,就是拿着用户名和密码去登录到服务器的过程,解决的是你是你的问题
  • 授权,授权就是你登录后获得了某些权限,就像是免死金牌有免死的权限一样.皇帝把令牌给了你你就获得了此权限.

使用方式:

  • cookie

cookie工作机制

苹果1->发送到服务器,服务器返回200 ok->客户端自动存储苹果1个到cookie
下一次请求
客户端增加香蕉1同时把第一次的苹果也放到head请求头里->发送到服务器,服务器返回200 ok ->客户端在把香蕉也存进cookie
此时 cookie中有两个元素,香蕉和苹果

cookie的作用

-会话管理:登录状态,购物车等,
客户端 用户名密码->服务器 返回->sessionId给客户端
下次请求
用户把sessionId发送给服务器,用户就知道你已经登录了.
-个性化:用户偏好,主题
同上面会话管理类似
-tracking:分析用户行为,用户追踪.
关键代码:有一个统一第三方网站
<img src="http://3rd-part.com/image.jpg?from=shop.com"/>
当我们加载这个图片时我们就会知道
  • xss(cross-site scriptiong)HttpOnly

    防止别人偷取我的cookie发到别处,

    使用:Set-Cookie:sessionid=123:HttpOnly 这样做本地脚本看不到,只能用户http信息交换

  • XSRF(Cross-site request forgert):

    使用Referer:www.google.com 标识从哪个网站跳转过来的.

  • Authorization

Basic

header头上加:

Authorization:Basic<username:Password(Base64ed)>

bearer

header头上加
Authorization:Bearer<bearer token>

OAuth2

我是GitHub用户,我要把我的信息授权到别的网站(掘金).
掘金点GitHub登录->github显示掘金相关登录界面->用户点确定->github授权返回给掘金认证code,
后面
掘金服务器拿着认证的code和自己的客户端密钥请求GitHub服务器->github返回AccessToken给掘金服务器:OAuth2结束.

接下来掘金就可以拿着token去github服务器请求相关用户信息了.

微信登录

refresh_token

{
	"token_type":"Bearer",
    "access_token":"xxxx",
    "refresh_token":"xxxx",
    "expires_time":"xxxx"
}
token有一个失效时间,服务器可以拿着refresh_token去请求新的access_token
目的,避免用户重复认证.

TCP/IP协议族

七层模型:应表会传网数物
五层模型:应传网数物
	
    应用层:
DNS: 域名解析服务 
HTTP: 下载内容 
FTP:文件传输协议,用来在客户机和FTP服务器之间传输文件。
DHCP:动态主机配置协议,DHCP服务器为客户机动态分配IP地址。
POP3:邮件接收协议,用于从POP3服务器接收邮件。
SMTP:邮件发送协议,用户通过SMTP服务器发送邮件。 
	传输层
TCP(Transmission Control Protocol,传输控制协议)
UDP(User Datagram Protocol,用户数据报协议)
	网络层
IP(Internet Protocol)网络层提供三个最基本的功能:地址、路由、分段和重组。同时还需要一些附加的功能,比如错误处理和诊断。

	数据链路层
以太网,wifi等
  • Tcp连接与关闭 三次握手,过程
  • 长连接 为什么要长连接,怎么保持?(心跳)

Https

  • HTTP over SSL 建立在SSL上面的HTTP叫Https
  • SSL:(Secure Socket Layer)安全层
  • TLS TransportLayer Secure
  • 定义:在Http之下增加了一个安全层,用于保障Http的加密传输
  • 本质在客户端和服务器之间协商出一套对称密钥,每次发送信息之前将内容加密,收到之后进行解密,达到内容加密传输 过程:
1. 客户端发送Client Hello(告诉服务器,我要建立链接)并附加上自己支持的(tls版本,Cipher Suite非对称加密和hash算法)到服务器->
2. 服务器返回(hello)-服务器(返回证书给客户端)->客户端(验证证书)->

高德地图百度地图的使用.

java基本设计模式及设计原则.

数据库相关知识.GreenDao等基本操作及原理,基本sql语句

protocol buffer

模版方法模式和钩子函数等方法提取公共基类简化开发流程

JNI相关知识

OKHttp相关知识

三级缓存 lruCache等