Example usage for android.content.res Resources getDimensionPixelOffset

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

Introduction

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

Prototype

public int getDimensionPixelOffset(@DimenRes int id) throws NotFoundException 

Source Link

Document

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

Usage

From source file:edu.hawaii.android.datetimepickermaterial.date.MonthView.java

public MonthView(Context context, AttributeSet attr) {
    super(context, attr);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

    mDayTextColor = res.getColor(R.color.date_picker_text_normal);
    mTodayNumberColor = res.getColor(R.color.green);
    mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled);
    mMonthTitleColor = res.getColor(R.color.white);
    mMonthTitleBGColor = res.getColor(R.color.circle_background);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - getMonthHeaderSize())
            / MAX_NUM_ROWS;//from  w w  w  .  ja v a2s.c o  m

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.superchat.date.MonthView.java

public MonthView(Context context, AttributeSet attr) {
    super(context, attr);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

    mDayTextColor = res.getColor(R.color.date_picker_text_normal);
    mTodayNumberColor = res.getColor(R.color.blue);
    mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled);
    mMonthTitleColor = res.getColor(android.R.color.white);
    mMonthTitleBGColor = res.getColor(R.color.circle_background);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - getMonthHeaderSize())
            / MAX_NUM_ROWS;/*from  w w w  .j  a  v  a  2  s.  c om*/

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java

@Nullable
@Override//from   w ww  .  j a va  2  s  . co  m
public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_download, container, false);

    View content = ViewUtils.$$(view, R.id.content);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view);
    FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(content, tip);

    Context context = getContext2();
    Assert.assertNotNull(content);
    Resources resources = context.getResources();

    Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new DownloadAdapter();
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
    mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.hasFixedSize();
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
    mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener());
    // Cancel change animation
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }
    int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH,
            paddingV);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    if (mInitPosition >= 0) {
        mRecyclerView.scrollToPosition(mInitPosition);
        mInitPosition = -1;
    }

    fastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable handlerDrawable = new HandlerDrawable();
    handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
    fastScroller.setHandlerDrawable(handlerDrawable);
    fastScroller.setOnDragHandlerListener(this);

    mFabLayout.setExpanded(false, false);
    mFabLayout.setHidePrimaryFab(true);
    mFabLayout.setAutoCancel(false);
    mFabLayout.setOnClickFabListener(this);
    addAboveSnackView(mFabLayout);

    updateView();

    guide();

    return view;
}

From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *///from  www . j  a v a2  s  .c  om
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap();

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);

    if (overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(ContextCompat.getColor(mContext, R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f,
                ContextCompat.getColor(mContext, R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight());
    int iconWidth = icon.getWidth();
    dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
    canvas.drawBitmap(phoneIcon, src, dst, photoPaint);

    canvas.setBitmap(null);

    return icon;
}

From source file:com.mattfred.betterpickers.calendardatepicker.MonthView.java

public MonthView(Context context) {
    super(context);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

    mDayTextColorEnabled = res.getColor(R.color.date_picker_text_normal);
    mDayTextColorDisabled = res.getColor(R.color.date_picker_text_disabled);
    mTodayNumberColor = res.getColor(R.color.bpBlue);
    mDisabledDayColor = res.getColor(R.color.bpDarker_red);
    mMonthTitleColor = res.getColor(R.color.date_picker_text_normal);
    mMonthTitleBGColor = res.getColor(R.color.circle_background);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - MONTH_HEADER_SIZE)
            / MAX_NUM_ROWS;//from   w w  w  .  j  av a 2 s . co  m

    // Set up accessibility components.
    mTouchHelper = new MonthViewTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

From source file:jp.seesaa.android.datetimepicker.date.MonthView.java

public MonthView(Context context, AttributeSet attr) {
    super(context, attr);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.dtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.dtp_sans_serif);

    mDayTextColor = res.getColor(R.color.dtp_date_picker_text_normal);
    mTodayNumberColor = res.getColor(R.color.dtp_blue);
    mDisabledDayTextColor = res.getColor(R.color.dtp_date_picker_text_disabled);
    mMonthTitleColor = res.getColor(R.color.dtp_white);
    mMonthTitleBGColor = res.getColor(R.color.dtp_circle_background);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.dtp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.dtp_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.dtp_date_picker_view_animator_height)
            - getMonthHeaderSize()) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;//from w ww  .j  ava  2 s .  co  m

    // Sets up any standard paints that will be used
    initView();
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

