android.view.ViewConfiguration Java Examples

The following examples show how to use android.view.ViewConfiguration. 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: SlidingLayer.java    From android-sliding-layer-lib with Apache License 2.0 6 votes vote down vote up
private void init() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            setLayerType(LAYER_TYPE_HARDWARE, null);
        }

        setWillNotDraw(false);
        setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
        setFocusable(true);

        final Context context = getContext();
        mScroller = new Scroller(context, sMenuInterpolator);

        final ViewConfiguration configuration = ViewConfiguration.get(context);
        mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
        mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

        final float density = context.getResources().getDisplayMetrics().density;
        mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);

        mRandom = new Random();
    }
 
Example #2
Source File: SystemBarTintManager.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@TargetApi(14)
private boolean hasNavBar(Context context) {
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}
 
Example #3
Source File: TrendRecyclerView.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initialize() {
    setWillNotDraw(false);

    this.paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStrokeCap(Paint.Cap.ROUND);

    this.textSize = (int) DisplayUtils.dpToPx(getContext(), TEXT_SIZE_DIP);
    this.textMargin = (int) DisplayUtils.dpToPx(getContext(), TEXT_MARGIN_DIP);
    this.lineWidth = (int) DisplayUtils.dpToPx(getContext(), LINE_WIDTH_DIP);

    setLineColor(Color.GRAY);

    this.keyLineList = new ArrayList<>();
    this.touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}
 
