Java Code Examples for org.chromium.base.ApiCompatibilityUtils#getDrawable()

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#getDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddExceptionPreference.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a AddException preference.
 * @param context The current context.
 * @param key The key to use for the preference.
 * @param message The custom message to show in the dialog.
 * @param callback A callback to receive notifications that an exception has been added.
 */
public AddExceptionPreference(
        Context context, String key, String message, SiteAddedCallback callback) {
    super(context);
    mDialogMessage = message;
    mSiteAddedCallback = callback;
    setOnPreferenceClickListener(this);

    setKey(key);
    Resources resources = getContext().getResources();
    mPrefAccentColor = ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color);

    Drawable plusIcon = ApiCompatibilityUtils.getDrawable(resources, R.drawable.plus);
    plusIcon.mutate();
    plusIcon.setColorFilter(mPrefAccentColor, PorterDuff.Mode.SRC_IN);
    setIcon(plusIcon);

    setTitle(resources.getString(R.string.website_settings_add_site));
}
 
Example 2
Source File: AddExceptionPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a AddException preference.
 * @param context The current context.
 * @param key The key to use for the preference.
 * @param message The custom message to show in the dialog.
 * @param callback A callback to receive notifications that an exception has been added.
 */
public AddExceptionPreference(
        Context context, String key, String message, SiteAddedCallback callback) {
    super(context);
    mDialogMessage = message;
    mSiteAddedCallback = callback;
    setOnPreferenceClickListener(this);

    setKey(key);
    Resources resources = getContext().getResources();
    mPrefAccentColor = ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color);

    Drawable plusIcon = ApiCompatibilityUtils.getDrawable(resources, R.drawable.plus);
    plusIcon.mutate();
    plusIcon.setColorFilter(mPrefAccentColor, PorterDuff.Mode.SRC_IN);
    setIcon(plusIcon);

    setTitle(resources.getString(R.string.website_settings_add_site));
}
 
Example 3
Source File: SyncPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the summary and icon for this preference to reflect the current state of syncing.
 */
public void updateSyncSummaryAndIcon() {
    setSummary(getSyncStatusSummary(getContext()));

    if (SyncPreference.showSyncErrorIcon(getContext())) {
        setIcon(ApiCompatibilityUtils.getDrawable(
                getContext().getResources(), R.drawable.sync_error));
    } else {
        // Sets preference icon and tints it to blue.
        Drawable icon = ApiCompatibilityUtils.getDrawable(
                getContext().getResources(), R.drawable.permission_background_sync);
        icon.setColorFilter(ApiCompatibilityUtils.getColor(
                                    getContext().getResources(), R.color.light_active_color),
                PorterDuff.Mode.SRC_IN);
        setIcon(icon);
    }
}
 
Example 4
Source File: AddExceptionPreference.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a AddException preference.
 * @param context The current context.
 * @param key The key to use for the preference.
 * @param message The custom message to show in the dialog.
 * @param callback A callback to receive notifications that an exception has been added.
 */
public AddExceptionPreference(
        Context context, String key, String message, SiteAddedCallback callback) {
    super(context);
    mDialogMessage = message;
    mSiteAddedCallback = callback;
    setOnPreferenceClickListener(this);

    setKey(key);
    Resources resources = getContext().getResources();
    mPrefAccentColor = ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color);

    Drawable plusIcon = ApiCompatibilityUtils.getDrawable(resources, R.drawable.plus);
    plusIcon.mutate();
    plusIcon.setColorFilter(mPrefAccentColor, PorterDuff.Mode.SRC_IN);
    setIcon(plusIcon);

    setTitle(resources.getString(R.string.website_settings_add_site));
}
 
Example 5
Source File: StaticResource.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static Bitmap decodeDrawable(Resources resources, int resId, int fitWidth,
        int fitHeight) {
    try {
        Drawable drawable = ApiCompatibilityUtils.getDrawable(resources, resId);
        int width = Math.max(drawable.getMinimumWidth(), Math.max(fitWidth, 1));
        int height = Math.max(drawable.getMinimumHeight(), Math.max(fitHeight, 1));
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);
        return bitmap;
    } catch (Resources.NotFoundException ex) {
        return null;
    }
}
 
Example 6
Source File: RecentTabsRowAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an RecentTabsRowAdapter used to populate an ExpandableList with other
 * devices and foreign tab cells.
 *
 * @param activity The Android activity this adapter will work in.
 * @param recentTabsManager The RecentTabsManager that will act as the data source.
 */