/**
 * Display the tv show details/*from  w w  w .j  a v a2s.c  om*/
 *
 * @param cursor Cursor with the data
 */
private void displayTVShowDetails(Cursor cursor) {
    LogUtils.LOGD(TAG, "displayTVShowDetails");
    cursor.moveToFirst();
    tvshowTitle = cursor.getString(TVShowDetailsQuery.TITLE);
    mediaTitle.setText(tvshowTitle);
    int numEpisodes = cursor.getInt(TVShowDetailsQuery.EPISODE),
            watchedEpisodes = cursor.getInt(TVShowDetailsQuery.WATCHEDEPISODES);
    setMediaUndertitle(numEpisodes, watchedEpisodes);

    setMediaPremiered(cursor.getString(TVShowDetailsQuery.PREMIERED),
            cursor.getString(TVShowDetailsQuery.STUDIO));

    mediaGenres.setText(cursor.getString(TVShowDetailsQuery.GENRES));

    setMediaRating(cursor.getDouble(TVShowDetailsQuery.RATING));

    mediaDescription.setText(cursor.getString(TVShowDetailsQuery.PLOT));

    Resources resources = getActivity().getResources();
    TypedArray styledAttributes = getActivity().getTheme()
            .obtainStyledAttributes(new int[] { R.attr.iconExpand, R.attr.iconCollapse });
    final int iconCollapseResId = styledAttributes.getResourceId(styledAttributes.getIndex(0),
            R.drawable.ic_expand_less_white_24dp);
    final int iconExpandResId = styledAttributes.getResourceId(styledAttributes.getIndex(1),
            R.drawable.ic_expand_more_white_24dp);
    styledAttributes.recycle();
    mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaDescription.toggle();
            mediaShowAll.setImageResource(mediaDescription.isExpanded() ? iconCollapseResId : iconExpandResId);
        }
    });

    //        // IMDB button
    //        imdbButton.setTag(cursor.getString(TVShowDetailsQuery.IMDBNUMBER));

    // Images
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
    UIUtils.loadImageWithCharacterAvatar(getActivity(), getHostManager(),
            cursor.getString(TVShowDetailsQuery.THUMBNAIL), tvshowTitle, mediaPoster, posterWidth,
            posterHeight);
    int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
    UIUtils.loadImageIntoImageview(getHostManager(), cursor.getString(TVShowDetailsQuery.FANART), mediaArt,
            displayMetrics.widthPixels, artHeight);
}

From source file:com.philliphsu.bottomsheetpickers.date.MonthView.java

