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:com.android.launcher3.BubbleTextView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    if (mBackground != null)
        mBackground.setCallback(this);

    if (mIcon instanceof PreloadIconDrawable) {
        ((PreloadIconDrawable) mIcon).applyPreloaderTheme(getPreloaderTheme());
    }//  w  w w. j a v a 2 s  . c  o  m
    mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}

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

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Intent intent = getIntent();
    fixIntent(intent);/*from w ww.j  av a  2 s .  c  om*/

    setContentView(R.layout.dialtacts_activity);

    mContactListFilterController = ContactListFilterController.getInstance(this);
    mContactListFilterController.addListener(mContactListFilterListener);

    findViewById(R.id.dialtacts_frame).addOnLayoutChangeListener(mFirstLayoutListener);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
    mViewPager.setOnPageChangeListener(mPageChangeListener);
    mViewPager.setOffscreenPageLimit(2);

    // Do same width calculation as ActionBar does
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int minCellSize = getResources().getDimensionPixelSize(R.dimen.fake_menu_button_min_width);
    int cellCount = dm.widthPixels / minCellSize;
    int fakeMenuItemWidth = dm.widthPixels / cellCount;
    if (DEBUG)
        Log.d(TAG, "The size of fake menu buttons (in pixel): " + fakeMenuItemWidth);

    // Soft menu button should appear only when there's no hardware menu button.
    mMenuButton = findViewById(R.id.overflow_menu);
    if (mMenuButton != null) {
        mMenuButton.setMinimumWidth(fakeMenuItemWidth);
        if (ViewConfiguration.get(this).hasPermanentMenuKey()) {
            // This is required for dialpad button's layout, so must not use GONE here.
            mMenuButton.setVisibility(View.INVISIBLE);
        } else {
            mMenuButton.setOnClickListener(this);
        }
    }
    mSearchButton = findViewById(R.id.searchButton);
    if (mSearchButton != null) {
        mSearchButton.setMinimumWidth(fakeMenuItemWidth);
        mSearchButton.setOnClickListener(this);
    }

    // Setup the ActionBar tabs (the order matches the tab-index contants TAB_INDEX_*)
    setupDialer();
    setupCallLog();
    setupFavorites();
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowHomeEnabled(false);

    // Load the last manually loaded tab
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLastManuallySelectedFragment = mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB,
            PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT);
    if (mLastManuallySelectedFragment >= TAB_INDEX_COUNT) {
        // Stored value may have exceeded the number of current tabs. Reset it.
        mLastManuallySelectedFragment = PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT;
    }

    setCurrentTab(intent);

    if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) && icicle == null) {
        setupFilterText(intent);
    }
}

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
    case SECTION_BREAK_VIEW_TYPE:
        return new ViewHolder(new View(parent.getContext()));
    case ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_icon, parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);/* w w w .  j  a  v  a  2 s. c o m*/
        return new ViewHolder(icon);
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_prediction_bar_icon,
                parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);
        return new ViewHolder(icon);
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search, parent, false));
    case SEARCH_MARKET_DIVIDER_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_search_market_divider, parent, false));
    case SEARCH_MARKET_VIEW_TYPE:
        View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market, parent, false);
        searchMarketView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
            }
        });
        return new ViewHolder(searchMarketView);
    default:
        throw new RuntimeException("Unexpected view type");
    }
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

public BottomSheet(Context context, boolean needFocus) {
    super(context, R.style.TransparentDialog);

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }//from   w  ww.ja v a2 s  .co  m
    ViewConfiguration vc = ViewConfiguration.get(context);
    touchSlop = vc.getScaledTouchSlop();

    Rect padding = new Rect();
    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);
    shadowDrawable.getPadding(padding);
    backgroundPaddingLeft = padding.left;
    backgroundPaddingTop = padding.top;

    container = new ContainerView(getContext());
    container.setBackgroundDrawable(backDrawable);
    focusable = needFocus;
    if (Build.VERSION.SDK_INT >= 21) {
        container.setFitsSystemWindows(true);
        container.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                lastInsets = insets;
                v.requestLayout();
                return insets.consumeSystemWindowInsets();
            }
        });
        container.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

    ciclePaint.setColor(0xffffffff);
    backDrawable.setAlpha(0);
}

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

