Skip to content
This repository was archived by the owner on Jan 30, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions library/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
buildToolsVersion "21.1.2"

defaultConfig {
// applicationId "com.oguzdev.circularfloatingactionmenu.library"
minSdkVersion 15
minSdkVersion 10
targetSdkVersion 21
versionCode 3
versionName "1.0.2"
Expand All @@ -26,6 +26,5 @@ repositories {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.nineoldandroids:library:2.4.0'
}

// apply from: '../gradle-mvn-push.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void detach() {
*/
public View getActivityContentView() {
try {
return ((Activity) getContext()).getWindow().getDecorView().findViewById(android.R.id.content);
return ((Activity) getContext()).findViewById(android.R.id.content);
}
catch(ClassCastException e) {
throw new ClassCastException("Please provide an Activity context for this FloatingActionButton.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.nineoldandroids.view.ViewHelper;
import com.oguzdev.circularfloatingactionmenu.library.animation.DefaultAnimationHandler;
import com.oguzdev.circularfloatingactionmenu.library.animation.MenuAnimationHandler;

Expand Down Expand Up @@ -118,7 +119,7 @@ public FloatingActionMenu(final View mainActionView,
// and ask the size from the system
addViewToCurrentContainer(item.view);
// Make item view invisible, just in case
item.view.setAlpha(0);
ViewHelper.setAlpha(item.view, 0);
// Wait for the right time
item.view.post(new ItemViewQueueListener(item));
}
Expand Down Expand Up @@ -505,7 +506,13 @@ public void removeViewFromCurrentContainer(View view) {
*/
private Point getScreenSize() {
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
if (android.os.Build.VERSION.SDK_INT >= 13) {
getWindowManager().getDefaultDisplay().getSize(size);
} else if (android.os.Build.VERSION.SDK_INT < 13) {
size.x = getWindowManager().getDefaultDisplay().getWidth();
size.y = getWindowManager().getDefaultDisplay().getHeight();
}

return size;
}

Expand Down Expand Up @@ -550,7 +557,7 @@ public void run() {
item.height = item.view.getMeasuredHeight();

// Revert everything back to normal
item.view.setAlpha(item.alpha);
ViewHelper.setAlpha(item.view, item.alpha);
// Remove the item view from view hierarchy
removeViewFromCurrentContainer(item.view);
}
Expand All @@ -573,7 +580,7 @@ public Item(View view, int width, int height) {
this.view = view;
this.width = width;
this.height = height;
alpha = view.getAlpha();
alpha = ViewHelper.getAlpha(view);
x = 0;
y = 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.oguzdev.circularfloatingactionmenu.library;

import android.view.View;


import static com.nineoldandroids.view.animation.AnimatorProxy.NEEDS_PROXY;
import static com.nineoldandroids.view.animation.AnimatorProxy.wrap;

/**
* Created by DwGG on 2015/4/4.
*/
public final class NineOldHelper {

public static Object getRealTarget(Object obj) {
return (NEEDS_PROXY ? wrap((View) obj) : obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package com.oguzdev.circularfloatingactionmenu.library;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand Down
65 changes: 42 additions & 23 deletions ...ava/com/oguzdev/circularfloatingactionmenu/library/animation/DefaultAnimationHandler.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
*/
package com.oguzdev.circularfloatingactionmenu.library.animation;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.graphics.Point;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.OvershootInterpolator;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.PropertyValuesHolder;
import com.nineoldandroids.view.ViewHelper;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.NineOldHelper;

/**
* An example animation handler
Expand All @@ -30,6 +31,7 @@ public DefaultAnimationHandler() {
setAnimating(false);
}


@Override
public void animateMenuOpening(Point center) {
super.animateMenuOpening(center);
Expand All @@ -39,18 +41,35 @@ public void animateMenuOpening(Point center) {
Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {

menu.getSubActionItems().get(i).view.setScaleX(0);
menu.getSubActionItems().get(i).view.setScaleY(0);
menu.getSubActionItems().get(i).view.setAlpha(0);

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
ViewHelper.setScaleX(menu.getSubActionItems().get(i).view, 0);
ViewHelper.setScaleY(menu.getSubActionItems().get(i).view, 0);
ViewHelper.setAlpha(menu.getSubActionItems().get(i).view, 0);

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("translationX", menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("translationY", menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat("rotation", 720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat("scaleX", 1);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat("scaleY", 1);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat("alpha", 1);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(NineOldHelper.getRealTarget(menu.getSubActionItems().get(i).view), pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);

// 使用ValueAnimator,效果同上
// final ValueAnimator animation = ValueAnimator.ofPropertyValuesHolder(pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
// final View targetView = menu.getSubActionItems().get(i).view;
// animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
// public void onAnimationUpdate(ValueAnimator animation) {
//
// ViewHelper.setTranslationX(targetView, (Float)animation.getAnimatedValue("translationX"));
// ViewHelper.setTranslationY(targetView, (Float)animation.getAnimatedValue("translationY"));
// ViewHelper.setRotation(targetView, (Float)animation.getAnimatedValue("rotation"));
// ViewHelper.setScaleX(targetView, (Float)animation.getAnimatedValue("scaleX"));
// ViewHelper.setScaleY(targetView, (Float)animation.getAnimatedValue("scaleY"));
// ViewHelper.setAlpha(targetView, (Float)animation.getAnimatedValue("alpha"));
// }
// });
// animation.setTarget(targetView);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new OvershootInterpolator(0.9f));
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));
Expand All @@ -77,14 +96,14 @@ public void animateMenuClosing(Point center) {

Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, - (menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2));
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("translationX", - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("translationY", - (menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2));
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat("rotation", -720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat("scaleX", 0);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat("scaleY", 0);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat("alpha", 0);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(NineOldHelper.getRealTarget(menu.getSubActionItems().get(i).view), pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
*/
package com.oguzdev.circularfloatingactionmenu.library.animation;

import android.animation.Animator;
import android.graphics.Point;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.view.ViewHelper;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;

/**
Expand Down Expand Up @@ -59,12 +60,12 @@ public void animateMenuClosing(Point center) {
*/
protected void restoreSubActionViewAfterAnimation(FloatingActionMenu.Item subActionItem, ActionType actionType) {
ViewGroup.LayoutParams params = subActionItem.view.getLayoutParams();
subActionItem.view.setTranslationX(0);
subActionItem.view.setTranslationY(0);
subActionItem.view.setRotation(0);
subActionItem.view.setScaleX(1);
subActionItem.view.setScaleY(1);
subActionItem.view.setAlpha(1);
ViewHelper.setTranslationX(subActionItem.view, 0);
ViewHelper.setTranslationY(subActionItem.view, 0);
ViewHelper.setRotation(subActionItem.view, 0);
ViewHelper.setScaleX(subActionItem.view, 1);
ViewHelper.setScaleY(subActionItem.view, 1);
ViewHelper.setAlpha(subActionItem.view, 1);
if(actionType == ActionType.OPENING) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) params;
if(menu.isSystemOverlay()) {
Expand Down
6 changes: 3 additions & 3 deletions samples/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.oguzdev.circularfloatingactionmenu.samples"
minSdkVersion 15
minSdkVersion 10
targetSdkVersion 21
versionCode 3
versionName "1.0.2"
Expand All @@ -22,6 +22,6 @@ android {
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.+'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:+'
}
4 changes: 2 additions & 2 deletions samples/src/main/java/com/oguzdev/circularfloatingactionmenu/samples/DemoActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.oguzdev.circularfloatingactionmenu.samples;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new ContentFragment())
.commit();
}
Expand Down
27 changes: 16 additions & 11 deletions ...rc/main/java/com/oguzdev/circularfloatingactionmenu/samples/MenuInScrollViewActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.oguzdev.circularfloatingactionmenu.samples;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
Expand All @@ -11,14 +10,13 @@
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;

import java.util.ArrayList;

public class MenuInScrollViewActivity extends ActionBarActivity implements FloatingActionMenu.MenuStateChangeListener, ViewTreeObserver.OnScrollChangedListener, View.OnLayoutChangeListener {
public class MenuInScrollViewActivity extends ActionBarActivity implements FloatingActionMenu.MenuStateChangeListener, ViewTreeObserver.OnScrollChangedListener, MyScrollView.OnSizeChangeListener {

private ArrayList<FloatingActionMenu> menus;
private FloatingActionMenu currentMenu;
Expand All @@ -31,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
final MyScrollView scrollView = (MyScrollView) findViewById(R.id.scrollView);
LinearLayout scrollViewBody = (LinearLayout) findViewById(R.id.scrollViewBody);

menus = new ArrayList<FloatingActionMenu>();
Expand Down Expand Up @@ -97,7 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
.build();

// Listen layout (size) changes on a main layout so that we could reposition the bottom menu
scrollView.addOnLayoutChangeListener(this);
// scrollView.addOnLayoutChangeListener(this);
scrollView.addSizeChangeListener(this);
}


Expand Down Expand Up @@ -146,12 +145,18 @@ public void onScrollChanged() {
}
}

// @Override
// public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// // update the position of the menu when the main layout changes size on events like soft keyboard open/close
// if(right - left != 0 && bottom - top != 0 &&
// (oldLeft != left || oldTop != top || oldRight != right || oldBottom != bottom) && bottomMenu != null) {
// bottomMenu.updateItemPositions();
// }
// }


@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// update the position of the menu when the main layout changes size on events like soft keyboard open/close
if(right - left != 0 && bottom - top != 0 &&
(oldLeft != left || oldTop != top || oldRight != right || oldBottom != bottom) && bottomMenu != null) {
bottomMenu.updateItemPositions();
}
public void onSizeChange(View v, int w, int h, int oldw, int oldh) {
bottomMenu.updateItemPositions();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.oguzdev.circularfloatingactionmenu.samples;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -23,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_with_custom_action_button);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new CustomButtonDemoFragment())
.commit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.oguzdev.circularfloatingactionmenu.samples;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -22,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_with_custom_animation);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new CustomAnimationDemoFragment())
.commit();
}
Expand Down
Loading