Skip to content

Commit 9a0fa98

Browse files
committed
Sample App base ui with material drawer
1 parent 1bca92e commit 9a0fa98

21 files changed

Lines changed: 266 additions & 26 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ext.minSdkVersion = 15
66
ext.compileSdkVersion = 25
77
ext.targetSdkVersion = 25
88
// Lib Versions
9+
ext.butterKnifeVersion = "8.5.1"
910
ext.appCompatLibVersion = "25.2.0"
1011
ext.retrofit2Version = "2.2.0"
1112
ext.retrofitGsonVersion = "2.2.0"

sample/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ dependencies {
2727
compile project(':net')
2828

2929
compile "com.android.support:appcompat-v7:$rootProject.appCompatLibVersion"
30+
compile "com.android.support:design:$rootProject.appCompatLibVersion"
31+
compile "com.jakewharton:butterknife:$rootProject.butterKnifeVersion"
32+
compile('com.mikepenz:materialdrawer:5.8.2@aar') {
33+
transitive = true
34+
}
35+
3036

3137
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
3238
exclude group: 'com.android.support', module: 'support-annotations'
3339
})
3440

35-
testCompile 'junit:junit:4.12'
3641

42+
compile 'com.mikepenz:crossfader:1.5.0@aar'
43+
compile 'com.android.support:support-v4:25.2.0'
44+
testCompile 'junit:junit:4.12'
3745
}
Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,95 @@
11
package com.michaelfotiadis.steam.dota2.loader.sample;
22

3-
import android.support.v7.app.AppCompatActivity;
43
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;
516

617
public class MainActivity extends AppCompatActivity {
718

19+
Toolbar mToolbar;
20+
21+
private Drawer mDrawer = null;
22+
private MiniDrawer mMiniDrawer = null;
23+
private Crossfader mCrossFader;
24+
825
@Override
9-
protected void onCreate(Bundle savedInstanceState) {
26+
protected void onCreate(final Bundle savedInstanceState) {
1027
super.onCreate(savedInstanceState);
1128
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+
1240
}
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+
1395
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.michaelfotiadis.steam.dota2.loader.sample.fragment.steam;
2+
3+
4+
import android.os.Bundle;
5+
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.michaelfotiadis.steam.dota2.loader.sample.R;
11+
12+
/**
13+
* A simple {@link Fragment} subclass.
14+
*/
15+
public class SteamFragment extends Fragment {
16+
17+
18+
public SteamFragment() {
19+
// Required empty public constructor
20+
}
21+
22+
23+
@Override
24+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
25+
Bundle savedInstanceState) {
26+
// Inflate the layout for this fragment
27+
return inflater.inflate(R.layout.fragment_steam, container, false);
28+
}
29+
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.michaelfotiadis.steam.dota2.loader.sample.utils;
2+
3+
import com.mikepenz.crossfader.Crossfader;
4+
import com.mikepenz.materialdrawer.interfaces.ICrossfader;
5+
6+
/**
7+
* Created by mikepenz on 18.07.15.
8+
*/
9+
public class CrossfadeWrapper implements ICrossfader {
10+
private Crossfader mCrossfader;
11+
12+
public CrossfadeWrapper(Crossfader crossfader) {
13+
this.mCrossfader = crossfader;
14+
}
15+
16+
@Override
17+
public void crossfade() {
18+
mCrossfader.crossFade();
19+
}
20+
21+
@Override
22+
public boolean isCrossfaded() {
23+
return mCrossfader.isCrossFaded();
24+
}
25+
}
61.6 KB
Loading
12.6 KB
Loading
30.9 KB
Loading
7.12 KB
Loading
101 KB
Loading

0 commit comments

Comments
 (0)