org.chromium.ui.base.DeviceFormFactor Java Examples

The following examples show how to use org.chromium.ui.base.DeviceFormFactor. 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: SnackbarView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance of the {@link SnackbarView}.
 * @param activity The activity that displays the snackbar.
 * @param listener An {@link OnClickListener} that will be called when the action button is
 *                 clicked.
 * @param snackbar The snackbar to be displayed.
 * @param parentView The ViewGroup used to display this snackbar. If this is null, this class
 *                   will determine where to attach the snackbar.
 */
SnackbarView(Activity activity, OnClickListener listener, Snackbar snackbar,
        @Nullable ViewGroup parentView) {
    mActivity = activity;
    mIsTablet = DeviceFormFactor.isTablet();

    if (parentView == null) {
        mOriginalParent = findParentView(activity);
        if (activity instanceof ChromeActivity) mAnimateOverWebContent = true;
    } else {
        mOriginalParent = parentView;
    }

    mParent = mOriginalParent;
    mView = (ViewGroup) LayoutInflater.from(activity).inflate(
            R.layout.snackbar, mParent, false);
    mAnimationDuration = mView.getResources()
            .getInteger(android.R.integer.config_mediumAnimTime);
    mMessageView = (TemplatePreservingTextView) mView.findViewById(R.id.snackbar_message);
    mActionButtonView = (TextView) mView.findViewById(R.id.snackbar_button);
    mActionButtonView.setOnClickListener(listener);
    mProfileImageView = (ImageView) mView.findViewById(R.id.snackbar_profile_image);

    updateInternal(snackbar, false);
}
 
Example #2
Source File: ChromeBrowserInitializer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #3
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Shows bookmark main UI.
 */
public static void showBookmarkManager(ChromeActivity activity) {
    String url = getFirstUrlToLoad(activity);

    if (activity.getBottomSheet() != null) {
        activity.getBottomSheetContentController().showContentAndOpenSheet(
                R.id.action_bookmarks);
    } else if (DeviceFormFactor.isTablet()) {
        openUrl(activity, url, activity.getComponentName());
    } else {
        Intent intent = new Intent(activity, BookmarkActivity.class);
        intent.setData(Uri.parse(url));
        intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
        activity.startActivity(intent);
    }
}
 
Example #4
Source File: RecentTabsExpandableListView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!DeviceFormFactor.isTablet(getContext())) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }

    // Increase padding if needed to ensure children are no wider than mMaxListViewWidth.
    int childWidth = MeasureSpec.getSize(widthMeasureSpec);
    int excessWidth = childWidth - mMaxListViewWidth;
    int horizontalPadding = 0;
    if (excessWidth > 0) {
        horizontalPadding += excessWidth / 2;
    }

    setPadding(horizontalPadding, 0, horizontalPadding, 0);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example #5
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #6
Source File: InfoBarContainer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public InfoBarContainer(Context context, int tabId, TabContentViewParent parentView, Tab tab) {
    super(context, null);
    tab.addObserver(mTabObserver);

    // TODO(newt): move this workaround into the infobar views if/when they're scrollable.
    // Workaround for http://crbug.com/407149. See explanation in onMeasure() below.
    setVerticalScrollBarEnabled(false);

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
    int topMarginDp = DeviceFormFactor.isTablet(context)
            ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP;
    lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics().density);
    setLayoutParams(lp);

    mTabId = tabId;
    mParentView = parentView;

    mLayout = new InfoBarContainerLayout(context);
    addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));

    // Chromium's InfoBarContainer may add an InfoBar immediately during this initialization
    // call, so make sure everything in the InfoBarContainer is completely ready beforehand.
    mNativeInfoBarContainer = nativeInit();
}
 
