org.chromium.ui.UiUtils Java Examples

The following examples show how to use org.chromium.ui.UiUtils. 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: ActivityWindowAndroid.java    From 365browser with Apache License 2.0 7 votes vote down vote up
@Override
protected void registerKeyboardVisibilityCallbacks() {
    Activity activity = getActivity().get();
    if (activity == null) return;
    View content = activity.findViewById(android.R.id.content);
    mIsKeyboardShowing = UiUtils.isKeyboardShowing(getActivity().get(), content);
    content.addOnLayoutChangeListener(this);
}
 
Example #2
Source File: FindToolbar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void showKeyboard() {
    if (!mFindQuery.hasWindowFocus()) {
        // HACK: showKeyboard() is normally called from activate() which is
        // triggered by an options menu item. Unfortunately, because the
        // options menu is still focused at this point, that means our
        // window doesn't actually have focus when this first gets called,
        // and hence it isn't the target of the Input Method, and in
        // practice that means the soft keyboard never shows up (whatever
        // flags you pass). So as a workaround we postpone asking for the
        // keyboard to be shown until just after the window gets refocused.
        // See onWindowFocusChanged(boolean hasFocus).
        mShowKeyboardOnceWindowIsFocused = true;
        return;
    }
    UiUtils.showKeyboard(mFindQuery);
}
 
Example #3
Source File: UrlBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
    super.onWindowFocusChanged(hasWindowFocus);
    if (hasWindowFocus) {
        if (mShowKeyboardOnWindowFocus && isFocused()) {
            // Without the call to post(..), the keyboard was not getting shown when the
            // window regained focus despite this being the final call in the view system
            // flow.
            post(new Runnable() {
                @Override
                public void run() {
                    UiUtils.showKeyboard(UrlBar.this);
                }
            });
        }
        mShowKeyboardOnWindowFocus = false;
    }
}
 
Example #4
Source File: EmptyBackgroundViewTablet.java    From delion with Apache License 2.0 6 votes vote down vote up
public void setEmptyContainerState(boolean shouldShow) {
    Animator nextAnimator = null;

    if (shouldShow && getVisibility() != View.VISIBLE
            && mCurrentTransitionAnimation != mAnimateInAnimation) {
        nextAnimator = mAnimateInAnimation;
        UiUtils.hideKeyboard(this);
    } else if (!shouldShow && getVisibility() != View.GONE
            && mCurrentTransitionAnimation != mAnimateOutAnimation) {
        nextAnimator = mAnimateOutAnimation;
    }

    if (nextAnimator != null) {
        if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
        mCurrentTransitionAnimation = nextAnimator;
        mCurrentTransitionAnimation.start();
    }
}
 
Example #5
Source File: ScreenshotTask.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares a given screenshot for sending with a feedback.
 * If no screenshot is given it creates one from the activity View if an activity is provided.
 * @param activity An activity or null
 * @param bitmap A screenshot or null
 * @return A feedback-ready screenshot or null
 */
private static Bitmap prepareScreenshot(@Nullable Activity activity, @Nullable Bitmap bitmap) {
    if (bitmap == null) {
        if (activity == null) return null;
        return UiUtils.generateScaledScreenshot(
                activity.getWindow().getDecorView().getRootView(),
                MAX_FEEDBACK_SCREENSHOT_DIMENSION, Bitmap.Config.ARGB_8888);
    }

    int screenshotMaxDimension = Math.max(bitmap.getWidth(), bitmap.getHeight());
    if (screenshotMaxDimension <= MAX_FEEDBACK_SCREENSHOT_DIMENSION) return bitmap;

    float screenshotScale = (float) MAX_FEEDBACK_SCREENSHOT_DIMENSION / screenshotMaxDimension;
    int destWidth = (int) (bitmap.getWidth() * screenshotScale);
    int destHeight = (int) (bitmap.getHeight() * screenshotScale);
    return Bitmap.createScaledBitmap(bitmap, destWidth, destHeight, true);
}
 
Example #6
Source File: FindToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
private void showKeyboard() {
    if (!mFindQuery.hasWindowFocus()) {
        // HACK: showKeyboard() is normally called from activate() which is
        // triggered by an options menu item. Unfortunately, because the
        // options menu is still focused at this point, that means our
        // window doesn't actually have focus when this first gets called,
        // and hence it isn't the target of the Input Method, and in
        // practice that means the soft keyboard never shows up (whatever
        // flags you pass). So as a workaround we postpone asking for the
        // keyboard to be shown until just after the window gets refocused.
        // See onWindowFocusChanged(boolean hasFocus).
        mShowKeyboardOnceWindowIsFocused = true;
        return;
    }
    UiUtils.showKeyboard(mFindQuery);
}
 