private void prepareSearchView() {
    final View searchViewLayout = getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
    mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
    mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
    mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
    // Since we're using a custom layout for showing SearchView instead of letting the
    // search menu icon do that job, we need to manually configure the View so it looks
    // "shown via search menu".
    // - it should be iconified by default
    // - it should not be iconified at this time
    // See also comments for onActionViewExpanded()/onActionViewCollapsed()
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setQueryHint(getString(R.string.hint_findContacts));
    mSearchView.setIconified(false);/*from w  w w. j a v  a2 s  .com*/
    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showInputMethod(view.findFocus());
            }
        }
    });

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        // Filter option menu should be shown on the right side of SearchView.
        final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
        filterOptionView.setVisibility(View.VISIBLE);
        filterOptionView.setOnClickListener(mFilterOptionClickListener);
    }

    getActionBar().setCustomView(searchViewLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}

From source file:com.goftagram.telegram.messenger.support.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);/*from  w  w  w .j a  v a2  s. c o  m*/
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));

    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:android.support.v7.widget.RecyclerViewEx.java

/**
 * Configure the scrolling touch slop for a specific use case.
 *
 * Set up the RecyclerViewEx's scrolling motion threshold based on common usages.
 * Valid arguments are {@link #TOUCH_SLOP_DEFAULT} and {@link #TOUCH_SLOP_PAGING}.
 *
 * @param slopConstant One of the <code>TOUCH_SLOP_</code> constants representing
 *                     the intended usage of this RecyclerViewEx
 *///  ww  w .  ja  va2 s . com
public void setScrollingTouchSlop(int slopConstant) {
    final ViewConfiguration vc = ViewConfiguration.get(getContext());
    switch (slopConstant) {
    default:
        Log.w(TAG, "setScrollingTouchSlop(): bad argument constant " + slopConstant + "; using default value");
        // fall-through
    case TOUCH_SLOP_DEFAULT:
        mTouchSlop = vc.getScaledTouchSlop();
        break;

    case TOUCH_SLOP_PAGING:
        mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(vc);
        break;
    }
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

/**
 * Handles the touch events to dismiss all apps when clicking outside the bounds of the
 * recycler view./*from w w  w. j a  v  a  2 s.c o  m*/
 */
private boolean handleTouchEvent(MotionEvent ev) {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mContentBounds.isEmpty()) {
            // Outset the fixed bounds and check if the touch is outside all apps
            Rect tmpRect = new Rect(mContentBounds);
            tmpRect.inset(-grid.allAppsIconSizePx / 2, 0);
            if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        } else {
            // Check if the touch is outside all apps
            if (ev.getX() < getPaddingLeft() || ev.getX() > (getWidth() - getPaddingRight())) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mBoundsCheckLastTouchDownPos.x > -1) {
            ViewConfiguration viewConfig = ViewConfiguration.get(getContext());
            float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x;
            float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y;
            float distance = (float) Math.hypot(dx, dy);
            if (distance < viewConfig.getScaledTouchSlop()) {
                // The background was clicked, so just go home
                Launcher launcher = Launcher.getLauncher(getContext());
                launcher.showWorkspace(true);
                return true;
            }
        }
        // Fall through
    case MotionEvent.ACTION_CANCEL:
        mBoundsCheckLastTouchDownPos.set(-1, -1);
        break;
    }
    return false;
}

From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java

