Example usage for android.view ViewConfiguration get

List of usage examples for android.view ViewConfiguration get

Introduction

In this page you can find the example usage for android.view ViewConfiguration get.

Prototype

public static ViewConfiguration get(Context context) 

Source Link

Document

Returns a configuration for the specified context.

Usage

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private void reopenMenu(MenuBuilder menu, boolean toggleMenuMode) {
    if (mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu()
            && (!ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(mContext))
                    || mDecorContentParent.isOverflowMenuShowPending())) {

        final Window.Callback cb = getWindowCallback();

        if (!mDecorContentParent.isOverflowMenuShowing() || !toggleMenuMode) {
            if (cb != null && !isDestroyed()) {
                // If we have a menu invalidation pending, do it now.
                if (mInvalidatePanelMenuPosted
                        && (mInvalidatePanelMenuFeatures & (1 << FEATURE_OPTIONS_PANEL)) != 0) {
                    mWindow.getDecorView().removeCallbacks(mInvalidatePanelMenuRunnable);
                    mInvalidatePanelMenuRunnable.run();
                }//  ww  w . java  2 s  . com

                final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true);

                // If we don't have a menu or we're waiting for a full content refresh,
                // forget it. This is a lingering event that no longer matters.
                if (st.menu != null && !st.refreshMenuContent
                        && cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) {
                    cb.onMenuOpened(FEATURE_SUPPORT_ACTION_BAR, st.menu);
                    mDecorContentParent.showOverflowMenu();
                }
            }
        } else {
            mDecorContentParent.hideOverflowMenu();
            if (!isDestroyed()) {
                final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true);
                cb.onPanelClosed(FEATURE_SUPPORT_ACTION_BAR, st.menu);
            }
        }
        return;
    }

    PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true);

    st.refreshDecorView = true;
    closePanel(st, false);

    openPanel(st, null);
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void onKeyUpPanel(int featureId, KeyEvent event) {
    if (mActionMode != null) {
        return;//from ww w  . ja va  2  s .  c  o  m
    }

    boolean playSoundEffect = false;
    final PanelFeatureState st = getPanelState(featureId, true);
    if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null
            && mDecorContentParent.canShowOverflowMenu()
            && !ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(mContext))) {
        if (!mDecorContentParent.isOverflowMenuShowing()) {
            if (!isDestroyed() && preparePanel(st, event)) {
                playSoundEffect = mDecorContentParent.showOverflowMenu();
            }
        } else {
            playSoundEffect = mDecorContentParent.hideOverflowMenu();
        }
    } else {
        if (st.isOpen || st.isHandled) {

            // Play the sound effect if the user closed an open menu (and not if
            // they just released a menu shortcut)
            playSoundEffect = st.isOpen;

            // Close menu
            closePanel(st, true);

        } else if (st.isPrepared) {
            boolean show = true;
            if (st.refreshMenuContent) {
                // Something may have invalidated the menu since we prepared it.
                // Re-prepare it to refresh.
                st.isPrepared = false;
                show = preparePanel(st, event);
            }

            if (show) {
                // Show menu
                openPanel(st, event);

                playSoundEffect = true;
            }
        }
    }

    if (playSoundEffect) {
        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager != null) {
            audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
        } else {
            Log.w(TAG, "Couldn't get audio manager");
        }
    }
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }/*from  w w  w  .j a v  a2s.  c o  m*/

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            obs.removeOnGlobalLayoutListener(this);
                        } else {
                            obs.removeGlobalOnLayoutListener(this);
                        }
                    }
                });
    }
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Update visibility of the search button and menu button at the bottom.
 * They should be invisible when bottom ActionBar's real items are available, and be visible
 * otherwise./*from ww w .j a  v a2 s.  c  om*/
 *
 * @param visible True when visible.
 */
private void updateFakeMenuButtonsVisibility(boolean visible) {
    // Note: Landscape mode does not have the fake menu and search buttons.
    if (DEBUG) {
        Log.d(TAG, "updateFakeMenuButtonVisibility(" + visible + ")");
    }

    if (mSearchButton != null) {
        if (visible) {
            mSearchButton.setVisibility(View.VISIBLE);
        } else {
            mSearchButton.setVisibility(View.INVISIBLE);
        }
    }
    if (mMenuButton != null) {
        if (visible && !ViewConfiguration.get(this).hasPermanentMenuKey()) {
            mMenuButton.setVisibility(View.VISIBLE);
        } else {
            mMenuButton.setVisibility(View.INVISIBLE);
        }
    }
}

