org.chromium.base.ApiCompatibilityUtils Java Examples

The following examples show how to use org.chromium.base.ApiCompatibilityUtils. 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: UiUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the set of locales supported by the current enabled Input Methods.
 * @param context A {@link Context} instance.
 * @return A possibly-empty {@link Set} of locale strings.
 */
public static Set<String> getIMELocales(Context context) {
    LinkedHashSet<String> locales = new LinkedHashSet<String>();
    InputMethodManager imManager =
            (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> enabledMethods = imManager.getEnabledInputMethodList();
    for (int i = 0; i < enabledMethods.size(); i++) {
        List<InputMethodSubtype> subtypes =
                imManager.getEnabledInputMethodSubtypeList(enabledMethods.get(i), true);
        if (subtypes == null) continue;
        for (int j = 0; j < subtypes.size(); j++) {
            String locale = ApiCompatibilityUtils.getLocale(subtypes.get(j));
            if (!TextUtils.isEmpty(locale)) locales.add(locale);
        }
    }
    return locales;
}
 
Example #2
Source File: IncognitoNewTabPageView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mScrollView = (NewTabPageScrollView) findViewById(R.id.ntp_scrollview);
    mScrollView.setBackgroundColor(
            ApiCompatibilityUtils.getColor(getResources(), R.color.ntp_bg_incognito));

    // FOCUS_BEFORE_DESCENDANTS is needed to support keyboard shortcuts. Otherwise, pressing
    // any shortcut causes the UrlBar to be focused. See ViewRootImpl.leaveTouchMode().
    mScrollView.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);

    View learnMore = findViewById(R.id.learn_more);
    learnMore.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mManager.loadIncognitoLearnMore();
        }
    });
}
 
Example #3
Source File: VisibleNetworks.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the specified object with this VisibleCell for equality.  Returns
 * {@code true} if the given object is a VisibleWifi and has identical values for
 * all of its fields except timestampMs.
 */
@Override
public boolean equals(Object object) {
    if (!(object instanceof VisibleCell)) {
        return false;
    }
    VisibleCell that = (VisibleCell) object;
    return ApiCompatibilityUtils.objectEquals(mRadioType, that.radioType())
            && ApiCompatibilityUtils.objectEquals(mCellId, that.cellId())
            && ApiCompatibilityUtils.objectEquals(
                       mLocationAreaCode, that.locationAreaCode())
            && ApiCompatibilityUtils.objectEquals(
                       mMobileCountryCode, that.mobileCountryCode())
            && ApiCompatibilityUtils.objectEquals(
                       mMobileNetworkCode, that.mobileNetworkCode())
            && ApiCompatibilityUtils.objectEquals(
                       mPrimaryScramblingCode, that.primaryScramblingCode())
            && ApiCompatibilityUtils.objectEquals(mPhysicalCellId, that.physicalCellId())
            && ApiCompatibilityUtils.objectEquals(
                       mTrackingAreaCode, that.trackingAreaCode());
}
 
Example #4
Source File: FindToolbarPhone.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateVisualsForTabModel(boolean isIncognito) {
    int queryTextColorId;
    if (isIncognito) {
        setBackgroundResource(R.color.incognito_primary_color);
        ColorStateList white = ApiCompatibilityUtils.getColorStateList(getResources(),
                R.color.light_mode_tint);
        mFindNextButton.setTint(white);
        mFindPrevButton.setTint(white);
        mCloseFindButton.setTint(white);
        queryTextColorId = R.color.find_in_page_query_white_color;
    } else {
        setBackgroundColor(Color.WHITE);
        ColorStateList dark = ApiCompatibilityUtils.getColorStateList(getResources(),
                R.color.dark_mode_tint);
        mFindNextButton.setTint(dark);
        mFindPrevButton.setTint(dark);
        mCloseFindButton.setTint(dark);
        queryTextColorId = R.color.find_in_page_query_color;
    }
    mFindQuery.setTextColor(
            ApiCompatibilityUtils.getColor(getContext().getResources(), queryTextColorId));
}
 
