AndroidInts相关知识总结

更新时间:2023-07-01 20:01:19 阅读: 评论:0

AndroidInts相关知识总结
⽬录
什么是Ints?
Ints相关类
IntsState
IntsStateController
IntsSource
IntsSourceConsumer(ImeIntsSourceConsumer)
ImeIntsSourceConsumer
IntsController
IntsChanged、IntsControlChanged⽅法
onStateChanged
onControlsChanged
总结
最近⼯作中总会涉及到Ints相关的⼀些内容,⽹上对于Ints的分析以及介绍还是较少的,这⾥对Ints涉及到⼀些概念和⽅法做⼀个总结。
什么是Ints?
WindowInts 源码解释为 window content的⼀系列插值集合,(个⼈理解为⼀个Activity相对于⼿机屏幕需要空出的地⽅以腾纳给statusbar、Ime、Navigationbar等系统窗⼝,具体表现为该区域需要的上下左右的宽⾼,⽐如输⼊法窗⼝的区域就是⼀个Int)
WindowInts包括三类:SystemWindowInts、StableInts、WIndowDecorInts
SystemWindowInts:全窗⼝下,被navigationbar、statusbar、ime或其他系统窗⼝覆盖的区域
StableInts:全窗⼝下,被系统UI覆盖的区域
WIndowDecorInts:系统预留属性
Ints相关类
IntsState
保存系统中所有的Ints的状态,他是状态描述者,持有系统中可以产⽣Window Ints的window状态private IntsSource[] mSources = new IntsSource[SIZE]; // mSources变量维护所有产⽣Ints的window(也就是IntsSource)的状态
它主要持有以下⼏种类型的Ints
ITYPE_STATUS_BAR,
ITYPE_NAVIGATION_BAR,
ITYPE_CAPTION_BAR,
ITYPE_TOP_GESTURES,
ITYPE_BOTTOM_GESTURES,
ITYPE_LEFT_GESTURES,
ITYPE_RIGHT_GESTURES,
ITYPE_TOP_TAPPABLE_ELEMENT,
ITYPE_BOTTOM_TAPPABLE_ELEMENT,
ITYPE_LEFT_DISPLAY_CUTOUT,
ITYPE_TOP_DISPLAY_CUTOUT,
ITYPE_RIGHT_DISPLAY_CUTOUT,
ITYPE_BOTTOM_DISPLAY_CUTOUT,
ITYPE_IME,
ITYPE_CLIMATE_BAR,
ITYPE_EXTRA_NAVIGATION_BAR
如果IntsState发⽣改变后,会通过MSG_INSETS_CHANGED消息发送到IntsController,进⾏修改并保存到变量mState中
public boolean onStateChanged(IntsState state) {
boolean stateChanged = !mState.equals(state, true /* excludingCaptionInts */,fal /* excludeInvisibleIme */) || !captionIntsUnchanged();
if (!stateChanged && mLastDispatchedState.equals(state)) {
return fal;
}
海参汤updateState(state);
boolean localStateChanged = !mState.equals(mLastDispatchedState,
true /* excludingCaptionInts */, true /* excludeInvisibleIme */);
mLastDispatchedState.t(state, true /* copySources */);
applyLocalVisibilityOverride();
if (localStateChanged) {
if (DEBUG) Log.d(TAG, "onStateChanged, notifyIntsChanged, nd state to WM: " + mState);
updateRequestedState();
}
return true;
}
IntsState的关键⽅法:
WindowInts calculateInts(...):基于当前source设置计算新的windowInts
void processSource(IntsSource source,...): 根据计算值更新source值
IntsStateController
管理所有窗⼝的Ints的state
private final IntsState mLastState = new IntsState(); //旧的IntsState
private final IntsState mState = new IntsState(); //新的IntsState
⼏个重要的⽅法:
private boolean isAboveIme(WindowContainer target)// 判断当前窗⼝是否处在输⼊法窗⼝层级上
void onImeControlTargetChanged(@Nullable IntsControlTarget imeTarget) //当输⼊法target 窗⼝发⽣变化触发
IntsState getIntsForDispatch(@NonNull WindowState target) //分发Ints 对Ints进⼀步更新(更新frame 或者visible)
IntsSource
是Ints产⽣者的描述,记录每⼀个产⽣Ints的window的状态,主要记录产⽣的Ints区域
private final @InternalIntsType int mType;  //Ints类型 nav或者status或者...
private final Rect mFrame;  //代表Ints区域
private boolean mVisible;  //Ints可见性
/*⼏个重要的⽅法/
public void tFrame(Rect frame)  //设置Ints⼤⼩
public void tVisible(boolean visible) //设置Ints可见性
private Ints calculateInts(Rect relativeFrame, Rect frame, boolean ignoreVisibility)  //根据frame以及ignoreVisibility 计算Ints
IntsSourceConsumer(ImeIntsSourceConsumer)
对单⼀IntsSource的消费者,其内部持有IntsSourceControl,可以控制其leash的可见性和动画,输⼊法有专门的ImeIntsSourceConsumer来消费输⼊法的Ints
protected boolean mRequestedVisible;  //单⼀Ints的可见性
private @Nullable IntsSourceControl mSourceControl; // 持有IntsSourceControl变量可以实现对单⼀IntsSource的控制
protected final IntsController mController; //所属的IntController
protected final IntsState mState;  //本地state
/⼏个重要的⽅法/
public void updateSource(IntsSource newSource, @AnimationType int animationType)  //更新mstate中的source 主要更新frame
public void show(boolean fromIme) //显⽰Ints
protected void tRequestedVisible(boolean requestedVisible) //设置Ints的可见性
public void tControl(@Nullable IntsSourceControl control,
@IntsType int[] showTypes, @IntsType int[] hideTypes) //后⾯讲
public void hide() //隐藏Ints
boolean applyLocalVisibilityOverride() //主要更新state可见性
protected boolean isRequestedVisibleAwaitingControl() //判断当前Ints是否会在获得control时更新可见性,即判断是否存在pending show(如果是bars 该⽅法等同于isRequestedVisible)
ImeIntsSourceConsumer
private boolean mIsRequestedVisibleAwaitingControl;  //判断是否存在⼀个请求要让输⼊法显⽰出来(但是由于当前尚未获得control因此暂时⽆法实现这个操作)
void notifyHidden()  //控制IMM隐藏输⼊法
public @ShowResult int requestShow(boolean fromIme) //控制IMM显⽰输⼊法
public void removeSurface() //移除输⼊法的surface
- IntsSourceControl
对IntsSource的控制者,⽤来控制Ints的产⽣者,内部持有控制输⼊法动画的Leash
private final @InternalIntsType int mType;  //IntsSource类型
private final @Nullable SurfaceControl mLeash;  //播放动画需要的Leash ,app可以控制对其设置position实现位移动画
private final Point mSurfacePosition;  //当前leash(Surface)在屏幕中的position
- IntsSourceProvider
他是特定IntsSource在rver端的控制者,他被称作provider是因为他提供IntsSource给客户端(客户端通过IntsSourceConsumer使⽤IntsSource)
这⾥重点关注ImeIntsSourceProvider
private IntsControlTarget mImeTargetFromIme;  //输⼊法Ints的control(Ints需要有⼀个control,否则他就会失控不可控制)
private Runnable mShowImeRunner;  //显⽰输⼊法线程
private boolean mIsImeLayoutDrawn; //输⼊法是否已经绘制完成
IntsController
它是WindowInts在client端的实现⽤来控制ints ,IntsController只在ViewRootImpl⾥⾯创建的,每个Window会对应⼀个ViewRootImpl,同样每
个ViewRootImpl会对应每个IntsController
/*关键成员变量*/
IntsState mState = new IntsState();  //记录本地State (Client端的Intsstate)
IntsState mLastDispatchedState = new IntsState(); //从system端传来的IntsState
IntsState mRequestedState = new IntsState(); //发送给系统端的IntsState
SparArray<IntsSourceConsumer> mSourceConsumers = new SparArray<>(); //持有sourceConsumers
/*关键⽅法*/
public void applyImeVisibility(boolean tVisible) //更新输⼊法可见性
public void notifyFinished(IntsAnimationControlRunner runner, boolean shown) //动画结束时回调
⽅法
public void onControlsChanged(IntsSourceControl[] activeControls) //当系统端分发新的Ints Controls时被调⽤
public boolean onStateChanged(IntsState state) //Ints或者IntsControl发⽣改变会调⽤
public void tSystemBarsBehavior(@Behavior int behavior)
public void tSystemBarsAppearance(@Appearance int appearance, @Appearance int mask)  //更改Systembar的表现⾏为
public void show(@IntsType int types, boolean fromIme) //显⽰Ints
void hide(@IntsType int types, boolean fromIme)  //隐藏Ints
private void updateState(IntsState newState) //更新state
private void updateRequestedState() //如果Ints在client端发⽣改变再重新发送到rver端
public void applyAnimation(@IntsType final int types, boolean show, boolean fromIme)  //更新Int
s动画
IntsChanged、IntsControlChanged⽅法
Ints的变化⼀般是通过消息机制来进⾏更改的,主要是两⽅⾯的更改包括IntsChanged和IntsControlChanged,他们是由System_rver经过WindowState调⽤到App进程的。
西南司法鉴定中心WindowState.java //属于Server端
void notifyIntsChanged() {
ProtoLog.d(WM_DEBUG_IME, "notifyIntsChanged for %s ", this);
try {
mClient.intsChanged(getIntsState());
傅永发愤读书} catch (RemoteException e) {
Slog.w(TAG, "Failed to deliver int state change w=" + this, e);
}
武则天秘史三级}
ViewRootImpl#W
@Override
public void intsChanged(IntsState intsState) {
final ViewRootImpl viewAncestor = ();
if (viewAncestor != null) {
viewAncestor.dispatchIntsChanged(intsState);
}
}
@Override
public void intsControlChanged(IntsState intsState,
IntsSourceControl[] activeControls) {
final ViewRootImpl viewAncestor = ();
if (viewAncestor != null) {
viewAncestor.dispatchIntsControlChanged(intsState, activeControls);
}
}
异步发送消息:MSG_INSETS_CHANGED、MSG_INSETS_CONTROL_CHANGED
怎么换ip地址ca MSG_INSETS_CHANGED:
break;
ca MSG_INSETS_CONTROL_CHANGED: {
break;  //⾸先都会调⽤IntsController的onStateChanged⽅法
}
onStateChanged
public boolean onStateChanged(IntsState state) {
boolean stateChanged = !mState.equals(state, true /* excludingCaptionInts */,fal /* excludeInvisibleIme */) //判断client端state和传来的state是否⼀致
|| !captionIntsUnchanged();
//同时判断上次rver端传来的state是否同当前传传来的state⼀致
if (!stateChanged && mLastDispatchedState.equals(state)) {
return fal;
}
if (DEBUG) Log.d(TAG, "onStateChanged: " + state);
updateState(state);
//判断client端本地state是否已经发⽣改变
boolean localStateChanged = !mState.equals(mLastDispatchedState,
true /* excludingCaptionInts */, true /* excludeInvisibleIme */);
笔记本电脑密码忘了怎么解除
//更新mLastDispatchedState 即更新rver端传来的state
mLastDispatchedState.t(state, true /* copySources */);
//将更新apply到本地
applyLocalVisibilityOverride();
if (localStateChanged) {
if (DEBUG) Log.d(TAG, "onStateChanged, notifyIntsChanged, nd state to WM: " + mState);
//如果本地Ints发⽣改变了,通知rver端Ints更改了
//更新传递给rver端的IntsState
updateRequestedState();
}
return true;
}
onControlsChanged
该⽅法在窗⼝获取焦点或者失去焦点的时候也会调⽤到
public void onControlsChanged(IntsSourceControl[] activeControls) {
if (activeControls != null) {
for (IntsSourceControl activeControl : activeControls) {
if (activeControl != null) {
// TODO(b/122982984): Figure out why it can be null.
mTmpControlArray.Type(), activeControl);
}
}
}
boolean requestedStateStale = fal;
final int[] showTypes = new int[1]; //系统Ints会根据showTypes数组内的值去更新可见性
final int[] hideTypes = new int[1];
/
/遍历所有的SourceConsumer 更新system_rver传来的IntsSourceControl
for (int i = mSourceConsumers.size() - 1; i >= 0; i--) {
final IntsSourceConsumer consumer = mSourceConsumers.valueAt(i);
final IntsSourceControl control = (Type());
consumer.tControl(control, showTypes, hideTypes);
}
// Ensure to create source consumers if not available yet.
//便利system_rver传递来的IntsSourceControl
for (int i = mTmpControlArray.size() - 1; i >= 0; i--) {
final IntsSourceControl control = mTmpControlArray.valueAt(i);
final @InternalIntsType int type = Type();
final IntsSourceConsumer consumer = getSourceConsumer(type);
//如果consumer不存在会创建
consumer.tControl(control, showTypes, hideTypes); //可以看到如果存在対赢得consumer 会调⽤tControl⽅法两次
...
}
mTmpControlArray.clear();
//showTypes、hideTypes值会在tControl⽅法内进⾏修改
int animatingTypes = invokeControllableIntsChangedListeners();佛系人生
showTypes[0] &= ~animatingTypes;
hideTypes[0] &= ~animatingTypes;
//假设showTypes[0]=8 代表要显⽰输⼊法
if (showTypes[0] != 0) {
applyAnimation(showTypes[0], true /* show */, fal /* fromIme */);
}
//假设hideTypes[0]=8 代表要隐藏输⼊法
if (hideTypes[0] != 0) {
applyAnimation(hideTypes[0], fal /* show */, fal /* fromIme */);
}
if (requestedStateStale) {
updateRequestedState();
}
}
总结
1. 每个ViewRootImpl对应⼀个IntsController实例,他是⼀个App进程中控制Ints的核⼼类,⽤于保存传递系统中产⽣Ints的window的状态和动
画需要的leash以及控制播放动画
2. IntsSource是对产⽣Ints的窗⼝的状态描述,包括可见性以及Ints的⼤⼩
3. 每个IntsController会持有⼀个成员变量mState(IntsState),它保存了系统中所有产⽣Ints的Window(IntsSource)的状态列表,状态主
要是指可见性以及产⽣Ints的window的区域⼤⼩
4. IntsSourceConsumer 是⽤来消费特定IntsSource,消费主要是指对产⽣Ints 的window即IntsSource进⾏可见性控制以及播放动画,通过
持有的window的Leash来实现,也就是mSourceControl(IntsSourceControl)
5. 每个IntsController会持有多个IntsSourceConsumer,他持有⼀个IntsSourceConsumers列表,SparArray mSourceConsumers
到这⾥Ints已经总结完毕,后续将进⼀步通过源码分析Ints的原理以及和App之间的关系,由于⽔平有限,难免有错误,若在阅读时发现不妥或者错误的地⽅留⾔指正,共同进步,谢谢!
Have a nice day!
以上就是Android Ints相关知识总结的详细内容,更多关于Android Ints的资料请关注其它相关⽂章!女人小说

本文发布于:2023-07-01 20:01:19,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1072759.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:是否   控制   系统   持有   动画   可见   相关   状态
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图