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..ffd4ba3 100644
--- a/app/res/layout/activity_base.xml
+++ b/app/res/layout/activity_base.xml
@@ -9,93 +9,107 @@
-
-
-
+ android:layout_height="match_parent">
-
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:orientation="vertical">
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/app/res/values/strings.xml b/app/res/values/strings.xml
index 8071995..c7aa05f 100644
--- a/app/res/values/strings.xml
+++ b/app/res/values/strings.xml
@@ -1,6 +1,7 @@
Dragger
Hi!
+ Lazy
EditText
List
Activity List
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/BaseActivity.java b/app/src/main/java/com/github/ppamorim/dragger/BaseActivity.java
index 6f63569..fbafbb2 100644
--- a/app/src/main/java/com/github/ppamorim/dragger/BaseActivity.java
+++ b/app/src/main/java/com/github/ppamorim/dragger/BaseActivity.java
@@ -21,6 +21,10 @@
public class BaseActivity extends AbstractToolbarActivity {
+ @OnClick(R.id.lazy) void onLazyClick() {
+ startActivity(new Intent(this, LazyActivity.class));
+ }
+
@OnClick(R.id.edittext) void onEditTextClick() {
startActivity(new Intent(this, EditTextActivity.class));
}
diff --git a/app/src/main/java/com/github/ppamorim/dragger/LazyActivity.java b/app/src/main/java/com/github/ppamorim/dragger/LazyActivity.java
new file mode 100644
index 0000000..266aedd
--- /dev/null
+++ b/app/src/main/java/com/github/ppamorim/dragger/LazyActivity.java
@@ -0,0 +1,24 @@
+package com.github.ppamorim.dragger;
+
+import android.os.Bundle;
+import android.os.Handler;
+import butterknife.ButterKnife;
+import com.github.ppamorim.dragger.app.R;
+
+public class LazyActivity extends LazyDraggerActivity {
+
+ @Override public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.layout_content);
+ ButterKnife.inject(this);
+ }
+
+ @Override protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ new Handler().postDelayed(new Runnable() {
+ @Override public void run() {
+ expand();
+ }
+ }, 1000);
+ }
+}
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/app/src/main/java/com/github/ppamorim/dragger/PanelActivity.java b/app/src/main/java/com/github/ppamorim/dragger/PanelActivity.java
index d65f2fe..e492f03 100644
--- a/app/src/main/java/com/github/ppamorim/dragger/PanelActivity.java
+++ b/app/src/main/java/com/github/ppamorim/dragger/PanelActivity.java
@@ -17,7 +17,6 @@
import android.os.Bundle;
import android.view.LayoutInflater;
-import butterknife.ButterKnife;
import butterknife.InjectView;
import com.github.ppamorim.dragger.app.R;
diff --git a/dragger/build.gradle b/dragger/build.gradle
index d80b1e7..aff88f0 100644
--- a/dragger/build.gradle
+++ b/dragger/build.gradle
@@ -3,7 +3,6 @@ apply plugin: 'checkstyle'
dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
- compile 'com.nineoldandroids:library:2.4.0'
}
android {
diff --git a/dragger/res/layout/lazy_dragger_panel.xml b/dragger/res/layout/lazy_dragger_panel.xml
new file mode 100644
index 0000000..889e1a9
--- /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..a714c59
--- /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..7de2309 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,10 +29,6 @@ public DraggerPanel getDraggerPanel() {
return draggerPanel;
}
- public void setShadowView(int shadowResID) {
- this.shadowResID = shadowResID;
- }
-
private void configDraggerView() {
draggerPanel = new DraggerPanel(this);
draggerPanel.initializeView();
@@ -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..28e1639 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,25 +57,10 @@ 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);
+ super.initializeView(R.layout.dragger_panel);
draggerView = (DraggerView) findViewById(R.id.dragger_view);
- dragView = (FrameLayout) findViewById(R.id.drag_view);
- shadowView = (FrameLayout) findViewById(R.id.shadow_view);
- if(attributes != null) {
+ 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..ca0abbf 100644
--- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java
+++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java
@@ -26,7 +26,6 @@
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
-import com.nineoldandroids.view.ViewHelper;
/**
* Class created to extends a FrameLayout, that's a root of the view
@@ -118,7 +117,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);
@@ -249,20 +248,20 @@ boolean isDragViewAboveTheMiddle() {
switch (dragPosition) {
case LEFT:
parentSize = dragView.getWidth();
- viewAxisPosition = -ViewHelper.getX(dragView) + (parentSize * dragLimit);
+ viewAxisPosition = -ViewCompat.getX(dragView) + (parentSize * dragLimit);
break;
case RIGHT:
parentSize = dragView.getWidth();
- viewAxisPosition = ViewHelper.getX(dragView) + (parentSize * dragLimit);
+ viewAxisPosition = ViewCompat.getX(dragView) + (parentSize * dragLimit);
break;
case TOP:
default:
parentSize = dragView.getHeight();
- viewAxisPosition = ViewHelper.getY(dragView) + (parentSize * dragLimit);
+ viewAxisPosition = ViewCompat.getY(dragView) + (parentSize * dragLimit);
break;
case BOTTOM:
parentSize = dragView.getHeight();
- viewAxisPosition = -ViewHelper.getY(dragView) + (parentSize * dragLimit);
+ viewAxisPosition = -ViewCompat.getY(dragView) + (parentSize * dragLimit);
break;
}
return parentSize < viewAxisPosition;
@@ -280,16 +279,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) {
@@ -350,7 +353,7 @@ private void notifyClosed() {
}
private void setViewAlpha(View view, float alpha) {
- ViewHelper.setAlpha(view, alpha);
+ ViewCompat.setAlpha(view, alpha);
}
private boolean smoothSlideTo(View view, int x, int y) {
@@ -381,7 +384,7 @@ private void finish() {
}
@Override public void onViewPositionChanged(float dragValue) {
- ViewHelper.setAlpha(shadowView, MAX_ALPHA - dragValue);
+ ViewCompat.setAlpha(shadowView, MAX_ALPHA - dragValue);
}
@Override public float dragVerticalDragRange() {
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..09c61ab
--- /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();
+ }
+
+ 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..91e6489
--- /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);
+ }
+
+ public void initializeView() {
+ super.initializeView(R.layout.lazy_dragger_panel);
+ 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..45cfddf
--- /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);
+ }
+ }
+
+}