Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class FadingActionBarHelperBase {
private boolean mFirstGlobalLayoutPerformed;
private FrameLayout mMarginView;
private View mListViewBackgroundView;
private int mActionBarAlpha = 255;

public final <T extends FadingActionBarHelperBase> T actionBarBackground(int drawableResId) {
mActionBarBackgroundResId = drawableResId;
Expand Down Expand Up @@ -173,7 +174,16 @@ public void initActionBar(Activity activity) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
mActionBarBackgroundDrawable.setCallback(mDrawableCallback);
}
mActionBarBackgroundDrawable.setAlpha(0);
setActionBarAlpha(0);
}

public int getActionbarAlpha(){
return mActionBarAlpha;
}

public void setActionBarAlpha(int alpha){
mActionBarBackgroundDrawable.setAlpha(alpha);
mActionBarAlpha = alpha;
}

protected abstract int getActionBarHeight();
Expand Down Expand Up @@ -310,7 +320,7 @@ private void onNewScroll(int scrollPosition) {
int headerHeight = currentHeaderHeight - getActionBarHeight();
float ratio = (float) Math.min(Math.max(scrollPosition, 0), headerHeight) / headerHeight;
int newAlpha = (int) (ratio * 255);
mActionBarBackgroundDrawable.setAlpha(newAlpha);
setActionBarAlpha(newAlpha);

addParallaxEffect(scrollPosition);
}
Expand Down
19 changes: 13 additions & 6 deletions samples/stock/res/layout/activity_navigation_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
<LinearLayout
android:id="@+id/left_drawer"
android:paddingTop="?android:attr/actionBarSize"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
android:layout_gravity="start">

<ListView
android:id="@+id/left_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>

</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

public class NavigationDrawerActivity extends Activity implements AdapterView.OnItemClickListener {

private DrawerLayout mDrawerLayout;
private LinearLayout mDrawer;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private ActionBarHolder mActionbarHolder;

private boolean mDrawerIsOpen = false;
private int mDrawerState = DrawerLayout.STATE_IDLE;
private int mOldAlpha = 0;

private CharSequence mDrawerTitle;
private CharSequence mTitle;
Expand All @@ -56,7 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
typedArray.recycle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawer = (LinearLayout) findViewById(R.id.left_drawer);
mDrawerList = (ListView) findViewById(R.id.left_drawer_list);

// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
Expand All @@ -80,10 +88,31 @@ protected void onCreate(Bundle savedInstanceState) {
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
mDrawerIsOpen = false;
}

public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
mDrawerIsOpen = true;
}

public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);

if (!mDrawerIsOpen && mDrawerState == DrawerLayout.STATE_IDLE && mActionbarHolder != null) {
mOldAlpha = mActionbarHolder.getAlpha();
}

mDrawerState = newState;
}

public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);

if (mActionbarHolder != null) {
int newAlpha = Math.round(mOldAlpha + ((255 - mOldAlpha) * slideOffset));
mActionbarHolder.overrideAlpha(newAlpha);
}
}
};

Expand Down Expand Up @@ -131,15 +160,26 @@ private void selectItem(int position) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

mActionbarHolder = (ActionBarHolder) fragment;
mOldAlpha = 0;

// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mCityNames[position]);
mDrawerLayout.closeDrawer(mDrawerList);
mDrawerLayout.closeDrawer(mDrawer);
}

@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}

public interface ActionBarHolder {

public void overrideAlpha(int alpha);

public int getAlpha();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import com.manuelpeinado.fadingactionbar.FadingActionBarHelper;

public class SampleFragment extends Fragment {
public class SampleFragment extends Fragment implements NavigationDrawerActivity.ActionBarHolder {
private FadingActionBarHelper mFadingHelper;
private Bundle mArguments;

Expand Down Expand Up @@ -59,4 +59,20 @@ public void onAttach(Activity activity) {
.lightActionBar(actionBarBg == R.drawable.ab_background_light);
mFadingHelper.initActionBar(activity);
}

@Override
public void overrideAlpha(int alpha) {
if (mFadingHelper != null){
mFadingHelper.setActionBarAlpha(alpha);
}
}

@Override
public int getAlpha(){
if (mFadingHelper != null){
return mFadingHelper.getActionbarAlpha();
} else {
return 0;
}
}
}