Skip to content

Commit

Permalink
sample updated
Browse files Browse the repository at this point in the history
  • Loading branch information
zagum committed Apr 11, 2017
1 parent ee3548f commit eeea9a1
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,98 @@
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

import com.github.zagum.expandicon.ExpandIconView;

public class SampleActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {

private ExpandIconView expandIconView1;
private ExpandIconView expandIconView2;
private ExpandIconView expandIconView3;
private GestureDetector gestureDetector;
private View swipeDetectionView;
private View clickView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);

expandIconView1 = (ExpandIconView) findViewById(R.id.expand_icon1);
expandIconView2 = (ExpandIconView) findViewById(R.id.expand_icon2);
expandIconView3 = (ExpandIconView) findViewById(R.id.expand_icon3);

expandIconView1.setFraction(.5f, false);
expandIconView2.setFraction(.5f, false);

clickView = findViewById(R.id.click);
clickView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandIconView3.switchState();
}
});

setUpSlidingContainer();
}

private void setUpSlidingContainer() {
gestureDetector = new GestureDetector(this, this);
gestureDetector.setIsLongpressEnabled(false);

swipeDetectionView = findViewById(R.id.swipe_detector);
swipeDetectionView.setClickable(true);
swipeDetectionView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
expandIconView1.setFraction(.5f, true);
expandIconView2.setFraction(.5f, true);
}
return gestureDetector.onTouchEvent(event);
}
});
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
float fraction;
if (Math.signum(distanceY) > 0) {
fraction = 1f;
} else {
fraction = 0f;
}
expandIconView1.setFraction(fraction, true);
expandIconView2.setFraction(fraction, true);
return false;
}

@Override
public boolean onDown(MotionEvent e) {
return false;
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}

@Override
public void onShowPress(MotionEvent e) {}

@Override
public void onLongPress(MotionEvent e) {}
private ExpandIconView expandIconView1;
private ExpandIconView expandIconView2;
private ExpandIconView expandIconView3;
private ExpandIconView expandIconView4;
private GestureDetector gestureDetector;
private View swipeDetectionView;
private View clickView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);

expandIconView1 = (ExpandIconView) findViewById(R.id.expand_icon1);
expandIconView2 = (ExpandIconView) findViewById(R.id.expand_icon2);
expandIconView3 = (ExpandIconView) findViewById(R.id.expand_icon3);
expandIconView4 = (ExpandIconView) findViewById(R.id.expand_icon4);

expandIconView1.setFraction(.5f, false);
expandIconView2.setFraction(.5f, false);

expandIconView3.setAnimationDuration(2000);

clickView = findViewById(R.id.click);
clickView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandIconView3.switchState();
}
});

setUpSlidingContainer();
}

private void setUpSlidingContainer() {
gestureDetector = new GestureDetector(this, this);
gestureDetector.setIsLongpressEnabled(false);

swipeDetectionView = findViewById(R.id.swipe_detector);
swipeDetectionView.setClickable(true);
swipeDetectionView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
expandIconView1.setFraction(.5f, true);
expandIconView2.setFraction(.5f, true);
expandIconView4.setFraction(.5f, true);
}
return gestureDetector.onTouchEvent(event);
}
});
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
float fraction;
if (Math.signum(distanceY) > 0) {
fraction = 1f;
} else {
fraction = 0f;
}
expandIconView1.setFraction(fraction, true);
expandIconView2.setFraction(fraction, true);
expandIconView4.setFraction(fraction, true);
return false;
}

@Override
public boolean onDown(MotionEvent e) {
return false;
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}

@Override
public void onShowPress(MotionEvent e) {
}

@Override
public void onLongPress(MotionEvent e) {
}
}
165 changes: 90 additions & 75 deletions expandicon-sample/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
@@ -1,91 +1,106 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SampleActivity">
android:id="@+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SampleActivity">

<FrameLayout
android:layout_width="80dp"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="80dp"
android:layout_height="wrap_content">

<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon1"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_roundedCorners="false"
app:eiv_switchColor="false"/>
<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon1"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_roundedCorners="false"
app:eiv_switchColor="false"/>

<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="56dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_colorLess="@color/colorPrimary"
app:eiv_colorMore="@color/colorAccent"
app:eiv_padding="8dp"
app:eiv_roundedCorners="false"
app:eiv_switchColor="true"/>
<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="56dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_colorIntermediate="#8ad750"
app:eiv_colorLess="@color/colorPrimary"
app:eiv_colorMore="@color/colorAccent"
app:eiv_padding="8dp"
app:eiv_roundedCorners="false"
app:eiv_switchColor="true"/>

</FrameLayout>
<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon4"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_colorLess="@color/colorPrimary"
app:eiv_colorMore="@color/colorAccent"
app:eiv_padding="8dp"
app:eiv_roundedCorners="false"
app:eiv_switchColor="true"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="150dp">
</FrameLayout>

<View
android:id="@+id/swipe_detector"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="80dp"
android:background="#f7f1f1"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="150dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/swipe_finger_up_and_down"
android:textStyle="italic"/>
<View
android:id="@+id/swipe_detector"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="80dp"
android:background="#f7f1f1"/>

</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/swipe_finger_up_and_down"
android:textStyle="italic"/>

</FrameLayout>

<FrameLayout
android:id="@+id/click"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="200dp"
android:background="?selectableItemBackground">

<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon3"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_colorLess="@color/colorPrimary"
app:eiv_colorMore="@color/colorAccent"
app:eiv_roundedCorners="false"
app:eiv_switchColor="true"/>
<FrameLayout
android:id="@+id/click"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="200dp"
android:background="?selectableItemBackground">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/click"
android:textStyle="bold"/>
<com.github.zagum.expandicon.ExpandIconView
android:id="@+id/expand_icon3"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
app:eiv_animationDuration="300"
app:eiv_color="#000"
app:eiv_colorLess="@color/colorPrimary"
app:eiv_colorMore="@color/colorAccent"
app:eiv_roundedCorners="false"
app:eiv_switchColor="true"/>

</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/click"
android:textStyle="bold"/>

</FrameLayout>

</FrameLayout>

0 comments on commit eeea9a1

Please sign in to comment.