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

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#getColor() . 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: CustomTabToolbar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void updateVisualsForState() {
    Resources resources = getResources();
    updateSecurityIcon(getSecurityLevel());
    updateButtonsTint();
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    int titleTextColor = mUseDarkColors
            ? ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text)
            : ApiCompatibilityUtils.getColor(resources,
                    R.color.url_emphasis_light_default_text);
    mTitleBar.setTextColor(titleTextColor);

    if (getProgressBar() != null) {
        if (!ColorUtils.isUsingDefaultToolbarColor(getResources(),
                getBackground().getColor())) {
            getProgressBar().setThemeColor(getBackground().getColor(), false);
        } else {
            getProgressBar().setBackgroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_background));
            getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_foreground));
        }
    }
}
 
Example 2
Source File: DualControlLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a standardized Button that can be used for DualControlLayouts showing buttons.
 *
 * @param isPrimary Whether or not the button is meant to act as a "Confirm" button.
 * @param text      Text to display on the button.
 * @param listener  Listener to alert when the button has been clicked.
 * @return Button that can be used in the view.
 */
public static Button createButtonForLayout(
        Context context, boolean isPrimary, String text, OnClickListener listener) {
    int lightActiveColor =
            ApiCompatibilityUtils.getColor(context.getResources(), R.color.light_active_color);

    if (isPrimary) {
        ButtonCompat primaryButton = new ButtonCompat(context, lightActiveColor, false);
        primaryButton.setId(R.id.button_primary);
        primaryButton.setOnClickListener(listener);
        primaryButton.setText(text);
        primaryButton.setTextColor(Color.WHITE);
        return primaryButton;
    } else {
        Button secondaryButton = ButtonCompat.createBorderlessButton(context);
        secondaryButton.setId(R.id.button_secondary);
        secondaryButton.setOnClickListener(listener);
        secondaryButton.setText(text);
        secondaryButton.setTextColor(lightActiveColor);
        return secondaryButton;
    }
}
 
Example 3
Source File: AutoSigninSnackbarController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Displays Auto sign-in snackbar, which communicates to the users that they
 * were signed in to the web site.
 */
@CalledByNative
private static void showSnackbar(Tab tab, String text) {
    SnackbarManager snackbarManager = tab.getSnackbarManager();
    if (snackbarManager == null) return;
    AutoSigninSnackbarController snackbarController =
            new AutoSigninSnackbarController(snackbarManager, tab);
    Snackbar snackbar = Snackbar.make(text, snackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_AUTO_LOGIN);
    Resources resources = tab.getWindowAndroid().getActivity().get().getResources();
    int backgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.light_active_color);
    Bitmap icon = BitmapFactory.decodeResource(
            resources, R.drawable.account_management_no_picture);
    snackbar.setSingleLine(false).setBackgroundColor(backgroundColor).setProfileImage(icon);
    snackbarManager.showSnackbar(snackbar);
}
 
Example 4
Source File: BookmarkWidgetService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@UiThread
public void initialize(Context context, final BookmarkId folderId,
        BookmarkLoaderCallback callback) {
    mCallback = callback;

    Resources res = context.getResources();
    mLargeIconBridge = new LargeIconBridge(
            Profile.getLastUsedProfile().getOriginalProfile());
    mMinIconSizeDp = (int) res.getDimension(R.dimen.default_favicon_min_size);
    mDisplayedIconSize = res.getDimensionPixelSize(R.dimen.default_favicon_size);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.default_favicon_corner_radius);
    int textSize = res.getDimensionPixelSize(R.dimen.default_favicon_icon_text_size);
    int iconColor =
            ApiCompatibilityUtils.getColor(res, R.color.default_favicon_background_color);
    mIconGenerator = new RoundedIconGenerator(mDisplayedIconSize, mDisplayedIconSize,
            mCornerRadius, iconColor, textSize);

    mRemainingTaskCount = 1;
    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.runAfterBookmarkModelLoaded(new Runnable() {
        @Override
        public void run() {
            loadBookmarks(folderId);
        }
    });
}
 
Example 5
Source File: ColorUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return The base color for the textbox given a toolbar background color.
 */
public static int getTextBoxColorForToolbarBackground(Resources res, boolean isNtp, int color) {
    if (shouldUseOpaqueTextboxBackground(color)) {
        // NTP should have no visible textbox in the toolbar, so just return the toolbar's
        // background color.
        if (isNtp) return ApiCompatibilityUtils.getColor(res, R.color.ntp_bg);

        return Color.WHITE;
    }
    return getColorWithOverlay(color, Color.WHITE, LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA);
}
 
Example 6
Source File: FadingEdgeScrollView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public FadingEdgeScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mSeparatorColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.toolbar_shadow_color);
    mSeparatorHeight = getResources().getDimensionPixelSize(R.dimen.separator_height);
}
 
