Example usage for android.graphics.drawable Drawable mutate

List of usage examples for android.graphics.drawable Drawable mutate

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable mutate.

Prototype

public @NonNull Drawable mutate() 

Source Link

Document

Make this drawable mutable.

Usage

From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java

private void updateEditTextBackground() {
    if (mEditText == null) {
        return;//w  ww  .java  2 s . co m
    }

    Drawable editTextBackground = mEditText.getBackground();
    if (editTextBackground == null) {
        return;
    }

    ensureBackgroundDrawableStateWorkaround();

    if (DrawableUtils.canSafelyMutateDrawable(editTextBackground)) {
        editTextBackground = editTextBackground.mutate();
    }

    if (mErrorShown && mErrorView != null) {
        // Set a color filter of the error color
        editTextBackground.setColorFilter(
                getPorterDuffColorFilter(mErrorView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN));
    } else if (mCounterOverflowed && mCounterView != null) {
        // Set a color filter of the counter color
        editTextBackground.setColorFilter(
                getPorterDuffColorFilter(mCounterView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN));
    } else {
        // Else reset the color filter and refresh the drawable state so that the
        // normal tint is used
        DrawableCompat.clearColorFilter(editTextBackground);
        mEditText.refreshDrawableState();
    }
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

private void updateUserColor() {
    if (mProfileNameContainer != null) {
        final Drawable d = mProfileNameContainer.getBackground();
        if (d != null) {
            d.mutate().setColorFilter(getUserColor(getActivity(), mUserId), Mode.MULTIPLY);
            mProfileNameContainer.invalidate();
        }/* w w w.ja  v a2 s . c o m*/
    }
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

public void toggleImageViewGrayFilter(ImageView image, boolean state) {
    Drawable originalIcon = image.getDrawable();
    Drawable res = originalIcon.mutate();
    if (state) {/* ww w .j av  a2s  . co  m*/
        res.clearColorFilter();
    } else {
        res.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    }
    image.setImageDrawable(res);
}

From source file:cnedu.ustcjd.widget.MultiSlider.java

private Drawable getTintedDrawable(Drawable drawable, int tintColor) {
    if (drawable != null && tintColor != 0) {
        Drawable wrappedDrawable = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTint(wrappedDrawable, tintColor);
        return wrappedDrawable;
    }//from   w w w  . ja va 2s .c o m
    return drawable;
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

public void changeUser(final long account_id, final User user) {
    mFriendship = null;//from  w  ww. j a v  a 2  s  . com
    mUserId = -1;
    mAccountId = -1;
    if (user == null || user.getId() <= 0 || getActivity() == null
            || !isMyActivatedAccount(getActivity(), account_id))
        return;
    if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) {
        mUserInfoTask.cancel(true);
    }
    final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId());
    mUserInfoTask = null;
    mErrorRetryContainer.setVisibility(View.GONE);
    mAccountId = account_id;
    mUserId = user.getId();
    mScreenName = user.getScreenName();

    updateUserColor();
    final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1;

    mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0);
    if (is_multiple_account_enabled) {
        final Drawable d = mListView.getBackground();
        if (d != null) {
            d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY);
            mListView.invalidate();
        }
    }

    mNameView.setText(user.getName());
    mScreenNameView.setText("@" + user.getScreenName());
    mScreenNameView.setCompoundDrawablesWithIntrinsicBounds(
            getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0);
    final String description = user.getDescription();
    mDescriptionContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE);
    mDescriptionContainer.setOnLongClickListener(this);
    mDescriptionView.setText(description);
    final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView);
    linkify.setOnLinkClickListener(this);
    linkify.addAllLinks();
    mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
    final String location = user.getLocation();
    mLocationContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE);
    mLocationContainer.setOnLongClickListener(this);
    mLocationView.setText(location);
    final String url = user.getURL() != null ? user.getURL().toString() : null;
    mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE);
    mURLContainer.setOnLongClickListener(this);
    mURLView.setText(url);
    mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt())));
    mTweetCount.setText(String.valueOf(user.getStatusesCount()));
    mFollowersCount.setText(String.valueOf(user.getFollowersCount()));
    mFriendsCount.setText(String.valueOf(user.getFriendsCount()));
    // final boolean display_profile_image =
    // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true);
    // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE
    // : View.GONE);
    // if (display_profile_image) {
    final String profile_image_url_string = parseString(user.getProfileImageURL());
    final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
    mLazyImageLoader.displayProfileImage(mProfileImageView,
            hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    // }

    String profile_banner_url_string = parseString(user.getProfileBannerImageUrl());
    if (profile_banner_url_string != null) {
        final int def_width = getResources().getDisplayMetrics().widthPixels;
        profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width);
    }
    final String banner_url = profile_banner_url_string;
    if (mProfileBackgroundView != null) {
        mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (banner_url != null) {
            mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url);
        } else {
            final Drawable d = getResources().getDrawable(R.drawable.linen);
            mProfileBackgroundView.setImageDrawable(d);
        }
    }

    mUser = user;
    if (isMyAccount(getActivity(), user.getId())) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        final URL profile_image_url = user.getProfileImageURL();
        if (profile_image_url != null) {
            values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString());
        }
        values.put(Accounts.USERNAME, user.getScreenName());
        final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1";
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new UserRecentPhotosAction());
    mAdapter.add(new FavoritesAction());
    mAdapter.add(new UserMentionsAction());
    mAdapter.add(new UserListTypesAction());
    if (user.getId() == mAccountId) {
        mAdapter.add(new MyTweetsRetweetedAction());
        mAdapter.add(new SavedSearchesAction());
        boolean nativeMapSupported = true;
        try {
            Class.forName("com.google.android.maps.MapActivity");
            Class.forName("com.google.android.maps.MapView");
        } catch (final ClassNotFoundException e) {
            nativeMapSupported = false;
        }
        if (nativeMapSupported) {
            mAdapter.add(new UserNearbyAction());
        }
        if (user.isProtected()) {
            mAdapter.add(new IncomingFriendshipsAction());
        }
        mAdapter.add(new UserBlocksAction());
    }
    mAdapter.notifyDataSetChanged();

    if (mRecentPhotosGallery != null) {
        mRecentPhotosGallery.setVisibility(View.GONE);
        mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity()));
        mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                ParcelableStatus pStatus = mMediaStatuses.get(position);
                final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string);
                if (spec != null) {
                    openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link),
                            pStatus.is_possibly_sensitive);
                }
            }

        });

        mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName());
        if (mMediaTimelineTask != null) {
            mMediaTimelineTask.execute();
        }
    }

    getFriendship();
    checkPushTracked();
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

