diff --git a/README.md b/README.md index 6b86f04..042a6cc 100644 --- a/README.md +++ b/README.md @@ -1,133 +1,42 @@ #AndroidResideMenu ------ -### 中文说明请点击 [这里][1] -The idea of ResideMenu is from Dribble [1][2] and [2][3]. It has come true and run in iOS devices. [iOS ResideMenu][4] -This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. +The idea of ResideMenu is from Dribble [1] and [2]. It has come true and run in iOS devices. [iOS ResideMenu][3] +This project is the ResideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution. - - - -Now with 3D support ! - -## DEMO -This copy is the demo. - -## Version Migration - -#### Upgrading to `v1.4` from `v1.3`, `v1.2`, `v1.1`, `v1.0` - -Duplicate the followed code in dispatchTouchEvent() of Activity, replace the old `dispatchTouchEvent()` code. - -```java - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - return resideMenu.dispatchTouchEvent(ev); - } -``` -## Requirements - -Run in Android 2.3 + - -## Installation - -### Gradle - -```gradle -repositories { - mavenCentral() -} -dependencies { - compile 'com.specyci:residemenu:1.6+' -} -``` - -### Other + - 1. import ResideMenu project to your workspace. - 2. make it as a dependency library project to your main project. -
**( see [example][5] )** +## Fixes +[Overlapping Soft NavigationBar to contentUI][4] -**or** +## [Default Usage][5] -If you want to merge ResideMenu with your project, you should follow these steps. +## Custom Usage - 1. Copy all files from src/com/special/ResideMenu to your project. - 2. Copy libs/nineoldandroids-library-2.4.0.jar to your project’s corresponding path: libs/ - 3. Copy res/drawable-hdpi/shadow.9.png to your project’s corresponding path: res/drawable-hdpi/ - 4. Copy res/layout/residemenu.xml and residemenu_item.xml to your project’s corresponding path: res/layout +Do your reside menu configurations, by creating an instance of ResideMenu with your custom layout's resource Ids. If you want to use default layout, just pass that variable as -1. -## Usage -init ResideMenu: write these code in Activity onCreate() ```java - // attach to current activity; - resideMenu = new ResideMenu(this); + resideMenu = new ResideMenu(activity, R.layout.menu_left, R.layout.menu_right); resideMenu.setBackground(R.drawable.menu_background); - resideMenu.attachToActivity(this); + resideMenu.attachToActivity(activity); + resideMenu.setScaleValue(0.5f); - // create menu items; - String titles[] = { "Home", "Profile", "Calendar", "Settings" }; - int icon[] = { R.drawable.icon_home, R.drawable.icon_profile, R.drawable.icon_calendar, R.drawable.icon_settings }; - - for (int i = 0; i < titles.length; i++){ - ResideMenuItem item = new ResideMenuItem(this, icon[i], titles[i]); - item.setOnClickListener(this); - resideMenu.addMenuItem(item, ResideMenu.DIRECTION_LEFT); // or ResideMenu.DIRECTION_RIGHT - } -``` -If you want to use slipping gesture to operate(lock/unlock) the menu, override this code in Acitivity dispatchTouchEvent() (please duplicate the followed code in dispatchTouchEvent() of Activity. -```java - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - return resideMenu.dispatchTouchEvent(ev); - } -``` -**On some occasions, the slipping gesture function for locking/unlocking menu, may have conflicts with your widgets, such as viewpager. By then you can add the viewpager to ignored view, please refer to next chapter – Ignored Views.** - -open/close menu -```java -resideMenu.openMenu(ResideMenu.DIRECTION_LEFT); // or ResideMenu.DIRECTION_RIGHT -resideMenu.closeMenu(); -``` - -listen in the menu state -```java - resideMenu.setMenuListener(menuListener); - private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() { - @Override - public void openMenu() { - Toast.makeText(mContext, "Menu is opened!", Toast.LENGTH_SHORT).show(); - } - - @Override - public void closeMenu() { - Toast.makeText(mContext, "Menu is closed!", Toast.LENGTH_SHORT).show(); - } - }; + resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT); + resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_LEFT); ``` -disable a swipe direction -```java - resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT); -``` +As your configuration's completed, now you can customize side menus by getting instances of them as following: -##Ignored Views -On some occasions, the slipping gesture function for locking/unlocking menu, may have conflicts with your widgets such as viewpager.By then you can add the viewpager to ignored view. ```java - // add gesture operation's ignored views - FrameLayout ignored_view = (FrameLayout) findViewById(R.id.ignored_view); - resideMenu.addIgnoredView(ignored_view); + View leftMenu = resideMenu.getLeftMenuView(); + // TODO: Do whatever you need to with leftMenu + View rightMenu = resideMenu.getRightMenuView(); + // TODO: Do whatever you need to with rightMenu ``` -So that in ignored view’s workplace, the slipping gesture will not be allowed to operate menu. - -##About me -A student from SCAU China.
-Email: specialcyci#gmail.com - - [1]: https://github.com/SpecialCyCi/AndroidResideMenu/blob/master/README_CN.md - [2]: http://dribbble.com/shots/1116265-Instasave-iPhone-App - [3]: http://dribbble.com/shots/1114754-Social-Feed-iOS7 - [4]: https://github.com/romaonthego/RESideMenu - [5]: https://github.com/SpecialCyCi/AndroidResideMenu/blob/master/ResideMenuDemo/project.properties + [1]: http://dribbble.com/shots/1116265-Instasave-iPhone-App + [2]: http://dribbble.com/shots/1114754-Social-Feed-iOS7 + [3]: https://github.com/romaonthego/RESideMenu + [4]: https://github.com/SpecialCyCi/AndroidResideMenu/issues/68 + [5]: https://github.com/SpecialCyCi/AndroidResideMenu#usage diff --git a/README_CN.md b/README_CN.md deleted file mode 100644 index 36a1d8b..0000000 --- a/README_CN.md +++ /dev/null @@ -1,129 +0,0 @@ -#AndroidResideMenu - ------- - -ReisdeMenu 创意灵感来自于Dribbble[1][1]还有[2][2],而这个是Android版的ResideMenu,在视觉效果上部分参考了[iOS版的RESideMenu][3],并在此感谢以上作者的贡献。 - - - -## DEMO - -本代码即是DEMO,您可以下载后选择您喜欢的IDE运行。SDK版本建议使用4.0以上 - -## Version Migration - -#### 从 `v1.0`, `v1.1`, `v1.2`, `v1.3` 升级到 `v1.4` - -如果你开启了手势滑动,你需要替换被依附的 Activity 里 `dispatchTouchEvent()` 代码 - -```java - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - return resideMenu.dispatchTouchEvent(ev); - } -``` - -## Requirements - -运行在 Android 2.3 + - -## Installation - -### Gradle - -```gradle -repositories { - mavenCentral() -} -dependencies { - compile 'com.specyci:residemenu:1.6+' -} -``` - -### Other - - 直接导入ResideMenu项目并作为依赖项目
- **[例子][6]** - -**or** - 直接合并到您的项目之中 - - 1. 复制src/com/special/ResideMenu下的所有代码到您的项目相应位置 - 2. 复制libs/nineoldandroids-library-2.4.0.jar到您项目libs/下 - 3. 复制res/drawable-hdpi/shadow.9.png到您的项目相应位置 - 4. 复制res/layout/residemenu.xml 和 residemenu_item.xml到您的项目相应位置 - -## Usage -写在Activity onCreate()中 -```java - // attach to current activity; - resideMenu = new ResideMenu(this); - resideMenu.setBackground(R.drawable.menu_background); - resideMenu.attachToActivity(this); - - // create menu items; - String titles[] = { "Home", "Profile", "Calendar", "Settings" }; - int icon[] = { R.drawable.icon_home, R.drawable.icon_profile, R.drawable.icon_calendar, R.drawable.icon_settings }; - - for (int i = 0; i < titles.length; i++){ - ResideMenuItem item = new ResideMenuItem(this, icon[i], titles[i]); - item.setOnClickListener(this); - resideMenu.addMenuItem(item, ResideMenu.DIRECTION_LEFT); // or ResideMenu.DIRECTION_RIGHT - } -``` -如果您需要使用手势滑动开启/关闭菜单,请复写activity的dispatchTouchEvent(),代码如下 -```java - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - return resideMenu.dispatchTouchEvent(ev); - } -``` -**在某些场景下,手势滑动开启/关闭菜单可能与您的某些控件产生冲突,例如viewpager,这时您可以把viewpager添加到ignored view.请参见下节Ignored Views** - -开启/关闭菜单 -open or close menu -```java -resideMenu.openMenu(ResideMenu.DIRECTION_LEFT); // or ResideMenu.DIRECTION_RIGHT -resideMenu.closeMenu(); -``` -监听菜单状态 -```java - resideMenu.setMenuListener(menuListener); - private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() { - @Override - public void openMenu() { - Toast.makeText(mContext, "Menu is opened!", Toast.LENGTH_SHORT).show(); - } - - @Override - public void closeMenu() { - Toast.makeText(mContext, "Menu is closed!", Toast.LENGTH_SHORT).show(); - } - }; -``` - -禁止手势操作某个菜单方向 -```java - resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT); -``` - - -##Ignored Views -在某些场景下,手势滑动开启/关闭菜单可能与您的某些控件产生冲突,例如viewpager,这时您可以把viewpager添加到ignored view. -```java - // add gesture operation's ignored views - FrameLayout ignored_view = (FrameLayout) findViewById(R.id.ignored_view); - resideMenu.addIgnoredView(ignored_view); -``` -这样子在ignored_view操作的区域就不允许用手势滑动操作菜单. - -##About me -A student from SCAU China.
-Email: specialcyci#gmail.com - -[1]: http://dribbble.com/shots/1116265-Instasave-iPhone-App -[2]: http://dribbble.com/shots/1114754-Social-Feed-iOS7 -[3]: https://github.com/romaonthego/RESideMenu -[4]: http://dribbble.com/shots/1116265-Instasave-iPhone-App -[5]: http://dribbble.com/shots/1114754-Social-Feed-iOS7 -[6]: https://github.com/SpecialCyCi/AndroidResideMenu/blob/master/ResideMenuDemo/project.properties diff --git a/ResideMenu/res/layout/residemenu.xml b/ResideMenu/res/layout/residemenu.xml deleted file mode 100644 index 3b8bb19..0000000 --- a/ResideMenu/res/layout/residemenu.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ResideMenu/res/layout/residemenu_custom.xml b/ResideMenu/res/layout/residemenu_custom.xml new file mode 100755 index 0000000..bdfa53b --- /dev/null +++ b/ResideMenu/res/layout/residemenu_custom.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ResideMenu/res/layout/residemenu_custom_left_scrollview.xml b/ResideMenu/res/layout/residemenu_custom_left_scrollview.xml new file mode 100755 index 0000000..0d31a0b --- /dev/null +++ b/ResideMenu/res/layout/residemenu_custom_left_scrollview.xml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ResideMenu/res/layout/residemenu_custom_right_scrollview.xml b/ResideMenu/res/layout/residemenu_custom_right_scrollview.xml new file mode 100755 index 0000000..2816f54 --- /dev/null +++ b/ResideMenu/res/layout/residemenu_custom_right_scrollview.xml @@ -0,0 +1,24 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ResideMenu/src/com/special/ResideMenu/ResideMenu.java b/ResideMenu/src/com/special/ResideMenu/ResideMenu.java index c7945ee..1dc72bf 100644 --- a/ResideMenu/src/com/special/ResideMenu/ResideMenu.java +++ b/ResideMenu/src/com/special/ResideMenu/ResideMenu.java @@ -11,6 +11,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ScrollView; + import com.nineoldandroids.animation.Animator; import com.nineoldandroids.animation.AnimatorSet; import com.nineoldandroids.animation.ObjectAnimator; @@ -25,10 +26,10 @@ * Time: 下午10:44 * Mail: specialcyci@gmail.com */ -public class ResideMenu extends FrameLayout{ +public class ResideMenu extends FrameLayout { - public static final int DIRECTION_LEFT = 0; - public static final int DIRECTION_RIGHT = 1; + public static final int DIRECTION_LEFT = 0; + public static final int DIRECTION_RIGHT = 1; private static final int PRESSED_MOVE_HORIZONTAL = 2; private static final int PRESSED_DOWN = 3; private static final int PRESSED_DONE = 4; @@ -38,19 +39,27 @@ public class ResideMenu extends FrameLayout{ private ImageView imageViewBackground; private LinearLayout layoutLeftMenu; private LinearLayout layoutRightMenu; - private ScrollView scrollViewLeftMenu; - private ScrollView scrollViewRightMenu; - private ScrollView scrollViewMenu; - /** Current attaching activity. */ + private View scrollViewLeftMenu; + private View scrollViewRightMenu; + private View scrollViewMenu; + /** + * Current attaching activity. + */ private Activity activity; - /** The DecorView of current activity. */ + /** + * The DecorView of current activity. + */ private ViewGroup viewDecor; private TouchDisableView viewActivity; - /** The flag of menu opening status. */ - private boolean isOpened; + /** + * The flag of menu opening status. + */ + private boolean isOpened; private float shadowAdjustScaleX; private float shadowAdjustScaleY; - /** Views which need stop to intercept touch events. */ + /** + * Views which need stop to intercept touch events. + */ private List ignoredViews; private List leftMenuItems; private List rightMenuItems; @@ -59,7 +68,7 @@ public class ResideMenu extends FrameLayout{ private float lastRawX; private boolean isInIgnoredView = false; private int scaleDirection = DIRECTION_LEFT; - private int pressedState = PRESSED_DOWN; + private int pressedState = PRESSED_DOWN; private List disabledSwipeDirection = new ArrayList(); // Valid scale factor is between 0.0f and 1.0f. private float mScaleValue = 0.5f; @@ -69,52 +78,115 @@ public class ResideMenu extends FrameLayout{ public ResideMenu(Context context) { super(context); - initViews(context); + initViews(context, -1, -1); + } + + /** + * This constructor provides you to create menus with your own custom + * layouts, but if you use custom menu then do not call addMenuItem because + * it will not be able to find default views + */ + public ResideMenu(Context context, int customLeftMenuId, + int customRightMenuId) { + super(context); + initViews(context, customLeftMenuId, customRightMenuId); } - private void initViews(Context context){ - LayoutInflater inflater = (LayoutInflater) - context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.residemenu, this); - scrollViewLeftMenu = (ScrollView) findViewById(R.id.sv_left_menu); - scrollViewRightMenu = (ScrollView) findViewById(R.id.sv_right_menu); + private void initViews(Context context, int customLeftMenuId, + int customRightMenuId) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + inflater.inflate(R.layout.residemenu_custom, this); + + if (customLeftMenuId >= 0) { + scrollViewLeftMenu = inflater.inflate(customLeftMenuId, this, false); + } else { + scrollViewLeftMenu = inflater.inflate( + R.layout.residemenu_custom_left_scrollview, this, false); + layoutLeftMenu = (LinearLayout) scrollViewLeftMenu.findViewById(R.id.layout_left_menu); + } + + if (customRightMenuId >= 0) { + scrollViewRightMenu = inflater.inflate(customRightMenuId, this, false); + } else { + scrollViewRightMenu = inflater.inflate( + R.layout.residemenu_custom_right_scrollview, this, false); + layoutRightMenu = (LinearLayout) scrollViewRightMenu.findViewById(R.id.layout_right_menu); + } + imageViewShadow = (ImageView) findViewById(R.id.iv_shadow); - layoutLeftMenu = (LinearLayout) findViewById(R.id.layout_left_menu); - layoutRightMenu = (LinearLayout) findViewById(R.id.layout_right_menu); imageViewBackground = (ImageView) findViewById(R.id.iv_background); + + RelativeLayout menuHolder = (RelativeLayout) findViewById(R.id.sv_menu_holder); + menuHolder.addView(scrollViewLeftMenu); + menuHolder.addView(scrollViewRightMenu); + } + + /** + * Returns left menu view so you can findViews and do whatever you want with + */ + public View getLeftMenuView() { + return scrollViewLeftMenu; + } + + /** + * Returns right menu view so you can findViews and do whatever you want with + */ + public View getRightMenuView() { + return scrollViewRightMenu; } @Override protected boolean fitSystemWindows(Rect insets) { - // Applies the content insets to the view's padding, consuming that content (modifying the insets to be 0), - // and returning true. This behavior is off by default and can be enabled through setFitsSystemWindows(boolean) + // Applies the content insets to the view's padding, consuming that + // content (modifying the insets to be 0), + // and returning true. This behavior is off by default and can be + // enabled through setFitsSystemWindows(boolean) // in api14+ devices. - this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top, - viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + insets.bottom); + + // This is added to fix soft navigationBar's overlapping to content above LOLLIPOP + int bottomPadding = viewActivity.getPaddingBottom() + insets.bottom; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + bottomPadding += getNavigationBarHeight(); + } + + this.setPadding(viewActivity.getPaddingLeft() + insets.left, + viewActivity.getPaddingTop() + insets.top, + viewActivity.getPaddingRight() + insets.right, + bottomPadding); insets.left = insets.top = insets.right = insets.bottom = 0; return true; } + private int getNavigationBarHeight() { + Resources resources = getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + return resources.getDimensionPixelSize(resourceId); + } + return 0; + } + /** * Set up the activity; * * @param activity */ - public void attachToActivity(Activity activity){ + public void attachToActivity(Activity activity) { initValue(activity); setShadowAdjustScaleXByOrientation(); viewDecor.addView(this, 0); } - private void initValue(Activity activity){ - this.activity = activity; - leftMenuItems = new ArrayList(); - rightMenuItems = new ArrayList(); - ignoredViews = new ArrayList(); + private void initValue(Activity activity) { + this.activity = activity; + leftMenuItems = new ArrayList(); + rightMenuItems = new ArrayList(); + ignoredViews = new ArrayList(); viewDecor = (ViewGroup) activity.getWindow().getDecorView(); viewActivity = new TouchDisableView(this.activity); - View mContent = viewDecor.getChildAt(0); + View mContent = viewDecor.getChildAt(0); viewDecor.removeViewAt(0); viewActivity.setContent(mContent); addView(viewActivity); @@ -124,7 +196,7 @@ private void initValue(Activity activity){ parent.removeView(scrollViewRightMenu); } - private void setShadowAdjustScaleXByOrientation(){ + private void setShadowAdjustScaleXByOrientation() { int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { shadowAdjustScaleX = 0.034f; @@ -140,7 +212,7 @@ private void setShadowAdjustScaleXByOrientation(){ * * @param imageResource */ - public void setBackground(int imageResource){ + public void setBackground(int imageResource) { imageViewBackground.setImageResource(imageResource); } @@ -149,7 +221,7 @@ public void setBackground(int imageResource){ * * @param isVisible */ - public void setShadowVisible(boolean isVisible){ + public void setShadowVisible(boolean isVisible) { if (isVisible) imageViewShadow.setBackgroundResource(R.drawable.shadow); else @@ -158,12 +230,13 @@ public void setShadowVisible(boolean isVisible){ /** * Add a single item to the left menu; - * + *

