/
BaseDrawerActivity.java
81 lines (69 loc) · 2.59 KB
/
BaseDrawerActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package io.github.froger.instamaterial.ui.activity;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import butterknife.InjectView;
import butterknife.OnClick;
import io.github.froger.instamaterial.R;
import io.github.froger.instamaterial.ui.utils.CircleTransformation;
/**
* Created by Miroslaw Stanek on 15.07.15.
*/
public class BaseDrawerActivity extends BaseActivity {
@InjectView(R.id.drawerLayout)
DrawerLayout drawerLayout;
@InjectView(R.id.ivUserProfilePhoto)
ImageView ivUserProfilePhoto;
private int avatarSize;
private String profilePhoto;
@Override
public void setContentView(int layoutResID) {
super.setContentViewWithoutInject(R.layout.activity_drawer);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.flContentRoot);
LayoutInflater.from(this).inflate(layoutResID, viewGroup, true);
injectViews();
setupHeader();
}
@Override
protected void setupToolbar() {
super.setupToolbar();
if (getToolbar() != null) {
getToolbar().setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(Gravity.LEFT);
}
});
}
}
@OnClick(R.id.vGlobalMenuHeader)
public void onGlobalMenuHeaderClick(final View v) {
drawerLayout.closeDrawer(Gravity.LEFT);
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, BaseDrawerActivity.this);
overridePendingTransition(0, 0);
}
}, 200);
}
private void setupHeader() {
this.avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
this.profilePhoto = getResources().getString(R.string.user_profile_photo);
Picasso.with(this)
.load(profilePhoto)
.placeholder(R.drawable.img_circle_placeholder)
.resize(avatarSize, avatarSize)
.centerCrop()
.transform(new CircleTransformation())
.into(ivUserProfilePhoto);
}
}