androidx.core.view.GestureDetectorCompat Java Examples

The following examples show how to use androidx.core.view.GestureDetectorCompat. 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: TwoDScrollView.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
private void prepare(AttributeSet attrs)
{
    setFocusable(true);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    mScroller = new Scroller(getContext());
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleListener);
    mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener);
    if (attrs != null)
    {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomViewExtension, 0, 0);
        autoScrollMargins = a.getDimensionPixelSize(R.styleable.CustomViewExtension_autoScrollMargins, 0);
        a.recycle();
    }
    mEdgeGlowLeft = new EdgeEffect(getContext());
    mEdgeGlowTop = new EdgeEffect(getContext());
    mEdgeGlowRight = new EdgeEffect(getContext());
    mEdgeGlowBottom = new EdgeEffect(getContext());
    setWillNotDraw(false);
}
 
Example #2
Source File: RecyclerViewFragment.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
  final LayoutManagerType layoutManagerType = (LayoutManagerType) getArguments()
      .getSerializable(KEY_EXTRA_LAYOUT_MANAGER_TYPE);

  final View view = inflater
      .inflate(layoutManagerType.getLayoutId(), container, false);

  selectedItemView = (TextView) view.findViewById(layoutManagerType.getSelectedItemId());
  recyclerView = (RecyclerView) view.findViewById(layoutManagerType.getRVId());
  recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
      DividerItemDecoration.VERTICAL_LIST));
  recyclerView.setHasFixedSize(true);
  recyclerView.addOnItemTouchListener(this);
  gestureDetector = new GestureDetectorCompat(getActivity(), new ItemTouchGestureDetector());
  layoutManager = getLayoutManager(layoutManagerType);
  recyclerView.setLayoutManager(layoutManager);

  // Specify an adapter which displays items
  List<String> items = makeItems();
  adapter = ItemListAdapter.newItemListAdapter(items, inflater);
  recyclerView.setAdapter(adapter);
  return view;
}
 
Example #3
Source File: Attacher.java    From PhotoDraweeView with Apache License 2.0 6 votes vote down vote up
public Attacher(DraweeView<GenericDraweeHierarchy> draweeView) {
    mDraweeView = new WeakReference<>(draweeView);
    draweeView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER);
    draweeView.setOnTouchListener(this);
    mScaleDragDetector = new ScaleDragDetector(draweeView.getContext(), this);
    mGestureDetector = new GestureDetectorCompat(draweeView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override public void onLongPress(MotionEvent e) {
                    super.onLongPress(e);
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getDraweeView());
                    }
                }
            });
    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
}
 
Example #4
Source File: MainActivity.java    From AndroidRubberIndicator with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // set gesture detector
    mDetector = new GestureDetectorCompat(this, new MyGestureListener());

    mRubberIndicator = (RubberIndicator) findViewById(R.id.rubber);
    mTextView = (TextView) findViewById(R.id.focus_position);
    
    // check to see if savedInstanceState is null
    if (savedInstanceState != null) {
        mRubberIndicator.setCount(savedInstanceState.getInt(KEY_INDICATOR_ITEM_NUM), savedInstanceState.getInt(KEY_INDICATOR_POSITION));
    } else {
        mRubberIndicator.setCount(indicatorItemNum, 3);
    }
    
    //mRubberIndicator.setCount(5, 2);
    mRubberIndicator.setOnMoveListener(this);
    updateFocusPosition();
}
 
Example #5
Source File: MatrixView.java    From WidgetCase with Apache License 2.0 5 votes vote down vote up
public MatrixView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mBitmap = Util.getAvatar(getResources(), DensityUtil.dp2px(220));
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mScreenW = getResources().getDisplayMetrics().widthPixels;
    mScreenH = getResources().getDisplayMetrics().heightPixels;
    LogUtil.logD("初始化", "mBitmap.H = " + mBitmap
            .getHeight() + "->屏幕宽高 = " + mScreenW + "-" + mScreenH);

    mDetector = new GestureDetectorCompat(context, this);
    mOverScroller = new OverScroller(context);
}
 
