-
Notifications
You must be signed in to change notification settings - Fork 119
/
MainActivity.java
72 lines (56 loc) · 2.35 KB
/
MainActivity.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
package com.goka.sample;
import com.goka.blurredgridmenu.GridMenu;
import com.goka.blurredgridmenu.GridMenuFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private GridMenuFragment mGridMenuFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGridMenuFragment = GridMenuFragment.newInstance(R.drawable.back);
findViewById(R.id.show_menu_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main_frame, mGridMenuFragment);
tx.addToBackStack(null);
tx.commit();
}
});
setupGridMenu();
mGridMenuFragment.setOnClickMenuListener(new GridMenuFragment.OnClickMenuListener() {
@Override
public void onClickMenu(GridMenu gridMenu, int position) {
Toast.makeText(MainActivity.this, "Title:" + gridMenu.getTitle() + ", Position:" + position,
Toast.LENGTH_SHORT).show();
}
});
}
private void setupGridMenu() {
List<GridMenu> menus = new ArrayList<>();
menus.add(new GridMenu("Home", R.drawable.home));
menus.add(new GridMenu("Calendar", R.drawable.calendar));
menus.add(new GridMenu("Overview", R.drawable.overview));
menus.add(new GridMenu("Groups", R.drawable.groups));
menus.add(new GridMenu("Lists", R.drawable.lists));
menus.add(new GridMenu("Profile", R.drawable.profile));
menus.add(new GridMenu("Timeline", R.drawable.timeline));
menus.add(new GridMenu("Setting", R.drawable.settings));
mGridMenuFragment.setupMenu(menus);
}
@Override
public void onBackPressed() {
if (0 == getSupportFragmentManager().getBackStackEntryCount()) {
super.onBackPressed();
} else {
getSupportFragmentManager().popBackStack();
}
}
}