Example #7
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example #8
Source File: InfoBarContainer.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Hide the View when the keyboard is showing.
    boolean isShowing = (getVisibility() == View.VISIBLE);
    if (UiUtils.isKeyboardShowing(getContext(), InfoBarContainer.this)) {
        if (isShowing) {
            // Set to invisible (instead of gone) so that onLayout() will be called when the
            // keyboard is dismissed.
            setVisibility(View.INVISIBLE);
        }
    } else {
        if (!isShowing && !mIsObscured) {
            setVisibility(View.VISIBLE);
        }
    }

    super.onLayout(changed, l, t, r, b);
}
 
Example #9
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example #10
Source File: ShareHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Clears all shared image files.
 */
public static void clearSharedImages() {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                File imagePath = UiUtils.getDirectoryForImageCapture(
                        ContextUtils.getApplicationContext());
                deleteShareImageFiles(new File(imagePath, SHARE_IMAGES_DIRECTORY_NAME));
            } catch (IOException ie) {
                // Ignore exception.
            }
            return null;
        }
    }.execute();
}
 
Example #11
Source File: UrlBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
    super.onWindowFocusChanged(hasWindowFocus);
    if (hasWindowFocus) {
        if (mShowKeyboardOnWindowFocus && isFocused()) {
            // Without the call to post(..), the keyboard was not getting shown when the
            // window regained focus despite this being the final call in the view system
            // flow.
            post(new Runnable() {
                @Override
                public void run() {
                    UiUtils.showKeyboard(UrlBar.this);
                }
            });
        }
        mShowKeyboardOnWindowFocus = false;
    }
}
 
Example #12
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void revertChanges() {
    if (!mUrlHasFocus) {
        setUrlToPageUrl();
    } else {
        Tab tab = mToolbarDataProvider.getTab();
        if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito())) {
            setUrlBarText("", null);
        } else {
            setUrlBarText(
                    mToolbarDataProvider.getText(), getCurrentTabUrl());
            selectAll();
        }
        hideSuggestions();
        UiUtils.hideKeyboard(mUrlBar);
    }
}
 
Example #13
Source File: ContextualSearchTranslateController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to {@link #getProficientLanguageList} except the the result is provided in
 * a {@link LinkedHashSet} to provide access to a unique ordered list.
 * @return a {@link LinkedHashSet} of languages the user is proficient using.
 */
private LinkedHashSet<String> getProficientLanguages() {
    LinkedHashSet<String> uniqueLanguages = new LinkedHashSet<String>();
    // The primary language, according to the translation-service, always comes first.
    String primaryLanguage = getNativeTranslateServiceTargetLanguage();
    if (isValidLocale(primaryLanguage)) {
        uniqueLanguages.add(trimLocaleToLanguage(primaryLanguage));
    }
    // Merge in the IME locales, if possible.
    if (!ContextualSearchFieldTrial.isKeyboardLanguagesForTranslationDisabled()) {
        Context context = mActivity.getApplicationContext();
        if (context != null) {
            for (String locale : UiUtils.getIMELocales(context)) {
                if (isValidLocale(locale)) uniqueLanguages.add(trimLocaleToLanguage(locale));
            }
        }
    }
    return uniqueLanguages;
}
 
Example #14
Source File: TabContentViewParent.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onContentChanged(Tab tab) {
    // If the tab is frozen, both native page and content view are not ready.
    if (tab.isFrozen()) return;

    View viewToShow = getViewToShow(tab);
    if (isShowing(viewToShow)) return;

    removeCurrentContent();
    LayoutParams lp = (LayoutParams) viewToShow.getLayoutParams();
    if (lp == null) {
        lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
    // Weirdly enough, if gravity is not top, top_margin is not respected by FrameLayout.
    // Yet for many native pages on tablet, top_margin is necessary to not overlap the tab
    // switcher.
    lp.gravity = Gravity.TOP;
    UiUtils.removeViewFromParent(viewToShow);
    addView(viewToShow, CONTENT_INDEX, lp);
    viewToShow.requestFocus();
}
 
Example #15
Source File: InfoBarContainer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Hide the View when the keyboard is showing.
    boolean isShowing = (getVisibility() == View.VISIBLE);
    if (UiUtils.isKeyboardShowing(getContext(), InfoBarContainer.this)) {
        if (isShowing) {
            // Set to invisible (instead of gone) so that onLayout() will be called when the
            // keyboard is dismissed.
            setVisibility(View.INVISIBLE);
        }
    } else {
        if (!isShowing && !mIsObscured) {
            setVisibility(View.VISIBLE);
        }
    }

    super.onLayout(changed, l, t, r, b);
}
 
Example #16
Source File: EmptyBackgroundViewTablet.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public void setEmptyContainerState(boolean shouldShow) {
    Animator nextAnimator = null;

    if (shouldShow && getVisibility() != View.VISIBLE
            && mCurrentTransitionAnimation != mAnimateInAnimation) {
        nextAnimator = mAnimateInAnimation;
        UiUtils.hideKeyboard(this);
    } else if (!shouldShow && getVisibility() != View.GONE
            && mCurrentTransitionAnimation != mAnimateOutAnimation) {
        nextAnimator = mAnimateOutAnimation;
    }

    if (nextAnimator != null) {
        if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
        mCurrentTransitionAnimation = nextAnimator;
        mCurrentTransitionAnimation.start();
    }
}
 
Example #17
Source File: BookmarkSearchView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
    super.onVisibilityChanged(changedView, visibility);
    // This method might be called very early. Null check on bookmark model here.
    if (mBookmarkModel == null) return;

    if (visibility == View.VISIBLE) {
        mBookmarkModel.addObserver(mModelObserver);
        updateHistoryList();
        mSearchText.requestFocus();
        UiUtils.showKeyboard(mSearchText);
    } else {
        UiUtils.hideKeyboard(mSearchText);
        mBookmarkModel.removeObserver(mModelObserver);
        resetUI();
        clearFocus();
    }
}
 
Example #18
Source File: SearchActivityLocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void focusTextBox() {
    if (mNativeInitialized) onUrlFocusChange(true);

    mUrlBar.setIgnoreTextChangesForAutocomplete(true);
    mUrlBar.setUrl("", null);
    mUrlBar.setIgnoreTextChangesForAutocomplete(false);

    mUrlBar.setCursorVisible(true);
    mUrlBar.setSelection(0, mUrlBar.getText().length());
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            UiUtils.showKeyboard(mUrlBar);
        }
    });
}
 
Example #19
Source File: ScreenshotTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares a given screenshot for sending with a feedback.
 * If no screenshot is given it creates one from the activity View if an activity is provided.
 * @param activity An activity or null
 * @param bitmap A screenshot or null
 * @return A feedback-ready screenshot or null
 */
private static Bitmap prepareScreenshot(@Nullable Activity activity, @Nullable Bitmap bitmap) {
    if (bitmap == null) {
        if (activity == null) return null;
        return UiUtils.generateScaledScreenshot(
                activity.getWindow().getDecorView().getRootView(),
                MAX_FEEDBACK_SCREENSHOT_DIMENSION, Bitmap.Config.ARGB_8888);
    }

    int screenshotMaxDimension = Math.max(bitmap.getWidth(), bitmap.getHeight());
    if (screenshotMaxDimension <= MAX_FEEDBACK_SCREENSHOT_DIMENSION) return bitmap;

    float screenshotScale = (float) MAX_FEEDBACK_SCREENSHOT_DIMENSION / screenshotMaxDimension;
    int destWidth = (int) (bitmap.getWidth() * screenshotScale);
    int destHeight = (int) (bitmap.getHeight() * screenshotScale);
    return Bitmap.createScaledBitmap(bitmap, destWidth, destHeight, true);
}
 
Example #20
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example #21
Source File: ShareHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Clears all shared image files.
 */
public static void clearSharedImages() {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                File imagePath = UiUtils.getDirectoryForImageCapture(
                        ContextUtils.getApplicationContext());
                deleteShareImageFiles(new File(imagePath, SHARE_IMAGES_DIRECTORY_NAME));
            } catch (IOException ie) {
                // Ignore exception.
            }
            return null;
        }
    }.execute();
}
 
Example #22
Source File: VrShellImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown() {
    if (mNativeVrShell != 0) {
        nativeDestroy(mNativeVrShell);
        mNativeVrShell = 0;
    }
    if (mNativePage != null) UiUtils.removeViewFromParent(mNativePage.getView());
    mTabModelSelector.removeObserver(mTabModelSelectorObserver);
    mTabModelSelectorTabObserver.destroy();
    mTab.removeObserver(mTabObserver);
    restoreTabFromVR();

    if (mTab != null) {
        mTab.updateBrowserControlsState(BrowserControlsState.SHOWN, true);
    }

    mContentVirtualDisplay.destroy();
    super.shutdown();
}
 
Example #23
Source File: UrlBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
    super.onWindowFocusChanged(hasWindowFocus);
    if (DEBUG) Log.i(TAG, "onWindowFocusChanged: " + hasWindowFocus);
    if (hasWindowFocus) {
        if (isFocused()) {
            // Without the call to post(..), the keyboard was not getting shown when the
            // window regained focus despite this being the final call in the view system
            // flow.
            post(new Runnable() {
                @Override
                public void run() {
                    UiUtils.showKeyboard(UrlBar.this);
                }
            });
        }
    }
}
 
