Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:com.github.mobile.util.HttpImageGetter.java

@TargetApi(13)
private Point fetchDisplaySize(WindowManager wm) {
    Point size = new Point();
    wm.getDefaultDisplay().getSize(size);
    return size;// ww  w .ja v  a2s .c  o m
}

From source file:com.oakesville.mythling.app.AppData.java

public Point getScreenSize() {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);//from  w ww  . j a  v a 2 s .c  o  m
    }
    return screenSize;
}

From source file:com.tekinarslan.material.sample.customui.slidingtab_new.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*  ww w  .  jav a 2s .c om*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    viewWidth = display.getWidth();
}

From source file:com.ubuntuone.android.files.fragment.GalleryFragment.java

@Override
public void onDownloadCached(String key, String path) {
    final GalleryViewHolder holder = holders.get(key);
    if (holder != null) {
        WindowManager wm = getActivity().getWindowManager();
        Display display = wm.getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        int maxDimention = Math.max(width, height);

        final Bitmap bitmap = BitmapUtilities.decodeFile(new File(path), maxDimention);
        mHandler.post(new Runnable() {
            @Override/*from  w  ww  . j  a  v a  2 s. c  om*/
            public void run() {
                if (holder.previewImage != null) {
                    holder.previewImage.setImageDrawable(new BitmapDrawable(bitmap));
                    holder.progressWrapper.setVisibility(View.GONE);
                }
            }
        });
    }
}

From source file:com.wenhui.syncedListView.lib.SyncedListLayout.java

private void init(Context context, AttributeSet attrs) {

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SyncedListLayout);
    try {/* www . jav  a 2s  .  com*/
        mLeftListId = a.getResourceId(R.styleable.SyncedListLayout_left_id, 0);
        mRightListId = a.getResourceId(R.styleable.SyncedListLayout_right_id, 0);
        mLeftScrollFactor = a.getFloat(R.styleable.SyncedListLayout_left_scroll_factor, 1f);
        mRightScrollFactor = a.getFloat(R.styleable.SyncedListLayout_right_scroll_factor, 1f);
    } finally {
        a.recycle();
    }

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metric = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metric);
    mAnimationVelocity = (int) (DEFAULT_VELOCITY * metric.density);

    gestureDetector = new GestureDetectorCompat(context, gestureListener);
    mScroller = new Scroller(context);

    mAnimationRunnable = new AnimationRunnable(context);
    mFlingRunnable = new FlingRunnable();
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

private void animateIn(final Dialog dialog) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams();
    params.width = rect.right;/*from  w w  w.j  av  a2 s  .c o m*/
    params.height = rect.bottom;
    zoomableImageView.setLayoutParams(params);

    zoomableImageView.setX(rect.left);
    zoomableImageView.setY(rect.top - statusBarHeightCorrection);
    zoomableImageView.setAlpha(0.0f);
    zoomableImageView.setImageBitmap(bitmap);

    WindowManager win = getActivity().getWindowManager();
    Display d = win.getDefaultDisplay();
    int displayWidth = d.getWidth(); // Width of the actual device
    int displayHeight = d.getHeight() + statusBarHeightCorrection;

    ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth);
    animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
        }
    });
    animWidth.setDuration(500);
    animWidth.setInterpolator(new LinearOutSlowInInterpolator());
    animWidth.start();

    ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight);
    animHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
        }
    });
    animHeight.setDuration(500);
    animHeight.setInterpolator(new LinearOutSlowInInterpolator());

    animHeight.start();

    if (statusBarHeightCorrection > 0) {
        zoomableImageView.animate().y(0.0f).setDuration(300).start();
    }

    ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f);
    animDim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            layoutParams.copyFrom(dialog.getWindow().getAttributes());
            layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue();
            dialog.getWindow().setAttributes(layoutParams);
        }
    });
    animDim.setDuration(300);
    animDim.setStartDelay(300);
    animDim.start();
    zoomableImageView.animate().alpha(1.0f).setDuration(300).start();
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * ?/*from  w w  w. ja va 2  s .c o  m*/
 *
 * @return
 */
public int getScreenWidth() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:cis350.blanket.IntentIntegrator.java

/**
 * Use a wide scanning rectangle./*from  w ww. ja  v a2 s .c om*/
 *
 * May work better for 1D barcodes.
 */
public void setWide() {
    addExtra("SCAN_WIDE", true);

    // For zxing-android-legacy, which doesn't support SCAN_WIDE
    WindowManager window = activity.getWindowManager();
    Display display = window.getDefaultDisplay();
    @SuppressWarnings("deprecation")
    int displayWidth = display.getWidth();
    @SuppressWarnings("deprecation")
    int displayHeight = display.getHeight();
    if (displayHeight > displayWidth) {
        // This is portrait dimensions, but the legacy barcode scanner is always in landscape mode.
        int temp = displayWidth;
        //noinspection SuspiciousNameCombination
        displayWidth = displayHeight;
        displayHeight = temp;
    }

    int desiredWidth = displayWidth * 9 / 10;
    int desiredHeight = Math.min(displayHeight * 3 / 4, 400); // Limit to 400px
    setScanningRectangle(desiredWidth, desiredHeight);
}

From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private int getScreenHeight() {
    Point size = new Point();
    WindowManager w = mActivity.getWindowManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        w.getDefaultDisplay().getSize(size);
        return size.y;
    } else {//from   ww w  .  j  a v a2  s. c o  m
        Display d = w.getDefaultDisplay();
        return d.getHeight();
    }
}

From source file:com.example.snowball.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();//from  ww  w  .  java 2 s.  c o  m
    mPlanetTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    WindowManager manager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(dm);
    width = dm.widthPixels;
    height = dm.heightPixels;
    // set a custom shadow that overlays the main content when the drawer
    //       opens
    //      mDrawerLayout.setDrawerShadow(R.drawable.nav_icon_menu,
    //            GravityCompat.START);
    //      mDrawerLayout.setContentDescription("");
    // set up the drawer's list view with items and click listener
    MyListAdapter myAdapter = new MyListAdapter(this, mPlanetTitles);
    mDrawerList.setAdapter(myAdapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.nav_icon_menu, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            actionStyle(menuitem);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            getActionBar().setNavigationMode(0);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        menuitem = 1;
        selectItem(1);
        actionStyle(1);
    }
}