Android Open Source - CustomViewPager Helper Class






From Project

Back to project page CustomViewPager.

License

The source code is released under:

Apache License

If you think the Android project CustomViewPager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kgnkbyl.custompager;
//  w  ww  . j  a  va 2s.c  om
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;

public class HelperClass {
  
  private static Point screenSize;
  
  public static int getWindowWidth(Context context){
    if(screenSize == null){
      WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      Display display = wm.getDefaultDisplay();
      screenSize = new Point();
      display.getSize(screenSize);
    }
    if(screenSize != null)
      return screenSize.x;
    else 
      return 0;
  }
  public static int getWindowHeight(Context context){
    if(screenSize == null){
      WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      Display display = wm.getDefaultDisplay();
      screenSize = new Point();
      display.getSize(screenSize);
    }
    if(screenSize != null)
      return screenSize.y;
    else 
      return 0;
  }
  
  public static int getCurrentCardPositionX(Context context){
    float cardWidth = context.getResources().getDimension(R.dimen.card_image_width);
    return (int) (getWindowWidth(context)/2 - cardWidth/2);
  }

}




Java Source Code List

com.kgnkbyl.custompager.CustomPagerAdapter.java
com.kgnkbyl.custompager.CustomPagerBase.java
com.kgnkbyl.custompager.HelperClass.java
com.kgnkbyl.custompager.MainActivity.java