Example 7
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void postInflationStartup() {
    super.postInflationStartup();

    getToolbarManager().setCloseButtonDrawable(mIntentDataProvider.getCloseButtonDrawable());
    getToolbarManager().setShowTitle(mIntentDataProvider.getTitleVisibilityState()
            == CustomTabsIntent.SHOW_PAGE_TITLE);
    if (CustomTabsConnection.getInstance(getApplication())
            .shouldHideDomainForSession(mSession)) {
        getToolbarManager().setUrlBarHidden(true);
    }
    int toolbarColor = mIntentDataProvider.getToolbarColor();
    getToolbarManager().updatePrimaryColor(toolbarColor, false);
    if (!mIntentDataProvider.isOpenedByChrome()) {
        getToolbarManager().setShouldUpdateToolbarPrimaryColor(false);
    }
    if (toolbarColor != ApiCompatibilityUtils.getColor(
            getResources(), R.color.default_primary_color)) {
        ApiCompatibilityUtils.setStatusBarColor(getWindow(),
                ColorUtils.getDarkenedColorForStatusBar(toolbarColor));
    }
    // Properly attach tab's infobar to the view hierarchy, as the main tab might have been
    // initialized prior to inflation.
    if (mMainTab != null) {
        ViewGroup bottomContainer = (ViewGroup) findViewById(R.id.bottom_container);
        mMainTab.getInfoBarContainer().setParentView(bottomContainer);
    }

    // Setting task title and icon to be null will preserve the client app's title and icon.
    ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor);
    showCustomButtonOnToolbar();
    mBottomBarDelegate = new CustomTabBottomBarDelegate(this, mIntentDataProvider,
            getFullscreenManager());
    mBottomBarDelegate.showBottomBarIfNecessary();
}
 
Example 8
Source File: ContentSettingsResources.java    From 365browser 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: PhysicalWebDiagnosticsPage.java    From delion with Apache License 2.0 5 votes vote down vote up
public PhysicalWebDiagnosticsPage(Context context) {
    mContext = context;

    Resources resources = mContext.getResources();
    mBackgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.ntp_bg);
    mThemeColor = ApiCompatibilityUtils.getColor(resources, R.color.default_primary_color);
    mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_success_color));
    mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_failure_color));
    mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_indeterminate_color));

    LayoutInflater inflater = LayoutInflater.from(mContext);
    mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null);

    mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch);
    mLaunchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mContext.startActivity(createListUrlsIntent(mContext));
        }
    });

    mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_diagnostics_text);
    mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS);
    mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml()));
}
 
Example 10
Source File: ConfirmImportantSitesDialogFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ClearBrowsingDataAdapter(
        String[] domains, String[] faviconURLs, Resources resources) {
    super(getActivity(), R.layout.confirm_important_sites_list_row, domains);
    mDomains = domains;
    mFaviconURLs = faviconURLs;
    mFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
    mCornerRadius = resources.getDimensionPixelSize(R.dimen.default_favicon_corner_radius);
    int textSize = resources.getDimensionPixelSize(R.dimen.default_favicon_icon_text_size);
    int iconColor = ApiCompatibilityUtils.getColor(
            resources, R.color.default_favicon_background_color);
    mIconGenerator = new RoundedIconGenerator(
            mFaviconSize, mFaviconSize, mCornerRadius, iconColor, textSize);
}
 
Example 11
Source File: SeparateTaskCustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void finishNativeInitialization() {
    super.finishNativeInitialization();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTaskDescriptionHelper = new ActivityTabTaskDescriptionHelper(this,
                ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color));
    }
}
 
Example 12
Source File: RecentTabsPage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor returns an instance of RecentTabsPage.
 *
 * @param activity The activity this view belongs to.
 * @param recentTabsManager The RecentTabsManager which provides the model data.
 */
public RecentTabsPage(ChromeActivity activity, RecentTabsManager recentTabsManager) {
    mActivity = activity;
    mRecentTabsManager = recentTabsManager;

    mTitle = activity.getResources().getString(R.string.recent_tabs);
    mThemeColor = ApiCompatibilityUtils.getColor(
            activity.getResources(), R.color.default_primary_color);
    mRecentTabsManager.setUpdatedCallback(this);
    LayoutInflater inflater = LayoutInflater.from(activity);
    mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
    mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
    mAdapter = new RecentTabsRowAdapter(activity, recentTabsManager);
    mListView.setAdapter(mAdapter);
    mListView.setOnChildClickListener(this);
    mListView.setGroupIndicator(null);
    mListView.setOnGroupCollapseListener(this);
    mListView.setOnGroupExpandListener(this);
    mListView.setOnCreateContextMenuListener(this);

    mView.addOnAttachStateChangeListener(this);
    ApplicationStatus.registerStateListenerForActivity(this, activity);
    // {@link #mInForeground} will be updated once the view is attached to the window.

    if (activity.getBottomSheet() != null) {
        View recentTabsRoot = mView.findViewById(R.id.recent_tabs_root);
        ApiCompatibilityUtils.setPaddingRelative(recentTabsRoot,
                ApiCompatibilityUtils.getPaddingStart(recentTabsRoot), 0,
                ApiCompatibilityUtils.getPaddingEnd(recentTabsRoot),
                activity.getResources().getDimensionPixelSize(
                        R.dimen.bottom_control_container_height));
    }

    onUpdated();
}
 
