Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Support for orientation, useful three new listeners and improvements about compatibility with ExoPlayer #86

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

rencsaridogan
Copy link

Hello,

I've been using DraggablePanel with ExoPlayer but there were problems since I was using SENSOR when DraggablePanel was active, and I was using PORTRAIT on minimized. I needed to check SecondView Alpha and I was in need of Timers to make the isMaximized, isMinimized better. So I added the listeners below and improved when they are triggered:

onTouchListener
clickedToMaximized
clickedToMinimize
smoothSlide

The improvements also helped me to collect true data about how much DraggablePanel is used because it was throwing events way more since onMaximized and onMinimezed were called more than once in some cases.

You have to initialize timers when you are initializing the DraggableView with the code below:

draggable_view.initializeTimers();

My code for the Listener looks like below:

draggable_view.setDraggableListener(new DraggableListener() {
            @Override
            public void onMaximized() {
                if (!draggable_view.isClickedMinimize()) {
                    if (videoPlayer != null && prerollShown)
                        videoPlayer.showPrerollLayout();
                    if (draggable_view.isMinimized())
                        functions.sendEventAnalytics("panel", "maximized");
                    videoPlayer.setVisibility(View.VISIBLE);
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
                } else {
                    draggable_view.setClickedtoMinimize();
                }
            }

            @Override
            public void onMinimized() {
                if (!draggable_view.isClickedMaximize()) {
                    if (videoPlayer != null && prerollShown)
                        videoPlayer.hidePrerollLayout();
                    functions.sendEventAnalytics("panel", "minimized");
                    functions.colorComponentsNormal(MainActivity.this);
                    if (draggable_view.getSecondViewAlpha() < 0.15) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                videoPlayer.setVisibility(View.VISIBLE);
                                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                            }
                        }, 300);
                    }
                } else {
                    draggable_view.setClickedtoMaximize();
                }
            }

            @Override
            public void onClosedToLeft() {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                functions.sendEventAnalytics("panel", "closed_to_left");
                draggableViewGone = true;
                if (videoPlayer != null)
                    if (videoPlayer.isPlaying())
                        videoPlayer.pause();
            }

            @Override
            public void onClosedToRight() {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                functions.sendEventAnalytics("panel", "closed_to_right");
                draggableViewGone = true;
                if (videoPlayer != null)
                    if (videoPlayer.isPlaying())
                        videoPlayer.pause();
            }

            @Override
            public void onTouchListener() {
                draggable_view.setSeekBarStatus(videoPlayer.areContolsVisible());
                if (draggable_view.getSecondViewAlpha() < 0.99 && !draggable_view.isMinimized()) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else if (draggable_view.isMinimized() && draggable_view.getSecondViewAlpha() > 0.1) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            }

            @Override
            public void clickedToMinimize() {
            }

            @Override
            public void smoothSlide() {
            }

            @Override
            public void clickedToMaximize() {
            }

        });

Best regards,
Renç Sarıdoğan.

@pedrovgs
Copy link
Owner

Hi @rencsaridogan, thanks for your PR. I'm going to review it right now.

I've noticed that your PR is breaking the checkstyle rules I've configured. Can you review the code and format it to match with the checkstyle? If you want to do it automatically you can use this project to configure your IDE: https://github.com/square/java-code-styles

* Called when the view is being dragged to either minimize or maximize
*/

void smoothSlide();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change the naming of the methods you've added to match with the naming of the project. If you review the methods already implemented all start using on as prefix. Based on that, we should rename these last three methods to:

void onTouch()

void onClickedToMaximize()

void onClickedToMinimize();

void onSmoothSlide();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it.

@rencsaridogan rencsaridogan changed the title CountDownTimer and SecondView Alpha Checker for better Performance added Support for orientation, useful three new listeners and improvements about compatibility with ExoPlayer Feb 14, 2016
@rencsaridogan
Copy link
Author

@pedrovgs I've implemented a change for anyone to be able to choose any rotation they like for the panel to work (Default is all), implemented the changes and applied the improvements we've discussed. ExoPlayer example is not added yet, working on that to prepare the best example to work on.

After the review you can merge this without waiting the example version. After the fixes and improvements it shouldn't effect the current version anyhow. Instead it should be adding the new features.

Best regards,
Renç Sarıdoğan.

@pedrovgs
Copy link
Owner

Sorry for the delay @rencsaridogan, I've been out for some time. I think I can wait for the ExoPlayer example before to merge this PR. Please, if you have time add the example and the documentation needed to show how to use the new feature :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants