Java 类android.view.Display 实例源码
项目:PresenterLite
文件:DisplayInfoHelper.java
public static void populate(Context context, View view, Display display) {
View da = view.findViewById(R.id.display_attributes);
Resources res = context.getResources();
if (da != null) {
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
((TextView) da.findViewById(R.id.density))
.setText(String.format("%s (%f)",
res.getString(R.string.density), metrics.density));
((TextView) da.findViewById(R.id.size)).setText(res
.getString(R.string.size));
((TextView) da.findViewById(R.id.dimensions))
.setText(String
.format("%dx%d (%dx%d)",
metrics.widthPixels,
metrics.heightPixels,
(int) ((float) metrics.widthPixels / metrics.density),
(int) ((float) metrics.heightPixels / metrics.density)));
}
}
项目:QRCodeScanner
文件:BarcodeScanView.java
private void init() {
// init surfaceholder
SurfaceHolder holder = getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(this);
WindowManager manager = (WindowManager) getContext().getSystemService(
Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
int width = screenWidth >= screenHeight ? screenWidth : screenHeight;
int height = screenWidth + screenHeight - width;
int rotation = display.getRotation();
mScanner = CameraScanner.getInstance();
mScanner.setRotation(0); //此处直接设为0,配合竖屏展示
mScanner.setReqSize(width, height);
}
项目:Bigbang
文件:ViewUtil.java
public static boolean isNavigationBarShow(Activity activity){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
Point realSize = new Point();
display.getSize(size);
display.getRealSize(realSize);
return realSize.y!=size.y;
}else {
boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
if(menu || back) {
return false;
}else {
return true;
}
}
}
项目:NeoTerm
文件:MainActivity.java
public void setUpStatusLabel() {
MainActivity Parent = this; // Too lazy to rename
if (Parent._btn != null) {
Parent._layout2.removeView(Parent._btn);
Parent._btn = null;
}
if (Parent._tv == null) {
//Get the display so we can know the screen size
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Parent._tv = new TextView(Parent);
Parent._tv.setMaxLines(2); // To show some long texts on smaller devices
Parent._tv.setMinLines(2); // Otherwise the background picture is getting resized at random, which does not look good
Parent._tv.setText(R.string.init);
// Padding is a good idea because if the display device is a TV the edges might be cut off
Parent._tv.setPadding((int) (width * 0.1), (int) (height * 0.1), (int) (width * 0.1), 0);
Parent._layout2.addView(Parent._tv);
}
}
项目:KrGallery
文件:AndroidUtilities.java
public static void checkDisplaySize() {
try {
Configuration configuration = applicationContext.getResources()
.getConfiguration();
usingHardwareInput = configuration.keyboard != Configuration.KEYBOARD_NOKEYS
&& configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
WindowManager manager = (WindowManager) applicationContext
.getSystemService(Context.WINDOW_SERVICE);
if (manager != null) {
Display display = manager.getDefaultDisplay();
if (display != null) {
display.getMetrics(displayMetrics);
display.getSize(displaySize);
Log.d("tmessages", "display size = " + displaySize.x + " " + displaySize.y + " "
+ displayMetrics.xdpi + "x" + displayMetrics.ydpi);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
项目:CalcMate
文件:Calculator.java
public void showFirstRunSimpleCling(boolean animate) {
// Enable the clings only if they have not been dismissed before
if(isClingsEnabled() && !CalculatorSettings.isDismissed(getContext(), Cling.SIMPLE_CLING_DISMISSED_KEY)) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int[] location = new int[3];
location[0] = 0;
location[1] = size.y / 2;
location[2] = 10;
initCling(R.id.simple_cling, location, 0, true, animate);
}
else {
removeCling(R.id.simple_cling);
}
}
项目:anyRTC-RTCP-Android
文件:CameraConfigurationManager.java
public void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point theScreenResolution = new Point();
theScreenResolution = getDisplaySize(display);
screenResolution = theScreenResolution;
Log.i(TAG, "Screen resolution: " + screenResolution);
/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
项目:homebank_android
文件:AppStoreInterstitial.java
private static void centerWindow(Window w) {
DisplayMetrics metrics = new DisplayMetrics();
Display display = w.getWindowManager().getDefaultDisplay();
display.getMetrics(metrics);
int width = Math.min(metrics.widthPixels - (int) (2 * DLG_PADDING_DP * metrics.density),
(int) (MAX_DIALOG_WIDTH_DP * metrics.density));
int height = Math.min(metrics.heightPixels - (int) ((2 * DLG_PADDING_DP + APPROX_STATUSBAR_HEIGHT_DP) * metrics.density),
(int) (MAX_DIALOG_HEIGHT_DP * metrics.density));
int x = (metrics.widthPixels - width) / 2;
int y = (metrics.heightPixels - height - ((int) (APPROX_STATUSBAR_HEIGHT_DP * metrics.density))) / 2;
LayoutParams params = w.getAttributes();
params.x = x;
params.y = y;
params.width = width;
params.height = height;
w.setAttributes(params);
w.setGravity(Gravity.LEFT | Gravity.TOP);
}
项目:MakiLite
文件:QuickTwitter.java
public void setUpWindow() {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 1.0f;
params.dimAmount = 0.4f;
getWindow().setAttributes(params);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
if (height > width) {
getWindow().setLayout((int) (width * .9), (int) (height * .7));
} else {
getWindow().setLayout((int) (width * .7), (int) (height * .8));
}
}
项目:OSchina_resources_android
文件:ShareDialogBuilder.java
@SuppressWarnings("deprecation")
@Override
public AlertDialog create() {
AlertDialog alertDialog = super.create();
Window window = alertDialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
WindowManager m = window.getWindowManager();
Display d = m.getDefaultDisplay();
WindowManager.LayoutParams p = window.getAttributes();
p.width = d.getWidth();
window.setAttributes(p);
}
this.mAlertDialog = alertDialog;
return alertDialog;
}
项目:ZxingScan
文件:CameraConfigurationManager.java
/**
* Reads, one time, values from the camera that are needed by the app.
*/
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
previewFormat = parameters.getPreviewFormat();
previewFormatString = parameters.get("preview-format");
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
screenResolution = new Point(display.getWidth(), display.getHeight());
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
// preview size is always something like 480*320, other 320*480
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
}
项目:Cable-Android
文件:ConversationPopupActivity.java
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 1.0f;
params.dimAmount = 0.1f;
params.gravity = Gravity.TOP;
getWindow().setAttributes(params);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
else getWindow().setLayout((int) (width * .7), (int) (height * .75));
super.onCreate(bundle, masterSecret);
titleView.setOnClickListener(null);
}
项目:social-login-helper
文件:InstagramDialog.java
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSpinner = new ProgressDialog(getContext());
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");
mContent = new LinearLayout(getContext());
mContent.setOrientation(LinearLayout.VERTICAL);
setUpTitle();
setUpWebView();
Display display = getWindow().getWindowManager().getDefaultDisplay();
final float scale = getContext().getResources().getDisplayMetrics().density;
float[] dimensions =
(display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE;
addContentView(mContent, new FrameLayout.LayoutParams((int) (dimensions[0] * scale + 0.5f),
(int) (dimensions[1] * scale + 0.5f)));
CookieSyncManager.createInstance(getContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
}
项目:pc-android-controller-android
文件:MotionClickService.java
@Override
public void onCreate() {
super.onCreate();
L.d("MotionClickService is create ");
DisplayMetrics dm = new DisplayMetrics();
Display mDisplay = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mDisplay.getMetrics(dm);
deviceWidth = dm.widthPixels;
deviceHeight = dm.heightPixels;
initSocket();
EventBus.getDefault().register(this);
}
项目:emerald
文件:Themer.java
public static void setWindowDecorations(Activity activity, SharedPreferences options) {
if (Build.VERSION.SDK_INT >= 21) {
activity.getWindow().setStatusBarColor(options.getInt(Keys.STATUS_BAR_BACKGROUND, 0x22000000));
activity.getWindow().setNavigationBarColor(options.getInt(Keys.NAV_BAR_BACKGROUND, 0x22000000));
} else {
activity.findViewById(R.id.dummy_top_view).setBackgroundColor(options.getInt(Keys.BAR_BACKGROUND, 0x22000000));
Display display = ((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
Point realSize = new Point();
display.getSize(size);
display.getRealSize(realSize);
int navBarHeight = size.y-realSize.y;
View dummyBottomView = activity.findViewById(R.id.dummy_bottom_view);
ViewGroup.LayoutParams p = dummyBottomView.getLayoutParams();
p.height = navBarHeight;
dummyBottomView.setLayoutParams(p);
if (navBarHeight > 0) {
dummyBottomView.setVisibility(View.VISIBLE);
dummyBottomView.setBackgroundColor(options.getInt(Keys.NAV_BAR_BACKGROUND, 0x22000000));
}
}
}
项目:DailyZhiHu
文件:SlidingMenu.java
/**
* Sets the behind width.
*
* @param i The width the Sliding Menu will open to, in pixels
*/
@SuppressWarnings("deprecation")
public void setBehindWidth(int i) {
int width;
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
try {
Class<?> cls = Display.class;
Class<?>[] parameterTypes = {Point.class};
Point parameter = new Point();
Method method = cls.getMethod("getSize", parameterTypes);
method.invoke(display, parameter);
width = parameter.x;
} catch (Exception e) {
width = display.getWidth();
}
setBehindOffset(width-i);
}
项目:Coder
文件:BaseFragment.java
@DoMain
public void showLoadingDialog(String msg) {
String content = null;
if (msg == null) {
content = "正在与服务器交互,请稍后.....";
} else {
content = msg;
}
View view = View.inflate(activity, R.layout.view_loading_dialog, null);
((TextView) view.findViewById(R.id.view_loading_dialog_desc)).setText(content);
alertDialog = new AlertDialog.Builder(activity)
.setView(view)
.create();
alertDialog.show();
WindowManager m = activity.getWindowManager();
Display d = m.getDefaultDisplay();
Window dialogWindow = alertDialog.getWindow();
WindowManager.LayoutParams p = dialogWindow.getAttributes();
p.width = (int) (d.getWidth() * 0.8);
dialogWindow.setAttributes(p);
}
项目:AndroidOCRFforID
文件:TransformImageView.java
/**
* This method calculates maximum size of both width and height of bitmap.
* It is the device screen diagonal for default implementation.
*
* @return - max bitmap size in pixels.
*/
@SuppressWarnings({"SuspiciousNameCombination", "deprecation"})
protected int calculateMaxBitmapSize() {
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
int width, height;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(size);
width = size.x*2;
height = size.y*2;
} else {
width = display.getWidth();
height = display.getHeight();
}
return (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
}
项目:ChemistryEasy
文件:OrdinaryTable.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.ordinary_table_layout, container, false);
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
x_size = (int) Math.floor((double)width / X_CROP);
y_size = (int) Math.floor((double)height / Y_CROP);
//calc of X margin
int x_margin = (width - x_size*18) /2;
view.setPadding(x_margin,x_margin,x_margin,x_margin);
Ui_init(view);
return view;
}
项目:QuranAndroid
文件:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen_main);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
//marshmallow check permission permissions
boolean hasPermission = (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
if (!hasPermission) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_WRITE_STORAGE);
} else {
validateFilesAndDownload();
}
}
项目:ChatExchange-old
文件:SlidingMenu.java
/**
* Sets the behind width.
*
* @param i The width the Sliding Menu will open to, in pixels
*/
@SuppressWarnings("deprecation")
public void setBehindWidth(int i)
{
int width;
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
try
{
Class<?> cls = Display.class;
Class<?>[] parameterTypes = {Point.class};
Point parameter = new Point();
Method method = cls.getMethod("getSize", parameterTypes);
method.invoke(display, parameter);
width = parameter.x;
}
catch (Exception e)
{
width = display.getWidth();
}
setBehindOffset(width - i);
}
项目:nightmode
文件:Utility.java
public static int getTrueScreenHeight(Context context) {
int dpi = 0;
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(dm);
dpi = dm.heightPixels;
} else {
try {
Class c = Class.forName("android.view.Display");
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
dpi = dm.heightPixels;
} catch (Exception e) {
e.printStackTrace();
}
}
return dpi;
}
项目:Selector
文件:QuickOptionDialog.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setGravity(Gravity.BOTTOM);
//getWindow().setNavigationBarColor(Color.TRANSPARENT);
WindowManager windowManager = getWindow().getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.width = display.getWidth();
getWindow().setAttributes(layoutParams);
mShare.setOnClickListener(this);
saveLocal.setOnClickListener(this);
collection.setOnClickListener(this);
// mPresent = new ImageBrowsePresenter(this);
}
项目:AirPanel
文件:MainActivity.java
public static Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else {
try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
return size;
}
项目:yyox
文件:UserPhoneActivity.java
/**
* 获得手机屏幕宽高
* @return
*/
public String getHeightAndWidth(){
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
//获得手机的宽带和高度像素单位为px
String str = "\n手机屏幕分辨率为1:" + dm.widthPixels
+" * "+ dm.heightPixels
+"\n手机屏幕分辨率为2:" + screenWidth
+" * "+ screenHeight;
return str;
}
项目:Hitalk
文件:CameraConfigurationManager.java
public void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
mScreenResolution = new Point(display.getWidth(), display.getHeight());
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = mScreenResolution.x;
screenResolutionForCamera.y = mScreenResolution.y;
// preview size is always something like 480*320, other 320*480
if (mScreenResolution.x < mScreenResolution.y) {
screenResolutionForCamera.x = mScreenResolution.y;
screenResolutionForCamera.y = mScreenResolution.x;
}
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
}
项目:PeSanKita-android
文件:ConversationPopupActivity.java
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 1.0f;
params.dimAmount = 0.1f;
params.gravity = Gravity.TOP;
getWindow().setAttributes(params);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
else getWindow().setLayout((int) (width * .7), (int) (height * .75));
super.onCreate(bundle, masterSecret);
titleView.setOnClickListener(null);
}
项目:redpacketui-open
文件:ADPacketFragment.java
private int getRealScreenHeight() {
int height = 0;
Display display = getActivity().getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
@SuppressWarnings("rawtypes")
Class c;
try {
c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
height = dm.heightPixels;
} catch (Exception e) {
e.printStackTrace();
}
return height;
}
项目:LuaViewPlayground
文件:CameraConfigurationManager.java
public void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point theScreenResolution = new Point();
theScreenResolution = getDisplaySize(display);
screenResolution = theScreenResolution;
Log.i(TAG, "Screen resolution: " + screenResolution);
/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
项目:YZxing
文件:CameraConfigurationManager.java
/**
* Reads, one time, values from the camera that are needed by the app.
*/
void initFromCameraParameters(OpenCamera camera) {
Camera.Parameters parameters = camera.getCamera().getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point theScreenResolution = new Point();
display.getSize(theScreenResolution);
screenResolution = theScreenResolution;
Log.i(TAG, "Screen resolution in current orientation: " + screenResolution);
cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Camera resolution: " + cameraResolution);
bestPreviewSize = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Best available preview size: " + bestPreviewSize);
}
项目:recyclviewpagger
文件:MainActivity.java
private DisplayMetrics getDisplayMetrics() {
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
return metrics;
}
项目:DailyStudy
文件:Measure.java
private static Point getAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
项目:Bella-Android
文件:MainActivity.java
public void checkForUpdate() {
//Check for update
new AppUpdater(this)
.setUpdateFrom(UpdateFrom.XML)
.setUpdateXML("https://raw.githubusercontent.com/Bella-Assistant/Bella-Android/alpha/update-changelog.xml")
.setTitleOnUpdateNotAvailable("Update not available")
.setContentOnUpdateNotAvailable("No update available. Check for updates again later!")
.setDisplay(com.github.javiersantos.appupdater.enums.Display.DIALOG)
.showAppUpdated(true)
.start();
}
项目:SmART-Form
文件:PictureUtils.java
/**
* Get a BitmapDrawable from a local file that is scaled down
* to fid the current Window size.
*/
@SuppressWarnings("deprecation")
public static BitmapDrawable getScaledDrawable(Activity a, String path) {
Log.d(TAG, "Inside getScaledDrawable()");
Display display = a.getWindowManager().getDefaultDisplay();
float destWidth = display.getWidth();
float destHeight = display.getHeight();
// Read in the dimensions of the image on disk
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
float srcWidth = options.outWidth;
float srcHeight = options.outHeight;
Log.d(TAG, "srcWidth: " + srcWidth);
Log.d(TAG, "srcHeight: " + srcHeight);
int inSampleSize = 1;
if( srcHeight > destHeight || srcWidth > destWidth) {
if(srcWidth > srcHeight){
inSampleSize = Math.round( srcHeight / destHeight );
}
else {
inSampleSize = Math.round(srcWidth / destWidth);
}
}
options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
Log.d(TAG, "inSampleSize: " + inSampleSize);
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return new BitmapDrawable(a.getResources(), bitmap);
}
项目:MeteorView
文件:Utils.java
public static int getScreenHeight(Context c) {
if (screenHeight == 0) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenHeight = size.y;
}
return screenHeight;
}
项目:FlickLauncher
文件:Launcher.java
private int mapConfigurationOriActivityInfoOri(int configOri) {
final Display d = getWindowManager().getDefaultDisplay();
int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
switch (d.getRotation()) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
// We are currently in the same basic orientation as the natural orientation
naturalOri = configOri;
break;
case Surface.ROTATION_90:
case Surface.ROTATION_270:
// We are currently in the other basic orientation to the natural orientation
naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
break;
}
int[] oriMap = {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
};
// Since the map starts at portrait, we need to offset if this device's natural orientation
// is landscape.
int indexOffset = 0;
if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
indexOffset = 1;
}
return oriMap[(d.getRotation() + indexOffset) % 4];
}
项目:GitHub
文件:App.java
public void getScreenSize() {
WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
Display display = windowManager.getDefaultDisplay();
display.getMetrics(dm);
DIMEN_RATE = dm.density / 1.0F;
DIMEN_DPI = dm.densityDpi;
SCREEN_WIDTH = dm.widthPixels;
SCREEN_HEIGHT = dm.heightPixels;
if (SCREEN_WIDTH > SCREEN_HEIGHT) {
int t = SCREEN_HEIGHT;
SCREEN_HEIGHT = SCREEN_WIDTH;
SCREEN_WIDTH = t;
}
}
项目:gmlrva
文件:ViewUtils.java
/**
* Procedure meant to provide the device's screen height in pixels.
* @param context the application's current {@link Context}.
* @return an Integer value representing the device's screen height, in pixels.
*/
@IntRange(from = 0) public static int getDeviceScreenHeight(@NonNull final Context context) {
synchronized (ViewUtils.class) {
if (sDeviceScreenHeight == 0) {
final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (windowManager != null) {
final Display display = windowManager.getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
sDeviceScreenHeight = size.y;
}
}
}
return sDeviceScreenHeight;
}
项目:GitHub
文件:FloatingActionsMenu.java
private void init(Context context, AttributeSet attributeSet) {
mAddButtonPlusColor = getColor(android.R.color.white);
mAddButtonColorNormal = getColor(android.R.color.holo_blue_dark);
mAddButtonColorPressed = getColor(android.R.color.holo_blue_light);
mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));
if (attributeSet != null) {
TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
if (attr != null) {
try {
mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_addButtonPlusIconColor, getColor(android.R.color.white));
mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
isHorizontal = attr.getBoolean(R.styleable.FloatingActionsMenu_addButtonIsHorizontal, false);
} finally {
attr.recycle();
}
}
}
WindowManager mWindowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
Display display = mWindowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(size);
mYHidden = size.y;
} else mYHidden = display.getHeight();
createAddButton(context);
}
项目:TimeSkyBackground
文件:SkyViewUtils.java
public static int getScreenWidth(Context c) {
WindowManager mWindowManager = (WindowManager)c.getSystemService(Context.WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
DisplayMetrics mMetrics = new DisplayMetrics();
mDisplay.getMetrics(mMetrics);
return mMetrics.widthPixels;
}