Example 13
Source File: ToolbarModelImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the primary color and changes the state for isUsingBrandColor.
 * @param color The primary color for the current tab.
 */
public void setPrimaryColor(int color) {
    mPrimaryColor = color;
    Context context = ContextUtils.getApplicationContext();
    mIsUsingBrandColor = !isIncognito()
            && mPrimaryColor != ApiCompatibilityUtils.getColor(context.getResources(),
                    R.color.default_primary_color)
            && getTab() != null && !getTab().isNativePage();
}
 
Example 14
Source File: RecentTabsGroupView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for inflating from XML.
 *
 * @param context The context this view will work in.
 * @param attrs The attribute set for this view.
 */
public RecentTabsGroupView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = getResources();
    mDeviceLabelExpandedColor = ApiCompatibilityUtils.getColor(res, R.color.light_active_color);
    mDeviceLabelCollapsedColor =
            ApiCompatibilityUtils.getColor(res, R.color.ntp_list_header_text);
    mTimeLabelExpandedColor =
            ApiCompatibilityUtils.getColor(res, R.color.ntp_list_header_subtext_active);
    mTimeLabelCollapsedColor =
            ApiCompatibilityUtils.getColor(res, R.color.ntp_list_header_subtext);
}
 
Example 15
Source File: ChromeHomeIncognitoNewTabPage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a ChromeHomeIncognitoNewTabPage.
 * @param context The context used to inflate the view.
 * @param tab The {@link Tab} that is showing this new tab page.
 * @param tabModelSelector The {@link TabModelSelector} used to open tabs.
 * @param layoutManager The {@link LayoutManagerChrome} used to observe overview mode changes.
 *                      This may be null if the NTP is created on startup due to
 *                      PartnerBrowserCustomizations.
 */
public ChromeHomeIncognitoNewTabPage(final Context context, final Tab tab,
        final TabModelSelector tabModelSelector,
        @Nullable final LayoutManagerChrome layoutManager) {
    super(context, tab, tabModelSelector, layoutManager);

    mView = LayoutInflater.from(context).inflate(
            R.layout.chrome_home_incognito_new_tab_page, null);
    initializeCloseButton(mView.findViewById(R.id.close_button));

    Resources res = context.getResources();
    mBackgroundColor = ApiCompatibilityUtils.getColor(res, R.color.ntp_bg_incognito);
    mThemeColor = ApiCompatibilityUtils.getColor(res, R.color.incognito_primary_color);
}
 
Example 16
Source File: SeparateTaskCustomTabActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void finishNativeInitialization() {
    super.finishNativeInitialization();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTaskDescriptionHelper = new ActivityTabTaskDescriptionHelper(this,
                ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color));
    }
}
 
Example 17
Source File: FilterAdapter.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public void initialize(DownloadManagerUi manager) {
    mManagerUi = manager;
    mSelectedBackgroundColor = ApiCompatibilityUtils
            .getColor(mManagerUi.getActivity().getResources(), R.color.default_primary_color);
}
 
Example 18
Source File: ListUrlsActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.physical_web_list_urls_activity);

    initSharedPreferences();

    mAdapter = new NearbyUrlsAdapter(this);

    View emptyView = findViewById(R.id.physical_web_empty);
    mListView = (ListView) findViewById(R.id.physical_web_urls_list);
    mListView.setEmptyView(emptyView);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);

    mEmptyListText = (TextView) findViewById(R.id.physical_web_empty_list_text);

    mScanningImageView = (ImageView) findViewById(R.id.physical_web_logo);

    mSwipeRefreshWidget =
            (SwipeRefreshWidget) findViewById(R.id.physical_web_swipe_refresh_widget);
    mSwipeRefreshWidget.setOnRefreshListener(this);

    mBottomBar = findViewById(R.id.physical_web_bottom_bar);

    int shadowColor = ApiCompatibilityUtils.getColor(getResources(),
            R.color.bottom_bar_shadow_color);
    FadingShadowView shadow =
            (FadingShadowView) findViewById(R.id.physical_web_bottom_bar_shadow);
    shadow.init(shadowColor, FadingShadow.POSITION_BOTTOM);

    View bottomBarClose = (View) findViewById(R.id.physical_web_bottom_bar_close);
    bottomBarClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideBottomBar();
        }
    });

    mPwsClient = new PwsClientImpl(this);
    int referer = getIntent().getIntExtra(REFERER_KEY, 0);
    if (savedInstanceState == null) {  // Ensure this is a newly-created activity.
        PhysicalWebUma.onActivityReferral(this, referer);
    }
    mIsInitialDisplayRecorded = false;
    mIsRefreshing = false;
    mIsRefreshUserInitiated = false;
    mPhysicalWebBleClient =
        PhysicalWebBleClient.getInstance((ChromeApplication) getApplicationContext());
}
 
