List of usage examples for android.view Display getHeight
@Deprecated public int getHeight()
From source file:im.neon.adapters.VectorMediasViewerAdapter.java
@SuppressLint("NewApi") private Point getDisplaySize() { Point size = new Point(); WindowManager w = ((Activity) mContext).getWindowManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { w.getDefaultDisplay().getSize(size); } else {//from w ww . j av a 2 s. c o m Display d = w.getDefaultDisplay(); size.x = d.getWidth(); size.y = d.getHeight(); } return size; }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
/** * Extract a photo from SkyDrive and creates a scaled bitmap according to the device resolution, this is needed to * prevent memory over-allocation that can cause some devices to crash when opening high-resolution pictures * * Note: this method should not be used for downloading photos, only for displaying photos on-screen * * @param photo The source photo to download * @param imageStream The stream that contains the photo * @return Scaled bitmap representation of the photo * @see http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966 *///from ww w. ja va 2 s . co m private Bitmap extractScaledBitmap(SkyDrivePhoto photo, InputStream imageStream) { Display display = getWindowManager().getDefaultDisplay(); int IMAGE_MAX_SIZE = Math.max(display.getWidth(), display.getHeight()); int scale = 1; if (photo.getHeight() > IMAGE_MAX_SIZE || photo.getWidth() > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math .ceil(Math.log(IMAGE_MAX_SIZE / (double) Math.max(photo.getHeight(), photo.getWidth())) / Math.log(0.5))); } BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inSampleSize = scale; return BitmapFactory.decodeStream(imageStream, (Rect) null, options); }
From source file:org.apache.cordova.splashscreen.SplashScreen.java
/** * Shows the splash screen over the full Activity *//*from w ww. j a va2 s . c o m*/ @SuppressWarnings("deprecation") private void showSplashScreen(final boolean hideAfterDelay) { final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000); final int drawableId = preferences.getInteger("SplashDrawableId", 0); // If the splash dialog is showing don't try to show it again if (splashDialog != null && splashDialog.isShowing()) { return; } if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { return; } cordova.getActivity().runOnUiThread(new Runnable() { public void run() { // Get reference to display Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); Context context = webView.getContext(); // Use an ImageView to render the image because of its flexible scaling options. splashImageView = new ImageView(context); splashImageView.setImageResource(drawableId); LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); splashImageView.setLayoutParams(layoutParams); splashImageView.setMinimumHeight(display.getHeight()); splashImageView.setMinimumWidth(display.getWidth()); // TODO: Use the background color of the webView's parent instead of using the preference. splashImageView.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK)); if (isMaintainAspectRatio()) { // CENTER_CROP scale mode is equivalent to CSS "background-size:cover" splashImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } else { // FIT_XY scales image non-uniformly to fit into image view. splashImageView.setScaleType(ImageView.ScaleType.FIT_XY); } // Create and show the dialog splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); // check to see if the splash screen should be full screen if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } splashDialog.setContentView(splashImageView); splashDialog.setCancelable(false); splashDialog.show(); // Set Runnable to remove splash screen just in case if (hideAfterDelay) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { removeSplashScreen(); } }, splashscreenTime); } } }); }
From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java
/** * Returns the screen dimensions as a Point. * * @return the screen dimensions.//from w w w .j av a2 s .c om */ private Point getScreenDim() { Display display = this.getWindowManager().getDefaultDisplay(); @SuppressWarnings("deprecation") Point size = new Point(display.getWidth(), display.getHeight()); return size; }
From source file:org.openqa.selendroid.server.model.DefaultSelendroidDriver.java
@Override @SuppressWarnings("deprecation") public byte[] takeScreenshot() { ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance(); // TODO ddary review later, but with getRecentDecorView() it seems to work better // long drawingTime = 0; // View container = null; // for (View view : viewAnalyzer.getTopLevelViews()) { // if (view != null && view.isShown() && view.hasWindowFocus() // && view.getDrawingTime() > drawingTime) { // container = view; // drawingTime = view.getDrawingTime(); // }//from www. j a va 2 s .co m // } // final View mainView = container; final View mainView = viewAnalyzer.getRecentDecorView(); if (mainView == null) { throw new SelendroidException("No open windows."); } done = false; long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis(); final byte[][] rawPng = new byte[1][1]; ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { Display display = serverInstrumentation.getCurrentActivity().getWindowManager() .getDefaultDisplay(); Point size = new Point(); try { display.getSize(size); } catch (NoSuchMethodError ignore) { // Older than api level 13 size.x = display.getWidth(); size.y = display.getHeight(); } // Get root view View view = mainView.getRootView(); // Create the bitmap to use to draw the screenshot final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); // Get current theme to know which background to use final Activity activity = serverInstrumentation.getCurrentActivity(); final Theme theme = activity.getTheme(); final TypedArray ta = theme .obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); final int res = ta.getResourceId(0, 0); final Drawable background = activity.getResources().getDrawable(res); // Draw background background.draw(canvas); // Draw views view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)) { throw new RuntimeException("Error while compressing screenshot image."); } try { stream.flush(); stream.close(); } catch (IOException e) { throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage()); } finally { Closeable closeable = (Closeable) stream; try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { // ignore } } rawPng[0] = stream.toByteArray(); mainView.destroyDrawingCache(); done = true; syncObject.notify(); } } }); waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot."); return rawPng[0]; }
From source file:com.undatech.opaque.RemoteCanvas.java
public RemoteCanvas(final Context context, AttributeSet attrSet) { super(context, attrSet); clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); final Display display = ((Activity) context).getWindow().getWindowManager().getDefaultDisplay(); displayWidth = display.getWidth();// ww w .j a va 2 s. co m displayHeight = display.getHeight(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); displayDensity = metrics.density; canvasZoomer = new CanvasZoomer(this); setScaleType(ImageView.ScaleType.MATRIX); if (android.os.Build.MODEL.contains("BlackBerry") || android.os.Build.BRAND.contains("BlackBerry") || android.os.Build.MANUFACTURER.contains("BlackBerry")) { bb = true; } }
From source file:me.wimanacra.collector.DisplayManagerCollector.java
@NonNull private JSONObject collectDisplayData(@NonNull Display display) throws JSONException { final DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);/* w ww . j av a 2 s .c o m*/ final JSONObject result = new JSONObject(); collectCurrentSizeRange(display, result); collectFlags(display, result); collectMetrics(display, result); collectRealMetrics(display, result); collectName(display, result); collectRealSize(display, result); collectRectSize(display, result); collectSize(display, result); collectRotation(display, result); collectIsValid(display, result); result.put("orientation", display.getRotation()).put("refreshRate", display.getRefreshRate()); //noinspection deprecation result.put("height", display.getHeight()).put("width", display.getWidth()).put("pixelFormat", display.getPixelFormat()); return result; }
From source file:com.makotosan.vimeodroid.vimeo.Methods.java
public MoogalXml getMoogalXml(String clipId, String userId, VideoQuality quality) { MoogalXml moogal = new MoogalXml(); Display display = ((WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay();/*from ww w . ja va 2 s. co m*/ String baseUrl = "http://vimeo.com/moogaloop/load/clip:" + clipId + "/local/?moog_width=" + display.getWidth() + "&moog_height=" + display.getHeight() + "&embed_location=¶m_server=vimeo.com¶m_force_embed=0¶m_multimoog=¶m_autoplay=1¶m_fullscreen=1¶m_md5=0¶m_force_info=undefined¶m_show_portrait=0¶m_show_title=0¶m_ver=39487¶m_show_byline=0¶m_context=user:" + userId + "¶m_clip_id=" + clipId + "¶m_color=00ADEF¶m_context_id=&context=user:" + userId; // Call it, and then we'll get XML final HttpGet request = new HttpGet(baseUrl); final HttpClient client = app.getHttpClient(); final ResponseHandler<String> handler = new BasicResponseHandler(); String finalUrl = ""; try { final String response = client.execute(request, handler); String requestSignature = ""; String requestSignatureExpires = ""; String embedCode = ""; final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); final XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new StringReader(response)); int eventType = xpp.getEventType(); String tagName = ""; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_TAG: tagName = xpp.getName(); break; case XmlPullParser.END_TAG: tagName = ""; break; case XmlPullParser.TEXT: if ("request_signature".equals(tagName)) { requestSignature = xpp.getText(); break; } if ("request_signature_expires".equals(tagName)) { requestSignatureExpires = xpp.getText(); break; } if ("embed_code".equals(tagName)) { embedCode = xpp.getText(); } break; } eventType = xpp.next(); } finalUrl = String.format( "http://vimeo.com/moogaloop/play/clip:%s/%s/%s/?q=%s&type=local&embed_location=", clipId, requestSignature, requestSignatureExpires, quality); moogal.setUrl(finalUrl); moogal.setEmbedCode(embedCode); moogal.setRequestSignature(requestSignature); moogal.setRequestSignatureExpires(requestSignatureExpires); // Log.d("GetMp4Url", "Playing video at " + finalUrl); } catch (Exception e) { e.printStackTrace(); } return moogal; // return finalUrl; }
From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java
private void enableParallaxEffect(ObservableScrollView scrollView, final View parallaxingView) { scrollView.setScrollViewListener(new ScrollViewListener() { @Override//from w w w. j a v a 2 s . com public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { WindowManager win = getWindowManager(); Display d = win.getDefaultDisplay(); int displayHeight = d.getHeight(); // Height of the actual device if (imageSize.getHeight() > displayHeight) { float[] values = new float[9]; photoViewAttacher.getDrawMatrix().getValues(values); float imageHeight = imageSize.getHeight(); float diff = imageHeight / displayHeight; if (y > oldy) { diff = -diff; } photoViewAttacher.onDrag(0, diff); } else { float pY = -(y / 3.0f); parallaxingView.setTranslationY(pY); } } }); }
From source file:org.navitproject.navit.Navit.java
/** * @brief Shows the native keyboard or other input method. * //www.j av a 2 s .c o m * @return {@code true} if an input method is going to be displayed, {@code false} if not */ public int showNativeKeyboard() { /* * Apologies for the huge mess that this function is, but Android's soft input API is a big * nightmare. Its devs have mercifully given us an option to show or hide the keyboard, but * there is no reliable way to figure out if it is actually showing, let alone how much of the * screen it occupies, so our best bet is guesswork. */ Configuration config = getResources().getConfiguration(); if ((config.keyboard == Configuration.KEYBOARD_QWERTY) && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)) /* physical keyboard present, exit */ return 0; /* Use SHOW_FORCED here, else keyboard won't show in landscape mode */ mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED); show_soft_keyboard_now_showing = true; /* * Crude way to estimate the height occupied by the keyboard: for AOSP on KitKat and Lollipop it * is about 62-63% of available screen width (in portrait mode) but no more than slightly above * 46% of height (in landscape mode). */ Display display_ = getWindowManager().getDefaultDisplay(); int width_ = display_.getWidth(); int height_ = display_.getHeight(); int maxHeight = height_ * 47 / 100; int inputHeight = width_ * 63 / 100; if (inputHeight > (maxHeight)) inputHeight = maxHeight; /* the receiver isn't going to fire before the UI thread becomes idle, well after this method returns */ Log.d(TAG, "showNativeKeyboard:return (assuming true)"); return inputHeight; }