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:io.lqd.sdk.model.LQDevice.java
@SuppressWarnings("deprecation") private static String getScreenSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int width = display.getWidth(); // deprecated int height = display.getHeight(); // deprecated return width + "x" + height; }
From source file:com.google.android.apps.santatracker.games.SplashActivity.java
@Override protected void onStart() { super.onStart(); // Orientation boolean gameIsLandscape = getIntent().getBooleanExtra(EXTRA_LANDSCAPE, false); boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); // Figure out how many degrees to rotate // Landscape always wants to be at 90degrees, portrait always wants to be at 0degrees float degreesToRotate = 0f; if (rotation == Surface.ROTATION_0) { degreesToRotate = gameIsLandscape && !isLandscape ? 90.0f : 0.0f; } else if (rotation == Surface.ROTATION_90) { degreesToRotate = gameIsLandscape && isLandscape ? 0f : -90f; } else if (rotation == Surface.ROTATION_180) { degreesToRotate = gameIsLandscape && !isLandscape ? -90f : -180f; } else if (rotation == Surface.ROTATION_270) { degreesToRotate = gameIsLandscape && isLandscape ? -180f : -270f; }//from w ww . j a v a 2s . c om // On a TV, should always be 0 if (isRunningOnTV()) { degreesToRotate = 0f; } // Rotate, if necessary if (degreesToRotate != 0) { Point size = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealSize(size); } else { display.getSize(size); } int w = size.x; int h = size.y; View mainLayout = findViewById(R.id.splash_layout); mainLayout.setRotation(degreesToRotate); mainLayout.setTranslationX((w - h) / 2); mainLayout.setTranslationY((h - w) / 2); ViewGroup.LayoutParams lp = mainLayout.getLayoutParams(); lp.height = w; lp.width = h; mainLayout.requestLayout(); } }
From source file:de.madvertise.android.sdk.MadView.java
/** * Constructor/*from ww w. j a va2s .c om*/ * * @param context * @param attrs */ public MadView(Context context, AttributeSet attrs) { super(context, attrs); MadUtil.logMessage(null, Log.DEBUG, "** Constructor for mad view called **"); setVisibility(INVISIBLE); if (context.checkCallingOrSelfPermission( android.Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) { MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); MadUtil.logMessage(null, Log.DEBUG, " *** Missing internet permissions! *** "); MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); throw new IllegalArgumentException(); } initParameters(attrs); Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); MadUtil.logMessage(null, Log.DEBUG, "Display values: Width = " + display.getWidth() + " ; Height = " + display.getHeight()); setGravity(Gravity.CENTER); initialBackground = this.getBackground(); Rect r = new Rect(0, 0, display.getWidth(), display.getHeight()); textBannerBackground = generateBackgroundDrawable(r, backgroundColor, 0xffffff); setClickable(true); setFocusable(true); setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); }
From source file:com.playhaven.android.req.PlayHavenRequest.java
@SuppressWarnings("deprecation") protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException { try {//from ww w .jav a 2s . co m SharedPreferences pref = PlayHaven.getPreferences(context); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer)); builder.path(context.getResources().getString(getApiPath(context))); builder.queryParam("app", getString(pref, AppPkg)); builder.queryParam("opt_out", getString(pref, OptOut, "0")); builder.queryParam("app_version", getString(pref, AppVersion)); builder.queryParam("os", getInt(pref, OSVersion, 0)); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); builder.queryParam("orientation", display.getRotation()); builder.queryParam("hardware", getString(pref, DeviceModel)); PlayHaven.ConnectionType connectionType = getConnectionType(context); builder.queryParam("connection", connectionType.ordinal()); builder.queryParam("idiom", context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK); /** * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically * account for rotation and screen decorations like the status bar. We only want to know available space. * * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth! */ Point size = new Point(); if (Build.VERSION.SDK_INT >= 13) { display.getSize(size); } else { size.x = display.getWidth(); size.y = display.getHeight(); } builder.queryParam("width", size.x); builder.queryParam("height", size.y); /** * SDK Version needs to be reported as a dotted numeric value * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build * IE: 2.0.0.20130201 * as opposed to an actual released build, which would be like 2.0.0 */ String sdkVersion = getString(pref, SDKVersion); String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]"); sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", "")); builder.queryParam("sdk_version", sdkVersion); builder.queryParam("plugin", getString(pref, PluginIdentifer)); Locale locale = context.getResources().getConfiguration().locale; builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage())); builder.queryParam("token", getString(pref, Token)); builder.queryParam("device", getString(pref, DeviceId)); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); builder.queryParam("dpi", metrics.densityDpi); String uuid = UUID.randomUUID().toString(); String nonce = base64Digest(uuid); builder.queryParam("nonce", nonce); ktsid = KontagentUtil.getSenderId(context); if (ktsid != null) builder.queryParam("sid", ktsid); addSignature(builder, pref, nonce); // Setup for signature verification String secret = getString(pref, Secret); SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC); sigMac = Mac.getInstance(HMAC); sigMac.init(key); sigMac.update(nonce.getBytes(UTF8)); return builder; } catch (Exception e) { throw new PlayHavenException(e); } }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
private AndroidApiService(Context context, Configuration config) { this.config = config; this.apiUrl = new ApiUrl(config); if (Logger.DEBUG) L.d("new ApiService()"); sdkVer = Build.VERSION.SDK;// w w w. j ava 2s. c o m sdkRel = Build.VERSION.RELEASE; try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); storeId = pi.packageName; clientVer = "" + pi.versionCode; } catch (NameNotFoundException e) { } TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId(); macAddress = NetworkUtils.getDeviceMacAddress(context); subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId(); simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); try { Class<Display> cls = Display.class; Method method = cls.getMethod("getRotation"); Object retobj = method.invoke(display); int rotation = Integer.parseInt(retobj.toString()); if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } else { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } } catch (Exception e) { if (display.getOrientation() == 1) { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } else { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } } SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // token = pref.getString(PREF_KEY_TOKEN, ""); // uid = pref.getString(PREF_KEY_UID, ""); // userId = pref.getString(PREF_KEY_USER_ID, ""); appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0); // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true); // ??SIM? String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0"); String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0"); if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) { if (Logger.DEBUG) L.d("Change SIM card."); cleanCredential(context); } this.getCredential(context); }
From source file:com.android.fastergallery.ui.TileImageView.java
public static boolean isHighResolution(Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels > 2048 || metrics.widthPixels > 2048; }
From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java
@SuppressWarnings("deprecation") @Override//ww w .ja v a 2s. c om public void onCreate() { created = true; settings = new RecSettings(); settings.load(getApplicationContext(), PreferenceManager.getDefaultSharedPreferences(getApplicationContext())); createNotification(NOTIFICATION_ID); if (settings.isSchedRecEnabled() && settings.getSchedRecTime() > System.currentTimeMillis() + 10000) { AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplicationContext(), ScheduleReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); alarmMgr.set(AlarmManager.RTC_WAKEUP, settings.getSchedRecTime(), alarmIntent); stopSelf(); return; } // Create new SurfaceView, set its size to 1x1, move // it to the top left corner and set this service as a callback WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE); surfaceView = new SurfaceView(this); // deprecated setting, but required on Android versions prior to 3.0 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); surfaceView.getHolder().addCallback(this); LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); layoutParams.gravity = Gravity.LEFT | Gravity.TOP; winMgr.addView(surfaceView, layoutParams); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.setReferenceCounted(false); wakeLock.acquire(); }
From source file:cn.edu.sdu.online.activity.FragmentTabsPager.java
private void createView() { floatView = new FloatView(getApplicationContext()); floatView.setOnClickListener(new imageviewListener()); floatView.setImageResource(R.drawable.releasetask); windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); windowManagerParams = ((FloatApplication) getApplication()).getWindowParams(); windowManagerParams.type = LayoutParams.TYPE_PHONE; windowManagerParams.format = PixelFormat.RGBA_8888; windowManagerParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE; windowManagerParams.gravity = Gravity.LEFT | Gravity.TOP; windowManagerParams.x = 8;/*from w ww.j av a 2s .co m*/ windowManagerParams.y = height - 260; windowManagerParams.width = LayoutParams.WRAP_CONTENT; windowManagerParams.height = LayoutParams.WRAP_CONTENT; windowManager.addView(floatView, windowManagerParams); }
From source file:com.zzisoo.toylibrary.adapter.ToyListAdapter.java
private void setItemSize(View v) { Context c = v.getContext();//from ww w . j a va2 s.c o m WindowManager wm = (WindowManager) v.getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int x = display.getWidth(); int y = display.getHeight(); int nwidth = x; if (Config.isLandscape(c)) { ((TextView) v.findViewById(R.id.tvToyTitle)).setMaxLines(Config.TITLE_MAX_LINE_LANDSCAPE); nwidth = x > y ? x : y; } else { ((TextView) v.findViewById(R.id.tvToyTitle)).setMaxLines(Config.TITLE_MAX_LINE_PORTRAIT); nwidth = x < y ? x : y; } int nItemPerWidth = nwidth / Config.getSpans(c); Log.e(TAG, ">>>" + x + "/" + y + " -->" + nItemPerWidth); v.findViewById(R.id.imageview_Background) .setLayoutParams(new LinearLayout.LayoutParams(nItemPerWidth, nItemPerWidth)); }
From source file:com.blueverdi.rosietheriveter.SitesFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { thisFragment = this; setRetainInstance(false);/*www . j a v a2s. c o m*/ myTour = new MySqliteHelperMyTour(getActivity()); networkAvailable = Utils.isNetworkAvailable(getActivity()); buildSitesList(); view = inflater.inflate(R.layout.sites_fragment, container, false); viewContainer = (LinearLayout) view.findViewById(R.id.view_container); RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup1); // implementation without nested fragments // first initialize the gallery view // --------------------------------- listLayout = (LinearLayout) inflater.inflate(R.layout.site_gallery_view, viewContainer, false); Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int rotation = display.getRotation(); switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: portrait = true; arrayLayout = R.layout.site_portrait; break; case Surface.ROTATION_90: case Surface.ROTATION_270: portrait = false; arrayLayout = R.layout.site_landscape; break; } // now initialize the map view // -------------------------- mapLayout = (LinearLayout) inflater.inflate(R.layout.site_map_view, viewContainer, false); try { MapsInitializer.initialize(this.getActivity()); } catch (Exception e) { e.printStackTrace(); } mapView = (MapView) mapLayout.findViewById(R.id.siteMap); mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { map = googleMap; map.getUiSettings().setMyLocationButtonEnabled(false); if (!networkAvailable) { Toast.makeText(thisFragment.getActivity(), thisFragment.getActivity().getString(R.string.internet_required), Toast.LENGTH_LONG) .show(); } // map.setMyLocationEnabled(true); // CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0); // map.animateCamera(cameraUpdate); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SITES, 0); if (networkAvailable) { map.animateCamera(cameraUpdate); } else { map.moveCamera(cameraUpdate); } markers = new HashMap<String, Site>(); for (Site s : sites) { LatLng ll = new LatLng(Double.parseDouble(s.getString(Site.LATITUDE)), Double.parseDouble(s.getString(Site.LONGITUDE))); Marker marker = map.addMarker(new MarkerOptions().position(ll).title(s.getString(Site.NAME))); markers.put(marker.getId(), s); } map.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { Site s = markers.get(marker.getId()); Intent i = new Intent(getActivity(), SiteActivity.class); i.putExtra(Site.PARCEL_NAME, s); SiteDetails sd = s.getDetails(); if (sd != null) { i.putExtra(SiteDetails.PARCEL_NAME, sd); } startActivity(i); getActivity().overridePendingTransition(R.anim.zoom_in, 0); return true; } }); } }); try { container.removeAllViews(); } catch (Exception e) { MyLog.d(TAG, "container evaporated inside onCreateView"); return view; } if (startInMapView) { RadioButton rb = (RadioButton) view.findViewById(R.id.radioMapView); rb.setChecked(true); setMap(); } else { setGallery(); } radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.radioListView) { setGallery(); } else { Toast.makeText(getActivity(), getString(R.string.getting_map), Toast.LENGTH_LONG).show(); setMap(); } } }); return view; }