Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

In this page you can find the example usage for android.view Display getSize.

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

From source file:org.uguess.android.sysinfo.SiragonManager.java

private String[] getInfoDisplay() {
    String[] display = new String[5];
    Display displayscreen = getActivity().getWindowManager().getDefaultDisplay();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    Point size = new Point();
    displayscreen.getSize(size);
    int width = size.x;
    int height = size.y;
    double x = Math.pow(width / displayMetrics.xdpi, 2);
    double y = Math.pow(height / displayMetrics.ydpi, 2);
    double tmpinch = Math.sqrt(x + y);
    double inches = Math.round(tmpinch * 100);
    tmpinch = inches / 100;/*from w  w  w.j  av a  2 s.co  m*/
    Display display2 = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    float refreshRating = display2.getRefreshRate();
    display[0] = String.valueOf("height: " + displayMetrics.heightPixels);
    display[1] = String.valueOf("width: " + displayMetrics.widthPixels);
    display[2] = String.valueOf("density: " + displayMetrics.densityDpi + " dpi");
    display[3] = String.valueOf("Physical size: " + tmpinch + '"');
    display[4] = String.valueOf("refresh rate: " + refreshRating + '"');

    return display;
}

From source file:com.android.tv.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG)/*from  w w w  .  j av  a 2 s  .  c  o m*/
        Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !PermissionUtils.hasAccessAllEpg(this)) {
        Toast.makeText(this, R.string.msg_not_supported_device, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    boolean skipToShowOnboarding = getIntent().getAction() == Intent.ACTION_VIEW
            && TvContract.isChannelUriForPassthroughInput(getIntent().getData());
    if (Features.ONBOARDING_EXPERIENCE.isEnabled(this) && OnboardingUtils.needToShowOnboarding(this)
            && !skipToShowOnboarding && !TvCommonUtils.isRunningInTest()) {
        // TODO: The onboarding is turned off in test, because tests are broken by the
        // onboarding. We need to enable the feature for tests later.
        startActivity(OnboardingActivity.buildIntent(this, getIntent()));
        finish();
        return;
    }

    TvApplication tvApplication = (TvApplication) getApplication();
    tvApplication.getMainActivityWrapper().onMainActivityCreated(this);
    if (BuildConfig.ENG && SystemProperties.ALLOW_STRICT_MODE.getValue()) {
        Toast.makeText(this, "Using Strict Mode for eng builds", Toast.LENGTH_SHORT).show();
    }
    mTracker = tvApplication.getTracker();
    mTvInputManagerHelper = tvApplication.getTvInputManagerHelper();
    mTvInputManagerHelper.addCallback(mTvInputCallback);
    mUsbTunerInputId = UsbTunerTvInputService.getInputId(this);
    mChannelDataManager = tvApplication.getChannelDataManager();
    mProgramDataManager = tvApplication.getProgramDataManager();
    mProgramDataManager.addOnCurrentProgramUpdatedListener(Channel.INVALID_ID,
            mOnCurrentProgramUpdatedListener);
    mProgramDataManager.setPrefetchEnabled(true);
    mChannelTuner = new ChannelTuner(mChannelDataManager, mTvInputManagerHelper);
    mChannelTuner.addListener(mChannelTunerListener);
    mChannelTuner.start();
    mPipInputManager = new PipInputManager(this, mTvInputManagerHelper, mChannelTuner);
    mPipInputManager.start();
    mMemoryManageables.add(mProgramDataManager);
    mMemoryManageables.add(ImageCache.getInstance());
    mMemoryManageables.add(TvContentRatingCache.getInstance());
    if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
        mDvrManager = tvApplication.getDvrManager();
        mDvrDataManager = tvApplication.getDvrDataManager();
    }

    DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int screenHeight = size.y;
    mDefaultRefreshRate = display.getRefreshRate();

    mOverlayRootView = (OverlayRootView) getLayoutInflater().inflate(R.layout.overlay_root_view, null, false);
    setContentView(R.layout.activity_tv);
    mTvView = (TunableTvView) findViewById(R.id.main_tunable_tv_view);
    int shrunkenTvViewHeight = getResources().getDimensionPixelSize(R.dimen.shrunken_tvview_height);
    mTvView.initialize((AppLayerTvView) findViewById(R.id.main_tv_view), false, screenHeight,
            shrunkenTvViewHeight);
    mTvView.setOnUnhandledInputEventListener(new OnUnhandledInputEventListener() {
        @Override
        public boolean onUnhandledInputEvent(InputEvent event) {
            if (isKeyEventBlocked()) {
                return true;
            }
            if (event instanceof KeyEvent) {
                KeyEvent keyEvent = (KeyEvent) event;
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.isLongPress()) {
                    if (onKeyLongPress(keyEvent.getKeyCode(), keyEvent)) {
                        return true;
                    }
                }
                if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                    return onKeyUp(keyEvent.getKeyCode(), keyEvent);
                } else if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    return onKeyDown(keyEvent.getKeyCode(), keyEvent);
                }
            }
            return false;
        }
    });
    mTimeShiftManager = new TimeShiftManager(this, mTvView, mProgramDataManager, mTracker,
            new OnCurrentProgramUpdatedListener() {
                @Override
                public void onCurrentProgramUpdated(long channelId, Program program) {
                    updateMediaSession();
                    switch (mTimeShiftManager.getLastActionId()) {
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_REWIND:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_FAST_FORWARD:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS:
                    case TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT:
                        updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW);
                        break;
                    default:
                        updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_UPDATE_INFO);
                        break;
                    }
                }
            });

    mPipView = (TunableTvView) findViewById(R.id.pip_tunable_tv_view);
    mPipView.initialize((AppLayerTvView) findViewById(R.id.pip_tv_view), true, screenHeight,
            shrunkenTvViewHeight);

    if (!PermissionUtils.hasAccessWatchedHistory(this)) {
        WatchedHistoryManager watchedHistoryManager = new WatchedHistoryManager(getApplicationContext());
        watchedHistoryManager.start();
        mTvView.setWatchedHistoryManager(watchedHistoryManager);
    }
    mTvViewUiManager = new TvViewUiManager(this, mTvView, mPipView,
            (FrameLayout) findViewById(android.R.id.content), mTvOptionsManager);

    mPipView.setFixedSurfaceSize(screenWidth / 2, screenHeight / 2);
    mPipView.setBlockScreenType(TunableTvView.BLOCK_SCREEN_TYPE_SHRUNKEN_TV_VIEW);

    ViewGroup sceneContainer = (ViewGroup) findViewById(R.id.scene_container);
    mChannelBannerView = (ChannelBannerView) getLayoutInflater().inflate(R.layout.channel_banner,
            sceneContainer, false);
    mKeypadChannelSwitchView = (KeypadChannelSwitchView) getLayoutInflater()
            .inflate(R.layout.keypad_channel_switch, sceneContainer, false);
    InputBannerView inputBannerView = (InputBannerView) getLayoutInflater().inflate(R.layout.input_banner,
            sceneContainer, false);
    SelectInputView selectInputView = (SelectInputView) getLayoutInflater().inflate(R.layout.select_input,
            sceneContainer, false);
    selectInputView.setOnInputSelectedCallback(new OnInputSelectedCallback() {
        @Override
        public void onTunerInputSelected() {
            Channel currentChannel = mChannelTuner.getCurrentChannel();
            if (currentChannel != null && !currentChannel.isPassthrough()) {
                hideOverlays();
            } else {
                tuneToLastWatchedChannelForTunerInput();
            }
        }

        @Override
        public void onPassthroughInputSelected(TvInputInfo input) {
            Channel currentChannel = mChannelTuner.getCurrentChannel();
            String currentInputId = currentChannel == null ? null : currentChannel.getInputId();
            if (TextUtils.equals(input.getId(), currentInputId)) {
                hideOverlays();
            } else {
                tuneToChannel(Channel.createPassthroughChannel(input.getId()));
            }
        }

        private void hideOverlays() {
            getOverlayManager().hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_DIALOG
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANELS
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_PROGRAM_GUIDE
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_MENU
                    | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT);
        }
    });
    mSearchFragment = new ProgramGuideSearchFragment();
    mOverlayManager = new TvOverlayManager(this, mChannelTuner, mKeypadChannelSwitchView, mChannelBannerView,
            inputBannerView, selectInputView, sceneContainer, mSearchFragment);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusStatus = AudioManager.AUDIOFOCUS_LOSS;

    mMediaSession = new MediaSession(this, MEDIA_SESSION_TAG);
    mMediaSession.setCallback(new MediaSession.Callback() {
        @Override
        public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
            // Consume the media button event here. Should not send it to other apps.
            return true;
        }
    });
    mMediaSession
            .setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mNowPlayingCardWidth = getResources().getDimensionPixelSize(R.dimen.notif_card_img_max_width);
    mNowPlayingCardHeight = getResources().getDimensionPixelSize(R.dimen.notif_card_img_height);

    mTvViewUiManager.restoreDisplayMode(false);
    if (!handleIntent(getIntent())) {
        finish();
        return;
    }

    mAudioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this,
            new AudioCapabilitiesReceiver.OnAc3PassthroughCapabilityChangeListener() {
                @Override
                public void onAc3PassthroughCapabilityChange(boolean capability) {
                    mAc3PassthroughSupported = capability;
                }
            });
    mAudioCapabilitiesReceiver.register();

    mAccessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
    mSendConfigInfoRecurringRunner = new RecurringRunner(this, TimeUnit.DAYS.toMillis(1),
            new SendConfigInfoRunnable(mTracker, mTvInputManagerHelper), null);
    mSendConfigInfoRecurringRunner.start();
    mChannelStatusRecurringRunner = SendChannelStatusRunnable.startChannelStatusRecurringRunner(this, mTracker,
            mChannelDataManager);

    // To avoid not updating Rating systems when changing language.
    mTvInputManagerHelper.getContentRatingsManager().update();

    initForTest();
}

