List of usage examples for android.content Context WINDOW_SERVICE
String WINDOW_SERVICE
To view the source code for android.content Context WINDOW_SERVICE.
Click Source Link
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String GetRotationInfo() { WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE); int nRotationDegrees = 0; // default switch (wMgr.getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: nRotationDegrees = 90;/*from ww w .j a va 2s .com*/ break; case Surface.ROTATION_180: nRotationDegrees = 180; break; case Surface.ROTATION_270: nRotationDegrees = 270; break; } return "ROTATION:" + nRotationDegrees; }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Gets the device screen size in pixels. * /*from w ww . ja va 2 s .c o m*/ * @param context * @return */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Point device_screenSize(Context context) { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); final Point size = new Point(); try { display.getSize(size); } catch (NoSuchMethodError ignore) { // Older device size.x = display.getWidth(); size.y = display.getHeight(); } return size; }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static DisplayMetrics device_screenMetrics(Context context) { DisplayMetrics metrics = new DisplayMetrics(); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); display.getMetrics(metrics);//from w w w.ja v a 2 s. com //display.getRealMetrics(metrics); return metrics; }
From source file:org.chromium.android_webview.test.AwSettingsTest.java
@SmallTest @Feature({ "AndroidWebView", "Preferences" }) public void testSetInitialScale() throws Throwable { final TestAwContentsClient contentClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentClient); final AwContents awContents = testContainerView.getAwContents(); final AwSettings awSettings = getAwSettingsOnUiThread(awContents); CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper(); WindowManager wm = (WindowManager) getInstrumentation().getTargetContext() .getSystemService(Context.WINDOW_SERVICE); Point screenSize = new Point(); wm.getDefaultDisplay().getSize(screenSize); // Make sure after 50% scale, page width still larger than screen. int height = screenSize.y * 2 + 1; int width = screenSize.x * 2 + 1; final String page = "<html><body>" + "<p style='height:" + height + "px;width:" + width + "px'>" + "testSetInitialScale</p></body></html>"; final float defaultScale = getInstrumentation().getTargetContext().getResources() .getDisplayMetrics().density; assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f); loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f); int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount(); awSettings.setInitialPageScale(50);/*from w w w . ja va 2 s.c o m*/ loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount); assertEquals(0.5f, getPixelScaleOnUiThread(awContents), .01f); onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount(); awSettings.setInitialPageScale(500); loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount); assertEquals(5.0f, getPixelScaleOnUiThread(awContents), .01f); onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount(); awSettings.setInitialPageScale(0); loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount); assertEquals(defaultScale, getPixelScaleOnUiThread(awContents), .01f); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Returns the device resolution type./* w w w. j a va2 s . c o m*/ * * @param context * @return {@link es.javocsoft.android.lib.toolbox.ToolBox.DEVICE_RESOLUTION_TYPE} */ public static DEVICE_RESOLUTION_TYPE device_getResolutionType(Context context) { DEVICE_RESOLUTION_TYPE res = null; DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); switch (metrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: res = DEVICE_RESOLUTION_TYPE.ldpi; break; case DisplayMetrics.DENSITY_MEDIUM: res = DEVICE_RESOLUTION_TYPE.mdpi; break; case DisplayMetrics.DENSITY_HIGH: res = DEVICE_RESOLUTION_TYPE.hdpi; break; case DisplayMetrics.DENSITY_XHIGH: res = DEVICE_RESOLUTION_TYPE.xhdpi; break; case DisplayMetrics.DENSITY_XXHIGH: res = DEVICE_RESOLUTION_TYPE.xxhdpi; break; } return res; }
From source file:com.android.mms.ui.MessageUtils.java
public static int calculateWallpaperSize(Context context, int height, int width) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int currentMaxHeight = windowManager.getDefaultDisplay().getHeight(); int currentMaxWidth = windowManager.getDefaultDisplay().getWidth(); MmsLog.d(TAG, "CurrentMaxHeight = " + currentMaxHeight + " CurrentMaxWidth = " + currentMaxWidth); int ratio = 1; while ((height / ratio) > currentMaxHeight || (width / ratio) > currentMaxWidth) { ratio *= 2;// w w w . j a v a2 s. c o m } return ratio; }
From source file:carnero.cgeo.original.libs.Base.java
public void storeCache(App app, Activity activity, Cache cache, String geocode, int listId, Handler handler) { try {/*from ww w.j a v a 2 s . com*/ // cache details if (cache != null) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", cache.geocode); final Long searchId = searchByGeocode(params, listId, false); cache = app.getCache(searchId); } else if (geocode != null) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", geocode); final Long searchId = searchByGeocode(params, listId, false); cache = app.getCache(searchId); } if (cache == null) { if (handler != null) { handler.sendMessage(new Message()); } return; } final HtmlImg imgGetter = new HtmlImg(activity, settings, cache.geocode, false, listId, true); // store images from description if (cache.description != null) { Html.fromHtml(cache.description, imgGetter, null); } // store spoilers if (cache.spoilers != null && cache.spoilers.isEmpty() == false) { for (Spoiler oneSpoiler : cache.spoilers) { imgGetter.getDrawable(oneSpoiler.url); } } // store map previews if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) { final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude); final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); final int maxWidth = display.getWidth() - 25; final int maxHeight = display.getHeight() - 25; int edge = 0; if (maxWidth > maxHeight) { edge = maxWidth; } else { edge = maxHeight; } String type = "mystery"; if (cache.found == true) { type = cache.type + "_found"; } else if (cache.disabled == true) { type = cache.type + "_disabled"; } else { type = cache.type; } final String markerUrl = urlencode_rfc3986( "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png"); final StringBuilder waypoints = new StringBuilder(); if (cache.waypoints != null && cache.waypoints.size() > 0) { for (Waypoint waypoint : cache.waypoints) { if (waypoint.latitude == null && waypoint.longitude == null) { continue; } waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_"); waypoints.append(waypoint.type); waypoints.append(".png%7C"); waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude)); waypoints.append(","); waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude)); } } // download map images in separate background thread for higher performance final String code = cache.geocode; final int finalEdge = edge; Thread staticMapsThread = new Thread("getting static map") { @Override public void run() { MapImg mapGetter = new MapImg(settings, code); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 1); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 2); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 3); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 4); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 5); } }; staticMapsThread.setPriority(Thread.MIN_PRIORITY); staticMapsThread.start(); } app.markStored(cache.geocode, listId); app.removeCacheFromCache(cache.geocode); if (handler != null) { handler.sendMessage(new Message()); } } catch (Exception e) { Log.e(Settings.tag, "cgBase.storeCache: " + e.toString()); } }
From source file:android.app.Activity.java
final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token, int ident, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances, Configuration config) { attachBaseContext(context);/* ww w . j a v a 2 s . c om*/ mFragments.attachActivity(this, mContainer, null); mWindow = PolicyManager.makeNewWindow(this); mWindow.setCallback(this); mWindow.getLayoutInflater().setPrivateFactory(this); if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { mWindow.setSoftInputMode(info.softInputMode); } if (info.uiOptions != 0) { mWindow.setUiOptions(info.uiOptions); } mUiThread = Thread.currentThread(); mMainThread = aThread; mInstrumentation = instr; mToken = token; mIdent = ident; mApplication = application; mIntent = intent; mComponent = intent.getComponent(); mActivityInfo = info; mTitle = title; mParent = parent; mEmbeddedID = id; mLastNonConfigurationInstances = lastNonConfigurationInstances; mWindow.setWindowManager((WindowManager) context.getSystemService(Context.WINDOW_SERVICE), mToken, mComponent.flattenToString(), (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0); if (mParent != null) { mWindow.setContainer(mParent.getWindow()); } mWindowManager = mWindow.getWindowManager(); mCurrentConfig = config; }
From source file:carnero.cgeo.cgBase.java
public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId, Handler handler) {// ww w. jav a 2 s .co m try { // cache details if (cache != null) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", cache.geocode); final Long searchId = searchByGeocode(params, listId, false); cache = app.getCache(searchId); } else if (geocode != null) { final HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", geocode); final Long searchId = searchByGeocode(params, listId, false); cache = app.getCache(searchId); } if (cache == null) { if (handler != null) { handler.sendMessage(new Message()); } return; } final cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, cache.geocode, false, listId, true); // store images from description if (cache.description != null) { Html.fromHtml(cache.description, imgGetter, null); } // store spoilers if (cache.spoilers != null && cache.spoilers.isEmpty() == false) { for (cgSpoiler oneSpoiler : cache.spoilers) { imgGetter.getDrawable(oneSpoiler.url); } } // store map previews if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) { final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude); final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); final int maxWidth = display.getWidth() - 25; final int maxHeight = display.getHeight() - 25; int edge = 0; if (maxWidth > maxHeight) { edge = maxWidth; } else { edge = maxHeight; } String type = "mystery"; if (cache.found == true) { type = cache.type + "_found"; } else if (cache.disabled == true) { type = cache.type + "_disabled"; } else { type = cache.type; } final String markerUrl = urlencode_rfc3986( "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png"); final StringBuilder waypoints = new StringBuilder(); if (cache.waypoints != null && cache.waypoints.size() > 0) { for (cgWaypoint waypoint : cache.waypoints) { if (waypoint.latitude == null && waypoint.longitude == null) { continue; } waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_"); waypoints.append(waypoint.type); waypoints.append(".png%7C"); waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude)); waypoints.append(","); waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude)); } } // download map images in separate background thread for higher performance final String code = cache.geocode; final int finalEdge = edge; Thread staticMapsThread = new Thread("getting static map") { @Override public void run() { cgMapImg mapGetter = new cgMapImg(settings, code); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 1); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size=" + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 2); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 3); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 4); mapGetter.getDrawable( "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size=" + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false", 5); } }; staticMapsThread.setPriority(Thread.MIN_PRIORITY); staticMapsThread.start(); } app.markStored(cache.geocode, listId); app.removeCacheFromCache(cache.geocode); if (handler != null) { handler.sendMessage(new Message()); } } catch (Exception e) { Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString()); } }