android ui 流程,android systemui流程

android systemui虽然在framwork里面但确是一个很完整的app,相比keyguardview等代码结构也很清晰

现在是想跟一下这个东西,看看framwork是如何在没有activity的情况下绘制大量的ui的。

先看下他的配置文件:

里面既有: 

也有   

但进去代码里面发现,他们并不是真正启动systemui的地方。

其实他是由系统服务来启动的,

SystemServer.java

ActivityManagerService.self().systemReady(new Runnable() {

public void run() {

Slog.i(TAG, "Making services ready");

startSystemUi(contextF);                try {

if (batteryF != null) batteryF.systemReady();

} catch (Throwable e) {

reportWtf("making Battery Service ready", e);

}

static final void startSystemUi(Context context) {

Intent intent = new Intent();

intent.setComponent(new ComponentName("com.android.systemui",

"com.android.systemui.SystemUIService"));

Slog.d(TAG, "Starting service: " + intent);

context.startService(intent);

} 进来后,发现会加载两个对象

并启动:

for (int i=0; i

Class cl = chooseClass(SERVICES[i]);

mServices[i].mContext = this;

Slog.d(TAG, "running: " + mServices[i]);

mServices[i].start();

}

这两个对象分别是:com.android.systemui.statusbar.tablet.TabletStatusBar

和com.android.systemui.power.PowerUI

接下来进入TabletStatusBar.start()

@Override

public void start() {

super.start(); // will add the main bar view

mIconPolicy = new TabletStatusBarPolicy(mContext);

}

接着看看它的父类是如何定义start()方法的:

public void start() {

// First set up our views and stuff.

View sb = makeStatusBarView();

// Connect in to the status bar manager service

StatusBarIconList iconList = new StatusBarIconList();

ArrayList notificationKeys = new ArrayList();

ArrayList notifications = new ArrayList();

mCommandQueue = new CommandQueue(this, iconList);

mBarService = IStatusBarService.Stub.asInterface(

ServiceManager.getService(Context.STATUS_BAR_SERVICE));

int[] switches = new int[7];

ArrayList binders = new ArrayList();

try {

mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications,

switches, binders);

} catch (RemoteException ex) {

// If the system process isn't there we're doomed anyway.

}

disable(switches[0]);

setSystemUiVisibility(switches[1]);

topAppWindowChanged(switches[2] != 0);

// StatusBarManagerService has a back up of IME token and it's restored here.

setImeWindowStatus(binders.get(0), switches[3], switches[4]);

setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);

// Set up the initial icon state

int N = iconList.size();

int viewIndex = 0;

for (int i=0; i

StatusBarIcon icon = iconList.getIcon(i);

if (icon != null) {

addIcon(iconList.getSlot(i), i, viewIndex, icon);

viewIndex++;

}

}

// Set up the initial notification state

N = notificationKeys.size();

if (N == notifications.size()) {

for (int i=0; i

addNotification(notificationKeys.get(i), notifications.get(i));

}

} else {

Log.wtf(TAG, "Notification list length mismatch: keys=" + N

+ " notifications=" + notifications.size());

}

// Put up the view

final int height = getStatusBarHeight();

final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

height,

WindowManager.LayoutParams.TYPE_STATUS_BAR,

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING

| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,

// We use a pixel format of RGB565 for the status bar to save memory bandwidth and

// to ensure that the layer can be handled by HWComposer.  On some devices the

// HWComposer is unable to handle SW-rendered RGBX_8888 layers.

PixelFormat.RGB_565);

// the status bar should be in an overlay if possible

final Display defaultDisplay

= ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))

.getDefaultDisplay();

// We explicitly leave FLAG_HARDWARE_ACCELERATED out of the flags.  The status bar occupies

// very little screen real-estate and is updated fairly frequently.  By using CPU rendering

// for the status bar, we prevent the GPU from having to wake up just to do these small

// updates, which should help keep power consumption down.

lp.gravity = getStatusBarGravity();

lp.setTitle("StatusBar");

lp.packageName = mContext.getPackageName();

lp.windowAnimations = R.style.Animation_StatusBar;

WindowManagerImpl.getDefault().addView(sb, lp);

if (SPEW) {

Slog.d(TAG, "Added status bar view: gravity=0x" + Integer.toHexString(lp.gravity)

+ " icons=" + iconList.size()

+ " disabled=0x" + Integer.toHexString(switches[0])

+ " lights=" + switches[1]

+ " menu=" + switches[2]

+ " imeButton=" + switches[3]

);

}

mDoNotDisturb = new DoNotDisturb(mContext);

}

显示view就在这里

再进入: makeStatusBarView()

简化以下 步骤,这样看的更清晰:

final TabletStatusBarView sb;

sb = (TabletStatusBarView)View.inflate(context, R.layout.zzz_status_bar_gemini_cu, null);

mShadow = sb.findViewById(R.id.bar_shadow);

mShadow.setOnTouchListener(

new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent ev) {

if (ev.getAction() == MotionEvent.ACTION_DOWN) {

// even though setting the systemUI visibility below will turn these views

// on, we need them to come up faster so that they can catch this motion

// event

mShadow.setVisibility(View.GONE);

mBarContents.setVisibility(View.VISIBLE);

try {

mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);

} catch (RemoteException ex) {

// system process dead

}

}

return false;

}

});

return sp

生成view和activity里面添加view是一样的。

再看下这些view是如何加进来的

final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

height,

WindowManager.LayoutParams.TYPE_STATUS_BAR,

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING

| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,

// We use a pixel format of RGB565 for the status bar to save memory bandwidth and

// to ensure that the layer can be handled by HWComposer.  On some devices the

// HWComposer is unable to handle SW-rendered RGBX_8888 layers.

PixelFormat.RGB_565);

// the status bar should be in an overlay if possible

final Display defaultDisplay

= ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))

.getDefaultDisplay();

// We explicitly leave FLAG_HARDWARE_ACCELERATED out of the flags.  The status bar occupies

// very little screen real-estate and is updated fairly frequently.  By using CPU rendering

// for the status bar, we prevent the GPU from having to wake up just to do these small

// updates, which should help keep power consumption down.

lp.gravity = getStatusBarGravity();

lp.setTitle("StatusBar");

lp.packageName = mContext.getPackageName();

lp.windowAnimations = R.style.Animation_StatusBar;

WindowManagerImpl.getDefault().addView(sb, lp);

看下 windowmanagerimpl 这个类的介绍:

It implements

* the ViewManager interface, allowing you to add any View subclass as a

* top-level window on the screen. Additional window manager specific layout

* parameters are defined for control over how windows are displayed.

* It also implemens the WindowManager interface, allowing you to control the

* displays attached to the device.

和activity.getwindowsmanage()实现了同样的接口,只不过这个类不对外开房。

到这里应该结束了。似乎可以看看windowsmanager的流程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值