android.app.Activity.getWindowManager()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(355)

本文整理了Java中android.app.Activity.getWindowManager()方法的一些代码示例,展示了Activity.getWindowManager()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getWindowManager()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getWindowManager

Activity.getWindowManager介绍

暂无

代码示例

代码示例来源:origin: CarGuo/GSYVideoPlayer

public static boolean getCurrentScreenLand(Activity context) {
    return context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90 ||
        context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270;

  }
}

代码示例来源:origin: H07000223/FlycoTabLayout

public SimpleHomeAdapter(Context context, String[] items) {
  this.mContext = context;
  this.mItems = items;
  mDisplayMetrics = new DisplayMetrics();
  ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
}

代码示例来源:origin: zwwill/yanxuan-weex-demo

public static int getDisplayWidth(Activity activity){
  int width=0;
  if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) {
    Point point=new Point();
    activity.getWindowManager().getDefaultDisplay().getSize(point);
    width = point.x;
  }
  return width;
}

代码示例来源:origin: libgdx/libgdx

@Override
public int getRotation () {
  int orientation = 0;
  if (context instanceof Activity) {
    orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
  } else {
    orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
  }
  switch (orientation) {
  case Surface.ROTATION_0:
    return 0;
  case Surface.ROTATION_90:
    return 90;
  case Surface.ROTATION_180:
    return 180;
  case Surface.ROTATION_270:
    return 270;
  default:
    return 0;
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public int getRotation () {
  int orientation = 0;
  if (context instanceof Activity) {
    orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
  } else {
    orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
  }
  switch (orientation) {
  case Surface.ROTATION_0:
    return 0;
  case Surface.ROTATION_90:
    return 90;
  case Surface.ROTATION_180:
    return 180;
  case Surface.ROTATION_270:
    return 270;
  default:
    return 0;
  }
}

代码示例来源:origin: arimorty/floatingsearchview

public static int getScreenWidth(Activity activity) {
  Display display = activity.getWindowManager().getDefaultDisplay();
  DisplayMetrics outMetrics = new DisplayMetrics();
  display.getMetrics(outMetrics);
  return outMetrics.widthPixels;
}

代码示例来源:origin: jeasonlzy/ImagePicker

/**
 * 获取手机大小(分辨率)
 */
public static DisplayMetrics getScreenPix(Activity activity) {
  DisplayMetrics displaysMetrics = new DisplayMetrics();
  activity.getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics);
  return displaysMetrics;
}

代码示例来源:origin: sunfusheng/MarqueeView

public static int getWindowHeight(Activity context) {
  DisplayMetrics metric = new DisplayMetrics();
  context.getWindowManager().getDefaultDisplay().getMetrics(metric);
  return metric.heightPixels;
}

代码示例来源:origin: arimorty/floatingsearchview

public static int getScreenHeight(Activity activity) {
  Display display = activity.getWindowManager().getDefaultDisplay();
  DisplayMetrics outMetrics = new DisplayMetrics();
  display.getMetrics(outMetrics);
  return outMetrics.heightPixels;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

public static float getdensity(Activity activity) {
  DisplayMetrics dm = new DisplayMetrics();
  activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
  float density = dm.density;
  return density;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

public static int getScreenSize(Activity activity) {
  int widthPixels = 0;
  int heightPixels = 0;
  DisplayMetrics dm = new DisplayMetrics();
  if (dm != null) {
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    widthPixels = dm.widthPixels;
    heightPixels = dm.heightPixels;
  }
  return widthPixels * heightPixels;
}

代码示例来源:origin: sunfusheng/StickyHeaderListView

public static int getWindowHeight(Activity activity){
    DisplayMetrics metric = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metric);
    return metric.heightPixels;
  }
}

代码示例来源:origin: sunfusheng/MarqueeView

public static int getWindowWidth(Activity context) {
  DisplayMetrics metric = new DisplayMetrics();
  context.getWindowManager().getDefaultDisplay().getMetrics(metric);
  return metric.widthPixels;
}

代码示例来源:origin: sunfusheng/StickyHeaderListView

public static  int getWindowWidth(Activity context){
  DisplayMetrics metric = new DisplayMetrics();
  context.getWindowManager().getDefaultDisplay().getMetrics(metric);
  return metric.widthPixels;
}

代码示例来源:origin: TommyLemon/APIJSON

@SuppressLint("NewApi")
private float getSmallestWidthDp(Activity activity) {
  DisplayMetrics metrics = new DisplayMetrics();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
  } else {
    // TODO this is not correct, but we don't really care pre-kitkat
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  }
  float widthDp = metrics.widthPixels / metrics.density;
  float heightDp = metrics.heightPixels / metrics.density;
  return Math.min(widthDp, heightDp);
}

代码示例来源:origin: stackoverflow.com

activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
int diff = (screenHeight - statusBarHeight) - height;
if (listener != null) {

代码示例来源:origin: jeasonlzy/ImagePicker

@SuppressLint("NewApi")
private float getSmallestWidthDp(Activity activity) {
  DisplayMetrics metrics = new DisplayMetrics();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
  } else {
    // TODO this is not correct, but we don't really care pre-kitkat
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  }
  float widthDp = metrics.widthPixels / metrics.density;
  float heightDp = metrics.heightPixels / metrics.density;
  return Math.min(widthDp, heightDp);
}

代码示例来源:origin: vondear/RxTool

private double getPPIOfDevice() {
    Point point = new Point();
    Activity activity = (Activity) context;
    activity.getWindowManager().getDefaultDisplay().getRealSize(point);//获取屏幕的真实分辨率
    DisplayMetrics dm = getResources().getDisplayMetrics();
    double x = Math.pow(point.x / dm.xdpi, 2);//
    double y = Math.pow(point.y / dm.ydpi, 2);
    double screenInches = Math.sqrt(x + y);
    Double ppi = Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2)) / screenInches;
    return ppi;
  }
}

代码示例来源:origin: orhanobut/dialogplus

public int getDefaultContentHeight() {
 Activity activity = (Activity) context;
 Display display = activity.getWindowManager().getDefaultDisplay();
 int displayHeight = display.getHeight() - Utils.getStatusBarHeight(activity);
 if (defaultContentHeight == 0) {
  defaultContentHeight = (displayHeight * 2) / 5;
 }
 return defaultContentHeight;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void removeAllViews_shouldCallOnAttachedToAndDetachedFromWindow() throws Exception {
 MyView parent = new MyView("parent", transcript);
 Activity activity = Robolectric.buildActivity(ContentViewActivity.class).create().get();
 activity.getWindowManager().addView(parent, new WindowManager.LayoutParams(100, 100));
 parent.addView(new MyView("child", transcript));
 parent.addView(new MyView("another child", transcript));
 ShadowLooper.runUiThreadTasks();
 transcript.clear();
 parent.removeAllViews();
 ShadowLooper.runUiThreadTasks();
 assertThat(transcript).containsExactly("another child detached", "child detached");
}

相关文章

Activity类方法