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

DragView positions and Drag Limit #58

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<com.github.pedrovgs.DraggableView
Expand All @@ -138,6 +140,8 @@ You can customize some of the view effects programatically or using xml styleabl
draggable_view:top_view_margin_bottom="@dimen/top_fragment_margin"
draggable_view:enable_click_to_maximize="false"
draggable_view:enable_click_to_minimize="true"
draggable_view:drag_limit_view="0.9"
draggable_view:position="left"
android:background="@color/black">

<!-- ....... -->
Expand Down
2 changes: 1 addition & 1 deletion draggablepanel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 18 additions & 2 deletions draggablepanel/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
<attr name="top_fragment_height" format="dimension"/>
<attr name="x_scale_factor" format="float"/>
<attr name="y_scale_factor" format="float"/>
<attr name="top_fragment_margin_right" format="dimension"/>
<attr name="top_fragment_margin" format="dimension"/>
<attr name="top_fragment_margin_top" format="dimension"/>
<attr name="top_fragment_margin_bottom" format="dimension"/>
<attr name="top_fragment_margin_left" format="dimension"/>
<attr name="top_fragment_margin_right" format="dimension"/>
<attr name="enable_horizontal_alpha_effect" format="boolean"/>
<attr name="enable_click_to_maximize_panel" format="boolean"/>
<attr name="enable_click_to_minimize_panel" format="boolean"/>
<attr name="enable_touch_listener_panel" format="boolean"/>
<attr name="drag_limit_panel" format="float"/>
</declare-styleable>

<declare-styleable name="draggable_view">
Expand All @@ -18,12 +22,24 @@
<attr name="top_view_height" format="dimension"/>
<attr name="top_view_x_scale_factor" format="float"/>
<attr name="top_view_y_scale_factor" format="float"/>
<attr name="top_view_margin_right" format="dimension"/>
<attr name="top_view_margin" format="dimension"/>
<attr name="top_view_margin_top" format="dimension"/>
<attr name="top_view_margin_bottom" format="dimension"/>
<attr name="top_view_margin_left" format="dimension"/>
<attr name="top_view_margin_right" format="dimension"/>
<attr name="enable_minimized_horizontal_alpha_effect" format="boolean"/>
<attr name="enable_click_to_maximize_view" format="boolean"/>
<attr name="enable_click_to_minimize_view" format="boolean"/>
<attr name="top_view_resize" format="boolean"/>
<attr name="drag_limit_view" format="float"/>
</declare-styleable>

<declare-styleable name="top_view_position">
<attr name="position" format="enum">
<enum name="left" value="0"/>
<enum name="center" value="1"/>
<enum name="right" value="2"/>
</attr>
</declare-styleable>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
139 changes: 107 additions & 32 deletions draggablepanel/src/main/java/com/github/pedrovgs/DraggablePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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;

/**
* Custom view created to handle DraggableView using fragments. With this custom view the client
Expand Down Expand Up @@ -50,14 +52,19 @@ public class DraggablePanel extends FrameLayout {
private Fragment topFragment;
private Fragment bottomFragment;
private int topFragmentHeight;
private int topFragmentMarginRight;
private int topFragmentMargin;
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);
Expand Down Expand Up @@ -145,6 +152,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.
Expand All @@ -161,6 +186,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.
Expand All @@ -178,12 +218,21 @@ public void setYScaleFactor(float yScaleFactor) {
}

/**
* Configure the top Fragment margin right applied when the view has been minimized.
* Configure all margins of the dragView and are applied when the dragView is minimized.
*
* @param topFragmentMarginRight in pixels.
* @param topFragmentMargin in pixels.
*/
public void setTopFragmentMarginRight(int topFragmentMarginRight) {
this.topFragmentMarginRight = topFragmentMarginRight;
public void setTopFragmentMargin(int topFragmentMargin) {
this.topFragmentMargin = topFragmentMargin;
}

/**
* Configure the top Fragment margin top applied when the view has been minimized.
*
* @param topFragmentMarginTop in pixels.
*/
public void setTopFragmentMarginTop(int topFragmentMarginTop) {
this.topFragmentMarginTop = topFragmentMarginTop;
}

/**
Expand All @@ -195,6 +244,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.
Expand Down Expand Up @@ -252,22 +319,26 @@ 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);
draggableView.setFragmentManager(fragmentManager);
draggableView.attachTopFragment(topFragment);
draggableView.setXTopViewScaleFactor(xScaleFactor);
draggableView.setYTopViewScaleFactor(yScaleFactor);
draggableView.setTopViewMarginRight(topFragmentMarginRight);
draggableView.setTopViewMargin(topFragmentMargin);
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);
}

/**
Expand Down Expand Up @@ -313,31 +384,35 @@ 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);
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));
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,
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));
setDragViewPosition(getContext().obtainStyledAttributes(attrs, R.styleable.top_view_position)
.getInt(R.styleable.top_view_position_position,
Position.RIGHT));
attributes.recycle();
}

Expand Down
Loading