Example #5
Source File: RecentTabsGroupView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mDeviceIcon = (ImageView) findViewById(R.id.device_icon);
    mTimeLabel = (TextView) findViewById(R.id.time_label);
    mDeviceLabel = (TextView) findViewById(R.id.device_label);
    mExpandCollapseIcon = (ImageView) findViewById(R.id.expand_collapse_icon);

    // Create drawable for expand/collapse arrow.
    LevelListDrawable collapseIcon = new LevelListDrawable();
    collapseIcon.addLevel(DRAWABLE_LEVEL_COLLAPSED, DRAWABLE_LEVEL_COLLAPSED,
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_expanded));
    TintedDrawable collapse =
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_collapsed);
    collapse.setTint(
            ApiCompatibilityUtils.getColorStateList(getResources(), R.color.blue_mode_tint));
    collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED, collapse);
    mExpandCollapseIcon.setImageDrawable(collapseIcon);
}
 
Example #6
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 6 votes vote down vote up
private View createIcon(GridLayout parent, int rowIndex) {
    // The icon has a pre-defined width.
    ImageView icon = new ImageView(parent.getContext());
    icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    icon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
    icon.setImageResource(mOption.getDrawableIconId());
    icon.setMaxWidth(mIconMaxWidth);

    // The icon floats to the right of everything.
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(2, 1));
    iconParams.topMargin = mVerticalMargin;
    ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing);
    parent.addView(icon, iconParams);

    icon.setOnClickListener(OptionSection.this);
    return icon;
}
 
Example #7
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a ToolbarPhone object.
 * @param context The Context in which this View object is created.
 * @param attrs The AttributeSet that was specified with this View.
 */
public ToolbarPhone(Context context, AttributeSet attrs) {
    super(context, attrs);
    mToolbarSidePadding = getResources().getDimensionPixelOffset(
            R.dimen.toolbar_edge_padding);
    mLocationBarVerticalMargin =
            getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin);
    mLocationBarBackgroundCornerRadius =
            getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius);
    mProgressBackBackgroundColorWhite = ApiCompatibilityUtils.getColor(getResources(),
            R.color.progress_bar_background_white);
    mLightModeDefaultColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.light_mode_tint);
    mDarkModeDefaultColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.dark_mode_tint);
}
 
Example #8
Source File: WebappActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void initializeWebappData() {
    if (mWebappInfo.displayMode() == WebDisplayMode.FULLSCREEN) {
        enterImmersiveMode();
    }

    final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
            ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));

    mSplashScreen = new FrameLayout(this);
    mSplashScreen.setBackgroundColor(backgroundColor);

    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.addView(mSplashScreen);

    mWebappUma.splashscreenVisible();
    mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
    mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);

    initializeSplashScreenWidgets(backgroundColor);
}
 
Example #9
Source File: CustomNotificationBuilder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the work profile badge if it is needed.
 */
private void addWorkProfileBadge(RemoteViews view) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
    int[] colors = new int[size * size];

    // Create an immutable bitmap, so that it can not be reused for painting a badge into it.
    Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);

    Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
    Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
            mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);

    // The input bitmap is immutable, so the output drawable will be a different instance from
    // the input drawable if the work profile badge was applied.
    if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
        view.setImageViewBitmap(
                R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
        view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
    }
}
 
Example #10
Source File: ToolbarTablet.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {
    if (isBookmarked) {
        mBookmarkButton.setImageResource(R.drawable.btn_star_filled);
        // Non-incognito mode shows a blue filled star.
        mBookmarkButton.setTint(isIncognito()
                ? mLightModeTint
                : ApiCompatibilityUtils.getColorStateList(
                        getResources(), R.color.blue_mode_tint));
        mBookmarkButton.setContentDescription(getContext().getString(
                R.string.edit_bookmark));
    } else {
        mBookmarkButton.setImageResource(R.drawable.btn_star);
        mBookmarkButton.setTint(isIncognito() ? mLightModeTint : mDarkModeTint);
        mBookmarkButton.setContentDescription(getContext().getString(
                R.string.accessibility_menu_bookmark));
    }
    mBookmarkButton.setEnabled(editingAllowed);
}
 
