Search in sources :

Example 86 with GestureDetector

use of android.view.GestureDetector in project enroscar by stanfy.

the class LoadableImageSwitcher method init.

private void init(final Context context) {
    super.setFactory(this);
    gestureDetector = new GestureDetector(context, this);
    gestureDetector.setIsLongpressEnabled(true);
}
Also used : GestureDetector(android.view.GestureDetector)

Example 87 with GestureDetector

use of android.view.GestureDetector in project android_frameworks_base by ParanoidAndroid.

the class KeyboardView method initGestureDetector.

private void initGestureDetector() {
    mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
            if (mPossiblePoly)
                return false;
            final float absX = Math.abs(velocityX);
            final float absY = Math.abs(velocityY);
            float deltaX = me2.getX() - me1.getX();
            float deltaY = me2.getY() - me1.getY();
            // Half the keyboard width
            int travelX = getWidth() / 2;
            // Half the keyboard height
            int travelY = getHeight() / 2;
            mSwipeTracker.computeCurrentVelocity(1000);
            final float endingVelocityX = mSwipeTracker.getXVelocity();
            final float endingVelocityY = mSwipeTracker.getYVelocity();
            boolean sendDownKey = false;
            if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
                if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
                    sendDownKey = true;
                } else {
                    swipeRight();
                    return true;
                }
            } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
                if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
                    sendDownKey = true;
                } else {
                    swipeLeft();
                    return true;
                }
            } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
                if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
                    sendDownKey = true;
                } else {
                    swipeUp();
                    return true;
                }
            } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
                if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
                    sendDownKey = true;
                } else {
                    swipeDown();
                    return true;
                }
            }
            if (sendDownKey) {
                detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
            }
            return false;
        }
    });
    mGestureDetector.setIsLongpressEnabled(false);
}
Also used : GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 88 with GestureDetector

use of android.view.GestureDetector in project platform_frameworks_base by android.

the class KeyboardView method initGestureDetector.

private void initGestureDetector() {
    if (mGestureDetector == null) {
        mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

            @Override
            public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
                if (mPossiblePoly)
                    return false;
                final float absX = Math.abs(velocityX);
                final float absY = Math.abs(velocityY);
                float deltaX = me2.getX() - me1.getX();
                float deltaY = me2.getY() - me1.getY();
                // Half the keyboard width
                int travelX = getWidth() / 2;
                // Half the keyboard height
                int travelY = getHeight() / 2;
                mSwipeTracker.computeCurrentVelocity(1000);
                final float endingVelocityX = mSwipeTracker.getXVelocity();
                final float endingVelocityY = mSwipeTracker.getYVelocity();
                boolean sendDownKey = false;
                if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
                    if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeRight();
                        return true;
                    }
                } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
                    if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeLeft();
                        return true;
                    }
                } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
                    if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeUp();
                        return true;
                    }
                } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
                    if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeDown();
                        return true;
                    }
                }
                if (sendDownKey) {
                    detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
                }
                return false;
            }
        });
        mGestureDetector.setIsLongpressEnabled(false);
    }
}
Also used : GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 89 with GestureDetector

use of android.view.GestureDetector in project NewPipe by TeamNewPipe.

the class PopupVideoPlayer method initPopup.