Example #7
Source File: SuggestionView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (DeviceFormFactor.isTablet(getContext())) {
        // Use the same image transform matrix as the navigation icon to ensure the same
        // scaling, which requires centering vertically based on the height of the
        // navigation icon view and not the image itself.
        canvas.save();
        mSuggestionIconLeft = getSuggestionIconLeftPosition();
        canvas.translate(
                mSuggestionIconLeft,
                (getMeasuredHeight() - mNavigationButton.getMeasuredHeight()) / 2f);
        canvas.concat(mNavigationButton.getImageMatrix());
        mSuggestionIcon.draw(canvas);
        canvas.restore();
    }
}
 
Example #8
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    RecordUserAction.record("MobileBookmarkManagerEntryOpened");
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet()) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #9
Source File: ItemChooserDialog.java    From delion with Apache License 2.0 6 votes vote down vote up
private void showDialogForView(View view) {
    mDialog = new Dialog(mActivity);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.addContentView(view,
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                          LinearLayout.LayoutParams.MATCH_PARENT));
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mItemSelectedCallback.onItemSelected("");
        }
    });

    Window window = mDialog.getWindow();
    if (!DeviceFormFactor.isTablet(mActivity)) {
        // On smaller screens, make the dialog fill the width of the screen,
        // and appear at the top.
        window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        window.setGravity(Gravity.TOP);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                         ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    mDialog.show();
}
 
Example #10
Source File: CustomTabToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void updateSecurityIcon(int securityLevel) {
    if (mState == STATE_TITLE_ONLY) return;

    mSecurityIconType = securityLevel;

    if (securityLevel == ConnectionSecurityLevel.NONE) {
        mAnimDelegate.hideSecurityButton();
    } else {
        boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
        int id = LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice);
        if (id == 0) {
            mSecurityButton.setImageDrawable(null);
        } else {
            // ImageView#setImageResource is no-op if given resource is the current one.
            mSecurityButton.setImageResource(id);
            mSecurityButton.setTint(LocationBarLayout.getColorStateList(
                    securityLevel, getToolbarDataProvider(), getResources()));
        }
        mAnimDelegate.showSecurityButton();
    }
    mUrlBar.emphasizeUrl();
    mUrlBar.invalidate();
}
 
Example #11
Source File: AsyncInitializationActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(newBase);

    // On N+, Chrome should always retain the tab strip layout on tablets. Normally in
    // multi-window, if Chrome is launched into a smaller screen Android will load the tab
    // switcher resources. Overriding the smallestScreenWidthDp in the Configuration ensures
    // Android will load the tab strip resources. See crbug.com/588838.
    if (Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        int smallestDeviceWidthDp = DeviceFormFactor.getSmallestDeviceWidthDp(this);

        if (smallestDeviceWidthDp >= DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) {
            Configuration overrideConfiguration = new Configuration();
            overrideConfiguration.smallestScreenWidthDp = smallestDeviceWidthDp;
            applyOverrideConfiguration(overrideConfiguration);
        }
    }
}
 
Example #12
Source File: ChromeBrowserInitializer.java    From delion with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #13
Source File: SuggestionView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (DeviceFormFactor.isTablet(getContext())) {
        // Use the same image transform matrix as the navigation icon to ensure the same
        // scaling, which requires centering vertically based on the height of the
        // navigation icon view and not the image itself.
        canvas.save();
        mSuggestionIconLeft = getSuggestionIconLeftPosition();
        canvas.translate(
                mSuggestionIconLeft,
                (getMeasuredHeight() - mNavigationButton.getMeasuredHeight()) / 2f);
        canvas.concat(mNavigationButton.getImageMatrix());
        mSuggestionIcon.draw(canvas);
        canvas.restore();
    }
}
 
