Example usage for android.widget RemoteViews setViewPadding

List of usage examples for android.widget RemoteViews setViewPadding

Introduction

In this page you can find the example usage for android.widget RemoteViews setViewPadding.

Prototype

public void setViewPadding(int viewId, int left, int top, int right, int bottom) 

Source Link

Document

Equivalent to calling android.view.View#setPadding(int,int,int,int) .

Usage

From source file:Main.java

/**
 * Sets the view padding for View with viewId of RemoveViews views.
 * Will only work from JELLY_BEAN.//from   w w w.j  av a  2s  .c o m
 * <p>
 * @param views The RemoteViews that contains viewId to set the padding for.
 * @param viewId The viewId to set the padding for
 * @param left Left padding in pixels.
 * @param top Top padding in pixels.
 * @param right Right padding in pixels.
 * @param bottom Bottom padding in pixels.
 */
public static final void setRemoteViewsPadding(RemoteViews views, int viewId, int left, int top, int right,
        int bottom) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        views.setViewPadding(viewId, left, top, right, bottom);
    }
}

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./* w w w  .  j a v a 2  s  .  com*/
    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;
}