Skip to content

Commit eeea9a1

Browse files
author
zagum
committed
sample updated
1 parent ee3548f commit eeea9a1

File tree

2 files changed

+180
-156
lines changed

2 files changed

+180
-156
lines changed

expandicon-sample/src/main/java/com/github/zagum/expandicon/sample/SampleActivity.java

+90-81
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,98 @@
55
import android.view.GestureDetector;
66
import android.view.MotionEvent;
77
import android.view.View;
8+
89
import com.github.zagum.expandicon.ExpandIconView;
910

1011
public class SampleActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {
1112

12-
private ExpandIconView expandIconView1;
13-
private ExpandIconView expandIconView2;
14-
private ExpandIconView expandIconView3;
15-
private GestureDetector gestureDetector;
16-
private View swipeDetectionView;
17-
private View clickView;
18-
19-
@Override
20-
protected void onCreate(Bundle savedInstanceState) {
21-
super.onCreate(savedInstanceState);
22-
setContentView(R.layout.activity_sample);
23-
24-
expandIconView1 = (ExpandIconView) findViewById(R.id.expand_icon1);
25-
expandIconView2 = (ExpandIconView) findViewById(R.id.expand_icon2);
26-
expandIconView3 = (ExpandIconView) findViewById(R.id.expand_icon3);
27-
28-
expandIconView1.setFraction(.5f, false);
29-
expandIconView2.setFraction(.5f, false);
30-
31-
clickView = findViewById(R.id.click);
32-
clickView.setOnClickListener(new View.OnClickListener() {
33-
@Override
34-
public void onClick(View v) {
35-
expandIconView3.switchState();
36-
}
37-
});
38-
39-
setUpSlidingContainer();
40-
}
41-
42-
private void setUpSlidingContainer() {
43-
gestureDetector = new GestureDetector(this, this);
44-
gestureDetector.setIsLongpressEnabled(false);
45-
46-
swipeDetectionView = findViewById(R.id.swipe_detector);
47-
swipeDetectionView.setClickable(true);
48-
swipeDetectionView.setOnTouchListener(new View.OnTouchListener() {
49-
@Override
50-
public boolean onTouch(View v, MotionEvent event) {
51-
if (event.getAction() == MotionEvent.ACTION_UP) {
52-
expandIconView1.setFraction(.5f, true);
53-
expandIconView2.setFraction(.5f, true);
54-
}
55-
return gestureDetector.onTouchEvent(event);
56-
}
57-
});
58-
}
59-
60-
@Override
61-
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
62-
float fraction;
63-
if (Math.signum(distanceY) > 0) {
64-
fraction = 1f;
65-
} else {
66-
fraction = 0f;
67-
}
68-
expandIconView1.setFraction(fraction, true);
69-
expandIconView2.setFraction(fraction, true);
70-
return false;
71-
}
72-
73-
@Override
74-
public boolean onDown(MotionEvent e) {
75-
return false;
76-
}
77-
78-
@Override
79-
public boolean onSingleTapUp(MotionEvent e) {
80-
return false;
81-
}
82-
83-
@Override
84-
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
85-
return false;
86-
}
87-
88-
@Override
89-
public void onShowPress(MotionEvent e) {}
90-
91-
@Override
92-
public void onLongPress(MotionEvent e) {}
13+
private ExpandIconView expandIconView1;
14+
private ExpandIconView expandIconView2;
15+
private ExpandIconView expandIconView3;
16+
private ExpandIconView expandIconView4;
17+
private GestureDetector gestureDetector;
18+
private View swipeDetectionView;
19+
private View clickView;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_sample);
25+
26+
expandIconView1 = (ExpandIconView) findViewById(R.id.expand_icon1);
27+
expandIconView2 = (ExpandIconView) findViewById(R.id.expand_icon2);
28+
expandIconView3 = (ExpandIconView) findViewById(R.id.expand_icon3);
29+
expandIconView4 = (ExpandIconView) findViewById(R.id.expand_icon4);
30+
31+
expandIconView1.setFraction(.5f, false);
32+
expandIconView2.setFraction(.5f, false);
33+
34+
expandIconView3.setAnimationDuration(2000);
35+
36+
clickView = findViewById(R.id.click);
37+
clickView.setOnClickListener(new View.OnClickListener() {
38+
@Override
39+
public void onClick(View v) {
40+
expandIconView3.switchState();
41+
}
42+
});
43+
44+
setUpSlidingContainer();
45+
}
46+
47+
private void setUpSlidingContainer() {
48+
gestureDetector = new GestureDetector(this, this);
49+
gestureDetector.setIsLongpressEnabled(false);
50+
51+
swipeDetectionView = findViewById(R.id.swipe_detector);
52+
swipeDetectionView.setClickable(true);
53+
swipeDetectionView.setOnTouchListener(new View.OnTouchListener() {
54+
@Override
55+
public boolean onTouch(View v, MotionEvent event) {
56+
if (event.getAction() == MotionEvent.ACTION_UP) {
57+
expandIconView1.setFraction(.5f, true);
58+
expandIconView2.setFraction(.5f, true);
59+
expandIconView4.setFraction(.5f, true);
60+
}
61+
return gestureDetector.onTouchEvent(event);
62+
}
63+
});
64+
}
65+
66+
@Override
67+
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
68+
float fraction;
69+
if (Math.signum(distanceY) > 0) {
70+
fraction = 1f;
71+
} else {
72+
fraction = 0f;
73+
}
74+
expandIconView1.setFraction(fraction, true);
75+
expandIconView2.setFraction(fraction, true);
76+
expandIconView4.setFraction(fraction, true);
77+
return false;
78+
}
79+
80+
@Override
81+
public boolean onDown(MotionEvent e) {
82+
return false;
83+
}
84+
85+
@Override
86+
public boolean onSingleTapUp(MotionEvent e) {
87+
return false;
88+
}
89+
90+
@Override
91+
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
92+
return false;
93+
}
94+
95+
@Override
96+
public void onShowPress(MotionEvent e) {
97+
}
98+
99+
@Override
100+
public void onLongPress(MotionEvent e) {
101+
}
93102
}
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,106 @@
11
<FrameLayout
2-
xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
android:id="@+id/container"
6-
android:layout_width="match_parent"
7-
android:layout_height="match_parent"
8-
tools:context=".SampleActivity">
2+
android:id="@+id/container"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".SampleActivity">
99