@SuppressLint({ "RtlHardcoded" })
private void initPopup() {
    if (DEBUG)
        Log.d(TAG, "initPopup() called");
    View rootView = View.inflate(this, R.layout.player_popup, null);
    viewHolder = new PopupViewHolder(rootView);
    viewHolder.getPlaybackSeekBar().setOnSeekBarChangeListener(internalListener);
    emVideoView = viewHolder.getVideoView();
    emVideoView.setOnPreparedListener(internalListener);
    emVideoView.setOnCompletionListener(internalListener);
    emVideoView.setOnErrorListener(internalListener);
    emVideoView.setOnSeekCompletionListener(internalListener);
    windowLayoutParams = new WindowManager.LayoutParams((int) getMinimumVideoWidth(currentPopupHeight), (int) currentPopupHeight, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
    windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    MySimpleOnGestureListener listener = new MySimpleOnGestureListener();
    gestureDetector = new GestureDetector(this, listener);
    gestureDetector.setIsLongpressEnabled(false);
    rootView.setOnTouchListener(listener);
    updateScreenSize();
    windowManager.addView(rootView, windowLayoutParams);
}
Also used : GestureDetector(android.view.GestureDetector) View(android.view.View) EMVideoView(com.devbrackets.android.exomedia.ui.widget.EMVideoView) PopupViewHolder(org.schabi.newpipe.player.popup.PopupViewHolder) WindowManager(android.view.WindowManager) SuppressLint(android.annotation.SuppressLint)

Example 90 with GestureDetector

use of android.view.GestureDetector in project Reader by TheKeeperOfPie.

the class ActivityMain method inflateNavigationDrawer.

private void inflateNavigationDrawer() {
    // TODO: Adhere to guidelines by making the increment 56dp on mobile and 64dp on tablet
    float standardIncrement = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
    float screenWidth = getResources().getDisplayMetrics().widthPixels;
    float navigationWidth = screenWidth - UtilsTheme.getAttributeDimension(this, R.attr.actionBarSize, standardIncrement);
    if (navigationWidth > standardIncrement * 6) {
        navigationWidth = standardIncrement * 6;
    }
    layoutNavigation.getLayoutParams().width = (int) navigationWidth;
    textAccountName.setTextColor(colorFilterPrimary.getColor());
    textAccountInfo.setTextColor(colorFilterPrimary.getColor());
    buttonAccounts.setColorFilter(colorFilterPrimary);
    View.OnClickListener onClickListener = v -> setAccountsVisible(!accountsVisible);
    textAccountName.setOnClickListener(onClickListener);
    textAccountInfo.setOnClickListener(onClickListener);
    buttonAccounts.setOnClickListener(onClickListener);
    adapterAccounts = new AccountsAdapter(colorFilterPrimary.getColor(), this);
    recyclerAccounts.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    recyclerAccounts.setAdapter(adapterAccounts);
    resetAccountList();
    final GestureDetectorCompat gestureDetector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            loadHeaderImage(true);
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            String permalink = sharedPreferences.getString(AppSettings.HEADER_PERMALINK, "");
            if (!TextUtils.isEmpty(permalink)) {
                Intent intentActivity = new Intent(ActivityMain.this, ActivityMain.class);
                intentActivity.setAction(Intent.ACTION_VIEW);
                intentActivity.setData(Uri.parse(Reddit.BASE_URL + permalink));
                startActivity(intentActivity);
                return true;
            }
            return super.onSingleTapConfirmed(e);
        }
    });
    // Add an empty view to remove extra margin on top
    viewNavigation.addHeaderView(new View(this));
    viewNavigation.setNavigationItemSelectedListener(menuItem -> {
        loadId = menuItem.getItemId();
        layoutDrawer.closeDrawer(GravityCompat.START);
        return true;
    });
    scrollHeaderVertical.setDispatchTouchListener((v, event) -> {
        gestureDetector.onTouchEvent(event);
        switch(MotionEventCompat.getActionMasked(event)) {
            case MotionEvent.ACTION_DOWN:
                layoutDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                layoutDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
                break;
        }
        return false;
    });
    loadHeaderImage(false);
}
Also used : Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) FragmentReply(com.winsonchiu.reader.comments.FragmentReply) Source(com.winsonchiu.reader.comments.Source) UtilsJson(com.winsonchiu.reader.utils.UtilsJson) Drawable(android.graphics.drawable.Drawable) UtilsAnimation(com.winsonchiu.reader.utils.UtilsAnimation) HorizontalScrollView(android.widget.HorizontalScrollView) Reddit(com.winsonchiu.reader.data.reddit.Reddit) EventListenerBase(com.winsonchiu.reader.utils.EventListenerBase) Handler(android.os.Handler) CustomTabsSession(android.support.customtabs.CustomTabsSession) Schedulers(rx.schedulers.Schedulers) JsonNode(com.fasterxml.jackson.databind.JsonNode) Log(android.util.Log) AccountManager(android.accounts.AccountManager) AdapterCommentList(com.winsonchiu.reader.comments.AdapterCommentList) Account(android.accounts.Account) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) AccountManagerFuture(android.accounts.AccountManagerFuture) UtilsColor(com.winsonchiu.reader.utils.UtilsColor) AccountManagerCallback(android.accounts.AccountManagerCallback) Html(android.text.Html) Time(com.winsonchiu.reader.data.reddit.Time) FragmentProfile(com.winsonchiu.reader.profile.FragmentProfile) ControllerHistory(com.winsonchiu.reader.history.ControllerHistory) GestureDetector(android.view.GestureDetector) ButterKnife(butterknife.ButterKnife) Environment(android.os.Environment) BitmapFactory(android.graphics.BitmapFactory) NonNull(android.support.annotation.NonNull) Receiver(com.winsonchiu.reader.inbox.Receiver) ComponentStatic(com.winsonchiu.reader.dagger.components.ComponentStatic) ControllerInbox(com.winsonchiu.reader.inbox.ControllerInbox) Toast(android.widget.Toast) RedditOpenHelper(com.winsonchiu.reader.data.database.reddit.RedditOpenHelper) Menu(android.view.Menu) Link(com.winsonchiu.reader.data.reddit.Link) DrawerLayout(android.support.v4.widget.DrawerLayout) ComponentName(android.content.ComponentName) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) FinalizingSubscriber(com.winsonchiu.reader.rx.FinalizingSubscriber) IOException(java.io.IOException) Thing(com.winsonchiu.reader.data.reddit.Thing) FragmentSearch(com.winsonchiu.reader.search.FragmentSearch) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ThemeColor(com.winsonchiu.reader.theme.ThemeColor) UtilsImage(com.winsonchiu.reader.utils.UtilsImage) UtilsTheme(com.winsonchiu.reader.utils.UtilsTheme) CustomTabsCallback(android.support.customtabs.CustomTabsCallback) NavigationView(android.support.design.widget.NavigationView) ImageButton(android.widget.ImageButton) Page(com.winsonchiu.reader.data.Page) ControllerCommentsTop(com.winsonchiu.reader.comments.ControllerCommentsTop) Historian(com.winsonchiu.reader.history.Historian) ActivitySettings(com.winsonchiu.reader.settings.ActivitySettings) PackageManager(android.content.pm.PackageManager) ControllerLinks(com.winsonchiu.reader.links.ControllerLinks) URL(java.net.URL) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ImageDownload(com.winsonchiu.reader.utils.ImageDownload) BindView(butterknife.BindView) Browser(android.provider.Browser) MotionEventCompat(android.support.v4.view.MotionEventCompat) Picasso(com.squareup.picasso.Picasso) ControllerProfile(com.winsonchiu.reader.profile.ControllerProfile) CustomTabsServiceConnection(android.support.customtabs.CustomTabsServiceConnection) Target(com.squareup.picasso.Target) View(android.view.View) CustomTabsClient(android.support.customtabs.CustomTabsClient) ControllerSearch(com.winsonchiu.reader.search.ControllerSearch) AccountsAdapter(com.winsonchiu.reader.accounts.AccountsAdapter) ScrollViewHeader(com.winsonchiu.reader.views.ScrollViewHeader) FragmentInbox(com.winsonchiu.reader.inbox.FragmentInbox) PorterDuff(android.graphics.PorterDuff) ComponentActivity(com.winsonchiu.reader.dagger.components.ComponentActivity) Observer(rx.Observer) FragmentComments(com.winsonchiu.reader.comments.FragmentComments) UtilsReddit(com.winsonchiu.reader.utils.UtilsReddit) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) DownloadManager(android.app.DownloadManager) List(java.util.List) TextView(android.widget.TextView) Themer(com.winsonchiu.reader.theme.Themer) Replyable(com.winsonchiu.reader.data.reddit.Replyable) RelativeLayout(android.widget.RelativeLayout) Seat(jp.wasabeef.takt.Seat) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Subreddit(com.winsonchiu.reader.data.reddit.Subreddit) AdapterLink(com.winsonchiu.reader.links.AdapterLink) UtilsRx(com.winsonchiu.reader.utils.UtilsRx) Intent(android.content.Intent) FragmentThreadList(com.winsonchiu.reader.links.FragmentThreadList) ObserverNext(com.winsonchiu.reader.rx.ObserverNext) Takt(jp.wasabeef.takt.Takt) MenuItem(android.view.MenuItem) FragmentHistory(com.winsonchiu.reader.history.FragmentHistory) Observable(rx.Observable) GravityCompat(android.support.v4.view.GravityCompat) Inject(javax.inject.Inject) MotionEvent(android.view.MotionEvent) Build(android.os.Build) AlarmManager(android.app.AlarmManager) URLUtil(android.webkit.URLUtil) MalformedURLException(java.net.MalformedURLException) LayoutInflater(android.view.LayoutInflater) Sort(com.winsonchiu.reader.data.reddit.Sort) Listing(com.winsonchiu.reader.data.reddit.Listing) Color(android.graphics.Color) Bitmap(android.graphics.Bitmap) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) Callback(com.squareup.picasso.Callback) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) Collections(java.util.Collections) Resources(android.content.res.Resources) CustomColorFilter(com.winsonchiu.reader.utils.CustomColorFilter) GestureDetector(android.view.GestureDetector) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent) AccountsAdapter(com.winsonchiu.reader.accounts.AccountsAdapter)

Aggregations

GestureDetector (android.view.GestureDetector)133 MotionEvent (android.view.MotionEvent)46 ScaleGestureDetector (android.view.ScaleGestureDetector)23 Paint (android.graphics.Paint)22 View (android.view.View)22 Scroller (android.widget.Scroller)13 WindowManager (android.view.WindowManager)11 Handler (android.os.Handler)9 TextView (android.widget.TextView)9 SimpleOnGestureListener (android.view.GestureDetector.SimpleOnGestureListener)8 LayoutInflater (android.view.LayoutInflater)8 TypedArray (android.content.res.TypedArray)7 ImageView (android.widget.ImageView)7 ViewConfiguration (android.view.ViewConfiguration)6 OverScroller (android.widget.OverScroller)6 Matrix (android.graphics.Matrix)5 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 SuppressLint (android.annotation.SuppressLint)4 Resources (android.content.res.Resources)4