Example #4
Source File: ViewDragHelper.java    From UltimateSwipeTool with Apache License 2.0 6 votes vote down vote up
/**
 * Apps should use ViewDragHelper.create() to get a new instance. This will
 * allow VDH to use internal compatibility implementations for different
 * platform versions.
 *
 * @param context   Context to init config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}
 
Example #5
Source File: ViewPagerTabFragmentParentFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_viewpagertabfragment_parent, container, false);

    AppCompatActivity parentActivity = (AppCompatActivity) getActivity();
    mPagerAdapter = new NavigationAdapter(getChildFragmentManager());
    mPager = (ViewPager) view.findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);

    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setViewPager(mPager);

    ViewConfiguration vc = ViewConfiguration.get(parentActivity);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionFrameLayout) view.findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);

    return view;
}
 
Example #6
Source File: AttachmentView.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN: {
			if (System.currentTimeMillis() - lastClickTime <= ViewConfiguration.getDoubleTapTimeout()) {
				event.setAction(MotionEvent.ACTION_CANCEL);
				return false;
			}
			break;
		}
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL: {
			lastClickTime = System.currentTimeMillis();
			break;
		}
	}
	return super.onTouchEvent(event);
}
 
Example #7
Source File: SpanVariableGridView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void startLongPressCheck() {

        if (mLongPressRunnable == null) {
            mLongPressRunnable = new Runnable() {
                public void run() {

                    if (mTouchState == TOUCH_STATE_CLICK) {
                        final int index = pointToPosition(INVALID_POSITION, mTouchStartX, mTouchStartY);
                        if (index != INVALID_POSITION && index == mTouchStartItemPosition) {
                            longClickChild(index);
                            mTouchState = TOUCH_STATE_LONG_CLICK;
                        }
                    }
                }
            };
        }

        postDelayed(mLongPressRunnable, ViewConfiguration.getLongPressTimeout());
    }
 
Example #8
Source File: MyPagerIndicator.java    From AndroidTranslucentUI with Apache License 2.0 6 votes vote down vote up
/**
 * @param context
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public MyPagerIndicator(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);
	if(isInEditMode())
		return;
	final Resources rs = getResources();
	final int defaultSelectedColor = rs.getColor(R.color.selected_color);
	TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.viewPager_indicator, defStyle, 0);
	setSelectedColor(array.getColor(R.styleable.viewPager_indicator_selectedColor, defaultSelectedColor));
	
	//viewPager_indicator_android_background��viewPager_indicator�µ�android_background����
	Drawable background = array.getDrawable(R.styleable.viewPager_indicator_android_background);
       if (background != null) {
         setBackgroundDrawable(background);
       }

       array.recycle();
       final ViewConfiguration configuration = ViewConfiguration.get(context);
       mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example #9
Source File: SystemBarTintManager.java    From XanderPanel with Apache License 2.0 6 votes vote down vote up
@TargetApi(14)
private boolean hasNavBar(Context context) {
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}
 
Example #10
Source File: KeyButtonView.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
public void run() {
    if (isPressed()) {
        if (mCode != 0) {
            if (mCode == KeyEvent.KEYCODE_DPAD_LEFT || mCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_SOFT_KEYBOARD |
                        KeyEvent.FLAG_KEEP_TOUCH_MODE, System.currentTimeMillis(), false);
                sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_SOFT_KEYBOARD |
                        KeyEvent.FLAG_KEEP_TOUCH_MODE, System.currentTimeMillis(), false);
                removeCallbacks(mCheckLongPress);
                postDelayed(mCheckLongPress, ViewConfiguration.getKeyRepeatDelay());
            } else {
                sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
                sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
            }
        } else {
            mLongPressConsumed = performLongClick();
        }
    }
}
 
Example #11
Source File: SwipeMenuLayout.java    From SwipeRecyclerView-master with Apache License 2.0 6 votes vote down vote up
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.recycler_swipe_SwipeMenuLayout);
    mLeftViewId = typedArray.getResourceId(R.styleable.recycler_swipe_SwipeMenuLayout_leftViewId, mLeftViewId);
    mContentViewId = typedArray.getResourceId(R.styleable.recycler_swipe_SwipeMenuLayout_contentViewId, mContentViewId);
    mRightViewId = typedArray.getResourceId(R.styleable.recycler_swipe_SwipeMenuLayout_rightViewId, mRightViewId);
    typedArray.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mScaledTouchSlop = configuration.getScaledTouchSlop();
    mScaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mScaledMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();

    mScroller = new OverScroller(getContext());
}
 
Example #12
Source File: PhotoViewPager.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
public PhotoViewPager(Context context, Adapter adapter) {
	super(context);
	setWillNotDraw(false);
	float density = ResourceUtils.obtainDensity(context);
	flingDistance = (int) (24 * density);
	ViewConfiguration configuration = ViewConfiguration.get(context);
	minimumVelocity = (int) (MIN_FLING_VELOCITY * density);
	maximumVelocity = configuration.getScaledMaximumFlingVelocity();
	touchSlop = configuration.getScaledTouchSlop();
	scroller = new OverScroller(context);
	edgeEffect = new EdgeEffect(context);
	this.adapter = adapter;
	for (int i = 0; i < 3; i++) {
		View view = adapter.onCreateView(this);
		super.addView(view, -1, generateDefaultLayoutParams());
		photoViews.add(adapter.getPhotoView(view));
	}
}
 
Example #13
Source File: Slider.java    From material with Apache License 2.0 6 votes vote down vote up
protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    //default color
    mPrimaryColor = ThemeUtil.colorControlActivated(context, 0xFF000000);
    mSecondaryColor = ThemeUtil.colorControlNormal(context, 0xFF000000);

    mDrawRect = new RectF();
    mTempRect = new RectF();
    mLeftTrackPath = new Path();
    mRightTrackPath = new Path();

    mThumbRadiusAnimator = new ThumbRadiusAnimator();
    mThumbStrokeAnimator = new ThumbStrokeAnimator();
    mThumbMoveAnimator = new ThumbMoveAnimator();

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMemoPoint = new PointF();

    applyStyle(context, attrs, defStyleAttr, defStyleRes);

    if(!isInEditMode())
        mStyleId = ThemeManager.getStyleId(context, attrs, defStyleAttr, defStyleRes);
}
 
Example #14
Source File: LrcView.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化画笔等
 */
@Override
public void init(Context context) {
    mScroller = new Scroller(getContext());
    mPaintForHighLightLrc = new Paint();
    //        mCurColorForHightLightLrc
    mPaintForHighLightLrc.setColor(getResources().getColor(R.color.light_blue_500));
    mPaintForHighLightLrc.setTextSize(mCurSizeForHightLightLrc);
    mPaintForHighLightLrc.setAntiAlias(true);

    mPaintForOtherLrc = new Paint();
    mPaintForOtherLrc.setColor(Color.WHITE);
    mPaintForOtherLrc.setTextSize(mCurSizeForOtherLrc);
    mPaintForOtherLrc.setAntiAlias(true);

    mPaintForTimeLine = new Paint();
    mPaintForTimeLine.setColor(COLOR_FOR_TIME_LINE);
    mPaintForTimeLine.setTextSize(SIZE_FOR_TIME);

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

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inDensity = 30;
    options.inTargetDensity = 30;
    arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.raw.lrc_arrow, options);
}
 
Example #15
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private void initAbsListView() {
	setClickable(true);
	setFocusableInTouchMode(true);
	setWillNotDraw(false);
	setAlwaysDrawnWithCacheEnabled(false);
	setScrollingCacheEnabled(true);
	final ViewConfiguration configuration = ViewConfiguration
			.get(getContext());
	mTouchSlop = configuration.getScaledTouchSlop();
	mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
	mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
	mDensity = getResources().getDisplayMetrics().density;
}
 
