Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InstaMaterial source files (Navigation drawer)
@Override
public void onGlobalMenuHeaderClick(final View v) {
drawerLayout.closeDrawer(Gravity.START);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int[] startingLocation = new int[2];
v.getLocationOnScreen(startingLocation);
startingLocation[0] += v.getWidth() / 2;
UserProfileActivity.startUserProfileFromLocation(startingLocation, BaseActivity.this);
overridePendingTransition(0, 0);
}
}, 200);
}
private void setupDrawer() {
GlobalMenuView menuView = new GlobalMenuView(this);
menuView.setOnHeaderClickListener(this);
drawerLayout = DrawerLayoutInstaller.from(this)
.drawerRoot(R.layout.drawer_root)
.drawerLeftView(menuView)
.drawerLeftWidth(Utils.dpToPx(300))
.withNavigationIconToggler(getToolbar())
.build();
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/vContentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/vLeftDrawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
private void addDrawerToActivity(DrawerLayout drawerLayout) {
ViewGroup rootView = (ViewGroup) activity.findViewById(android.R.id.content);
ViewGroup drawerContentRoot = (ViewGroup) drawerLayout.getChildAt(0);
View contentView = rootView.getChildAt(0);
rootView.removeView(contentView);
drawerContentRoot.addView(contentView, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
));
rootView.addView(drawerLayout, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
));
}
public class GlobalMenuView extends ListView implements View.OnClickListener {
private OnHeaderClickListener onHeaderClickListener;
private GlobalMenuAdapter globalMenuAdapter;
private ImageView ivUserProfilePhoto;
private int avatarSize;
private String profilePhoto;
public GlobalMenuView(Context context) {
super(context);
init();
}
private void init() {
setChoiceMode(CHOICE_MODE_SINGLE);
setDivider(getResources().getDrawable(android.R.color.transparent));
setDividerHeight(0);
setBackgroundColor(Color.WHITE);
setupHeader();
setupAdapter();
}
private void setupAdapter() {
globalMenuAdapter = new GlobalMenuAdapter(getContext());
setAdapter(globalMenuAdapter);
}
private void setupHeader() {
this.avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
this.profilePhoto = getResources().getString(R.string.user_profile_photo);
setHeaderDividersEnabled(true);
View vHeader = LayoutInflater.from(getContext()).inflate(R.layout.view_global_menu_header, null);
ivUserProfilePhoto = (ImageView) vHeader.findViewById(R.id.ivUserProfilePhoto);
Picasso.with(getContext())
.load(profilePhoto)
.placeholder(R.drawable.img_circle_placeholder)
.resize(avatarSize, avatarSize)
.centerCrop()
.transform(new CircleTransformation())
.into(ivUserProfilePhoto);
addHeaderView(vHeader);
vHeader.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (onHeaderClickListener != null) {
onHeaderClickListener.onGlobalMenuHeaderClick(v);
}
}
public interface OnHeaderClickListener {
public void onGlobalMenuHeaderClick(View v);
}
public void setOnHeaderClickListener(OnHeaderClickListener onHeaderClickListener) {
this.onHeaderClickListener = onHeaderClickListener;
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#dddddd" />
</FrameLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.