Java Code Examples for android.view.WindowManager#removeView()

The following examples show how to use android.view.WindowManager#removeView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatToast.java    From MobileGuard with MIT License 6 votes vote down vote up
/**
 * Show the view in front of screen at position x,y until call close()
 * @param x the position x of view
 * @param y the position y of view
 */
public void show(int x, int y) {
    mParams.x = x;
    mParams.y = y;
    if (mView != mNextView) {
        // remove the old view if necessary
        close();
        mView = mNextView;
        Context context = mView.getContext().getApplicationContext();
        if (context == null) {
            context = mView.getContext();
        }
        mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        if (mView.getParent() != null) {
            mWM.removeView(mView);
        }
        mWM.addView(mView, mParams);
    }
}
 
Example 2
Source File: FloatToast.java    From MobileGuard with MIT License 6 votes vote down vote up
/**
     * Show the view in front of screen at last position until call close()
     * If the first show, it will show in center of screen.
     * You also can call show(x, y) to specific position.
     */
    public void show() {
        if (mView != mNextView) {
            // remove the old view if necessary
            close();
            mView = mNextView;
            Context context = mView.getContext().getApplicationContext();
            if (context == null) {
                context = mView.getContext();
            }
            mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
            if (mView.getParent() != null) {
                mWM.removeView(mView);
            }
            // get device width and height
            Point point = new Point();
            mWM.getDefaultDisplay().getSize(point);
            // get config x,y
            mParams.x = ConfigUtils.getInt(context, Constant.KEY_FLOAT_TOAST_X, (point.x - mView.getWidth()) / 2);
            mParams.y = ConfigUtils.getInt(context, Constant.KEY_FLOAT_TOAST_Y, (point.y - mView.getHeight()) / 2);
//            System.out.println("config (x, y) = " + mParams.x + "," + mParams.y);

            mWM.addView(mView, mParams);
        }
    }
 
Example 3
Source File: SplashScreenSurface.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void remove() {
    if (DEBUG_SPLASH_SCREEN) Slog.v(TAG, "Removing splash screen window for " + mAppToken + ": "
                    + this + " Callers=" + Debug.getCallers(4));

    final WindowManager wm = mView.getContext().getSystemService(WindowManager.class);
    wm.removeView(mView);
}
 
Example 4
Source File: LiveMainActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
public void removeFloatingWindow(Context context) {
    if (mFloatingView != null) {
        WindowManager windowManager = getWindowManager(context);
        windowManager.removeView(mFloatingView);
        mFloatingView.removeFloatingWindow(FloatingPlayer.getInstance().getKSYTextureView());
        mFloatingView = null;
    }
}
 
Example 5
Source File: PlumbleOverlay.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
public void hide() {
    if(!mShown)
        return;
    mShown = false;
    mService.unregisterObserver(mObserver);
    mOverlayList.setAdapter(null);
    try {
        WindowManager windowManager = (WindowManager) mService.getSystemService(Context.WINDOW_SERVICE);
        windowManager.removeView(mOverlayView);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: StatusBarView.java    From FloatBall with Apache License 2.0 5 votes vote down vote up
public void detachFromWindow(WindowManager windowManager) {
    if (!isAdded) return;
    isAdded = false;
    removeOnLayoutChangeListener(layoutChangeListener);
    if (getContext() instanceof Activity) {
        windowManager.removeViewImmediate(this);
    } else {
        windowManager.removeView(this);
    }
}
 
Example 7
Source File: FloatBall.java    From FloatBall with Apache License 2.0 5 votes vote down vote up
public void detachFromWindow(WindowManager windowManager) {
    this.windowManager = null;
    if (isAdded) {
        removeSleepRunnable();
        if (getContext() instanceof Activity) {
            windowManager.removeViewImmediate(this);
        } else {
            windowManager.removeView(this);
        }
        isAdded = false;
        sleep = false;
    }
}
 
Example 8
Source File: FloatingPlayingActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
public void removeFloatingWindow(Context context) {
    if (mFloatingView != null) {
        WindowManager windowManager = getWindowManager(context);
        windowManager.removeView(mFloatingView);
        mFloatingView = null;
    }
}
 
Example 9
Source File: TouchInterceptor.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void stopDragging() {
    if (mDragView != null) {
        mDragView.setVisibility(GONE);
        WindowManager wm = (WindowManager) getContext().getSystemService("window");
        wm.removeView(mDragView);
        mDragView.setImageDrawable(null);
        mDragView = null;
    }
    if (mDragBitmap != null) {
        mDragBitmap.recycle();
        mDragBitmap = null;
    }
}
 
Example 10
Source File: DragNDropListView.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void stopDrag(int itemIndex) {
	if (mDragView != null) {
		if (mDragListener != null)
			mDragListener.onStopDrag(getChildAt(itemIndex));
		mDragView.setVisibility(GONE);
		WindowManager wm = (WindowManager) getContext().getSystemService(
				Context.WINDOW_SERVICE);
		wm.removeView(mDragView);
		mDragView.setImageDrawable(null);
		mDragView = null;
	}
}
 
Example 11
Source File: VodMainActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
public void removeFloatingWindow(Context context) {
    if (mFloatingView != null) {
        WindowManager windowManager = getWindowManager(context);
        windowManager.removeView(mFloatingView);
        mFloatingView.removeFloatingWindow(FloatingPlayer.getInstance().getKSYTextureView());
        mFloatingView = null;
    }
}
 
Example 12
Source File: GalgoService.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    if (mTextView != null) {
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        wm.removeView(mTextView);
    }
}
 
Example 13
Source File: FloatWindowManager.java    From FloatWindow with Apache License 2.0 5 votes vote down vote up
/**
 * 将小悬浮窗从屏幕上移除
 * 
 * @param context
 */
public void removeSmallWindow() {
	if (smallWindow != null) {
		WindowManager windowManager = getWindowManager();
		windowManager.removeView(smallWindow);
		smallWindow = null;
	}
}
 
Example 14
Source File: Mixture.java    From frenchtoast with Apache License 2.0 5 votes vote down vote up
@MainThread public void show() {
  assertMainThread();
  View view = toast.getView();
  if (view == null) {
    throw new IllegalStateException("Can't show a Toast with no View.");
  }

  Context context = toast.getView().getContext();

  WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);

  // We can resolve the Gravity here by using the Locale for getting
  // the layout direction
  Configuration config = view.getContext().getResources().getConfiguration();
  int gravity = toast.getGravity();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    gravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
  }
  params.gravity = gravity;
  if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
    params.horizontalWeight = 1.0f;
  }
  if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
    params.verticalWeight = 1.0f;
  }
  params.x = toast.getXOffset();
  params.y = toast.getYOffset();
  params.verticalMargin = toast.getVerticalMargin();
  params.horizontalMargin = toast.getHorizontalMargin();
  params.packageName = context.getPackageName();
  if (view.getParent() != null) {
    windowManager.removeView(view);
  }
  windowManager.addView(view, params);
  trySendAccessibilityEvent(view);
}
 
