Search in sources :

Example 26 with WindowManager

use of android.view.WindowManager in project robotium by RobotiumTech.

the class ViewFetcher method getScrollListWindowHeight.

/**
	 * Returns the height of the scroll or list view parent
	 * @param view the view who's parents height should be returned
	 * @return the height of the scroll or list view parent
	 */
@SuppressWarnings("deprecation")
public float getScrollListWindowHeight(View view) {
    final int[] xyParent = new int[2];
    View parent = getScrollOrListParent(view);
    final float windowHeight;
    if (parent == null) {
        WindowManager windowManager = (WindowManager) instrumentation.getTargetContext().getSystemService(Context.WINDOW_SERVICE);
        windowHeight = windowManager.getDefaultDisplay().getHeight();
    } else {
        parent.getLocationOnScreen(xyParent);
        windowHeight = xyParent[1] + parent.getHeight();
    }
    parent = null;
    return windowHeight;
}
Also used : TextView(android.widget.TextView) View(android.view.View) WebView(android.webkit.WebView) WindowManager(android.view.WindowManager)

Example 27 with WindowManager

use of android.view.WindowManager in project GT by Tencent.

the class DeviceUtils method getDevHeight.

/**
	 * 获取设备屏幕高度
	 * 
	 * @param context
	 *            应用程序的上下文环境
	 * @return 设备屏幕高度
	 */
public static int getDevHeight() {
    WindowManager wm = (WindowManager) GTApp.getContext().getSystemService(Context.WINDOW_SERVICE);
    int height = 800;
    if (null != wm.getDefaultDisplay()) {
        height = wm.getDefaultDisplay().getHeight();
    }
    return height;
}
Also used : WindowManager(android.view.WindowManager)

Example 28 with WindowManager

use of android.view.WindowManager in project GT by Tencent.

the class DeviceUtils method getDevWidth.

/**
	 * 获取设备屏幕宽度
	 * 
	 * @param context
	 *            应用程序的上下文环境
	 * @return 设备屏幕宽度
	 */
public static int getDevWidth() {
    WindowManager wm = (WindowManager) GTApp.getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = 480;
    if (null != wm.getDefaultDisplay()) {
        width = wm.getDefaultDisplay().getWidth();
    }
    return width;
}
Also used : WindowManager(android.view.WindowManager)

Example 29 with WindowManager

use of android.view.WindowManager in project GT by Tencent.

the class GTFloatView method createView.

private void createView() {
    wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    wmParams = new WindowManager.LayoutParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | 8;
    // 调整悬浮窗口至左上角
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    try {
        wm.addView(view_floatview, wmParams);
    } catch (Exception e) {
        /*
			 * 有的Android6会报permission denied for this window type问题
			 * https://github.com/intercom/intercom-android/issues/116
			 * 在这种系统上直接屏蔽悬浮窗
			 */
        stopSelf();
        return;
    }
    final int sbar_height = DeviceUtils.getStatusBarHeight(getApplicationContext());
    view_floatview.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - sbar_height;
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    move_event = false;
                    up_event = false;
                    state = MotionEvent.ACTION_DOWN;
                    StartX = x;
                    StartY = y;
                    mTouchStartX = event.getX();
                    mTouchStartY = event.getY();
                    touchX = mTouchStartX;
                    touchY = mTouchStartY;
                    ProX = event.getRawX();
                    ProY = event.getRawY();
                    clickHandler.sendEmptyMessage(0);
                    break;
                case MotionEvent.ACTION_MOVE:
                    state = MotionEvent.ACTION_MOVE;
                    moveX = event.getRawX();
                    moveY = event.getRawY();
                    final ViewConfiguration configuration = ViewConfiguration.get(getApplicationContext());
                    int mTouchSlop = configuration.getScaledTouchSlop();
                    // 第一次move
                    if (move_oldX == -1000 && move_oldY == -1000) {
                        move_oldX = moveX;
                        move_oldY = moveY;
                        if (Math.abs(moveX - ProX) < mTouchSlop * 2 && Math.abs(moveY - ProY) < mTouchSlop * 2) {
                            move_event = false;
                        } else {
                            move_event = true;
                            updateViewPosition();
                        }
                    } else {
                        if (move_event == false) {
                            if (Math.abs(moveX - move_oldX) < mTouchSlop * 2 && Math.abs(moveY - move_oldY) < mTouchSlop * 2) {
                                move_event = false;
                            } else {
                                move_event = true;
                                updateViewPosition();
                            }
                        } else {
                            updateViewPosition();
                        }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    state = MotionEvent.ACTION_UP;
                    updateViewPositionEnd();
                    move_oldX = -1000;
                    move_oldY = -1000;
                    mTouchStartX = mTouchStartY = 0;
                    up_event = true;
                    clickHandler.sendEmptyMessage(1);
                    break;
            }
            return true;
        }
    });
}
Also used : ViewConfiguration(android.view.ViewConfiguration) OnTouchListener(android.view.View.OnTouchListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WindowManager(android.view.WindowManager) MotionEvent(android.view.MotionEvent)

Example 30 with WindowManager

use of android.view.WindowManager in project FloatingView by UFreedom.

the class UIUtils method getScreenHeight.

public static int getScreenHeight(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return dm.heightPixels;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Aggregations

WindowManager (android.view.WindowManager)394 Display (android.view.Display)177 Point (android.graphics.Point)121 DisplayMetrics (android.util.DisplayMetrics)100 View (android.view.View)42 IWindowManager (android.view.IWindowManager)37 Context (android.content.Context)34 Resources (android.content.res.Resources)25 ImageView (android.widget.ImageView)23 Configuration (android.content.res.Configuration)19 SuppressLint (android.annotation.SuppressLint)17 Camera (android.hardware.Camera)17 Intent (android.content.Intent)16 Rect (android.graphics.Rect)16 RemoteException (android.os.RemoteException)15 LayoutParams (android.view.WindowManager.LayoutParams)15 Dialog (android.app.Dialog)14 TextView (android.widget.TextView)14 Bitmap (android.graphics.Bitmap)10 PointerLocationView (com.android.internal.widget.PointerLocationView)10