pedrovgs / DraggablePanel

Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.
Apache License 2.0
2.99k stars 606 forks source link

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

Open rencsaridogan opened 8 years ago

rencsaridogan commented 8 years ago

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 commented 8 years ago

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

rencsaridogan commented 8 years ago

@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 commented 8 years ago

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 :)