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:android.support.v7.app.NotificationCompatImplBase.java

private static RemoteViews applyStandardTemplate(Context context, CharSequence contentTitle,
        CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText,
        boolean useChronometer, long when, int resId, boolean fitIn1U) {
    RemoteViews contentView = new RemoteViews(context.getPackageName(), resId);
    boolean showLine3 = false;
    boolean showLine2 = false;

    // On versions before Jellybean, the large icon was shown by SystemUI, so we need to hide
    // it here.//ww w  .java2s.c o m
    if (largeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        contentView.setViewVisibility(R.id.icon, View.VISIBLE);
        contentView.setImageViewBitmap(R.id.icon, largeIcon);
    } else {
        contentView.setViewVisibility(R.id.icon, View.GONE);
    }
    if (contentTitle != null) {
        contentView.setTextViewText(R.id.title, contentTitle);
    }
    if (contentText != null) {
        contentView.setTextViewText(R.id.text, contentText);
        showLine3 = true;
    }
    if (contentInfo != null) {
        contentView.setTextViewText(R.id.info, contentInfo);
        contentView.setViewVisibility(R.id.info, View.VISIBLE);
        showLine3 = true;
    } else if (number > 0) {
        final int tooBig = context.getResources().getInteger(R.integer.status_bar_notification_info_maxnum);
        if (number > tooBig) {
            contentView.setTextViewText(R.id.info,
                    context.getResources().getString(R.string.status_bar_notification_info_overflow));
        } else {
            NumberFormat f = NumberFormat.getIntegerInstance();
            contentView.setTextViewText(R.id.info, f.format(number));
        }
        contentView.setViewVisibility(R.id.info, View.VISIBLE);
        showLine3 = true;
    } else {
        contentView.setViewVisibility(R.id.info, View.GONE);
    }

    // Need to show three lines? Only allow on Jellybean+
    if (subText != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        contentView.setTextViewText(R.id.text, subText);
        if (contentText != null) {
            contentView.setTextViewText(R.id.text2, contentText);
            contentView.setViewVisibility(R.id.text2, View.VISIBLE);
            showLine2 = true;
        } else {
            contentView.setViewVisibility(R.id.text2, View.GONE);
        }
    }

    // RemoteViews.setViewPadding and RemoteViews.setTextViewTextSize is not available on ICS-
    if (showLine2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (fitIn1U) {
            // need to shrink all the type to make sure everything fits
            final Resources res = context.getResources();
            final float subTextSize = res.getDimensionPixelSize(R.dimen.notification_subtext_size);
            contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
        }
        // vertical centering
        contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
    }

    if (when != 0) {
        if (useChronometer) {
            contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
            contentView.setLong(R.id.chronometer, "setBase",
                    when + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
            contentView.setBoolean(R.id.chronometer, "setStarted", true);
        } else {
            contentView.setViewVisibility(R.id.time, View.VISIBLE);
            contentView.setLong(R.id.time, "setTime", when);
        }
    }
    contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
    return contentView;
}

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * get the height of NavigationBar/*from   w w  w . j av  a 2s. c om*/
 */

public static int getNavigationBarHeight(Activity mActivity) {
    Resources resources = mActivity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    int height = resources.getDimensionPixelSize(resourceId);
    return height;
}

From source file:com.xxxifan.devbox.core.util.ViewUtils.java

private static int readInternalDimen(String key, Resources res, int fallback) {
    int resourceId = res.getIdentifier(key, "dimen", "android");
    return resourceId > 0 ? res.getDimensionPixelSize(resourceId) : fallback;
}

From source file:Main.java

/**
 * Resize a {@link Drawable} to the given size.<br />
 * Metrics and density are given by the {@link Resources} bount to this instance.
 * @param ctx Context./*from  w  w w  .ja v a 2 s .c  om*/
 * @param drawable {@link Drawable} to resize.
 * @param widthId Reference to the dimension containing the desired width.
 * @param heightId Reference to the dimension containing the desired height.
 * @return A scaled {@link Drawable}.
 */
public static Drawable resizeDrawable(Context ctx, Drawable drawable, int widthId, int heightId) {
    Resources res = ctx.getResources();
    //float density = res.getDisplayMetrics().density;

    //Get a bitmap from the drawable
    Bitmap bmp = drawableToBitmap(drawable);

    //Create a scaled bitmap
    //      bmp = Bitmap.createScaledBitmap(
    //            bmp,
    //            (int)(width * density),
    //            (int)(height * density),
    //            true);
    bmp = Bitmap.createScaledBitmap(bmp, res.getDimensionPixelSize(widthId),
            res.getDimensionPixelSize(heightId), true);

    //Convert bitmap to drawable
    return new BitmapDrawable(res, bmp);
}

From source file:com.android.mail.browse.ConversationItemViewCoordinates.java

@SuppressLint("NewApi")
private static void setFramePadding(Context context, ViewGroup view, boolean useFullPadding) {
    final Resources res = context.getResources();
    final int padding = res.getDimensionPixelSize(
            useFullPadding ? R.dimen.conv_list_card_border_padding : R.dimen.conv_list_no_border_padding);

    final View frame = view.findViewById(R.id.conversation_item_frame);
    if (Utils.isRunningJBMR1OrLater()) {
        // start, top, end, bottom
        frame.setPaddingRelative(frame.getPaddingStart(), padding, frame.getPaddingEnd(), padding);
    } else {//from   w w  w. ja v  a  2  s  .  c  o  m
        frame.setPadding(frame.getPaddingLeft(), padding, frame.getPaddingRight(), padding);
    }
}

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

/**
 * Adds padding to the bottom of the given {@link android.widget.ListView} so that the floating action button
 * does not obscure any content./*from  ww  w  . ja  v a  2  s.com*/
 *
 * @param listView to add the padding to
 * @param res valid resources object
 */
public static void addBottomPaddingToListViewForFab(ListView listView, Resources res) {
    final int fabPadding = res.getDimensionPixelSize(R.dimen.floating_action_button_list_bottom_padding);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        listView.setPaddingRelative(listView.getPaddingStart(), listView.getPaddingTop(),
                listView.getPaddingEnd(), listView.getPaddingBottom() + fabPadding);
    else
        listView.setPadding(listView.getPaddingLeft(), listView.getPaddingTop(), listView.getPaddingRight(),
                listView.getPaddingBottom() + fabPadding);

    listView.setClipToPadding(false);
}

From source file:com.simas.vc.helpers.Utils.java

public static int getNavigationBarHeight() {
    Resources resources = VC.getAppContext().getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }/*from w w  w.  j av  a2s.c o  m*/
    return 0;
}

From source file:ca.frozen.curlingtv.classes.Utils.java

public static int getNavigationBarHeight(Context context, int orientation) {
    Resources resources = context.getResources();
    String name = orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
            : "navigation_bar_height_landscape";
    int id = resources.getIdentifier(name, "dimen", "android");
    return (id > 0) ? resources.getDimensionPixelSize(id) : 0;
}

From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java

/**
 * Creates the rounded icon generator to use for notifications based on the dimensions
 * and resolution of the device we're running on.
 *
 * @param appContext The application context to retrieve resources from.
 * @return The newly created rounded icon generator.
 *///w  w w. j a v  a 2  s.  c om
@VisibleForTesting
public static RoundedIconGenerator createRoundedIconGenerator(Context appContext) {
    Resources res = appContext.getResources();
    float density = res.getDisplayMetrics().density;

    int widthPx = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
    int heightPx = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);

    return new RoundedIconGenerator(widthPx, heightPx, Math.min(widthPx, heightPx) / 2,
            NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_TEXT_SIZE_DP * density);
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

public static void statusBarHeight(Resources resources, View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            int statusBarHeight = resources.getDimensionPixelSize(resourceId);
            if (statusBarHeight > 0) {
                view.setLayoutParams(//from ww w .ja v  a  2  s  . c o  m
                        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, statusBarHeight));
            }
        }
    } else {
        view.setVisibility(View.GONE);
    }
}