Example usage for android.graphics Point Point

List of usage examples for android.graphics Point Point

Introduction

In this page you can find the example usage for android.graphics Point Point.

Prototype

public Point() 

Source Link

Usage

From source file:Main.java

public static int[] getScreenSize(Context context, boolean useDeviceSize) {

    int[] size = new int[2];

    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();//  w  w  w.jav a  2 s .com
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;

    if (!useDeviceSize) {
        size[0] = widthPixels;
        size[1] = heightPixels - getStatusBarHeight(context);

        return size;
    }

    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            widthPixels = realSize.x;
            heightPixels = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = widthPixels;
    size[1] = heightPixels;
    return size;
}

From source file:Main.java

public static int[] getRealScreenSize(Context context) {

    int[] size = new int[2];

    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();// ww  w .jav  a 2  s . c om
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);

    // since SDK_INT = 1;
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
        try {
            widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    } else if (Build.VERSION.SDK_INT >= 17) {// includes window decorations (statusbar bar/menu bar)
        Point realSize = new Point();
        d.getRealSize(realSize);
        widthPixels = realSize.x;
        heightPixels = realSize.y;
    }

    size[0] = widthPixels;
    size[1] = heightPixels;
    return size;
}

From source file:Main.java

/**
 * Calculate displey size./*from  w ww  .  j a  v  a2 s .c om*/
 * @param context Context.
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private static void calculateDisplaySize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point screenSize = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(screenSize);

        displayWidth = screenSize.x;
        displayHeight = screenSize.y;
    } else {
        displayWidth = display.getWidth();
        displayHeight = display.getHeight();
    }
}

From source file:Main.java

/**
 * Compute the minimum cache size for a view. When the cache is created we do not actually
 * know the size of the mapview, so the screenRatio is an approximation of the required size.
 *
 * @param c              the context//from   w ww .  j ava2  s. c  o  m
 * @param tileSize       the tile size
 * @param overdrawFactor the overdraw factor applied to the mapview
 * @param screenRatio    the part of the screen the view covers
 * @return the minimum cache size for the view
 */
@SuppressWarnings("deprecation")
@TargetApi(13)
public static int getMinimumCacheSize(Context c, int tileSize, double overdrawFactor, float screenRatio) {
    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int height;
    int width;
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point p = new Point();
        display.getSize(p);
        height = p.y;
        width = p.x;
    } else {
        // deprecated since Android 13
        height = display.getHeight();
        width = display.getWidth();
    }

    // height  * overdrawFactor / tileSize calculates the number of tiles that would cover
    // the view port, adding 1 is required since we can have part tiles on either side,
    // adding 2 adds another row/column as spare and ensures that we will generally have
    // a larger number of tiles in the cache than a TileLayer will render for a view.
    // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part
    // of a screen (the result can be too low if a MapView is very narrow).
    // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the
    // middle of a view.
    return (int) Math.max(4, screenRatio * (2 + (height * overdrawFactor / tileSize))
            * (2 + (width * overdrawFactor / tileSize)));
}

From source file:com.achillesrasquinha.biblegenerator.ImageGenerator.java

public ImageGenerator(Context context) {
    mContext = context;//from  w  ww  .  j a  v  a 2  s.co  m

    DisplayMetrics m = mContext.getResources().getDisplayMetrics();

    mImageSize = new Point();
    mImageSize.x = m.widthPixels;
    mImageSize.y = mImageSize.x;

    mX = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, m));
    mSizeTitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 24, m);
    mYTitle = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, m) + mSizeTitle);
    mSizeSubtitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, m);
    mYSubtitle = Math
            .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, m) + mYTitle + mSizeSubtitle);
    mLineSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, m);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextAlign(TextPaint.Align.LEFT);
    mTextPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto/Roboto-Medium.ttf"));

    mColor1 = ContextCompat.getColor(mContext, R.color.primary_text_default_material_light);
    mColor2 = ContextCompat.getColor(mContext, R.color.primary_text_disabled_material_light);
    mColor3 = ContextCompat.getColor(mContext, R.color.secondary_text_default_material_light);
}

From source file:com.jerrellmardis.amphitheatre.util.Utils.java

/**
 * Returns the screen/display size/*  www .  j  a v a  2  s  .  c o m*/
 *
 * @param context
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    return new Point(width, height);
}

From source file:com.feigdev.fourcolumngv.FourColumnGridViewActivity.java

/** Called when the activity is first created. */
@Override/*w  w  w.  j  av a2s  .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    GridView g = (GridView) findViewById(R.id.myGrid);
    g.setAdapter(new ImageAdapter(this));

    Display display = getWindowManager().getDefaultDisplay();
    imgSize = new Point();
    imgSize.set((display.getWidth()) / 4, (display.getWidth()) / 4);

}

From source file:com.in.mobile.gesture.ad.AdMechanism.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ad_mechanism);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }/*from   ww w.  j a  v  a  2 s.com*/

    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    new AdContentLoader(frameLayout, size, this);

    GCMRegistrar.checkManifest(this);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(Commons.DISPLAY_MESSAGE_ACTION));

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                GCMRegistrar.register(getApplicationContext(), Commons.SENDER_ID);
            } catch (Exception e) {
                Log.e("AdMechanism - onCreate", e.toString());
            }
        }
    });

    thread.start();

    // extract to sdcard
    // extractDatabaseFile(new DatabaseCommons());

}

From source file:com.example.toolbar.view.MultiViewPager.java

public MultiViewPager(Context context) {
    super(context);
    size = new Point();
    maxSize = new Point();
}

From source file:com.example.sortgame3.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mainAct = this;
    start = false;//  w  w  w.java2s  . c om
    SoundPlayer.initSounds(this);
    SoundPlayer.playSoundMedia(this, R.raw.cephalopod);
    showWelcome();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    Point screenSize = new Point();
    getWindowManager().getDefaultDisplay().getSize(screenSize);
    screenWidth = screenSize.x;
    screenHeight = screenSize.y;
    game = new Game(gameWidth, gameHeight, this);

    coordTrans = new CoordinateTranslator(screenWidth, screenHeight, gameWidth, gameHeight, new Point(0, 0));
    mGLView = new Vizualization(this, game);
    setContentView(mGLView);

    detector = new GestureDetectorCompat(this, new SimpleListener());

}