Example #16
Source File: DragController.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Thunk void checkScrollState(int x, int y) {
    final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
    final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final int forwardDirection = mIsRtl ? SCROLL_RIGHT : SCROLL_LEFT;
    final int backwardsDirection = mIsRtl ? SCROLL_LEFT : SCROLL_RIGHT;

    if (x < mScrollZone) {
        if (mScrollState == SCROLL_OUTSIDE_ZONE) {
            mScrollState = SCROLL_WAITING_IN_ZONE;
            if (mDragScroller.onEnterScrollArea(x, y, forwardDirection)) {
                dragLayer.onEnterScrollArea(forwardDirection);
                mScrollRunnable.setDirection(forwardDirection);
                mHandler.postDelayed(mScrollRunnable, delay);
            }
        }
    } else if (x > mScrollView.getWidth() - mScrollZone) {
        if (mScrollState == SCROLL_OUTSIDE_ZONE) {
            mScrollState = SCROLL_WAITING_IN_ZONE;
            if (mDragScroller.onEnterScrollArea(x, y, backwardsDirection)) {
                dragLayer.onEnterScrollArea(backwardsDirection);
                mScrollRunnable.setDirection(backwardsDirection);
                mHandler.postDelayed(mScrollRunnable, delay);
            }
        }
    } else {
        clearScrollRunnable();
    }
}
 
Example #17
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    switch (mMode) {
        case MODE_PRESS: {
            switch (mManagedButton) {
                case BUTTON_INCREMENT: {
                    mIncrementVirtualButtonPressed = true;
                    invalidate(0, mBottomSelectionDividerBottom, getRight(), getBottom());
                } break;
                case BUTTON_DECREMENT: {
                    mDecrementVirtualButtonPressed = true;
                    invalidate(0, 0, getRight(), mTopSelectionDividerTop);
                }
            }
        } break;
        case MODE_TAPPED: {
            switch (mManagedButton) {
                case BUTTON_INCREMENT: {
                    if (!mIncrementVirtualButtonPressed) {
                        NumberPicker.this.postDelayed(this,
                                ViewConfiguration.getPressedStateDuration());
                    }
                    mIncrementVirtualButtonPressed ^= true;
                    invalidate(0, mBottomSelectionDividerBottom, getRight(), getBottom());
                } break;
                case BUTTON_DECREMENT: {
                    if (!mDecrementVirtualButtonPressed) {
                        NumberPicker.this.postDelayed(this,
                                ViewConfiguration.getPressedStateDuration());
                    }
                    mDecrementVirtualButtonPressed ^= true;
                    invalidate(0, 0, getRight(), mTopSelectionDividerTop);
                }
            }
        } break;
    }
}
 
Example #18
Source File: TDevice.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
public static boolean hasHardwareMenuKey(Context context)
{
	boolean flag = false;
	if (PRE_HC)
		flag = true;
	else if (GTE_ICS)
	{
		flag = ViewConfiguration.get(context).hasPermanentMenuKey();
	}
	else
		flag = false;
	return flag;
}
 
Example #19
Source File: SwitchButton.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initView() {
	mConf = Configuration.getDefault(getContext().getResources().getDisplayMetrics().density);
	mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
	mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
	mAnimationController = AnimationController.getDefault().init(mOnAnimateListener);
	mBounds = new Rect();
	if (SHOW_RECT) {
		mRectPaint = new Paint();
		mRectPaint.setStyle(Style.STROKE);
	}
}
 
Example #20
Source File: LinePageIndicator.java    From InfiniteViewPager with MIT License 5 votes vote down vote up
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
      setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example #21
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
private void initAbsListView() {
    setClickable(true);
    setFocusableInTouchMode(true);
    setWillNotDraw(false);
    setAlwaysDrawnWithCacheEnabled(false);
    setScrollingCacheEnabled(true);
    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    this.mTouchSlop = configuration.getScaledTouchSlop();
    this.mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    this.mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    this.mOverscrollDistance = configuration.getScaledOverscrollDistance() + 200;
    this.mOverflingDistance = configuration.getScaledOverflingDistance() + 100;
    this.mViewHelper = ViewHelperFactory.create(this);
}
 
Example #22
Source File: ImageViewTouchBase.java    From FlickableView with Apache License 2.0 5 votes vote down vote up
protected void init(Context context, AttributeSet attrs, int defStyle) {
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = configuration.getScaledMaximumFlingVelocity();
    mDefaultAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    setScaleType(ScaleType.MATRIX);
}
 
