Java Code Examples for android.view.ViewConfiguration

The following are top voted examples for showing how to use android.view.ViewConfiguration. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: buildAPKsSamples   File: FoldingLayoutActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fold);

    mImageView = (ImageView)findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING,
            ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image));

    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

    mAnchorSeekBar = (SeekBar)findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout)findViewById(R.id.fold_view);
    mFoldLayout.setBackgroundColor(Color.BLACK);
    mFoldLayout.setFoldListener(mOnFoldListener);

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

    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

    mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector());
    mItemSelectedListener = new ItemSelectedListener();

    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();

    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
}
 
Example 2
Project: GravityBox   File: KeyButtonView.java   Source Code and License 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 3
Project: letv   File: PullToZoomBase.java   Source Code and License 6 votes vote down vote up
@SuppressLint({"NewApi"})
private void init(Context context, AttributeSet attrs) {
    setGravity(17);
    this.mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    this.mScreenHeight = localDisplayMetrics.heightPixels;
    this.mScreenWidth = localDisplayMetrics.widthPixels;
    this.mRootView = createRootView(context, attrs);
    if (attrs != null) {
        LayoutInflater mLayoutInflater = LayoutInflater.from(getContext());
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PullToZoomView);
        int zoomViewResId = a.getResourceId(2, 0);
        if (zoomViewResId > 0) {
            this.mZoomView = mLayoutInflater.inflate(zoomViewResId, null, false);
        }
        int headerViewResId = a.getResourceId(0, 0);
        if (headerViewResId > 0) {
            this.mHeaderView = mLayoutInflater.inflate(headerViewResId, null, false);
        }
        this.isParallax = a.getBoolean(1, true);
        handleStyledAttributes(a);
        a.recycle();
    }
    addView(this.mRootView, -1, -1);
}
 
Example 4
Project: Hello-Music-droid   File: ViewDragHelper.java   Source Code and License 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 initialize 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
Project: quickblox-android   File: CoreBaseActivity.java   Source Code and License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    actionBar = getSupportActionBar();

    // Hack. Forcing overflow button on actionbar on devices with hardware menu button
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
}
 
Example 6
Project: XphotoView   File: GooglePhotosGestureDetector.java   Source Code and License 6 votes vote down vote up
public GooglePhotosGestureDetector(@Nullable Context context, @NonNull GooglePhotosGestureListener listener) {
    this.gestureListener = listener;
    gestureHandler = new GestureHandler();
    if (context == null) {
        MIN_FLING_VELOCITY = ViewConfiguration.getMinimumFlingVelocity();
        MAX_FLING_VELOCITY = ViewConfiguration.getMaximumFlingVelocity();
        DOUBLE_TAP_SLOP = 100;
        SCALE_SPAN_SLOP = 16;
    } else {
        ViewConfiguration config = ViewConfiguration.get(context);
        MIN_FLING_VELOCITY = config.getScaledMinimumFlingVelocity();
        MAX_FLING_VELOCITY = config.getScaledMaximumFlingVelocity();
        DOUBLE_TAP_SLOP = config.getScaledDoubleTapSlop();
        SCALE_SPAN_SLOP = config.getScaledTouchSlop() * 2;
    }
}
 
Example 7
Project: Nird2   File: RepeatableImageKey.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
	switch (motionEvent.getAction()) {
		case ACTION_DOWN:
			view.postDelayed(repeater,
					ViewConfiguration.getKeyRepeatTimeout());
			performHapticFeedback(KEYBOARD_TAP);
			return false;
		case ACTION_CANCEL:
		case ACTION_UP:
			view.removeCallbacks(repeater);
			return false;
		default:
			return false;
	}
}
 
Example 8
Project: PlusGram   File: RecyclerView.java   Source Code and License 6 votes vote down vote up
/**
 * Configure the scrolling touch slop for a specific use case.
 *
 * Set up the RecyclerView'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 RecyclerView
 */
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;
    }
}
 
Example 9
Project: GitHub   File: SystemBarTintManager.java   Source Code and License 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
Project: boohee_v5.6   File: ViewDragHelper.java   Source Code and License 6 votes vote down vote up
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    } else if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    } else {
        this.mParentView = forParent;
        this.mCallback = cb;
        ViewConfiguration vc = ViewConfiguration.get(context);
        this.mEdgeSize = (int) ((20.0f * context.getResources().getDisplayMetrics().density) + 0.5f);
        this.mTouchSlop = vc.getScaledTouchSlop();
        this.mMaxVelocity = (float) vc.getScaledMaximumFlingVelocity();
        this.mMinVelocity = (float) vc.getScaledMinimumFlingVelocity();
        this.mScroller = ScrollerCompat.create(context, sInterpolator);
    }
}
 
