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

Commit

Permalink
Merge pull request #74 from Mariovc/develop
Browse files Browse the repository at this point in the history
Added method to configure DraggablePanel to resize
  • Loading branch information
pedrovgs committed Nov 29, 2015
2 parents 7788612 + 2cd74a6 commit 9a958f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public void setEnableHorizontalAlphaEffect(boolean enableHorizontalAlphaEffect)
this.enableHorizontalAlphaEffect = enableHorizontalAlphaEffect;
}

/**
* Configure the top Fragment to resize instead of scale it.
*/
public void setTopFragmentResize(boolean topViewResize) {
draggableView.setTopViewResize(topViewResize);
}

/**
* Close the custom view applying an animation to close the view to the left side of the screen.
*/
Expand Down
58 changes: 31 additions & 27 deletions draggablepanel/src/main/java/com/github/pedrovgs/DraggableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class DraggableView extends RelativeLayout {

private View dragView;
private View secondView;
private TypedArray attributes;

private FragmentManager fragmentManager;
private ViewDragHelper viewDragHelper;
Expand All @@ -72,6 +71,10 @@ public class DraggableView extends RelativeLayout {
private boolean touchEnabled;

private DraggableListener listener;
private int topViewHeight;
private float scaleFactorX, scaleFactorY;
private int marginBottom, marginRight;
private int dragViewId, secondViewId;

public DraggableView(Context context) {
super(context);
Expand Down Expand Up @@ -222,6 +225,7 @@ public void setDraggableListener(DraggableListener listener) {
*/
public void setTopViewResize(boolean topViewResize) {
this.topViewResize = topViewResize;
initializeTransformer();
}

/**
Expand Down Expand Up @@ -441,18 +445,13 @@ else if (isDragViewAtTop()) {
@Override protected void onFinishInflate() {
super.onFinishInflate();
if (!isInEditMode()) {
mapGUI(attributes);
initializeTransformer(attributes);
attributes.recycle();
mapGUI();
initializeTransformer();
initializeViewDragHelper();
}
}

private void mapGUI(TypedArray attributes) {
int dragViewId =
attributes.getResourceId(R.styleable.draggable_view_top_view_id, R.id.drag_view);
int secondViewId =
attributes.getResourceId(R.styleable.draggable_view_bottom_view_id, R.id.second_view);
private void mapGUI() {
dragView = findViewById(dragViewId);
secondView = findViewById(secondViewId);
}
Expand Down Expand Up @@ -642,25 +641,14 @@ private void initializeViewDragHelper() {
/**
* Initialize Transformer with a scalable or change width/height implementation.
*/
private void initializeTransformer(TypedArray attributes) {
topViewResize =
attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE);
private void initializeTransformer() {
TransformerFactory transformerFactory = new TransformerFactory();
transformer = transformerFactory.getTransformer(topViewResize, dragView, this);
transformer.setViewHeight(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,
DEFAULT_TOP_VIEW_MARGIN));
transformer.setMarginBottom(
attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom,
DEFAULT_TOP_VIEW_MARGIN));
transformer.setViewHeight(topViewHeight);
transformer.setXScaleFactor(scaleFactorX);
transformer.setYScaleFactor(scaleFactorY);
transformer.setMarginRight(marginRight);
transformer.setMarginBottom(marginBottom);
}

/**
Expand All @@ -679,7 +667,23 @@ private void initializeAttributes(AttributeSet attrs) {
this.enableClickToMinimize =
attributes.getBoolean(R.styleable.draggable_view_enable_click_to_minimize_view,
DEFAULT_ENABLE_CLICK_TO_MINIMIZE);
this.attributes = attributes;
this.topViewResize =
attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE);
this.topViewHeight = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height,
DEFAULT_TOP_VIEW_HEIGHT);
this.scaleFactorX = attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor,
DEFAULT_SCALE_FACTOR);
this.scaleFactorY = attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor,
DEFAULT_SCALE_FACTOR);
this.marginBottom = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom,
DEFAULT_TOP_VIEW_MARGIN);
this.marginRight = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right,
DEFAULT_TOP_VIEW_MARGIN);
this.dragViewId =
attributes.getResourceId(R.styleable.draggable_view_top_view_id, R.id.drag_view);
this.secondViewId =
attributes.getResourceId(R.styleable.draggable_view_bottom_view_id, R.id.second_view);
attributes.recycle();
}

/**
Expand Down

0 comments on commit 9a958f7

Please sign in to comment.