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;
}
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;
}
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;
}
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;
}
});
}
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;
}
Aggregations