Example usage for android.content.res Resources getDimension

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

Introduction

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

Prototype

public float getDimension(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID.

Usage

From source file:cx.ring.model.Conference.java

public void showCallNotification(Context ctx) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx);
    notificationManager.cancel(notificationId);

    if (getParticipants().isEmpty())
        return;/* w  ww .java2s  .  c o  m*/
    SipCall call = getParticipants().get(0);
    CallContact contact = call.getContact();
    final Uri call_uri = Uri.withAppendedPath(SipCall.CONTENT_URI, call.getCallId());
    PendingIntent goto_intent = PendingIntent.getActivity(ctx, new Random().nextInt(), getViewIntent(ctx),
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder noti = new NotificationCompat.Builder(ctx);
    if (isOnGoing()) {
        noti.setContentTitle(ctx.getString(R.string.notif_current_call_title, contact.getDisplayName()))
                .setContentText(ctx.getText(R.string.notif_current_call)).setContentIntent(goto_intent)
                .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup),
                        PendingIntent.getService(
                                ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END)
                                        .setClass(ctx, LocalService.class).setData(call_uri),
                                PendingIntent.FLAG_ONE_SHOT));
    } else if (isRinging()) {
        if (isIncoming()) {
            noti.setContentTitle(ctx.getString(R.string.notif_incoming_call_title, contact.getDisplayName()))
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setContentText(ctx.getText(R.string.notif_incoming_call)).setContentIntent(goto_intent)
                    .setFullScreenIntent(goto_intent, true)
                    .addAction(R.drawable.ic_action_accept, ctx.getText(R.string.action_call_accept),
                            PendingIntent.getService(ctx, new Random().nextInt(),
                                    new Intent(LocalService.ACTION_CALL_ACCEPT)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT))
                    .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_decline),
                            PendingIntent.getService(ctx, new Random().nextInt(),
                                    new Intent(LocalService.ACTION_CALL_REFUSE)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT));
        } else {
            noti.setContentTitle(ctx.getString(R.string.notif_outgoing_call_title, contact.getDisplayName()))
                    .setContentText(ctx.getText(R.string.notif_outgoing_call)).setContentIntent(goto_intent)
                    .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup),
                            PendingIntent.getService(
                                    ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT));
        }

    } else {
        notificationManager.cancel(notificationId);
        return;
    }

    noti.setOngoing(true).setCategory(NotificationCompat.CATEGORY_CALL).setSmallIcon(R.drawable.ic_launcher);

    if (contact.getPhoto() != null) {
        Resources res = ctx.getResources();
        int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
        int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
        noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false));
    }
    notificationManager.notify(notificationId, noti.build());
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

public CollectionListAdapter(Activity activity, @Nullable List<Collection> colList,
        @Nullable Callback callback) {
    final Resources resources = activity.getResources();
    mMaxHeight = resources.getDimension(R.dimen.list_item_max_content)
            - resources.getDimension(R.dimen.row_vertical_padding);
    final View content = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    mMaxWidth = content.getWidth() - 2 * resources.getDimension(R.dimen.page_vertical_margin);

    if (colList != null) {
        setColList(colList);/* w  w w .ja  va 2  s  . com*/
    }
    setCallback(callback);
}

From source file:com.cls.sugutomo.map.ClusterOP.java

public ClusterOP(Resources resources) {
    baseBitmaps = new Bitmap[res.length];
    for (int i = 0; i < res.length; i++) {
        baseBitmaps[i] = BitmapFactory.decodeResource(resources, res[i]);
    }/*from ww w.  j a v a  2  s  . c  o m*/
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    paint.setTextSize(resources.getDimension(R.dimen.text_size));
}

From source file:sk.ab.herbs.billingmodule.skulist.AcquireFragment.java

private void addSkuRows(final List<SkuRowData> inList, List<String> skusList, final @SkuType String billingType,
        final Runnable executeWhenFinished) {

    mBillingProvider.getBillingManager().querySkuDetailsAsync(billingType, skusList,
            new SkuDetailsResponseListener() {
                @Override/*from ww w. ja  v  a2s .c o  m*/
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {

                    if (responseCode != BillingResponse.OK) {
                        Log.w(TAG, "Unsuccessful query for type: " + billingType + ". Error code: "
                                + responseCode);
                    } else if (skuDetailsList != null && skuDetailsList.size() > 0) {
                        // If we successfully got SKUs, add a header in front of the row
                        @StringRes
                        int stringRes = (billingType == SkuType.INAPP) ? R.string.header_inapp
                                : R.string.header_subscriptions;
                        inList.add(new SkuRowData(getString(stringRes)));
                        // Then fill all the other rows
                        for (SkuDetails details : skuDetailsList) {
                            Log.i(TAG, "Adding sku: " + details);
                            inList.add(new SkuRowData(details, SkusAdapter.TYPE_NORMAL, billingType));
                        }

                        if (inList.size() == 0) {
                            displayAnErrorIfNeeded();
                        } else {
                            if (mRecyclerView.getAdapter() == null) {
                                mRecyclerView.setAdapter(mAdapter);
                                Resources res = getContext().getResources();
                                mRecyclerView.addItemDecoration(new CardsWithHeadersDecoration(mAdapter,
                                        (int) res.getDimension(R.dimen.header_gap),
                                        (int) res.getDimension(R.dimen.row_gap)));
                                mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                            }

                            mAdapter.updateData(inList);
                            setWaitScreen(false);
                        }

                    }

                    if (executeWhenFinished != null) {
                        executeWhenFinished.run();
                    }
                }
            });
}