Example #14
Source File: ToolbarSceneLayer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public SceneOverlayLayer getUpdatedSceneOverlayTree(RectF viewport, RectF visibleViewport,
        LayerTitleCache layerTitleCache, ResourceManager resourceManager, float yOffset) {
    boolean forceHideBrowserControlsAndroidView =
            mLayoutProvider.getActiveLayout().forceHideBrowserControlsAndroidView();
    ViewportMode viewportMode = mLayoutProvider.getActiveLayout().getViewportMode();

    // TODO(mdjones): Create a "theme provider" to handle cases like this.
    int color = mRenderHost.getBrowserControlsBackgroundColor();
    float alpha = mRenderHost.getBrowserControlsUrlBarAlpha();
    ChromeFullscreenManager fullscreenManager = mLayoutProvider.getFullscreenManager();
    if (fullscreenManager.areBrowserControlsAtBottom() && fullscreenManager.getTab() != null) {
        color = fullscreenManager.getTab().getDefaultThemeColor();
        if (!fullscreenManager.getTab().isIncognito()) alpha = 1f;
    }

    update(color, alpha, mLayoutProvider.getFullscreenManager(), resourceManager,
            forceHideBrowserControlsAndroidView, viewportMode, DeviceFormFactor.isTablet(),
            viewport.height());

    return this;
}
 
Example #15
Source File: RecentTabsExpandableListView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!DeviceFormFactor.isTablet(getContext())) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }

    // Increase padding if needed to ensure children are no wider than mMaxListViewWidth.
    int childWidth = MeasureSpec.getSize(widthMeasureSpec);
    int excessWidth = childWidth - mMaxListViewWidth;
    int horizontalPadding = 0;
    if (excessWidth > 0) {
        horizontalPadding += excessWidth / 2;
    }

    setPadding(horizontalPadding, 0, horizontalPadding, 0);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example #16
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the size of the virtual tab strip, making the tabs resize and move accordingly.
 * @param width  The new available width.
 * @param height The new height this stack should be.
 */
public void onSizeChanged(float width, float height) {
    if (mWidth == width && mHeight == height) return;

    boolean widthChanged = mWidth != width;

    mWidth = width;
    mHeight = height;

    for (int i = 0; i < mStripTabs.length; i++) {
        mStripTabs[i].setHeight(mHeight);
    }

    if (widthChanged) {
        computeAndUpdateTabWidth(false);
        setShouldCascadeTabs(width >= DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP);
    }
    if (mStripTabs.length > 0) mUpdateHost.requestUpdate();

    // Dismiss tab menu, similar to how the app menu is dismissed on orientation change
    mTabMenu.dismiss();
}
 
Example #17
Source File: BookmarkUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #18
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the size of the virtual tab strip, making the tabs resize and move accordingly.
 * @param width  The new available width.
 * @param height The new height this stack should be.
 */
public void onSizeChanged(float width, float height) {
    if (mWidth == width && mHeight == height) return;

    boolean widthChanged = mWidth != width;

    mWidth = width;
    mHeight = height;

    for (int i = 0; i < mStripTabs.length; i++) {
        mStripTabs[i].setHeight(mHeight);
    }

    if (widthChanged) {
        computeAndUpdateTabWidth(false);
        setShouldCascadeTabs(width >= DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP);
    }
    if (mStripTabs.length > 0) mUpdateHost.requestUpdate();

    // Dismiss tab menu, similar to how the app menu is dismissed on orientation change
    mTabMenu.dismiss();
}
 
Example #19
Source File: HistoryManagerUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the browsing history manager.
 *
 * @param activity The {@link ChromeActivity} that owns the {@link HistoryManager}.
 * @param tab The {@link Tab} to used to display the native page version of the
 *            {@link HistoryManager}.
 */
public static void showHistoryManager(ChromeActivity activity, Tab tab) {
    Context appContext = ContextUtils.getApplicationContext();
    if (activity.getBottomSheet() != null) {
        activity.getBottomSheetContentController().showContentAndOpenSheet(R.id.action_history);
    } else if (DeviceFormFactor.isTablet()) {
        // History shows up as a tab on tablets.
        LoadUrlParams params = new LoadUrlParams(UrlConstants.NATIVE_HISTORY_URL);
        tab.loadUrl(params);
    } else {
        Intent intent = new Intent();
        intent.setClass(appContext, HistoryActivity.class);
        intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
        activity.startActivity(intent);
    }
}
 
