SystemUI下拉通知栏的源码分析

SystemUI下拉通知栏的源码分析super_l是systemUI的⼀个总的布局⽂件。
下⾯是super_l的源码:
<com.android.systemui.statusbar.phone.StatusBarWindowView
xmlns:android="schemas.android/apk/res/android"
xmlns:systemui="schemas.android/apk/res/com.android.systemui"
android:focusable="true"
android:descendantFocusability="afterDescendants"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
>
<include layout="@layout/status_bar"
android:layout_width="match_parent"
android:layout_height="@*android:dimen/status_bar_height"
/>
<com.android.systemui.statusbar.phone.PanelHolder
android:id="@+id/panel_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/status_bar_expanded"
android:layout_width="match_parent"
android:layout_height="match_parent"
/
>
<ViewStub android:id="@+id/quick_settings_stub"
android:layout="@layout/quick_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</com.android.systemui.statusbar.phone.PanelHolder>
</com.android.systemui.statusbar.phone.StatusBarWindowView>
从上⾯的源码可以知道,systemUI布局⼤概分为三个部分
第⼀:status_bar,这部分是状态栏。
第⼆:status_bar_expanded,这部分是下拉通知栏。
斩波调速器第三:quick_settings_stub,这部分是下拉快捷设置栏。
其中,本⽂中是重点分析下拉通知栏。
*************************************************分割线**************************************
下⾯是下拉通知栏的布局⽂件status_l:
<com.android.systemui.statusbar.phone.NotificationPanelView
xmlns:android="schemas.android/apk/res/android"
xmlns:systemui="schemas.android/apk/res/com.android.systemui"
android:id="@+id/notification_panel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/notification_panel_bg"
android:paddingTop="@dimen/notification_panel_padding_top"
android:layout_marginStart="@dimen/notification_panel_margin_left"
>
<View
android:id="@+id/handle"
android:layout_width="match_parent"
android:layout_height="@dimen/close_handle_height"
android:background="@drawable/status_bar_close"
android:visibility="invisible"
/>
<include
layout="@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"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/close_handle_underlap"
android:orientation="vertical"
android:animateLayoutChanges="false"
>
<include layout="@layout/status_bar_expanded_header"
android:layout_width="match_parent"
android:layout_height="@dimen/notification_panel_header_height"
/>
<TextView
android:id="@+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"
/>
静电接地控制器<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"频闪灯
>
<ViewStub android:id="@+id/flip_settings_stub"
android:layout="@layout/flip_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/
>
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:overScrollMode="ifContentScrolls"
>
<com.android.systemui.statusbar.policy.NotificationRowLayout
android:id="@+id/latestItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
systemui:rowHeight="@dimen/notification_row_min_height"
/>
</ScrollView>
</FrameLayout>
</LinearLayout>
</com.android.systemui.statusbar.phone.NotificationPanelView>
其中,代码段: <include layout="@layout/status_bar_expanded_header"
android:layout_width="match_parent"
android:layout_height="@dimen/notification_panel_header_height"
/>
该代码段是下拉通知栏的顶部的布局,包括时间,⽇期和⼀个清除通知消息的按钮。
代码段:<com.android.systemui.statusbar.policy.NotificationRowLayout
android:id="@+id/latestItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
systemui:rowHeight="@dimen/notification_row_min_height"
/>
该代码段是⽤于存放下拉通知栏⾥⾯的各种通知消息。
下⾯主要分析com.android.systemui.statusbar.phone.NotificationPanelView下拉通知栏的实现类的源码:
public class NotificationPanelView extends PanelView {};由类定义的代码可以知道该类是继承PanelView类,PanelView类则是继承于FrameLayout。
下拉菜单栏的主要实现都是在NotificationPanelView的⽗类PanelView中实现。
看以下的代码段:
protected void onFinishInflate() {
mHandleView = findViewById(R.id.handle);
loadDimens();
if (DEBUG) logf("handle view: " + mHandleView);
if (mHandleView != null) {
mHandleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("Garment30", "onTouch");
int pointerIndex = event.findPointerIndex(mTrackingPointer);
if (pointerIndex < 0) {
pointerIndex = 0;
mTrackingPointer = PointerId(pointerIndex);
}
final float y = Y(pointerIndex);
final float rawDelta = RawY() - Y();
final float rawY = y + rawDelta;
if (DEBUG) logf("Touch: a=%s p=[%d,%d] y=%.1f rawY=%.1f off=%.1f",
MotionEvent.Action()),
mTrackingPointer, pointerIndex,
y, rawY, mTouchOffset);
LocationOnScreen(mAbsPos);机器人装配生产线
switch (ActionMasked()) {
case MotionEvent.ACTION_DOWN:
Log.i("Garment30", "ACTION_DOWN");
mHandleView.setPressed(true);
postInvalidate(); // catch the press state change
mInitialTouchY = y;
mVelocityTracker = FlingTracker.obtain();
trackMovement(event);
mTimeAnimator.cancel(); // end any outstanding animations
mTouchOffset = (rawY - mAbsPos[1]) - mExpandedHeight;
if (mExpandedHeight == 0) {
mJustPeeked = true;
runPeekAnimation();
}
break;
case MotionEvent.ACTION_POINTER_UP:
Log.i("Garment30", "ACTION_POINTER_UP");
final int upPointer = ActionIndex());
if (mTrackingPointer == upPointer) {
// gesture is ongoing, find a new pointer to track
final int newIndex = PointerId(0) != upPointer ? 0 : 1;
final float newY = Y(newIndex);
final float newRawY = newY + rawDelta;
mTrackingPointer = PointerId(newIndex);
mTouchOffset = (newRawY - mAbsPos[1]) - mExpandedHeight;
mInitialTouchY = newY;
}
break;
case MotionEvent.ACTION_MOVE:
Log.i("Garment30", "ACTION_MOVE");
Log.i("Garment28", "PanelView---ACTION_MOVE");
final float h = rawY - mAbsPos[1] - mTouchOffset;
if (h > mPeekHeight) {
Log.i("Garment28", "PanelView---h > mPeekHeight");
if (mPeekAnimator != null && mPeekAnimator.isStarted()) {
mPeekAnimator.cancel();
}
褐变度
mJustPeeked = false;
}
if (!mJustPeeked) {
Log.i("Garment28", "PanelView---!mJustPeeked--h:"+h);
//下⾯两段代码需要同时使⽤
PanelView.this.setExpandedHeightInternal(h);//屏蔽了这段代码,下拉菜单⽆法随⼿的移动⼀起下拉,松⼿后菜单移动到默认的长度
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);//屏蔽了这段代码,下拉通知栏显⽰为透明,松⼿后才正常
}
trackMovement(event);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Log.i("Garment30", "ACTION_CANCEL");
mFinalTouchY = y;
mTrackingPointer = -1;
mHandleView.setPressed(false);
postInvalidate(); // catch the press state change
trackMovement(event);
float vel = 0, yVel = 0, xVel = 0;
boolean negative = false;
if (mVelocityTracker != null) {
// the velocitytracker might be null if we got a bad input stream
mVelocityTrackerputeCurrentVelocity(1000);
yVel = YVelocity();
negative = yVel < 0;
xVel = XVelocity();
if (xVel < 0) {
xVel = -xVel;
}
if (xVel > mFlingGestureMaxXVelocityPx) {
xVel = mFlingGestureMaxXVelocityPx; // limit how much we care about the x axis                                }
vel = (float)Math.hypot(yVel, xVel);
if (vel > mFlingGestureMaxOutputVelocityPx) {
vel = mFlingGestureMaxOutputVelocityPx;
}
mVelocityTracker = null;
}
// if you've barely moved your finger, we treat the velocity as 0
// preventing spurious flings due to touch screen jitter
final float deltaY = Math.abs(mFinalTouchY - mInitialTouchY);
if (deltaY < mFlingGestureMinDistPx
|| vel < mFlingExpandMinVelocityPx
) {
vel = 0;
}
if (negative) {
vel = -vel;
}
if (DEBUG) logf("gesture: dy=%f vel=(%f,%f) vlinear=%f",
deltaY,
xVel, yVel,
vel);
女性快乐器
fling(vel, true);    //松⼿后下拉通知栏回弹的动画
break;
}
return true;

本文发布于:2024-09-23 13:27:07,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/154650.html

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

标签:通知   代码   移动   布局   知道   源码   默认   实现
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议