Android TextToast显示流程

 Android Toast有TextToastRecord和CustomToastRecord两种方式进行显示,最主要的差别在service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); TextToastRecord的callback等于null

@MainActivity.java
Toast.makeText(MainActivity.this, "xww make toast", Toast.LENGTH_SHORT)
@frameworks/base/core/java/android/widget/Toast.java
    makeText(context, null, text, duration);
        Toast result = new Toast(context, looper);
            mContext = context;  // Toast的context
            mTN = new TN(context, context.getPackageName(), mToken, mCallbacks, looper);
@frameworks/base/core/java/android/widget/ToastPresenter.java
                mPresenter = new ToastPresenter(context, accessibilityManager, getService(), packageName);
                    mContext = context;  //ToastPresenter的context
@frameworks/base/core/java/android/app/ContextImpl.java
                    mWindowManager = context.getSystemService(WindowManager.class);
                        SystemServiceRegistry.getSystemServiceName(serviceClass);
                            final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass);
                            return serviceName;
        View v = ToastPresenter.getTextToastView(context, text);
            View view = LayoutInflater.from(context).inflate(TEXT_TOAST_LAYOUT, null);
            TextView textView = view.findViewById(com.android.internal.R.id.message);
            textView.setText(text);
            return view;
       result.mNextView = v; // Toast的context
.show())
    INotificationManager service = getService();
        sService = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    TN tn = mTN;
    tn.mNextView = mNextView; // 设置TN的mNextView
    final int displayId = mContext.getDisplayId();
@frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
    service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback);  //TextToastRecord和CustomToastRecord主要是这里的差异, callback等于null
      enqueueToast(pkg, token, text, null, duration, displayId, callback);
@frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
        mWindowManagerInternal.addWindowToken(windowToken, TYPE_TOAST, displayId,null
        record = getToastRecord(callingUid, callingPid, pkg, isSystemToast, token, text, callback, duration, windowToken, displayId, textCallback);  // callback等于null
        f (callback == null) { return new TextToastRecord(this, mStatusBar, uid, pid, packageName, isSystemToast, token, text, duration, windowToken, displayId, textCallback); 
            final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */);
            new WindowToken.Builder(this, binder, type).setDisplayContent(dc) .setPersistOnEmpty(true).setOwnerCanManageAppTokens(true).setOptions(options).build();
        mToastQueue.add(record);
        showNextToastLocked(false);
            ToastRecord record = mToastQueue.get(0);
            tryShowToast(record, rateLimitingEnabled, isWithinQuota, isPackageInForeground))
@frameworks/base/services/core/java/com/android/server/notification/toast/TextToastRecord.java
                record.show();
@frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
                    mStatusBar.showToast(uid, pkg, token, text, windowToken, getDuration(), mCallback);  //进入到com.android.systemui
@frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
                        mBar.showToast(uid, packageName, token, text, windowToken, duration, callback);
                            mHandler.obtainMessage(MSG_SHOW_TOAST, args).sendToTarget(); 
@frameworks/base/packages/SystemUI/src/com/android/systemui/toast/ToastUI.java
                                case MSG_SHOW_TOAST: {  callbacks.showToast(uid, packageName, token, text, windowToken, duration, callback);
                                    mPresenter = new ToastPresenter(context, mIAccessibilityManager, mNotificationManager, packageName); 
                                    mToastLogger.logOnShowToast(uid, packageName, text.toString(), token.toString());
                                    mPresenter.show(mToast.getView(), token, windowToken, duration, mToast.getGravity(),mToast.getXOffset(), mToast.getYOffset(), mToast.getHorizontalMargin(), mToast.getVerticalMargin(), mCallback, mToast.hasCustomAnimation());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛文旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值