Skip to content

Commit 2114ab5

Browse files
committed
Merge pull request navasmdc#50 from shark0017/master
Add animations to widgets and fix it
2 parents d0b1f6c + 2cd53c6 commit 2114ab5

File tree

12 files changed

+283
-68
lines changed

12 files changed

+283
-68
lines changed

MaterialDesign/.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="gen"/>
53
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
64
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
75
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
86
<classpathentry kind="lib" path="libs/nineoldandroids-2.4.0.jar"/>
7+
<classpathentry kind="src" path="src"/>
8+
<classpathentry kind="src" path="gen"/>
99
<classpathentry kind="output" path="bin/classes"/>
1010
</classpath>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:interpolator="@android:anim/accelerate_interpolator"
4+
android:shareInterpolator="true"
5+
android:startOffset="50">
6+
7+
<alpha
8+
android:duration="200"
9+
android:fromAlpha="1.0"
10+
android:toAlpha="0.0" />
11+
12+
<scale
13+
android:fromXScale="1.0"
14+
android:toXScale="0.8"
15+
android:fromYScale="1.0"
16+
android:toYScale="0.8"
17+
android:pivotX="50%"
18+
android:pivotY="50%"
19+
android:duration="200"/>
20+
21+
</set>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<alpha
5+
android:duration="200"
6+
android:fromAlpha="0.0"
7+
android:toAlpha="1.0" />
8+
9+
<scale
10+
android:duration="200"
11+
android:fromXScale="0.8"
12+
android:fromYScale="0.8"
13+
android:pivotX="50%"
14+
android:pivotY="50%"
15+
android:toXScale="1.0"
16+
android:toYScale="1.0" />
17+
18+
</set>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:interpolator="@android:anim/accelerate_interpolator"
4+
android:shareInterpolator="true"
5+
android:startOffset="50">
6+
<alpha
7+
android:fromAlpha="1.0"
8+
android:toAlpha="0.0"
9+
android:duration="200" />
10+
</set>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android">
3+
<alpha
4+
android:fromAlpha="0.0"
5+
android:toAlpha="1.0"
6+
android:duration="200" />
7+
</set>

MaterialDesign/res/layout/color_selector.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/rootSelector"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:background="#55000000"
78
android:padding="40dp" >
89

910
<LinearLayout
11+
android:id="@+id/contentSelector"
1012
android:layout_width="fill_parent"
1113
android:layout_height="wrap_content"
1214
android:layout_centerInParent="true"

MaterialDesign/res/layout/dialog.xml

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,74 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/dialog_rootView"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent"
56
android:background="#55000000"
6-
android:padding="32dp">
7-
8-
<LinearLayout
7+
android:padding="32dp" >
8+
9+
<RelativeLayout
910
android:id="@+id/contentDialog"
11+
android:layout_width="match_parent"
1012
android:layout_height="wrap_content"
11-
android:layout_width="fill_parent"
12-
android:background="@drawable/dialog_background"
1313
android:layout_centerInParent="true"
14-
android:orientation="vertical"
14+
android:background="@drawable/dialog_background"
1515
android:padding="24dp">
1616

1717
<TextView
1818
android:id="@+id/title"
1919
android:layout_width="wrap_content"
2020
android:layout_height="wrap_content"
21+
android:layout_marginBottom="24dp"
2122
android:text="Title"
22-
android:layout_marginBottom="24dp"
23-
android:textColor="#000"
24-
android:textAppearance="?android:attr/textAppearanceLarge" />
25-
<TextView
26-
android:id="@+id/message"
27-
android:layout_width="wrap_content"
23+
android:textAppearance="?android:attr/textAppearanceLarge"
24+
android:textColor="#000" />
25+
26+
<ScrollView
27+
android:id="@+id/message_scrollView"
28+
android:layout_width="match_parent"
2829
android:layout_height="wrap_content"
29-
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam"
30-
android:layout_marginBottom="24dp"
31-
android:textColor="#000"/>
32-
<LinearLayout
30+
android:layout_below="@id/title"
31+
android:paddingBottom="50dp"
32+
android:scrollbarSize="2dp"
33+
android:scrollbarThumbVertical="@color/thumbColor" >
34+
35+
<LinearLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent"
38+
android:orientation="vertical" >
39+
40+
<TextView
41+
android:id="@+id/message"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam"
45+
android:textColor="#000"
46+
android:textSize="18sp" />
47+
</LinearLayout>
48+
</ScrollView>
49+
50+
<LinearLayout
51+
android:layout_width="match_parent"
3352
android:layout_height="wrap_content"
34-
android:layout_width="fill_parent"
35-
android:orientation="horizontal"
36-
android:gravity="right">
37-
38-
<com.gc.materialdesign.views.ButtonFlat
53+
android:layout_alignBottom="@id/message_scrollView"
54+
android:layout_marginTop="24dp"
55+
android:gravity="right"
56+
android:orientation="horizontal" >
57+
58+
<com.gc.materialdesign.views.ButtonFlat
3959
android:id="@+id/button_cancel"
4060
android:layout_width="wrap_content"
4161
android:layout_height="wrap_content"
42-
android:background="#000"
43-
android:text="cancel" />
44-
<com.gc.materialdesign.views.ButtonFlat
62+
android:text="Cancel"
63+
android:textColor="#000" />
64+
65+
<com.gc.materialdesign.views.ButtonFlat
4566
android:id="@+id/button_accept"
4667
android:layout_width="wrap_content"
4768
android:layout_height="wrap_content"
48-
android:background="#1E88E5"
49-
android:text="accept" />
69+
android:text="Accept"
70+
android:textColor="#1E88E5" />
5071
</LinearLayout>
51-
52-
</LinearLayout>
53-
72+
</RelativeLayout>
5473