10-
<FrameLayout
11-
android:layout_width="80dp"
12-
android:layout_height="wrap_content">
10+
<FrameLayout
11+
android:layout_width="80dp"
12+
android:layout_height="wrap_content">
1313

14-
<com.github.zagum.expandicon.ExpandIconView
15-
android:id="@+id/expand_icon1"
16-
android:layout_width="24dp"
17-
android:layout_height="24dp"
18-
android:layout_gravity="center_horizontal"
19-
android:layout_marginTop="16dp"
20-
app:eiv_animationDuration="300"
21-
app:eiv_color="#000"
22-
app:eiv_roundedCorners="false"
23-
app:eiv_switchColor="false"/>
14+
<com.github.zagum.expandicon.ExpandIconView
15+
android:id="@+id/expand_icon1"
16+
android:layout_width="24dp"
17+
android:layout_height="24dp"
18+
android:layout_gravity="center_horizontal"
19+
android:layout_marginTop="16dp"
20+
app:eiv_animationDuration="300"
21+
app:eiv_color="#000"
22+
app:eiv_roundedCorners="false"
23+
app:eiv_switchColor="false"/>
2424

25-
<com.github.zagum.expandicon.ExpandIconView
26-
android:id="@+id/expand_icon2"
27-
android:layout_width="48dp"
28-
android:layout_height="48dp"
29-
android:layout_gravity="center_horizontal"
30-
android:layout_marginTop="56dp"
31-
app:eiv_animationDuration="300"
32-
app:eiv_color="#000"
33-
app:eiv_colorLess="@color/colorPrimary"
34-
app:eiv_colorMore="@color/colorAccent"
35-
app:eiv_padding="8dp"
36-
app:eiv_roundedCorners="false"
37-
app:eiv_switchColor="true"/>
25+
<com.github.zagum.expandicon.ExpandIconView
26+
android:id="@+id/expand_icon2"
27+
android:layout_width="48dp"
28+
android:layout_height="48dp"
29+
android:layout_gravity="center_horizontal"
30+
android:layout_marginTop="56dp"
31+
app:eiv_animationDuration="300"
32+
app:eiv_color="#000"
33+
app:eiv_colorIntermediate="#8ad750"
34+
app:eiv_colorLess="@color/colorPrimary"
35+
app:eiv_colorMore="@color/colorAccent"
36+
app:eiv_padding="8dp"
37+
app:eiv_roundedCorners="false"
38+
app:eiv_switchColor="true"/>
3839

