Search in sources :

Example 21 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project vlc-android by GeoffreyMetais.

the class PopupManager method showPopup.

public void showPopup() {
    mService.addCallback(this);
    LayoutInflater li = (LayoutInflater) VLCApplication.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mRootView = (PopupLayout) li.inflate(R.layout.video_popup, null);
    if (mAlwaysOn)
        mRootView.setKeepScreenOn(true);
    mPlayPauseButton = mRootView.findViewById(R.id.video_play_pause);
    mCloseButton = mRootView.findViewById(R.id.popup_close);
    mExpandButton = mRootView.findViewById(R.id.popup_expand);
    mPlayPauseButton.setOnClickListener(this);
    mCloseButton.setOnClickListener(this);
    mExpandButton.setOnClickListener(this);
    GestureDetectorCompat gestureDetector = new GestureDetectorCompat(mService, this);
    gestureDetector.setOnDoubleTapListener(this);
    mRootView.setGestureDetector(gestureDetector);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.setVideoView((SurfaceView) mRootView.findViewById(R.id.player_surface));
    vlcVout.addCallback(this);
    vlcVout.attachViews(this);
    mRootView.setVLCVOut(vlcVout);
}
Also used : LayoutInflater(android.view.LayoutInflater) IVLCVout(org.videolan.libvlc.IVLCVout) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat)

Example 22 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project BaseProject by feer921.

the class SimpleClickListener method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    if (recyclerView == null) {
        this.recyclerView = rv;
        this.baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
        mGestureDetector = new GestureDetectorCompat(recyclerView.getContext(), new ItemTouchHelperGestureListener(recyclerView));
    } else if (recyclerView != rv) {
        this.recyclerView = rv;
        this.baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
        mGestureDetector = new GestureDetectorCompat(recyclerView.getContext(), new ItemTouchHelperGestureListener(recyclerView));
    }
    if (!mGestureDetector.onTouchEvent(e) && e.getActionMasked() == MotionEvent.ACTION_UP && mIsShowPress) {
        if (mPressedView != null) {
            BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(mPressedView);
            if (vh == null || !isHeaderOrFooterView(vh.getItemViewType())) {
                mPressedView.setPressed(false);
            }
        }
        mIsShowPress = false;
        mIsPrepressed = false;
    }
    return false;
}
Also used : BaseViewHolder(com.chad.library.adapter.base.BaseViewHolder) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat)

Example 23 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat 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)

Example 24 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project Reader by TheKeeperOfPie.