From source file:com.android.launcher2.Workspace.java

/**
 * Initializes various states for this workspace.
 *//*from   ww w .j  av  a 2 s. co m*/
protected void initWorkspace() {
    Context context = getContext();
    mCurrentPage = mDefaultPage;
    Launcher.setScreen(mCurrentPage);
    LauncherApplication app = (LauncherApplication) context.getApplicationContext();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setChildrenDrawnWithCacheEnabled(true);

    final Resources res = getResources();
    try {
        mBackground = res.getDrawable(R.drawable.apps_customize_bg);
    } catch (Resources.NotFoundException e) {
        // In this case, we will skip drawing background protection
    }

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);
    mWallpaperTravelWidth = (int) (mDisplaySize.x
            * wallpaperTravelToScreenWidthRatio(mDisplaySize.x, mDisplaySize.y));

    mMaxDistanceForFolderCreation = (0.55f * res.getDimensionPixelSize(R.dimen.app_icon_size));
    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
}

From source file:net.robotmedia.acv.ui.widget.OcrLayout.java

/** Updates screenWidth and screenHeight. */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void determineScreenDimensions(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    if (android.os.Build.VERSION.SDK_INT >= 19) {
        // Get the total size of the screen (because on android 4.4 and
        // above we use immersive mode to hide the navigation bar).
        DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getRealMetrics(metrics);

        this.screenWidth = metrics.widthPixels;
        this.screenHeight = metrics.heightPixels;
    } else if (android.os.Build.VERSION.SDK_INT >= 13) {
        // Get the size of the screen minus the height of the navigation bar
        Point size = new Point();
        display.getSize(size);

        this.screenWidth = size.x;
        this.screenHeight = size.y;
    } else {/*from   w w  w.  j  av a 2  s . co  m*/
        // Get the size of the screen minus the height of the navigation bar (old method)
        this.screenWidth = display.getWidth(); // deprecated
        this.screenHeight = display.getHeight(); // deprecated
    }
}

