Skip to content

Commit

Permalink
Format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecialCyCi committed May 26, 2014
1 parent 78db7d6 commit 7543ef2
Showing 1 changed file with 68 additions and 68 deletions.
136 changes: 68 additions & 68 deletions ResideMenu/src/com/special/ResideMenu/ResideMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ public class ResideMenu extends FrameLayout implements GestureDetector.OnGesture
public static final int DIRECTION_LEFT = 0;
public static final int DIRECTION_RIGHT = 1;

private ImageView iv_shadow;
private ImageView iv_background;
private LinearLayout layout_left_menu;
private LinearLayout layout_right_menu;
private ScrollView sv_left_menu;
private ScrollView sv_right_menu;
private ScrollView sv_menu;
private ImageView imageViewShadow;
private ImageView imageViewBackground;
private LinearLayout layoutLeftMenu;
private LinearLayout layoutRightMenu;
private ScrollView scrollViewLeftMenu;
private ScrollView scrollViewRightMenu;
private ScrollView scrollViewMenu;
/** the activity that view attach to */
private Activity activity;
/** the decorview of the activity */
private ViewGroup view_decor;
private ViewGroup viewDecor;
/** the viewgroup of the activity */
private TouchDisableView view_activity;
private TouchDisableView viewActivity;
/** the flag of menu open status */
private boolean isOpened;
private GestureDetector gestureDetector;
private float shadow_AdjustScaleX;
private float shadow_AdjustScaleY;
private float shadowAdjustScaleX;
private float shadowAdjustScaleY;
/** the view which don't want to intercept touch event */
private List<View> ignoredViews;
private List<ResideMenuItem> leftMenuItems;
Expand All @@ -67,12 +67,12 @@ public ResideMenu(Context context) {
private void initViews(Context context){
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.residemenu, this);
sv_left_menu = (ScrollView) findViewById(R.id.sv_left_menu);
sv_right_menu = (ScrollView) findViewById(R.id.sv_right_menu);
iv_shadow = (ImageView) findViewById(R.id.iv_shadow);
layout_left_menu = (LinearLayout) findViewById(R.id.layout_left_menu);
layout_right_menu = (LinearLayout) findViewById(R.id.layout_right_menu);
iv_background = (ImageView) findViewById(R.id.iv_background);
scrollViewLeftMenu = (ScrollView) findViewById(R.id.sv_left_menu);
scrollViewRightMenu = (ScrollView) findViewById(R.id.sv_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);
}

/**
Expand All @@ -83,7 +83,7 @@ private void initViews(Context context){
public void attachToActivity(Activity activity){
initValue(activity);
setShadowAdjustScaleXByOrientation();
view_decor.addView(this, 0);
viewDecor.addView(this, 0);
setViewPadding();
}

Expand All @@ -93,23 +93,23 @@ private void initValue(Activity activity){
rightMenuItems = new ArrayList<ResideMenuItem>();
gestureDetector = new GestureDetector(this);
ignoredViews = new ArrayList<View>();
view_decor = (ViewGroup) activity.getWindow().getDecorView();
view_activity = new TouchDisableView(this.activity);
viewDecor = (ViewGroup) activity.getWindow().getDecorView();
viewActivity = new TouchDisableView(this.activity);

View mContent = view_decor.getChildAt(0);
view_decor.removeViewAt(0);
view_activity.setContent(mContent);
view_decor.addView(view_activity, 0);
View mContent = viewDecor.getChildAt(0);
viewDecor.removeViewAt(0);
viewActivity.setContent(mContent);
viewDecor.addView(viewActivity, 0);
}

private void setShadowAdjustScaleXByOrientation(){
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
shadow_AdjustScaleX = 0.034f;
shadow_AdjustScaleY = 0.12f;
shadowAdjustScaleX = 0.034f;
shadowAdjustScaleY = 0.12f;
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
shadow_AdjustScaleX = 0.06f;
shadow_AdjustScaleY = 0.07f;
shadowAdjustScaleX = 0.06f;
shadowAdjustScaleY = 0.07f;
}
}

Expand All @@ -119,7 +119,7 @@ private void setShadowAdjustScaleXByOrientation(){
* @param imageResrouce
*/
public void setBackground(int imageResrouce){
iv_background.setImageResource(imageResrouce);
imageViewBackground.setImageResource(imageResrouce);
}