Example #11
Source File: IncognitoNewTabPage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an Incognito NewTabPage.
 * @param activity The activity used to create the new tab page's View.
 */
public IncognitoNewTabPage(Activity activity) {
    mActivity = activity;

    mTitle = activity.getResources().getString(R.string.button_new_tab);
    mBackgroundColor =
            ApiCompatibilityUtils.getColor(activity.getResources(), R.color.ntp_bg_incognito);
    mThemeColor = ApiCompatibilityUtils.getColor(activity.getResources(),
            R.color.incognito_primary_color);

    LayoutInflater inflater = LayoutInflater.from(activity);
    mIncognitoNewTabPageView = (IncognitoNewTabPageView) inflater.inflate(useMDIncognitoNTP()
                    ? R.layout.new_tab_page_incognito_md
                    : R.layout.new_tab_page_incognito,
            null);
    mIncognitoNewTabPageView.initialize(mIncognitoNewTabPageManager);

    if (!useMDIncognitoNTP()) {
        TextView newTabIncognitoMessage = (TextView) mIncognitoNewTabPageView.findViewById(
                R.id.new_tab_incognito_message);
        newTabIncognitoMessage.setText(
                activity.getResources().getString(R.string.new_tab_incognito_message));
    }
}
 
Example #12
Source File: SnackbarView.java    From delion with Apache License 2.0 6 votes vote down vote up
void adjustViewPosition() {
    mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect);
    // Only update if the visible frame has changed, otherwise there will be a layout loop.
    if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) {
        mPreviousVisibleRect.set(mCurrentVisibleRect);

        int keyboardHeight = mParent.getHeight() - mCurrentVisibleRect.bottom
                + mCurrentVisibleRect.top;
        MarginLayoutParams lp = getLayoutParams();
        lp.bottomMargin = keyboardHeight;
        if (mIsTablet) {
            int margin = mParent.getResources()
                    .getDimensionPixelSize(R.dimen.snackbar_margin_tablet);
            ApiCompatibilityUtils.setMarginStart(lp, margin);
            lp.bottomMargin += margin;
            int width = mParent.getResources()
                    .getDimensionPixelSize(R.dimen.snackbar_width_tablet);
            lp.width = Math.min(width, mParent.getWidth() - 2 * margin);
        }
        mView.setLayoutParams(lp);
    }
}
 
Example #13
Source File: CustomTabTabPersistencePolicy.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Given a list of metadata files, determine which are applicable for deletion based on the
 * deletion strategy of Custom Tabs.
 *
 * @param currentTimeMillis The current time in milliseconds
 *                          ({@link System#currentTimeMillis()}.
 * @param allMetadataFiles The complete list of all metadata files to check.
 * @return The list of metadata files that are applicable for deletion.
 */
protected static List<File> getMetadataFilesForDeletion(
        long currentTimeMillis, List<File> allMetadataFiles) {
    Collections.sort(allMetadataFiles, new Comparator<File>() {
        @Override
        public int compare(File lhs, File rhs) {
            long lhsModifiedTime = lhs.lastModified();
            long rhsModifiedTime = rhs.lastModified();

            // Sort such that older files (those with an lower timestamp number) are at the
            // end of the sorted listed.
            return ApiCompatibilityUtils.compareLong(rhsModifiedTime, lhsModifiedTime);
        }
    });

    List<File> stateFilesApplicableForDeletion = new ArrayList<File>();
    for (int i = 0; i < allMetadataFiles.size(); i++) {
        File file = allMetadataFiles.get(i);
        long fileAge = currentTimeMillis - file.lastModified();
        if (i >= MAXIMUM_STATE_FILES || fileAge >= STATE_EXPIRY_THRESHOLD) {
            stateFilesApplicableForDeletion.add(file);
        }
    }
    return stateFilesApplicableForDeletion;
}
 
Example #14
Source File: DownloadManagerUi.java    From delion with Apache License 2.0 6 votes vote down vote up
SpaceDisplay(final ViewGroup parent) {
    mSpaceUsedTextView = (TextView) parent.findViewById(R.id.space_used_display);
    mSpaceTotalTextView = (TextView) parent.findViewById(R.id.space_total_display);
    mSpaceBar = (ProgressBar) parent.findViewById(R.id.space_bar);

    mFileSystemBytesTask = new AsyncTask<Void, Void, Long>() {
        @Override
        protected Long doInBackground(Void... params) {
            StatFs statFs = new StatFs(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS).getPath());
            long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs);
            long blockSize = ApiCompatibilityUtils.getBlockSize(statFs);
            long fileSystemBytes = totalBlocks * blockSize;
            return fileSystemBytes;
        }
    };
    mFileSystemBytesTask.execute();
}
 
