Skip to content

Commit

Permalink
Add ability to add custom action title in and out animators
Browse files Browse the repository at this point in the history
  • Loading branch information
Jawnnypoo committed Oct 11, 2016
1 parent ee85d58 commit 88c5d61
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 26 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ android:
components:
- platform-tools
- tools

# The BuildTools version used by your project
- build-tools-24.0.1

# The SDK version used to compile your project
- build-tools-24.0.3
- android-24

# Additional components
- extra-android-m2repository

before_script:
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
buildToolsVersion "24.0.3"

defaultConfig {
applicationId "com.ovenbits.quickactionview.sample"
Expand All @@ -26,8 +26,8 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile project(':quickactionview')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* A fake model to show usage
* Created by John on 11/24/15.
*/
public class Cheese {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

/**
* Adapter for the recyclerview, which holds cheeses
* Created by John on 11/24/15.
*/
public class CheeseAdapter extends RecyclerView.Adapter<CheeseViewHolder> implements QuickActionView.OnActionSelectedListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

/**
* The view holder related to each Cheese item
* Created by John on 11/24/15.
*/
public class CheeseViewHolder extends RecyclerView.ViewHolder {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ovenbits.quickactionview.sample;

import android.view.View;
import android.view.animation.OvershootInterpolator;

import com.ovenbits.quickactionview.Action;
import com.ovenbits.quickactionview.ActionsTitleInAnimator;
import com.ovenbits.quickactionview.ActionsTitleOutAnimator;

/**
* Default animator which animates the action title in and out
*/
public class CustomActionsTitleAnimator implements ActionsTitleInAnimator, ActionsTitleOutAnimator {

private static final int DURATION = 200; //ms

@Override
public void animateActionTitleIn(Action action, int index, View view) {
view.setAlpha(0.0f);
view.setScaleX(0.0f);
view.setScaleY(0.0f);
view.animate()
.alpha(1.0f)
.scaleX(1.0f)
.scaleY(1.0f)
.setInterpolator(new OvershootInterpolator())
.setDuration(DURATION);
}

@Override
public int animateActionTitleOut(Action action, int index, View view) {
view.animate()
.alpha(0.0f)
.scaleX(0.0f)
.scaleY(0.0f)
.setDuration(DURATION);
return DURATION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void onClick(View v) {
.setTextColor(Color.MAGENTA);

PopAnimator popAnimator = new PopAnimator(true);
CustomActionsTitleAnimator actionTitleAnimator = new CustomActionsTitleAnimator();
QuickActionView qav = QuickActionView.make(this)
.addActions(R.menu.actions_2)
.setOnActionSelectedListener(mQuickActionListener)
Expand All @@ -89,6 +90,8 @@ public void onClick(View v) {
.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.indicator))
.setActionConfig(actionConfig, R.id.action_add_to_cart)
.setActionsOutAnimator(popAnimator)
.setActionsTitleInAnimator(actionTitleAnimator)
.setActionsTitleOutAnimator(actionTitleAnimator)
.register(findViewById(R.id.custom_parent));
CustomActionsInAnimator customActionsInAnimator = new CustomActionsInAnimator(qav);
qav.setActionsInAnimator(customActionsInAnimator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

/**
* Shows usage of the QuickActionView from within a RecyclerView
* Created by John on 11/24/15.
*/
public class RecyclerViewActivity extends AppCompatActivity {

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Mon Oct 10 22:22:39 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4 changes: 2 additions & 2 deletions quickactionview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
buildToolsVersion "24.0.3"

defaultConfig {
minSdkVersion 15
Expand All @@ -24,7 +24,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:appcompat-v7:24.2.1'
}

apply from: 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ovenbits.quickactionview;

import android.view.View;

/**
* Custom animations for an {@link Action} label animating in
*/
public interface ActionsTitleInAnimator {

/**
* Animate the action title view as the QuickActionView action title appears
* @param action The action being animated
* @param index The position of the action in its parent
* @param view The action title view
*/
void animateActionTitleIn(Action action, int index, View view);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ovenbits.quickactionview;

import android.view.View;

/**
* Custom animations for an {@link Action} label animating in
*/
public interface ActionsTitleOutAnimator {

/**
* Animate the action title view as the QuickActionView action title disappears
* @param action The action being animated
* @param index The position of the action in its parent
* @param view The action title view
* @return The duration of this animation, in milliseconds, so that the view can be properly
* hidden when the animation completes
*/
int animateActionTitleOut(Action action, int index, View view);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.ovenbits.quickactionview.animator.FadeInFadeOutActionsTitleAnimator;
import com.ovenbits.quickactionview.animator.SlideFromCenterAnimator;

import java.util.ArrayList;
Expand Down Expand Up @@ -58,7 +59,8 @@ public class QuickActionView {
private Config mConfig;
private ActionsInAnimator mActionsInAnimator;
private ActionsOutAnimator mActionsOutAnimator;

private ActionsTitleInAnimator mActionsTitleInAnimator;
private ActionsTitleOutAnimator mActionsTitleOutAnimator;

@ColorInt
private int mScrimColor = Color.parseColor("#99000000");
Expand All @@ -74,8 +76,11 @@ private QuickActionView(Context context) {
mActionDistance = context.getResources().getDimensionPixelSize(R.dimen.qav_action_distance);
mActionPadding = context.getResources().getDimensionPixelSize(R.dimen.qav_action_padding);
SlideFromCenterAnimator defaultAnimator = new SlideFromCenterAnimator(true);
FadeInFadeOutActionsTitleAnimator defaultTitleAnimator = new FadeInFadeOutActionsTitleAnimator();
mActionsInAnimator = defaultAnimator;
mActionsOutAnimator = defaultAnimator;
mActionsTitleInAnimator = defaultTitleAnimator;
mActionsTitleOutAnimator = defaultTitleAnimator;
}

/**
Expand Down Expand Up @@ -398,6 +403,28 @@ public QuickActionView setActionsOutAnimator(ActionsOutAnimator actionsOutAnimat
return this;
}

/**
* Override the animations for when the QuickActionView action title shows
*
* @param actionsTitleInAnimator the custom animator
* @return this QuickActionView
*/
public QuickActionView setActionsTitleInAnimator(ActionsTitleInAnimator actionsTitleInAnimator) {
mActionsTitleInAnimator = actionsTitleInAnimator;
return this;
}

/**
* Override the animations for when the QuickActionView dismisses
*
* @param actionsTitleOutAnimator the custom animator
* @return this QuickActionView
*/
public QuickActionView setActionsTitleOutAnimator(ActionsTitleOutAnimator actionsTitleOutAnimator) {
mActionsTitleOutAnimator = actionsTitleOutAnimator;
return this;
}

/**
* Set a custom configuration for the action with the given id
*
Expand Down Expand Up @@ -702,7 +729,6 @@ public QuickActionViewLayout(Context context, ArrayList<Action> actions, Point c
}
}


@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
mScrimView.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
Expand All @@ -726,7 +752,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
titleView.layout((int) titleLeft, (int) titleTop, (int) (titleLeft + titleView.getMeasuredWidth()), (int) (titleTop + titleView.getMeasuredHeight()));
}
index++;

}

if (!mAnimated) {
Expand Down Expand Up @@ -807,6 +832,7 @@ public boolean onTouchEvent(MotionEvent event) {
if (actionTitleView != null) {
actionTitleView.setVisibility(View.VISIBLE);
actionTitleView.bringToFront();
mActionsTitleInAnimator.animateActionTitleIn(actionView.getAction(), index, actionTitleView);
}
if (mOnActionHoverChangedListener != null) {
mOnActionHoverChangedListener.onActionHoverChanged(actionView.getAction(), QuickActionView.this, true);
Expand All @@ -816,9 +842,15 @@ public boolean onTouchEvent(MotionEvent event) {
if (actionView.isSelected()) {
actionView.setSelected(false);
actionView.animateInterpolation(0);
ActionTitleView actionTitleView = mActionTitleViews.get(actionView.getAction());
final ActionTitleView actionTitleView = mActionTitleViews.get(actionView.getAction());
if (actionTitleView != null) {
actionTitleView.setVisibility(View.GONE);
int timeTaken = mActionsTitleOutAnimator.animateActionTitleOut(actionView.getAction(), index, actionTitleView);
actionTitleView.postDelayed(new Runnable() {
@Override
public void run() {
actionTitleView.setVisibility(View.GONE);
}
}, timeTaken);
}
if (mOnActionHoverChangedListener != null) {
mOnActionHoverChangedListener.onActionHoverChanged(actionView.getAction(), QuickActionView.this, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.ovenbits.quickactionview.animator;

import android.view.View;

import com.ovenbits.quickactionview.Action;
import com.ovenbits.quickactionview.ActionsTitleInAnimator;
import com.ovenbits.quickactionview.ActionsTitleOutAnimator;

/**
* Default animator which animates the action title in and out
*/
public class FadeInFadeOutActionsTitleAnimator implements ActionsTitleInAnimator, ActionsTitleOutAnimator {

private int mDuration; //ms

public FadeInFadeOutActionsTitleAnimator() {
this(100);
}

public FadeInFadeOutActionsTitleAnimator(int duration) {
mDuration = duration;
}

@Override
public void animateActionTitleIn(Action action, int index, View view) {
view.setAlpha(0.0f);
view.animate().alpha(1.0f).setDuration(mDuration);
}

@Override
public int animateActionTitleOut(Action action, int index, View view) {
view.animate().alpha(0.0f).setDuration(mDuration);
return mDuration;
}
}

0 comments on commit 88c5d61

Please sign in to comment.