public RecentTabsRowAdapter(Activity activity, RecentTabsManager recentTabsManager) {
    mActivity = activity;
    mRecentTabsManager = recentTabsManager;
    mGroups = new ArrayList<>();
    mFaviconCache = new FaviconCache(MAX_NUM_FAVICONS_TO_CACHE);

    Resources resources = activity.getResources();
    mDefaultFavicon = ApiCompatibilityUtils.getDrawable(resources, R.drawable.default_favicon);
    mFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);

    RecordHistogram.recordEnumeratedHistogram("HistoryPage.OtherDevicesMenu",
            OtherSessionsActions.MENU_INITIALIZED, OtherSessionsActions.LIMIT);
}
 
Example 7
Source File: SiteSettingsCategory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the icon for permissions that have been disabled by Android.
 */
Drawable getDisabledInAndroidIcon(Activity activity) {
    Drawable icon = ApiCompatibilityUtils.getDrawable(activity.getResources(),
            R.drawable.exclamation_triangle);
    icon.mutate();
    int disabledColor = ApiCompatibilityUtils.getColor(activity.getResources(),
            R.color.pref_accent_color);
    icon.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN);
    return icon;
}
 
Example 8
Source File: ContentSettingsResources.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Drawable object of the icon for a content type with a disabled tint.
 */
public static Drawable getDisabledIcon(int contentType, Resources resources) {
    Drawable icon = ApiCompatibilityUtils.getDrawable(resources, getIcon(contentType));
    icon.mutate();
    int disabledColor = ApiCompatibilityUtils.getColor(resources,
            R.color.primary_text_disabled_material_light);
    icon.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN);
    return icon;
}
 
Example 9
Source File: RecentTabsRowAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an RecentTabsRowAdapter used to populate an ExpandableList with other
 * devices and foreign tab cells.
 *
 * @param activity The Android activity this adapter will work in.
 * @param recentTabsManager The RecentTabsManager that will act as the data source.
 */
public RecentTabsRowAdapter(Activity activity, RecentTabsManager recentTabsManager) {
    mActivity = activity;
    mRecentTabsManager = recentTabsManager;
    mGroups = new ArrayList<Group>();
    mFaviconCache = buildFaviconCache(MAX_NUM_FAVICONS_TO_CACHE);

    Resources resources = activity.getResources();
    mDefaultFavicon = ApiCompatibilityUtils.getDrawable(resources, R.drawable.default_favicon);
    mFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);

    RecordHistogram.recordEnumeratedHistogram("HistoryPage.OtherDevicesMenu",
            OtherSessionsActions.MENU_INITIALIZED, OtherSessionsActions.LIMIT);
}
 
Example 10
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void setTabSwitcherAnimationMenuBadgeDrawable() {
    mTabSwitcherAnimationMenuBadgeDarkDrawable = ApiCompatibilityUtils.getDrawable(
            getResources(), R.drawable.badge_update_dark);
    mTabSwitcherAnimationMenuBadgeDarkDrawable.mutate();
    ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeDarkDrawable).setGravity(Gravity.CENTER);

    mTabSwitcherAnimationMenuBadgeLightDrawable = ApiCompatibilityUtils.getDrawable(
            getResources(), R.drawable.badge_update_light);
    mTabSwitcherAnimationMenuBadgeLightDrawable.mutate();
    ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeLightDrawable).setGravity(Gravity.CENTER);
}
 
Example 11
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
private void setTabSwitcherAnimationMenuBadgeDrawable() {
    mTabSwitcherAnimationMenuBadgeDarkDrawable = ApiCompatibilityUtils.getDrawable(
            getResources(), R.drawable.badge_update_dark);
    mTabSwitcherAnimationMenuBadgeDarkDrawable.mutate();
    ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeDarkDrawable).setGravity(Gravity.CENTER);

    mTabSwitcherAnimationMenuBadgeLightDrawable = ApiCompatibilityUtils.getDrawable(
            getResources(), R.drawable.badge_update_light);
    mTabSwitcherAnimationMenuBadgeLightDrawable.mutate();
    ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeLightDrawable).setGravity(Gravity.CENTER);
}
 
Example 12
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
private void setTabSwitcherAnimationMenuDrawable() {
    if (!shouldShowMenuButton()) return;
    mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawable(getResources(),
            R.drawable.btn_menu);
    mTabSwitcherAnimationMenuDrawable.mutate();
    mTabSwitcherAnimationMenuDrawable.setColorFilter(
            isIncognito() ? mLightModeDefaultColor : mDarkModeDefaultColor,
            PorterDuff.Mode.SRC_IN);
    ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Gravity.CENTER);
}
 
