|
1 | 1 | package com.michaelfotiadis.steam.dota2.loader.sample; |
2 | 2 |
|
3 | | -import android.support.v7.app.AppCompatActivity; |
4 | 3 | import android.os.Bundle; |
| 4 | +import android.support.v7.app.AppCompatActivity; |
| 5 | +import android.support.v7.widget.Toolbar; |
| 6 | + |
| 7 | +import com.michaelfotiadis.steam.dota2.loader.sample.utils.CrossfadeWrapper; |
| 8 | +import com.mikepenz.crossfader.Crossfader; |
| 9 | +import com.mikepenz.crossfader.util.UIUtils; |
| 10 | +import com.mikepenz.materialdrawer.Drawer; |
| 11 | +import com.mikepenz.materialdrawer.DrawerBuilder; |
| 12 | +import com.mikepenz.materialdrawer.MiniDrawer; |
| 13 | +import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; |
| 14 | + |
| 15 | +import butterknife.ButterKnife; |
5 | 16 |
|
6 | 17 | public class MainActivity extends AppCompatActivity { |
7 | 18 |
|
| 19 | + Toolbar mToolbar; |
| 20 | + |
| 21 | + private Drawer mDrawer = null; |
| 22 | + private MiniDrawer mMiniDrawer = null; |
| 23 | + private Crossfader mCrossFader; |
| 24 | + |
8 | 25 | @Override |
9 | | - protected void onCreate(Bundle savedInstanceState) { |
| 26 | + protected void onCreate(final Bundle savedInstanceState) { |
10 | 27 | super.onCreate(savedInstanceState); |
11 | 28 | setContentView(R.layout.activity_main); |
| 29 | + |
| 30 | + mToolbar = (Toolbar) findViewById(R.id.toolbar); |
| 31 | + |
| 32 | + setSupportActionBar(mToolbar); |
| 33 | + |
| 34 | + setTitle("Steam Loader Sample"); |
| 35 | + |
| 36 | + ButterKnife.bind(this); |
| 37 | + |
| 38 | + buildMiniDrawer(savedInstanceState); |
| 39 | + |
12 | 40 | } |
| 41 | + |
| 42 | + private void buildMiniDrawer(final Bundle savedInstanceState) { |
| 43 | + final PrimaryDrawerItem item1 = new PrimaryDrawerItem().withIdentifier(1).withName("Steam") |
| 44 | + .withIcon(R.drawable.ic_steam).withIconTintingEnabled(true); |
| 45 | + final PrimaryDrawerItem item2 = new PrimaryDrawerItem().withIdentifier(1).withName("Dota 2") |
| 46 | + .withIcon(R.drawable.ic_dota_2).withIconTintingEnabled(true); |
| 47 | + |
| 48 | + mDrawer = new DrawerBuilder() |
| 49 | + .withActivity(this) |
| 50 | + .withTranslucentStatusBar(false) |
| 51 | + .withToolbar(mToolbar) |
| 52 | + .withCloseOnClick(true) |
| 53 | + .withGenerateMiniDrawer(true) |
| 54 | + .withSavedInstance(savedInstanceState) |
| 55 | + .withActionBarDrawerToggle(true) |
| 56 | + .addDrawerItems(item1, item2) |
| 57 | + .buildView(); |
| 58 | + |
| 59 | + //the MiniDrawer is managed by the Drawer and we just get it to hook it into the Crossfader |
| 60 | + mMiniDrawer = mDrawer.getMiniDrawer(); |
| 61 | + |
| 62 | + //get the widths in px for the first and second panel |
| 63 | + int firstWidth = (int) UIUtils.convertDpToPixel(300, this); |
| 64 | + int secondWidth = (int) UIUtils.convertDpToPixel(72, this); |
| 65 | + |
| 66 | + //create and build our crossfader (see the MiniDrawer is also builded in here, as the build method returns the view to be used in the crossfader) |
| 67 | + //the crossfader library can be found here: https://github.com/mikepenz/Crossfader |
| 68 | + mCrossFader = new Crossfader() |
| 69 | + .withContent(findViewById(R.id.content_frame)) |
| 70 | + .withFirst(mDrawer.getSlider(), firstWidth) |
| 71 | + .withSecond(mMiniDrawer.build(this), secondWidth) |
| 72 | + .withSavedInstance(savedInstanceState) |
| 73 | + .build(); |
| 74 | + |
| 75 | + //define the crossfader to be used with the miniDrawer. This is required to be able to automatically toggle open / close |
| 76 | + mMiniDrawer.withCrossFader(new CrossfadeWrapper(mCrossFader)); |
| 77 | + |
| 78 | + //define a shadow (this is only for normal LTR layouts if you have a RTL app you need to define the other one |
| 79 | + mCrossFader.getCrossFadeSlidingPaneLayout().setShadowResourceLeft(R.drawable.material_drawer_shadow_left); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + protected void onSaveInstanceState(Bundle outState) { |
| 84 | + //add the values which need to be saved from the drawer to the bundle |
| 85 | + if (mDrawer != null) { |
| 86 | + outState = mDrawer.saveInstanceState(outState); |
| 87 | + } |
| 88 | + //add the values which need to be saved from the crossFader to the bundle |
| 89 | + if (mCrossFader != null) { |
| 90 | + outState = mCrossFader.saveInstanceState(outState); |
| 91 | + } |
| 92 | + super.onSaveInstanceState(outState); |
| 93 | + } |
| 94 | + |
13 | 95 | } |
0 commit comments