* WARNING: It will be removed from v2.0. + * * @param menuItem */ @Deprecated - public void addMenuItem(ResideMenuItem menuItem){ + public void addMenuItem(ResideMenuItem menuItem) { this.leftMenuItems.add(menuItem); layoutLeftMenu.addView(menuItem); } @@ -174,11 +247,11 @@ public void addMenuItem(ResideMenuItem menuItem){ * @param menuItem * @param direction */ - public void addMenuItem(ResideMenuItem menuItem, int direction){ - if (direction == DIRECTION_LEFT){ + public void addMenuItem(ResideMenuItem menuItem, int direction) { + if (direction == DIRECTION_LEFT) { this.leftMenuItems.add(menuItem); layoutLeftMenu.addView(menuItem); - }else{ + } else { this.rightMenuItems.add(menuItem); layoutRightMenu.addView(menuItem); } @@ -186,10 +259,11 @@ public void addMenuItem(ResideMenuItem menuItem, int direction){ /** * WARNING: It will be removed from v2.0. + * * @param menuItems */ @Deprecated - public void setMenuItems(List menuItems){ + public void setMenuItems(List menuItems) { this.leftMenuItems = menuItems; rebuildMenu(); } @@ -200,7 +274,7 @@ public void setMenuItems(List menuItems){ * @param menuItems * @param direction */ - public void setMenuItems(List menuItems, int direction){ + public void setMenuItems(List menuItems, int direction) { if (direction == DIRECTION_LEFT) this.leftMenuItems = menuItems; else @@ -208,17 +282,23 @@ public void setMenuItems(List menuItems, int direction){ rebuildMenu(); } - private void rebuildMenu(){ - layoutLeftMenu.removeAllViews(); - layoutRightMenu.removeAllViews(); - for (ResideMenuItem leftMenuItem : leftMenuItems) - layoutLeftMenu.addView(leftMenuItem); - for (ResideMenuItem rightMenuItem : rightMenuItems) - layoutRightMenu.addView(rightMenuItem); + private void rebuildMenu() { + if (layoutLeftMenu != null) { + layoutLeftMenu.removeAllViews(); + for (ResideMenuItem leftMenuItem : leftMenuItems) + layoutLeftMenu.addView(leftMenuItem); + } + + if (layoutRightMenu != null) { + layoutRightMenu.removeAllViews(); + for (ResideMenuItem rightMenuItem : rightMenuItems) + layoutRightMenu.addView(rightMenuItem); + } } /** * WARNING: It will be removed from v2.0. + * * @return */ @Deprecated @@ -232,7 +312,7 @@ public List getMenuItems() { * @return */ public List getMenuItems(int direction) { - if ( direction == DIRECTION_LEFT) + if (direction == DIRECTION_LEFT) return leftMenuItems; else return rightMenuItems; @@ -256,14 +336,14 @@ public OnMenuListener getMenuListener() { /** * Show the menu; */ - public void openMenu(int direction){ + public void openMenu(int direction) { setScaleDirection(direction); isOpened = true; AnimatorSet scaleDown_activity = buildScaleDownAnimation(viewActivity, mScaleValue, mScaleValue); AnimatorSet scaleDown_shadow = buildScaleDownAnimation(imageViewShadow, - mScaleValue + shadowAdjustScaleX, mScaleValue + shadowAdjustScaleY); + mScaleValue + shadowAdjustScaleX, mScaleValue + shadowAdjustScaleY); AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 1.0f); scaleDown_shadow.addListener(animationListener); scaleDown_activity.playTogether(scaleDown_shadow); @@ -274,7 +354,7 @@ public void openMenu(int direction){ /** * Close the menu; */ - public void closeMenu(){ + public void closeMenu() { isOpened = false; AnimatorSet scaleUp_activity = buildScaleUpAnimation(viewActivity, 1.0f, 1.0f); @@ -287,30 +367,30 @@ public void closeMenu(){ } @Deprecated - public void setDirectionDisable(int direction){ + public void setDirectionDisable(int direction) { disabledSwipeDirection.add(direction); } - public void setSwipeDirectionDisable(int direction){ + public void setSwipeDirectionDisable(int direction) { disabledSwipeDirection.add(direction); } - private boolean isInDisableDirection(int direction){ + private boolean isInDisableDirection(int direction) { return disabledSwipeDirection.contains(direction); } - private void setScaleDirection(int direction){ + private void setScaleDirection(int direction) { int screenWidth = getScreenWidth(); float pivotX; float pivotY = getScreenHeight() * 0.5f; - if (direction == DIRECTION_LEFT){ + if (direction == DIRECTION_LEFT) { scrollViewMenu = scrollViewLeftMenu; - pivotX = screenWidth * 1.5f; - }else{ + pivotX = screenWidth * 1.5f; + } else { scrollViewMenu = scrollViewRightMenu; - pivotX = screenWidth * -0.5f; + pivotX = screenWidth * -0.5f; } ViewHelper.setPivotX(viewActivity, pivotX); @@ -339,7 +419,7 @@ public void onClick(View view) { private Animator.AnimatorListener animationListener = new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { - if (isOpened()){ + if (isOpened()) { showScrollViewMenu(scrollViewMenu); if (menuListener != null) menuListener.openMenu(); @@ -349,10 +429,10 @@ public void onAnimationStart(Animator animation) { @Override public void onAnimationEnd(Animator animation) { // reset the view; - if(isOpened()){ + if (isOpened()) { viewActivity.setTouchDisable(true); viewActivity.setOnClickListener(viewActivityOnClickListener); - }else{ + } else { viewActivity.setTouchDisable(false); viewActivity.setOnClickListener(null); hideScrollViewMenu(scrollViewLeftMenu); @@ -381,7 +461,7 @@ public void onAnimationRepeat(Animator animation) { * @param targetScaleY * @return */ - private AnimatorSet buildScaleDownAnimation(View target,float targetScaleX,float targetScaleY){ + private AnimatorSet buildScaleDownAnimation(View target, float targetScaleX, float targetScaleY) { AnimatorSet scaleDown = new AnimatorSet(); scaleDown.playTogether( @@ -408,7 +488,7 @@ private AnimatorSet buildScaleDownAnimation(View target,float targetScaleX,float * @param targetScaleY * @return */ - private AnimatorSet buildScaleUpAnimation(View target,float targetScaleX,float targetScaleY){ + private AnimatorSet buildScaleUpAnimation(View target, float targetScaleX, float targetScaleY) { AnimatorSet scaleUp = new AnimatorSet(); scaleUp.playTogether( @@ -424,7 +504,7 @@ private AnimatorSet buildScaleUpAnimation(View target,float targetScaleX,float t return scaleUp; } - private AnimatorSet buildMenuAnimation(View target, float alpha){ + private AnimatorSet buildMenuAnimation(View target, float alpha) { AnimatorSet alphaAnimation = new AnimatorSet(); alphaAnimation.playTogether( @@ -442,22 +522,23 @@ private AnimatorSet buildMenuAnimation(View target, float alpha){ * * @param v */ - public void addIgnoredView(View v){ + public void addIgnoredView(View v) { ignoredViews.add(v); } /** * Remove a view from ignored views; + * * @param v */ - public void removeIgnoredView(View v){ + public void removeIgnoredView(View v) { ignoredViews.remove(v); } /** * Clear the ignored view list; */ - public void clearIgnoredViewList(){ + public void clearIgnoredViewList() { ignoredViews.clear(); } @@ -478,16 +559,16 @@ private boolean isInIgnoredView(MotionEvent ev) { return false; } - private void setScaleDirectionByRawX(float currentRawX){ + private void setScaleDirectionByRawX(float currentRawX) { if (currentRawX < lastRawX) setScaleDirection(DIRECTION_RIGHT); else setScaleDirection(DIRECTION_LEFT); } - private float getTargetScale(float currentRawX){ + private float getTargetScale(float currentRawX) { float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f; - scaleFloatX = scaleDirection == DIRECTION_RIGHT ? - scaleFloatX : scaleFloatX; + scaleFloatX = scaleDirection == DIRECTION_RIGHT ? -scaleFloatX : scaleFloatX; float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX; targetScale = targetScale > 1.0f ? 1.0f : targetScale; @@ -503,35 +584,35 @@ public boolean dispatchTouchEvent(MotionEvent ev) { if (currentActivityScaleX == 1.0f) setScaleDirectionByRawX(ev.getRawX()); - switch (ev.getAction()){ + switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastActionDownX = ev.getX(); lastActionDownY = ev.getY(); isInIgnoredView = isInIgnoredView(ev) && !isOpened(); - pressedState = PRESSED_DOWN; + pressedState = PRESSED_DOWN; break; case MotionEvent.ACTION_MOVE: if (isInIgnoredView || isInDisableDirection(scaleDirection)) break; - if(pressedState != PRESSED_DOWN && + if (pressedState != PRESSED_DOWN && pressedState != PRESSED_MOVE_HORIZONTAL) break; int xOffset = (int) (ev.getX() - lastActionDownX); int yOffset = (int) (ev.getY() - lastActionDownY); - if(pressedState == PRESSED_DOWN) { - if(yOffset > 25 || yOffset < -25) { + if (pressedState == PRESSED_DOWN) { + if (yOffset > 25 || yOffset < -25) { pressedState = PRESSED_MOVE_VERTICAL; break; } - if(xOffset < -50 || xOffset > 50) { + if (xOffset < -50 || xOffset > 50) { pressedState = PRESSED_MOVE_HORIZONTAL; ev.setAction(MotionEvent.ACTION_CANCEL); } - } else if(pressedState == PRESSED_MOVE_HORIZONTAL) { + } else if (pressedState == PRESSED_MOVE_HORIZONTAL) { if (currentActivityScaleX < 0.95) showScrollViewMenu(scrollViewMenu); @@ -554,15 +635,15 @@ public boolean dispatchTouchEvent(MotionEvent ev) { if (pressedState != PRESSED_MOVE_HORIZONTAL) break; pressedState = PRESSED_DONE; - if (isOpened()){ + if (isOpened()) { if (currentActivityScaleX > 0.56f) closeMenu(); else openMenu(scaleDirection); - }else{ - if (currentActivityScaleX < 0.94f){ + } else { + if (currentActivityScaleX < 0.94f) { openMenu(scaleDirection); - }else{ + } else { closeMenu(); } } @@ -574,16 +655,16 @@ public boolean dispatchTouchEvent(MotionEvent ev) { return super.dispatchTouchEvent(ev); } - public int getScreenHeight(){ + public int getScreenHeight() { activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics.heightPixels; } - public int getScreenWidth(){ + public int getScreenWidth() { activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics.widthPixels; } - + public void setScaleValue(float scaleValue) { this.mScaleValue = scaleValue; } @@ -592,7 +673,7 @@ public void setUse3D(boolean use3D) { mUse3D = use3D; } - public interface OnMenuListener{ + public interface OnMenuListener { /** * This method will be called at the finished time of opening menu animations. @@ -605,14 +686,14 @@ public interface OnMenuListener{ public void closeMenu(); } - private void showScrollViewMenu(ScrollView scrollViewMenu){ - if (scrollViewMenu != null && scrollViewMenu.getParent() == null){ + private void showScrollViewMenu(ScrollView scrollViewMenu) { + if (scrollViewMenu != null && scrollViewMenu.getParent() == null) { addView(scrollViewMenu); } } - private void hideScrollViewMenu(ScrollView scrollViewMenu){ - if (scrollViewMenu != null && scrollViewMenu.getParent() != null){ + private void hideScrollViewMenu(ScrollView scrollViewMenu) { + if (scrollViewMenu != null && scrollViewMenu.getParent() != null) { removeView(scrollViewMenu); } }