@Override
public void onClick(final View view) {
    switch (view.getId()) {
    case R.id.follow: {
        if (mUser != null && mAccountId != mUser.getId()) {
            mFollowProgress.setVisibility(View.VISIBLE);
            mFollowButton.setVisibility(View.GONE);
            if (mFriendship.isSourceFollowingTarget()) {
                mService.destroyFriendship(mAccountId, mUser.getId());
            } else {
                mService.createFriendship(mAccountId, mUser.getId());
            }/* w  w w .jav a  2  s  .  co  m*/
        }
        break;
    }
    case R.id.retry: {
        reloadUserInfo();
        break;
    }
    case R.id.name_container: {
        if (mUser != null) {
        }
        break;
    }
    case R.id.profile_image_container: {
        final String profile_image_url_string = getOriginalTwitterProfileImage(
                parseString(mUser.getProfileImageURL()));
        if (profile_image_url_string == null)
            return;
        final Uri uri = Uri.parse(profile_image_url_string);
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.getId(), mUser.getScreenName());
        break;
    }
    case R.id.more_options: {
        if (mUser == null || mFriendship == null)
            return;
        if (!isMyActivatedAccount(getActivity(), mUser.getId())) {
            mPopupMenu = PopupMenu.getInstance(getActivity(), view);
            mPopupMenu.inflate(R.menu.action_user_profile);
            final Menu menu = mPopupMenu.getMenu();
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            final MenuItem trackItem = menu.findItem(MENU_TRACKING);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            if (trackItem != null) {
                if (mPreferences.getBoolean(com.dwdesign.tweetings.Constants.PREFERENCE_KEY_PUSH_NOTIFICATIONS,
                        false) == false) {
                    trackItem.setVisible(false);
                } else {
                    if (tracking == true) {
                        trackItem.setTitle(R.string.untrack_user);
                    } else {
                        trackItem.setTitle(R.string.track_user);
                    }
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
            final MenuItem wantRetweetsItem = menu.findItem(MENU_WANT_RETWEETS);
            if (mFriendship.wantRetweets() == true) {
                wantRetweetsItem.setTitle(R.string.disable_retweet);
            } else {
                wantRetweetsItem.setTitle(R.string.enable_retweet);
            }
            mPopupMenu.setOnMenuItemClickListener(this);
            mPopupMenu.show();
        }
        break;
    }
    }

}

From source file:dev.memento.MainActivity.java

/**
 * Converts the given drawable to a gray image. This method may be 
 * used to simulate the color of disable icons in Honeycomb's ActionBar.
 * /*from  w  w  w .  j  a  va2s .  c o m*/
 * @return a version of the given drawable with a color filter applied.
 */
private Drawable convertDrawableToGrayScale(Drawable drawable) {
    if (drawable == null)
        return null;

    Drawable res = drawable.mutate();
    res.setColorFilter(Color.GRAY, Mode.SRC_IN);
    return res;
}

From source file:cw.kop.autobackground.LiveWallpaperService.java

@SuppressLint("NewApi")
private void startNotification(boolean useNotification) {
    if (useNotification) {
        normalView = new RemoteViews(getPackageName(), R.layout.notification_layout);
        normalView.setInt(R.id.notification_container, "setBackgroundColor",
                AppSettings.getNotificationColor());
        normalView.setImageViewResource(R.id.notification_icon, R.drawable.app_icon);
        normalView.setTextViewText(R.id.notification_title, AppSettings.getNotificationTitle());
        normalView.setInt(R.id.notification_title, "setTextColor", AppSettings.getNotificationTitleColor());
        normalView.setTextViewText(R.id.notification_summary, AppSettings.getNotificationSummary());
        normalView.setInt(R.id.notification_summary, "setTextColor", AppSettings.getNotificationSummaryColor());

        Drawable coloredImageOne = LiveWallpaperService.this.getResources()
                .getDrawable(AppSettings.getNotificationOptionDrawable(0));
        Drawable coloredImageTwo = LiveWallpaperService.this.getResources()
                .getDrawable(AppSettings.getNotificationOptionDrawable(1));
        Drawable coloredImageThree = LiveWallpaperService.this.getResources()
                .getDrawable(AppSettings.getNotificationOptionDrawable(2));

        coloredImageOne.mutate().setColorFilter(AppSettings.getNotificationOptionColor(0),
                PorterDuff.Mode.MULTIPLY);
        coloredImageTwo.mutate().setColorFilter(AppSettings.getNotificationOptionColor(1),
                PorterDuff.Mode.MULTIPLY);
        coloredImageThree.mutate().setColorFilter(AppSettings.getNotificationOptionColor(2),
                PorterDuff.Mode.MULTIPLY);

        Bitmap mutableBitmapOne = Bitmap.createBitmap(coloredImageOne.getIntrinsicWidth(),
                coloredImageOne.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvasOne = new Canvas(mutableBitmapOne);
        coloredImageOne.setBounds(0, 0, coloredImageOne.getIntrinsicWidth(),
                coloredImageOne.getIntrinsicHeight());
        coloredImageOne.draw(canvasOne);

        Bitmap mutableBitmapTwo = Bitmap.createBitmap(coloredImageTwo.getIntrinsicWidth(),
                coloredImageTwo.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvasTwo = new Canvas(mutableBitmapTwo);
        coloredImageTwo.setBounds(0, 0, coloredImageTwo.getIntrinsicWidth(),
                coloredImageTwo.getIntrinsicHeight());
        coloredImageTwo.draw(canvasTwo);

        Bitmap mutableBitmapThree = Bitmap.createBitmap(coloredImageThree.getIntrinsicWidth(),
                coloredImageThree.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvasThree = new Canvas(mutableBitmapThree);
        coloredImageThree.setBounds(0, 0, coloredImageThree.getIntrinsicWidth(),
                coloredImageThree.getIntrinsicHeight());
        coloredImageThree.draw(canvasThree);

        if (AppSettings.useNotificationGame()) {
            if (setupGameTiles()) {
                bigView = new RemoteViews(getPackageName(), R.layout.notification_game);
                tileIds = new int[] { R.id.notification_game_tile_0, R.id.notification_game_tile_1,
                        R.id.notification_game_tile_2, R.id.notification_game_tile_3,
                        R.id.notification_game_tile_4, R.id.notification_game_tile_5,
                        R.id.notification_game_tile_6, R.id.notification_game_tile_7,
                        R.id.notification_game_tile_8, R.id.notification_game_tile_9 };
                bigView.setOnClickPendingIntent(tileIds[0], pendingTile0);
                bigView.setOnClickPendingIntent(tileIds[1], pendingTile1);
                bigView.setOnClickPendingIntent(tileIds[2], pendingTile2);
                bigView.setOnClickPendingIntent(tileIds[3], pendingTile3);
                bigView.setOnClickPendingIntent(tileIds[4], pendingTile4);
                bigView.setOnClickPendingIntent(tileIds[5], pendingTile5);
                bigView.setOnClickPendingIntent(tileIds[6], pendingTile6);
                bigView.setOnClickPendingIntent(tileIds[7], pendingTile7);
                bigView.setOnClickPendingIntent(tileIds[8], pendingTile8);
                bigView.setOnClickPendingIntent(tileIds[9], pendingTile9);
            } else {
                bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout);
                closeNotificationDrawer(LiveWallpaperService.this);
                Toast.makeText(LiveWallpaperService.this, "Not enough images to create game", Toast.LENGTH_LONG)
                        .show();/* ww w  .j  av  a 2 s  .  c  o m*/
                AppSettings.setUseNotificationGame(false);
            }
        } else {
            bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout);
        }
        bigView.setInt(R.id.notification_big_container, "setBackgroundColor",
                AppSettings.getNotificationColor());
        bigView.setImageViewResource(R.id.notification_big_icon, R.drawable.app_icon);
        bigView.setTextViewText(R.id.notification_big_title, AppSettings.getNotificationTitle());
        bigView.setInt(R.id.notification_big_title, "setTextColor", AppSettings.getNotificationTitleColor());
        bigView.setTextViewText(R.id.notification_big_summary, AppSettings.getNotificationSummary());
        bigView.setInt(R.id.notification_big_summary, "setTextColor",
                AppSettings.getNotificationSummaryColor());

        bigView.setImageViewBitmap(R.id.notification_button_one_image, mutableBitmapOne);
        bigView.setImageViewBitmap(R.id.notification_button_two_image, mutableBitmapTwo);
        bigView.setImageViewBitmap(R.id.notification_button_three_image, mutableBitmapThree);
        bigView.setTextViewText(R.id.notification_button_one_text, AppSettings.getNotificationOptionTitle(0));
        bigView.setInt(R.id.notification_button_one_text, "setTextColor",
                AppSettings.getNotificationOptionColor(0));
        bigView.setTextViewText(R.id.notification_button_two_text, AppSettings.getNotificationOptionTitle(1));
        bigView.setInt(R.id.notification_button_two_text, "setTextColor",
                AppSettings.getNotificationOptionColor(1));
        bigView.setTextViewText(R.id.notification_button_three_text, AppSettings.getNotificationOptionTitle(2));
        bigView.setInt(R.id.notification_button_three_text, "setTextColor",
                AppSettings.getNotificationOptionColor(2));

        if (getIntentForNotification(AppSettings.getNotificationIconAction()) != null) {
            normalView.setOnClickPendingIntent(R.id.notification_icon,
                    getIntentForNotification(AppSettings.getNotificationIconAction()));
            bigView.setOnClickPendingIntent(R.id.notification_big_icon,
                    getIntentForNotification(AppSettings.getNotificationIconAction()));
        } else {
            normalView.setOnClickPendingIntent(R.id.notification_icon, pendingAppIntent);
            bigView.setOnClickPendingIntent(R.id.notification_big_icon, pendingAppIntent);
        }

        notificationBuilder = new Notification.Builder(this).setContent(normalView)
                .setSmallIcon(R.drawable.notification_icon).setOngoing(true);

        if (Build.VERSION.SDK_INT >= 16) {
            if (AppSettings.useNotificationGame()) {
                notificationBuilder.setPriority(Notification.PRIORITY_MAX);
            } else {
                notificationBuilder.setPriority(Notification.PRIORITY_MIN);
            }
            if (getIntentForNotification(AppSettings.getNotificationOptionTitle(0)) != null) {
                bigView.setOnClickPendingIntent(R.id.notification_button_one,
                        getIntentForNotification(AppSettings.getNotificationOptionTitle(0)));
            }
            if (getIntentForNotification(AppSettings.getNotificationOptionTitle(1)) != null) {
                bigView.setOnClickPendingIntent(R.id.notification_button_two,
                        getIntentForNotification(AppSettings.getNotificationOptionTitle(1)));
            }
            if (getIntentForNotification(AppSettings.getNotificationOptionTitle(2)) != null) {
                bigView.setOnClickPendingIntent(R.id.notification_button_three,
                        getIntentForNotification(AppSettings.getNotificationOptionTitle(2)));
            }
        } else {
            notificationBuilder.setContentTitle(AppSettings.getNotificationTitle());
            notificationBuilder.setContentText(AppSettings.getNotificationSummary());
            notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(0),
                    AppSettings.getNotificationOptionTitle(0),
                    getIntentForNotification(AppSettings.getNotificationOptionTitle(0)));
            notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(1),
                    AppSettings.getNotificationOptionTitle(1),
                    getIntentForNotification(AppSettings.getNotificationOptionTitle(1)));
            notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(2),
                    AppSettings.getNotificationOptionTitle(2),
                    getIntentForNotification(AppSettings.getNotificationOptionTitle(2)));
        }

        pushNotification();

        if (FileHandler.getCurrentBitmapFile() != null) {
            notifyChangeImage();
        }
    } else {
        notificationManager.cancel(NOTIFICATION_ID);
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Set a drawable to draw in the insets area for the status bar.
 * Note that this will only be activated if this DrawerLayout fitsSystemWindows.
 *
 * @param bg Background drawable to draw behind the status bar
 *//* w  ww  . j a v a 2s  . co  m*/
public void setStatusBarBackground(@Nullable final Drawable bg) {
    if (mStatusBarBackground != bg) {
        if (mStatusBarBackground != null) {
            mStatusBarBackground.setCallback(null);
        }
        mStatusBarBackground = bg != null ? bg.mutate() : null;
        if (mStatusBarBackground != null) {
            if (mStatusBarBackground.isStateful()) {
                mStatusBarBackground.setState(getDrawableState());
            }
            DrawableCompat.setLayoutDirection(mStatusBarBackground, ViewCompat.getLayoutDirection(this));
            mStatusBarBackground.setVisible(getVisibility() == VISIBLE, false);
            mStatusBarBackground.setCallback(this);
        }
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId,
        final String action, final String parelableKey, final String parelableJSONKey,
        final FiretweetParcelable parcelable) {
    if (context == null || menu == null || action == null || parelableKey == null || parcelable == null)
        return;/*from  w ww . jav a  2 s .  c  o  m*/
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final Intent queryIntent = new Intent(action);
    queryIntent.setExtrasClassLoader(context.getClassLoader());
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        if (isExtensionUseJSON(info)) {
            intent.putExtra(parelableJSONKey, JSONSerializer.toJSONObjectString(parcelable));
        } else {
            intent.putExtra(parelableKey, parcelable);
        }
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final Drawable metaDataDrawable = getMetadataDrawable(pm, info.activityInfo,
                METADATA_KEY_EXTENSION_ICON);
        final int actionIconColor = ThemeUtils.getThemeForegroundColor(context);
        if (metaDataDrawable != null) {
            metaDataDrawable.mutate();
            metaDataDrawable.setColorFilter(actionIconColor, Mode.SRC_ATOP);
            item.setIcon(metaDataDrawable);
        } else {
            final Drawable icon = info.loadIcon(pm);
            final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
            if (iw > 0 && ih > 0) {
                final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
                iconWithPadding.setBounds(0, 0, iw, ih);
                item.setIcon(iconWithPadding);
            } else {
                item.setIcon(icon);
            }
        }

    }
}