From source file:org.telegram.ui.ChatActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//from  ww  w .j  a v a 2s  .  c  o  m
    Display display = parentActivity.getWindowManager().getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT < 13) {
        displaySize.set(display.getWidth(), display.getHeight());
    } else {
        display.getSize(displaySize);
    }
}

From source file:org.telegram.ui.ChatActivity.java

@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    fixLayout();// w ww . ja  v a 2s.  c  o  m

    if (parentActivity != null) {
        Display display = parentActivity.getWindowManager().getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT < 13) {
            displaySize.set(display.getWidth(), display.getHeight());
        } else {
            display.getSize(displaySize);
        }
    }
}

From source file:cc.flydev.launcher.Workspace.java

/**
 * Initializes various states for this workspace.
 *//* w ww. j  av  a  2  s . c  om*/
protected void initWorkspace() {
    Context context = getContext();
    mCurrentPage = mDefaultPage;
    Launcher.setScreen(mCurrentPage);
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setClipChildren(false);
    setClipToPadding(false);
    setChildrenDrawnWithCacheEnabled(true);

    // This is a bit of a hack to account for the fact that we translate the workspace
    // up a bit, and still need to draw the background covering the whole screen.
    setMinScale(mOverviewModeShrinkFactor - 0.2f);
    setupLayoutTransition();

    final Resources res = getResources();
    try {
        mBackground = res.getDrawable(R.drawable.apps_customize_bg);
    } catch (Resources.NotFoundException e) {
        // In this case, we will skip drawing background protection
    }

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);

    mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);
    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