Example #20
Source File: InfoBarContainer.java    From delion with Apache License 2.0 6 votes vote down vote up
public InfoBarContainer(Context context, int tabId, TabContentViewParent parentView, Tab tab) {
    super(context, null);
    tab.addObserver(mTabObserver);

    // TODO(newt): move this workaround into the infobar views if/when they're scrollable.
    // Workaround for http://crbug.com/407149. See explanation in onMeasure() below.
    setVerticalScrollBarEnabled(false);

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
    int topMarginDp = DeviceFormFactor.isTablet(context)
            ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP;
    lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics().density);
    setLayoutParams(lp);

    mTabId = tabId;
    mParentView = parentView;

    mLayout = new InfoBarContainerLayout(context);
    addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));

    // Chromium's InfoBarContainer may add an InfoBar immediately during this initialization
    // call, so make sure everything in the InfoBarContainer is completely ready beforehand.
    mNativeInfoBarContainer = nativeInit();
}
 
Example #21
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #22
Source File: LayerTitleCache.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private String getUpdatedTitleInternal(Tab tab, String titleString,
        boolean fetchFaviconFromHistory) {
    final int tabId = tab.getId();
    Bitmap originalFavicon = tab.getFavicon();

    boolean isDarkTheme = tab.isIncognito();
    // The theme might require lighter text.
    if (!DeviceFormFactor.isTablet(mContext)) {
        isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    }

    ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    boolean isRtl = tab.isTitleDirectionRtl();
    TitleBitmapFactory titleBitmapFactory = isDarkTheme
            ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory;

    Title title = mTitles.get(tabId);
    if (title == null) {
        title = new Title();
        mTitles.put(tabId, title);
        title.register();
    }

    title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString),
            titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon),
            fetchFaviconFromHistory);

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(),
                title.getFaviconResId(), isDarkTheme, isRtl);
    }
    return titleString;
}
 
Example #23
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the security icon displayed in the LocationBar.
 */
@Override
public void updateSecurityIcon(int securityLevel) {
    boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
    boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOfflinePage();
    int id = getSecurityIconResource(securityLevel, isSmallDevice, isOfflinePage);
    if (id == 0) {
        mSecurityButton.setImageDrawable(null);
    } else {
        // ImageView#setImageResource is no-op if given resource is the current one.
        mSecurityButton.setImageResource(id);
        mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarDataProvider(),
                getResources(), ColorUtils.shouldUseOpaqueTextboxBackground(
                        getToolbarDataProvider().getPrimaryColor())));
    }

    updateVerboseStatusVisibility();

    boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme();
    if (mSecurityIconResource == id
            && mIsEmphasizingHttpsScheme == shouldEmphasizeHttpsScheme) {
        return;
    }
    mSecurityIconResource = id;

    changeLocationBarIcon();
    updateLocationBarIconContainerVisibility();
    // Since we emphasize the scheme of the URL based on the security type, we need to
    // refresh the emphasis.
    mUrlBar.deEmphasizeUrl();
    emphasizeUrl();
    mIsEmphasizingHttpsScheme = shouldEmphasizeHttpsScheme;
}
 
Example #24
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void updateNavigationButton() {
    boolean isTablet = DeviceFormFactor.isTablet(getContext());
    NavigationButtonType type = NavigationButtonType.EMPTY;
    if (isTablet && !mSuggestionItems.isEmpty()) {
        // If there are suggestions showing, show the icon for the default suggestion.
        type = suggestionTypeToNavigationButtonType(
                mSuggestionItems.get(0).getSuggestion());
    } else if (isTablet) {
        type = NavigationButtonType.PAGE;
    }

    if (type != mNavigationButtonType) setNavigationButtonType(type);
}
 
