// aapi 25publicvoidhandleShow(IBinderwindowToken){if(localLOGV)Log.v(TAG,"HANDLE SHOW: "+this+" mView="+mView+" mNextView="+mNextView);if(mView!=mNextView){// remove the old view if necessaryhandleHide();mView=mNextView;Contextcontext=mView.getContext().getApplicationContext();StringpackageName=mView.getContext().getOpPackageName();if(context==null){context=mView.getContext();}mWM=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);// We can resolve the Gravity here by using the Locale for getting// the layout directionfinalConfigurationconfig=mView.getContext().getResources().getConfiguration();finalintgravity=Gravity.getAbsoluteGravity(mGravity,config.getLayoutDirection());mParams.gravity=gravity;if((gravity&Gravity.HORIZONTAL_GRAVITY_MASK)==Gravity.FILL_HORIZONTAL){mParams.horizontalWeight=1.0f;}if((gravity&Gravity.VERTICAL_GRAVITY_MASK)==Gravity.FILL_VERTICAL){mParams.verticalWeight=1.0f;}mParams.x=mX;mParams.y=mY;mParams.verticalMargin=mVerticalMargin;mParams.horizontalMargin=mHorizontalMargin;mParams.packageName=packageName;mParams.hideTimeoutMilliseconds=mDuration==Toast.LENGTH_LONG?LONG_DURATION_TIMEOUT:SHORT_DURATION_TIMEOUT;mParams.token=windowToken;if(mView.getParent()!=null){if(localLOGV)Log.v(TAG,"REMOVE! "+mView+" in "+this);mWM.removeView(mView);}if(localLOGV)Log.v(TAG,"ADD! "+mView+" in "+this);mWM.addView(mView,mParams);trySendAccessibilityEvent();}}
// api 26publicvoidhandleShow(IBinderwindowToken){if(localLOGV)Log.v(TAG,"HANDLE SHOW: "+this+" mView="+mView+" mNextView="+mNextView);// If a cancel/hide is pending - no need to show - at this point// the window token is already invalid and no need to do any work.if(mHandler.hasMessages(CANCEL)||mHandler.hasMessages(HIDE)){return;}if(mView!=mNextView){// remove the old view if necessaryhandleHide();mView=mNextView;Contextcontext=mView.getContext().getApplicationContext();StringpackageName=mView.getContext().getOpPackageName();if(context==null){context=mView.getContext();}mWM=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);// We can resolve the Gravity here by using the Locale for getting// the layout directionfinalConfigurationconfig=mView.getContext().getResources().getConfiguration();finalintgravity=Gravity.getAbsoluteGravity(mGravity,config.getLayoutDirection());mParams.gravity=gravity;if((gravity&Gravity.HORIZONTAL_GRAVITY_MASK)==Gravity.FILL_HORIZONTAL){mParams.horizontalWeight=1.0f;}if((gravity&Gravity.VERTICAL_GRAVITY_MASK)==Gravity.FILL_VERTICAL){mParams.verticalWeight=1.0f;}mParams.x=mX;mParams.y=mY;mParams.verticalMargin=mVerticalMargin;mParams.horizontalMargin=mHorizontalMargin;mParams.packageName=packageName;mParams.hideTimeoutMilliseconds=mDuration==Toast.LENGTH_LONG?LONG_DURATION_TIMEOUT:SHORT_DURATION_TIMEOUT;mParams.token=windowToken;if(mView.getParent()!=null){if(localLOGV)Log.v(TAG,"REMOVE! "+mView+" in "+this);mWM.removeView(mView);}if(localLOGV)Log.v(TAG,"ADD! "+mView+" in "+this);// Since the notification manager service cancels the token right// after it notifies us to cancel the toast there is an inherent// race and we may attempt to add a window after the token has been// invalidated. Let us hedge against that.try{mWM.addView(mView,mParams);trySendAccessibilityEvent();}catch(WindowManager.BadTokenExceptione){/* ignore */}}}