Skip to content

Commit 3e41c84

Browse files
committed
Add the ability to get the center point of the QuickActionView to allow for things like circular reveal.
1 parent b14bd88 commit 3e41c84

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.ovenbits.quickactionview.sample;
2+
3+
import android.graphics.Point;
4+
import android.os.Build;
5+
import android.view.View;
6+
import android.view.ViewAnimationUtils;
7+
import android.view.animation.LinearInterpolator;
8+
9+
import com.ovenbits.quickactionview.Action;
10+
import com.ovenbits.quickactionview.ActionView;
11+
import com.ovenbits.quickactionview.ActionsInAnimator;
12+
import com.ovenbits.quickactionview.QuickActionView;
13+
14+
/**
15+
* Example of how to create a custom animations in animator
16+
*/
17+
public class CustomActionsInAnimator implements ActionsInAnimator {
18+
19+
private LinearInterpolator mInterpolator = new LinearInterpolator();
20+
private QuickActionView mQuickActionView;
21+
22+
public CustomActionsInAnimator(QuickActionView view) {
23+
mQuickActionView = view;
24+
}
25+
26+
@Override
27+
public void animateActionIn(Action action, int index, ActionView view, Point center) {
28+
view.animate()
29+
.alpha(1.0f)
30+
.setDuration(200)
31+
.setInterpolator(mInterpolator);
32+
}
33+
34+
@Override
35+
public void animateIndicatorIn(View indicator) {
36+
indicator.setAlpha(0);
37+
indicator.animate().alpha(1).setDuration(200);
38+
}
39+
40+
@Override
41+
public void animateScrimIn(View scrim) {
42+
Point center = mQuickActionView.getCenterPoint();
43+
if (Build.VERSION.SDK_INT >= 21 && center != null) {
44+
ViewAnimationUtils.createCircularReveal(scrim, center.x, center.y, 0, Math.max(scrim.getHeight(), scrim.getWidth()))
45+
.start();
46+
} else {
47+
scrim.setAlpha(0f);
48+
scrim.animate().alpha(1f).setDuration(200);
49+
}
50+
}
51+
}

app/src/main/java/com/ovenbits/quickactionview/sample/MainActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void onClick(View v) {
7878
.setTextColor(Color.MAGENTA);
7979

8080
PopAnimator popAnimator = new PopAnimator(true);
81-
QuickActionView.make(this)
81+
QuickActionView qav = QuickActionView.make(this)
8282
.addActions(R.menu.actions_2)
8383
.setOnActionSelectedListener(mQuickActionListener)
8484
.setBackgroundColor(Color.RED)
@@ -88,8 +88,9 @@ public void onClick(View v) {
8888
.setTextBackgroundDrawable(R.drawable.text_background)
8989
.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.indicator))
9090
.setActionConfig(actionConfig, R.id.action_add_to_cart)
91-
.setActionsInAnimator(popAnimator)
9291
.setActionsOutAnimator(popAnimator)
9392
.register(findViewById(R.id.custom_parent));
93+
CustomActionsInAnimator customActionsInAnimator = new CustomActionsInAnimator(qav);
94+
qav.setActionsInAnimator(customActionsInAnimator);
9495
}
9596
}

quickactionview/src/main/java/com/ovenbits/quickactionview/QuickActionView.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,18 @@ public QuickActionView setActionConfig(Action.Config config, @IdRes int actionId
416416
throw new IllegalArgumentException("No Action exists with id " + actionId);
417417
}
418418

419+
/**
420+
* Get the center point of the {@link QuickActionView} aka the point at which the actions will eminate from
421+
* @return the center point, or null if the view has not yet been created
422+
*/
423+
@Nullable
424+
public Point getCenterPoint() {
425+
if (mQuickActionViewLayout != null) {
426+
return mQuickActionViewLayout.mCenterPoint;
427+
}
428+
return null;
429+
}
430+
419431
private void display(Point point) {
420432
if (mActions == null) {
421433
throw new IllegalStateException("You need to give the QuickActionView actions before calling show!");

0 commit comments

Comments
 (0)