Android Screen Size Get getScreenSize(@Nonnull Context context)

Here you can find the source of getScreenSize(@Nonnull Context context)

Description

Retrieves the screen size category for the device's default display from the Configuration values.

License

Apache License

Parameter

Parameter Description
context The Context to use to retrieve the WindowManager

Return

The retrieved screen size configuration, can be one of , , , (use the int 4 for this configuration, constant available only from API 11)

Declaration

public static int getScreenSize(@Nonnull Context context) 

Method Source Code

//package com.java2s;
/*/*w  ww. j  a v a2 s  .c o  m*/
 * Copyright 2013 Luluvise Ltd
 * Copyright 2013 Marco Salis - fast3r(at)gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.annotation.Nonnull;

import android.content.Context;

import android.content.res.Configuration;

public class Main {
    /**
     * Retrieves the screen size category for the device's default display from
     * the {@link Configuration} values.
     * 
     * @param context
     *            The {@link Context} to use to retrieve the
     *            {@link WindowManager}
     * @return The retrieved screen size configuration, can be one of
     *         {@link Configuration#SCREENLAYOUT_SIZE_SMALL},
     *         {@link Configuration#SCREENLAYOUT_SIZE_NORMAL},
     *         {@link Configuration#SCREENLAYOUT_SIZE_LARGE},
     *         {@link Configuration#SCREENLAYOUT_SIZE_XLARGE} (<b>use the int 4
     *         for this configuration, constant available only from API 11</b>)
     */
    public static int getScreenSize(@Nonnull Context context) {
        final Configuration conf = context.getResources()
                .getConfiguration();
        return conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    }
}

Related

  1. getScreenWidth(Context context)
  2. getScreenWidth(Display display)
  3. getScreenSizePixels(Context ctx)
  4. getRealScreenDimensions(Context context)
  5. getScreenHeight(Context context)
  6. getScreenWidth(Context context)
  7. getScreenDensity(Context context)
  8. getScreenSize(Activity ctx)
  9. getScreenSize(Context context)