/**
 * Initializes various states for this workspace.
 *//* www .j a  v a  2s .  co m*/
protected void initWorkspace() {
    mCurrentPage = mDefaultPage;
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setClipChildren(false);
    setClipToPadding(false);
    setChildrenDrawnWithCacheEnabled(true);

    setMinScale(mOverviewModeShrinkFactor);
    setupLayoutTransition();

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);

    mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);

    // Set the wallpaper dimensions when Launcher starts up
    setWallpaperDimension();

    setEdgeGlowColor(getResources().getColor(R.color.workspace_edge_effect_color));
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

/**
 * Initializes various states for this workspace.
 *///from   w w w  . ja va2  s  .c om
protected void initWorkspace() {
    Context context = getContext();
    mCurrentPage = mDefaultPage;
    Launcher.setScreen(mCurrentPage);
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setClipChildren(false);
    setClipToPadding(false);
    setChildrenDrawnWithCacheEnabled(true);

    // This is a bit of a hack to account for the fact that we translate the
    // workspace
    // up a bit, and still need to draw the background covering the whole
    // screen.
    setMinScale(mOverviewModeShrinkFactor - 0.2f);
    setupLayoutTransition();

    final Resources res = getResources();
    try {
        mBackground = res.getDrawable(R.drawable.apps_customize_bg);
    } catch (Resources.NotFoundException e) {
        // In this case, we will skip drawing background protection
    }

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);

    mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);
    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
}

From source file:com.cyou.poplauncher.Workspace.java

/**
 * Initializes various states for this workspace.
 */// www.ja  v a  2s.  com
protected void initWorkspace() {
    Context context = getContext();
    mCurrentPage = mDefaultPage;
    Launcher.setScreen(mCurrentPage);
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setClipChildren(false);
    setClipToPadding(false);
    setChildrenDrawnWithCacheEnabled(true);

    setMinScale(mOverviewModeShrinkFactor);
    setupLayoutTransition();

    final Resources res = getResources();
    try {
        mBackground = res.getDrawable(R.drawable.apps_customize_bg);
    } catch (Resources.NotFoundException e) {
        // In this case, we will skip drawing background protection
    }

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);

    mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);
    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);

    // Set the wallpaper dimensions when Launcher starts up
    setWallpaperDimension();
}