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.yahala.ui.LaunchActivity.java

private void fixLayout() {
    if (containerView != null) {
        ViewTreeObserver obs = containerView.getViewTreeObserver();
        obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override/*from ww  w  .  j a va 2 s .  c o m*/
            public void onGlobalLayout() {
                WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
                int rotation = manager.getDefaultDisplay().getRotation();

                int height;
                int currentActionBarHeight = getSupportActionBar().getHeight();
                if (currentActionBarHeight != OSUtilities.dp(48)
                        && currentActionBarHeight != OSUtilities.dp(40)) {
                    height = currentActionBarHeight;
                } else {
                    height = OSUtilities.dp(48);
                    if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
                        height = OSUtilities.dp(40);
                    }
                }

                if (notificationView != null) {
                    notificationView.applyOrientationPaddings(
                            rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height);
                }

                if (Build.VERSION.SDK_INT < 16) {
                    containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        });
    }
}

From source file:com.bt.download.android.gui.Librarian.java

public ScreenMetrics readScreenMetrics() {
    ScreenMetrics sm = new ScreenMetrics();

    try {//  w  ww  .  j  a v a 2 s  . c  om
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        context.getResources().getDisplayMetrics();
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);

        sm.densityDpi = dm.densityDpi;
        sm.heightPixels = dm.heightPixels;
        sm.widthPixels = dm.widthPixels;
        sm.xdpi = dm.xdpi;
        sm.ydpi = dm.ydpi;
    } catch (Throwable e) {
        Log.e(TAG, "Unable to get the device display dimensions", e);
    }

    return sm;
}

From source file:com.bt.download.android.gui.Librarian.java

public double getScreenSizeInInches() {
    double screenInches = 0;

    try {//from   w  w w .  j a  v a2 s. co m
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        context.getResources().getDisplayMetrics();
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);

        double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
        double y = Math.pow(dm.heightPixels / dm.ydpi, 2);

        screenInches = Math.sqrt(x + y);

    } catch (Throwable e) {
        Log.e(TAG, "Unable to get the device display dimensions", e);
    }

    return screenInches;
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

public static Point getPreviewDimension() {

    //        Taken from: http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels
    View v = ((Activity) mContext).findViewById(R.id.camera_controls_layout);

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//  w w w.  jav a2  s  . c om

    Point dim = null;

    if (v != null) {
        if (getOrientation() == Surface.ROTATION_0 || getOrientation() == Surface.ROTATION_180)
            dim = new Point(size.x, size.y - v.getHeight());
        //                return size.y - v.getHeight();
        else if (getOrientation() == Surface.ROTATION_90 || getOrientation() == Surface.ROTATION_270)
            dim = new Point(size.x - v.getWidth(), size.y);
        //                return size.x - v.getWidth();
    }

    return dim;

}

From source file:com.pdftron.pdf.controls.UserCropDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_user_crop_dialog, null);
    if (mRemoveCropHelperMode) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
    } else {//from   w ww .j  av a2  s.  c  om
        int width = 10;
        int height = 10;
        WindowManager wm = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            android.graphics.Point size = new android.graphics.Point();
            display.getSize(size);
            width = size.x - 10;
            height = size.y - 10;
        } else {
            width = display.getWidth() - 10;
            height = display.getHeight() - 10;
        }

        int maxImageSize = width * height * 4;
        if (maxImageSize > 0) {
            int maxImages = (DEFAULT_MEM_CACHE_SIZE * 1000) / maxImageSize;
            if (maxImages > 0) {
                mPagesToPreRenderPerDirection = Math.min(MAX_PAGES_TO_PRERENDER_PER_DIRECTION,
                        (maxImages - 1) / 2);
            }
        }
    }
    initUI(view);
    return view;
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

public WearableDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mFlingWatcher = new FlingWatcherFactory(this);
    mTopDrawerDraggerCallback = new TopDrawerDraggerCallback();
    mTopDrawerDragger = ViewDragHelper.create(this, 1f /* sensitivity */, mTopDrawerDraggerCallback);
    mTopDrawerDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP);

    mBottomDrawerDraggerCallback = new BottomDrawerDraggerCallback();
    mBottomDrawerDragger = ViewDragHelper.create(this, 1f /* sensitivity */, mBottomDrawerDraggerCallback);
    mBottomDrawerDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM);

    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(metrics);
    mNestedScrollSlopPx = Math.round(metrics.density * NESTED_SCROLL_SLOP_DP);

    AccessibilityManager accessibilityManager = (AccessibilityManager) context
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    mIsAccessibilityEnabled = accessibilityManager.isEnabled();
}

