From 500b3375ecbe185687bd8c6770001b3ff5316bb0 Mon Sep 17 00:00:00 2001 From: Pedro Paulo de Amorim Date: Fri, 15 May 2015 17:41:53 -0300 Subject: [PATCH 1/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9b6213..20df6db 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ dependencies { ``` -You will use with lists(RecyclerView, List/GridView, ScrollView)? +Will you use with lists(RecyclerView, List/GridView, ScrollView)? -------------------------------------------------------------------- I decided that need to be Out-Of-Box, then... From b0dd501e2c99ac3249e5f424b2f723099803d3f6 Mon Sep 17 00:00:00 2001 From: ppamorim Date: Mon, 25 May 2015 12:06:16 -0300 Subject: [PATCH 2/6] update --- .../dragger/ActivityListActivity.java | 4 +- .../github/ppamorim/dragger/ListActivity.java | 2 +- dragger/res/layout/lazy_dragger_panel.xml | 21 ++++++ .../ppamorim/dragger/BaseDraggerActivity.java | 19 ++++++ .../ppamorim/dragger/BaseDraggerPanel.java | 68 +++++++++++++++++++ .../ppamorim/dragger/DraggerActivity.java | 17 +---- .../github/ppamorim/dragger/DraggerPanel.java | 43 +----------- .../github/ppamorim/dragger/DraggerView.java | 10 ++- .../ppamorim/dragger/LazyDraggerActivity.java | 54 +++++++++++++++ .../ppamorim/dragger/LazyDraggerPanel.java | 61 +++++++++++++++++ .../ppamorim/dragger/LazyDraggerView.java | 30 ++++++++ 11 files changed, 268 insertions(+), 61 deletions(-) create mode 100644 dragger/res/layout/lazy_dragger_panel.xml create mode 100644 dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerActivity.java create mode 100644 dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerPanel.java create mode 100644 dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerActivity.java create mode 100644 dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerPanel.java create mode 100644 dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerView.java diff --git a/app/src/main/java/com/github/ppamorim/dragger/ActivityListActivity.java b/app/src/main/java/com/github/ppamorim/dragger/ActivityListActivity.java index 2be2ac5..d45d048 100644 --- a/app/src/main/java/com/github/ppamorim/dragger/ActivityListActivity.java +++ b/app/src/main/java/com/github/ppamorim/dragger/ActivityListActivity.java @@ -36,7 +36,7 @@ public void configRecyclerView() { recyclerView.setHasFixedSize(true); recyclerView.setItemAnimator(new DefaultItemAnimator()); LinearLayoutManager layoutManager = new LinearLayoutManager(this); - layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(new RendererAdapter(texts, new RendererBuilder(new Factory()))); recyclerView.setScrollViewCallbacks(observableScrollViewCallbacks); @@ -46,7 +46,7 @@ public void configRecyclerView() { new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { - setSlideEnabled(scrollY != 0); + setSlideEnabled(scrollY == 0); } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { } diff --git a/app/src/main/java/com/github/ppamorim/dragger/ListActivity.java b/app/src/main/java/com/github/ppamorim/dragger/ListActivity.java index f4bb84c..5a0a1eb 100644 --- a/app/src/main/java/com/github/ppamorim/dragger/ListActivity.java +++ b/app/src/main/java/com/github/ppamorim/dragger/ListActivity.java @@ -67,7 +67,7 @@ public void configRecyclerView() { new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { - draggerView.setSlideEnabled(scrollY != 0); + draggerView.setSlideEnabled(scrollY == 0); } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { } diff --git a/dragger/res/layout/lazy_dragger_panel.xml b/dragger/res/layout/lazy_dragger_panel.xml new file mode 100644 index 0000000..5f33490 --- /dev/null +++ b/dragger/res/layout/lazy_dragger_panel.xml @@ -0,0 +1,21 @@ + + + + + + + + \ No newline at end of file diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerActivity.java b/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerActivity.java new file mode 100644 index 0000000..dc5ad7f --- /dev/null +++ b/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerActivity.java @@ -0,0 +1,19 @@ +package com.github.ppamorim.dragger; + +import android.support.v7.app.AppCompatActivity; +import android.view.LayoutInflater; +import android.view.View; + +public class BaseDraggerActivity extends AppCompatActivity { + + public int shadowResID = -1; + + public void setShadowView(int shadowResID) { + this.shadowResID = shadowResID; + } + + public View inflateLayout(int layoutResID) { + return LayoutInflater.from(this).inflate(layoutResID, null); + } + +} diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerPanel.java b/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerPanel.java new file mode 100644 index 0000000..5727e1f --- /dev/null +++ b/dragger/src/main/java/com/github/ppamorim/dragger/BaseDraggerPanel.java @@ -0,0 +1,68 @@ +package com.github.ppamorim.dragger; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; + +public class BaseDraggerPanel extends FrameLayout { + + private static final float DEFAULT_DRAG_LIMIT = 0.5f; + private static final int DEFAULT_DRAG_POSITION = DraggerPosition.TOP.ordinal(); + + public TypedArray attributes; + public float draggerLimit; + public int draggerPosition; + + public FrameLayout dragView; + public FrameLayout shadowView; + + public BaseDraggerPanel(Context context) { + super(context); + } + + public BaseDraggerPanel(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public BaseDraggerPanel(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Apply all the custom view configuration and inflate the main view. The view won't be + * visible if this method is not called. + */ + public void initializeView(int layoutId) { + inflate(getContext(), layoutId, this); + dragView = (FrameLayout) findViewById(R.id.drag_view); + shadowView = (FrameLayout) findViewById(R.id.shadow_view); + } + + public void addViewOnShadow(View view) { + eraseViewIfNeeded(shadowView); + shadowView.addView(view); + } + + public void addViewOnDrag(View view) { + eraseViewIfNeeded(dragView); + dragView.addView(view); + } + + public void eraseViewIfNeeded(FrameLayout frameLayout) { + if (frameLayout.getChildCount() > 0) { + frameLayout.removeAllViews(); + } + } + + public void initializeAttributes(AttributeSet attrs) { + attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout); + if(attributes != null) { + draggerLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT); + draggerPosition = + attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION); + } + } + +} diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java index 31504d1..f454a46 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java @@ -15,13 +15,8 @@ */ package com.github.ppamorim.dragger; -import android.support.v7.app.AppCompatActivity; -import android.view.LayoutInflater; -import android.view.View; +public class DraggerActivity extends BaseDraggerActivity { -public class DraggerActivity extends AppCompatActivity { - - private int shadowResID = -1; private DraggerPanel draggerPanel; @Override public void setContentView(int layoutResID) { @@ -34,13 +29,9 @@ public DraggerPanel getDraggerPanel() { return draggerPanel; } - public void setShadowView(int shadowResID) { - this.shadowResID = shadowResID; - } - private void configDraggerView() { draggerPanel = new DraggerPanel(this); - draggerPanel.initializeView(); + draggerPanel.initializeView(R.layout.dragger_panel); } private void configViews(int layoutResID) { @@ -51,10 +42,6 @@ private void configViews(int layoutResID) { draggerPanel.addViewOnShadow(inflateLayout(shadowResID)); } - private View inflateLayout(int layoutResID) { - return LayoutInflater.from(this).inflate(layoutResID, null); - } - public void setDraggerPosition(DraggerPosition dragPosition) { draggerPanel.setDraggerPosition(dragPosition); } diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java index 0588c81..063f425 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java @@ -16,23 +16,12 @@ package com.github.ppamorim.dragger; import android.content.Context; -import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; -import android.widget.FrameLayout; -public class DraggerPanel extends FrameLayout { - - private static final float DEFAULT_DRAG_LIMIT = 0.5f; - private static final int DEFAULT_DRAG_POSITION = DraggerPosition.TOP.ordinal(); - - private TypedArray attributes; - private float draggerLimit; - private int draggerPosition; +public class DraggerPanel extends BaseDraggerPanel { private DraggerView draggerView; - private FrameLayout dragView; - private FrameLayout shadowView; public DraggerPanel(Context context) { super(context); @@ -68,24 +57,9 @@ public void setSlideEnabled(boolean enabled) { draggerView.setSlideEnabled(enabled); } - private void initializeAttributes(AttributeSet attrs) { - attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout); - if(attributes != null) { - draggerLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT); - draggerPosition = - attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION); - } - } - - /** - * Apply all the custom view configuration and inflate the main view. The view won't be - * visible if this method is not called. - */ - public void initializeView() { - inflate(getContext(), R.layout.dragger_panel, this); + @Override public void initializeView(int layoutId) { + super.initializeView(layoutId); draggerView = (DraggerView) findViewById(R.id.dragger_view); - dragView = (FrameLayout) findViewById(R.id.drag_view); - shadowView = (FrameLayout) findViewById(R.id.shadow_view); if(attributes != null) { setDraggerLimit(draggerLimit); setDraggerPosition(DraggerPosition.getDragPosition(draggerPosition)); @@ -97,17 +71,6 @@ public void addViewOnDrag(View view) { dragView.addView(view); } - public void addViewOnShadow(View view) { - eraseViewIfNeeded(shadowView); - shadowView.addView(view); - } - - private void eraseViewIfNeeded(FrameLayout frameLayout) { - if (frameLayout.getChildCount() > 0) { - frameLayout.removeAllViews(); - } - } - public void closeActivity() { draggerView.closeActivity(); } diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java index 5f88203..2e2fd80 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java @@ -118,7 +118,7 @@ public DraggerView(Context context, AttributeSet attrs, int defStyle) { } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!isEnabled() || canSlide()) { + if (!isEnabled() || !canSlide()) { return false; } final int action = MotionEventCompat.getActionMasked(ev); @@ -280,16 +280,20 @@ public void expandWithDelay() { }, DELAY); } - private void showViews() { + protected void showViews() { setViewAlpha(dragView, MAX_ALPHA); shadowView.setVisibility(VISIBLE); } - private void openActivity() { + public void openActivity() { animationFinish = true; moveToCenter(); } + public void setCanFinish(Boolean canFinish) { + this.canFinish = canFinish; + } + public void closeActivity() { if (dragPosition != null) { switch (dragPosition) { diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerActivity.java b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerActivity.java new file mode 100644 index 0000000..3fbf73d --- /dev/null +++ b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerActivity.java @@ -0,0 +1,54 @@ +package com.github.ppamorim.dragger; + +public class LazyDraggerActivity extends BaseDraggerActivity { + + private LazyDraggerPanel lazyDraggerPanel; + + @Override public void setContentView(int layoutResID) { + configDraggerView(); + configViews(layoutResID); + super.setContentView(lazyDraggerPanel); + } + + public LazyDraggerPanel getDraggerPanel() { + return lazyDraggerPanel; + } + + private void configDraggerView() { + lazyDraggerPanel = new LazyDraggerPanel(this); + lazyDraggerPanel.initializeView(R.layout.lazy_dragger_panel); + } + + private void configViews(int layoutResID) { + lazyDraggerPanel.addViewOnDrag(inflateLayout(layoutResID)); + if (shadowResID == -1) { + shadowResID = R.layout.layout_shadow; + } + lazyDraggerPanel.addViewOnShadow(inflateLayout(shadowResID)); + } + + public void setDraggerPosition(DraggerPosition dragPosition) { + lazyDraggerPanel.setLazyDraggerPosition(dragPosition); + } + + public void setDraggerLimit(float dragLimit) { + lazyDraggerPanel.setLazyDraggerLimit(dragLimit); + } + + public void setDraggerCallback(DraggerCallback draggerCallback) { + lazyDraggerPanel.setLazyDraggerCallback(draggerCallback); + } + + public void setSlideEnabled(boolean enabled) { + lazyDraggerPanel.setSlideEnabled(enabled); + } + + public void closeActivity() { + lazyDraggerPanel.closeActivity(); + } + + public void expand() { + lazyDraggerPanel.expand(); + } + +} diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerPanel.java b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerPanel.java new file mode 100644 index 0000000..7d27cb7 --- /dev/null +++ b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerPanel.java @@ -0,0 +1,61 @@ +package com.github.ppamorim.dragger; + +import android.content.Context; +import android.util.AttributeSet; + +public class LazyDraggerPanel extends BaseDraggerPanel { + + private LazyDraggerView lazyDraggerView; + + public LazyDraggerPanel(Context context) { + super(context); + } + + public LazyDraggerPanel(Context context, AttributeSet attrs) { + super(context, attrs); + initializeAttributes(attrs); + } + + public LazyDraggerPanel(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + initializeAttributes(attrs); + } + + public LazyDraggerView getLazyDraggerView() { + return lazyDraggerView; + } + + public void setLazyDraggerLimit(float draggerLimit) { + lazyDraggerView.setDraggerLimit(draggerLimit); + } + + public void setLazyDraggerPosition(DraggerPosition dragPosition) { + lazyDraggerView.setDraggerPosition(dragPosition); + } + + public void setLazyDraggerCallback(DraggerCallback draggerCallback) { + lazyDraggerView.setDraggerCallback(draggerCallback); + } + + public void setSlideEnabled(boolean enabled) { + lazyDraggerView.setSlideEnabled(enabled); + } + + @Override public void initializeView(int layoutId) { + super.initializeView(layoutId); + lazyDraggerView = (LazyDraggerView) findViewById(R.id.dragger_view); + if(attributes != null) { + setLazyDraggerLimit(draggerLimit); + setLazyDraggerPosition(DraggerPosition.getDragPosition(draggerPosition)); + } + } + + public void closeActivity() { + lazyDraggerView.closeActivity(); + } + + public void expand() { + lazyDraggerView.expand(); + } + +} diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerView.java b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerView.java new file mode 100644 index 0000000..fc372ce --- /dev/null +++ b/dragger/src/main/java/com/github/ppamorim/dragger/LazyDraggerView.java @@ -0,0 +1,30 @@ +package com.github.ppamorim.dragger; + +import android.content.Context; +import android.util.AttributeSet; + +public class LazyDraggerView extends DraggerView { + + public LazyDraggerView(Context context) { + super(context); + } + + public LazyDraggerView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LazyDraggerView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override public void expandWithDelay() {} + + public void expand() { + if (isEnabled()) { + showViews(); + openActivity(); + setCanFinish(true); + } + } + +} From 5dc9d297f13c84bfdd2efd114341e255ace8648a Mon Sep 17 00:00:00 2001 From: ppamorim Date: Mon, 25 May 2015 12:53:33 -0300 Subject: [PATCH 3/6] update --- app/AndroidManifest.xml | 1 + app/res/layout/activity_base.xml | 9 +++++++ app/res/values/strings.xml | 1 + .../github/ppamorim/dragger/BaseActivity.java | 4 ++++ .../github/ppamorim/dragger/LazyActivity.java | 24 +++++++++++++++++++ dragger/res/layout/lazy_dragger_panel.xml | 4 ++-- .../ppamorim/dragger/DraggerActivity.java | 2 +- .../github/ppamorim/dragger/DraggerPanel.java | 4 ++-- .../ppamorim/dragger/LazyDraggerActivity.java | 2 +- .../ppamorim/dragger/LazyDraggerPanel.java | 4 ++-- 10 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/github/ppamorim/dragger/LazyActivity.java diff --git a/app/AndroidManifest.xml b/app/AndroidManifest.xml index 5cba665..18d8466 100644 --- a/app/AndroidManifest.xml +++ b/app/AndroidManifest.xml @@ -19,6 +19,7 @@ + diff --git a/app/res/layout/activity_base.xml b/app/res/layout/activity_base.xml index 03244ea..9b2127d 100644 --- a/app/res/layout/activity_base.xml +++ b/app/res/layout/activity_base.xml @@ -16,6 +16,15 @@ android:gravity="center" android:orientation="vertical"> +