Example #6
Source File: SwipeLayout.java    From SwipeLayout with MIT License 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    if (draggedViewId != 0) {
        draggedView = findViewById(draggedViewId);
    }

    if (staticLeftViewId != 0) {
        staticLeftView = findViewById(staticLeftViewId);
    }

    if (staticRightViewId != 0) {
        staticRightView = findViewById(staticRightViewId);
    }

    if (draggedView == null) {
        throw new RuntimeException("'draggedItem' must be specified");
    } else if (isTogether && currentDirection == LEFT && staticRightView == null) {
        throw new RuntimeException("If 'isTogether = true' 'rightItem' must be specified");
    } else if (isTogether && currentDirection == RIGHT && staticLeftView == null) {
        throw new RuntimeException("If 'isTogether = true' 'leftItem' must be specified");
    } else if (currentDirection == LEFT && !isContinuousSwipe && staticRightView == null) {
        throw new RuntimeException("Must be specified 'rightItem' or flag isContinuousSwipe = true");
    } else if (currentDirection == RIGHT && !isContinuousSwipe && staticLeftView == null) {
        throw new RuntimeException("Must be specified 'leftItem' or flag isContinuousSwipe = true");
    } else if (currentDirection == HORIZONTAL && (staticRightView == null || staticLeftView == null)) {
        throw new RuntimeException("'leftItem' and 'rightItem' must be specified");
    }

    dragHelper = ViewDragHelper.create(this, 1.0f, dragHelperCallback);
    gestureDetector = new GestureDetectorCompat(getContext(), gestureDetectorCallBack);

    setupPost();
    super.onFinishInflate();
}
 
Example #7
Source File: ImageViewerView.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
private void init() {
    inflate(getContext(), R.layout.image_viewer, this);

    backgroundView = findViewById(R.id.backgroundView);
    pager = (MultiTouchViewPager) findViewById(R.id.pager);

    dismissContainer = (ViewGroup) findViewById(R.id.container);
    swipeDismissListener = new SwipeToDismissListener(findViewById(R.id.dismissView), this, this);
    dismissContainer.setOnTouchListener(swipeDismissListener);

    directionDetector = new SwipeDirectionDetector(getContext()) {
        @Override
        public void onDirectionDetected(Direction direction) {
            ImageViewerView.this.direction = direction;
        }
    };

    scaleDetector = new ScaleGestureDetector(getContext(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener());

    gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (pager.isScrolled()) {
                onClick(e, isOverlayWasClicked);
            }
            return false;
        }
    });
}
 
Example #8
Source File: NestedScrollingChildView.java    From zone-sdk with MIT License 5 votes vote down vote up
public NestedScrollingChildView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setOrientation(LinearLayout.VERTICAL);
    mScroller = new OverScroller(context);
    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    mDetector = new GestureDetectorCompat(context, this);
    //todo 1
    setNestedScrollingEnabled(true);
}
 
Example #9
Source File: ZGestrueDetector.java    From zone-sdk with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private ZGestrueDetector(Context context, OnRotationGestureListener rotationListener, OnScaleGestureListener scaleListener, GestureDetector.OnGestureListener moveListener) {
    this.context = context;
    this.rotationListener = rotationListener;
    this.scaleListener = scaleListener;
    this.moveListener = moveListener;
    if (moveListener!=null)
        moveGesture =new GestureDetectorCompat(context,zMoveListener);
    if (moveListener!=null)
        scaleGesture =new ScaleGestureDetector(context,zScaleListener);
    if (rotationListener!=null)
        ratotionGesture =new RotationGestureDetector(zRotationListener);
}
 
Example #10
Source File: ScaleRecyclerView.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs,
            R.styleable.ScaleRecyclerView);
    mScaleEnable = custom.getBoolean(R.styleable.ScaleRecyclerView_srvScaleEnable,
            false);
    mScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvScale, 1);
    mMinScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMinScale,
            0.000000001f);
    mMaxScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMaxScale,
            6);
    custom.recycle();
    mGestureDetector = new GestureDetectorCompat(context, new DoubleTapListener());
    mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());
}
 