the class FragmentCommentsInner method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    scrollToPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    scrollToPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
    layoutRoot = (CustomFrameLayout) inflater.inflate(R.layout.fragment_comments_inner, container, false);
    CallbackYouTubeDestruction callbackYouTubeDestruction = () -> {
        adapterCommentList.destroyYouTubePlayerFragments();
        adapterLink.destroyYouTubePlayerFragments();
    };
    swipeRefreshCommentList = (SwipeRefreshLayout) layoutRoot.findViewById(R.id.swipe_refresh_comment_list);
    swipeRefreshCommentList.setOnRefreshListener(() -> controllerComments.reloadAllComments());
    linearLayoutManager = new LinearLayoutManager(getActivity());
    recyclerCommentList = (RecyclerView) layoutRoot.findViewById(R.id.recycler_comment_list);
    recyclerCommentList.setLayoutManager(linearLayoutManager);
    recyclerCommentList.setHasFixedSize(true);
    recyclerCommentList.setItemAnimator(null);
    AdapterListener adapterListenerComment = new AdapterListener() {

        @Override
        public void scrollAndCenter(int position, int height) {
            linearLayoutManager.scrollToPositionWithOffset(position, 0);
        }

        @Override
        public void hideToolbar() {
            callback.hideToolbar();
        }

        @Override
        public void clearDecoration() {
            callback.clearDecoration();
        }

        @Override
        public void requestMore() {
            controllerComments.loadMoreComments();
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerCommentList.requestDisallowInterceptTouchEvent(disallow);
            swipeRefreshCommentList.requestDisallowInterceptTouchEvent(disallow);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
        }
    };
    AdapterLink.ViewHolderLink.Listener listenerLink = new LinksListenerBase(mListener.getEventListenerBase()) {

        @Override
        public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
        }

        @Override
        public void onDelete(Link link) {
        }

        @Override
        public void onReport(Link link) {
        }

        @Override
        public void onSave(Link link) {
        }

        @Override
        public void onMarkNsfw(Link link) {
        }
    };
    AdapterCommentList.ViewHolderComment.Listener listenerComment = new AdapterCommentList.ViewHolderComment.Listener() {

        @Override
        public void onToggleComment(Comment comment) {
            controllerComments.toggleComment(comment);
        }

        @Override
        public void onShowReplyEditor(Comment comment) {
        }

        @Override
        public void onEditComment(Comment comment, String text) {
        }

        @Override
        public void onSendComment(Comment comment, String text) {
        }

        @Override
        public void onMarkRead(Comment comment) {
        }

        @Override
        public void onLoadNestedComments(Comment comment) {
            controllerComments.loadNestedComments(comment);
        }

        @Override
        public void onJumpToParent(Comment comment) {
            controllerComments.jumpToParent(comment);
        }

        @Override
        public void onViewProfile(Comment comment) {
        }

        @Override
        public void onCopyText(Comment comment) {
        }

        @Override
        public void onDeleteComment(Comment comment) {
        }

        @Override
        public void onReport(Comment comment) {
            // TODO: Add comment text
            new AlertDialog.Builder(getContext()).setTitle(R.string.report_title).setSingleChoiceItems(Report.getDisplayReasons(getResources()), -1, (dialog, which) -> {
                reportSelected = Report.values()[which];
            }).setPositiveButton(R.string.ok, (dialog, which) -> {
                if (reportSelected == Report.OTHER) {
                    View viewDialog = LayoutInflater.from(getContext()).inflate(R.layout.dialog_text_input, null, false);
                    final EditText editText = (EditText) viewDialog.findViewById(R.id.edit_text);
                    editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(100) });
                    new AlertDialog.Builder(getContext()).setView(viewDialog).setTitle(R.string.item_report).setPositiveButton(R.string.ok, (dialog1, which1) -> {
                        mListener.getEventListenerBase().onReport(link, editText.getText().toString()).subscribe(new ObserverError<String>() {

                            @Override
                            public void onError(Throwable e) {
                                controllerComments.getEventHolder().getErrors().call(CommentsError.REPORT);
                            }
                        });
                    }).setNegativeButton(R.string.cancel, (dialog1, which1) -> {
                        dialog1.dismiss();
                    }).show();
                } else if (reportSelected != null) {
                    mListener.getEventListenerBase().onReport(link, reportSelected.getReason()).subscribe(new ObserverError<String>() {

                        @Override
                        public void onError(Throwable e) {
                            controllerComments.getEventHolder().getErrors().call(CommentsError.REPORT);
                        }
                    });
                }
            }).setNegativeButton(R.string.cancel, null).show();
        }

        @Override
        public void onVoteComment(Comment comment, AdapterCommentList.ViewHolderComment viewHolderComment, Likes vote) {
        }

        @Override
        public void onSave(Comment comment) {
        }
    };
    adapterCommentList = new AdapterCommentList(getActivity(), adapterListenerComment, listenerComment, listenerLink, youTubeListener, callbackYouTubeDestruction, getArguments().getBoolean(ARG_IS_GRID, false), getArguments().getString(ARG_FIRST_LINK_NAME), getArguments().getInt(ARG_COLOR_LINK, 0), getArguments().getBoolean(ARG_ACTIONS_EXPANDED, false));
    observer = new RecyclerView.AdapterDataObserver() {

        @Override
        public void onItemRangeChanged(int positionStart, int itemCount) {
            super.onItemRangeChanged(positionStart, itemCount);
            if (positionStart == 0) {
                callback.releaseYouTube();
            }
        }
    };
    adapterCommentList.registerAdapterDataObserver(observer);
    recyclerCommentList.setAdapter(adapterCommentList);
    layoutManagerLink = new LinearLayoutManagerWrapHeight(getActivity(), LinearLayoutManager.VERTICAL, false);
    layoutManagerLink.setOnSizeChangedListener((width, height, oldWidth, oldHeight) -> {
        if (postExpanded && targetExpandPostHeight == 0) {
            targetExpandPostHeight = height + heightExpandHandle;
            postExpanded = false;
            expandPost(true);
        }
    });
    AdapterListener adapterListenerLink = new AdapterListener() {

        @Override
        public void scrollAndCenter(int position, int height) {
            layoutManagerLink.scrollToPositionWithOffset(position, 0);
        }

        @Override
        public void hideToolbar() {
            callback.hideToolbar();
        }

        @Override
        public void clearDecoration() {
            callback.clearDecoration();
        }

        @Override
        public void requestMore() {
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerLink.requestDisallowInterceptTouchEvent(disallow);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
        }
    };
    adapterLink = new AdapterLinkHeader(getActivity(), controllerComments, adapterListenerLink, listenerLink, youTubeListener, callbackYouTubeDestruction, getArguments().getBoolean(ARG_IS_GRID, false), getArguments().getString(ARG_FIRST_LINK_NAME), getArguments().getInt(ARG_COLOR_LINK, 0), getArguments().getBoolean(ARG_ACTIONS_EXPANDED, false));
    final GestureDetectorCompat gestureDetectorExpand = new GestureDetectorCompat(getActivity(), new GestureDetector.SimpleOnGestureListener() {

        private float startY;

        private int startHeight;

        @Override
        public boolean onDown(MotionEvent e) {
            if (targetExpandPostHeight == 0) {
                targetExpandPostHeight = layoutManagerLink.getFirstChildHeight() + heightExpandHandle;
            }
            if (e.getY() > imageExpandIndicator.getY() && e.getY() < imageExpandIndicator.getY() + heightExpandHandle) {
                startY = e.getY();
                startHeight = targetExpandPostHeight;
            } else {
                startY = 0;
            }
            return super.onDown(e);
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (startY == 0) {
                return super.onScroll(e1, e2, distanceX, distanceY);
            }
            float distance = e2.getY() - startY;
            targetExpandPostHeight = (int) Math.min(startHeight + distance, layoutRoot.getHeight());
            layoutExpandPostInner.getLayoutParams().height = targetExpandPostHeight;
            layoutExpandPostInner.requestLayout();
            return super.onScroll(e1, e2, distanceX, distanceY);
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (startY == 0) {
                return super.onFling(e1, e2, velocityX, velocityY);
            }
            if (velocityY < -expandFlingThreshold) {
                startY = 0;
                expandPost(false);
                return true;
            } else if (velocityY > expandFlingThreshold) {
                startY = 0;
                targetExpandPostHeight = layoutRoot.getHeight() - heightExpandHandle;
                postExpanded = false;
                expandPost(true);
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    });
    heightExpandHandle = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 33, getResources().getDisplayMetrics());
    expandFlingThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, EXPAND_FLING_THRESHOLD, getResources().getDisplayMetrics());
    layoutExpandPostInner = (ViewGroup) layoutRoot.findViewById(R.id.layout_expand_post_inner);
    imageExpandIndicator = (ImageView) layoutRoot.findViewById(R.id.image_expand_indicator);
    imageExpandIndicator.setColorFilter(themer.getColorFilterIcon());
    layoutRoot.setDispatchTouchListener((v, event) -> gestureDetectorExpand.onTouchEvent(event));
    recyclerLink = (RecyclerView) layoutRoot.findViewById(R.id.recycler_link);
    recyclerLink.setLayoutManager(layoutManagerLink);
    recyclerLink.setItemAnimator(null);
    if (savedInstanceState != null) {
        String youtubeId = savedInstanceState.getString(ARG_YOUTUBE_ID, null);
        if (!TextUtils.isEmpty(youtubeId)) {
            callback.loadYouTubeVideo(youtubeId, savedInstanceState.getInt(ARG_YOUTUBE_TIME, 0));
        }
    }
    if (savedInstanceState != null && savedInstanceState.containsKey("Link")) {
        adapterLink.setAnimationFinished(true);
        adapterCommentList.setAnimationFinished(true);
        controllerComments.setLinkFromCache((Link) savedInstanceState.get("Link"));
    } else if (link != null) {
        controllerComments.setLink(link);
        link = null;
    }
    adapterCommentList.setData(controllerComments.getData());
    if (animationFinished) {
        setAnimationFinished(true);
    }
    return layoutRoot;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Context(android.content.Context) GestureDetector(android.view.GestureDetector) CallbackYouTubeDestruction(com.winsonchiu.reader.utils.CallbackYouTubeDestruction) Bundle(android.os.Bundle) LinksListenerBase(com.winsonchiu.reader.links.LinksListenerBase) CustomApplication(com.winsonchiu.reader.CustomApplication) AdapterLink(com.winsonchiu.reader.links.AdapterLink) UtilsRx(com.winsonchiu.reader.utils.UtilsRx) ImageView(android.widget.ImageView) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) UtilsList(com.winsonchiu.reader.utils.UtilsList) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Animator(android.animation.Animator) CustomFrameLayout(com.winsonchiu.reader.views.CustomFrameLayout) UtilsAnimation(com.winsonchiu.reader.utils.UtilsAnimation) Likes(com.winsonchiu.reader.data.reddit.Likes) MotionEvent(android.view.MotionEvent) Link(com.winsonchiu.reader.data.reddit.Link) View(android.view.View) Comment(com.winsonchiu.reader.data.reddit.Comment) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RectF(android.graphics.RectF) LinearLayoutManagerWrapHeight(com.winsonchiu.reader.utils.LinearLayoutManagerWrapHeight) LayoutInflater(android.view.LayoutInflater) YouTubeListener(com.winsonchiu.reader.utils.YouTubeListener) Sort(com.winsonchiu.reader.data.reddit.Sort) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ComponentActivity(com.winsonchiu.reader.dagger.components.ComponentActivity) ViewGroup(android.view.ViewGroup) R(com.winsonchiu.reader.R) RecyclerView(android.support.v7.widget.RecyclerView) FragmentBase(com.winsonchiu.reader.FragmentBase) AlertDialog(android.support.v7.app.AlertDialog) TypedValue(android.util.TypedValue) ActivityMain(com.winsonchiu.reader.ActivityMain) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) FragmentListenerBase(com.winsonchiu.reader.FragmentListenerBase) RxAdapterEvent(com.winsonchiu.reader.adapter.RxAdapterEvent) Nullable(android.support.annotation.Nullable) InputFilter(android.text.InputFilter) Activity(android.app.Activity) Subscription(rx.Subscription) EditText(android.widget.EditText) ObserverError(com.winsonchiu.reader.rx.ObserverError) ValueAnimator(android.animation.ValueAnimator) Report(com.winsonchiu.reader.data.reddit.Report) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) YouTubeListener(com.winsonchiu.reader.utils.YouTubeListener) CallbackYouTubeDestruction(com.winsonchiu.reader.utils.CallbackYouTubeDestruction) LinearLayoutManagerWrapHeight(com.winsonchiu.reader.utils.LinearLayoutManagerWrapHeight) GestureDetector(android.view.GestureDetector) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EditText(android.widget.EditText) Comment(com.winsonchiu.reader.data.reddit.Comment) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) InputFilter(android.text.InputFilter) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent) LinksListenerBase(com.winsonchiu.reader.links.LinksListenerBase) ObserverError(com.winsonchiu.reader.rx.ObserverError) RecyclerView(android.support.v7.widget.RecyclerView) Likes(com.winsonchiu.reader.data.reddit.Likes) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Link(com.winsonchiu.reader.data.reddit.Link)