Example 11
Project: LiuAGeAndroid   File: SystemBarTintManager.java   Source Code and License 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 12
Project: keepass2android   File: LatinKeyboard.java   Source Code and License 6 votes vote down vote up
@SuppressLint("ResourceAsColor")
public SlidingLocaleDrawable(Drawable background, int width, int height) {
          mBackground = background;
          setDefaultBounds(mBackground);
          mWidth = width;
          mHeight = height;
          mTextPaint = new TextPaint();
          mTextPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18));
          
          mTextPaint.setColor(R.color.latinkeyboard_transparent);
          mTextPaint.setTextAlign(Align.CENTER);
          mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE);
          mTextPaint.setAntiAlias(true);
          mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2;
          mLeftDrawable =
                  mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_left);
          mRightDrawable =
                  mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_right);
          mThreshold = ViewConfiguration.get(mContext).getScaledTouchSlop();
      }
 
Example 13
Project: chromium-for-android-56-debug-video   File: StackLayout.java   Source Code and License 6 votes vote down vote up
/**
 * @param context     The current Android's context.
 * @param updateHost  The {@link LayoutUpdateHost} view for this layout.
 * @param renderHost  The {@link LayoutRenderHost} view for this layout.
 * @param eventFilter The {@link EventFilter} that is needed for this view.
 */
public StackLayout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost renderHost,
        EventFilter eventFilter) {
    super(context, updateHost, renderHost, eventFilter);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinDirectionThreshold = configuration.getScaledTouchSlop();
    mMinShortPressThresholdSqr =
            configuration.getScaledPagingTouchSlop() * configuration.getScaledPagingTouchSlop();

    mMinMaxInnerMargin = (int) (MIN_INNER_MARGIN_PERCENT_DP + 0.5);
    mFlingSpeed = FLING_SPEED_DP;
    mStacks = new Stack[2];
    mStacks[0] = new Stack(context, this);
    mStacks[1] = new Stack(context, this);
    mStackRects = new RectF[2];
    mStackRects[0] = new RectF();
    mStackRects[1] = new RectF();

    mViewContainer = new FrameLayout(getContext());
    mSceneLayer = new TabListSceneLayer();
}
 
Example 14
Project: Tribe   File: DraggableSquareView.java   Source Code and License 6 votes vote down vote up
public DraggableSquareView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mDragHelper = ViewDragHelper
            .create(this, 10f, new DragHelperCallback());
    moveDetector = new GestureDetectorCompat(context,
            new MoveDetector());
    moveDetector.setIsLongpressEnabled(false); // 不能处理长按事件,否则违背最初设计的初衷
    spaceInterval = (int) getResources().getDimension(R.dimen.drag_square_interval); // 小方块之间的间隔

    // 滑动的距离阈值由系统提供
    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();

    anchorHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (draggingView != null) {
                // 开始移动重心的动画
                draggingView.startAnchorAnimation();
            }
        }
    };
}
 
Example 15
Project: FlickLauncher   File: DragController.java   Source Code and License 6 votes vote down vote up
/**
 * Determines whether the user flung the current item to delete it.
 *
 * @return the vector at which the item was flung, or null if no fling was detected.
 */
private PointF isFlingingToDelete(DragSource source) {
    if (mFlingToDeleteDropTarget == null) return null;
    if (!source.supportsFlingToDelete()) return null;

    ViewConfiguration config = ViewConfiguration.get(mLauncher);
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
    PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
    float theta = MAX_FLING_DEGREES + 1;
    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF upVec = new PointF(0f, -1f);
        theta = getAngleBetweenVectors(vel, upVec);
    } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() &&
            mVelocityTracker.getXVelocity() < mFlingToDeleteThresholdVelocity) {
        // Remove icon is on left side instead of top, so check if we are flinging to the left.
        PointF leftVec = new PointF(-1f, 0f);
        theta = getAngleBetweenVectors(vel, leftVec);
    }
    if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
        return vel;
    }
    return null;
}
 