Example #11
Source File: DragFlowLayout.java    From android-drag-FlowLayout with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    mWindomHelper = new AlertWindowHelper(context);
    mGestureDetector = new GestureDetectorCompat(context, new GestureListenerImpl());
}
 
Example #12
Source File: UploadWidgetVideoView.java    From cloudinary_android with MIT License 4 votes vote down vote up
public void init() {
    gestureDetector = new GestureDetectorCompat(getContext(), new GestureListener());
}
 
Example #13
Source File: ItemTouchHelper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void startGestureDetection() {
    mItemTouchHelperGestureListener = new ItemTouchHelperGestureListener();
    mGestureDetector = new GestureDetectorCompat(mRecyclerView.getContext(),
            mItemTouchHelperGestureListener);
}
 
Example #14
Source File: ItemTouchHelper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void startGestureDetection() {
    mItemTouchHelperGestureListener = new ItemTouchHelperGestureListener();
    mGestureDetector = new GestureDetectorCompat(mRecyclerView.getContext(),
            mItemTouchHelperGestureListener);
}
 
Example #15
Source File: MobiComConversationFragment.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    geoApiKey = Utils.getMetaDataValue(ApplozicService.getContext(getContext()), ConversationActivity.GOOGLE_API_KEY_META_DATA);
    String jsonString = FileUtils.loadSettingsJsonFile(ApplozicService.getContext(getContext()));
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }

    richMessageActionProcessor = new RichMessageActionProcessor(this);

    restrictedWords = FileUtils.loadRestrictedWordsFile(getContext());
    conversationUIService = new ConversationUIService(getActivity());
    syncCallService = SyncCallService.getInstance(getActivity());
    appContactService = new AppContactService(getActivity());
    messageDatabaseService = new MessageDatabaseService(getActivity());
    fileClientService = new FileClientService(getActivity());
    setHasOptionsMenu(true);
    imageThumbnailLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return fileClientService.loadThumbnailImage(getContext(), (Message) data, getImageLayoutParam(false).width, getImageLayoutParam(false).height);
        }
    };

    imageCache = ImageCache.getInstance((getActivity()).getSupportFragmentManager(), 0.1f);
    imageThumbnailLoader.setImageFadeIn(false);
    imageThumbnailLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
    messageImageLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return fileClientService.loadMessageImage(getContext(), (String) data);
        }
    };
    messageImageLoader.setImageFadeIn(false);
    messageImageLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
    applozicAudioRecordManager = new ApplozicAudioRecordManager(getActivity());
    mDetector = new GestureDetectorCompat(getContext(), this);

}
 
Example #16
Source File: OnZoneTapListener.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
public OnZoneTapListener(View view) {
    this.view = view;
    Context context = view.getContext();
    gestureDetector = new GestureDetectorCompat(context, new OnGestureListener());
    pagerTapZoneWidth = context.getResources().getDimensionPixelSize(R.dimen.tap_zone_width);
}
 
Example #17
Source File: ItemTouchHelper.java    From Carbon with Apache License 2.0 4 votes vote down vote up
private void startGestureDetection() {
    mItemTouchHelperGestureListener = new ItemTouchHelperGestureListener();
    mGestureDetector = new GestureDetectorCompat(mRecyclerView.getContext(),
            mItemTouchHelperGestureListener);
}
 