Example #15
Source File: DownloadManagerUi.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the UI for the given Activity.
 *
 * @param activity Activity that is showing the UI.
 */
public void initialize(DownloadManagerUiDelegate delegate, Activity activity) {
    mDelegate = delegate;

    mActionBarDrawerToggle = new ActionBarDrawerToggle(activity,
            this, (Toolbar) findViewById(R.id.action_bar),
            R.string.accessibility_bookmark_drawer_toggle_btn_open,
            R.string.accessibility_bookmark_drawer_toggle_btn_close);
    addDrawerListener(mActionBarDrawerToggle);
    mActionBarDrawerToggle.syncState();

    FadingShadowView shadow = (FadingShadowView) findViewById(R.id.shadow);
    if (DeviceFormFactor.isLargeTablet(getContext())) {
        shadow.setVisibility(View.GONE);
    } else {
        shadow.init(ApiCompatibilityUtils.getColor(getResources(),
                R.color.toolbar_shadow_color), FadingShadow.POSITION_TOP);
    }

    mSpaceDisplay.update(0);

    ((Toolbar) findViewById(R.id.action_bar)).setTitle(R.string.menu_downloads);
}
 
Example #16
Source File: ToolbarTablet.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {
    if (isBookmarked) {
        mBookmarkButton.setImageResource(R.drawable.btn_star_filled);
        // Non-incognito mode shows a blue filled star.
        mBookmarkButton.setTint(isIncognito()
                ? mLightModeTint
                : ApiCompatibilityUtils.getColorStateList(
                        getResources(), R.color.blue_mode_tint));
        mBookmarkButton.setContentDescription(getContext().getString(
                R.string.edit_bookmark));
    } else {
        mBookmarkButton.setImageResource(R.drawable.btn_star);
        mBookmarkButton.setTint(isIncognito() ? mLightModeTint : mDarkModeTint);
        mBookmarkButton.setContentDescription(getContext().getString(
                R.string.accessibility_menu_bookmark));
    }
    mBookmarkButton.setEnabled(editingAllowed);
}
 
Example #17
Source File: UrlBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    mFocused = focused;
    if (!focused) mAutocompleteSpan.clearSpan();
    super.onFocusChanged(focused, direction, previouslyFocusedRect);

    if (focused && mFirstFocusTimeMs == 0) {
        mFirstFocusTimeMs = SystemClock.elapsedRealtime();
        if (mOmniboxLivenessListener != null) mOmniboxLivenessListener.onOmniboxFocused();
    }

    if (focused) StartupMetrics.getInstance().recordFocusedOmnibox();

    // When unfocused, force left-to-right rendering at the paragraph level (which is desired
    // for URLs). Right-to-left runs are still rendered RTL, but will not flip the whole URL
    // around. This is consistent with OmniboxViewViews on desktop. When focused, render text
    // normally (to allow users to make non-URL searches and to avoid showing Android's split
    // insertion point when an RTL user enters RTL text).
    if (focused) {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT);
    } else {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR);
    }
    // Always align to the same as the paragraph direction (LTR = left, RTL = right).
    ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START);
}
 
