Java Code Examples for org.chromium.ui.base.DeviceFormFactor

The following examples show how to use org.chromium.ui.base.DeviceFormFactor. These examples are extracted from open source projects. 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 Project: delion   Source File: BookmarkUtils.java    License: 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 2
Source Project: delion   Source File: StripLayoutHelper.java    License: 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 3
Source Project: delion   Source File: ChromeBrowserInitializer.java    License: 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 4
Source Project: delion   Source File: AsyncInitializationActivity.java    License: 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 5
Source Project: delion   Source File: ItemChooserDialog.java    License: 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 6
Source Project: 365browser   Source File: BookmarkUtils.java    License: 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 7
Source Project: delion   Source File: SuggestionView.java    License: 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 Project: delion   Source File: RecentTabsExpandableListView.java    License: 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 9
Source Project: 365browser   Source File: BookmarkUtils.java    License: 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 10
Source Project: AndroidChromium   Source File: InfoBarContainer.java    License: 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 11
Source Project: delion   Source File: CustomTabToolbar.java    License: 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 12
Source Project: delion   Source File: InfoBarContainer.java    License: 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 13
Source Project: 365browser   Source File: SnackbarView.java    License: 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 14
Source Project: AndroidChromium   Source File: BookmarkUtils.java    License: 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 15
Source Project: 365browser   Source File: ToolbarSceneLayer.java    License: 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 16
Source Project: AndroidChromium   Source File: StripLayoutHelper.java    License: 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 Project: 365browser   Source File: ChromeBrowserInitializer.java    License: 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 18
Source Project: AndroidChromium   Source File: ChromeBrowserInitializer.java    License: 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 19
Source Project: AndroidChromium   Source File: SuggestionView.java    License: 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 20
@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 21
Source Project: 365browser   Source File: HistoryManagerUtils.java    License: 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 22
Source Project: delion   Source File: WebsiteSettingsPopup.java    License: 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(mContext)) {
        task.run();
    } else {
        mContainer.postDelayed(task, FADE_DURATION + CLOSE_CLEANUP_DELAY);
    }
}
 
Example 23
Source Project: delion   Source File: BookmarkUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Shows bookmark main UI.
 */
public static void showBookmarkManager(Activity activity) {
    String url = getFirstUrlToLoad(activity);

    if (DeviceFormFactor.isTablet(activity)) {
        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 24
Source Project: 365browser   Source File: WebappUrlBar.java    License: Apache License 2.0 5 votes vote down vote up
private void updateSecurityIcon(int securityLevel) {
    boolean isSmallDevice = !DeviceFormFactor.isTablet();
    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 25
Source Project: 365browser   Source File: LocationBarLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void updateNavigationButton() {
    boolean isTablet = DeviceFormFactor.isTablet();
    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 26
Source Project: 365browser   Source File: CustomTabToolbar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void updateSecurityIcon(int securityLevel) {
    if (mState == STATE_TITLE_ONLY) return;

    mSecurityIconType = securityLevel;

    boolean isSmallDevice = !DeviceFormFactor.isTablet();
    boolean isOfflinePage =
            getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCurrentTab());

    int id = LocationBarLayout.getSecurityIconResource(
            securityLevel, isSmallDevice, isOfflinePage);
    boolean showSecurityButton = true;
    if (id == 0) {
        // Hide the button if we don't have an actual icon to display.
        showSecurityButton = false;
        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(), false /* omnibox is not opaque */));
    }

    mShowsOfflinePage = isOfflinePage;

    if (showSecurityButton) {
        mAnimDelegate.showSecurityButton();
    } else {
        mAnimDelegate.hideSecurityButton();
    }

    mUrlBar.emphasizeUrl();
    mUrlBar.invalidate();
}
 
Example 27
Source Project: delion   Source File: LayerTitleCache.java    License: 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();
    // If theme colors are enabled in the tab switcher, the theme might require lighter text.
    if (FeatureUtilities.areTabSwitcherThemeColorsEnabled()
            && !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 28
Source Project: AndroidChromium   Source File: ToolbarManager.java    License: Apache License 2.0 5 votes vote down vote up
private boolean shouldShowCusrsorInLocationBar() {
    Tab tab = mToolbarModel.getTab();
    if (tab == null) return false;
    NativePage nativePage = tab.getNativePage();
    if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
        return false;
    }

    Context context = mToolbar.getContext();
    return DeviceFormFactor.isTablet(context)
            && context.getResources().getConfiguration().keyboard
            == Configuration.KEYBOARD_QWERTY;
}
 
Example 29
Source Project: delion   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether Reader mode and its new UI are enabled.
 * @param context A context
 */
public static boolean isEnabled(Context context) {
    if (context == null) return false;

    boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
            && !CommandLine.getInstance().hasSwitch(
                    ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
            && !DeviceFormFactor.isTablet(context)
            && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
            && !SysUtils.isLowEndDevice();
    return enabled;
}
 
Example 30
Source Project: delion   Source File: DeviceClassManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The {@link DeviceClassManager} constructor should be self contained and
 * rely on system information and command line flags.
 */
private DeviceClassManager() {
    // Device based configurations.
    if (SysUtils.isLowEndDevice()) {
        mEnableSnapshots = false;
        mEnableLayerDecorationCache = true;
        mEnableAccessibilityLayout = true;
        mEnableAnimations = false;
        mEnablePrerendering = false;
        mEnableToolbarSwipe = false;
        mDisableDomainReliability = true;
    } else {
        mEnableSnapshots = true;
        mEnableLayerDecorationCache = true;
        mEnableAccessibilityLayout = false;
        mEnableAnimations = true;
        mEnablePrerendering = true;
        mEnableToolbarSwipe = true;
        mDisableDomainReliability = false;
    }

    if (DeviceFormFactor.isTablet(ContextUtils.getApplicationContext())) {
        mEnableAccessibilityLayout = false;
    }

    // Flag based configurations.
    CommandLine commandLine = CommandLine.getInstance();
    mEnableAccessibilityLayout |= commandLine
            .hasSwitch(ChromeSwitches.ENABLE_ACCESSIBILITY_TAB_SWITCHER);
    mEnableFullscreen =
            !commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN);
    mEnableToolbarSwipeInDocumentMode =
            commandLine.hasSwitch(ChromeSwitches.ENABLE_TOOLBAR_SWIPE_IN_DOCUMENT_MODE);

    // Related features.
    if (mEnableAccessibilityLayout) {
        mEnableAnimations = false;
    }
}