List of usage examples for android.util DisplayMetrics DisplayMetrics
public DisplayMetrics()
From source file:count.ly.messaging.DeviceInfo.java
/** * Returns the non-scaled pixel resolution of the current default display being used by the * WindowManager in the specified context. * @param context context to use to retrieve the current WindowManager * @return a string in the format "WxH", or the empty string "" if resolution cannot be determined *//*from w w w.j a v a 2 s. c o m*/ static String getResolution(final Context context) { // user reported NPE in this method; that means either getSystemService or getDefaultDisplay // were returning null, even though the documentation doesn't say they should do so; so now // we catch Throwable and return empty string if that happens String resolution = ""; try { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); resolution = metrics.widthPixels + "x" + metrics.heightPixels; } catch (Throwable t) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.i(Countly.TAG, "Device resolution cannot be determined"); } } return resolution; }
From source file:com.example.propertylist.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_project_sales_list); ImageView mImageView = new ImageView(this); DisplayMetrics metrics;/*from ww w . j av a 2s . c o m*/ int mScreenWidth; int mScreenHeight; api_key = getResources().getString(R.string.key); metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); mScreenWidth = metrics.widthPixels; mScreenHeight = metrics.heightPixels; if (mScreenWidth >= minScreenwidth) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { if (mScreenWidth >= minLandScreenwidth) { largeScreen = true; } } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { if (mScreenHeight > minLandScreenwidth) { largeScreen = true; } } } else { largeScreen = false; } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(getResources(), R.id.daft_logo_image, options); mImageView.setImageBitmap( // ensure image size is 100 x 100. decodeSampledBitmapFromResource(getResources(), R.id.daft_logo_image, 100, 100)); handler = new Handler() { @Override public void handleMessage(Message msg) { hideProgressDialog(); startListActivity(); } }; }
From source file:com.morphoss.jumble.frontend.CategoryScreenActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_category); gridLayout = (GridLayout) findViewById(R.id.gridView1); gridLayout.setRowCount(2);/*from w ww .j a v a2s . c o m*/ DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels; pga = new CategoryGridAdapter(this, width, height); new LoadCategoryTask().execute(); }
From source file:com.tencent.wetest.common.util.DeviceUtil.java
/** * ??//w w w .j a v a 2s . com * @param cx * @return ? ( width x height ) */ public static String getDisplayMetrics(Context cx) { WindowManager mWindowManager = (WindowManager) cx.getSystemService(Context.WINDOW_SERVICE); Display display = mWindowManager.getDefaultDisplay(); DisplayMetrics metric = new DisplayMetrics(); Point size = new Point(); String str = ""; try { if (Build.VERSION.SDK_INT >= 11) { display.getRealSize(size); str += String.valueOf(size.x) + " x " + String.valueOf(size.y); } else { Method method = Class.forName("android.view.Display").getMethod("getRealMetrics", DisplayMetrics.class); method.invoke(display, metric); str += String.valueOf(metric.widthPixels) + " x " + String.valueOf(metric.heightPixels); } } catch (Exception e) { display.getMetrics(metric); str += String.valueOf(metric.widthPixels) + " x " + String.valueOf(metric.heightPixels); Logger.error("getDeviceRealMetric Exception : " + e.toString()); } return str; }
From source file:com.zhihuigu.sosoOffice.LoadActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a_load);/*from w w w . ja va2s . c om*/ mMainFrameTask = new MainFrameTask(this); mMainFrameTask.execute(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); MyApplication.getInstance(this).setScreenWidth(dm.widthPixels); MyApplication.getInstance(this).setScreenHeight(dm.heightPixels); // new Thread(runnable).start(); }
From source file:com.umeng.message.example.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pushDao = PushDao.getInstance(this); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels;//from w w w . ja v a 2 s .c om setContentView(R.layout.activity_main); printKeyValue(); mPushAgent = PushAgent.getInstance(this); mPushAgent.onAppStart(); mPushAgent.enable(MyApplication.mRegisterCallback); tvStatus = (TextView) findViewById(R.id.tvStatus); btnEnable = (ImageView) findViewById(R.id.btnEnable); btnaAddTag = (Button) findViewById(R.id.btnAddTags); btnAddAlias = (Button) findViewById(R.id.btnAddAlias); btnListTag = (Button) findViewById(R.id.btnListTags); infoTextView = (TextView) findViewById(R.id.info); edTag = (EditText) findViewById(R.id.edTag); edAlias = (EditText) findViewById(R.id.edAlias); edAliasType = (EditText) findViewById(R.id.edAliasType); spAliasType = (Spinner) findViewById(R.id.spAliasType); edAliasType.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { edAliasTypeFocus = true; } else { edAliasTypeFocus = false; } } }); edAliasType.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (edAliasTypeFocus) { spAliasType.setSelection(0); } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); String[] aliasType = new String[] { "Alias Type:", ALIAS_TYPE.SINA_WEIBO, ALIAS_TYPE.BAIDU, ALIAS_TYPE.KAIXIN, ALIAS_TYPE.QQ, ALIAS_TYPE.RENREN, ALIAS_TYPE.TENCENT_WEIBO, ALIAS_TYPE.WEIXIN }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, aliasType); spAliasType.setAdapter(adapter); spAliasType.setBackgroundColor(Color.LTGRAY); spAliasType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub TextView tv = (TextView) arg1; if (tv != null) { int rate = (int) (5.0f * (float) screenWidth / 320.0f); int textSize = rate < 15 ? 15 : rate; tv.setTextSize((float) textSize); } if (arg2 != 0) { String type = (String) spAliasType.getItemAtPosition(arg2); edAliasType.setText(type); } else if (!edAliasTypeFocus) { edAliasType.setText(""); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); tvStatus.setOnClickListener(clickListener); btnEnable.setOnClickListener(clickListener); btnaAddTag.setOnClickListener(clickListener); btnListTag.setOnClickListener(clickListener); btnAddAlias.setOnClickListener(clickListener); updateStatus(); mPushAgent.setPushIntentServiceClass(MyPushIntentService.class); callbackReceiver = new CallbackReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(MyApplication.CALLBACK_RECEIVER_ACTION); registerReceiver(callbackReceiver, filter); }
From source file:ly.count.android.api.DeviceInfoTests.java
private Context mockContextForTestingDensity(final int density) { final DisplayMetrics metrics = new DisplayMetrics(); metrics.densityDpi = density;// w ww . j a v a 2s . c om final Resources mockResources = mock(Resources.class); when(mockResources.getDisplayMetrics()).thenReturn(metrics); final Context mockContext = mock(Context.class); when(mockContext.getResources()).thenReturn(mockResources); return mockContext; }
From source file:fr.univsavoie.ltp.client.map.Popup.java
/** * Afficher sur la map un popup qui affiche les * informations de l'utilisateur connect. *///from ww w .j av a 2s.c o m public final void popupDisplayUserInfos() { DisplayMetrics dm = new DisplayMetrics(); this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm); //final int height = dm.heightPixels; final int width = dm.widthPixels; int popupWidth = (int) (width * 0.75); //int popupHeight = height / 2; // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupAccount); LayoutInflater layoutInflater = (LayoutInflater) this.activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(R.layout.popup_account, viewGroup); layout.setBackgroundResource(R.drawable.popup_gradient); // Crer le PopupWindow final PopupWindow popupUserInfos = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true); popupUserInfos.setBackgroundDrawable(new BitmapDrawable()); popupUserInfos.setOutsideTouchable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. final int OFFSET_X = 0; final int OFFSET_Y = 0; // Displaying the popup at the specified location, + offsets. this.activity.findViewById(R.id.layoutMain).post(new Runnable() { public void run() { popupUserInfos.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y); } }); /* * Evenements composants du PopupWindow */ // Ecouteur d'vnement sur le bouton pour se dconnecter Button close = (Button) layout.findViewById(R.id.close); close.setOnClickListener(new OnClickListener() { public void onClick(View v) { popupUserInfos.dismiss(); } }); }
From source file:illab.nabal.proxy.AuthWebDialog.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // prepare web view layout mLayout = new LinearLayout(getContext()); mLayout.setOrientation(LinearLayout.VERTICAL); // set up title bar setUpTitle();//from w w w .j a v a2s . c o m // set up web view setUpWebView(); // determine screen width and height DisplayMetrics displaymetrics = new DisplayMetrics(); getWindow().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int screenWidth = displaymetrics.widthPixels; int screenHeight = displaymetrics.heightPixels; // add layout to screen LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams((int) (screenWidth * 0.90), (int) (screenHeight * 0.90)); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(mLayout, layoutParams); }
From source file:com.ternup.caddisfly.activity.VideoActivity.java
private void playVideo(File videoFile) { DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); int height = dm.heightPixels; int width = dm.widthPixels; final VideoView videoHolder = (VideoView) this.findViewById(R.id.video_player_view); videoHolder.setMinimumWidth(width);//w ww .ja va2 s . com videoHolder.setMinimumHeight(height); //getWindow().setFormat(PixelFormat.TRANSLUCENT); videoHolder.setMediaController(new MediaController(this)); videoHolder.setVideoPath(videoFile.getAbsolutePath()); videoHolder.requestFocus(); videoHolder.start(); }