Example #18
Source File: SuggestionView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (getMeasuredWidth() == 0) return;

    if (mSuggestion.getType() != OmniboxSuggestionType.SEARCH_SUGGEST_TAIL) {
        mContentsView.resetTextWidths();
    }

    boolean refineVisible = mRefineView.getVisibility() == VISIBLE;
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    int contentsViewOffsetX = isRtl && refineVisible ? mRefineWidth : 0;
    mContentsView.layout(
            contentsViewOffsetX,
            0,
            contentsViewOffsetX + mContentsView.getMeasuredWidth(),
            mContentsView.getMeasuredHeight());
    int refineViewOffsetX = isRtl ? 0 : getMeasuredWidth() - mRefineWidth;
    mRefineView.layout(
            refineViewOffsetX,
            0,
            refineViewOffsetX + mRefineWidth,
            mContentsView.getMeasuredHeight());
}
 
Example #19
Source File: SuggestionView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sets a description line for the omnibox suggestion.
 *
 * @param str The description text.
 * @param isUrl Whether this text is a URL (as opposed to a normal string).
 */
private void showDescriptionLine(Spannable str, boolean isUrl) {
    TextView textLine = mContentsView.mTextLine2;
    if (textLine.getVisibility() != VISIBLE) {
        textLine.setVisibility(VISIBLE);
    }
    textLine.setText(str, BufferType.SPANNABLE);

    // Force left-to-right rendering for URLs. See UrlBar constructor for details.
    if (isUrl) {
        textLine.setTextColor(URL_COLOR);
        ApiCompatibilityUtils.setTextDirection(textLine, TEXT_DIRECTION_LTR);
    } else {
        textLine.setTextColor(getStandardFontColor());
        ApiCompatibilityUtils.setTextDirection(textLine, TEXT_DIRECTION_INHERIT);
    }
}
 
Example #20
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Call to force the UI to update the state of various buttons based on whether or not the
 * current tab is incognito.
 */
@Override
public void updateVisualsForState() {
    if (updateUseDarkColors() || mIsEmphasizingHttpsScheme != shouldEmphasizeHttpsScheme()) {
        updateSecurityIcon(getSecurityLevel());
    }
    ColorStateList colorStateList = ApiCompatibilityUtils.getColorStateList(getResources(),
            mUseDarkColors ? R.color.dark_mode_tint : R.color.light_mode_tint);
    mMicButton.setTint(colorStateList);
    mDeleteButton.setTint(colorStateList);

    setNavigationButtonType(mNavigationButtonType);
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    if (mSuggestionList != null) {
        mSuggestionList.setBackground(getSuggestionPopupBackground());
    }
    mSuggestionListAdapter.setUseDarkColors(mUseDarkColors);
}
 
Example #21
Source File: SuggestionView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private int getUrlBarLeftOffset() {
    if (mLocationBar.mustQueryUrlBarLocationForSuggestions()) {
        View contentView = getRootView().findViewById(android.R.id.content);
        ViewUtils.getRelativeLayoutPosition(contentView, mUrlBar, mViewPositionHolder);
        return mViewPositionHolder[0];
    } else {
        return ApiCompatibilityUtils.isLayoutRtl(this) ? mPhoneUrlBarLeftOffsetRtlPx
                : mPhoneUrlBarLeftOffsetPx;
    }
}
 
Example #22
Source File: ContentWrapperView.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructs a ContentWrapperView object.
 * @param context The context to create this View with.
 */
public ContentWrapperView(Context context, InfoBar infoBar, int backgroundType, View panel,
        boolean infoBarsFromTop) {
    // Set up this ViewGroup.
    super(context);
    mInfoBar = infoBar;
    mGravity = infoBarsFromTop ? Gravity.BOTTOM : Gravity.TOP;
    mInfoBarsFromTop = infoBarsFromTop;

    // Pull out resources we need for the backgrounds.  Defaults to the INFO type.
    int separatorBackground = R.color.infobar_info_background_separator;
    int layoutBackground = R.drawable.infobar_info_background;
    if (backgroundType == InfoBar.BACKGROUND_TYPE_WARNING) {
        layoutBackground = R.drawable.infobar_warning_background;
        separatorBackground = R.color.infobar_warning_background_separator;
    }

    // Set up this view.
    Resources resources = context.getResources();
    LayoutParams wrapParams = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    setLayoutParams(wrapParams);
    ApiCompatibilityUtils.setBackgroundForView(this, resources.getDrawable(layoutBackground));

    // Add a separator line that delineates different InfoBars.
    View separator = new View(context);
    separator.setBackgroundColor(resources.getColor(separatorBackground));
    addView(separator, new LayoutParams(LayoutParams.MATCH_PARENT, getBoundaryHeight(context),
            mGravity));

    // Add the InfoBar content.
    addChildView(panel);
}
 