Example 15
Source File: FloatbarService.java    From CircleFloatBar with Apache License 2.0 5 votes vote down vote up
private void createFloatBarView() {
    displayHeight = getResources().getDisplayMetrics().heightPixels;
    displayWidth = getResources().getDisplayMetrics().widthPixels;
    defaultX = displayWidth * 0.9f;
    defaultY = displayHeight / 2;

    thresholdX = (int)(getResources().getDisplayMetrics().widthPixels * 0.1f);
    thresholdY = (int)(getResources().getDisplayMetrics().heightPixels * 0.1f);

    wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    params = new WindowManager.LayoutParams();
    if(Build.VERSION.SDK_INT>=26){
        params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    }else{
        params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    params.gravity = Gravity.LEFT | Gravity.TOP;
    params.x = (int) (displayHeight * 0.9f);
    params.y = displayWidth / 2;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.format = PixelFormat.RGBA_8888;
    //for get showmenuview width & height
    wm.addView(showMenuView, params);
    wm.removeView(showMenuView);

    wm.addView(hideMenuView, params);


}
 
Example 16
Source File: VenvyUIUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static void removeView(View view, WindowManager manager) {

        try {
            manager.removeView(view);
        } catch (Exception e) {
            VenvyLog.e(TAG, e);
        }
    }
 
Example 17
Source File: Utils.java    From pandora with Apache License 2.0 5 votes vote down vote up
public static void removeViewFromWindow(View v) {
    try {
        WindowManager windowManager = (WindowManager) Utils.getContext().getSystemService(Context.WINDOW_SERVICE);
        windowManager.removeView(v);
    } catch (Throwable t){
        t.printStackTrace();
    }
}
 
Example 18
Source File: ManagerSuperToast.java    From Bitocle with Apache License 2.0 4 votes vote down vote up
protected void removeSuperToast(SuperToast superToast) {

        final WindowManager windowManager = superToast
                .getWindowManager();

        final View toastView = superToast.getView();

        if (windowManager != null) {

            mQueue.poll();

            windowManager.removeView(toastView);

            sendMessageDelayed(superToast,
                    Messages.DISPLAY_SUPERTOAST, 500);

            if(superToast.getOnDismissListener() != null) {

                superToast.getOnDismissListener().onDismiss(superToast.getView());

            }

        }

    }
 
Example 19
Source File: JsWindow.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public void handleShow() {
	if (mView != mNextView) {
		// remove the old view if necessary
		mView = mNextView;
		Context context = mView.getContext().getApplicationContext();
		String packageName = mView.getContext().getOpPackageName();
		System.out.println("pkg:" + packageName);
		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 direction
		final Configuration config = mView.getContext().getResources()
				.getConfiguration();
		final int gravity = 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;
		if (mView.getParent() != null) {
			mWM.removeView(mView);
		}
		System.out.println("add view start");
		try {
			mWM.addView(mView, mParams);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("add view end");
		trySendAccessibilityEvent();
	}
}
 
Example 20
Source File: Toast.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void handleShow(IBinder windowToken) {
    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 necessary
        handleHide();
        mView = mNextView;
        Context context = mView.getContext().getApplicationContext();
        String packageName = 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 direction
        final Configuration config = mView.getContext().getResources().getConfiguration();
        final int gravity = 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.BadTokenException e) {
            /* ignore */
        }
    }
}