List of usage examples for android.view ViewConfiguration get
public static ViewConfiguration get(Context context)
From source file:com.artifex.mupdflib.TwoWayView.java
public TwoWayView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context;//from w ww . jav a2 s . c o m mLayoutMode = LAYOUT_NORMAL; mTouchMode = TOUCH_MODE_REST; mLastTouchMode = TOUCH_MODE_UNKNOWN; mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE; final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); mFlingVelocity = vc.getScaledMinimumFlingVelocity(); mOverscrollDistance = getScaledOverscrollDistance(vc); mScroller = new Scroller(context); mIsVertical = true; mTempRect = new Rect(); mArrowScrollFocusResult = new ArrowScrollFocusResult(); mSelectorPosition = INVALID_POSITION; mSelectorRect = new Rect(); mResurrectToPosition = INVALID_POSITION; mNextSelectedPosition = INVALID_POSITION; mNextSelectedRowId = INVALID_ROW_ID; mSelectedPosition = INVALID_POSITION; mSelectedRowId = INVALID_ROW_ID; mOldSelectedPosition = INVALID_POSITION; mOldSelectedRowId = INVALID_ROW_ID; mChoiceMode = ChoiceMode.NONE; mRecycler = new RecycleBin(); mAreAllItemsSelectable = true; setClickable(true); setFocusableInTouchMode(true); setWillNotDraw(false); setAlwaysDrawnWithCacheEnabled(false); setWillNotDraw(false); setClipToPadding(false); ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwoWayView, defStyle, 0); mDrawSelectorOnTop = a.getBoolean(R.styleable.TwoWayView_android_drawSelectorOnTop, false); Drawable d = a.getDrawable(R.styleable.TwoWayView_android_listSelector); if (d != null) { setSelector(d); } int orientation = a.getInt(R.styleable.TwoWayView_android_orientation, -1); if (orientation >= 0) { setOrientation(Orientation.values()[orientation]); } int choiceMode = a.getInt(R.styleable.TwoWayView_android_choiceMode, -1); if (choiceMode >= 0) { setChoiceMode(ChoiceMode.values()[choiceMode]); } a.recycle(); }
From source file:com.hippo.refreshlayout.RefreshLayout.java
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * * @param context/*from w ww .j a va 2 s . com*/ * @param attrs */ public RefreshLayout(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); mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mCircleDiameter = (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 mHeaderSpinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density); mHeaderTotalDragDistance = mHeaderSpinnerOffsetEnd; mNestedScrollingParentHelper = new NestedScrollingParentHelper(this); mNestedScrollingChildHelper = new NestedScrollingChildHelper(this); setNestedScrollingEnabled(true); mHeaderOriginalOffsetTop = mHeaderCurrentTargetOffsetTop = -mCircleDiameter; moveToStart(1.0f); final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS); setEnabled(a.getBoolean(0, true)); a.recycle(); mProgressBar = new SwipeProgressBar(this); mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT); }
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
public StaggeredGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); mFlingVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = new OverScrollerSGV(context); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); setWillNotDraw(false);/* ww w . j a v a2 s . c om*/ setClipToPadding(false); SgvAnimationHelper.initialize(context); mDragState = ReorderUtils.DRAG_STATE_NONE; mIsDragReorderingEnabled = true; mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final ViewConfiguration configuration = ViewConfiguration.get(context); mOverscrollDistance = configuration.getScaledOverflingDistance(); // Disable splitting event. Only one of the children can handle motion event. setMotionEventSplittingEnabled(false); }
From source file:com.example.sky.test.view.ViewPager.java
void initViewPager() { setWillNotDraw(false);//w w w . ja v a 2 s .c o m setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = configuration.getScaledPagingTouchSlop(); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new ViewPager.MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { private final Rect mTempRect = new Rect(); @Override public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) { // First let the ViewPager itself try and consume them... final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets); if (applied.isConsumed()) { // If the ViewPager consumed all insets, return now return applied; } // Now we'll manually dispatch the insets to our children. Since ViewPager // children are always full-height, we do not want to use the standard // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them, // the rest of the children will not receive any insets. To workaround this // we manually dispatch the applied insets, not allowing children to // consume them from each other. We do however keep track of any insets // which are consumed, returning the union of our children's consumption final Rect res = mTempRect; res.left = applied.getSystemWindowInsetLeft(); res.top = applied.getSystemWindowInsetTop(); res.right = applied.getSystemWindowInsetRight(); res.bottom = applied.getSystemWindowInsetBottom(); for (int i = 0, count = getChildCount(); i < count; i++) { final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied); // Now keep track of any consumed by tracking each dimension's min // value res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left); res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top); res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right); res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom); } // Now return a new WindowInsets, using the consumed window insets return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom); } }); }
From source file:at.jclehner.rxdroid.DrugListActivity.java
@Override public View makeView(int offset) { if (offset <= -(InfiniteViewPagerAdapter.MAX / 2)) { if (LOGV) Log.d(TAG, "makeView: returning stub for offset=" + offset); return new ViewStub(this); }/*from ww w .j ava 2s .c om*/ final View v = getLayoutInflater().inflate(R.layout.drug_list_fragment, null); final AutoDragSortListView listView = (AutoDragSortListView) v.findViewById(android.R.id.list); final TextView emptyView = (TextView) v.findViewById(android.R.id.empty); final Date date = DateTime.add(mOriginalDate, Calendar.DAY_OF_MONTH, offset); if (LOGV) Log.d(TAG, "makeView: date=" + DateTime.toDateString(date)); final List<Drug> drugs = Entries.getAllDrugs(mCurrentPatientId); Collections.sort(drugs, new DrugComparator()); updateListAdapter(listView, date, drugs); final String text; if (drugs.isEmpty()) { if (Settings.getBoolean(Keys.COMPACT_ACTION_BAR, Defaults.COMPACT_ACTION_BAR)) { Log.d(TAG, "COMPACT_ACTION_BAR"); final boolean hasHardwareMenuKey; if (Version.SDK_IS_PRE_HONEYCOMB) hasHardwareMenuKey = true; else { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // For Honeycomb, there appears to be no way to find out. As it // targets tablets only, we will assume that none of these have a // hardware menu key... hasHardwareMenuKey = false; } else hasHardwareMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); } final StringBuilder sb = new StringBuilder( getString(R.string._msg_no_drugs_compact_ab, getString(R.string._title_add))); if (hasHardwareMenuKey) sb.append(" " + getString(R.string._help_msg_menu_hardware)); else sb.append(" " + getString(R.string._help_msg_menu_ab_overflow)); text = sb.toString(); } else { Log.d(TAG, "EXTENDED_ACTION_BAR"); text = getString(R.string._msg_no_drugs_extended_ab, getString(R.string._title_add)); } } else text = getString(R.string._msg_no_doses_on_this_day, getString(R.string._title_add)); emptyView.setText(text); listView.setEmptyView(emptyView); listView.setDragHandleId(R.id.drug_icon); return v; }
From source file:android.support.v7.widget.helper.ItemTouchHelper.java
private void setupCallbacks() { ViewConfiguration vc = ViewConfiguration.get(mRecyclerView.getContext()); mSlop = vc.getScaledTouchSlop();/*from w w w . java2 s . com*/ mRecyclerView.addItemDecoration(this); mRecyclerView.addOnItemTouchListener(mOnItemTouchListener); mRecyclerView.addOnChildAttachStateChangeListener(this); initGestureDetector(); }
From source file:android.support.v7.widget.RecyclerViewEx.java
public RecyclerViewEx(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); 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();//from w w w . j a v a 2 s . c o m 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 RecyclerViewAccessibilityDelegateEx(this)); }
From source file:com.android.mylauncher3.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);//from ww w . ja v a 2s. c om 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.startSearchFromAllApps(v, mMarketSearchIntent, mLastSearchQuery); } }); return new ViewHolder(searchMarketView); default: throw new RuntimeException("Unexpected view type"); } }
From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java
@Override public void onCreate(Bundle state) { super.onCreate(state); // Disable IME for this application getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); setContentView(R.layout.main);/*from w w w. ja v a 2 s . co m*/ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Prepare the interstitial Ad mInterstitialAd = new InterstitialAd(getApplicationContext()); // Insert the Ad Unit ID mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ads)); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); // Load requested Ad mInterstitialAd.loadAd(adRequest); mPager = findViewById(R.id.panelswitch); mSmallPager = findViewById(R.id.smallPanelswitch); mLargePager = findViewById(R.id.largePanelswitch); isTelevision = Utils.isTelevision(this); mDrawerList = findViewById(R.id.navList); mDrawerLayout = findViewById(R.id.drawer_layout); addDrawerItems(); setupDrawer(); if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); } if (mClearButton == null) { mClearButton = findViewById(R.id.clear); mClearButton.setOnClickListener(mListener); mClearButton.setOnLongClickListener(mListener); } if (mBackspaceButton == null) { mBackspaceButton = findViewById(R.id.del); mBackspaceButton.setOnClickListener(mListener); mBackspaceButton.setOnLongClickListener(mListener); } mPersist = new Persist(this); mPersist.load(); mHistory = mPersist.history; mDisplay = findViewById(R.id.display); mLogic = new Logic(this, mHistory, mDisplay); mLogic.setListener(this); if (mPersist.getMode() != null) mLogic.mBaseModule.setMode(mPersist.getMode()); mLogic.setDeleteMode(mPersist.getDeleteMode()); mLogic.setLineLength(mDisplay.getMaxDigits()); mHistoryAdapter = new HistoryAdapter(this, mHistory); mHistory.setObserver(mHistoryAdapter); mPulldown = findViewById(R.id.pulldown); mPulldown.setBarHeight(getResources().getDimensionPixelSize(R.dimen.history_bar_height)); mPulldown.setSlideDirection(Direction.DOWN); if (CalculatorSettings.clickToOpenHistory(this)) { mPulldown.enableClick(true); mPulldown.enableTouch(false); } mPulldown.setBackgroundResource(R.color.mainbackground); mHistoryView = mPulldown.findViewById(R.id.history); setUpHistory(); mGraph = new Graph(mLogic); if (mPager != null) { mPager.setAdapter(new PageAdapter(mPager, mListener, mGraph, mLogic)); mPager.setCurrentItem(state == null ? Panel.BASIC.getOrder() : state.getInt(STATE_CURRENT_VIEW, Panel.BASIC.getOrder())); mPager.addOnPageChangeListener(this); runCling(false); mListener.setHandler(this, mLogic, mPager); } else if (mSmallPager != null && mLargePager != null) { // Expanded UI mSmallPager.setAdapter(new SmallPageAdapter(mSmallPager, mLogic)); mLargePager.setAdapter(new LargePageAdapter(mLargePager, mGraph, mLogic)); mSmallPager.setCurrentItem(state == null ? SmallPanel.ADVANCED.getOrder() : state.getInt(STATE_CURRENT_VIEW_SMALL, SmallPanel.ADVANCED.getOrder())); mLargePager.setCurrentItem(state == null ? LargePanel.BASIC.getOrder() : state.getInt(STATE_CURRENT_VIEW_LARGE, LargePanel.BASIC.getOrder())); mSmallPager.addOnPageChangeListener(this); mLargePager.addOnPageChangeListener(this); runCling(false); mListener.setHandler(this, mLogic, mSmallPager, mLargePager); } mDisplay.setOnKeyListener(mListener); if (!ViewConfiguration.get(this).hasPermanentMenuKey()) { createFakeMenu(); } mLogic.resumeWithHistory(); updateDeleteMode(); mPulldown.bringToFront(); }
From source file:com.example.android.wifidirect.WiFiDirectActivity.java
private void setOverflowShowingAlways() { try {//from ww w.j a v a 2s .co m ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } catch (Exception e) { e.printStackTrace(); } }