Example 16
Project: letv   File: ViewDragHelper.java   Source Code and License 6 votes vote down vote up
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    } else if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    } else {
        this.mParentView = forParent;
        this.mCallback = cb;
        ViewConfiguration vc = ViewConfiguration.get(context);
        this.mEdgeSize = (int) ((TitleBar.BACKBTN_LEFT_MARGIN * context.getResources().getDisplayMetrics().density) + 0.5f);
        this.mTouchSlop = vc.getScaledTouchSlop();
        this.mMaxVelocity = (float) vc.getScaledMaximumFlingVelocity();
        this.mMinVelocity = (float) vc.getScaledMinimumFlingVelocity();
        this.mScroller = ScrollerCompat.create(context, sInterpolator);
    }
}
 
Example 17
Project: KUtils-master   File: SystemBarTintManager.java   Source Code and License 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 18
Project: Cable-Android   File: RepeatableImageKey.java   Source Code and License 6 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
  switch (motionEvent.getAction()) {
  case MotionEvent.ACTION_DOWN:
    view.postDelayed(repeater, VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1
                               ? ViewConfiguration.getKeyRepeatTimeout()
                               : ViewConfiguration.getLongPressTimeout());
    performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
    return false;
  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    view.removeCallbacks(repeater);
    return false;
  default:
    return false;
  }
}
 
Example 19
Project: head   File: SystemBarTintManager.java   Source Code and License 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 20
Project: WebPager   File: CustomViewPager.java   Source Code and License 6 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);
	final float density = context.getResources().getDisplayMetrics().density;

	mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
	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 MyAccessibilityDelegate());

	if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
		ViewCompat.setImportantForAccessibility(this,
			ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
	}
}
 
Example 21
Project: AutoRecycleView   File: SuperSwipeRefreshLayout.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public SuperSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    /**
     * getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件
     */
    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();

    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mHeaderViewWidth = (int) display.getWidth();
    mFooterViewWidth = (int) display.getWidth();
    mHeaderViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density);
    mFooterViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density);
    defaultProgressView = new CircleProgressView(getContext());
    createHeaderViewContainer();
    createFooterViewContainer();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    density = metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}
 
Example 22
Project: Android-PullRefresh   File: PullRefreshLayout.java   Source Code and License 5 votes vote down vote up
public PullRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.refresh_PullRefreshLayout);
    final int colorsId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColors, 0);
    final int colorId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColor, 0);
    a.recycle();
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    int defaultDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    mDurationToStartPosition = defaultDuration;
    mDurationToCorrectPosition = defaultDuration;
    mSpinnerFinalOffset = mTotalDragDistance = dp2px(DRAG_MAX_DISTANCE);
    mRefreshView = new ImageView(context);
    if (colorsId > 0) {
        mColorSchemeColors = context.getResources().getIntArray(colorsId);
    } else {
        mColorSchemeColors = new int[]{Color.rgb(0xC9, 0x34, 0x37), Color.rgb(0x37, 0x5B, 0xF1), Color.rgb(0xF7, 0xD2, 0x3E), Color.rgb(0x34, 0xA3, 0x50)};
    }

    if (colorId > 0) {
        mColorSchemeColors = new int[]{ContextCompat.getColor(context, colorId)};
    }
    setDefaultRefreshStyle();
    mRefreshView.setVisibility(View.GONE);

    setWillNotDraw(false);
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
}
 
Example 23
Project: SuperNote   File: NoteMainActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void initViews() {

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

    mPresenter.initDataBase();
    initDrawer();
    initAdapter();

    mRvNoteList.setAdapter(mAdapter);
    mRvNoteList.setOnTouchListener(this);

    mPresenter.initNoteRvLayoutManager();
}
 
Example 24
Project: airgram   File: NumberPicker.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }
    final int action = event.getActionMasked();
    switch (action) {
        case MotionEvent.ACTION_DOWN: {
            removeAllCallbacks();
            mInputText.setVisibility(View.INVISIBLE);
            mLastDownOrMoveEventY = mLastDownEventY = event.getY();
            mLastDownEventTime = event.getEventTime();
            mIngonreMoveEvents = false;
            if (mLastDownEventY < mTopSelectionDividerTop) {
                if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
                    mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_DECREMENT);
                }
            } else if (mLastDownEventY > mBottomSelectionDividerBottom) {
                if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
                    mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_INCREMENT);
                }
            }
            getParent().requestDisallowInterceptTouchEvent(true);
            if (!mFlingScroller.isFinished()) {
                mFlingScroller.forceFinished(true);
                mAdjustScroller.forceFinished(true);
                onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            } else if (!mAdjustScroller.isFinished()) {
                mFlingScroller.forceFinished(true);
                mAdjustScroller.forceFinished(true);
            } else if (mLastDownEventY < mTopSelectionDividerTop) {
                postChangeCurrentByOneFromLongPress(false, ViewConfiguration.getLongPressTimeout());
            } else if (mLastDownEventY > mBottomSelectionDividerBottom) {
                postChangeCurrentByOneFromLongPress(true, ViewConfiguration.getLongPressTimeout());
            }
            return true;
        }
    }
    return false;
}
 