private void onTouchMove(MotionEvent ev) {
    if (isLayoutFrozen() || mTouchFromScrolling) {
        return;//from ww w.  j  a  va  2  s  .  c o  m
    }

    if (mTouchSlop == -1) {
        mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    }

    if (mMotionView != null && mMotionPosition >= 0
            && !MathUtils.near(mStartX, mStartY, ev.getX(), ev.getY(), mTouchSlop)) {
        removeTapCallback();
        if (mMotionView.isPressed()) {
            // Remove any future long press/tap checks
            removeLongPressCallback();
            mMotionView.setPressed(false);
            setPressed(false);
        }
        updateSelectorState();
        cancelDrawingSelector();
    }
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

/**
 * {@inheritDoc} from Fragment/*www.j a v a 2s .  c  om*/
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(android.R.id.list);
    final LinearLayoutManager manager = new LinearLayoutManager(getActivity());
    manager.setStackFromEnd(true);
    manager.setReverseLayout(false);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(manager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
        private final List<ViewHolder> mAddAnimations = new ArrayList<ViewHolder>();
        private PopupTransitionAnimation mPopupTransitionAnimation;

        @Override
        public boolean animateAdd(final ViewHolder holder) {
            final ConversationMessageView view = (ConversationMessageView) holder.itemView;
            final ConversationMessageData data = view.getData();
            endAnimation(holder);
            final long timeSinceSend = System.currentTimeMillis() - data.getReceivedTimeStamp();
            if (data.getReceivedTimeStamp() == InsertNewMessageAction.getLastSentMessageTimestamp()
                    && !data.getIsIncoming() && timeSinceSend < MESSAGE_ANIMATION_MAX_WAIT) {
                final ConversationMessageBubbleView messageBubble = (ConversationMessageBubbleView) view
                        .findViewById(R.id.message_content);
                final Rect startRect = UiUtils.getMeasuredBoundsOnScreen(mComposeMessageView);
                final View composeBubbleView = mComposeMessageView.findViewById(R.id.compose_message_text);
                final Rect composeBubbleRect = UiUtils.getMeasuredBoundsOnScreen(composeBubbleView);
                final AttachmentPreview attachmentView = (AttachmentPreview) mComposeMessageView
                        .findViewById(R.id.attachment_draft_view);
                final Rect attachmentRect = UiUtils.getMeasuredBoundsOnScreen(attachmentView);
                if (attachmentView.getVisibility() == View.VISIBLE) {
                    startRect.top = attachmentRect.top;
                } else {
                    startRect.top = composeBubbleRect.top;
                }
                startRect.top -= view.getPaddingTop();
                startRect.bottom = composeBubbleRect.bottom;
                startRect.left += view.getPaddingRight();

                view.setAlpha(0);
                mPopupTransitionAnimation = new PopupTransitionAnimation(startRect, view);
                mPopupTransitionAnimation.setOnStartCallback(new Runnable() {
                    @Override
                    public void run() {
                        final int startWidth = composeBubbleRect.width();
                        attachmentView.onMessageAnimationStart();
                        messageBubble.kickOffMorphAnimation(startWidth,
                                messageBubble.findViewById(R.id.message_text_and_info).getMeasuredWidth());
                    }
                });
                mPopupTransitionAnimation.setOnStopCallback(new Runnable() {
                    @Override
                    public void run() {
                        view.setAlpha(1);
                    }
                });
                mPopupTransitionAnimation.startAfterLayoutComplete();
                mAddAnimations.add(holder);
                return true;
            } else {
                return super.animateAdd(holder);
            }
        }

        @Override
        public void endAnimation(final ViewHolder holder) {
            if (mAddAnimations.remove(holder)) {
                holder.itemView.clearAnimation();
            }
            super.endAnimation(holder);
        }

        @Override
        public void endAnimations() {
            for (final ViewHolder holder : mAddAnimations) {
                holder.itemView.clearAnimation();
            }
            mAddAnimations.clear();
            if (mPopupTransitionAnimation != null) {
                mPopupTransitionAnimation.cancel();
            }
            super.endAnimations();
        }
    });
    mRecyclerView.setAdapter(mAdapter);

    if (savedInstanceState != null) {
        mListState = savedInstanceState.getParcelable(SAVED_INSTANCE_STATE_LIST_VIEW_STATE_KEY);
    }

    mConversationComposeDivider = view.findViewById(R.id.conversation_compose_divider);
    mScrollToDismissThreshold = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
    mRecyclerView.addOnScrollListener(mListScrollListener);
    mFastScroller = ConversationFastScroller.addTo(mRecyclerView,
            UiUtils.isRtlMode() ? ConversationFastScroller.POSITION_LEFT_SIDE
                    : ConversationFastScroller.POSITION_RIGHT_SIDE);

    mComposeMessageView = (ComposeMessageView) view.findViewById(R.id.message_compose_view_container);
    // Bind the compose message view to the DraftMessageData
    mComposeMessageView.bind(DataModel.get().createDraftMessageData(mBinding.getData().getConversationId()),
            this);

    return view;
}