public MonthView(Context context, AttributeSet attr) {
    super(context, attr);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.bsp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.bsp_sans_serif);

    mDayTextColor = res.getColor(R.color.bsp_text_color_primary_light);
    // Same as background color
    mSelectedDayTextColor = getColor(context, R.color.bsp_date_picker_view_animator);
    mTodayNumberColor = Utils.getThemeAccentColor(context);
    mDisabledDayTextColor = res.getColor(R.color.bsp_text_color_disabled_light);
    mMonthTitleColor = res.getColor(android.R.color.white);
    mMonthTitleBGColor = res.getColor(R.color.bsp_circle_background);
    mMonthDayLabelTextColor = getColor(context, R.color.bsp_text_color_disabled_light);

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(DRAW_TITLE ? R.dimen.bsp_month_list_item_header_height
            : R.dimen.bsp_month_list_item_header_height_no_title);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.bsp_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.bsp_date_picker_view_animator_height)
            - getMonthHeaderSize() - getMonthNavigationBarSize()) / MAX_NUM_ROWS;
    mEdgePadding = res.getDimensionPixelSize(R.dimen.bsp_month_view_edge_padding);

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;/*  w  ww .ja v  a2 s  .  c om*/

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.android.mail.ui.ConversationViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    LogUtils.d(LOG_TAG, "IN CVF.onActivityCreated, this=%s visible=%s", this, isUserVisible());
    super.onActivityCreated(savedInstanceState);

    if (mActivity == null || mActivity.isFinishing()) {
        // Activity is finishing, just bail.
        return;//from  w w w .ja  va  2s .  co m
    }

    Context context = getContext();
    mTemplates = new HtmlConversationTemplates(context);

    final FormattedDateBuilder dateBuilder = new FormattedDateBuilder(context);

    mNavigationController = mActivity.getKeyboardNavigationController();

    mAdapter = new ConversationViewAdapter(mActivity, this, getLoaderManager(), this, this,
            getContactInfoSource(), this, this, getListController(), this, mAddressCache, dateBuilder,
            mBidiFormatter, this);
    mConversationContainer.setOverlayAdapter(mAdapter);

    // set up snap header (the adapter usually does this with the other ones)
    mConversationContainer.getSnapHeader().initialize(this, mAddressCache, this, getContactInfoSource(),
            mActivity.getAccountController().getVeiledAddressMatcher());

    final Resources resources = getResources();
    mMaxAutoLoadMessages = resources.getInteger(R.integer.max_auto_load_messages);

    mSideMarginPx = resources.getDimensionPixelOffset(R.dimen.conversation_message_content_margin_side);

    mUrlToMessageIdMap = new ArrayMap<String, String>();
    final InlineAttachmentViewIntentBuilderCreator creator = InlineAttachmentViewIntentBuilderCreatorHolder
            .getInlineAttachmentViewIntentCreator();
    final WebViewContextMenu contextMenu = new WebViewContextMenu(getActivity(), creator
            .createInlineAttachmentViewIntentBuilder(mAccount, mConversation != null ? mConversation.id : -1));
    contextMenu.setCallbacks(this);
    mWebView.setOnCreateContextMenuListener(contextMenu);

    // set this up here instead of onCreateView to ensure the latest Account is loaded
    setupOverviewMode();

    // Defer the call to initLoader with a Handler.
    // We want to wait until we know which fragments are present and their final visibility
    // states before going off and doing work. This prevents extraneous loading from occurring
    // as the ViewPager shifts about before the initial position is set.
    //
    // e.g. click on item #10
    // ViewPager.setAdapter() actually first loads #0 and #1 under the assumption that #0 is
    // the initial primary item
    // Then CPC immediately sets the primary item to #10, which tears down #0/#1 and sets up
    // #9/#10/#11.
    getHandler().post(new FragmentRunnable("showConversation", this) {
        @Override
        public void go() {
            showConversation();
        }
    });

    if (mConversation != null && mConversation.conversationBaseUri != null
            && !Utils.isEmpty(mAccount.accountCookieQueryUri)) {
        // Set the cookie for this base url
        new SetCookieTask(getContext(), mConversation.conversationBaseUri.toString(),
                mAccount.accountCookieQueryUri).execute();
    }

    // Find the height of the screen for manually scrolling the webview via keyboard.
    final Rect screen = new Rect();
    mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(screen);
    mMaxScreenHeight = screen.bottom;
    mTopOfVisibleScreen = screen.top + mActivity.getSupportActionBar().getHeight();
}

From source file:com.android.contacts.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *//*from  w w w. j a  v  a2 s  .  co  m*/
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
    // These icons have the same height and width so either is fine for the size.
    final Bitmap phoneIcon = BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the
    // app badge which overlaps the type overlay.
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);
    if (!BuildCompat.isAtLeastO() && overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    int iconWidth = icon.getWidth();
    if (BuildCompat.isAtLeastO()) {
        // On O we need to calculate where the phone icon goes slightly differently. The whole
        // canvas area is 108dp, a centered circle with a diameter of 66dp is the "safe zone".
        // So we start the drawing the phone icon at
        // 108dp - 21 dp (distance from right edge of safe zone to the edge of the canvas)
        // - 24 dp (size of the phone icon) on the x axis (left)
        // The y axis is simply 21dp for the distance to the safe zone (top).
        // See go/o-icons-eng for more details and a handy picture.
        final int left = (int) (mIconSize - (45 * density));
        final int top = (int) (21 * density);
        canvas.drawBitmap(phoneIcon, left, top, photoPaint);
    } else {
        dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
        canvas.drawBitmap(phoneIcon, null, dst, photoPaint);
    }

    canvas.setBitmap(null);
    return icon;
}