Example usage for android.content.res Resources getDimensionPixelSize

List of usage examples for android.content.res Resources getDimensionPixelSize

Introduction

In this page you can find the example usage for android.content.res Resources getDimensionPixelSize.

Prototype

public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID for use as a size in raw pixels.

Usage

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Configures the floating action button, clipping it to a circle and setting its translation z.
 * @param view The float action button's view.
 * @param res The resources file.//  w  w  w . j a v a2  s. c  o  m
 */
public static void setupFloatingActionButton(View view, Resources res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setOutlineProvider(OVAL_OUTLINE_PROVIDER);
        view.setTranslationZ(res.getDimensionPixelSize(R.dimen.floating_action_button_translation_z));
    }
}

From source file:com.waz.zclient.utils.ViewUtils.java

public static int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    String name = ViewUtils.isInPortrait(context) ? "navigation_bar_height" : "navigation_bar_height_landscape";
    int resourceId = resources.getIdentifier(name, "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }/*from w  ww  .  j  av  a  2 s  .c  o  m*/
    return 0;
}

From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java

public static int getNavBarHeight(Activity activity) {
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    //?NavigationBar
    int height = resources.getDimensionPixelSize(resourceId);
    return height;
}

From source file:Main.java

public static int getNavigationBarHeight(Context c) {
    int result = 0;
    boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey) {
        //The device has a navigation bar
        Resources resources = c.getResources();

        int orientation = resources.getConfiguration().orientation;
        int resourceId;
        if (isTablet(c)) {
            resourceId = resources//  w  ww. jav  a  2  s. c  om
                    .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                            : "navigation_bar_height_landscape", "dimen", "android");
        } else {
            resourceId = resources
                    .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                            : "navigation_bar_width", "dimen", "android");
        }

        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        }
    }
    return result;
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static int NavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int orientation = resources.getConfiguration().orientation;

    int id = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
            : "navigation_bar_height_landscape", "dimen", "android");
    if (id > 0) {
        return resources.getDimensionPixelSize(id);
    }/*from  w  w w .j ava  2 s  . c o m*/
    return 0;
}

From source file:com.linkbubble.util.Util.java

public static Integer getSystemStatusBarHeight(Context context) {
    Integer result = null;// w ww  . ja  v a 2  s.  c  om
    try {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = resources.getDimensionPixelSize(resourceId);
        }
    } catch (Exception e) {
    }

    return result;
}

From source file:com.linkbubble.util.Util.java

public static Integer getSystemNavigationBarHeight(Context context) {
    Integer result = null;/* ww w  .  jav a  2s.  c  om*/
    try {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = resources.getDimensionPixelSize(resourceId);
        }
    } catch (Exception e) {
    }

    return result;
}

From source file:util.Utils.java

/**
 * ???//from   w ww  .  j  a  v  a  2s  .com
 *
 * @param context 
 * @return ??
 */
public static int getStatusBarHeight(Context context) {
    int result = 0;
    Resources res = context.getResources();
    int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }
    return result;
}

From source file:com.syncedsynapse.kore2.utils.UIUtils.java

/**
 * Fills the standard cast info list, consisting of a {@link android.widget.GridLayout}
 * with actor images and a Textview with the name and the role of the additional cast.
 * The number of actor presented on the {@link android.widget.GridLayout} is controlled
 * through the global setting, and only actors with images are presented.
 * The rest are presented in the additionalCastView TextView
 *
 * @param context Activity/*from   w  ww  .j a v a2  s  .  co  m*/
 * @param castList Cast list
 * @param castListView GridLayout on which too show actors that have images
 * @param additionalCastTitleView View with additional cast title
 * @param additionalCastView Additional cast
 */
public static void setupCastInfo(final Context context, List<VideoType.Cast> castList, GridLayout castListView,
        TextView additionalCastTitleView, TextView additionalCastView) {
    HostManager hostManager = HostManager.getInstance(context);
    Resources resources = context.getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);

    View.OnClickListener castListClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openImdbForPerson(context, (String) v.getTag());
        }
    };

    castListView.removeAllViews();
    int numColumns = castListView.getColumnCount();

    int layoutMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.remote_content_hmargin);
    int imageMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin);
    int imageWidth = (displayMetrics.widthPixels - layoutMarginPx - numColumns * imageMarginPx) / numColumns;
    int imageHeight = (int) (imageWidth * 1.2);

    List<VideoType.Cast> noPicturesCastList = new ArrayList<VideoType.Cast>();
    int maxCastPictures = Settings.DEFAULT_MAX_CAST_PICTURES;
    int currentPictureNumber = 0;
    for (int i = 0; i < castList.size(); i++) {
        VideoType.Cast actor = castList.get(i);

        if (((maxCastPictures == -1) || (currentPictureNumber < maxCastPictures))
                && (actor.thumbnail != null)) {
            // Present the picture
            currentPictureNumber++;
            View castView = LayoutInflater.from(context).inflate(R.layout.grid_item_cast, castListView, false);
            ImageView castPicture = (ImageView) castView.findViewById(R.id.picture);
            TextView castName = (TextView) castView.findViewById(R.id.name);
            TextView castRole = (TextView) castView.findViewById(R.id.role);

            castView.getLayoutParams().width = imageWidth;
            castView.getLayoutParams().height = (int) (imageHeight * 1.2);
            castView.setTag(actor.name);
            castView.setOnClickListener(castListClickListener);

            castName.setText(actor.name);
            castRole.setText(actor.role);
            UIUtils.loadImageWithCharacterAvatar(context, hostManager, actor.thumbnail, actor.name, castPicture,
                    imageWidth, imageHeight);
            castListView.addView(castView);
        } else {
            noPicturesCastList.add(actor);
        }
    }

    // Additional cast
    if (noPicturesCastList.size() > 0) {
        additionalCastTitleView.setVisibility(View.VISIBLE);
        additionalCastView.setVisibility(View.VISIBLE);
        StringBuilder castListText = new StringBuilder();
        boolean first = true;
        for (VideoType.Cast cast : noPicturesCastList) {
            if (!first)
                castListText.append("\n");
            first = false;
            if (!TextUtils.isEmpty(cast.role)) {
                castListText.append(
                        String.format(context.getString(R.string.cast_list_text), cast.name, cast.role));
            } else {
                castListText.append(cast.name);
            }
        }
        additionalCastView.setText(castListText);
    } else {
        additionalCastTitleView.setVisibility(View.GONE);
        additionalCastView.setVisibility(View.GONE);
    }
}

From source file:com.google.android.leanbackjank.presenter.GridItemPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);/*from  w  ww .jav  a2s  .  com*/
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ResourcesCompat.getColor(parent.getResources(), R.color.jank_yellow, null));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}