Example #25
Source File: ItemChooserDialog.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void showDialogForView(View view) {
    mDialog = new Dialog(mActivity) {
        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if (!hasFocus) super.dismiss();
        }
    };
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setCanceledOnTouchOutside(true);
    mDialog.addContentView(view,
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                          LinearLayout.LayoutParams.MATCH_PARENT));
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mItemSelectedCallback.onItemSelected("");
        }
    });

    Window window = mDialog.getWindow();
    if (!DeviceFormFactor.isTablet(mActivity)) {
        // On smaller screens, make the dialog fill the width of the screen,
        // and appear at the top.
        window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        window.setGravity(Gravity.TOP);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                         ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    mDialog.show();
}
 
Example #26
Source File: ToolbarSceneLayer.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public SceneOverlayLayer getUpdatedSceneOverlayTree(LayerTitleCache layerTitleCache,
        ResourceManager resourceManager, float yOffset) {
    boolean forceHideBrowserControlsAndroidView =
            mLayoutProvider.getActiveLayout().forceHideBrowserControlsAndroidView();
    int flags = mLayoutProvider.getActiveLayout().getSizingFlags();

    update(mRenderHost.getBrowserControlsBackgroundColor(),
            mRenderHost.getBrowserControlsUrlBarAlpha(), mLayoutProvider.getFullscreenManager(),
            resourceManager, forceHideBrowserControlsAndroidView, flags,
            DeviceFormFactor.isTablet(mContext));

    return this;
}
 
Example #27
Source File: PageInfoPopup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Dismiss the popup, and then run a task after the animation has completed (if there is one).
 */
private void runAfterDismiss(Runnable task) {
    mDialog.dismiss();
    if (DeviceFormFactor.isTablet()) {
        task.run();
    } else {
        mContainer.postDelayed(task, FADE_DURATION + CLOSE_CLEANUP_DELAY);
    }
}
 
Example #28
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void internalInit() {
    mTabObserver = new EmptyTabObserver() {
        @Override
        public void onContentChanged(Tab tab) {
            CompositorViewHolder.this.onContentChanged();
        }
    };

    mEnableCompositorTabStrip = DeviceFormFactor.isTablet(getContext());

    addOnLayoutChangeListener(new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            propagateViewportToLayouts(right - left, bottom - top);

            // If there's an event that needs to occur after the keyboard is hidden, post
            // it as a delayed event.  Otherwise this happens in the midst of the
            // ContentView's relayout, which causes the ContentView to relayout on top of the
            // stack view.  The 30ms is arbitrary, hoping to let the view get one repaint
            // in so the full page is shown.
            if (mPostHideKeyboardTask != null) {
                new Handler().postDelayed(mPostHideKeyboardTask, 30);
                mPostHideKeyboardTask = null;
            }
        }
    });

    mCompositorView = new CompositorView(getContext(), this);
    // mCompositorView should always be the first child.
    addView(mCompositorView, 0,
            new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
 
Example #29
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateActionMode(ActionMode mode, Menu menu) {
    mode.setTitle(DeviceFormFactor.isTablet()
                    ? mContext.getString(R.string.actionbar_textselection_title)
                    : null);
    mode.setSubtitle(null);
    createActionMenu(mode, menu);
}
 
Example #30
Source File: ItemChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void showDialogForView(View view) {
    mDialog = new Dialog(mActivity) {
        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if (!mIgnorePendingWindowFocusChangeForClose && !hasFocus) super.dismiss();
            setIgnorePendingWindowFocusChangeForClose(false);
        }
    };
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setCanceledOnTouchOutside(true);
    mDialog.addContentView(view,
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                          LinearLayout.LayoutParams.MATCH_PARENT));
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mItemSelectedCallback.onItemSelected("");
        }
    });

    Window window = mDialog.getWindow();
    if (!DeviceFormFactor.isTablet()) {
        // On smaller screens, make the dialog fill the width of the screen,
        // and appear at the top.
        window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        window.setGravity(Gravity.TOP);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                         ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    mDialog.show();
}