Example 25
Project: GitHub   File: Utils.java   Source Code and License 5 votes vote down vote up
/**
 * initialize method, called inside the Chart.init() method. backwards
 * compatibility - to not break existing code
 *
 * @param res
 */
@Deprecated
public static void init(Resources res) {

    mMetrics = res.getDisplayMetrics();

    // noinspection deprecation
    mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
    // noinspection deprecation
    mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
}
 
Example 26
Project: scab   File: CirclePageIndicator.java   Source Code and License 5 votes vote down vote up
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

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

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example 27
Project: PlusGram   File: RecyclerView.java   Source Code and License 5 votes vote down vote up
public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);
    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));
    // Create the layoutManager if specified.

    // Re-set whether nested scrolling is enabled so that it is set on all API levels
    setNestedScrollingEnabled(true);
}
 
Example 28
Project: MultiSelecter   File: SuperSwipeRefreshLayout.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public SuperSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    /**
     * getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件
     */
    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();

    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mHeaderViewWidth = (int) display.getWidth();
    mFooterViewWidth = (int) display.getWidth();
    mHeaderViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density);
    mFooterViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density);
    defaultProgressView = new CircleProgressView(getContext());
    createHeaderViewContainer();
    createFooterViewContainer();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    density = metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}
 
Example 29
Project: GitHub   File: CirclePageIndicator.java   Source Code and License 5 votes vote down vote up
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

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

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example 30
Project: anyRTC-RTCP-Android   File: BaseDialog.java   Source Code and License 5 votes vote down vote up
/**
 * 判断当前用户触摸是否超出了Dialog的显示区域
 *
 * @param context
 * @param event
 * @return
 */
private boolean isOutOfBounds(Context context, MotionEvent event) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
    final View decorView = getWindow().getDecorView();
    return (x < -slop) || (y < -slop) || (x > (decorView.getWidth() + slop))
            || (y > (decorView.getHeight() + slop));
}
 
Example 31
Project: AndroidUiKit   File: ISwipeRefreshLayout.java   Source Code and License 5 votes vote down vote up
/**
 * Constructor that is called when inflating ISwipeRefreshLayout from XML.
 *
 * @param context
 * @param attrs
 */
public ISwipeRefreshLayout(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 DisplayMetrics metrics = getResources().getDisplayMetrics();
    mRefreshViewHeight = (int) (DEFAULT_HEADER_HEIGHT * metrics.density);
    HEADER_VIEW_MIN_HEIGHT = mRefreshViewHeight;
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    mTotalDragDistance = (int) (DEFAULT_HEADER_TARGET * metrics.density);
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

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

    //add default refreshview
    setRefreshHeaderView(new ClassicIRefreshHeaderView(getContext()));
}
 
Example 32
Project: betterHotels   File: ReactionView.java   Source Code and License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs){
    //Initially the View is not visible until it is alerted to show at a specific position, sX and sY
    setVisibility(View.GONE);
    setLayoutTransition(new ReactionLayoutTransition());
    visibilityListeners = new ArrayList<>();
    reactionListeners = new ArrayList<>();
    vc = ViewConfiguration.get(context);
    sX = 0f;
    sY = 0f;
    //backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    //backgroundPaint.setColor(Color.parseColor("#FFFFFF"));
    //backgroundPaint.setStyle(Paint.Style.FILL);
    //backgroundPaint.setAlpha(230);
    addIcons(context);
}
 
