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.i370.ui.view.PagerSlidingTabStrip.java
private void scrollToChild(int position, int offset) { // System.out.println("=====scrollToChild pos="+position+" offset="+offset); if (tabCount == 0) { return;/* w w w . j a v a 2 s . c om*/ } int newScrollX = tabsContainer.getChildAt(position).getLeft() + offset; int[] location = new int[2]; tabsContainer.getChildAt(position).getLocationOnScreen(location); // System.out.println("local x="+location[0]+"; y="+location[1]); WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); int scWidth = manager.getDefaultDisplay().getWidth(); if (click2ScrollPage) {//itempage //?item??? if (location[0] < 0 || location[0] + tabsContainer.getChildAt(position).getWidth() > scWidth) { newScrollX -= scrollOffset; scrollTo(newScrollX, 0); //System.out.println("click2ScrollPage scrollTo x="+newScrollX); } } else { if (position > 0 || offset > 0) { newScrollX -= scrollOffset; } if (newScrollX != lastScrollX) { lastScrollX = newScrollX; scrollTo(newScrollX, 0); // System.out.println("scrollTo x="+newScrollX); } } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override protected void firstPassLoadOnUiThread() { final FrameLayout.LayoutParams wrapperLP = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);//from w w w .j a v a 2 s. c o m final SwimmingFragment that = this; scoreView = getScoreView(); pauseView = getPauseView(); int diveViewBottomMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_bottom); int diveViewStartMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_left); int diveViewSize = (int) context.getResources().getDimension(R.dimen.dive_image_size); FrameLayout.LayoutParams diveViewLP = new LayoutParams(diveViewSize, diveViewSize); diveViewLP.setMargins(diveViewStartMargin, 0, 0, diveViewBottomMargin); diveViewLP.gravity = Gravity.BOTTOM | Gravity.LEFT; if (VERSION.SDK_INT >= 17) { diveViewLP.setMarginStart(diveViewStartMargin); } diveView = new DiveView(context); countdownView = new TextView(context); countdownView.setGravity(Gravity.CENTER); countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow)); countdownView.setTypeface(Typeface.DEFAULT_BOLD); countdownView.setText("0"); countdownView.setVisibility(View.INVISIBLE); Locale locale = context.getResources().getConfiguration().locale; countdownView.setText(NumberFormat.getInstance(locale).format(3)); Point screenDimens = AndroidUtils.getScreenSize(); UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10); LinearLayout gameView = new LinearLayout(context); gameView.setOrientation(LinearLayout.VERTICAL); // Add game view. swimmingView = new SwimmingView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 7); gameView.addView(swimmingView, lp); if (editorMode) { LinearLayout buttonWrapper = new LinearLayout(context); buttonWrapper.setOrientation(LinearLayout.HORIZONTAL); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); gameView.addView(buttonWrapper, lp); resetButton = getButton(R.string.reset_level, new OnClickListener() { @Override public void onClick(View v) { SwimmingModel level = levelManager.loadDefaultLevel(); initializeLevel(level, false); getActivity().getSharedPreferences(context.getString(R.string.swimming), Context.MODE_PRIVATE) .edit().putString(CURRENT_LEVEL_KEY, null).commit(); } }); deleteButton = getButton(R.string.delete_levels, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new DeleteLevelDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "delete"); } }); loadButton = getButton(R.string.load_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new LoadLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "load"); } }); saveButton = getButton(R.string.save_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new SaveLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "save"); } }); collisionModeButton = new ToggleButton(context); collisionModeButton.setText(R.string.scenery_mode); collisionModeButton.setTextOff(context.getString(R.string.scenery_mode)); collisionModeButton.setTextOn(context.getString(R.string.collision_mode)); collisionModeButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.collisionMode = isChecked; } }); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); buttonWrapper.addView(deleteButton, lp); buttonWrapper.addView(resetButton, lp); buttonWrapper.addView(loadButton, lp); buttonWrapper.addView(saveButton, lp); buttonWrapper.addView(collisionModeButton, lp); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometerSensor == null) { // TODO: The game won't be playable without this, so what should we do? Log.d(TAG, "Accelerometer sensor is null"); } displayRotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); wrapper.addView(gameView, 0, wrapperLP); wrapper.addView(countdownView, 1); wrapper.addView(diveView, 2, diveViewLP); wrapper.addView(scoreView, 3); wrapper.addView(pauseView, 4); }
From source file:com.farmerbb.secondscreen.util.U.java
public static boolean runSizeCommand(Context context, String requestedRes) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); disp.getRealMetrics(metrics);//from w w w . j a v a2 s .co m SharedPreferences prefMain = getPrefMain(context); String currentRes = " "; String nativeRes; if (prefMain.getBoolean("landscape", false)) nativeRes = Integer.toString(prefMain.getInt("height", 0)) + "x" + Integer.toString(prefMain.getInt("width", 0)); else nativeRes = Integer.toString(prefMain.getInt("width", 0)) + "x" + Integer.toString(prefMain.getInt("height", 0)); if (prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); currentRes = prefCurrent.getString("size", "reset"); if ("reset".equals(currentRes)) currentRes = nativeRes; } else { if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.widthPixels) + "x" + Integer.toString(metrics.heightPixels); } else if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.heightPixels) + "x" + Integer.toString(metrics.widthPixels); } } if (requestedRes.equals("reset")) requestedRes = nativeRes; return !requestedRes.equals(currentRes); }
From source file:de.madvertise.android.sdk.MadView.java
/** * Starts a background thread to fetch a new ad. Method is called * from the refresh timer task//ww w. j av a2 s .c o m */ private void requestNewAd() { MadUtil.logMessage(null, Log.DEBUG, "Trying to fetch a new ad"); // exit if already requesting a new ad, not used yet if (runningRefreshAd) { MadUtil.logMessage(null, Log.DEBUG, "Another request is still in progress ..."); return; } new Thread() { public void run() { // read all parameters, that we need for the request // get site token from manifest xml file String siteToken = MadUtil.getToken(getContext()); if (siteToken == null) { siteToken = ""; MadUtil.logMessage(null, Log.DEBUG, "Cannot show ads, since the appID ist null"); } else { MadUtil.logMessage(null, Log.DEBUG, "appID = " + siteToken); } // get uid (does not work in emulator) String uid = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID); if (uid == null) { uid = ""; } else { uid = getMD5Hash(uid); } MadUtil.logMessage(null, Log.DEBUG, "uid = " + uid); // get display metrics Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int displayHeight = display.getHeight(); int displayWidth = display.getWidth(); MadUtil.logMessage(null, Log.DEBUG, "Display height = " + Integer.toString(displayHeight)); MadUtil.logMessage(null, Log.DEBUG, "Display width = " + Integer.toString(displayWidth)); // create post request HttpPost postRequest = new HttpPost(MadUtil.MAD_SERVER + "/site/" + siteToken); postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); List<NameValuePair> parameterList = new ArrayList<NameValuePair>(); parameterList.add(new BasicNameValuePair("ua", MadUtil.getUA())); parameterList.add(new BasicNameValuePair("app", "true")); parameterList.add(new BasicNameValuePair("debug", Boolean.toString(testMode))); parameterList.add(new BasicNameValuePair("ip", MadUtil.getLocalIpAddress())); parameterList.add(new BasicNameValuePair("format", "json")); parameterList.add(new BasicNameValuePair("requester", "android_sdk")); parameterList.add(new BasicNameValuePair("version", "1.1")); parameterList.add(new BasicNameValuePair("uid", uid)); parameterList.add(new BasicNameValuePair("banner_type", bannerType)); parameterList.add(new BasicNameValuePair("deliver_only_text", Boolean.toString(deliverOnlyText))); MadUtil.refreshCoordinates(getContext()); if (MadUtil.getLocation() != null) { parameterList.add( new BasicNameValuePair("lat", Double.toString(MadUtil.getLocation().getLatitude()))); parameterList.add( new BasicNameValuePair("lng", Double.toString(MadUtil.getLocation().getLongitude()))); } UrlEncodedFormEntity urlEncodedEntity = null; try { urlEncodedEntity = new UrlEncodedFormEntity(parameterList); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } postRequest.setEntity(urlEncodedEntity); MadUtil.logMessage(null, Log.DEBUG, "Post request created"); MadUtil.logMessage(null, Log.DEBUG, "Uri : " + postRequest.getURI().toASCIIString()); MadUtil.logMessage(null, Log.DEBUG, "All headers : " + MadUtil.getAllHeadersAsString(postRequest.getAllHeaders())); MadUtil.logMessage(null, Log.DEBUG, "All request parameters :" + MadUtil.printRequestParameters(parameterList)); synchronized (this) { // send blocking request to ad server HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse = null; InputStream inputStream = null; boolean jsonFetched = false; JSONObject json = null; try { HttpParams clientParams = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(clientParams, MadUtil.CONNECTION_TIMEOUT.intValue()); HttpConnectionParams.setSoTimeout(clientParams, MadUtil.CONNECTION_TIMEOUT.intValue()); MadUtil.logMessage(null, Log.DEBUG, "Sending request"); httpResponse = httpClient.execute(postRequest); MadUtil.logMessage(null, Log.DEBUG, "Response Code => " + httpResponse.getStatusLine().getStatusCode()); if (testMode) MadUtil.logMessage(null, Log.DEBUG, "Madvertise Debug Response: " + httpResponse.getLastHeader("X-Madvertise-Debug")); int responseCode = httpResponse.getStatusLine().getStatusCode(); HttpEntity entity = httpResponse.getEntity(); if (responseCode == 200 && entity != null) { inputStream = entity.getContent(); String resultString = MadUtil.convertStreamToString(inputStream); MadUtil.logMessage(null, Log.DEBUG, "Response => " + resultString); json = new JSONObject(resultString); jsonFetched = true; } } catch (ClientProtocolException e) { e.printStackTrace(); MadUtil.logMessage(null, Log.DEBUG, "Error in HTTP request / protocol"); } catch (IOException e) { e.printStackTrace(); MadUtil.logMessage(null, Log.DEBUG, "Could not receive a http response on an ad reqeust"); } catch (JSONException e) { e.printStackTrace(); MadUtil.logMessage(null, Log.DEBUG, "Could not parse json object"); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { } } // create ad, this is a blocking call if (jsonFetched) { currentAd = new Ad(getContext(), json); } } mHandler.post(mUpdateResults); } }.start(); }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@SuppressLint("NewApi") public static int getWidth(Context mContext) { int width = 0; WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size);//from w w w . java 2 s . com width = size.x; } else { width = display.getWidth(); // Deprecated } return width; }
From source file:flex.android.magiccube.activity.ActivityBattleMode.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mode_battle); btMoveBack = (ImageButton) findViewById(R.id.bt_battle_moveback); btMoveForward = (ImageButton) findViewById(R.id.bt_battle_moveforward); btStartOb = (ImageButton) findViewById(R.id.bt_battle_startob); clock = (ImageView) findViewById(R.id.img_battle_clock); txtTime = (TextView) findViewById(R.id.txt_battle_time); txtNStep = (TextView) findViewById(R.id.txt_battle_nStep); img_nstep = (ImageView) findViewById(R.id.img_battle_nstep); progress = (SeekBar) findViewById(R.id.sbar_battle_timer); /*//from w w w . ja va 2s. co m * clock.setVisibility(View.VISIBLE); * btMoveForward.setVisibility(View.VISIBLE); * btMoveBack.setVisibility(View.VISIBLE); */ glView = (ViewBattleMode) findViewById(R.id.game_view_battle); glView.SetOnTimerListener(this); // glView.setOnStateListener(this); glView.SetOnStepListener(this); glView.SetMessageSender(this); glView.SetDrawCube(false); glView.setOnStateListener(this); glView2 = (ViewBattleMode) findViewById(R.id.game_view_battle2); glView2.SetCanMove(false); btMoveBack.setOnClickListener(buttonListener); btMoveForward.setOnClickListener(buttonListener); btStartOb.setOnClickListener(buttonListener); float fontsize = 25.f; Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Angies New House.ttf"); txtTime.setTypeface(typeFace); txtTime.setTextColor(Color.GRAY); txtTime.setTextSize(fontsize); txtNStep.setTypeface(typeFace); txtNStep.setTextColor(Color.GRAY); txtNStep.setTextSize(fontsize); State = OnStateListener.NONE; BgVolume = MagiccubePreference.GetPreference(MagiccubePreference.BgVolume, this); LinearBgVolume = MusicPlayThread.GetLinearVolume(BgVolume); GamingbgmPlayer = MediaPlayer.create(this, R.raw.bg2); ObservingbgmPlayer = MediaPlayer.create(this, R.raw.bg); FinishbgmPlayer = MediaPlayer.create(this, R.raw.finish); GamingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); ObservingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); FinishbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); Init(); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "...", Toast.LENGTH_LONG).show(); finish(); return; } WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); width = wm.getDefaultDisplay().getWidth(); height = wm.getDefaultDisplay().getHeight(); layout_moveforward = (LinearLayout) findViewById(R.id.layout_battle_moveforward); layout_moveback = (LinearLayout) findViewById(R.id.layout_battle_moveback); int buttonwidth = width / 5; int buttonheight = height / 13; LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(buttonwidth, buttonheight); btMoveForward.setLayoutParams(parms); btMoveBack.setLayoutParams(parms); layout_moveforward.setPadding(width / 2 - buttonwidth / 2, height - buttonheight, 0, 0); layout_moveback.setPadding(width / 15, height - buttonheight, 0, 0); }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@SuppressLint("NewApi") public static int getHeight(Context mContext) { int height = 0; WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size);/*from www.j a v a 2s.c om*/ height = size.y; } else { height = display.getHeight(); // Deprecated } return height; }
From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java
private boolean dispatchCenterWrapperTouchEvent(MotionEvent event) { Log.d(TAG, "dispatchCenterWrapperTouchEvent " + event); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); DisplayMetrics screen = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(screen); if (mSurfaceYDisplayRange == 0) { mSurfaceYDisplayRange = Math.min(screen.widthPixels, screen.heightPixels); }//from w w w.j a va 2s .co m float x_changed, y_changed; if (touchX != -1f && touchY != -1f) { y_changed = event.getRawY() - touchY; x_changed = event.getRawX() - touchX; } else { x_changed = 0f; y_changed = 0f; } // Log.e("tag","x_c=" + x_changed + "screen_x =" + screen.xdpi +" screen_rawx" + event.getRawX()); float coef = Math.abs(y_changed / x_changed); float xgesturesize = (((event.getRawX() - touchX) / screen.xdpi) * 2.54f);//2.54f float delta_y = Math.max(1f, (Math.abs(mInitTouchY - event.getRawY()) / screen.xdpi + 0.5f) * 2f); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchAction = TOUCH_NONE; touchX = event.getRawX(); mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); touchY = mInitTouchY = event.getRawY(); break; case MotionEvent.ACTION_MOVE: if (mTouchAction != TOUCH_SEEK && coef > 2) { if (Math.abs(y_changed / mSurfaceYDisplayRange) < 0.05) { return false; } touchX = event.getRawX(); touchY = event.getRawY(); if (activity == null) { if ((int) touchX > (4 * screen.widthPixels / 7)) { doVolumeTouch(y_changed); // hideCenterInfo(); // hideOverlay(true); } // Brightness (Up or Down - Left side) if ((int) touchX < (3 * screen.widthPixels / 7)) { doBrightnessTouch(y_changed); } } else { if (!activity.swap && activity.left.getVisibility() == View.VISIBLE && activity.right.getVisibility() == View.VISIBLE) { if ((int) touchX > (3 * screen.widthPixels / 4)) { doVolumeTouch(y_changed); // hideCenterInfo(); // hideOverlay(true); } // Brightness (Up or Down - Left side) else if ((int) touchX >= (2 * screen.widthPixels / 4)) { doBrightnessTouch(y_changed); } } else { if ((int) touchX < (1 * screen.widthPixels / 4)) { doBrightnessTouch(y_changed); // hideCenterInfo(); // hideOverlay(true); } // Brightness (Up or Down - Left side) else if ((int) touchX < (2 * screen.widthPixels / 4)) { doVolumeTouch(y_changed); } } } } else { doSeekTouch(Math.round(delta_y), xgesturesize, false); } break; case MotionEvent.ACTION_UP: if (mTouchAction == TOUCH_SEEK) { doSeekTouch(Math.round(delta_y), xgesturesize, true); } if (mTouchAction != TOUCH_NONE) { hideCenterInfo(); } touchX = -1f; touchY = -1f; break; default: break; } return mTouchAction != TOUCH_NONE; }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap decodeByteArray(byte[] data, int index, int length) { try {/*from w ww. j a v a2 s .co m*/ WindowManager wm = (WindowManager) SplashActivity.getInstance() .getSystemService(Context.WINDOW_SERVICE); //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; o.inInputShareable = true; o.inPurgeable = true; o.inDither = false; BitmapFactory.decodeByteArray(data, index, length, o); //The new size we want to scale to final int IMAGE_MAX_SIZE = wm.getDefaultDisplay().getWidth(); //Find the correct scale value. It should be the power of 2. int scale = 1; if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.ceil( Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize o.inSampleSize = scale; o.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(data, index, length, o); } catch (Exception e) { Log.e("Tools.decodeByteArray", e.getMessage(), e); } return null; }
From source file:com.kayac.slidingmenu.ui.views.DraggableLayout.java
public static Point getScreenSize(Context c) { Point p = new Point(); WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); p.x = display.getWidth();//from w w w . j av a 2s.co m p.y = display.getHeight(); return p; }