Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ppamorim/Dragger
Browse files Browse the repository at this point in the history
  • Loading branch information
ppamorim committed May 25, 2015
2 parents e2faee2 + c453eea commit e15d123
Show file tree
Hide file tree
Showing 18 changed files with 393 additions and 145 deletions.
1 change: 1 addition & 0 deletions app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</intent-filter>
</activity>

<activity android:name="com.github.ppamorim.dragger.LazyActivity"/>
<activity android:name="com.github.ppamorim.dragger.EditTextActivity"/>
<activity android:name="com.github.ppamorim.dragger.ListActivity"/>
<activity android:name="com.github.ppamorim.dragger.ActivityListActivity"/>
Expand Down
166 changes: 90 additions & 76 deletions app/res/layout/activity_base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,107 @@

<include layout="@layout/toolbar"/>

<LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_edittext"
android:padding="16dp"/>
android:layout_height="match_parent">

<Button
android:id="@+id/list"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_list"
android:padding="16dp"/>
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/activity_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_activity_list"
android:padding="16dp"/>
<Button
android:id="@+id/lazy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_lazy"
android:padding="16dp"/>

<Button
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_menu"
android:padding="16dp"/>
<Button
android:id="@+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_edittext"
android:padding="16dp"/>

<Button
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_left"
android:padding="16dp"/>
<Button
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_list"
android:padding="16dp"/>

<Button
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_right"
android:padding="16dp"/>
<Button
android:id="@+id/activity_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_activity_list"
android:padding="16dp"/>

<Button
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_top"
android:padding="16dp"/>
<Button
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_menu"
android:padding="16dp"/>

<Button
android:id="@+id/bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_bottom"
android:padding="16dp"/>
<Button
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_left"
android:padding="16dp"/>

<Button
android:id="@+id/panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_panel"
android:padding="16dp"/>
<Button
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_right"
android:padding="16dp"/>

<Button
android:id="@+id/activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_activity"
android:padding="16dp"/>
<Button
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_top"
android:padding="16dp"/>

<Button
android:id="@+id/bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_bottom"
android:padding="16dp"/>

<Button
android:id="@+id/panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_panel"
android:padding="16dp"/>

<Button
android:id="@+id/activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/open_activity"
android:padding="16dp"/>

</LinearLayout>

</LinearLayout>
</ScrollView>

</LinearLayout>
1 change: 1 addition & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">Dragger</string>
<string name="hi">Hi!</string>
<string name="open_lazy">Lazy</string>
<string name="open_edittext">EditText</string>
<string name="open_list">List</string>
<string name="open_activity_list">Activity List</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/github/ppamorim/dragger/LazyActivity.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion dragger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions dragger/res/layout/lazy_dragger_panel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<com.github.ppamorim.dragger.LazyDraggerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dragger_layout="http://schemas.android.com/apk/res-auto"
android:id="@+id/dragger_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
dragger_layout:shadow_view_id="@+id/shadow_view"
dragger_layout:drag_view_id="@+id/drag_view">

<FrameLayout
android:id="@+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"/>

<FrameLayout
android:id="@+id/drag_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</com.github.ppamorim.dragger.LazyDraggerView>
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Loading

0 comments on commit e15d123

Please sign in to comment.