From source file:com.scoreflex.Scoreflex.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private static Point getScreenSize() {
    final Point size = new Point();
    WindowManager w = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();

    try {//w  w w .ja  v  a 2 s  . co  m
        Method getSizeMethod = d.getClass().getDeclaredMethod("getSize", Point.class);
        getSizeMethod.invoke(d, size);
    } catch (Exception e) {
        size.x = d.getWidth();
        size.y = d.getHeight();
    }
    return size;
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

/**
 * Called when the activity is first created.
 *///from w  ww.  j  ava  2  s .co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.download);

    WindowManager w = getWindowManager();
    Display d = w.getDefaultDisplay();
    swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
    gestureScanner = new GestureDetector(this);

    playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
    emptyTextView = (TextView) findViewById(R.id.download_empty);
    songTitleTextView = (TextView) findViewById(R.id.download_song_title);
    artistTextView = (TextView) findViewById(R.id.download_artist);
    albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
    positionTextView = (TextView) findViewById(R.id.download_position);
    durationTextView = (TextView) findViewById(R.id.download_duration);
    statusTextView = (TextView) findViewById(R.id.download_status);
    progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
    playlistView = (ListView) findViewById(R.id.download_list);
    previousButton = findViewById(R.id.download_previous);
    nextButton = findViewById(R.id.download_next);
    pauseButton = findViewById(R.id.download_pause);
    stopButton = findViewById(R.id.download_stop);
    startButton = findViewById(R.id.download_start);
    shuffleButton = findViewById(R.id.download_shuffle);
    repeatButton = (ImageButton) findViewById(R.id.download_repeat);
    equalizerButton = (Button) findViewById(R.id.download_equalizer);
    visualizerButton = (Button) findViewById(R.id.download_visualizer);
    // jukeboxButton = (Button) findViewById(R.id.download_jukebox);
    // shareButton = (ImageView) findViewById(R.id.download_share);
    // starButton = (ImageView) findViewById(R.id.download_star);
    LinearLayout visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
    toggleListButton = (ImageButton) findViewById(R.id.download_toggle_list);

    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent me) {
            return gestureScanner.onTouchEvent(me);
        }
    };
    previousButton.setOnTouchListener(touchListener);
    nextButton.setOnTouchListener(touchListener);
    pauseButton.setOnTouchListener(touchListener);
    stopButton.setOnTouchListener(touchListener);
    // startButton.setOnTouchListener(touchListener);
    equalizerButton.setOnTouchListener(touchListener);
    visualizerButton.setOnTouchListener(touchListener);
    //jukeboxButton.setOnTouchListener(touchListener);
    //shareButton.setOnTouchListener(touchListener);
    //starButton.setOnTouchListener(touchListener);
    emptyTextView.setOnTouchListener(touchListener);
    albumArtImageView.setOnTouchListener(touchListener);

    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            getDownloadService().previous();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
                getDownloadService().next();
                onCurrentChanged();
                onProgressChanged();
            }
        }
    });

    pauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().pause();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    stopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().reset();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    startButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            warnIfNetworkOrStorageUnavailable();
            start();
            onCurrentChanged();
            onProgressChanged();
        }
    });

    shuffleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getDownloadService().shuffle();
            Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
            setControlsVisible(true);
        }
    });

    repeatButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
            getDownloadService().setRepeatMode(repeatMode);
            onDownloadListChanged();
            switch (repeatMode) {
            case OFF:
                Util.toast(DownloadActivity.this, R.string.download_repeat_off);
                break;
            case ALL:
                Util.toast(DownloadActivity.this, R.string.download_repeat_all);
                break;
            case SINGLE:
                Util.toast(DownloadActivity.this, R.string.download_repeat_single);
                break;
            default:
                break;
            }
            setControlsVisible(true);
        }
    });

    equalizerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
            setControlsVisible(true);
        }
    });

    visualizerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean active = !visualizerView.isActive();
            visualizerView.setActive(active);
            getDownloadService().setShowVisualization(visualizerView.isActive());
            updateButtons();
            Util.toast(DownloadActivity.this,
                    active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
            setControlsVisible(true);
        }
    });

    /* jukeboxButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
        getDownloadService().setJukeboxEnabled(jukeboxEnabled);
        updateButtons();
        Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
        setControlsVisible(true);
    }
     });*/

    /*shareButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (currentPlaying != null) {
            ShareUtil.shareInBackground(DownloadActivity.this, currentPlaying.getSong());
        }
        setControlsVisible(true);
    }
    });*/

    /*starButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (currentPlaying != null) {
            MusicDirectory.Entry song = currentPlaying.getSong();
            StarUtil.starInBackground(DownloadActivity.this, song, !song.isStarred());
            starButton.setImageResource(song.isStarred() ? R.drawable.starred : R.drawable.unstarred);
        }
        setControlsVisible(true);
    }
    });*/

    toggleListButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleFullscreenAlbumArt();
        }
    });

    progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int position, boolean fromUser) {
            if (fromUser) {
                Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true);
                setControlsVisible(true);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // Notification that the user has started a touch gesture. Clients may want to use this to disable advancing the seekbar.
            seekInProgress = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // Notification that the user has finished a touch gesture. Clients may want to use this to re-enable advancing the seekbar.
            seekInProgress = false;
            int position = seekBar.getProgress();
            Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true);
            getDownloadService().seekTo(position);
        }
    });

    playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            warnIfNetworkOrStorageUnavailable();
            getDownloadService().play(position);
            onCurrentChanged();
            onProgressChanged();
        }
    });

    registerForContextMenu(playlistView);

    DownloadService downloadService = getDownloadService();
    if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
        warnIfNetworkOrStorageUnavailable();
        downloadService.setShufflePlayEnabled(true);
    }

    boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null;
    boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null;

    if (!equalizerAvailable) {
        equalizerButton.setVisibility(View.GONE);
    }
    if (!visualizerAvailable) {
        visualizerButton.setVisibility(View.GONE);
    } else {
        visualizerView = new VisualizerView(this);
        visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
    }

    final View overflowButton = findViewById(R.id.download_overflow);
    overflowButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new PopupMenuHelper().showMenu(DownloadActivity.this, overflowButton, R.menu.nowplaying);
        }
    });
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private int getNavBarSize() {
    Point size = new Point();
    Point realSize = new Point();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getSize(size);/*w ww. j a v  a  2s  .c  o m*/
    display.getRealSize(realSize);

    return realSize.y - size.y;
}

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);
    }/*www .  jav  a  2 s  . c  o 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;
}