Skip to content

Commit

Permalink
can make a direction disable
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecialCyCi committed Apr 13, 2014
1 parent dfec012 commit 6cc421c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions ResideMenu/src/com/special/ResideMenu/ResideMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ResideMenu extends FrameLayout implements GestureDetector.OnGesture
private float lastRawX;
private boolean canScale = false;
private int scaleDirection = DIRECTION_LEFT;
private List<Integer> disableDirection = new ArrayList<Integer>();

public ResideMenu(Context context) {
super(context);
Expand Down Expand Up @@ -242,6 +243,9 @@ private void setViewPadding(){
*/
@Deprecated
public void openMenu(int direction){
if (isInDisableDirection(direction))
throw new IllegalArgumentException("You have set this direction disable, but now you want to open menu in this direction.");

isOpened = true;
setScaleDirection(direction);
AnimatorSet scaleDown_activity = buildScaleDownAnimation(view_activity, 0.5f, 0.5f);
Expand All @@ -257,6 +261,7 @@ public void openMenu(int direction){
* close the reslide menu;
*/
public void closeMenu(){

isOpened = false;
AnimatorSet scaleUp_activity = buildScaleUpAnimation(view_activity, 1.0f, 1.0f);
AnimatorSet scaleUp_shadow = buildScaleUpAnimation(iv_shadow, 1.0f, 1.0f);
Expand All @@ -267,15 +272,16 @@ public void closeMenu(){
scaleUp_activity.start();
}

private List<Integer> disableScaleDirection = new ArrayList<Integer>();
public void setDisableDirection(int direction){
disableDirection.add(direction);
}

public void setDisableScaleDirection(int direction){
disableScaleDirection.add(direction);
private boolean isInDisableDirection(int direction){
return disableDirection.contains(direction);
}

private void setScaleDirection(int direction){
if (disableScaleDirection.contains(direction))
return;

int screenWidth = getScreenWidth();
float pivotX;
float pivotY = getScreenHeight() * 0.5f;
Expand Down Expand Up @@ -460,33 +466,33 @@ private float getTargetScale(float currentRawX){

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
float activityScale = ViewHelper.getScaleX(view_activity);
float currentActivityScaleX = ViewHelper.getScaleX(view_activity);
if (currentActivityScaleX == 1.0f)
setScaleDirectionByRawX(ev.getRawX());

switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
canScale = !isInIgnoredView(ev);
break;

case MotionEvent.ACTION_MOVE:
if (!canScale)
if (!canScale || isInDisableDirection(scaleDirection))
break;
if (activityScale == 1.0f)
setScaleDirectionByRawX(ev.getRawX());
if (activityScale < 0.95)
if (currentActivityScaleX < 0.95)
sv_menu.setVisibility(VISIBLE);

float targetScale = getTargetScale(ev.getRawX());
ViewHelper.setScaleX(view_activity, targetScale);
ViewHelper.setScaleY(view_activity, targetScale);
ViewHelper.setScaleX(iv_shadow, targetScale + shadow_AdjustScaleX);
ViewHelper.setScaleY(iv_shadow, targetScale + shadow_AdjustScaleY);
ViewHelper.setAlpha(sv_menu, ( 1 - targetScale ) * 2.0f);
ViewHelper.setAlpha(sv_menu, (1 - targetScale) * 2.0f);
break;

case MotionEvent.ACTION_UP:
if (!canScale)
break;
if (activityScale > 0.75f){
if (currentActivityScaleX > 0.75f){
closeMenu();
}else{
openMenu(scaleDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void setUpMenu() {
resideMenu.addMenuItem(itemCalendar, ResideMenu.DIRECTION_RIGHT);
resideMenu.addMenuItem(itemSettings, ResideMenu.DIRECTION_RIGHT);

resideMenu.setDisableScaleDirection(ResideMenu.DIRECTION_RIGHT);
resideMenu.setDisableDirection(ResideMenu.DIRECTION_RIGHT);
findViewById(R.id.title_bar_menu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down

0 comments on commit 6cc421c

Please sign in to comment.