55-
</RelativeLayout>
74+
</RelativeLayout>

MaterialDesign/res/layout/snackbar.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<RelativeLayout
77
android:layout_width="fill_parent"
88
android:layout_height="wrap_content"
9+
android:minHeight="56dp"
910
android:layout_alignParentBottom="true" >
1011

1112
<RelativeLayout
@@ -26,15 +27,16 @@
2627
android:layout_alignParentRight="true"
2728
android:layout_centerVertical="true"
2829
android:layout_marginLeft="24dp"
29-
android:text="action" />
30+
android:text="ACTION" />
3031

31-
<TextView
32+
<TextView
3233
android:id="@+id/text"
3334
android:layout_width="fill_parent"
3435
android:layout_height="wrap_content"
3536
android:layout_centerVertical="true"
3637
android:layout_toLeftOf="@id/buttonflat"
3738
android:textColor="#FFF" />
39+
3840
</RelativeLayout>
3941
</RelativeLayout>
4042

MaterialDesign/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="green">#00FF00</color>
4-
4+
<color name="thumbColor">#66aaaaaa</color>
55
</resources>

MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,31 @@
88
import android.content.DialogInterface;
99
import android.graphics.Color;
1010
import android.os.Bundle;
11+
import android.view.MotionEvent;
1112
import android.view.View;
1213
import android.view.Window;
14+
import android.view.View.OnTouchListener;
15+
import android.view.animation.Animation;
16+
import android.view.animation.AnimationUtils;
17+
import android.view.animation.Animation.AnimationListener;
1318
import android.widget.LinearLayout;
1419
import android.widget.LinearLayout.LayoutParams;
20+
import android.widget.RelativeLayout;
1521

1622
public class ColorSelector extends android.app.Dialog implements OnValueChangedListener{
1723

1824
int color = Color.BLACK;
25+
Context context;
1926
View colorView;
27+
View view, backView;//background
2028

2129
OnColorSelectedListener onColorSelectedListener;
2230
Slider red, green, blue;
2331

2432

2533
public ColorSelector(Context context,Integer color, OnColorSelectedListener onColorSelectedListener) {
2634
super(context, android.R.style.Theme_Translucent);
27-
35+
this.context = context;
2836
this.onColorSelectedListener = onColorSelectedListener;
2937
if(color != null)
3038
this.color = color;
@@ -36,15 +44,30 @@ public void onDismiss(DialogInterface dialog) {
3644
ColorSelector.this.onColorSelectedListener.onColorSelected(ColorSelector.this.color);
3745
}
3846
});
39-
4047
}
4148

49+
50+
4251
@Override
4352
protected void onCreate(Bundle savedInstanceState) {
4453
requestWindowFeature(Window.FEATURE_NO_TITLE);
4554
super.onCreate(savedInstanceState);
4655
setContentView(R.layout.color_selector);
4756

57+
view = (LinearLayout)findViewById(R.id.contentSelector);
58+
backView = (RelativeLayout)findViewById(R.id.rootSelector);
59+
backView.setOnTouchListener(new OnTouchListener() {
60+
61+
@Override
62+
public boolean onTouch(View v, MotionEvent event) {
63+
if (event.getX() < view.getLeft() || event.getX() >view.getRight()
64+
|| event.getY() > view.getBottom() || event.getY() < view.getTop()) {
65+
dismiss();
66+
}
67+
return false;
68+
}
69+
});
70+
4871
colorView = findViewById(R.id.viewColor);
4972
colorView.setBackgroundColor(color);
5073
// Resize ColorView
@@ -77,6 +100,13 @@ public void run() {
77100
blue.setOnValueChangedListener(this);
78101
}
79102

103+
@Override
104+
public void show() {
105+
super.show();
106+
view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.dialog_main_show_amination));
107+
backView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.dialog_root_show_amin));
108+
}
109+
80110
@Override
81111
public void onValueChanged(int value) {
82112
color = Color.rgb(red.getValue(), green.getValue(), blue.getValue());
@@ -85,9 +115,39 @@ public void onValueChanged(int value) {
85115

86116

87117
// Event that execute when color selector is closed
88-
public interface OnColorSelectedListener{
89-
public void onColorSelected(int color);
90-
}
91-
118+
public interface OnColorSelectedListener{
119+
public void onColorSelected(int color);
120+
}
121+
122+
@Override
123+
public void dismiss() {
124+
Animation anim = AnimationUtils.loadAnimation(context, R.anim.dialog_main_hide_amination);
125+
126+
anim.setAnimationListener(new AnimationListener() {
127+
128+
@Override
129+
public void onAnimationStart(Animation animation) {
130+
}
131+
132+
@Override
133+
public void onAnimationRepeat(Animation animation) {
134+
}
135+
136+
@Override
137+
public void onAnimationEnd(Animation animation) {
138+
view.post(new Runnable() {
139+
@Override
140+
public void run() {
141+
ColorSelector.super.dismiss();
142+
}
143+
});
144+
}
145+
});
146+
147+
Animation backAnim = AnimationUtils.loadAnimation(context, R.anim.dialog_root_hide_amin);
148+
149+
view.startAnimation(anim);
150+
backView.startAnimation(backAnim);
151+
}
92152

93153
}

0 commit comments

Comments
 (0)