Skip to content

Commit

Permalink
Added demo for icon animation when sliding navigation drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
balysv committed Oct 12, 2014
1 parent f8326a2 commit b78f397
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 139 deletions.
2 changes: 2 additions & 0 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ dependencies {
compile project(':library')
absCompile project(':extras-abs')
abcCompile project(':extras-abc')

compile 'com.android.support:support-v4:20.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo);
helper = new BaseActivityHelper();
helper.init(getWindow().getDecorView());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CustomViewActivity extends BaseActivity implements View.OnClickList
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initCustomActionBar();
helper.init(getWindow().getDecorView(), materialMenu);
}

private void initCustomActionBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class HomeIconActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
materialMenu = new MaterialMenuIconCompat(this, Color.WHITE, Stroke.THIN);
helper.init(getWindow().getDecorView(), materialMenu);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo);
helper = new BaseActivityHelper();
helper.init(getWindow().getDecorView());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class CustomViewActivity extends BaseActivity implements View.OnClickList
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initCustomActionBar();
helper.init(getWindow().getDecorView(), materialMenu);
}

private void initCustomActionBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class HomeIconActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
materialMenu = new MaterialMenuIconSherlock(this, Color.WHITE, Stroke.THIN);
helper.init(getWindow().getDecorView(), materialMenu);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package com.balysv.materialmenu.demo;

import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
import android.widget.SeekBar;

import com.balysv.materialmenu.MaterialMenu;
import com.balysv.materialmenu.MaterialMenuView;

import java.util.Random;

import static com.balysv.materialmenu.MaterialMenuDrawable.AnimationState;
import static com.balysv.materialmenu.MaterialMenuDrawable.IconState;

public class BaseActivityHelper implements View.OnClickListener, SeekBar.OnSeekBarChangeListener {

private MaterialMenuView materialMenuView;
private int materialButtonState;
private MaterialMenu materialIcon;
private DrawerLayout drawerLayout;

public void init(View parent) {
public void init(View parent, MaterialMenu actionBarIcon) {
SeekBar duration = (SeekBar) parent.findViewById(R.id.item_animation_duration);
duration.setMax(4600);
duration.setProgress(2600);
duration.setOnSeekBarChangeListener(this);

materialMenuView = (MaterialMenuView) parent.findViewById(R.id.material_menu_button);
materialMenuView.setOnClickListener(this);
materialIcon = actionBarIcon;

parent.findViewById(R.id.switch_item_arrow).setOnClickListener(this);
parent.findViewById(R.id.switch_item_menu).setOnClickListener(this);
Expand All @@ -31,6 +38,35 @@ public void init(View parent) {
parent.findViewById(R.id.animate_item_menu).setOnClickListener(this);
parent.findViewById(R.id.animate_item_x).setOnClickListener(this);
parent.findViewById(R.id.animate_item_check).setOnClickListener(this);

drawerLayout = ((DrawerLayout) parent.findViewById(R.id.drawer_layout));
drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
private boolean direction = false;

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
materialIcon.setTransformationOffset(
AnimationState.BURGER_ARROW,
direction ? 2 - slideOffset : slideOffset
);
}

@Override
public void onDrawerOpened(android.view.View drawerView) {
direction = true;
}

@Override
public void onDrawerClosed(android.view.View drawerView) {
direction = false;
}
});

drawerLayout.postDelayed(new Runnable() {
@Override public void run() {
drawerLayout.openDrawer(Gravity.LEFT);
}
}, 1500);
}

@Override public void onClick(View v) {
Expand Down
Loading

0 comments on commit b78f397

Please sign in to comment.