|
11 | 11 | import android.view.Menu;
|
12 | 12 | import android.view.MenuItem;
|
13 | 13 | import android.view.View;
|
14 |
| -import android.view.ViewGroup; |
15 | 14 | import android.view.WindowManager;
|
16 | 15 | import android.view.animation.AlphaAnimation;
|
17 |
| -import android.widget.LinearLayout; |
18 | 16 |
|
19 | 17 | import com.maowubian.baseproject.R;
|
| 18 | +import com.maowubian.baseproject.component.game.ui.GameFragment; |
20 | 19 | import com.maowubian.baseproject.component.home.adapter.HomeVpAdapter;
|
| 20 | +import com.maowubian.baseproject.component.home.events.HomeEvents; |
| 21 | +import com.maowubian.baseproject.component.movie.ui.MovieFragment; |
| 22 | +import com.maowubian.baseproject.component.music.ui.MusicFragment; |
21 | 23 | import com.maowubian.baseproject.databinding.HomeDatabinding;
|
22 | 24 |
|
23 |
| -import java.lang.reflect.Field; |
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.List;
|
26 | 27 |
|
|
30 | 31 | public class HomePageActivity extends AppCompatActivity {
|
31 | 32 |
|
32 | 33 | private HomeDatabinding databinding;
|
| 34 | + |
33 | 35 | private List<Fragment> fragments = new ArrayList<>();
|
| 36 | + |
34 | 37 | private Context mContext;
|
35 | 38 |
|
36 | 39 | @Override
|
37 | 40 | protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
38 | 41 | super.onCreate(savedInstanceState);
|
39 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
40 |
| - //透明状态栏 |
41 |
| - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
42 |
| - //透明导航栏 |
43 |
| - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
44 |
| - } |
45 |
| - |
| 42 | + fullScreenWithTitleBar(); |
46 | 43 | mContext = this;
|
47 |
| - |
48 | 44 | databinding = DataBindingUtil.setContentView(this, R.layout.activity_home_page);
|
49 |
| - databinding.space.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,getStatusbarHeight())); |
50 |
| - |
| 45 | + HomeEvents.onNavigationCLick(databinding.nv); |
| 46 | + init(); |
51 | 47 |
|
52 |
| - AppFragment appFragment1 = new AppFragment(); |
53 |
| - AppFragment appFragment2 = new AppFragment(); |
54 |
| - AppFragment appFragment3 = new AppFragment(); |
| 48 | + } |
55 | 49 |
|
56 |
| - fragments.add(appFragment1); |
57 |
| - fragments.add(appFragment2); |
58 |
| - fragments.add(appFragment3); |
59 |
| - databinding.vp.setAdapter(new HomeVpAdapter(getSupportFragmentManager(), fragments)); |
| 50 | + private void init() { |
60 | 51 |
|
61 |
| - Menu menu = databinding.nv.getMenu(); |
62 | 52 |
|
63 |
| - menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { |
64 |
| - @Override |
65 |
| - public boolean onMenuItemClick(MenuItem item) { |
| 53 | + MusicFragment musicFragment = new MusicFragment(); |
| 54 | + MovieFragment movieFragment = new MovieFragment(); |
| 55 | + GameFragment gameFragment = new GameFragment(); |
66 | 56 |
|
67 |
| - Snackbar bar = Snackbar.make(databinding.nv, "哈哈哈", Snackbar.LENGTH_SHORT); |
68 |
| - bar.show(); |
69 |
| - View view = bar.getView(); |
70 |
| - view.setBackgroundColor(0x55f44336); |
71 |
| - view.setAnimation(new AlphaAnimation(0, 1)); |
| 57 | + fragments.add(musicFragment); |
| 58 | + fragments.add(movieFragment); |
| 59 | + fragments.add(gameFragment); |
72 | 60 |
|
73 |
| - return true; |
74 |
| - } |
75 |
| - }); |
| 61 | + databinding.vp.setAdapter(new HomeVpAdapter(getSupportFragmentManager(), fragments)); |
76 | 62 |
|
77 | 63 |
|
78 | 64 | }
|
79 | 65 |
|
80 |
| - private int getStatusbarHeight() { |
81 |
| - try { |
82 |
| - Class<?> c = Class.forName("com.android.internal.R$dimen"); |
83 |
| - Object o = c.newInstance(); |
84 |
| - Field field = c.getField("status_bar_height"); |
85 |
| - int i = Integer.parseInt(field.get(o).toString()); |
86 |
| - return getResources().getDimensionPixelOffset(i); |
87 |
| - |
88 |
| - } catch (Exception e) { |
89 |
| - e.printStackTrace(); |
| 66 | + private void fullScreenWithTitleBar() { |
| 67 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| 68 | + //透明状态栏 |
| 69 | + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| 70 | + //透明导航栏 |
| 71 | + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
90 | 72 | }
|
91 |
| - return 0; |
92 | 73 | }
|
| 74 | + |
| 75 | + |
93 | 76 | }
|
0 commit comments