Java Code Examples for android.view.Display#getRefreshRate()

The following examples show how to use android.view.Display#getRefreshRate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataLayout.java    From power-adapters with Apache License 2.0 6 votes vote down vote up
/** Returns whether now is an appropriate time to perform animations. */
private boolean shouldAnimate() {
    if (!mAnimationEnabled) {
        return false;
    }
    Display display = currentDisplay();
    if (display == null) {
        return false;
    }
    if (mVisibleStartTime <= 0) {
        return false;
    }
    long threshold = (long) (1000 / display.getRefreshRate());
    long millisVisible = elapsedRealtime() - mVisibleStartTime;
    return millisVisible > threshold;
}
 
Example 2
Source File: VideoFrameReleaseTimeHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void updateDefaultDisplayRefreshRateParams() {
  // Note: If we fail to update the parameters, we leave them set to their previous values.
  Display defaultDisplay = windowManager.getDefaultDisplay();
  if (defaultDisplay != null) {
    double defaultDisplayRefreshRate = defaultDisplay.getRefreshRate();
    vsyncDurationNs = (long) (C.NANOS_PER_SECOND / defaultDisplayRefreshRate);
    vsyncOffsetNs = (vsyncDurationNs * VSYNC_OFFSET_PERCENTAGE) / 100;
  }
}
 
Example 3
Source File: VideoFrameReleaseTimeHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateDefaultDisplayRefreshRateParams() {
  // Note: If we fail to update the parameters, we leave them set to their previous values.
  Display defaultDisplay = windowManager.getDefaultDisplay();
  if (defaultDisplay != null) {
    double defaultDisplayRefreshRate = defaultDisplay.getRefreshRate();
    vsyncDurationNs = (long) (C.NANOS_PER_SECOND / defaultDisplayRefreshRate);
    vsyncOffsetNs = (vsyncDurationNs * VSYNC_OFFSET_PERCENTAGE) / 100;
  }
}
 
Example 4
Source File: VideoFrameReleaseTimeHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateDefaultDisplayRefreshRateParams() {
  // Note: If we fail to update the parameters, we leave them set to their previous values.
  Display defaultDisplay = windowManager.getDefaultDisplay();
  if (defaultDisplay != null) {
    double defaultDisplayRefreshRate = defaultDisplay.getRefreshRate();
    vsyncDurationNs = (long) (C.NANOS_PER_SECOND / defaultDisplayRefreshRate);
    vsyncOffsetNs = (vsyncDurationNs * VSYNC_OFFSET_PERCENTAGE) / 100;
  }
}
 
Example 5
Source File: FPSFrameMonitor.java    From StickyDecoration with Apache License 2.0 5 votes vote down vote up
public void init(Context context, FrameDataCallback callback) {
    // getInstance our choreographer callback and register it
    fpsFrameCallback = new FPSFrameCallback(fpsConfig, callback);
    Choreographer.getInstance().postFrameCallback(fpsFrameCallback);
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    fpsConfig.deviceRefreshRateInMs = 1000f / display.getRefreshRate();
    fpsConfig.refreshRate = display.getRefreshRate();
}
 
Example 6
Source File: MiscUtils.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the approximate refresh time, in nanoseconds, of the default display associated
 * with the activity.
 * <p>
 * The actual refresh rate can vary slightly (e.g. 58-62fps on a 60fps device).
 */
public static long getDisplayRefreshNsec(Activity activity) {
    Display display = ((WindowManager)
            activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    double displayFps = display.getRefreshRate();
    long refreshNs = Math.round(1000000000L / displayFps);
    Log.d(TAG, "refresh rate is " + displayFps + " fps --> " + refreshNs + " ns");
    return refreshNs;
}
 
Example 7
Source File: VideoFrameReleaseTimeHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updateDefaultDisplayRefreshRateParams() {
  // Note: If we fail to update the parameters, we leave them set to their previous values.
  Display defaultDisplay = windowManager.getDefaultDisplay();
  if (defaultDisplay != null) {
    double defaultDisplayRefreshRate = defaultDisplay.getRefreshRate();
    vsyncDurationNs = (long) (C.NANOS_PER_SECOND / defaultDisplayRefreshRate);
    vsyncOffsetNs = (vsyncDurationNs * VSYNC_OFFSET_PERCENTAGE) / 100;
  }
}
 
Example 8
Source File: MiscUtils.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the approximate refresh time, in nanoseconds, of the default display associated
 * with the activity.
 * <p>
 * The actual refresh rate can vary slightly (e.g. 58-62fps on a 60fps device).
 */
public static long getDisplayRefreshNsec(Activity activity) {
    Display display = ((WindowManager)
            activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    double displayFps = display.getRefreshRate();
    long refreshNs = Math.round(1000000000L / displayFps);
    Log.d(TAG, "refresh rate is " + displayFps + " fps --> " + refreshNs + " ns");
    return refreshNs;
}
 
Example 9
Source File: VideoFrameReleaseTimeHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updateDefaultDisplayRefreshRateParams() {
  // Note: If we fail to update the parameters, we leave them set to their previous values.
  Display defaultDisplay = windowManager.getDefaultDisplay();
  if (defaultDisplay != null) {
    double defaultDisplayRefreshRate = defaultDisplay.getRefreshRate();
    vsyncDurationNs = (long) (C.NANOS_PER_SECOND / defaultDisplayRefreshRate);
    vsyncOffsetNs = (vsyncDurationNs * VSYNC_OFFSET_PERCENTAGE) / 100;
  }
}
 
Example 10
Source File: FrameRateTracker.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The natural screen refresh rate, in hertz. May not always return the same value if a display
 * has a dynamic refresh rate.
 */
public static float getDisplayRefreshRate(@NonNull Context context) {
  Display display = ServiceUtil.getWindowManager(context).getDefaultDisplay();
  return display.getRefreshRate();
}
 
Example 11
Source File: FPSBuilder.java    From Animer with Apache License 2.0 4 votes vote down vote up
/**
 * configures the fpsConfig to the device's hardware
 * refreshRate ex. 60fps and deviceRefreshRateInMs ex. 16.6ms
 * @param context
 */
private void setFrameRate(Context context){
    Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    fpsConfig.deviceRefreshRateInMs = 1000f/display.getRefreshRate();
    fpsConfig.refreshRate = display.getRefreshRate();
}
 
Example 12
Source File: TinyDancerBuilder.java    From TinyDancer with MIT License 4 votes vote down vote up
/**
 * configures the fpsConfig to the device's hardware
 * refreshRate ex. 60fps and deviceRefreshRateInMs ex. 16.6ms
 * @param context
 */
private void setFrameRate(Context context){
    Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    fpsConfig.deviceRefreshRateInMs = 1000f/display.getRefreshRate();
    fpsConfig.refreshRate = display.getRefreshRate();
}