39-
</FrameLayout>
40+
<com.github.zagum.expandicon.ExpandIconView
41+
android:id="@+id/expand_icon4"
42+
android:layout_width="48dp"
43+
android:layout_height="48dp"
44+
android:layout_gravity="center_horizontal"
45+
android:layout_marginTop="100dp"
46+
app:eiv_animationDuration="300"
47+
app:eiv_color="#000"
48+
app:eiv_colorLess="@color/colorPrimary"
49+
app:eiv_colorMore="@color/colorAccent"
50+
app:eiv_padding="8dp"
51+
app:eiv_roundedCorners="false"
52+
app:eiv_switchColor="true"/>
4053

41-
<FrameLayout
42-
android:layout_width="match_parent"
43-
android:layout_height="150dp">
54+
</FrameLayout>
4455

45-
<View
46-
android:id="@+id/swipe_detector"
47-
android:layout_width="match_parent"
48-
android:layout_height="150dp"
49-
android:layout_marginLeft="80dp"
50-
android:background="#f7f1f1"/>
56+
<FrameLayout
57+
android:layout_width="match_parent"
58+
android:layout_height="150dp">
5159

52-
<TextView
53-
android:layout_width="wrap_content"
54-
android:layout_height="wrap_content"
55-
android:layout_gravity="center"
56-
android:text="@string/swipe_finger_up_and_down"
57-
android:textStyle="italic"/>
60+
<View
61+
android:id="@+id/swipe_detector"
62+
android:layout_width="match_parent"
63+
android:layout_height="150dp"
64+
android:layout_marginLeft="80dp"
65+
android:background="#f7f1f1"/>
5866

59-
</FrameLayout>
67+
<TextView
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:layout_gravity="center"
71+
android:text="@string/swipe_finger_up_and_down"
72+
android:textStyle="italic"/>
6073

74+
</FrameLayout>
6175

62-
<FrameLayout
63-
android:id="@+id/click"
64-
android:layout_width="match_parent"
65-
android:layout_height="48dp"
66-
android:layout_marginTop="200dp"
67-
android:background="?selectableItemBackground">
6876

69-
<com.github.zagum.expandicon.ExpandIconView
70-
android:id="@+id/expand_icon3"
71-
android:layout_width="24dp"
72-
android:layout_height="24dp"
73-
android:layout_gravity="center_vertical"
74-
android:layout_marginLeft="16dp"
75-
app:eiv_animationDuration="300"
76-
app:eiv_color="#000"
77-
app:eiv_colorLess="@color/colorPrimary"
78-
app:eiv_colorMore="@color/colorAccent"
79-
app:eiv_roundedCorners="false"
80-
app:eiv_switchColor="true"/>
77+
<FrameLayout
78+
android:id="@+id/click"
79+
android:layout_width="match_parent"
80+
android:layout_height="48dp"
81+
android:layout_marginTop="200dp"
82+
android:background="?selectableItemBackground">
8183

82-
<TextView
83-
android:layout_width="wrap_content"
84-
android:layout_height="wrap_content"
85-
android:layout_gravity="center"
86-
android:text="@string/click"
87-
android:textStyle="bold"/>
84+
<com.github.zagum.expandicon.ExpandIconView
85+
android:id="@+id/expand_icon3"
86+
android:layout_width="24dp"
87+
android:layout_height="24dp"
88+
android:layout_gravity="center_vertical"
89+
android:layout_marginLeft="16dp"
90+
app:eiv_animationDuration="300"
91+
app:eiv_color="#000"
92+
app:eiv_colorLess="@color/colorPrimary"
93+
app:eiv_colorMore="@color/colorAccent"
94+
app:eiv_roundedCorners="false"
95+
app:eiv_switchColor="true"/>
8896

89-
</FrameLayout>
97+
<TextView
98+
android:layout_width="wrap_content"
99+
android:layout_height="wrap_content"
100+
android:layout_gravity="center"
101+
android:text="@string/click"
102+
android:textStyle="bold"/>
103+
104+
</FrameLayout>
90105

91106
</FrameLayout>

0 commit comments

Comments
 (0)