List of usage examples for android.view Display getWidth
@Deprecated public int getWidth()
From source file:com.manning.androidhacks.hack007.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Display display = getWindowManager().getDefaultDisplay(); mDrawView = new DrawView(this); mDrawView.height = display.getHeight(); mDrawView.width = display.getWidth(); setContentView(mDrawView);//from w ww.j a va2s.com }
From source file:com.waz.zclient.utils.ViewUtils.java
public static int getRealDisplayWidth(Context context) { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int realWidth; if (Build.VERSION.SDK_INT >= 17) { //new pleasant way to get real metrics DisplayMetrics realMetrics = new DisplayMetrics(); display.getRealMetrics(realMetrics); realWidth = realMetrics.widthPixels; } else if (Build.VERSION.SDK_INT >= 14) { //reflection for this weird in-between time try {/*from w w w. j a v a 2s . c om*/ Method getRawW = Display.class.getMethod("getRawWidth"); realWidth = (Integer) getRawW.invoke(display); } catch (Exception e) { //this may not be 100% accurate, but it's all we've got realWidth = display.getWidth(); } } else { //This should be close, as lower API devices should not have window navigation bars realWidth = display.getWidth(); } return realWidth; }
From source file:me.kaidul.uhunt.MainActivity.java
@SuppressLint("NewApi") static int getDeviceWidth(Activity activity) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size);//from w w w . j ava 2 s .co m return size.x; } else { Display display = activity.getWindowManager().getDefaultDisplay(); return display.getWidth(); } }
From source file:com.pixate.freestyle.fragment.GridViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_gridview, null); /**/*from www .j a v a2 s . c o m*/ * Getting grid item width and height, column numbers are fixed as 2 and * calculate each item's width and height */ Display display = getActivity().getWindowManager().getDefaultDisplay(); int _nScreenWidth = display.getWidth(); int _nRealSpaceWidth = _nScreenWidth - getResources().getDimensionPixelSize(R.dimen.grid_item_spacing) * (getResources().getInteger(R.integer.grid_col_count) + 1); m_nItemWidth = (_nRealSpaceWidth / getResources().getInteger(R.integer.grid_col_count)); m_nItemHeight = m_nItemWidth; grid = (GridView) view.findViewById(R.id.gridview); ImageAdapter adapter = new ImageAdapter(getActivity(), m_nItemWidth, m_nItemHeight); grid.setAdapter(adapter); return view; }
From source file:com.feigdev.fourcolumngv.FourColumnGridViewActivity.java
/** Called when the activity is first created. */ @Override//from ww w . ja v a 2 s. c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView g = (GridView) findViewById(R.id.myGrid); g.setAdapter(new ImageAdapter(this)); Display display = getWindowManager().getDefaultDisplay(); imgSize = new Point(); imgSize.set((display.getWidth()) / 4, (display.getWidth()) / 4); }
From source file:com.figo.campaignhelper.GenerateActivity.java
Bitmap encodeAsBitmap(String contents) throws WriterException { String contentsToEncode = contents; if (contentsToEncode == null) { return null; }// w ww . j a va 2s .c o m Map<EncodeHintType, Object> hints = null; String encoding = guessAppropriateEncoding(contentsToEncode); if (encoding != null) { hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); hints.put(EncodeHintType.CHARACTER_SET, encoding); } MultiFormatWriter writer = new MultiFormatWriter(); WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int widthD = display.getWidth(); int heightD = display.getHeight(); int dimension = widthD < heightD ? widthD : heightD; dimension = dimension * 7 / 8; BitMatrix result = writer.encode(contentsToEncode, BarcodeFormat.QR_CODE, dimension, dimension, hints); int width = result.getWidth(); int height = result.getHeight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
From source file:mobisocial.musubi.social.QRInviteDialog.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Activity context = getActivity();/* ww w . j a v a2 s . c o m*/ getDialog().setTitle("Exchange Info"); // This assumes the view is full screen, which is a bad assumption WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); int smallerDimension = width < height ? width : height; Uri uri = EmailInviteActivity.getInvitationUrl(context); if (uri.getQueryParameter("n") == null) { Toast.makeText(getActivity(), "You must set up an account and a enter a name to connect with friends.", Toast.LENGTH_LONG).show(); dismiss(); return; } if (uri.getQueryParameter("t") == null) { dismiss(); Toast.makeText(getActivity(), "No identities to share", Toast.LENGTH_SHORT).show(); return; } Intent intent = new Intent(Intents.Encode.ACTION); intent.setClass(getActivity(), QRInviteDialog.class); intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intent.putExtra(Intents.Encode.DATA, uri.toString()); try { qrCodeEncoder = new QRCodeEncoder(context, intent, smallerDimension); //setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle()); Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); ImageView image = (ImageView) view.findViewById(R.id.image_view); image.setImageBitmap(bitmap); TextView contents = (TextView) view.findViewById(R.id.contents_text_view); contents.setText(qrCodeEncoder.getDisplayContents()); view.findViewById(R.id.ok_button).setOnClickListener(mCameraListener); } catch (WriterException e) { Log.e(TAG, "Could not encode barcode", e); showErrorMessage(R.string.msg_encode_contents_failed); qrCodeEncoder = null; } catch (IllegalArgumentException e) { Log.e(TAG, "Could not encode barcode", e); showErrorMessage(R.string.msg_encode_contents_failed); qrCodeEncoder = null; } }
From source file:com.drjane.promise.ui.fragment.CalendarFragment.java
private void initGridView() { // ??/*from ww w . j av a 2 s .c o m*/ WindowManager windowManager = getActivity().getWindowManager(); Display display = windowManager.getDefaultDisplay(); int Width = display.getWidth(); int Height = display.getHeight(); mGridView = new CustomGridView(getActivity()); mGridView.setNumColumns(7); mGridView.setColumnWidth(40); // gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); if (Width == 720 && Height == 1280) { mGridView.setColumnWidth(40); } mGridView.setGravity(Gravity.CENTER_VERTICAL); mGridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); // gridView mGridView.setVerticalSpacing(1); mGridView.setHorizontalSpacing(1); mHandler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub mGridView.setAdapter(calendarGridViewAdapter); } }); }
From source file:it.sasabz.android.sasabus.classes.dialogs.SelectFavoritenDialog.java
/** Called with the activity is first created. */ @Override/* w ww. j av a2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.favoriten_listview); this.setTitle(R.string.mode_favoriten); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; getWindow().setAttributes(lp); Display dm = getWindow().getWindowManager().getDefaultDisplay(); int width = dm.getWidth(); int height = dm.getHeight(); getWindow().setLayout(width / 5 * 4, height / 2); fillData(); }
From source file:pro.dbro.iburn_2012.FragmentTabsPager.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Display display = getWindowManager().getDefaultDisplay(); display_width = display.getWidth(); setContentView(R.layout.fragment_tabs_pager); app = (iBurnApplication) getApplicationContext(); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup();/*from w w w. jav a 2s . c o m*/ mViewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator("Map"), OpenStreetMapFragment.class, null); mTabsAdapter.addTab(mTabHost.newTabSpec("art").setIndicator("Art"), ArtFragment.CursorLoaderListFragment.class, null); mTabsAdapter.addTab(mTabHost.newTabSpec("camps").setIndicator("Camps"), CampFragment.CursorLoaderListFragment.class, null); mTabsAdapter.addTab(mTabHost.newTabSpec("events").setIndicator("Events"), EventFragment.CursorLoaderListFragment.class, null); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } res = getResources(); prefs = getSharedPreferences("PREFS", 0); editor = prefs.edit(); /* * Uncomment this to populate initial data from JSON * If you do this, comment out DBWrapper.getWritableDatabase() * to avoid also copying bundled pre-populated database if(prefs.getBoolean("dbReady", false)){ new DataUtils.PopulateDBFromJsonTask().execute(); } */ }