1,Status Bar 上的icon 的配置
android 预定义需要在status bar上显示的icon.其在framework/base/core/res/res/values/config.xml
<!-- Component to be used as the status bar service. Must implement the IStatusBar
interface. This name is in the ComponentName flattened format (package/class) -->
<string name="config_statusBarComponent">com.android.systemui/com.android.systemui.statusbar.StatusBarService</string>
<!-- Do not translate. Defines the slots for the right-hand side icons. That is to say, the
icons in the status bar that are not notifications. -->
<string-array name="config_statusBarIcons">
<item><xliff:g id="id">ime</xliff:g></item>
<item><xliff:g id="id">sync_failing</xliff:g></item>
<item><xliff:g id="id">sync_active</xliff:g></item>
<item><xliff:g id="id">gps</xliff:g></item>
<item><xliff:g id="id">bluetooth</xliff:g></item>
<item><xliff:g id="id">nfc</xliff:g></item>
<item><xliff:g id="id">tty</xliff:g></item>
<item><xliff:g id="id">speakerphone</xliff:g></item>
<item><xliff:g id="id">mute</xliff:g></item>
<item><xliff:g id="id">volume</xliff:g></item>
<item><xliff:g id="id">wifi</xliff:g></item>
<item><xliff:g id="id">cdma_eri</xliff:g></item>
<item><xliff:g id="id">data_connection</xliff:g></item>
<item><xliff:g id="id">phone_evdo_signal</xliff:g></item>
<item><xliff:g id="id">phone_signal</xliff:g></item>
<item><xliff:g id="id">battery</xliff:g></item>
<item><xliff:g id="id">alarm_clock</xliff:g></item>
<item><xliff:g id="id">headset</xliff:g></item>
<item><xliff:g id="id">secure</xliff:g></item>
<item><xliff:g id="id">clock</xliff:g></item>
</string-array>
这些icon在这个string array的位置就决定了其在status bar 上显示的位置了。我们可以从code里面得出该结论。所以当你要调换icon的顺序时,改动这个config.xml就可以了。下面我们来看如何得到该结论:
1,在StatusBarManagerService 初始化的时候就会读取config.xml下icons 的String array.
1)StatusBarManagerService.java
StatusBarIconList mIcons = new StatusBarIconList();
public StatusBarManagerService(Context context) {
mContext = context;
final Resources res = context.getResources();
mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
}
2)StatusBarIconList.java
public void defineSlots(String[] slots) {
final int N = slots.length;
String[] s = mSlots = new String[N];
for (int i=0; i<N; i++) {
s[i] = slots[i];
Slog.i("", "StatusBarIconList "+i+" : "+ slots[i]);
}
mIcons = new StatusBarIcon[N];
}
这里的mSlots这个string array就是保存了刚才config.xml中读出来的,并new 对应数目的StatusBarIcon。
3)StatusBarPolicy.java
// battery
mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
....
mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
....
4)StatusBarManager.java
public void setIcon(String slot, int iconId, int iconLevel) {
try {
mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel);
Slog.i("StatusBarManager", "setIcon: slot"+slot+" packageName:"+ mContext.getPackageName());
} catch (RemoteException ex) {
// system process is dead anyway.
throw new RuntimeException(ex);
}
}
5)StatusBarManagerService.java
public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
enforceStatusBar();
synchronized (mIcons) {
int index = mIcons.getSlotIndex(slot);
if (index < 0) {
throw new SecurityException("invalid status bar icon slot: " + slot);
}
StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
mIcons.setIcon(index, icon);
if (mBar != null) {
try {
mBar.setIcon(index, icon);
} catch (RemoteException ex) {
}
}
}
}
// ================================================================================
// Callbacks from the status bar service.
// ================================================================================
public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
List<IBinder> notificationKeys, List<StatusBarNotification> notifications) {
enforceStatusBarService();
Slog.i(TAG, "registerStatusBar bar=" + bar);
mBar = bar;
synchronized (mIcons) {
iconList.copyFrom(mIcons);
}
synchronized (mNotifications) {
Slog.i(TAG, "mNotifications=" + mNotifications.);
for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
notificationKeys.add(e.getKey());
notifications.add(e.getValue());
}
}
}
这里的registerStatusBar会在StatusBarService的onCreate的时候调用:
StatusBarIconList iconList = new StatusBarIconList();
ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
mCommandQueue = new CommandQueue(this, iconList);
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware")); // helen
try {
mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications);
} catch (RemoteException ex) {
// If the system process isn't there we're doomed anyway.
}
6)CommandQueue。java
public void setIcon(int index, StatusBarIcon icon) {
synchronized (mList) {
int what = MSG_ICON | index;
mHandler.removeMessages(what);
mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
}
}
case MSG_ICON: {
final int index = msg.what & INDEX_MASK;
final int viewIndex = mList.getViewIndex(index);
switch (msg.arg1) {
case OP_SET_ICON: {
StatusBarIcon icon = (StatusBarIcon)msg.obj;
StatusBarIcon old = mList.getIcon(index);
if (old == null) {
mList.setIcon(index, icon);
mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
} else {
mList.setIcon(index, icon);
mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
old, icon);
}
break;
}
case OP_REMOVE_ICON:
if (mList.getIcon(index) != null) {
mList.removeIcon(index);
mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
}
break;
}
break;
}
7)StatusBarService.java
public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
if (SPEW_ICONS) {
Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
+ " icon=" + icon);
}
StatusBarIconView view = new StatusBarIconView(this, slot);
view.set(icon);
mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize));
}
分享到:
相关推荐
在Android 2.3(Gingerbread)版本中,StatusBar默认仅包含一些基本功能,如通知和解锁控件。然而,根据您的标题和描述,这个压缩包可能包含了使开发者能够在StatusBar上添加额外功能,比如back、home和menu按钮的...
### Android2.3状态栏透明修改教程 #### 知识点一:状态栏透明修改方法 **背景介绍:** 在Android开发中,有时为了达到更好的视觉效果或满足特定设计需求,开发者需要对系统的状态栏进行定制化修改。本文将详细...
我们来深入解析一下Android 2.3版本中StatusBar的相关知识点。 首先,StatusBar的启动过程分为几个步骤: 1. **系统StatusBarService的启动**: - 在开机流程中,系统会注册StatusBar服务。通过`ServiceManager....
在压缩包中的"stateBar"文件可能表示状态栏(StatusBar)的相关设置。在Android中,状态栏显示着系统图标、时间、通知等信息。如果水波点击效果涉及到状态栏,可能意味着开发者希望点击屏幕时整个屏幕(包括状态栏)...
[Android开发从零开始].19.Status.Bar.Notifications.mp4 67.5MB [Android开发从零开始].20.广播事件处理(1).mp4 50.3MB [Android开发从零开始].21.广播事件处理(2).mp4 42.3MB [Android开发从零开始].22.数据...
- Launcher、Menu、StatusBar、Tab等各类图标的推荐尺寸。 通过以上内容,我们可以看到Android从最初的构想到今天成为全球最广泛使用的移动操作系统之一,经历了不断的创新和发展。它不仅改变了人们的生活方式,也为...
#### 2.29 App->Notification->StatusBar 进一步讨论了如何与系统状态栏交互,包括更改状态栏的颜色等。 #### 2.30 App->Preferences->PreferencesfromXML 这部分内容讲解了如何使用XML文件来配置应用偏好设置。 #...
Android 键盘/Android 系统/API Domes/Certificate Installer(证书安装)/com.android.gestuer.builder()/com.android.sdksetup()/Custom Locale()/Dev Tools(开发工具)/Example Wallpapers(墙纸式样)/HTML查看器/...
2. **Framework层UI修改**:这部分介绍了如何在框架级别进行UI的调整,例如LockScreen、StatusBar等组件的修改。 #### 三、应用程序UI修改详解 **1.1 应用程序UI共性修改** **1.1.1 修改应用程序显示图标** - **...
- statusbar_background.9.png - 状态栏背景 - status_bar_background.png - 下拉栏背景 - status_bar_close_on.9.png - 下拉菜单最下面的样式 - title_bar_portrait.9.png - “正在进行的”背景 2. **2.3 ROM...
- **方法**: 通过`<meta name="apple-mobile-web-app-status-bar-style" content="black">`等属性设置顶栏颜色。 **2.9 电话号码识别** - **方法**: 使用`tel:`协议链接电话号码,使其可点击拨打。 **2.10 邮箱...