Example 13
Source File: TabularContextMenuUi.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * This creates a checkerboard style background displayed before the image is shown.
 */
private void setBackgroundForImageView(ImageView imageView, Resources resources) {
    Drawable drawable =
            ApiCompatibilityUtils.getDrawable(resources, R.drawable.checkerboard_background);
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    BitmapDrawable bm = new BitmapDrawable(resources, bitmap);
    bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    imageView.setVisibility(View.VISIBLE);
    imageView.setBackground(bm);
}
 
Example 14
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mLocationBar = (LocationBarPhone) findViewById(R.id.location_bar);

    mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons);

    mHomeButton = (TintedImageButton) findViewById(R.id.home_button);

    mUrlBar = (TextView) findViewById(R.id.url_bar);

    mUrlActionContainer = findViewById(R.id.url_action_container);

    mBrowsingModeViews.add(mLocationBar);

    mToolbarBackground = new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL));
    mTabSwitcherAnimationBgOverlay =
            new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL));

    mLocationBarBackground =
            ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.card_single);
    mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
    mLocationBar.setPadding(
            mLocationBarBackgroundPadding.left, mLocationBarBackgroundPadding.top,
            mLocationBarBackgroundPadding.right, mLocationBarBackgroundPadding.bottom);

    setLayoutTransition(null);

    mMenuButtonWrapper.setVisibility(View.VISIBLE);
    inflateTabSwitchingResources();

    setWillNotDraw(false);
}
 
Example 15
Source File: SingleWebsitePreferences.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the icon for permissions that have been disabled by Chrome.
 */
private Drawable getDisabledInChromeIcon(int contentType) {
    Drawable icon = ApiCompatibilityUtils.getDrawable(getResources(),
            ContentSettingsResources.getIcon(contentType));
    icon.mutate();
    int disabledColor = ApiCompatibilityUtils.getColor(getResources(),
            R.color.primary_text_disabled_material_light);
    icon.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN);
    return icon;
}
 
Example 16
Source File: SelectableItemHighlightView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for inflating from XML.
 */
public SelectableItemHighlightView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Drawable clickDrawable = context.obtainStyledAttributes(new int[] {
            android.R.attr.selectableItemBackground }).getDrawable(0);
    Drawable longClickDrawable = ApiCompatibilityUtils.getDrawable(context.getResources(),
            R.drawable.selectable_item_highlight);
    LayerDrawable ld = new LayerDrawable(new Drawable[] {clickDrawable, longClickDrawable});
    setBackground(ld);
}
 
Example 17
Source File: WebappUrlBar.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateSecurityIcon(int securityLevel) {
    boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
    mCurrentIconResource =
            LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice);

    if (mCurrentIconResource != 0 && mIconResourceWidths.get(mCurrentIconResource, -1) == -1) {
        Drawable icon = ApiCompatibilityUtils.getDrawable(getResources(), mCurrentIconResource);
        mIconResourceWidths.put(mCurrentIconResource, icon.getIntrinsicWidth());
    }

    ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(mUrlBar,
            mCurrentIconResource, 0, 0, 0);
}
 
Example 18
Source File: WebappUrlBar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void updateSecurityIcon(int securityLevel) {
    boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
    mCurrentIconResource =
            LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice, false);

    if (mCurrentIconResource != 0 && mIconResourceWidths.get(mCurrentIconResource, -1) == -1) {
        Drawable icon = ApiCompatibilityUtils.getDrawable(getResources(), mCurrentIconResource);
        mIconResourceWidths.put(mCurrentIconResource, icon.getIntrinsicWidth());
    }

    ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(mUrlBar,
            mCurrentIconResource, 0, 0, 0);
}
 
Example 19
Source File: SelectableItemHighlightView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for inflating from XML.
 */
public SelectableItemHighlightView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Drawable clickDrawable = context.obtainStyledAttributes(new int[] {
            android.R.attr.selectableItemBackground }).getDrawable(0);
    Drawable longClickDrawable = ApiCompatibilityUtils.getDrawable(context.getResources(),
            R.drawable.selectable_item_highlight);
    LayerDrawable ld = new LayerDrawable(new Drawable[] {clickDrawable, longClickDrawable});
    setBackground(ld);
}
 
Example 20
Source File: TextBubble.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
BubbleBackgroundDrawable(Context context) {
    mBubbleContentsDrawable = ApiCompatibilityUtils.getDrawable(
            context.getResources(), R.drawable.menu_bg);
    mBubbleArrowDrawable = (BitmapDrawable) ApiCompatibilityUtils.getDrawable(
            context.getResources(), R.drawable.bubble_point_white);
}