Example usage for android.view Display getRefreshRate

List of usage examples for android.view Display getRefreshRate

Introduction

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

Prototype

public float getRefreshRate() 

Source Link

Document

Gets the refresh rate of this display in frames per second.

Usage

From source file:com.fallahpoor.infocenter.fragments.ScreenFragment.java

private String getRefreshRate(Display display) {

    return String.format(Utils.getLocale(), "%.0f %s", display.getRefreshRate(),
            getString(R.string.scr_sub_item_hertz));

}

From source file:org.acra.collector.DisplayManagerCollector.java

@NonNull
private Object collectDisplayData(@NonNull Display display) {
    final DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);/*from  www.  j  a v  a  2  s  .  c  o  m*/

    //noinspection deprecation
    return collectCurrentSizeRange(display) + collectFlags(display) + display.getDisplayId() + ".height="
            + display.getHeight() + '\n' + collectMetrics(display) + collectName(display)
            + display.getDisplayId() + ".orientation=" + display.getRotation() + '\n' + display.getDisplayId()
            + ".pixelFormat=" + display.getPixelFormat() + '\n' + collectRealMetrics(display)
            + collectRealSize(display) + collectRectSize(display) + display.getDisplayId() + ".refreshRate="
            + display.getRefreshRate() + '\n' + collectRotation(display) + collectSize(display)
            + display.getDisplayId() + ".width=" + display.getWidth() + '\n' + collectIsValid(display);
}

From source file:me.wimanacra.collector.DisplayManagerCollector.java

@NonNull
private JSONObject collectDisplayData(@NonNull Display display) throws JSONException {
    final DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);//from   ww  w.  j  ava 2  s  . c o m

    final JSONObject result = new JSONObject();
    collectCurrentSizeRange(display, result);
    collectFlags(display, result);
    collectMetrics(display, result);
    collectRealMetrics(display, result);
    collectName(display, result);
    collectRealSize(display, result);
    collectRectSize(display, result);
    collectSize(display, result);
    collectRotation(display, result);
    collectIsValid(display, result);
    result.put("orientation", display.getRotation()).put("refreshRate", display.getRefreshRate());
    //noinspection deprecation
    result.put("height", display.getHeight()).put("width", display.getWidth()).put("pixelFormat",
            display.getPixelFormat());
    return result;
}

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);/*from w w w. ja v  a 2 s  . c o m*/
    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;
    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)/*ww w.jav  a 2s  .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.ferdi2005.secondgram.support.widget.RecyclerView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mLayoutOrScrollCounter = 0;//  www . j  av a 2s .c o  m
    mIsAttached = true;
    mFirstLayoutComplete = mFirstLayoutComplete && !isLayoutRequested();
    if (mLayout != null) {
        mLayout.dispatchAttachedToWindow(this);
    }
    mPostedAnimatorRunner = false;

    if (ALLOW_THREAD_GAP_WORK) {
        // Register with gap worker
        mGapWorker = GapWorker.sGapWorker.get();
        if (mGapWorker == null) {
            mGapWorker = new GapWorker();

            // break 60 fps assumption if data from display appears valid
            // NOTE: we only do this query once, statically, because it's very expensive (> 1ms)
            Display display = ViewCompat.getDisplay(this);
            float refreshRate = 60.0f;
            if (!isInEditMode() && display != null) {
                float displayRefreshRate = display.getRefreshRate();
                if (displayRefreshRate >= 30.0f) {
                    refreshRate = displayRefreshRate;
                }
            }
            mGapWorker.mFrameIntervalNs = (long) (1000000000 / refreshRate);
            GapWorker.sGapWorker.set(mGapWorker);
        }
        mGapWorker.add(this);
    }
}