From f9b7b515f9e79201bf345674ecbf2f77ca841a87 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 10:30:49 -0300 Subject: [PATCH 01/11] huge implementations --- draggablepanel/build.gradle | 2 +- draggablepanel/res/values/attrs.xml | 20 +- .../github/pedrovgs/DraggableListener.java | 8 + .../com/github/pedrovgs/DraggablePanel.java | 123 ++++++-- .../com/github/pedrovgs/DraggableView.java | 147 ++++++--- .../pedrovgs/DraggableViewCallback.java | 31 +- .../github/pedrovgs/shadow/ShadowView.java | 282 ++++++++++++++++++ .../com/github/pedrovgs/shadow/ZDepth.java | 90 ++++++ .../github/pedrovgs/shadow/ZDepthParam.java | 32 ++ .../github/pedrovgs/shadow/layout/Shadow.java | 9 + .../pedrovgs/shadow/layout/ShadowRect.java | 53 ++++ .../pedrovgs/shadow/util/DisplayUtils.java | 10 + .../transformer/ResizeTransformer.java | 43 ++- .../transformer/ScaleTransformer.java | 32 +- .../pedrovgs/transformer/Transformer.java | 57 +++- .../transformer/TransformerFactory.java | 4 +- .../res/layout/activity_tv_shows_sample.xml | 6 +- sample/res/layout/activity_video_sample.xml | 2 +- sample/res/layout/activity_youtube_sample.xml | 10 +- .../sample/activity/TvShowsActivity.java | 5 + .../sample/activity/VideoSampleActivity.java | 4 + .../activity/YoutubeSampleActivity.java | 4 + 22 files changed, 876 insertions(+), 98 deletions(-) create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java diff --git a/draggablepanel/build.gradle b/draggablepanel/build.gradle index 149fbde..0569058 100644 --- a/draggablepanel/build.gradle +++ b/draggablepanel/build.gradle @@ -30,7 +30,7 @@ android { } } -apply from: 'https://raw.github.com/jpardogo/gradle-mvn-push/master/gradle-mvn-push.gradle' +//apply from: 'https://raw.github.com/jpardogo/gradle-mvn-push/master/gradle-mvn-push.gradle' task checkstyle(type: Checkstyle) { diff --git a/draggablepanel/res/values/attrs.xml b/draggablepanel/res/values/attrs.xml index 7521a99..0300dbe 100644 --- a/draggablepanel/res/values/attrs.xml +++ b/draggablepanel/res/values/attrs.xml @@ -4,12 +4,16 @@ - + + + + + @@ -18,12 +22,24 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableListener.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableListener.java index 1747659..4772fc3 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableListener.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableListener.java @@ -42,4 +42,12 @@ public interface DraggableListener { * Called when the view is closed to the right. */ void onClosedToRight(); + + /** + * Called when the view is sliding. + * + * @param scroll return the scroll value, 0.0 is minimized and 1.0 is maximized. + */ + void onTopViewSlide(float scroll); + } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index f1f0556..d783bd7 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -21,6 +21,7 @@ import android.support.v4.app.FragmentManager; import android.util.AttributeSet; import android.widget.FrameLayout; +import com.github.pedrovgs.transformer.Transformer; /** * Custom view created to handle DraggableView using fragments. With this custom view the client @@ -50,14 +51,18 @@ public class DraggablePanel extends FrameLayout { private Fragment topFragment; private Fragment bottomFragment; private int topFragmentHeight; - private int topFragmentMarginRight; + private int topFragmentMarginTop; private int topFragmentMarginBottom; + private int topFragmentMarginLeft; + private int topFragmentMarginRight; private float xScaleFactor; private float yScaleFactor; private boolean enableHorizontalAlphaEffect; private boolean enableClickToMaximize; private boolean enableClickToMinimize; private boolean enableTouchListener; + private float dragLimit; + private int dragViewPosition; public DraggablePanel(Context context) { super(context); @@ -145,6 +150,24 @@ public void setClickToMinimizeEnabled(boolean enableClickToMinimize) { this.enableClickToMinimize = enableClickToMinimize; } + /** + * Enable or disable touch listener on drag view + * + * @param enableTouchListener to enable or disable the touch. + */ + public void setEnableTouchListener(boolean enableTouchListener) { + this.enableTouchListener = enableTouchListener; + } + + /** + * Configure the drag view limit. + * + * @param dragLimit in pixels + */ + public void setDragLimit(float dragLimit) { + this.dragLimit = dragLimit; + } + /** * * Slide the view based on scroll of the nav drawer. @@ -161,6 +184,21 @@ public void slideHorizontally(float slideOffset, float drawerPosition, int width draggableView.slideHorizontally(slideOffset, drawerPosition, width); } + /** + * Configure the position of the drag view then this is minimized, can be left, center or right. + */ + public void setDragViewPosition(int dragViewPosition) { + this.dragViewPosition = dragViewPosition; + } + + /** + * Configure the horizontal scale factor applied when the top fragment is dragged to the bottom + * of the custom view. + */ + public void setTopFragmentHeight(int topFragmentHeight) { + this.topFragmentHeight = topFragmentHeight; + } + /** * Configure the horizontal scale factor applied when the top fragment is dragged to the bottom * of the custom view. @@ -178,12 +216,12 @@ public void setYScaleFactor(float yScaleFactor) { } /** - * Configure the top Fragment margin right applied when the view has been minimized. + * Configure the top Fragment margin top applied when the view has been minimized. * - * @param topFragmentMarginRight in pixels. + * @param topFragmentMarginTop in pixels. */ - public void setTopFragmentMarginRight(int topFragmentMarginRight) { - this.topFragmentMarginRight = topFragmentMarginRight; + public void setTopFragmentMarginTop(int topFragmentMarginTop) { + this.topFragmentMarginTop = topFragmentMarginTop; } /** @@ -195,6 +233,24 @@ public void setTopFragmentMarginBottom(int topFragmentMarginBottom) { this.topFragmentMarginBottom = topFragmentMarginBottom; } + /** + * Configure the top Fragment margin left applied when the view has been minimized. + * + * @param topFragmentMarginLeft in pixels. + */ + public void setTopFragmentMarginLeft(int topFragmentMarginLeft) { + this.topFragmentMarginLeft = topFragmentMarginLeft; + } + + /** + * Configure the top Fragment margin right applied when the view has been minimized. + * + * @param topFragmentMarginRight in pixels. + */ + public void setTopFragmentMarginRight(int topFragmentMarginRight) { + this.topFragmentMarginRight = topFragmentMarginRight; + } + /** * Configure the DraggableListener that is going to be invoked when the view be minimized, * maximized, closed to the left or right. @@ -260,14 +316,18 @@ public void initializeView() { draggableView.attachTopFragment(topFragment); draggableView.setXTopViewScaleFactor(xScaleFactor); draggableView.setYTopViewScaleFactor(yScaleFactor); - draggableView.setTopViewMarginRight(topFragmentMarginRight); + draggableView.setTopViewMarginTop(topFragmentMarginTop); + draggableView.setTopViewMarginLeft(topFragmentMarginLeft); draggableView.setTopViewMarginBottom(topFragmentMarginBottom); + draggableView.setTopViewMarginRight(topFragmentMarginRight); draggableView.attachBottomFragment(bottomFragment); draggableView.setDraggableListener(draggableListener); draggableView.setHorizontalAlphaEffectEnabled(enableHorizontalAlphaEffect); draggableView.setClickToMaximizeEnabled(enableClickToMaximize); draggableView.setClickToMinimizeEnabled(enableClickToMinimize); draggableView.setTouchEnabled(enableTouchListener); + draggableView.setDragLimit(dragLimit); + draggableView.setDragViewPosition(dragViewPosition); } /** @@ -313,31 +373,32 @@ public boolean isClosedAtLeft() { */ private void initializeAttrs(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_panel); - this.topFragmentHeight = - attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_height, - DEFAULT_TOP_FRAGMENT_HEIGHT); - this.xScaleFactor = - attributes.getFloat(R.styleable.draggable_panel_x_scale_factor, DEFAULT_SCALE_FACTOR); - this.yScaleFactor = - attributes.getFloat(R.styleable.draggable_panel_y_scale_factor, DEFAULT_SCALE_FACTOR); - this.topFragmentMarginRight = - attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_right, - DEFAULT_TOP_FRAGMENT_MARGIN); - this.topFragmentMarginBottom = - attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_bottom, - DEFAULT_TOP_FRAGMENT_MARGIN); - this.enableHorizontalAlphaEffect = - attributes.getBoolean(R.styleable.draggable_panel_enable_horizontal_alpha_effect, - DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT); - this.enableClickToMaximize = - attributes.getBoolean(R.styleable.draggable_panel_enable_click_to_maximize_panel, - DEFAULT_ENABLE_CLICK_TO_MAXIMIZE); - this.enableClickToMinimize = - attributes.getBoolean(R.styleable.draggable_panel_enable_click_to_minimize_panel, - DEFAULT_ENABLE_CLICK_TO_MINIMIZE); - this.enableTouchListener = - attributes.getBoolean(R.styleable.draggable_panel_enable_touch_listener_panel, - DEFAULT_ENABLE_TOUCH_LISTENER); + setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position).getInt(R.styleable.top_view_position_position, + Transformer.RIGHT)); + setTopFragmentHeight(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_height, + DEFAULT_TOP_FRAGMENT_HEIGHT)); + setXScaleFactor(attributes.getFloat(R.styleable.draggable_panel_x_scale_factor, + DEFAULT_SCALE_FACTOR)); + setYScaleFactor(attributes.getFloat(R.styleable.draggable_panel_y_scale_factor, + DEFAULT_SCALE_FACTOR)); + setTopFragmentMarginTop(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_top, + DEFAULT_TOP_FRAGMENT_MARGIN)); + setTopFragmentMarginBottom(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_bottom, + DEFAULT_TOP_FRAGMENT_MARGIN)); + setTopFragmentMarginLeft(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_left, + DEFAULT_TOP_FRAGMENT_MARGIN)); + setTopFragmentMarginRight(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_right, + DEFAULT_TOP_FRAGMENT_MARGIN)); + setEnableHorizontalAlphaEffect(attributes.getBoolean(R.styleable.draggable_panel_enable_horizontal_alpha_effect, + DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT)); + setClickToMaximizeEnabled(attributes.getBoolean(R.styleable.draggable_panel_enable_click_to_maximize_panel, + DEFAULT_ENABLE_CLICK_TO_MAXIMIZE)); + setClickToMinimizeEnabled(attributes.getBoolean(R.styleable.draggable_panel_enable_click_to_minimize_panel, + DEFAULT_ENABLE_CLICK_TO_MINIMIZE)); + setEnableTouchListener(attributes.getBoolean(R.styleable.draggable_panel_enable_touch_listener_panel, + DEFAULT_ENABLE_TOUCH_LISTENER)); + setDragLimit(attributes.getFloat(R.styleable.draggable_panel_drag_limit_panel, + Transformer.DEFAULT_DRAG_LIMIT)); attributes.recycle(); } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index 79fbbda..836de42 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -41,6 +41,8 @@ public class DraggableView extends RelativeLayout { private static final int DEFAULT_SCALE_FACTOR = 2; private static final int DEFAULT_TOP_VIEW_MARGIN = 30; private static final int DEFAULT_TOP_VIEW_HEIGHT = -1; + private static final int MAX_ALPHA = 1; + private static final int MIN_ALPHA = 0; private static final float SLIDE_TOP = 0f; private static final float SLIDE_BOTTOM = 1f; private static final float MIN_SLIDE_OFFSET = 0.1f; @@ -48,6 +50,7 @@ public class DraggableView extends RelativeLayout { private static final boolean DEFAULT_ENABLE_CLICK_TO_MAXIMIZE = false; private static final boolean DEFAULT_ENABLE_CLICK_TO_MINIMIZE = false; private static final boolean DEFAULT_ENABLE_TOUCH_LISTENER = true; + private static final int DEFAULT_POSITION = 0; private static final int MIN_SLIDING_DISTANCE_ON_CLICK = 10; private static final int ONE_HUNDRED = 100; private static final float SENSITIVITY = 1f; @@ -58,6 +61,7 @@ public class DraggableView extends RelativeLayout { private View dragView; private View secondView; private TypedArray attributes; + private TypedArray attributePosition; private FragmentManager fragmentManager; private ViewDragHelper viewDragHelper; @@ -68,6 +72,7 @@ public class DraggableView extends RelativeLayout { private boolean enableClickToMaximize; private boolean enableClickToMinimize; private boolean touchEnabled; + private int position; private DraggableListener listener; @@ -175,20 +180,47 @@ public void setYTopViewScaleFactor(float yScaleFactor) { transformer.setYScaleFactor(yScaleFactor); } + /** + * Configure the dragView margin left applied when the dragView is minimized. + * + * @param topViewMarginLeft in pixels. + */ + public void setTopViewMarginLeft(int topViewMarginLeft) { + transformer.setMarginLeft(topViewMarginLeft); + } + /** * Configure the dragged view margin right applied when the dragged view is minimized. * - * @param topFragmentMarginRight in pixels. + * @param topViewMarginRight in pixels. */ - public void setTopViewMarginRight(int topFragmentMarginRight) { - transformer.setMarginRight(topFragmentMarginRight); + public void setTopViewMarginRight(int topViewMarginRight) { + transformer.setMarginRight(topViewMarginRight); + } + + /** + * Configure the dragView margin top applied when the dragView is minimized. + * + * @param topViewMarginTop in pixels. + */ + public void setTopViewMarginTop(int topViewMarginTop) { + transformer.setMarginTop(topViewMarginTop); } /** * Configure the dragView margin bottom applied when the dragView is minimized. + * + * @param topViewMarginBottom in pixels. + */ + public void setTopViewMarginBottom(int topViewMarginBottom) { + transformer.setMarginBottom(topViewMarginBottom); + } + + /** + * Configure the position of the drag view then this is minimized, can be left, center or right. */ - public void setTopViewMarginBottom(int topFragmentMarginBottom) { - transformer.setMarginBottom(topFragmentMarginBottom); + public void setDragViewPosition(int dragViewPosition) { + transformer.setViewPosition(dragViewPosition); } /** @@ -200,6 +232,15 @@ public void setTopViewHeight(int topFragmentHeight) { transformer.setViewHeight(topFragmentHeight); } + /** + * Configure the drag view limit. + * + * @param dragLimit, between 0.0 and 1.0 + */ + public void setDragLimit(float dragLimit) { + transformer.setDragLimit(dragLimit); + } + /** * Configure the disabling of the alpha effect applied when the dragView is dragged horizontally. */ @@ -254,7 +295,7 @@ public void minimize() { */ public void closeToRight() { if (viewDragHelper.smoothSlideViewTo(dragView, transformer.getOriginalWidth(), - getHeight() - transformer.getMinHeightPlusMargin())) { + getHeight() - transformer.getMinHeightPlusVerticalSides())) { ViewCompat.postInvalidateOnAnimation(this); notifyCloseToRightListener(); } @@ -265,7 +306,7 @@ public void closeToRight() { */ public void closeToLeft() { if (viewDragHelper.smoothSlideViewTo(dragView, -transformer.getOriginalWidth(), - getHeight() - transformer.getMinHeightPlusMargin())) { + getHeight() - transformer.getMinHeightPlusVerticalSides())) { ViewCompat.postInvalidateOnAnimation(this); notifyCloseToLeftListener(); } @@ -403,9 +444,9 @@ private MotionEvent cloneMotionEventWithAction(MotionEvent event, int action) { * Override method to configure the dragged view and secondView layout properly. */ @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - if (isInEditMode()) + if (isInEditMode()) { super.onLayout(changed, left, top, right, bottom); - else if (isDragViewAtTop()) { + } else if (isDragViewAtTop()) { dragView.layout(left, top, right, transformer.getOriginalHeight()); secondView.layout(left, transformer.getOriginalHeight(), right, bottom); ViewHelper.setY(dragView, top); @@ -493,7 +534,7 @@ void changeDragViewScale() { void changeBackgroundAlpha() { Drawable background = getBackground(); if (background != null) { - int newAlpha = (int) (ONE_HUNDRED * (1 - getVerticalDragOffset())); + int newAlpha = (int) (ONE_HUNDRED * (MAX_ALPHA - getVerticalDragOffset())); background.setAlpha(newAlpha); } } @@ -502,7 +543,7 @@ void changeBackgroundAlpha() { * Modify the second view alpha based on dragged view vertical position. */ void changeSecondViewAlpha() { - ViewHelper.setAlpha(secondView, 1 - getVerticalDragOffset()); + ViewHelper.setAlpha(secondView, MAX_ALPHA - getVerticalDragOffset()); } /** @@ -511,9 +552,9 @@ void changeSecondViewAlpha() { */ void changeDragViewViewAlpha() { if (enableHorizontalAlphaEffect) { - float alpha = 1 - getHorizontalDragOffset(); - if (alpha == 0) { - alpha = 1; + float alpha = MAX_ALPHA - getHorizontalDragOffset(); + if (alpha == MIN_ALPHA) { + alpha = MAX_ALPHA; } ViewHelper.setAlpha(dragView, alpha); } @@ -523,8 +564,8 @@ void changeDragViewViewAlpha() { * Restore view alpha to 1 */ void restoreAlpha() { - if (enableHorizontalAlphaEffect && ViewHelper.getAlpha(dragView) < 1) { - ViewHelper.setAlpha(dragView, 1); + if (enableHorizontalAlphaEffect && ViewHelper.getAlpha(dragView) < MAX_ALPHA) { + ViewHelper.setAlpha(dragView, MAX_ALPHA); } } @@ -564,6 +605,15 @@ boolean isDragViewAtTop() { return transformer.isViewAtTop(); } + /** + * Check if dragged view is at the left of the custom view. + * + * @return true if dragged view left position is equals to custom view width. + */ + boolean isDragViewAtLeft() { + return transformer.isViewAtLeft(); + } + /** * Check if dragged view is at the right of the custom view. * @@ -617,7 +667,7 @@ private void addFragmentToView(final int viewId, final Fragment fragment) { * Initialize the viewDragHelper. */ private void initializeViewDragHelper() { - viewDragHelper = ViewDragHelper.create(this, SENSITIVITY, new DraggableViewCallback(this, dragView)); + viewDragHelper = ViewDragHelper.create(this, SENSITIVITY, new DraggableViewCallback(this, dragView, listener)); } /** @@ -628,20 +678,25 @@ private void initializeTransformer(TypedArray attributes) { attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE); TransformerFactory transformerFactory = new TransformerFactory(); transformer = transformerFactory.getTransformer(topViewResize, dragView, this); - transformer.setViewHeight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height, + setDragViewPosition(attributePosition.getInt(R.styleable.top_view_position_position, + Transformer.RIGHT)); + setTopViewHeight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height, DEFAULT_TOP_VIEW_HEIGHT)); - transformer.setXScaleFactor( - attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, - DEFAULT_SCALE_FACTOR)); - transformer.setYScaleFactor( - attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, - DEFAULT_SCALE_FACTOR)); - transformer.setMarginRight( - attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right, + setXTopViewScaleFactor(attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, + DEFAULT_SCALE_FACTOR)); + setYTopViewScaleFactor(attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, + DEFAULT_SCALE_FACTOR)); + setTopViewMarginTop(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_top, + DEFAULT_TOP_VIEW_MARGIN)); + setTopViewMarginBottom(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom, DEFAULT_TOP_VIEW_MARGIN)); - transformer.setMarginBottom( - attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom, + setTopViewMarginLeft(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_left, + DEFAULT_TOP_VIEW_MARGIN)); + setTopViewMarginRight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right, DEFAULT_TOP_VIEW_MARGIN)); + setDragLimit(attributes.getFloat(R.styleable.draggable_view_drag_limit_view, + Transformer.DEFAULT_DRAG_LIMIT)); + attributes.recycle(); } /** @@ -651,15 +706,13 @@ private void initializeTransformer(TypedArray attributes) { */ private void initializeAttributes(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_view); - this.enableHorizontalAlphaEffect = - attributes.getBoolean(R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect, - DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT); - this.enableClickToMaximize = - attributes.getBoolean(R.styleable.draggable_view_enable_click_to_maximize_view, - DEFAULT_ENABLE_CLICK_TO_MAXIMIZE); - this.enableClickToMinimize = - attributes.getBoolean(R.styleable.draggable_view_enable_click_to_minimize_view, - DEFAULT_ENABLE_CLICK_TO_MINIMIZE); + attributePosition = getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position); + setHorizontalAlphaEffectEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect, + DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT)); + setClickToMaximizeEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_click_to_maximize_view, + DEFAULT_ENABLE_CLICK_TO_MAXIMIZE)); + setClickToMinimizeEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_click_to_minimize_view, + DEFAULT_ENABLE_CLICK_TO_MINIMIZE)); this.attributes = attributes; } @@ -672,7 +725,7 @@ private void initializeAttributes(AttributeSet attrs) { */ private boolean smoothSlideTo(float slideOffset) { final int topBound = getPaddingTop(); - int x = (int) (slideOffset * (getWidth() - transformer.getMinWidthPlusMarginRight())); + int x = (int) (slideOffset * (getWidth() - transformer.getMinWidthPlusMarginHorizontalSides())); int y = (int) (topBound + slideOffset * getVerticalDragRange()); if (viewDragHelper.smoothSlideViewTo(dragView, x, y)) { ViewCompat.postInvalidateOnAnimation(this); @@ -681,6 +734,13 @@ private boolean smoothSlideTo(float slideOffset) { return false; } + /** + * @return configured dragged view margin left configured. + */ + private int getDragViewMarginLeft() { + return transformer.getMarginLeft(); + } + /** * @return configured dragged view margin right configured. */ @@ -688,6 +748,13 @@ private int getDragViewMarginRight() { return transformer.getMarginRight(); } + /** + * @return configured dragged view margin top. + */ + private int getDragViewMarginTop() { + return transformer.getMarginTop(); + } + /** * @return configured dragged view margin bottom. */ @@ -719,7 +786,7 @@ private float getVerticalDragOffset() { * @return the difference between the custom view height and the dragged view height. */ private float getVerticalDragRange() { - return getHeight() - transformer.getMinHeightPlusMargin(); + return getHeight() - transformer.getMinHeightPlusVerticalSides(); } /** @@ -759,6 +826,6 @@ private void notifyCloseToLeftListener() { } public int getDraggedViewHeightPlusMarginTop() { - return transformer.getMinHeightPlusMargin(); + return transformer.getMinHeightPlusVerticalSides(); } } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java index 08016ba..8d2bcc0 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java @@ -15,6 +15,7 @@ */ package com.github.pedrovgs; +import android.os.Debug; import android.support.v4.widget.ViewDragHelper; import android.view.View; @@ -31,6 +32,10 @@ class DraggableViewCallback extends ViewDragHelper.Callback { private static final float X_MIN_VELOCITY = 1500; private static final float Y_MIN_VELOCITY = 1000; + private boolean listenerEnabled; + private int verticalDragRange = 0; + + private DraggableListener draggableListener; private DraggableView draggableView; private View draggedView; @@ -39,9 +44,22 @@ class DraggableViewCallback extends ViewDragHelper.Callback { * * @param draggableView instance used to apply some animations or visual effects. */ - public DraggableViewCallback(DraggableView draggableView, View draggedView) { + public DraggableViewCallback(DraggableView draggableView, View draggedView, DraggableListener draggableListener) { this.draggableView = draggableView; this.draggedView = draggedView; + this.draggableListener = draggableListener; + } + + public void setListenerEnabled(boolean listenerEnabled) { + this.listenerEnabled = listenerEnabled; + } + + public void setVerticalDragRange(int verticalDragRange) { + this.verticalDragRange = verticalDragRange; + } + + private int getVerticalDragRange() { + return verticalDragRange; } /** @@ -64,6 +82,16 @@ public DraggableViewCallback(DraggableView draggableView, View draggedView) { draggableView.changeSecondViewPosition(); draggableView.changeBackgroundAlpha(); } + + if(listenerEnabled) { + float fractionScreen = (float) Math.abs(top) / (float) getVerticalDragRange(); + if (fractionScreen >= 1) { + fractionScreen = 1; + } + if (draggableListener != null) { + draggableListener.onTopViewSlide(fractionScreen); + } + } } /** @@ -77,7 +105,6 @@ public DraggableViewCallback(DraggableView draggableView, View draggedView) { */ @Override public void onViewReleased(View releasedChild, float xVel, float yVel) { super.onViewReleased(releasedChild, xVel, yVel); - if (draggableView.isDragViewAtBottom() && !draggableView.isDragViewAtRight()) { triggerOnReleaseActionsWhileHorizontalDrag(xVel); } else { diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java new file mode 100644 index 0000000..75c029a --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java @@ -0,0 +1,282 @@ +package com.github.pedrovgs.shadow; + +import android.content.Context; +import android.graphics.Canvas; +import android.os.Build; +import android.util.AttributeSet; +import android.view.View; +import android.view.animation.LinearInterpolator; +import com.github.pedrovgs.shadow.layout.Shadow; +import com.nineoldandroids.animation.PropertyValuesHolder; +import com.nineoldandroids.animation.ValueAnimator; + +public class ShadowView extends View { + protected static final String TAG = "ShadowView"; + + protected static final String ANIM_PROPERTY_ALPHA_TOP_SHADOW = "alphaTopShadow"; + protected static final String ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW = "alphaBottomShadow"; + protected static final String ANIM_PROPERTY_OFFSET_TOP_SHADOW = "offsetTopShadow"; + protected static final String ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW = "offsetBottomShadow"; + protected static final String ANIM_PROPERTY_BLUR_TOP_SHADOW = "blurTopShadow"; + protected static final String ANIM_PROPERTY_BLUR_BOTTOM_SHADOW = "blurBottomShadow"; + + protected Shadow mShadow; + protected ZDepthParam mZDepthParam; + protected int mZDepthPaddingLeft; + protected int mZDepthPaddingTop; + protected int mZDepthPaddingRight; + protected int mZDepthPaddingBottom; + protected long mZDepthAnimDuration; + protected boolean mZDepthDoAnimation; + + protected ShadowView(Context context) { + this(context, null); + init(); + } + + protected ShadowView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + init(); + } + + protected ShadowView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(); + } + + protected void init() { + setWillNotDraw(false); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + } + + protected void setZDepthDoAnimation(boolean doAnimation) { + mZDepthDoAnimation = doAnimation; + } + + protected void setZDepthAnimDuration(long duration) { + mZDepthAnimDuration = duration; + } + + protected void setZDepthPaddingLeft(int zDepthPaddingLeftValue) { + ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingLeftValue); + mZDepthPaddingLeft = measureZDepthPadding(zDepth); + } + + protected void setZDepthPaddingTop(int zDepthPaddingTopValue) { + ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingTopValue); + mZDepthPaddingTop = measureZDepthPadding(zDepth); + } + + protected void setZDepthPaddingRight(int zDepthPaddingRightValue) { + ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingRightValue); + mZDepthPaddingRight = measureZDepthPadding(zDepth); + } + + protected void setZDepthPaddingBottom(int zDepthPaddingBottomValue) { + ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingBottomValue); + mZDepthPaddingBottom = measureZDepthPadding(zDepth); + } + + protected int measureZDepthPadding(ZDepth zDepth) { + float maxAboveBlurRadius = zDepth.getBlurTopShadowPx(getContext()); + float maxAboveOffset = zDepth.getOffsetYTopShadowPx(getContext()); + float maxBelowBlurRadius = zDepth.getBlurBottomShadowPx(getContext()); + float maxBelowOffset = zDepth.getOffsetYBottomShadowPx(getContext()); + + float maxAboveSize = maxAboveBlurRadius + maxAboveOffset; + float maxBelowSize = maxBelowBlurRadius + maxBelowOffset; + + return (int) Math.max(maxAboveSize, maxBelowSize); + } + + protected int getZDepthPaddingLeft() { + return mZDepthPaddingLeft; + } + + protected int getZDepthPaddingTop() { + return mZDepthPaddingTop; + } + + protected int getZDepthPaddingRight() { + return mZDepthPaddingRight; + } + + protected int getZDepthPaddingBottom() { + return mZDepthPaddingBottom; + } + + protected void setShape(int shape) { + //switch (shape) { + // case ZDepthShadowLayout.SHAPE_RECT: + // mShadow = new ShadowRect(); + // break; + // default: + // throw new IllegalArgumentException("unknown shape value."); + //} + } + + protected void setZDepth(int zDepthValue) { + ZDepth zDepth = getZDepthWithAttributeValue(zDepthValue); + setZDepth(zDepth); + } + + protected void setZDepth(ZDepth zDepth) { + mZDepthParam = new ZDepthParam(); + mZDepthParam.initZDepth(getContext(), zDepth); + } + + private ZDepth getZDepthWithAttributeValue(int zDepthValue) { + switch (zDepthValue) { + case 0: return ZDepth.Depth0; + case 1: return ZDepth.Depth1; + case 2: return ZDepth.Depth2; + case 3: return ZDepth.Depth3; + case 4: return ZDepth.Depth4; + case 5: return ZDepth.Depth5; + default: throw new IllegalArgumentException("unknown zDepth value."); + } + } + + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int wSize = MeasureSpec.getSize(widthMeasureSpec); + int hSize = MeasureSpec.getSize(heightMeasureSpec); + + int wMode = MeasureSpec.getMode(widthMeasureSpec); + int hMode = MeasureSpec.getMode(heightMeasureSpec); + + switch (wMode) { + case MeasureSpec.EXACTLY: + // NOP + break; + + case MeasureSpec.AT_MOST: + case MeasureSpec.UNSPECIFIED: + wSize = 0; + break; + } + + switch (hMode) { + case MeasureSpec.EXACTLY: + // NOP + break; + + case MeasureSpec.AT_MOST: + case MeasureSpec.UNSPECIFIED: + hSize = 0; + break; + } + + super.onMeasure( + MeasureSpec.makeMeasureSpec(wSize, wMode), + MeasureSpec.makeMeasureSpec(hSize, hMode)); + } + + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + int parentWidth = (right - left); + int parentHeight = (bottom - top); + + mShadow.setParameter(mZDepthParam, + mZDepthPaddingLeft, + mZDepthPaddingTop, + parentWidth - mZDepthPaddingRight, + parentHeight - mZDepthPaddingBottom); + } + + @Override protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + mShadow.onDraw(canvas); + } + + protected void changeZDepth(ZDepth zDepth) { + + int newAlphaTopShadow = zDepth.getAlphaTopShadow(); + int newAlphaBottomShadow = zDepth.getAlphaBottomShadow(); + float newOffsetYTopShadow = zDepth.getOffsetYTopShadowPx(getContext()); + float newOffsetYBottomShadow = zDepth.getOffsetYBottomShadowPx(getContext()); + float newBlurTopShadow = zDepth.getBlurTopShadowPx(getContext()); + float newBlurBottomShadow = zDepth.getBlurBottomShadowPx(getContext()); + + if (!mZDepthDoAnimation) { + mZDepthParam.mAlphaTopShadow = newAlphaTopShadow; + mZDepthParam.mAlphaBottomShadow = newAlphaBottomShadow; + mZDepthParam.mOffsetYTopShadowPx = newOffsetYTopShadow; + mZDepthParam.mOffsetYBottomShadowPx = newOffsetYBottomShadow; + mZDepthParam.mBlurTopShadowPx = newBlurTopShadow; + mZDepthParam.mBlurBottomShadowPx = newBlurBottomShadow; + + mShadow.setParameter(mZDepthParam, + mZDepthPaddingLeft, + mZDepthPaddingTop, + getWidth() - mZDepthPaddingRight, + getHeight() - mZDepthPaddingBottom); + invalidate(); + return; + } + + int nowAlphaTopShadow = mZDepthParam.mAlphaTopShadow; + int nowAlphaBottomShadow = mZDepthParam.mAlphaBottomShadow; + float nowOffsetYTopShadow = mZDepthParam.mOffsetYTopShadowPx; + float nowOffsetYBottomShadow = mZDepthParam.mOffsetYBottomShadowPx; + float nowBlurTopShadow = mZDepthParam.mBlurTopShadowPx; + float nowBlurBottomShadow = mZDepthParam.mBlurBottomShadowPx; + + PropertyValuesHolder alphaTopShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_TOP_SHADOW, + nowAlphaTopShadow, + newAlphaTopShadow); + PropertyValuesHolder alphaBottomShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW, + nowAlphaBottomShadow, + newAlphaBottomShadow); + PropertyValuesHolder offsetTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_TOP_SHADOW, + nowOffsetYTopShadow, + newOffsetYTopShadow); + PropertyValuesHolder offsetBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW, + nowOffsetYBottomShadow, + newOffsetYBottomShadow); + PropertyValuesHolder blurTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_TOP_SHADOW, + nowBlurTopShadow, + newBlurTopShadow); + PropertyValuesHolder blurBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW, + nowBlurBottomShadow, + newBlurBottomShadow); + + ValueAnimator anim = ValueAnimator + .ofPropertyValuesHolder( + alphaTopShadowHolder, + alphaBottomShadowHolder, + offsetTopShadowHolder, + offsetBottomShadowHolder, + blurTopShadowHolder, + blurBottomShadowHolder); + anim.setDuration(mZDepthAnimDuration); + anim.setInterpolator(new LinearInterpolator()); + anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int alphaTopShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_TOP_SHADOW); + int alphaBottomShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW); + float offsetTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_TOP_SHADOW); + float offsetBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW); + float blurTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_TOP_SHADOW); + float blurBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW); + + mZDepthParam.mAlphaTopShadow = alphaTopShadow; + mZDepthParam.mAlphaBottomShadow = alphaBottomShadow; + mZDepthParam.mOffsetYTopShadowPx = offsetTopShadow; + mZDepthParam.mOffsetYBottomShadowPx = offsetBottomShadow; + mZDepthParam.mBlurTopShadowPx = blurTopShadow; + mZDepthParam.mBlurBottomShadowPx = blurBottomShadow; + + mShadow.setParameter(mZDepthParam, + mZDepthPaddingLeft, + mZDepthPaddingTop, + getWidth() - mZDepthPaddingRight, + getHeight() - mZDepthPaddingBottom); + + invalidate(); + } + }); + anim.start(); + } +} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java new file mode 100644 index 0000000..7e925d4 --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java @@ -0,0 +1,90 @@ +package com.github.pedrovgs.shadow; + +import android.content.Context; +import com.github.pedrovgs.shadow.util.DisplayUtils; + +public enum ZDepth { + + Depth0(0, + 0, + 0, + 0, + 0, + 0), + + Depth1(30, + 61, + 1.0f, + 1.0f, + 1.5f, + 1.0f), + + Depth2(40, + 58, + 3.0f, + 3.0f, + 3.0f, + 3.0f), + + Depth3(48, + 58, + 10.0f, + 6.0f, + 10.0f, + 3.0f), + + Depth4(64, + 56, + 14.0f, + 10.0f, + 14.0f, + 5.0f), + + Depth5(76, + 56, + 19.0f, + 15.0f, + 19.0f, + 6.0f); + + public final int mAlphaTopShadow; + public final int mAlphaBottomShadow; + public final float mOffsetYTopShadow; + public final float mOffsetYBottomShadow; + public final float mBlurTopShadow; + public final float mBlurBottomShadow; + + private ZDepth(int alphaTopShadow, int alphaBottomShadow, float offsetYTopShadow, float offsetYBottomShadow, float blurTopShadow, float blurBottomShadow) { + mAlphaTopShadow = alphaTopShadow; + mAlphaBottomShadow = alphaBottomShadow; + mOffsetYTopShadow = offsetYTopShadow; + mOffsetYBottomShadow = offsetYBottomShadow; + mBlurTopShadow = blurTopShadow; + mBlurBottomShadow = blurBottomShadow; + } + + public int getAlphaTopShadow() { + return mAlphaTopShadow; + } + + public int getAlphaBottomShadow() { + return mAlphaBottomShadow; + } + + public float getOffsetYTopShadowPx(Context context) { + return DisplayUtils.convertDpToPx(context, mOffsetYTopShadow); + } + + public float getOffsetYBottomShadowPx(Context context) { + return DisplayUtils.convertDpToPx(context, mOffsetYBottomShadow); + } + + public float getBlurTopShadowPx(Context context) { + return DisplayUtils.convertDpToPx(context, mBlurTopShadow); + } + + public float getBlurBottomShadowPx(Context context) { + return DisplayUtils.convertDpToPx(context, mBlurBottomShadow); + } + +} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java new file mode 100644 index 0000000..f3429b3 --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java @@ -0,0 +1,32 @@ +package com.github.pedrovgs.shadow; + +import android.content.Context; +import android.graphics.Color; + +/** + * Created by pedro on 3/10/15. + */ +public class ZDepthParam { + + public int mAlphaTopShadow; + public int mAlphaBottomShadow; + public float mOffsetYTopShadowPx; + public float mOffsetYBottomShadowPx; + public float mBlurTopShadowPx; + public float mBlurBottomShadowPx; + + public void initZDepth(Context context, ZDepth zDepth) { + mAlphaTopShadow = zDepth.getAlphaTopShadow(); + mAlphaBottomShadow = zDepth.getAlphaBottomShadow(); + mOffsetYTopShadowPx = zDepth.getOffsetYTopShadowPx(context); + mOffsetYBottomShadowPx = zDepth.getOffsetYBottomShadowPx(context); + mBlurTopShadowPx = zDepth.getBlurTopShadowPx(context); + mBlurBottomShadowPx = zDepth.getBlurBottomShadowPx(context); + } + public int getColorTopShadow() { + return Color.argb(mAlphaTopShadow, 0, 0, 0); + } + public int getColorBottomShadow() { + return Color.argb(mAlphaBottomShadow, 0, 0, 0); + } +} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java new file mode 100644 index 0000000..4d7bc83 --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java @@ -0,0 +1,9 @@ +package com.github.pedrovgs.shadow.layout; + +import android.graphics.Canvas; +import com.github.pedrovgs.shadow.ZDepthParam; + +public interface Shadow { + public void setParameter(ZDepthParam parameter, int left, int top, int right, int bottom); + public void onDraw(Canvas canvas); +} \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java new file mode 100644 index 0000000..79754d5 --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java @@ -0,0 +1,53 @@ +package com.github.pedrovgs.shadow.layout; + +import android.graphics.BlurMaskFilter; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Rect; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.shapes.RectShape; +import com.github.pedrovgs.shadow.ZDepthParam; + +public class ShadowRect implements Shadow { + + private ShapeDrawable mTopShadow; + private ShapeDrawable mBottomShadow; + private Rect mRectTopShadow; + private Rect mRectBottomShadow; + + public ShadowRect() { + mRectTopShadow = new Rect(); + mRectBottomShadow = new Rect(); + mTopShadow = new ShapeDrawable(new RectShape()); + mBottomShadow = new ShapeDrawable(new RectShape()); + } + + @Override public void setParameter(ZDepthParam param, int left, int top, int right, int bottom) { + mRectTopShadow.left = left; + mRectTopShadow.top = (int) (top + param.mOffsetYTopShadowPx); + mRectTopShadow.right = right; + mRectTopShadow.bottom = (int) (bottom + param.mOffsetYTopShadowPx); + mRectBottomShadow.left = left; + mRectBottomShadow.top = (int) (top + param.mOffsetYBottomShadowPx); + mRectBottomShadow.right = right; + mRectBottomShadow.bottom = (int) (bottom + param.mOffsetYBottomShadowPx); + mTopShadow.getPaint().setColor(Color.argb(param.mAlphaTopShadow, 0, 0, 0)); + if (0 < param.mBlurTopShadowPx) { + mTopShadow.getPaint().setMaskFilter(new BlurMaskFilter(param.mBlurTopShadowPx, BlurMaskFilter.Blur.NORMAL)); + } else { + mTopShadow.getPaint().setMaskFilter(null); + } + mBottomShadow.getPaint().setColor(Color.argb(param.mAlphaBottomShadow, 0, 0, 0)); + if (0 < param.mBlurBottomShadowPx) { + mBottomShadow.getPaint().setMaskFilter(new BlurMaskFilter(param.mBlurBottomShadowPx, BlurMaskFilter.Blur.NORMAL)); + } else { + mBottomShadow.getPaint().setMaskFilter(null); + } + } + + @Override public void onDraw(Canvas canvas) { + canvas.drawRect(mRectBottomShadow, mBottomShadow.getPaint()); + canvas.drawRect(mRectTopShadow, mTopShadow.getPaint()); + } + +} \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java new file mode 100644 index 0000000..4805598 --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java @@ -0,0 +1,10 @@ +package com.github.pedrovgs.shadow.util; + +import android.content.Context; + +public class DisplayUtils { + public static int convertDpToPx(Context context, float dp) { + float scale = context.getResources().getDisplayMetrics().density; + return (int) (dp * scale + 0.5f); + } +} \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java index 6af7bc3..3dbc525 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java @@ -53,14 +53,41 @@ class ResizeTransformer extends Transformer { */ @Override public void updatePosition(float verticalDragOffset) { - int right = getViewRightPosition(verticalDragOffset); - int left = right - layoutParams.width; + + int right; + int left; int top = getView().getTop(); int bottom = top + layoutParams.height; + switch (getViewPosition()) { + case Transformer.LEFT: + left = getViewLeftPosition(verticalDragOffset); + right = layoutParams.width; + break; + case Transformer.CENTER: + right = layoutParams.width/2; + left = right; + break; + case Transformer.RIGHT: + right = getViewRightPosition(verticalDragOffset); + left = right - layoutParams.width; + break; + default: + right = 0; + left = 0; + break; + } + getView().layout(left, top, right, bottom); } + /** + * @return true if the left position of the view plus the right left is equals to the parent + * width. + */ + @Override public boolean isViewAtLeft() { + return getView().getLeft() + getMarginLeft() == getParentView().getWidth(); + } /** * @return true if the right position of the view plus the right margin is equals to the parent @@ -97,15 +124,15 @@ public void updatePosition(float verticalDragOffset) { /** * Uses the Y scale factor to calculate the min possible height. */ - @Override public int getMinHeightPlusMargin() { - return (int) (getOriginalHeight() * (1 - 1 / getYScaleFactor()) + getMarginBottom()); + @Override public int getMinHeightPlusVerticalSides() { + return (int) (getOriginalHeight() * (1 - 1 / getYScaleFactor()) + getMarginTop() + getMarginBottom()); } /** * Uses the X scale factor to calculate the min possible width. */ - @Override public int getMinWidthPlusMarginRight() { - return (int) (getOriginalWidth() * (1 - 1 / getXScaleFactor()) + getMarginRight()); + @Override public int getMinWidthPlusMarginHorizontalSides() { + return (int) (getOriginalWidth() * (1 - 1 / getXScaleFactor()) + getMarginLeft() + getMarginRight()); } /** @@ -117,4 +144,8 @@ private int getViewRightPosition(float verticalDragOffset) { return (int) ((getOriginalWidth()) - getMarginRight() * verticalDragOffset); } + private int getViewLeftPosition(float verticalDragOffset) { + return (int) ((getOriginalWidth()) - getMarginLeft() * verticalDragOffset); + } + } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java index e49a13e..7959cf5 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java @@ -47,8 +47,15 @@ class ScaleTransformer extends Transformer { * @param verticalDragOffset used to calculate the new position. */ @Override public void updatePosition(float verticalDragOffset) { - ViewHelper.setPivotX(getView(), getView().getWidth() - getMarginRight()); - ViewHelper.setPivotY(getView(), getView().getHeight() - getMarginBottom()); + ViewHelper.setPivotX(getView(), generateHorizontalPivot()); + ViewHelper.setPivotY(getView(), generateVerticalPivot()); + } + + /** + * @return true if the left corner of the view matches with the parent view width. + */ + @Override public boolean isViewAtLeft() { + return getView().getLeft() == getParentView().getWidth(); } /** @@ -84,15 +91,32 @@ class ScaleTransformer extends Transformer { /** * @return min view height taking into account the configured margin. */ - @Override public int getMinHeightPlusMargin() { + @Override public int getMinHeightPlusVerticalSides() { return getView().getHeight(); } /** * @return min view width. */ - @Override public int getMinWidthPlusMarginRight() { + @Override public int getMinWidthPlusMarginHorizontalSides() { return getOriginalWidth(); } + private float generateHorizontalPivot() { + switch (getViewPosition()) { + case Transformer.LEFT: + return getMarginLeft(); + case Transformer.CENTER: + return getView().getWidth()/2; + case Transformer.RIGHT: + return getView().getWidth() - getMarginRight(); + default: + return getView().getWidth() - getMarginRight(); + } + } + + private float generateVerticalPivot() { + return getView().getHeight() - getMarginBottom(); + } + } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java index 93a248c..39ce7db 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java @@ -34,10 +34,18 @@ */ public abstract class Transformer { + public static final float DEFAULT_DRAG_LIMIT = 0.5f; + + public static final int LEFT = 0; + public static final int CENTER = 1; + public static final int RIGHT = 2; + private final View view; private final View parent; + private int marginLeft; private int marginRight; + private int marginTop; private int marginBottom; private float xScaleFactor; @@ -46,11 +54,22 @@ public abstract class Transformer { private int originalHeight; private int originalWidth; + private int position; + private float dragLimit; + public Transformer(View view, View parent) { this.view = view; this.parent = parent; } + public int getViewPosition() { + return position; + } + + public void setViewPosition(int position) { + this.position = position; + } + public float getXScaleFactor() { return xScaleFactor; } @@ -67,6 +86,14 @@ public void setYScaleFactor(float yScaleFactor) { this.yScaleFactor = yScaleFactor; } + public int getMarginLeft() { + return marginLeft; + } + + public void setMarginLeft(int marginLeft) { + this.marginLeft = Math.round(marginLeft); + } + public int getMarginRight() { return marginRight; } @@ -75,6 +102,14 @@ public void setMarginRight(int marginRight) { this.marginRight = Math.round(marginRight); } + public int getMarginTop() { + return marginTop; + } + + public void setMarginTop(int marginTop) { + this.marginTop = Math.round(marginTop); + } + public int getMarginBottom() { return marginBottom; } @@ -83,6 +118,14 @@ public void setMarginBottom(int marginBottom) { this.marginBottom = Math.round(marginBottom); } + public float getDragLimit() { + return dragLimit; + } + + public void setDragLimit(float dragLimit) { + this.dragLimit = dragLimit; + } + /** * Change view height using the LayoutParams of the view. * @@ -136,10 +179,12 @@ public boolean isViewAtTop() { public boolean isAboveTheMiddle() { int parentHeight = parent.getHeight(); - float viewYPosition = ViewHelper.getY(view) + (view.getHeight() * 0.5f); - return viewYPosition < (parentHeight * 0.5); + float viewYPosition = ViewHelper.getY(view) + (view.getHeight() * getDragLimit()); + return viewYPosition < (parentHeight * getDragLimit()); } + public abstract boolean isViewAtLeft(); + public abstract boolean isViewAtRight(); public abstract boolean isViewAtBottom(); @@ -149,12 +194,12 @@ public boolean isAboveTheMiddle() { public abstract boolean isNextToLeftBound(); /** - * @return min possible height, after apply the transformation, plus the margin right. + * @return min possible height, after apply the transformation, plus the margin right and left. */ - public abstract int getMinHeightPlusMargin(); + public abstract int getMinHeightPlusVerticalSides(); /** - * @return min possible width, after apply the transformation. + * @return min possible width, after apply the transformation, plus the margin top and bottom. */ - public abstract int getMinWidthPlusMarginRight(); + public abstract int getMinWidthPlusMarginHorizontalSides(); } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java index 149714c..179ac5a 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java @@ -15,6 +15,8 @@ */ package com.github.pedrovgs.transformer; +import android.content.res.TypedArray; +import android.util.AttributeSet; import android.view.View; /** @@ -26,7 +28,7 @@ public class TransformerFactory { public Transformer getTransformer(final boolean resize, final View view, final View parent) { - Transformer transformer = null; + Transformer transformer; if (resize) { transformer = new ResizeTransformer(view, parent); } else { diff --git a/sample/res/layout/activity_tv_shows_sample.xml b/sample/res/layout/activity_tv_shows_sample.xml index 10c4855..e42de7e 100644 --- a/sample/res/layout/activity_tv_shows_sample.xml +++ b/sample/res/layout/activity_tv_shows_sample.xml @@ -26,8 +26,12 @@ draggable_view:bottom_view_id="@+id/lv_episodes" draggable_view:top_view_x_scale_factor="@dimen/x_scale_factor" draggable_view:top_view_y_scale_factor="@dimen/y_scale_factor" - draggable_view:top_view_margin_right="@dimen/top_fragment_margin" + draggable_view:top_view_margin_top="@dimen/top_fragment_margin" draggable_view:top_view_margin_bottom="@dimen/top_fragment_margin" + draggable_view:top_view_margin_left="@dimen/top_fragment_margin" + draggable_view:top_view_margin_right="@dimen/top_fragment_margin" + draggable_view:drag_limit_view="0.5" + draggable_view:position="center" android:background="@color/black"> diff --git a/sample/res/layout/activity_video_sample.xml b/sample/res/layout/activity_video_sample.xml index 2ce622a..b171f46 100644 --- a/sample/res/layout/activity_video_sample.xml +++ b/sample/res/layout/activity_video_sample.xml @@ -28,7 +28,7 @@ draggable_view:top_view_margin_right="@dimen/top_fragment_margin" draggable_view:top_view_margin_bottom="@dimen/top_fragment_margin" draggable_view:enable_minimized_horizontal_alpha_effect="false" - draggable_view:top_view_resize="true" + draggable_view:position="left" android:background="@color/black"> diff --git a/sample/res/layout/activity_youtube_sample.xml b/sample/res/layout/activity_youtube_sample.xml index c278f12..2bba115 100644 --- a/sample/res/layout/activity_youtube_sample.xml +++ b/sample/res/layout/activity_youtube_sample.xml @@ -23,8 +23,12 @@ draggable_panel:x_scale_factor="@dimen/x_scale_factor" draggable_panel:y_scale_factor="@dimen/y_scale_factor" draggable_panel:top_fragment_height="@dimen/top_fragment_height" - draggable_panel:top_fragment_margin_right="@dimen/top_fragment_margin" - draggable_panel:top_fragment_margin_bottom="@dimen/top_fragment_margin" - draggable_panel:enable_horizontal_alpha_effect="false"/> + draggable_panel:top_view_margin_top="@dimen/top_fragment_margin" + draggable_panel:top_view_margin_bottom="@dimen/top_fragment_margin" + draggable_panel:top_view_margin_left="@dimen/top_fragment_margin" + draggable_panel:top_view_margin_right="@dimen/top_fragment_margin" + draggable_panel:enable_horizontal_alpha_effect="false" + draggable_panel:drag_limit_panel="0.9" + draggable_panel:position="right"/> \ No newline at end of file diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java index ebf2dc5..45a69a9 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java @@ -35,6 +35,7 @@ import com.github.pedrovgs.sample.renderer.rendererbuilder.EpisodeRendererBuilder; import com.github.pedrovgs.sample.viewmodel.EpisodeViewModel; import com.github.pedrovgs.sample.viewmodel.TvShowViewModel; +import com.github.pedrovgs.transformer.Transformer; import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.RendererAdapter; import com.squareup.picasso.Picasso; @@ -139,6 +140,10 @@ private void hookListeners() { @Override public void onClosedToRight() { resetActionBarTitle(); } + + @Override public void onTopViewSlide(float scroll) { + + } }); } diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java index 83e2dbf..583c43a 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java @@ -100,6 +100,10 @@ private void hookDraggableViewListener() { @Override public void onClosedToRight() { pauseVideo(); } + + @Override public void onTopViewSlide(float scroll) { + + } }); } diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java index 756e20d..b471400 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java @@ -134,6 +134,10 @@ private void hookDraggablePanelListeners() { @Override public void onClosedToRight() { pauseVideo(); } + + @Override public void onTopViewSlide(float scroll) { + + } }); } From 27658a9b4878b8a56b06699d98d00b8761ebf476 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 11:12:00 -0300 Subject: [PATCH 02/11] error fix --- .../java/com/github/pedrovgs/DraggablePanel.java | 3 ++- .../java/com/github/pedrovgs/DraggableView.java | 3 ++- .../com/github/pedrovgs/DraggableViewCallback.java | 3 +-- .../pedrovgs/transformer/ResizeTransformer.java | 5 +---- .../pedrovgs/transformer/ScaleTransformer.java | 1 - sample/build.gradle | 1 - sample/res/layout/activity_tv_shows_sample.xml | 3 ++- sample/res/layout/activity_youtube_sample.xml | 13 +++++++------ 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index d783bd7..f8f11f1 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -373,7 +373,8 @@ public boolean isClosedAtLeft() { */ private void initializeAttrs(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_panel); - setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position).getInt(R.styleable.top_view_position_position, + setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position) + .getInt(R.styleable.top_view_position_position, Transformer.RIGHT)); setTopFragmentHeight(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_height, DEFAULT_TOP_FRAGMENT_HEIGHT)); diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index 836de42..e555656 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -707,7 +707,8 @@ private void initializeTransformer(TypedArray attributes) { private void initializeAttributes(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_view); attributePosition = getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position); - setHorizontalAlphaEffectEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect, + setHorizontalAlphaEffectEnabled(attributes.getBoolean( + R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect, DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT)); setClickToMaximizeEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_click_to_maximize_view, DEFAULT_ENABLE_CLICK_TO_MAXIMIZE)); diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java index 8d2bcc0..a224826 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java @@ -15,7 +15,6 @@ */ package com.github.pedrovgs; -import android.os.Debug; import android.support.v4.widget.ViewDragHelper; import android.view.View; @@ -83,7 +82,7 @@ private int getVerticalDragRange() { draggableView.changeBackgroundAlpha(); } - if(listenerEnabled) { + if (listenerEnabled) { float fractionScreen = (float) Math.abs(top) / (float) getVerticalDragRange(); if (fractionScreen >= 1) { fractionScreen = 1; diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java index 3dbc525..8e51183 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java @@ -69,13 +69,10 @@ public void updatePosition(float verticalDragOffset) { left = right; break; case Transformer.RIGHT: + default: right = getViewRightPosition(verticalDragOffset); left = right - layoutParams.width; break; - default: - right = 0; - left = 0; - break; } getView().layout(left, top, right, bottom); diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java index 7959cf5..1d64529 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java @@ -109,7 +109,6 @@ private float generateHorizontalPivot() { case Transformer.CENTER: return getView().getWidth()/2; case Transformer.RIGHT: - return getView().getWidth() - getMarginRight(); default: return getView().getWidth() - getMarginRight(); } diff --git a/sample/build.gradle b/sample/build.gradle index 047b963..293dbc2 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -43,7 +43,6 @@ android { } } - task checkstyle(type: Checkstyle) { configFile file('../config/checkstyle/checkstyle.xml') source 'src/main/java' diff --git a/sample/res/layout/activity_tv_shows_sample.xml b/sample/res/layout/activity_tv_shows_sample.xml index e42de7e..bcc9bac 100644 --- a/sample/res/layout/activity_tv_shows_sample.xml +++ b/sample/res/layout/activity_tv_shows_sample.xml @@ -31,7 +31,8 @@ draggable_view:top_view_margin_left="@dimen/top_fragment_margin" draggable_view:top_view_margin_right="@dimen/top_fragment_margin" draggable_view:drag_limit_view="0.5" - draggable_view:position="center" + draggable_view:position="right" + draggable_view:top_view_resize="true" android:background="@color/black"> diff --git a/sample/res/layout/activity_youtube_sample.xml b/sample/res/layout/activity_youtube_sample.xml index 2bba115..e77124f 100644 --- a/sample/res/layout/activity_youtube_sample.xml +++ b/sample/res/layout/activity_youtube_sample.xml @@ -23,12 +23,13 @@ draggable_panel:x_scale_factor="@dimen/x_scale_factor" draggable_panel:y_scale_factor="@dimen/y_scale_factor" draggable_panel:top_fragment_height="@dimen/top_fragment_height" - draggable_panel:top_view_margin_top="@dimen/top_fragment_margin" - draggable_panel:top_view_margin_bottom="@dimen/top_fragment_margin" - draggable_panel:top_view_margin_left="@dimen/top_fragment_margin" - draggable_panel:top_view_margin_right="@dimen/top_fragment_margin" + draggable_panel:top_fragment_margin_top="@dimen/top_fragment_margin" + draggable_panel:top_fragment_margin_bottom="@dimen/top_fragment_margin" + draggable_panel:top_fragment_margin_left="@dimen/top_fragment_margin" + draggable_panel:top_fragment_margin_right="@dimen/top_fragment_margin" draggable_panel:enable_horizontal_alpha_effect="false" - draggable_panel:drag_limit_panel="0.9" - draggable_panel:position="right"/> + draggable_panel:position="center" + draggable_panel:top_view_resize="true" + draggable_panel:drag_limit_panel="0.9"/> \ No newline at end of file From e545a53802f903def67c9d46c2444db9731608d4 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 11:12:23 -0300 Subject: [PATCH 03/11] shadow removed --- .../github/pedrovgs/shadow/ShadowView.java | 282 ------------------ .../com/github/pedrovgs/shadow/ZDepth.java | 90 ------ .../github/pedrovgs/shadow/ZDepthParam.java | 32 -- .../github/pedrovgs/shadow/layout/Shadow.java | 9 - .../pedrovgs/shadow/layout/ShadowRect.java | 53 ---- .../pedrovgs/shadow/util/DisplayUtils.java | 10 - 6 files changed, 476 deletions(-) delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java delete mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java deleted file mode 100644 index 75c029a..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ShadowView.java +++ /dev/null @@ -1,282 +0,0 @@ -package com.github.pedrovgs.shadow; - -import android.content.Context; -import android.graphics.Canvas; -import android.os.Build; -import android.util.AttributeSet; -import android.view.View; -import android.view.animation.LinearInterpolator; -import com.github.pedrovgs.shadow.layout.Shadow; -import com.nineoldandroids.animation.PropertyValuesHolder; -import com.nineoldandroids.animation.ValueAnimator; - -public class ShadowView extends View { - protected static final String TAG = "ShadowView"; - - protected static final String ANIM_PROPERTY_ALPHA_TOP_SHADOW = "alphaTopShadow"; - protected static final String ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW = "alphaBottomShadow"; - protected static final String ANIM_PROPERTY_OFFSET_TOP_SHADOW = "offsetTopShadow"; - protected static final String ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW = "offsetBottomShadow"; - protected static final String ANIM_PROPERTY_BLUR_TOP_SHADOW = "blurTopShadow"; - protected static final String ANIM_PROPERTY_BLUR_BOTTOM_SHADOW = "blurBottomShadow"; - - protected Shadow mShadow; - protected ZDepthParam mZDepthParam; - protected int mZDepthPaddingLeft; - protected int mZDepthPaddingTop; - protected int mZDepthPaddingRight; - protected int mZDepthPaddingBottom; - protected long mZDepthAnimDuration; - protected boolean mZDepthDoAnimation; - - protected ShadowView(Context context) { - this(context, null); - init(); - } - - protected ShadowView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - init(); - } - - protected ShadowView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(); - } - - protected void init() { - setWillNotDraw(false); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } - } - - protected void setZDepthDoAnimation(boolean doAnimation) { - mZDepthDoAnimation = doAnimation; - } - - protected void setZDepthAnimDuration(long duration) { - mZDepthAnimDuration = duration; - } - - protected void setZDepthPaddingLeft(int zDepthPaddingLeftValue) { - ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingLeftValue); - mZDepthPaddingLeft = measureZDepthPadding(zDepth); - } - - protected void setZDepthPaddingTop(int zDepthPaddingTopValue) { - ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingTopValue); - mZDepthPaddingTop = measureZDepthPadding(zDepth); - } - - protected void setZDepthPaddingRight(int zDepthPaddingRightValue) { - ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingRightValue); - mZDepthPaddingRight = measureZDepthPadding(zDepth); - } - - protected void setZDepthPaddingBottom(int zDepthPaddingBottomValue) { - ZDepth zDepth = getZDepthWithAttributeValue(zDepthPaddingBottomValue); - mZDepthPaddingBottom = measureZDepthPadding(zDepth); - } - - protected int measureZDepthPadding(ZDepth zDepth) { - float maxAboveBlurRadius = zDepth.getBlurTopShadowPx(getContext()); - float maxAboveOffset = zDepth.getOffsetYTopShadowPx(getContext()); - float maxBelowBlurRadius = zDepth.getBlurBottomShadowPx(getContext()); - float maxBelowOffset = zDepth.getOffsetYBottomShadowPx(getContext()); - - float maxAboveSize = maxAboveBlurRadius + maxAboveOffset; - float maxBelowSize = maxBelowBlurRadius + maxBelowOffset; - - return (int) Math.max(maxAboveSize, maxBelowSize); - } - - protected int getZDepthPaddingLeft() { - return mZDepthPaddingLeft; - } - - protected int getZDepthPaddingTop() { - return mZDepthPaddingTop; - } - - protected int getZDepthPaddingRight() { - return mZDepthPaddingRight; - } - - protected int getZDepthPaddingBottom() { - return mZDepthPaddingBottom; - } - - protected void setShape(int shape) { - //switch (shape) { - // case ZDepthShadowLayout.SHAPE_RECT: - // mShadow = new ShadowRect(); - // break; - // default: - // throw new IllegalArgumentException("unknown shape value."); - //} - } - - protected void setZDepth(int zDepthValue) { - ZDepth zDepth = getZDepthWithAttributeValue(zDepthValue); - setZDepth(zDepth); - } - - protected void setZDepth(ZDepth zDepth) { - mZDepthParam = new ZDepthParam(); - mZDepthParam.initZDepth(getContext(), zDepth); - } - - private ZDepth getZDepthWithAttributeValue(int zDepthValue) { - switch (zDepthValue) { - case 0: return ZDepth.Depth0; - case 1: return ZDepth.Depth1; - case 2: return ZDepth.Depth2; - case 3: return ZDepth.Depth3; - case 4: return ZDepth.Depth4; - case 5: return ZDepth.Depth5; - default: throw new IllegalArgumentException("unknown zDepth value."); - } - } - - @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int wSize = MeasureSpec.getSize(widthMeasureSpec); - int hSize = MeasureSpec.getSize(heightMeasureSpec); - - int wMode = MeasureSpec.getMode(widthMeasureSpec); - int hMode = MeasureSpec.getMode(heightMeasureSpec); - - switch (wMode) { - case MeasureSpec.EXACTLY: - // NOP - break; - - case MeasureSpec.AT_MOST: - case MeasureSpec.UNSPECIFIED: - wSize = 0; - break; - } - - switch (hMode) { - case MeasureSpec.EXACTLY: - // NOP - break; - - case MeasureSpec.AT_MOST: - case MeasureSpec.UNSPECIFIED: - hSize = 0; - break; - } - - super.onMeasure( - MeasureSpec.makeMeasureSpec(wSize, wMode), - MeasureSpec.makeMeasureSpec(hSize, hMode)); - } - - @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - int parentWidth = (right - left); - int parentHeight = (bottom - top); - - mShadow.setParameter(mZDepthParam, - mZDepthPaddingLeft, - mZDepthPaddingTop, - parentWidth - mZDepthPaddingRight, - parentHeight - mZDepthPaddingBottom); - } - - @Override protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - mShadow.onDraw(canvas); - } - - protected void changeZDepth(ZDepth zDepth) { - - int newAlphaTopShadow = zDepth.getAlphaTopShadow(); - int newAlphaBottomShadow = zDepth.getAlphaBottomShadow(); - float newOffsetYTopShadow = zDepth.getOffsetYTopShadowPx(getContext()); - float newOffsetYBottomShadow = zDepth.getOffsetYBottomShadowPx(getContext()); - float newBlurTopShadow = zDepth.getBlurTopShadowPx(getContext()); - float newBlurBottomShadow = zDepth.getBlurBottomShadowPx(getContext()); - - if (!mZDepthDoAnimation) { - mZDepthParam.mAlphaTopShadow = newAlphaTopShadow; - mZDepthParam.mAlphaBottomShadow = newAlphaBottomShadow; - mZDepthParam.mOffsetYTopShadowPx = newOffsetYTopShadow; - mZDepthParam.mOffsetYBottomShadowPx = newOffsetYBottomShadow; - mZDepthParam.mBlurTopShadowPx = newBlurTopShadow; - mZDepthParam.mBlurBottomShadowPx = newBlurBottomShadow; - - mShadow.setParameter(mZDepthParam, - mZDepthPaddingLeft, - mZDepthPaddingTop, - getWidth() - mZDepthPaddingRight, - getHeight() - mZDepthPaddingBottom); - invalidate(); - return; - } - - int nowAlphaTopShadow = mZDepthParam.mAlphaTopShadow; - int nowAlphaBottomShadow = mZDepthParam.mAlphaBottomShadow; - float nowOffsetYTopShadow = mZDepthParam.mOffsetYTopShadowPx; - float nowOffsetYBottomShadow = mZDepthParam.mOffsetYBottomShadowPx; - float nowBlurTopShadow = mZDepthParam.mBlurTopShadowPx; - float nowBlurBottomShadow = mZDepthParam.mBlurBottomShadowPx; - - PropertyValuesHolder alphaTopShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_TOP_SHADOW, - nowAlphaTopShadow, - newAlphaTopShadow); - PropertyValuesHolder alphaBottomShadowHolder = PropertyValuesHolder.ofInt(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW, - nowAlphaBottomShadow, - newAlphaBottomShadow); - PropertyValuesHolder offsetTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_TOP_SHADOW, - nowOffsetYTopShadow, - newOffsetYTopShadow); - PropertyValuesHolder offsetBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW, - nowOffsetYBottomShadow, - newOffsetYBottomShadow); - PropertyValuesHolder blurTopShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_TOP_SHADOW, - nowBlurTopShadow, - newBlurTopShadow); - PropertyValuesHolder blurBottomShadowHolder = PropertyValuesHolder.ofFloat(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW, - nowBlurBottomShadow, - newBlurBottomShadow); - - ValueAnimator anim = ValueAnimator - .ofPropertyValuesHolder( - alphaTopShadowHolder, - alphaBottomShadowHolder, - offsetTopShadowHolder, - offsetBottomShadowHolder, - blurTopShadowHolder, - blurBottomShadowHolder); - anim.setDuration(mZDepthAnimDuration); - anim.setInterpolator(new LinearInterpolator()); - anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - int alphaTopShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_TOP_SHADOW); - int alphaBottomShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW); - float offsetTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_TOP_SHADOW); - float offsetBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW); - float blurTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_TOP_SHADOW); - float blurBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW); - - mZDepthParam.mAlphaTopShadow = alphaTopShadow; - mZDepthParam.mAlphaBottomShadow = alphaBottomShadow; - mZDepthParam.mOffsetYTopShadowPx = offsetTopShadow; - mZDepthParam.mOffsetYBottomShadowPx = offsetBottomShadow; - mZDepthParam.mBlurTopShadowPx = blurTopShadow; - mZDepthParam.mBlurBottomShadowPx = blurBottomShadow; - - mShadow.setParameter(mZDepthParam, - mZDepthPaddingLeft, - mZDepthPaddingTop, - getWidth() - mZDepthPaddingRight, - getHeight() - mZDepthPaddingBottom); - - invalidate(); - } - }); - anim.start(); - } -} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java deleted file mode 100644 index 7e925d4..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepth.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.github.pedrovgs.shadow; - -import android.content.Context; -import com.github.pedrovgs.shadow.util.DisplayUtils; - -public enum ZDepth { - - Depth0(0, - 0, - 0, - 0, - 0, - 0), - - Depth1(30, - 61, - 1.0f, - 1.0f, - 1.5f, - 1.0f), - - Depth2(40, - 58, - 3.0f, - 3.0f, - 3.0f, - 3.0f), - - Depth3(48, - 58, - 10.0f, - 6.0f, - 10.0f, - 3.0f), - - Depth4(64, - 56, - 14.0f, - 10.0f, - 14.0f, - 5.0f), - - Depth5(76, - 56, - 19.0f, - 15.0f, - 19.0f, - 6.0f); - - public final int mAlphaTopShadow; - public final int mAlphaBottomShadow; - public final float mOffsetYTopShadow; - public final float mOffsetYBottomShadow; - public final float mBlurTopShadow; - public final float mBlurBottomShadow; - - private ZDepth(int alphaTopShadow, int alphaBottomShadow, float offsetYTopShadow, float offsetYBottomShadow, float blurTopShadow, float blurBottomShadow) { - mAlphaTopShadow = alphaTopShadow; - mAlphaBottomShadow = alphaBottomShadow; - mOffsetYTopShadow = offsetYTopShadow; - mOffsetYBottomShadow = offsetYBottomShadow; - mBlurTopShadow = blurTopShadow; - mBlurBottomShadow = blurBottomShadow; - } - - public int getAlphaTopShadow() { - return mAlphaTopShadow; - } - - public int getAlphaBottomShadow() { - return mAlphaBottomShadow; - } - - public float getOffsetYTopShadowPx(Context context) { - return DisplayUtils.convertDpToPx(context, mOffsetYTopShadow); - } - - public float getOffsetYBottomShadowPx(Context context) { - return DisplayUtils.convertDpToPx(context, mOffsetYBottomShadow); - } - - public float getBlurTopShadowPx(Context context) { - return DisplayUtils.convertDpToPx(context, mBlurTopShadow); - } - - public float getBlurBottomShadowPx(Context context) { - return DisplayUtils.convertDpToPx(context, mBlurBottomShadow); - } - -} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java deleted file mode 100644 index f3429b3..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/ZDepthParam.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.pedrovgs.shadow; - -import android.content.Context; -import android.graphics.Color; - -/** - * Created by pedro on 3/10/15. - */ -public class ZDepthParam { - - public int mAlphaTopShadow; - public int mAlphaBottomShadow; - public float mOffsetYTopShadowPx; - public float mOffsetYBottomShadowPx; - public float mBlurTopShadowPx; - public float mBlurBottomShadowPx; - - public void initZDepth(Context context, ZDepth zDepth) { - mAlphaTopShadow = zDepth.getAlphaTopShadow(); - mAlphaBottomShadow = zDepth.getAlphaBottomShadow(); - mOffsetYTopShadowPx = zDepth.getOffsetYTopShadowPx(context); - mOffsetYBottomShadowPx = zDepth.getOffsetYBottomShadowPx(context); - mBlurTopShadowPx = zDepth.getBlurTopShadowPx(context); - mBlurBottomShadowPx = zDepth.getBlurBottomShadowPx(context); - } - public int getColorTopShadow() { - return Color.argb(mAlphaTopShadow, 0, 0, 0); - } - public int getColorBottomShadow() { - return Color.argb(mAlphaBottomShadow, 0, 0, 0); - } -} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java deleted file mode 100644 index 4d7bc83..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/Shadow.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.pedrovgs.shadow.layout; - -import android.graphics.Canvas; -import com.github.pedrovgs.shadow.ZDepthParam; - -public interface Shadow { - public void setParameter(ZDepthParam parameter, int left, int top, int right, int bottom); - public void onDraw(Canvas canvas); -} \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java deleted file mode 100644 index 79754d5..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/layout/ShadowRect.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.pedrovgs.shadow.layout; - -import android.graphics.BlurMaskFilter; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Rect; -import android.graphics.drawable.ShapeDrawable; -import android.graphics.drawable.shapes.RectShape; -import com.github.pedrovgs.shadow.ZDepthParam; - -public class ShadowRect implements Shadow { - - private ShapeDrawable mTopShadow; - private ShapeDrawable mBottomShadow; - private Rect mRectTopShadow; - private Rect mRectBottomShadow; - - public ShadowRect() { - mRectTopShadow = new Rect(); - mRectBottomShadow = new Rect(); - mTopShadow = new ShapeDrawable(new RectShape()); - mBottomShadow = new ShapeDrawable(new RectShape()); - } - - @Override public void setParameter(ZDepthParam param, int left, int top, int right, int bottom) { - mRectTopShadow.left = left; - mRectTopShadow.top = (int) (top + param.mOffsetYTopShadowPx); - mRectTopShadow.right = right; - mRectTopShadow.bottom = (int) (bottom + param.mOffsetYTopShadowPx); - mRectBottomShadow.left = left; - mRectBottomShadow.top = (int) (top + param.mOffsetYBottomShadowPx); - mRectBottomShadow.right = right; - mRectBottomShadow.bottom = (int) (bottom + param.mOffsetYBottomShadowPx); - mTopShadow.getPaint().setColor(Color.argb(param.mAlphaTopShadow, 0, 0, 0)); - if (0 < param.mBlurTopShadowPx) { - mTopShadow.getPaint().setMaskFilter(new BlurMaskFilter(param.mBlurTopShadowPx, BlurMaskFilter.Blur.NORMAL)); - } else { - mTopShadow.getPaint().setMaskFilter(null); - } - mBottomShadow.getPaint().setColor(Color.argb(param.mAlphaBottomShadow, 0, 0, 0)); - if (0 < param.mBlurBottomShadowPx) { - mBottomShadow.getPaint().setMaskFilter(new BlurMaskFilter(param.mBlurBottomShadowPx, BlurMaskFilter.Blur.NORMAL)); - } else { - mBottomShadow.getPaint().setMaskFilter(null); - } - } - - @Override public void onDraw(Canvas canvas) { - canvas.drawRect(mRectBottomShadow, mBottomShadow.getPaint()); - canvas.drawRect(mRectTopShadow, mTopShadow.getPaint()); - } - -} \ No newline at end of file diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java b/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java deleted file mode 100644 index 4805598..0000000 --- a/draggablepanel/src/main/java/com/github/pedrovgs/shadow/util/DisplayUtils.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.pedrovgs.shadow.util; - -import android.content.Context; - -public class DisplayUtils { - public static int convertDpToPx(Context context, float dp) { - float scale = context.getResources().getDisplayMetrics().density; - return (int) (dp * scale + 0.5f); - } -} \ No newline at end of file From 4c1500e9ff3f5713e6c06f520f50dc81bc661bf9 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 11:14:42 -0300 Subject: [PATCH 04/11] some travis CI issues solved --- .../java/com/github/pedrovgs/transformer/ResizeTransformer.java | 2 +- .../java/com/github/pedrovgs/transformer/ScaleTransformer.java | 2 +- .../com/github/pedrovgs/transformer/TransformerFactory.java | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java index 8e51183..13c3f60 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java @@ -65,7 +65,7 @@ public void updatePosition(float verticalDragOffset) { right = layoutParams.width; break; case Transformer.CENTER: - right = layoutParams.width/2; + right = layoutParams.width / 2; left = right; break; case Transformer.RIGHT: diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java index 1d64529..a5cd858 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java @@ -107,7 +107,7 @@ private float generateHorizontalPivot() { case Transformer.LEFT: return getMarginLeft(); case Transformer.CENTER: - return getView().getWidth()/2; + return getView().getWidth() / 2; case Transformer.RIGHT: default: return getView().getWidth() - getMarginRight(); diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java index 179ac5a..5375223 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/TransformerFactory.java @@ -15,8 +15,6 @@ */ package com.github.pedrovgs.transformer; -import android.content.res.TypedArray; -import android.util.AttributeSet; import android.view.View; /** From 653df0aafb0426957de86c9f75e5fd8a50a2d0ae Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 11:19:54 -0300 Subject: [PATCH 05/11] fix on tvShowActivity --- .../com/github/pedrovgs/sample/activity/TvShowsActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java index 45a69a9..2fda938 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java @@ -35,7 +35,6 @@ import com.github.pedrovgs.sample.renderer.rendererbuilder.EpisodeRendererBuilder; import com.github.pedrovgs.sample.viewmodel.EpisodeViewModel; import com.github.pedrovgs.sample.viewmodel.TvShowViewModel; -import com.github.pedrovgs.transformer.Transformer; import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.RendererAdapter; import com.squareup.picasso.Picasso; From d5e7591c6d52690d337c6d5a0155478fc3aef656 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 11:54:47 -0300 Subject: [PATCH 06/11] add setTopFragmentMargin --- draggablepanel/res/values/attrs.xml | 2 ++ .../src/main/java/com/github/pedrovgs/DraggablePanel.java | 8 ++++++++ .../src/main/java/com/github/pedrovgs/DraggableView.java | 6 ++++++ .../java/com/github/pedrovgs/transformer/Transformer.java | 8 ++++++++ sample/res/layout/activity_tv_shows_sample.xml | 3 --- sample/res/layout/activity_video_sample.xml | 5 +++-- sample/res/layout/activity_youtube_sample.xml | 5 +---- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/draggablepanel/res/values/attrs.xml b/draggablepanel/res/values/attrs.xml index 0300dbe..13136ba 100644 --- a/draggablepanel/res/values/attrs.xml +++ b/draggablepanel/res/values/attrs.xml @@ -4,6 +4,7 @@ + @@ -22,6 +23,7 @@ + diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index f8f11f1..0f0d941 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -51,6 +51,7 @@ public class DraggablePanel extends FrameLayout { private Fragment topFragment; private Fragment bottomFragment; private int topFragmentHeight; + private int topFragmentMargin; private int topFragmentMarginTop; private int topFragmentMarginBottom; private int topFragmentMarginLeft; @@ -215,6 +216,10 @@ public void setYScaleFactor(float yScaleFactor) { this.yScaleFactor = yScaleFactor; } + public void setTopFragmentMargin(int topFragmentMargin) { + this.topFragmentMargin = topFragmentMargin; + } + /** * Configure the top Fragment margin top applied when the view has been minimized. * @@ -316,6 +321,7 @@ public void initializeView() { draggableView.attachTopFragment(topFragment); draggableView.setXTopViewScaleFactor(xScaleFactor); draggableView.setYTopViewScaleFactor(yScaleFactor); + draggableView.setTopViewMargin(topFragmentMargin); draggableView.setTopViewMarginTop(topFragmentMarginTop); draggableView.setTopViewMarginLeft(topFragmentMarginLeft); draggableView.setTopViewMarginBottom(topFragmentMarginBottom); @@ -382,6 +388,8 @@ private void initializeAttrs(AttributeSet attrs) { DEFAULT_SCALE_FACTOR)); setYScaleFactor(attributes.getFloat(R.styleable.draggable_panel_y_scale_factor, DEFAULT_SCALE_FACTOR)); + setTopFragmentMargin(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin, + DEFAULT_TOP_FRAGMENT_MARGIN)); setTopFragmentMarginTop(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_top, DEFAULT_TOP_FRAGMENT_MARGIN)); setTopFragmentMarginBottom(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_margin_bottom, diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index e555656..b86f884 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -180,6 +180,10 @@ public void setYTopViewScaleFactor(float yScaleFactor) { transformer.setYScaleFactor(yScaleFactor); } + public void setTopViewMargin(int topViewMargin) { + transformer.setMargins(topViewMargin); + } + /** * Configure the dragView margin left applied when the dragView is minimized. * @@ -686,6 +690,8 @@ private void initializeTransformer(TypedArray attributes) { DEFAULT_SCALE_FACTOR)); setYTopViewScaleFactor(attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, DEFAULT_SCALE_FACTOR)); + setTopViewMargin(attributes.getDimensionPixelOffset(R.styleable.draggable_view_top_view_margin, + DEFAULT_TOP_VIEW_MARGIN)); setTopViewMarginTop(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_top, DEFAULT_TOP_VIEW_MARGIN)); setTopViewMarginBottom(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom, diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java index 39ce7db..a5e87f5 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java @@ -86,6 +86,14 @@ public void setYScaleFactor(float yScaleFactor) { this.yScaleFactor = yScaleFactor; } + public void setMargins(int margins) { + margins = Math.round(margins); + this.marginLeft = margins; + this.marginRight = margins; + this.marginTop = margins; + this.marginBottom = margins; + } + public int getMarginLeft() { return marginLeft; } diff --git a/sample/res/layout/activity_tv_shows_sample.xml b/sample/res/layout/activity_tv_shows_sample.xml index bcc9bac..13c3f66 100644 --- a/sample/res/layout/activity_tv_shows_sample.xml +++ b/sample/res/layout/activity_tv_shows_sample.xml @@ -30,9 +30,6 @@ draggable_view:top_view_margin_bottom="@dimen/top_fragment_margin" draggable_view:top_view_margin_left="@dimen/top_fragment_margin" draggable_view:top_view_margin_right="@dimen/top_fragment_margin" - draggable_view:drag_limit_view="0.5" - draggable_view:position="right" - draggable_view:top_view_resize="true" android:background="@color/black"> diff --git a/sample/res/layout/activity_video_sample.xml b/sample/res/layout/activity_video_sample.xml index b171f46..4e45db8 100644 --- a/sample/res/layout/activity_video_sample.xml +++ b/sample/res/layout/activity_video_sample.xml @@ -25,10 +25,11 @@ draggable_view:top_view_x_scale_factor="@dimen/x_scale_factor" draggable_view:top_view_y_scale_factor="@dimen/y_scale_factor" draggable_view:top_view_height="@dimen/top_fragment_height" - draggable_view:top_view_margin_right="@dimen/top_fragment_margin" + draggable_view:top_view_margin_top="@dimen/top_fragment_margin" draggable_view:top_view_margin_bottom="@dimen/top_fragment_margin" + draggable_view:top_view_margin_left="@dimen/top_fragment_margin" + draggable_view:top_view_margin_right="@dimen/top_fragment_margin" draggable_view:enable_minimized_horizontal_alpha_effect="false" - draggable_view:position="left" android:background="@color/black"> diff --git a/sample/res/layout/activity_youtube_sample.xml b/sample/res/layout/activity_youtube_sample.xml index e77124f..966cc84 100644 --- a/sample/res/layout/activity_youtube_sample.xml +++ b/sample/res/layout/activity_youtube_sample.xml @@ -27,9 +27,6 @@ draggable_panel:top_fragment_margin_bottom="@dimen/top_fragment_margin" draggable_panel:top_fragment_margin_left="@dimen/top_fragment_margin" draggable_panel:top_fragment_margin_right="@dimen/top_fragment_margin" - draggable_panel:enable_horizontal_alpha_effect="false" - draggable_panel:position="center" - draggable_panel:top_view_resize="true" - draggable_panel:drag_limit_panel="0.9"/> + draggable_panel:enable_horizontal_alpha_effect="false"/> \ No newline at end of file From ef3e7092c87462bc23642750f4f887511f3c147a Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Wed, 11 Mar 2015 12:00:31 -0300 Subject: [PATCH 07/11] some updates on readme and minor changes --- README.md | 4 ++++ draggablepanel/res/values/attrs.xml | 2 -- .../src/main/java/com/github/pedrovgs/DraggablePanel.java | 5 +++++ .../src/main/java/com/github/pedrovgs/DraggableView.java | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 031d2d3..a4da1f2 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,8 @@ You can customize some of the view effects programatically or using xml styleabl * Draggable view margin bottom applied when the view is minimized. * Enable or disable the horizontal alpha effect applied while the view is being horizontally dragged. * Enable or disable touch on minimized/maximized view to minimize/maximize. +* Set the minimized view to the left, center and right +* Change the drag limit, between 0.0 and 1.0 ```xml diff --git a/draggablepanel/res/values/attrs.xml b/draggablepanel/res/values/attrs.xml index 13136ba..9d068e6 100644 --- a/draggablepanel/res/values/attrs.xml +++ b/draggablepanel/res/values/attrs.xml @@ -14,7 +14,6 @@ - @@ -33,7 +32,6 @@ - diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index 0f0d941..3da18a2 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -216,6 +216,11 @@ public void setYScaleFactor(float yScaleFactor) { this.yScaleFactor = yScaleFactor; } + /** + * Configure all margins of the dragView and are applied when the dragView is minimized. + * + * @param topFragmentMargin in pixels. + */ public void setTopFragmentMargin(int topFragmentMargin) { this.topFragmentMargin = topFragmentMargin; } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index b86f884..3348b3c 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -180,6 +180,11 @@ public void setYTopViewScaleFactor(float yScaleFactor) { transformer.setYScaleFactor(yScaleFactor); } + /** + * Configure all margins of the dragView and are applied when the dragView is minimized. + * + * @param topViewMargin in pixels. + */ public void setTopViewMargin(int topViewMargin) { transformer.setMargins(topViewMargin); } From 47171499950bbc6302c75c29e5161474dec0a81a Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Mon, 6 Apr 2015 09:57:49 -0300 Subject: [PATCH 08/11] some updates on draggableView and tests --- .../src/main/java/com/github/pedrovgs/DraggablePanel.java | 1 - .../src/main/java/com/github/pedrovgs/DraggableView.java | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index 3da18a2..bf5ad2e 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -318,7 +318,6 @@ public void minimize() { public void initializeView() { checkFragmentConsistency(); checkSupportFragmentManagerConsistency(); - inflate(getContext(), R.layout.draggable_panel, this); draggableView = (DraggableView) findViewById(R.id.draggable_view); draggableView.setTopViewHeight(topFragmentHeight); diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index 3348b3c..f970657 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -49,8 +49,6 @@ public class DraggableView extends RelativeLayout { private static final boolean DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT = true; private static final boolean DEFAULT_ENABLE_CLICK_TO_MAXIMIZE = false; private static final boolean DEFAULT_ENABLE_CLICK_TO_MINIMIZE = false; - private static final boolean DEFAULT_ENABLE_TOUCH_LISTENER = true; - private static final int DEFAULT_POSITION = 0; private static final int MIN_SLIDING_DISTANCE_ON_CLICK = 10; private static final int ONE_HUNDRED = 100; private static final float SENSITIVITY = 1f; @@ -72,7 +70,6 @@ public class DraggableView extends RelativeLayout { private boolean enableClickToMaximize; private boolean enableClickToMinimize; private boolean touchEnabled; - private int position; private DraggableListener listener; @@ -717,7 +714,6 @@ private void initializeTransformer(TypedArray attributes) { */ private void initializeAttributes(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_view); - attributePosition = getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position); setHorizontalAlphaEffectEnabled(attributes.getBoolean( R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect, DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT)); @@ -725,6 +721,7 @@ private void initializeAttributes(AttributeSet attrs) { DEFAULT_ENABLE_CLICK_TO_MAXIMIZE)); setClickToMinimizeEnabled(attributes.getBoolean(R.styleable.draggable_view_enable_click_to_minimize_view, DEFAULT_ENABLE_CLICK_TO_MINIMIZE)); + this.attributePosition = getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position); this.attributes = attributes; } From 10b85585ed73a8259d4897144dd7c0b8cc236b97 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Mon, 6 Apr 2015 11:24:11 -0300 Subject: [PATCH 09/11] some updates on draggableView and tests --- .../com/github/pedrovgs/DraggablePanel.java | 7 ++--- .../com/github/pedrovgs/DraggableView.java | 13 ++++++--- .../pedrovgs/DraggableViewCallback.java | 19 ++++++------- .../github/pedrovgs/transformer/Position.java | 27 +++++++++++++++++++ .../transformer/ResizeTransformer.java | 6 ++--- .../transformer/ScaleTransformer.java | 6 ++--- .../pedrovgs/transformer/Transformer.java | 4 --- .../sample/activity/TvShowsActivity.java | 3 ++- .../sample/activity/VideoSampleActivity.java | 2 +- .../activity/YoutubeSampleActivity.java | 8 +++--- 10 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 draggablepanel/src/main/java/com/github/pedrovgs/transformer/Position.java diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java index bf5ad2e..8836e67 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java @@ -21,6 +21,7 @@ import android.support.v4.app.FragmentManager; import android.util.AttributeSet; import android.widget.FrameLayout; +import com.github.pedrovgs.transformer.Position; import com.github.pedrovgs.transformer.Transformer; /** @@ -383,9 +384,6 @@ public boolean isClosedAtLeft() { */ private void initializeAttrs(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_panel); - setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position) - .getInt(R.styleable.top_view_position_position, - Transformer.RIGHT)); setTopFragmentHeight(attributes.getDimensionPixelSize(R.styleable.draggable_panel_top_fragment_height, DEFAULT_TOP_FRAGMENT_HEIGHT)); setXScaleFactor(attributes.getFloat(R.styleable.draggable_panel_x_scale_factor, @@ -412,6 +410,9 @@ private void initializeAttrs(AttributeSet attrs) { DEFAULT_ENABLE_TOUCH_LISTENER)); setDragLimit(attributes.getFloat(R.styleable.draggable_panel_drag_limit_panel, Transformer.DEFAULT_DRAG_LIMIT)); + setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position) + .getInt(R.styleable.top_view_position_position, + Position.RIGHT)); attributes.recycle(); } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java index f970657..4f426df 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java @@ -27,6 +27,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.RelativeLayout; +import com.github.pedrovgs.transformer.Position; import com.github.pedrovgs.transformer.Transformer; import com.github.pedrovgs.transformer.TransformerFactory; import com.nineoldandroids.view.ViewHelper; @@ -63,6 +64,7 @@ public class DraggableView extends RelativeLayout { private FragmentManager fragmentManager; private ViewDragHelper viewDragHelper; + private DraggableViewCallback draggableViewCallback; private Transformer transformer; private boolean enableHorizontalAlphaEffect; @@ -256,10 +258,11 @@ public void setHorizontalAlphaEffectEnabled(boolean enableHorizontalAlphaEffect) /** * Configure the DraggableListener notified when the view is minimized, maximized, closed to the - * right or closed to the left. + * right or closed to the left and the actual position on Y axis. */ public void setDraggableListener(DraggableListener listener) { this.listener = listener; + draggableViewCallback.setDraggableListener(listener); } /** @@ -673,7 +676,9 @@ private void addFragmentToView(final int viewId, final Fragment fragment) { * Initialize the viewDragHelper. */ private void initializeViewDragHelper() { - viewDragHelper = ViewDragHelper.create(this, SENSITIVITY, new DraggableViewCallback(this, dragView, listener)); + draggableViewCallback = new DraggableViewCallback(this, dragView, listener, + (int) getVerticalDragRange()); + viewDragHelper = ViewDragHelper.create(this, SENSITIVITY, draggableViewCallback); } /** @@ -684,8 +689,6 @@ private void initializeTransformer(TypedArray attributes) { attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE); TransformerFactory transformerFactory = new TransformerFactory(); transformer = transformerFactory.getTransformer(topViewResize, dragView, this); - setDragViewPosition(attributePosition.getInt(R.styleable.top_view_position_position, - Transformer.RIGHT)); setTopViewHeight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height, DEFAULT_TOP_VIEW_HEIGHT)); setXTopViewScaleFactor(attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, @@ -704,6 +707,8 @@ private void initializeTransformer(TypedArray attributes) { DEFAULT_TOP_VIEW_MARGIN)); setDragLimit(attributes.getFloat(R.styleable.draggable_view_drag_limit_view, Transformer.DEFAULT_DRAG_LIMIT)); + setDragViewPosition(attributePosition.getInt(R.styleable.top_view_position_position, + Position.RIGHT)); attributes.recycle(); } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java index a224826..46e1e5a 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java @@ -31,7 +31,6 @@ class DraggableViewCallback extends ViewDragHelper.Callback { private static final float X_MIN_VELOCITY = 1500; private static final float Y_MIN_VELOCITY = 1000; - private boolean listenerEnabled; private int verticalDragRange = 0; private DraggableListener draggableListener; @@ -43,18 +42,16 @@ class DraggableViewCallback extends ViewDragHelper.Callback { * * @param draggableView instance used to apply some animations or visual effects. */ - public DraggableViewCallback(DraggableView draggableView, View draggedView, DraggableListener draggableListener) { + public DraggableViewCallback(DraggableView draggableView, View draggedView, + DraggableListener draggableListener, int height) { this.draggableView = draggableView; this.draggedView = draggedView; this.draggableListener = draggableListener; + this.verticalDragRange = height; } - public void setListenerEnabled(boolean listenerEnabled) { - this.listenerEnabled = listenerEnabled; - } - - public void setVerticalDragRange(int verticalDragRange) { - this.verticalDragRange = verticalDragRange; + public void setDraggableListener(DraggableListener draggableListener) { + this.draggableListener = draggableListener; } private int getVerticalDragRange() { @@ -82,12 +79,12 @@ private int getVerticalDragRange() { draggableView.changeBackgroundAlpha(); } - if (listenerEnabled) { - float fractionScreen = (float) Math.abs(top) / (float) getVerticalDragRange(); + if (draggableListener != null) { + float fractionScreen = (float) Math.abs(top) / (float) verticalDragRange; if (fractionScreen >= 1) { fractionScreen = 1; } - if (draggableListener != null) { + if(fractionScreen >= 0.0) { draggableListener.onTopViewSlide(fractionScreen); } } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Position.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Position.java new file mode 100644 index 0000000..f35f02e --- /dev/null +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Position.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 Pedro Vicente Gómez Sánchez. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.pedrovgs.transformer; + +/** + * This class represent the position of the top view + * + * @author Pedro Paulo de Amorim + */ +public class Position { + public static final int LEFT = 0; + public static final int CENTER = 1; + public static final int RIGHT = 2; +} diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java index 13c3f60..5b5fbf3 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ResizeTransformer.java @@ -60,15 +60,15 @@ public void updatePosition(float verticalDragOffset) { int bottom = top + layoutParams.height; switch (getViewPosition()) { - case Transformer.LEFT: + case Position.LEFT: left = getViewLeftPosition(verticalDragOffset); right = layoutParams.width; break; - case Transformer.CENTER: + case Position.CENTER: right = layoutParams.width / 2; left = right; break; - case Transformer.RIGHT: + case Position.RIGHT: default: right = getViewRightPosition(verticalDragOffset); left = right - layoutParams.width; diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java index a5cd858..1a7dd85 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/ScaleTransformer.java @@ -104,11 +104,11 @@ class ScaleTransformer extends Transformer { private float generateHorizontalPivot() { switch (getViewPosition()) { - case Transformer.LEFT: + case Position.LEFT: return getMarginLeft(); - case Transformer.CENTER: + case Position.CENTER: return getView().getWidth() / 2; - case Transformer.RIGHT: + case Position.RIGHT: default: return getView().getWidth() - getMarginRight(); } diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java index a5e87f5..639325e 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/transformer/Transformer.java @@ -36,10 +36,6 @@ public abstract class Transformer { public static final float DEFAULT_DRAG_LIMIT = 0.5f; - public static final int LEFT = 0; - public static final int CENTER = 1; - public static final int RIGHT = 2; - private final View view; private final View parent; diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java index 2fda938..220db1b 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/TvShowsActivity.java @@ -70,9 +70,10 @@ public class TvShowsActivity extends DIFragmentActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tv_shows_sample); ButterKnife.inject(this); + hookListeners(); initializeDraggableView(); initializeGridView(); - hookListeners(); + } /** diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java index 583c43a..d9cfb08 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/VideoSampleActivity.java @@ -58,9 +58,9 @@ public class VideoSampleActivity extends FragmentActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_sample); ButterKnife.inject(this); + hookDraggableViewListener(); initializeVideoView(); initializePoster(); - hookDraggableViewListener(); } /** diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java index b471400..d2648cd 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java @@ -61,8 +61,8 @@ public class YoutubeSampleActivity extends FragmentActivity { setContentView(R.layout.activity_youtube_sample); ButterKnife.inject(this); initializeYoutubeFragment(); - initializeDraggablePanel(); hookDraggablePanelListeners(); + initializeDraggablePanel(); } /** @@ -123,9 +123,7 @@ private void hookDraggablePanelListeners() { playVideo(); } - @Override public void onMinimized() { - //Empty - } + @Override public void onMinimized() {} @Override public void onClosedToLeft() { pauseVideo(); @@ -136,7 +134,7 @@ private void hookDraggablePanelListeners() { } @Override public void onTopViewSlide(float scroll) { - + System.out.println("scroll: " + scroll); } }); } From 51c689b478d524e406e0daced49b7355a7f62b16 Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Mon, 6 Apr 2015 11:31:44 -0300 Subject: [PATCH 10/11] fix on travis CI error --- .../main/java/com/github/pedrovgs/DraggableViewCallback.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java index 46e1e5a..ba93cc6 100644 --- a/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java +++ b/draggablepanel/src/main/java/com/github/pedrovgs/DraggableViewCallback.java @@ -84,7 +84,7 @@ private int getVerticalDragRange() { if (fractionScreen >= 1) { fractionScreen = 1; } - if(fractionScreen >= 0.0) { + if (fractionScreen >= 0.0) { draggableListener.onTopViewSlide(fractionScreen); } } From acbeab8d0288d385d8cb93c7e6918bb6df89f00f Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Mon, 6 Apr 2015 15:04:10 -0300 Subject: [PATCH 11/11] fix on travis CI error --- .../pedrovgs/sample/activity/YoutubeSampleActivity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java index d2648cd..98e279b 100644 --- a/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java +++ b/sample/src/main/java/com/github/pedrovgs/sample/activity/YoutubeSampleActivity.java @@ -123,7 +123,7 @@ private void hookDraggablePanelListeners() { playVideo(); } - @Override public void onMinimized() {} + @Override public void onMinimized() { } @Override public void onClosedToLeft() { pauseVideo(); @@ -133,9 +133,7 @@ private void hookDraggablePanelListeners() { pauseVideo(); } - @Override public void onTopViewSlide(float scroll) { - System.out.println("scroll: " + scroll); - } + @Override public void onTopViewSlide(float scroll) { } }); }