From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }//from w ww  . j  a v a2  s  . c  o m

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset,
                                            bottomBar.isShy(), bottomBar.mIsTabletMode));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            obs.removeOnGlobalLayoutListener(this);
                        } else {
                            obs.removeGlobalOnLayoutListener(this);
                        }
                    }
                });
    }
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private boolean onKeyUpPanel(int featureId, KeyEvent event) {
    if (mActionMode != null) {
        return false;
    }//ww  w . j  a v  a2s .co  m

    boolean handled = false;
    final PanelFeatureState st = getPanelState(featureId, true);
    if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null
            && mDecorContentParent.canShowOverflowMenu()
            && !ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(mContext))) {
        if (!mDecorContentParent.isOverflowMenuShowing()) {
            if (!isDestroyed() && preparePanel(st, event)) {
                handled = mDecorContentParent.showOverflowMenu();
            }
        } else {
            handled = mDecorContentParent.hideOverflowMenu();
        }
    } else {
        if (st.isOpen || st.isHandled) {
            // Play the sound effect if the user closed an open menu (and not if
            // they just released a menu shortcut)
            handled = st.isOpen;
            // Close menu
            closePanel(st, true);
        } else if (st.isPrepared) {
            boolean show = true;
            if (st.refreshMenuContent) {
                // Something may have invalidated the menu since we prepared it.
                // Re-prepare it to refresh.
                st.isPrepared = false;
                show = preparePanel(st, event);
            }

            if (show) {
                // Show menu
                openPanel(st, event);
                handled = true;
            }
        }
    }

    if (handled) {
        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager != null) {
            audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
        } else {
            Log.w(TAG, "Couldn't get audio manager");
        }
    }
    return handled;
}

From source file:com.harry.refresh.SwipyRefreshLayout.java

/**
     * Constructor that is called when inflating SwipeRefreshLayout from XML.
     */* ww  w .j a  va  2s .c o  m*/
     * @param context
     * @param attrs
     */
    public SwipyRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

        mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

        setWillNotDraw(false);
        mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

        final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
        setEnabled(a.getBoolean(0, true));
        a.recycle();

        final TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.SwipyRefreshLayout);
        SwipeRefreshLayoutDirection direction = SwipeRefreshLayoutDirection
                .getFromInt(a2.getInt(R.styleable.SwipyRefreshLayout_direction, 0));
        if (direction != SwipeRefreshLayoutDirection.BOTH) {
            mDirection = direction;
            mBothDirection = false;
        } else {
            mDirection = SwipeRefreshLayoutDirection.TOP;
            mBothDirection = true;
        }
        a2.recycle();

        final DisplayMetrics metrics = getResources().getDisplayMetrics();
        mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
        mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

        createProgressView();
        ViewCompat.setChildrenDrawingOrderEnabled(this, true);
        // the absolute offset has to take into account that the circle starts at an offset
        mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    }

From source file:cc.flydev.launcher.Page.java

private PointF isFlingingToDelete() {
    ViewConfiguration config = ViewConfiguration.get(getContext());
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());

    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
        PointF upVec = new PointF(0f, -1f);
        float theta = (float) Math
                .acos(((vel.x * upVec.x) + (vel.y * upVec.y)) / (vel.length() * upVec.length()));
        if (theta <= Math.toRadians(FLING_TO_DELETE_MAX_FLING_DEGREES)) {
            return vel;
        }/*from w w  w.java 2  s.  c o  m*/
    }
    return null;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Returns true if the menu hardware menu is present on the device
 * /*from w ww. j  a v a  2  s. co m*/
 * This function requires API Level 14.
 * 
 * @param context
 * @return
 */
@SuppressLint("NewApi")
public static boolean device_isHardwareMenuButtonPresent(Context context) {
    if (device_getAPILevel() >= 14) {
        //This requires API Level 14
        return ViewConfiguration.get(context).hasPermanentMenuKey();
    } else {
        return false;
    }
}