Example #23
Source File: PromoDialogLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the header layout needs to be adjusted to ensure the scrollable content
 * is usable in small form factors.
 *
 * @return Whether the layout needed to be adjusted.
 */
private boolean fixupHeader() {
    if (mParams.drawableResource != 0 || mParams.vectorDrawableResource != 0) return false;

    int minScrollHeight =
            getResources().getDimensionPixelSize(R.dimen.promo_dialog_min_scrollable_height);
    boolean shouldHeaderScroll = mScrollingContainer.getMeasuredHeight() < minScrollHeight;
    ViewGroup desiredParent;
    boolean applyHeaderPadding;
    if (shouldHeaderScroll) {
        desiredParent = mScrollableContent;
        applyHeaderPadding = false;
    } else {
        desiredParent = this;
        applyHeaderPadding = true;
    }
    if (mHeaderView.getParent() == desiredParent) return false;
    ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView);
    desiredParent.addView(mHeaderView, 0);

    int startEndPadding = applyHeaderPadding
            ? getResources().getDimensionPixelSize(R.dimen.promo_dialog_padding)
            : 0;
    ApiCompatibilityUtils.setPaddingRelative(
            mHeaderView, startEndPadding, 0, startEndPadding, 0);
    return true;
}
 
Example #24
Source File: BottomSheetContentController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateVisuals(boolean isIncognitoTabModelSelected) {
    setBackgroundResource(isIncognitoTabModelSelected ? R.color.incognito_primary_color
                                                      : R.color.default_primary_color);

    ColorStateList tint = ApiCompatibilityUtils.getColorStateList(getResources(),
            isIncognitoTabModelSelected ? R.color.bottom_nav_tint_incognito
                                        : R.color.bottom_nav_tint);
    setItemIconTintList(tint);
    setItemTextColor(tint);
}
 
Example #25
Source File: ToolbarTablet.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the toolbar start padding based on whether the buttons are visible.
 * @param buttonsVisible Whether the toolbar buttons are visible.
 */
private void setStartPaddingBasedOnButtonVisibility(boolean buttonsVisible) {
    buttonsVisible = buttonsVisible || mHomeButton.getVisibility() == View.VISIBLE;

    ApiCompatibilityUtils.setPaddingRelative(this,
            buttonsVisible ? mStartPaddingWithButtons : mStartPaddingWithoutButtons,
            getPaddingTop(),
            ApiCompatibilityUtils.getPaddingEnd(this),
            getPaddingBottom());
}
 
Example #26
Source File: SpaceDisplay.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected Long doInBackground(Void... params) {
    File downloadDirectory = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS);

    // Create the downloads directory, if necessary.
    if (!downloadDirectory.exists()) {
        try {
            // mkdirs() can fail, so we still need to check if the directory exists
            // later.
            downloadDirectory.mkdirs();
        } catch (SecurityException e) {
            Log.e(TAG, "SecurityException when creating download directory.", e);
        }
    }

    // Determine how much space is available on the storage device where downloads
    // reside.  If the downloads directory doesn't exist, it is likely that the user
    // doesn't have an SD card installed.
    long blocks = 0;
    if (downloadDirectory.exists()) {
        StatFs statFs = new StatFs(downloadDirectory.getPath());
        if (mFetchTotalSize) {
            blocks = ApiCompatibilityUtils.getBlockCount(statFs);
        } else {
            blocks = ApiCompatibilityUtils.getAvailableBlocks(statFs);
        }

        return blocks * ApiCompatibilityUtils.getBlockSize(statFs);
    } else {
        Log.e(TAG, "Download directory doesn't exist.");
        return 0L;
    }
}
 
Example #27
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 #28
Source File: RecentTabsGroupView.java    From 365browser 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 #29
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 #30
Source File: SiteSettingsCategory.java    From AndroidChromium 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;
}