Example #24
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void revertChanges() {
    if (!mUrlHasFocus) {
        setUrlToPageUrl();
    } else {
        Tab tab = mToolbarDataProvider.getTab();
        if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito())) {
            setUrlBarText("", null);
        } else {
            setUrlBarText(
                    mToolbarDataProvider.getText(), getCurrentTabUrl());
            selectAll();
        }
        hideSuggestions();
        UiUtils.hideKeyboard(mUrlBar);
    }
}
 
Example #25
Source File: ContextualSearchTranslateController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to {@link #getProficientLanguageList} except the the result is provided in
 * a {@link LinkedHashSet} to provide access to a unique ordered list.
 * @return a {@link LinkedHashSet} of languages the user is proficient using.
 */
private LinkedHashSet<String> getProficientLanguages() {
    LinkedHashSet<String> uniqueLanguages = new LinkedHashSet<String>();
    // The primary language, according to the translation-service, always comes first.
    String primaryLanguage = getNativeTranslateServiceTargetLanguage();
    if (isValidLocale(primaryLanguage)) {
        uniqueLanguages.add(trimLocaleToLanguage(primaryLanguage));
    }
    // Merge in the IME locales, if possible.
    Context context = mActivity.getApplicationContext();
    if (context != null) {
        for (String locale : UiUtils.getIMELocales(context)) {
            if (isValidLocale(locale)) uniqueLanguages.add(trimLocaleToLanguage(locale));
        }
    }
    return uniqueLanguages;
}
 
Example #26
Source File: InfoBarContainer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Hide the View when the keyboard is showing.
    boolean isShowing = (getVisibility() == View.VISIBLE);
    if (UiUtils.isKeyboardShowing(getContext(), InfoBarContainer.this)) {
        if (isShowing) {
            // Set to invisible (instead of gone) so that onLayout() will be called when the
            // keyboard is dismissed.
            setVisibility(View.INVISIBLE);
        }
    } else {
        if (!isShowing && !mIsObscured) {
            setVisibility(View.VISIBLE);
        }
    }

    super.onLayout(changed, l, t, r, b);
}
 
Example #27
Source File: SelectableListToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
protected void showSelectionView(List<E> selectedItems, boolean wasSelectionEnabled) {
    getMenu().setGroupVisible(mNormalGroupResId, false);
    getMenu().setGroupVisible(mSelectedGroupResId, true);
    if (mHasSearchView) mSearchView.setVisibility(View.GONE);

    setNavigationButton(NAVIGATION_BUTTON_SELECTION_BACK);
    setBackgroundColor(mSelectionBackgroundColor);
    setOverflowIcon(mSelectionMenuButton);

    switchToNumberRollView(selectedItems, wasSelectionEnabled);

    if (mIsSearching) UiUtils.hideKeyboard(mSearchEditText);

    onThemeChanged(false);
    updateDisplayStyleIfNecessary();
}
 
Example #28
Source File: EmptyBackgroundViewTablet.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void setEmptyContainerState(boolean shouldShow) {
    Animator nextAnimator = null;

    if (shouldShow && getVisibility() != View.VISIBLE
            && mCurrentTransitionAnimation != mAnimateInAnimation) {
        nextAnimator = mAnimateInAnimation;
        UiUtils.hideKeyboard(this);
    } else if (!shouldShow && getVisibility() != View.GONE
            && mCurrentTransitionAnimation != mAnimateOutAnimation) {
        nextAnimator = mAnimateOutAnimation;
    }

    if (nextAnimator != null) {
        if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
        mCurrentTransitionAnimation = nextAnimator;
        mCurrentTransitionAnimation.start();
    }
}
 
Example #29
Source File: FindToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void showKeyboard() {
    if (!mFindQuery.hasWindowFocus()) {
        // HACK: showKeyboard() is normally called from activate() which is
        // triggered by an options menu item. Unfortunately, because the
        // options menu is still focused at this point, that means our
        // window doesn't actually have focus when this first gets called,
        // and hence it isn't the target of the Input Method, and in
        // practice that means the soft keyboard never shows up (whatever
        // flags you pass). So as a workaround we postpone asking for the
        // keyboard to be shown until just after the window gets refocused.
        // See onWindowFocusChanged(boolean hasFocus).
        mShowKeyboardOnceWindowIsFocused = true;
        return;
    }
    UiUtils.showKeyboard(mFindQuery);
}
 
Example #30
Source File: SelectFileDialog.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Uri result) {
    mCameraOutputUri = result;
    if (mCameraOutputUri == null && captureCamera()) {
        onFileNotSelected();
        return;
    }

    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    camera.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        camera.setClipData(ClipData.newUri(
                mWindowAndroid.getApplicationContext().getContentResolver(),
                UiUtils.IMAGE_FILE_PATH, mCameraOutputUri));
    }
    if (mDirectToCamera) {
        mWindow.showIntent(camera, mCallback, R.string.low_memory_error);
    } else {
        launchSelectFileWithCameraIntent(true, camera);
    }
}