Example 25 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project Reader by TheKeeperOfPie.

the class FragmentComments method onCreateView.

@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    layoutRoot = (CustomFrameLayout) inflater.inflate(R.layout.fragment_comments, container, false);
    ButterKnife.bind(this, layoutRoot);
    youTubeListener = new YouTubeListener() {

        @Override
        public void loadYouTubeVideo(Link link, final String id, final int timeInMillis) {
            loadYoutubeVideo(id, timeInMillis);
        }

        @Override
        public boolean hideYouTube() {
            if (layoutYouTube.isShown()) {
                if (youTubePlayer != null) {
                    youTubePlayer.pause();
                }
                toggleYouTubeVisibility(View.GONE);
                return false;
            }
            return true;
        }
    };
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setBackgroundColor(themer.getColorPrimary());
    setUpToolbar();
    behaviorFloatingActionButton = new ScrollAwareFloatingActionButtonBehavior(getActivity(), null, new ScrollAwareFloatingActionButtonBehavior.OnVisibilityChangeListener() {

        @Override
        public void onStartHideFromScroll() {
            hideLayoutActions(0);
        }

        @Override
        public void onEndHideFromScroll() {
            buttonExpandActions.setImageResource(R.drawable.ic_unfold_more_white_24dp);
            buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
        }
    });
    buttonExpandActions.setOnClickListener(v -> toggleLayoutActions());
    ((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setBehavior(behaviorFloatingActionButton);
    buttonJumpTop.setOnClickListener(v -> fragmentCurrent.scrollToPositionWithOffset(0, 0));
    buttonJumpTop.setOnLongClickListener(v -> {
        Toast.makeText(getActivity(), getString(R.string.content_description_button_jump_top), Toast.LENGTH_SHORT).show();
        return false;
    });
    buttonCommentPrevious.setOnClickListener(v -> fragmentCurrent.previousComment());
    buttonCommentPrevious.setOnLongClickListener(v -> {
        Toast.makeText(getActivity(), getString(R.string.content_description_button_comment_previous), Toast.LENGTH_SHORT).show();
        return false;
    });
    buttonCommentNext.setOnClickListener(v -> fragmentCurrent.nextComment());
    buttonCommentNext.setOnLongClickListener(v -> {
        Toast.makeText(getActivity(), getString(R.string.content_description_button_comment_next), Toast.LENGTH_SHORT).show();
        return false;
    });
    // Margin is included within shadow margin on pre-Lollipop, so remove all regular margin
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setMargins(0, 0, 0, 0);
        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
        LinearLayout.LayoutParams layoutParamsJumpTop = (LinearLayout.LayoutParams) buttonJumpTop.getLayoutParams();
        layoutParamsJumpTop.setMargins(0, 0, 0, 0);
        buttonJumpTop.setLayoutParams(layoutParamsJumpTop);
        LinearLayout.LayoutParams layoutParamsPrevious = (LinearLayout.LayoutParams) buttonCommentPrevious.getLayoutParams();
        layoutParamsPrevious.setMargins(0, 0, 0, 0);
        buttonCommentPrevious.setLayoutParams(layoutParamsPrevious);
        LinearLayout.LayoutParams layoutParamsNext = (LinearLayout.LayoutParams) buttonCommentNext.getLayoutParams();
        layoutParamsNext.setMargins(0, 0, 0, 0);
        buttonCommentNext.setLayoutParams(layoutParamsNext);
        ViewGroup.MarginLayoutParams layoutParamsActions = (ViewGroup.MarginLayoutParams) layoutActions.getLayoutParams();
        layoutParamsActions.setMarginStart(margin);
        layoutParamsActions.setMarginEnd(margin);
        layoutActions.setLayoutParams(layoutParamsActions);
    }
    buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
    buttonJumpTop.setColorFilter(themer.getColorFilterAccent());
    buttonCommentPrevious.setColorFilter(themer.getColorFilterAccent());
    buttonCommentNext.setColorFilter(themer.getColorFilterAccent());
    isStartOnLeft = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
    final float screenWidth = getResources().getDisplayMetrics().widthPixels;
    swipeEndDistance = screenWidth * 0.4f;
    gestureDetector = new GestureDetectorCompat(getActivity(), new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (isFinished) {
                return true;
            }
            swipeDifferenceX = e2.getX() - e1.getX();
            if (isStartOnLeft) {
                if (e1.getX() > screenWidth * 0.2f || swipeDifferenceX < 0) {
                    return super.onScroll(e1, e2, distanceX, distanceY);
                }
            } else {
                if (e1.getX() < screenWidth * 0.8f || swipeDifferenceX > 0) {
                    return super.onScroll(e1, e2, distanceX, distanceY);
                }
            }
            if (!hasSwipedEnd) {
                FragmentBase fragment = (FragmentBase) getFragmentManager().findFragmentByTag(fragmentParentTag);
                if (fragment != null) {
                    fragment.setVisibilityOfThing(View.VISIBLE, linkTop);
                    fragment.onHiddenChanged(false);
                }
                hasSwipedEnd = true;
            }
            float ratio = 1f - swipeDifferenceX / screenWidth;
            buttonExpandActions.setAlpha(ratio);
            buttonExpandActions.setScaleX(ratio);
            buttonExpandActions.setScaleY(ratio);
            layoutAppBar.setTranslationX(swipeDifferenceX);
            layoutComments.setTranslationX(swipeDifferenceX);
            viewBackground.setTranslationX(swipeDifferenceX);
            return super.onScroll(e1, e2, distanceX, distanceY);
        }
    });
    if (preferences.getBoolean(AppSettings.SWIPE_EXIT_COMMENTS, true)) {
        layoutRoot.setDispatchTouchListener(this);
    }
    if (savedInstanceState == null) {
        if (getArguments().getInt(ARG_YOUTUBE_TIME, -1) >= 0) {
            loadYoutubeVideo(getArguments().getString(ARG_YOUTUBE_ID), getArguments().getInt(ARG_YOUTUBE_TIME));
        }
    } else {
        String youtubeId = savedInstanceState.getString(ARG_YOUTUBE_ID, null);
        if (!TextUtils.isEmpty(youtubeId)) {
            loadYoutubeVideo(youtubeId, savedInstanceState.getInt(ARG_YOUTUBE_TIME, 0));
        }
    }
    fragmentCallback = new FragmentCommentsInner.Callback() {

        @Override
        public void loadYouTubeVideo(String id, int timeInMillis) {
            FragmentComments.this.loadYoutubeVideo(id, timeInMillis);
        }

        @Override
        public void releaseYouTube() {
            FragmentComments.this.releaseYouTube();
        }

        @Override
        public void setPostExpanded(boolean expanded) {
            FragmentComments.this.setPostExpanded(expanded);
        }

        @Override
        public void setIsCommentThread(boolean isCommentThread) {
            FragmentComments.this.setIsCommentThread(isCommentThread);
        }

        @Override
        public void setSort(Sort sort) {
            FragmentComments.this.setSort(sort);
        }

        @Override
        public void setTitle(CharSequence title) {
            FragmentComments.this.setTitle(title);
        }

        @Override
        public void clearDecoration() {
            behaviorFloatingActionButton.animateOut(buttonExpandActions);
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void hideToolbar() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public int getAppBarHeight() {
            return layoutAppBar.getHeight();
        }

        @Override
        public boolean isCurrentFragment(FragmentCommentsInner fragmentCommentsInner) {
            return positionCurrent == fragmentCommentsInner.getPosition();
        }

        @Override
        public void loadYouTubeVideo(Link link, String id, int timeInMillis) {
            youTubeListener.loadYouTubeVideo(link, id, timeInMillis);
        }

        @Override
        public boolean hideYouTube() {
            return youTubeListener.hideYouTube();
        }
    };
    setUpPager();
    if (!getArguments().getBoolean(ARG_INITIALIZED, false)) {
        viewBackground.setVisibility(View.INVISIBLE);
        pagerComments.setVisibility(View.INVISIBLE);
        layoutAppBar.setVisibility(View.GONE);
        layoutComments.postOnAnimation(() -> animateEnter(layoutRoot));
    } else {
        setAnimationFinished(true);
    }
    return layoutRoot;
}
Also used : ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) FragmentBase(com.winsonchiu.reader.FragmentBase) Sort(com.winsonchiu.reader.data.reddit.Sort) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) AppBarLayout(android.support.design.widget.AppBarLayout) ViewGroup(android.view.ViewGroup) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) YouTubeListener(com.winsonchiu.reader.utils.YouTubeListener) MotionEvent(android.view.MotionEvent) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Link(com.winsonchiu.reader.data.reddit.Link) LinearLayout(android.widget.LinearLayout)

Aggregations

GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)33 MotionEvent (android.view.MotionEvent)12 ScaleGestureDetector (android.view.ScaleGestureDetector)8 Paint (android.graphics.Paint)6 Intent (android.content.Intent)5 View (android.view.View)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 GestureDetector (android.view.GestureDetector)4 LayoutInflater (android.view.LayoutInflater)4 OverScroller (android.widget.OverScroller)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3 TextPaint (android.text.TextPaint)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 Link (com.winsonchiu.reader.data.reddit.Link)3 Sort (com.winsonchiu.reader.data.reddit.Sort)3 AdapterLink (com.winsonchiu.reader.links.AdapterLink)3 Activity (android.app.Activity)2