Example #23
Source File: SwipeDismissRecyclerViewTouchListener.java    From droidddle with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new swipe-to-dismiss touch listener for the given list view.
 *
 * @param recyclerView The list view whose items should be dismissable.
 * @param callbacks    The callback to trigger when the user has indicated that she would like to
 *                     dismiss one or more list items.
 */
public SwipeDismissRecyclerViewTouchListener(RecyclerView recyclerView, DismissCallbacks callbacks) {
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
    mRecyclerView = recyclerView;
    mCallbacks = callbacks;
}
 
Example #24
Source File: Utils.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 判断手机是否含有虚拟按键  99%
 */
public static boolean hasVirtualNavigationBar(Context context) {
    boolean hasSoftwareKeys = true;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).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;

        hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        hasSoftwareKeys = !hasMenuKey && !hasBackKey;
    }

    return hasSoftwareKeys;
}
 
Example #25
Source File: MoneySelectRuleView.java    From RulerView with Apache License 2.0 5 votes vote down vote up
public MoneySelectRuleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initAttrs(context, attrs);

    // 初始化final常量,必须在构造中赋初值
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    TOUCH_SLOP = viewConfiguration.getScaledTouchSlop();
    MIN_FLING_VELOCITY = viewConfiguration.getScaledMinimumFlingVelocity();
    MAX_FLING_VELOCITY = viewConfiguration.getScaledMaximumFlingVelocity();

    calculateValues();
    init(context);
}
 
Example #26
Source File: VerticalViewPager.java    From VerticalViewPager with MIT License 5 votes vote down vote up
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    
    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}
 
Example #27
Source File: PileLayout.java    From timecat with Apache License 2.0 5 votes vote down vote up
public PileLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.pile);
    interval = (int) a.getDimension(R.styleable.pile_interval, interval);
    sizeRatio = a.getFloat(R.styleable.pile_sizeRatio, sizeRatio);
    scaleStep = a.getFloat(R.styleable.pile_scaleStep, scaleStep);
    displayCount = a.getFloat(R.styleable.pile_displayCount, displayCount);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    onClickListener = v -> {
        if (null != adapter) {
            int position = Integer.parseInt(v.getTag().toString());
            if (position >= 0 && position < adapter.getItemCount()) {
                adapter.onItemClick(((FrameLayout) v).getChildAt(0), position);
            }
        }
    };

    getViewTreeObserver().addOnGlobalLayoutListener(() -> {
        if (getHeight() > 0 && null != adapter && !hasSetAdapter) {
            setAdapter(adapter);
        }
    });
}
 
Example #28
Source File: UnderlinePageIndicator.java    From iMoney with Apache License 2.0 5 votes vote down vote up
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
      setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example #29
Source File: PullToZoomBase.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    setGravity(Gravity.CENTER);

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

    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    mScreenHeight = localDisplayMetrics.heightPixels;
    mScreenWidth = localDisplayMetrics.widthPixels;

    // Refreshable View
    // By passing the attrs, we can add ListView/GridView params via XML
    mRootView = createRootView(context, attrs);

    if (attrs != null) {
        LayoutInflater mLayoutInflater = LayoutInflater.from(getContext());
        //初始化状态View
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PullToZoomView);

        int zoomViewResId = a.getResourceId(R.styleable.PullToZoomView_zoomView, 0);
        if (zoomViewResId > 0) {
            mZoomView = mLayoutInflater.inflate(zoomViewResId, null, false);
        }

        int headerViewResId = a.getResourceId(R.styleable.PullToZoomView_headerView, 0);
        if (headerViewResId > 0) {
            mHeaderView = mLayoutInflater.inflate(headerViewResId, null, false);
        }

        isParallax = a.getBoolean(R.styleable.PullToZoomListView_isHeadParallax, true);

        // Let the derivative classes have a go at handling attributes, then
        // recycle them...
        handleStyledAttributes(a);
        a.recycle();
    }
    addView(mRootView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
 
Example #30
Source File: PullToRefreshLayout.java    From aurora-imui with MIT License 5 votes vote down vote up
private void sendCancelEvent() {
    if (mLastMoveEvent == null) {
        return;
    }
    MotionEvent last = mLastMoveEvent;
    MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime() + ViewConfiguration.getLongPressTimeout(), MotionEvent.ACTION_CANCEL, last.getX(), last.getY(), last.getMetaState());
    super.dispatchTouchEvent(e);
}