Example 33
Project: orgzly-android   File: GesturedListView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    maxFlingVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
    minFlingVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
    // touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    gestureDetector = new GestureDetector(getContext(), this);
    selector = getSelector();

    int menuContainerId = 0;
    HashMap<Gesture, Integer> gestureMenuMap = new HashMap<>();

    /* Get attributes from XML. */
    if (attrs != null) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.GesturedListView);

        menuContainerId = typedArray.getResourceId(R.styleable.GesturedListView_menu_container, 0);

        int child;

        child = typedArray.getInt(R.styleable.GesturedListView_menu_for_fling_left, -1);
        if (child != -1) {
            gestureMenuMap.put(Gesture.FLING_LEFT, child);
        }

        child = typedArray.getInt(R.styleable.GesturedListView_menu_for_fling_right, -1);
        if (child != -1) {
            gestureMenuMap.put(Gesture.FLING_RIGHT, child);
        }

        typedArray.recycle();
    }


    /* Disable selector. */
    // setSelector(android.R.color.transparent);

    itemMenus = new GesturedListViewItemMenus(this, gestureMenuMap, menuContainerId);
}
 
Example 34
Project: airgram   File: RecyclerView.java   Source Code and License 5 votes vote down vote up
public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);
    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));
    // Create the layoutManager if specified.

    // Re-set whether nested scrolling is enabled so that it is set on all API levels
    setNestedScrollingEnabled(true);
}
 
Example 35
Project: HorizontalLoopView   File: HorizontalLoopView.java   Source Code and License 5 votes vote down vote up
/**
 * 初始化一些滚动的属性
 */
private void initScroll() {
    mScroller = new Scroller(getContext());
    //水平垂直
    setGravity(Gravity.CENTER_VERTICAL);
    //水平方向
    setOrientation(HORIZONTAL);
    //视图滚动配置
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    //获取最小滚动距离
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    //最大滚动距离
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

}
 
Example 36
Project: DateScroller   File: DateScrollerView.java   Source Code and License 5 votes vote down vote up
private void init() {

        scroller = new OverScroller(getContext());
        //the touch distance for distinguish touch event between click and scroll
        touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();

        popUpView = new PopUpView();

        dateData = new ArrayList<>();
        currentYear = calendar.get(Calendar.YEAR);
        addMoreDays();
    }
 
Example 37
Project: AppFirCloud   File: SwipeMenuLayout.java   Source Code and License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mScaleTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMaxVelocity = ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
    //初始化滑动帮助类对象
    //mScroller = new Scroller(context);

    //右滑删除功能的开关,默认开
    isSwipeEnable = true;
    //IOS、QQ式交互,默认开
    isIos = true;
    //左滑右滑的开关,默认左滑打开菜单
    isLeftSwipe = true;
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout, defStyleAttr, 0);
    int count = ta.getIndexCount();
    for (int i = 0; i < count; i++) {
        int attr = ta.getIndex(i);
        //如果引用成AndroidLib 资源都不是常量,无法使用switch case
        if (attr == R.styleable.SwipeMenuLayout_swipeEnable) {
            isSwipeEnable = ta.getBoolean(attr, true);
        } else if (attr == R.styleable.SwipeMenuLayout_ios) {
            isIos = ta.getBoolean(attr, true);
        } else if (attr == R.styleable.SwipeMenuLayout_leftSwipe) {
            isLeftSwipe = ta.getBoolean(attr, true);
        }
    }
    ta.recycle();


}
 
Example 38
Project: UiLib   File: LRecyclerView.java   Source Code and License 5 votes vote down vote up
private void init() {
    if (pullRefreshEnabled) {
        mRefreshHeader = new ArrowRefreshHeader(getContext());
        mRefreshHeader.setProgressStyle(mRefreshProgressStyle);
    }
    LoadingMoreFooter footView = new LoadingMoreFooter(getContext());
    footView.setProgressStyle(mLoadingMoreProgressStyle);
    mFootView = footView;
    mFootView.setVisibility(GONE);

    mScaleTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}
 
Example 39
Project: mvparms   File: DeviceUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 设备是否有实体菜单
 *
 * @param context
 * @return
 */
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 40
Project: RLibrary   File: SwipeMenuLayout.java   Source Code and License 5 votes vote down vote up
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout);
    mLeftViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_leftViewId, mLeftViewId);
    mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId);
    mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId);
    typedArray.recycle();

    ViewConfiguration mViewConfig = ViewConfiguration.get(getContext());
    mScaledTouchSlop = mViewConfig.getScaledTouchSlop();
    mScroller = new OverScroller(getContext());
    mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity();
    mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity();
}