Example #18
Source File: AttractionsActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.topFrameLayout);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mGridViewPager = (GridViewPager) findViewById(R.id.gridViewPager);
    mDotsPageIndicator = (DotsPageIndicator) findViewById(R.id.dotsPageIndicator);
    mAdapter = new AttractionsGridPagerAdapter(this, mAttractions);
    mAdapter.setOnChromeFadeListener(this);
    mGridViewPager.setAdapter(mAdapter);
    mDotsPageIndicator.setPager(mGridViewPager);
    mDotsPageIndicator.setOnPageChangeListener(mAdapter);

    topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Call through to super implementation
            insets = topFrameLayout.onApplyWindowInsets(insets);

            boolean round = insets.isRound();

            // Store system window insets regardless of screen shape
            mInsets.set(insets.getSystemWindowInsetLeft(),
                    insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(),
                    insets.getSystemWindowInsetBottom());

            if (round) {
                // On a round screen calculate the square inset to use.
                // Alternatively could use BoxInsetLayout, although calculating
                // the inset ourselves lets us position views outside the center
                // box. For example, slightly lower on the round screen (by giving
                // up some horizontal space).
                mInsets = Utils.calculateBottomInsetsOnRoundDevice(
                        getWindowManager().getDefaultDisplay(), mInsets);

                // Boost the dots indicator up by the bottom inset
                FrameLayout.LayoutParams params =
                        (FrameLayout.LayoutParams) mDotsPageIndicator.getLayoutParams();
                params.bottomMargin = mInsets.bottom;
                mDotsPageIndicator.setLayoutParams(params);
            }

            mAdapter.setInsets(mInsets);
            return insets;
        }
    });

    // Set up the DismissOverlayView
    mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
    mDismissOverlayView.setIntroText(getString(R.string.exit_intro_text));
    mDismissOverlayView.showIntroIfNecessary();
    mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());

    Uri attractionsUri = getIntent().getParcelableExtra(Constants.EXTRA_ATTRACTIONS_URI);
    if (attractionsUri != null) {
        new FetchDataAsyncTask(this).execute(attractionsUri);
        UtilityService.clearNotification(this);
        UtilityService.clearRemoteNotifications(this);
    } else {
        finish();
    }
}
 
Example #19
Source File: PictureInPictureGestureHelper.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
public static PictureInPictureGestureHelper applyTo(@NonNull View child) {
  TouchInterceptingFrameLayout  parent          = (TouchInterceptingFrameLayout) child.getParent();
  PictureInPictureGestureHelper helper          = new PictureInPictureGestureHelper(parent, child);
  GestureDetectorCompat         gestureDetector = new GestureDetectorCompat(child.getContext(), helper);

  parent.setOnInterceptTouchEventListener((event) -> {
    if (helper.velocityTracker == null) {
      helper.velocityTracker = VelocityTracker.obtain();
    }

    helper.velocityTracker.addMovement(event);

    return false;
  });

  parent.setOnTouchListener((v, event) -> {
    if (helper.velocityTracker != null) {
      helper.velocityTracker.recycle();
      helper.velocityTracker = null;
    }

    return false;
  });

  child.setOnTouchListener((v, event) -> {
    boolean handled = gestureDetector.onTouchEvent(event);

    if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
      if (!handled) {
        handled = helper.onGestureFinished(event);
      }

      if (helper.velocityTracker != null) {
        helper.velocityTracker.recycle();
        helper.velocityTracker = null;
      }
    }

    return handled;
  });

  return helper;
}
 
Example #20
Source File: ImageEditorView.java    From mollyim-android with GNU General Public License v3.0 3 votes vote down vote up
private void init() {
  setWillNotDraw(false);
  setModel(new EditorModel());

  editText = createAHiddenTextEntryField();

  doubleTap = new GestureDetectorCompat(getContext(), new DoubleTapGestureListener());

  setOnTouchListener((v, event) -> doubleTap.onTouchEvent(event));
}
 
Example #21
Source File: ImageEditorView.java    From deltachat-android with GNU General Public License v3.0 3 votes vote down vote up
private void init() {
  setWillNotDraw(false);
  setModel(new EditorModel());

  editText = createAHiddenTextEntryField();

  doubleTap = new GestureDetectorCompat(getContext(), new DoubleTapGestureListener());

  setOnTouchListener((v, event) -> doubleTap.onTouchEvent(event));
}