由于工作需要,希望修改android5.1的SystemUI,默认Android5.1的SystemUI状态栏,下滑的时候,只会出现的屏幕中间的。不管你下拉从屏幕顶端哪里下滑状态栏。我们需要状态栏出现的位置由下滑的位置决定,因为我们的机器是15.6寸的,所以必须这样修改。
android5.1SystemUI的statusBar 实际上主要布局文件是super_status_bar.xml ,这个布局文件包括status_bar_expanded.xml
<com.android.systemui.statusbar.phone.PanelHolder
android:id="@+id/panel_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent" >
"@layout/status_bar_expanded"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
com.android.systemui.statusbar.phone.PanelHolder>
status_bar_expanded.xml包括下拉后显示的头和通知和快速设置
<com.android.systemui.statusbar.phone.NotificationPanelView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:id="@+id/notification_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
>
"@layout/carrier_label"
android:layout_height="@dimen/carrier_label_height"
android:layout_width="match_parent"
android:layout_marginBottom="@dimen/close_handle_height"
android:layout_gravity="bottom"
/>
"@layout/keyguard_status_view"
android:layout_height="wrap_content"
android:visibility="gone" />
"@+id/emergency_calls_only"
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Network.EmergencyOnly"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="4dp"
android:gravity="center"
android:visibility="gone"
/>
<com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:id="@+id/notification_container_parent"
android:clipToPadding="false"
android:clipChildren="false">
<com.android.systemui.statusbar.phone.ObservableScrollView
android:id="@+id/scroll_view"
android:layout_width="@dimen/notification_panel_width"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:scrollbars="none"
android:overScrollMode="never"
android:fillViewport="true">
"match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
"@layout/qs_panel"
android:layout_marginTop="@dimen/status_bar_header_height_expanded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/notification_side_padding"
android:layout_marginRight="@dimen/notification_side_padding"/>
"@+id/reserve_notification_space"
android:layout_height="@dimen/min_stack_height"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/notifications_top_padding" />
"@dimen/notification_side_padding"
android:layout_width="match_parent" />
com.android.systemui.statusbar.phone.ObservableScrollView>
<com.android.systemui.statusbar.stack.NotificationStackScrollLayout
android:id="@+id/notification_stack_scroller"
android:layout_width="@dimen/notification_panel_width"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:layout_marginBottom="@dimen/close_handle_underlap"
android:importantForAccessibility="no" />
"@+id/keyguard_user_switcher"
android:layout="@layout/keyguard_user_switcher"
android:layout_height="match_parent"
android:layout_width="match_parent" />
"@layout/keyguard_status_bar"
android:visibility="invisible" />
com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer>
"@layout/keyguard_bottom_area"
android:visibility="gone" />
"@layout/status_bar_expanded_header" />
<com.android.systemui.statusbar.AlphaOptimizedView
android:id="@+id/qs_navbar_scrim"
android:layout_height="96dp"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:visibility="invisible"
android:background="@drawable/qs_navbar_scrim" />
com.android.systemui.statusbar.phone.NotificationPanelView><
NotificationStackScrollLayout 是通知,如果用系统通知会显示在这里
<com.android.systemui.statusbar.phone.StatusBarHeaderView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:id="@+id/header"
android:layout_width="@dimen/notification_panel_width"
android:layout_height="@dimen/status_bar_header_height"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:paddingStart="@dimen/notification_side_padding"
android:paddingEnd="@dimen/notification_side_padding"
android:baselineAligned="false"
android:elevation="4dp"
android:background="@drawable/notification_header_bg"
android:clickable="true"
android:focusable="true"
>
<com.android.systemui.statusbar.phone.MultiUserSwitch android:id="@+id/multi_user_switch"
android:layout_width="@dimen/multi_user_switch_width_collapsed"
android:layout_height="@dimen/status_bar_header_height"
android:layout_alignParentEnd="true"
android:background="@drawable/ripple_drawable" >
"@+id/multi_user_avatar"
android:layout_width="@dimen/multi_user_avatar_expanded_size"
android:layout_height="@dimen/multi_user_avatar_expanded_size"
android:layout_gravity="center"
android:scaleType="centerInside"/>
com.android.systemui.statusbar.phone.MultiUserSwitch>
<com.android.keyguard.AlphaOptimizedImageButton android:id="@+id/settings_button"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_toStartOf="@id/multi_user_switch"
android:layout_width="48dp"
android:layout_height="@dimen/status_bar_header_height"
android:background="@drawable/ripple_drawable"
android:src="@drawable/ic_settings"
android:contentDescription="@string/accessibility_desc_settings" />
"@+id/system_icons_super_container"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_bar_header_height"
android:layout_toStartOf="@id/multi_user_switch"
android:layout_alignWithParentIfMissing="true"
android:layout_marginStart="16dp"
android:background="@drawable/ripple_drawable"
android:paddingEnd="4dp" >
"@+id/system_icons_container"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_bar_height"
android:layout_gravity="center_vertical"
>
"@layout/system_icons" />
"@+id/battery_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/header_battery_margin_expanded"
android:paddingEnd="@dimen/battery_level_padding_end"
android:textColor="#ffffff"
android:textSize="@dimen/battery_level_text_size"
android:importantForAccessibility="noHideDescendants"/>
"@+id/header_emergency_calls_only"
android:layout_height="@dimen/status_bar_header_height"
android:layout_width="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/system_icons_super_container"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:visibility="gone"
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.EmergencyCallsOnly"
android:text="@*android:string/emergency_calls_only"
android:singleLine="true"
android:gravity="center_vertical" />
"@+id/date_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/clock_collapsed_bottom_margin"
android:layout_alignParentBottom="true">
<com.android.systemui.statusbar.policy.DateView android:id="@+id/date_collapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Date"
android:layout_below="@id/clock"
systemui:datePattern="@string/abbrev_wday_month_day_no_year_alarm"
/>
<com.android.systemui.statusbar.policy.DateView android:id="@+id/date_expanded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Date"
android:layout_below="@id/clock"
systemui:datePattern="eeeeMMMMd"
/>
"@layout/split_clock_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_above="@id/date_group"
android:id="@+id/clock"
/>
com.android.systemui.statusbar.phone.StatusBarHeaderView这个是头用于显示时间和电池图标等。
com.android.systemui.statusbar.stack.NotificationStackScrollLayout是快速设置的那一块。
当下滑发生的时候,我们需要记录下触摸的位置,然后当开始展开状态栏的时候我们要计算状态栏出现的位置。
PhoneStatusBar–>interceptTouchEvent函数用于获取下滑动作出现时的坐标记录如下:
panelTouchPos_x为我们定义的坐标变量
panelTouchPos_x=(int)event.getRawX();
然后在PhoneStatusBar–>updateExpandedViewPos()计算并修改菜单栏出现的位置。必须同时修改头和通知栏以及快速设置才可以。
private int panelTouchPos_x = 0;
@Override
public void updateExpandedViewPos(int thingy) {
if (SPEW) Log.v(TAG, "updateExpandedViewPos");
// on larger devices, the notification panel is propped open a bit
mNotificationPanel.setMinimumHeight(
(int)(mNotificationPanelMinHeightFrac * mCurrentDisplaySize.y));
int statusBarWidth=mStatusBarWindow.getWidth();
int left;
FrameLayout.LayoutParams lp= (FrameLayout.LayoutParams)mHeader.getLayoutParams();
int panelWidth=lp.width;
if ((panelTouchPos_x+(panelWidth/2))>statusBarWidth){
left=statusBarWidth-panelWidth;
}else if(panelTouchPos_x2) {
left=0;
}else{
left=panelTouchPos_x-(panelWidth/2);
}
lp.gravity=Gravity.TOP|Gravity.LEFT;
lp.setMargins(left,lp.topMargin,lp.rightMargin,lp.bottomMargin);
mHeader.setLayoutParams(lp);
ObservableScrollView mScrollView= (ObservableScrollView) this.mStatusBarWindow.findViewById(R.id.scroll_view);
lp=(FrameLayout.LayoutParams)mScrollView.getLayoutParams();
lp.gravity=Gravity.TOP|Gravity.LEFT;
lp.setMargins(left,lp.topMargin,lp.rightMargin,lp.bottomMargin);
mScrollView.setLayoutParams(lp);
lp=(FrameLayout.LayoutParams)mStackScroller.getLayoutParams();
lp.gravity=Gravity.TOP|Gravity.LEFT;
lp.setMargins(left,lp.topMargin,lp.rightMargin,lp.bottomMargin);
mStackScroller.setLayoutParams(lp);
updateCarrierLabelVisibility(false);
}