/**
Expand All @@ -129,9 +129,9 @@ public void setBackground(int imageResrouce){
*/
public void setShadowVisible(boolean isVisible){
if (isVisible)
iv_shadow.setImageResource(R.drawable.shadow);
imageViewShadow.setImageResource(R.drawable.shadow);
else
iv_shadow.setImageBitmap(null);
imageViewShadow.setImageBitmap(null);
}

/**
Expand All @@ -142,7 +142,7 @@ public void setShadowVisible(boolean isVisible){
@Deprecated
public void addMenuItem(ResideMenuItem menuItem){
this.leftMenuItems.add(menuItem);
layout_left_menu.addView(menuItem);
layoutLeftMenu.addView(menuItem);
}

/**
Expand All @@ -154,10 +154,10 @@ public void addMenuItem(ResideMenuItem menuItem){
public void addMenuItem(ResideMenuItem menuItem, int direction){
if (direction == DIRECTION_LEFT){
this.leftMenuItems.add(menuItem);
layout_left_menu.addView(menuItem);
layoutLeftMenu.addView(menuItem);
}else{
this.rightMenuItems.add(menuItem);
layout_right_menu.addView(menuItem);
layoutRightMenu.addView(menuItem);
}
}

Expand Down Expand Up @@ -187,12 +187,12 @@ public void setMenuItems(List<ResideMenuItem> menuItems, int direction){
}

private void rebuildMenu(){
layout_left_menu.removeAllViews();
layout_right_menu.removeAllViews();
layoutLeftMenu.removeAllViews();
layoutRightMenu.removeAllViews();
for(int i = 0; i < leftMenuItems.size() ; i ++)
layout_left_menu.addView(leftMenuItems.get(i), i);
layoutLeftMenu.addView(leftMenuItems.get(i), i);
for(int i = 0; i < rightMenuItems.size() ; i ++)
layout_right_menu.addView(rightMenuItems.get(i), i);
layoutRightMenu.addView(rightMenuItems.get(i), i);
}

/**
Expand Down Expand Up @@ -237,10 +237,10 @@ public OnMenuListener getMenuListener() {
* padding of activity can't get at the moment of onCreateView();
*/
private void setViewPadding(){
this.setPadding(view_activity.getPaddingLeft(),
view_activity.getPaddingTop(),
view_activity.getPaddingRight(),
view_activity.getPaddingBottom());
this.setPadding(viewActivity.getPaddingLeft(),
viewActivity.getPaddingTop(),
viewActivity.getPaddingRight(),
viewActivity.getPaddingBottom());
}

