2626import android .support .annotation .DrawableRes ;
2727import android .support .annotation .IntDef ;
2828import android .support .annotation .NonNull ;
29+ import android .support .v4 .view .ViewCompat ;
2930import android .util .DisplayMetrics ;
3031import android .view .DisplayCutout ;
3132import android .view .HapticFeedbackConstants ;
@@ -544,7 +545,7 @@ public void addViewToWindow(View view, Options options) {
544545 mWindowManager .addView (mFullscreenObserverView , mFullscreenObserverView .getWindowLayoutParams ());
545546 mTargetFloatingView = floatingView ;
546547 } else {
547- mWindowManager . removeViewImmediate (mTrashView );
548+ removeViewImmediate (mTrashView );
548549 }
549550 // 必ずトップに来て欲しいので毎回貼り付け
550551 mWindowManager .addView (mTrashView , mTrashView .getWindowLayoutParams ());
@@ -559,7 +560,7 @@ private void removeViewToWindow(FloatingView floatingView) {
559560 final int matchIndex = mFloatingViewList .indexOf (floatingView );
560561 // 見つかった場合は表示とリストから削除
561562 if (matchIndex != -1 ) {
562- mWindowManager . removeViewImmediate (floatingView );
563+ removeViewImmediate (floatingView );
563564 mFloatingViewList .remove (matchIndex );
564565 }
565566
@@ -576,17 +577,29 @@ private void removeViewToWindow(FloatingView floatingView) {
576577 * ViewをWindowから全て取り外します。
577578 */
578579 public void removeAllViewToWindow () {
579- mWindowManager . removeViewImmediate (mFullscreenObserverView );
580- mWindowManager . removeViewImmediate (mTrashView );
580+ removeViewImmediate (mFullscreenObserverView );
581+ removeViewImmediate (mTrashView );
581582 // FloatingViewの削除
582583 final int size = mFloatingViewList .size ();
583584 for (int i = 0 ; i < size ; i ++) {
584585 final FloatingView floatingView = mFloatingViewList .get (i );
585- mWindowManager . removeViewImmediate (floatingView );
586+ removeViewImmediate (floatingView );
586587 }
587588 mFloatingViewList .clear ();
588589 }
589590
591+ /**
592+ * Safely remove the View (issue #89)
593+ *
594+ * @param view {@link View}
595+ */
596+ private void removeViewImmediate (View view ) {
597+ if (!ViewCompat .isAttachedToWindow (view )) {
598+ return ;
599+ }
600+ mWindowManager .removeViewImmediate (view );
601+ }
602+
590603 /**
591604 * Find the safe area of DisplayCutout.
592605 *
0 commit comments