Example 19
Source File: DownloadUtils.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent that allows viewing the given file in an internal media viewer.
 * @param fileUri  URI pointing at the file, ideally in file:// form.
 * @param shareUri URI pointing at the file, ideally in content:// form.
 * @param mimeType MIME type of the file.
 * @return Intent that can be fired to open the file.
 */
public static Intent getMediaViewerIntentForDownloadItem(
        Uri fileUri, Uri shareUri, String mimeType) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(fileUri, mimeType);

    Bitmap closeIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_arrow_back_white_24dp);
    Bitmap shareIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_share_white_24dp);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.BLACK);
    builder.setCloseButtonIcon(closeIcon);
    builder.setShowTitle(true);

    // Create a PendingIntent that can be used to view the file externally.
    // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
    //                    different viewers could be visible at the same time.
    Intent chooserIntent = Intent.createChooser(viewIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String openWithStr = context.getString(R.string.download_manager_open_with);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(
            context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.addMenuItem(openWithStr, pendingViewIntent);

    // Create a PendingIntent that shares the file with external apps.
    PendingIntent pendingShareIntent = PendingIntent.getActivity(
            context, 0, createShareIntent(shareUri, mimeType), 0);
    builder.setActionButton(
            shareIcon, context.getString(R.string.share), pendingShareIntent, true);

    // The color of the media viewer is dependent on the file type.
    int backgroundRes;
    if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
        backgroundRes = R.color.image_viewer_bg;
    } else {
        backgroundRes = R.color.media_viewer_bg;
    }
    int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);

    // Build up the Intent further.
    Intent intent = builder.build().intent;
    intent.setPackage(context.getPackageName());
    intent.setData(fileUri);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
    intent.putExtra(
            CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
    intent.putExtra(
            CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    IntentHandler.addTrustedIntentExtras(intent, context);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClass(context, CustomTabActivity.class);
    return intent;
}
 
Example 20
Source File: DownloadUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent that allows viewing the given file in an internal media viewer.
 * @param fileUri    URI pointing at the file, ideally in file:// form.  Used only when
 *                   the media viewer is trying to locate the file on disk.
 * @param contentUri content:// URI pointing at the file.
 * @param mimeType   MIME type of the file.
 * @return Intent that can be fired to open the file.
 */
public static Intent getMediaViewerIntentForDownloadItem(
        Uri fileUri, Uri contentUri, String mimeType) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(contentUri, mimeType);

    Bitmap closeIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_arrow_back_white_24dp);
    Bitmap shareIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_share_white_24dp);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.BLACK);
    builder.setCloseButtonIcon(closeIcon);
    builder.setShowTitle(true);

    // Create a PendingIntent that can be used to view the file externally.
    // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
    //                    different viewers could be visible at the same time.
    Intent chooserIntent = Intent.createChooser(viewIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String openWithStr = context.getString(R.string.download_manager_open_with);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(
            context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.addMenuItem(openWithStr, pendingViewIntent);

    // Create a PendingIntent that shares the file with external apps.
    PendingIntent pendingShareIntent = PendingIntent.getActivity(
            context, 0, createShareIntent(contentUri, mimeType), 0);
    builder.setActionButton(
            shareIcon, context.getString(R.string.share), pendingShareIntent, true);

    // The color of the media viewer is dependent on the file type.
    int backgroundRes;
    if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
        backgroundRes = R.color.image_viewer_bg;
    } else {
        backgroundRes = R.color.media_viewer_bg;
    }
    int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);

    // Build up the Intent further.
    Intent intent = builder.build().intent;
    intent.setPackage(context.getPackageName());
    intent.setData(contentUri);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_MEDIA_VIEWER_URL, fileUri.toString());
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_ENABLE_EMBEDDED_MEDIA_EXPERIENCE, true);
    intent.putExtra(
            CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
    intent.putExtra(
            CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    IntentHandler.addTrustedIntentExtras(intent);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClass(context, ChromeLauncherActivity.class);
    return intent;
}