From source file:com.android.messaging.datamodel.BugleNotifications.java

private static void checkInitialized() {
    if (!sInitialized) {
        final Resources resources = Factory.get().getApplicationContext().getResources();
        sWearableImageWidth = resources.getDimensionPixelSize(R.dimen.notification_wearable_image_width);
        sWearableImageHeight = resources.getDimensionPixelSize(R.dimen.notification_wearable_image_height);
        sIconHeight = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
        sIconWidth = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);

        sInitialized = true;/* ww  w . java 2  s  .c om*/
    }
}

From source file:com.github.amlcurran.showcaseview.StandardShowcaseDrawer.java

public StandardShowcaseDrawer(Resources resources, Resources.Theme theme) {
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY);
    eraserPaint = new Paint();
    eraserPaint.setColor(0xFFFFFF);/*from www  .  j  a v  a  2s  .  c om*/
    eraserPaint.setAlpha(0);
    eraserPaint.setXfermode(xfermode);
    eraserPaint.setAntiAlias(true);
    basicPaint = new Paint();
    showcaseRadius = resources.getDimension(R.dimen.showcase_radius);
    showcaseDrawable = ResourcesCompat.getDrawable(resources, R.drawable.cling_bleached, theme);
}

From source file:kr.kdev.dg1s.biowiki.util.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   www .  j  a v  a2  s.c o  m*/

    final Resources res = getResources();

    mCentered = true;
    mLineWidth = res.getDimension(R.dimen.page_indicator_line_width);
    mGapWidth = res.getDimension(R.dimen.page_indicator_gap_width);
    setStrokeWidth(res.getDimension(R.dimen.page_indicator_stroke_width));
    mPaintUnselected.setColor(res.getColor(R.color.page_indicator_unselected_color));
    mPaintSelected.setColor(res.getColor(R.color.page_indicator_selected_color));

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:org.jitsi.impl.androidtray.AndroidPopup.java

/**
 * Builds notification and returns the builder object which can be used to
 * extend the notification./*w  w  w .j a  v a 2s. c  o  m*/
 * @return builder object describing current notification.
 */
NotificationCompat.Builder buildNotification() {
    Context ctx = JitsiApplication.getGlobalContext();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setSmallIcon(smallIcon)
            .setContentTitle(popupMessage.getMessageTitle()).setContentText(getMessage()).setAutoCancel(true)// will be cancelled once clciked
            .setVibrate(new long[] {}) // no vibration
            .setSound(null); // no sound

    // Big view comes with API11
    if (AndroidUtils.hasAPI(11)) {
        Resources res = JitsiApplication.getAppResources();

        // Preferred size
        int prefWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
        int prefHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);

        // Use popup icon if any
        Bitmap iconBmp = null;
        byte[] icon = popupMessage.getIcon();
        if (icon != null) {
            iconBmp = AndroidImageUtil.scaledBitmapFromBytes(icon, prefWidth, prefHeight);
        }

        // Set default avatar
        if (iconBmp == null && contact != null) {
            iconBmp = AndroidImageUtil.scaledBitmapFromResource(res, R.drawable.avatar, prefWidth, prefHeight);
        }

        if (iconBmp != null) {
            if (iconBmp.getWidth() > prefWidth || iconBmp.getHeight() > prefHeight) {
                iconBmp = Bitmap.createScaledBitmap(iconBmp, prefWidth, prefHeight, true);
            }

            builder.setLargeIcon(iconBmp);
        }

        // Build inbox style
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        onBuildInboxStyle(inboxStyle);
        builder.setStyle(inboxStyle);
    }

    return builder;
}

From source file:neu.showcaseview.StandardShowcaseDrawer.java

public StandardShowcaseDrawer(Resources resources, Resources.Theme theme, float factor) {
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY);
    eraserPaint = new Paint();
    eraserPaint.setColor(0xFFFFFF);/*w ww  . ja va2  s  .co m*/
    eraserPaint.setAlpha(0);
    eraserPaint.setXfermode(xfermode);
    eraserPaint.setAntiAlias(true);
    basicPaint = new Paint();
    this.factor = factor;
    showcaseRadius = resources.getDimension(R.dimen.showcase_radius) * factor;
    showcaseDrawable = ResourcesCompat.getDrawable(resources, R.drawable.cling_bleached, theme);
}

From source file:nl.atcomputing.refcard.tabs.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from w w w .  j  a v  a 2  s .  c  om*/
 */
protected TextView createDefaultTabView(Context context) {
    Resources resources = getResources();
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.textSizeSmall));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(resources.getColor(R.color.atwhite_secondarytext));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    //            // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
    //            textView.setAllCaps(true);
    //        }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * resources.getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}