/**
Expand All @@ -252,9 +252,9 @@ public void openMenu(int direction){
setScaleDirection(direction);

isOpened = true;
AnimatorSet scaleDown_activity = buildScaleDownAnimation(view_activity, 0.5f, 0.5f);
AnimatorSet scaleDown_shadow = buildScaleDownAnimation(iv_shadow, 0.5f + shadow_AdjustScaleX, 0.5f + shadow_AdjustScaleY);
AnimatorSet alpha_menu = buildMenuAnimation(sv_menu, 1.0f);
AnimatorSet scaleDown_activity = buildScaleDownAnimation(viewActivity, 0.5f, 0.5f);
AnimatorSet scaleDown_shadow = buildScaleDownAnimation(imageViewShadow, 0.5f + shadowAdjustScaleX, 0.5f + shadowAdjustScaleY);
AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 1.0f);
scaleDown_shadow.addListener(animationListener);
scaleDown_activity.playTogether(scaleDown_shadow);
scaleDown_activity.playTogether(alpha_menu);
Expand All @@ -267,9 +267,9 @@ public void openMenu(int direction){
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);
AnimatorSet alpha_menu = buildMenuAnimation(sv_menu, 0.0f);
AnimatorSet scaleUp_activity = buildScaleUpAnimation(viewActivity, 1.0f, 1.0f);
AnimatorSet scaleUp_shadow = buildScaleUpAnimation(imageViewShadow, 1.0f, 1.0f);
AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 0.0f);
scaleUp_activity.addListener(animationListener);
scaleUp_activity.playTogether(scaleUp_shadow);
scaleUp_activity.playTogether(alpha_menu);
Expand All @@ -291,17 +291,17 @@ private void setScaleDirection(int direction){
float pivotY = getScreenHeight() * 0.5f;

if (direction == DIRECTION_LEFT){
sv_menu = sv_left_menu;
scrollViewMenu = scrollViewLeftMenu;
pivotX = screenWidth * 1.5f;
}else{
sv_menu = sv_right_menu;
scrollViewMenu = scrollViewRightMenu;
pivotX = screenWidth * -0.5f;
}

ViewHelper.setPivotX(view_activity, pivotX);
ViewHelper.setPivotY(view_activity, pivotY);
ViewHelper.setPivotX(iv_shadow, pivotX);
ViewHelper.setPivotY(iv_shadow, pivotY);
ViewHelper.setPivotX(viewActivity, pivotX);
ViewHelper.setPivotY(viewActivity, pivotY);
ViewHelper.setPivotX(imageViewShadow, pivotX);
ViewHelper.setPivotY(imageViewShadow, pivotY);
scaleDirection = direction;
}

Expand All @@ -325,7 +325,7 @@ public void onClick(View view) {
@Override
public void onAnimationStart(Animator animation) {
if (isOpened){
sv_menu.setVisibility(VISIBLE);
scrollViewMenu.setVisibility(VISIBLE);
if (menuListener != null)
menuListener.openMenu();
}
Expand All @@ -335,12 +335,12 @@ public void onAnimationStart(Animator animation) {
public void onAnimationEnd(Animator animation) {
// reset the view;
if(isOpened){
view_activity.setTouchDisable(true);
view_activity.setOnClickListener(viewActivityOnClickListener);
viewActivity.setTouchDisable(true);
viewActivity.setOnClickListener(viewActivityOnClickListener);
}else{
view_activity.setTouchDisable(false);
view_activity.setOnClickListener(null);
sv_menu.setVisibility(GONE);
viewActivity.setTouchDisable(false);
viewActivity.setOnClickListener(null);
scrollViewMenu.setVisibility(GONE);
if (menuListener != null)
menuListener.closeMenu();
}
Expand Down Expand Up @@ -474,15 +474,15 @@ private float getTargetScale(float currentRawX){
float scaleFloatX = ((currentRawX - lastRawX) / getScreenWidth()) * 0.75f;
scaleFloatX = scaleDirection == DIRECTION_RIGHT ? - scaleFloatX : scaleFloatX;

float targetScale = ViewHelper.getScaleX(view_activity) - scaleFloatX;
float targetScale = ViewHelper.getScaleX(viewActivity) - scaleFloatX;
targetScale = targetScale > 1.0f ? 1.0f : targetScale;
targetScale = targetScale < 0.5f ? 0.5f : targetScale;
return targetScale;
}

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

Expand All @@ -495,14 +495,14 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!canScale || isInDisableDirection(scaleDirection))
break;
if (currentActivityScaleX < 0.95)
sv_menu.setVisibility(VISIBLE);
scrollViewMenu.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.setScaleX(viewActivity, targetScale);
ViewHelper.setScaleY(viewActivity, targetScale);
ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);
break;

case MotionEvent.ACTION_UP:
Expand Down

0 comments on commit 7543ef2

Please sign in to comment.