Skip to content

Commit 25f75b5

Browse files
committed
Adding sliding menu from net.simonvt.menudrawer
1 parent c2a0074 commit 25f75b5

24 files changed

+221
-14
lines changed

app/assets/fonts/Roboto-Regular.ttf

155 KB
Binary file not shown.

app/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<dagger.version>1.0.1</dagger.version>
2121
<otto.version>1.3.4</otto.version>
2222
<gson.version>2.2.4</gson.version>
23+
<menudrawer.version>3.0.2</menudrawer.version>
2324
</properties>
2425

2526
<dependencies>
@@ -56,7 +57,12 @@
5657
<version>${abs.version}</version>
5758
<type>apklib</type>
5859
</dependency>
59-
60+
<dependency>
61+
<groupId>net.simonvt.menudrawer</groupId>
62+
<artifactId>menudrawer</artifactId>
63+
<version>${menudrawer.version}</version>
64+
<type>apklib</type>
65+
</dependency>
6066
<dependency>
6167
<groupId>com.github.kevinsawicki</groupId>
6268
<artifactId>http-request</artifactId>

app/res/color/nav_text_selector.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:state_enabled="false" android:color="@color/nav_button_text_disabled" />
5+
<item android:color="@color/nav_button_text_light" />
6+
</selector>

app/res/drawable-hdpi/ic_drawer.png

963 Bytes
Loading

app/res/drawable-hdpi/ic_home.png

646 Bytes
Loading

app/res/drawable-hdpi/ic_timer.png

1.02 KB
Loading

app/res/drawable-mdpi/ic_drawer.png

955 Bytes
Loading

app/res/drawable-mdpi/ic_home.png

464 Bytes
Loading

app/res/drawable-mdpi/ic_timer.png

642 Bytes
Loading

app/res/drawable-xhdpi/ic_drawer.png

979 Bytes
Loading

app/res/drawable-xhdpi/ic_home.png

919 Bytes
Loading

app/res/drawable-xhdpi/ic_timer.png

1.53 KB
Loading

app/res/drawable-xxhdpi/ic_home.png

1.64 KB
Loading

app/res/drawable-xxhdpi/ic_timer.png

2.61 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
4+
5+
<solid android:color="@color/nav_button_disabled" />
6+
7+
</shape>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
4+
5+
<solid
6+
android:color="@android:color/transparent" />
7+
8+
</shape>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
4+
5+
<solid
6+
android:color="@color/nav_button_pressed" />
7+
8+
</shape>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<item android:drawable="@drawable/nav_menu_button_background_pressed" android:state_pressed="true" />
6+
<item android:drawable="@drawable/nav_menu_button_background_disabled" android:state_enabled="false"/>
7+
<item android:drawable="@drawable/nav_menu_button_background_enabled" />
8+
9+
</selector>

app/res/layout/navigation_drawer.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@color/nav_background"
8+
android:gravity="center_horizontal">
9+
10+
<com.donnfelker.android.bootstrap.ui.view.CapitalizedTextView
11+
android:layout_width="fill_parent"
12+
android:layout_height="wrap_content"
13+
android:id="@+id/home"
14+
android:text="@string/home"
15+
android:drawableLeft="@drawable/ic_home"
16+
style="@style/NavMenuButton"
17+
android:paddingLeft="10dp"
18+
android:gravity="left|center_vertical"
19+
/>
20+
21+
<View
22+
android:layout_width="fill_parent"
23+
android:layout_height="1dp"
24+
android:background="@color/vert_sep_color"
25+
/>
26+
27+
<com.donnfelker.android.bootstrap.ui.view.CapitalizedTextView
28+
android:layout_width="fill_parent"
29+
android:layout_height="wrap_content"
30+
android:id="@+id/timer"
31+
android:text="@string/timer"
32+
android:drawableLeft="@drawable/ic_timer"
33+
style="@style/NavMenuButton"
34+
android:paddingLeft="10dp"
35+
android:gravity="left|center_vertical"
36+
/>
37+
38+
<View
39+
android:layout_width="fill_parent"
40+
android:layout_height="1dp"
41+
android:background="@color/vert_sep_color"
42+
/>
43+
44+
45+
<TextView
46+
android:id="@+id/version"
47+
android:layout_width="match_parent"
48+
android:layout_height="match_parent"
49+
style="@style/NavMenuButton"
50+
android:gravity="bottom"
51+
android:layout_marginLeft="5dp"
52+
android:layout_marginBottom="5dp"
53+
android:textSize="9sp"
54+
/>
55+
56+
57+
</LinearLayout>

app/res/values/colors.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
<color name="button_background_disabled_start">#7b7b7b</color>
3535
<color name="button_background_disabled_end">#646464</color>
3636
<color name="text_shadow">#000000</color>
37-
37+
<color name="vert_sep_color">#222222</color>
3838
<color name="background_selected">#1fb6ed</color>
39+
<color name="nav_button_text_light">#A6A6A6</color>
40+
<color name="nav_button_pressed">#5A5A5A</color>
41+
<color name="nav_button_disabled">#252525</color>
42+
<color name="nav_button_text_disabled">#464646</color>
43+
<color name="nav_background">#2f2f2f</color>
3944

4045
</resources>

app/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<string name="pause">Pause</string>
4040
<string name="resume">Resume</string>
4141
<string name="timer">Timer</string>
42+
<string name="home">Home</string>
4243

4344

4445
</resources>

app/res/values/styles.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@
8989
<item name="android:textColor">#464646</item>
9090
</style>
9191

92+
<style name="NavMenuButton">
93+
<item name="android:textColor">@color/nav_text_selector</item>
94+
<item name="android:background">@drawable/nav_menu_button_background_selector</item>
95+
</style>
96+
9297
</resources>

app/src/main/java/com/donnfelker/android/bootstrap/ui/CarouselActivity.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,90 @@
22

33
package com.donnfelker.android.bootstrap.ui;
44

5-
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
6-
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
75
import android.content.Intent;
86
import android.os.Bundle;
97
import android.support.v4.view.ViewPager;
8+
import android.view.View;
109

11-
import com.actionbarsherlock.view.Menu;
1210
import com.actionbarsherlock.view.MenuItem;
1311
import com.actionbarsherlock.view.Window;
14-
import com.donnfelker.android.bootstrap.BootstrapApplication;
1512
import com.donnfelker.android.bootstrap.R;
16-
import com.donnfelker.android.bootstrap.R.id;
17-
1813
import com.viewpagerindicator.TitlePageIndicator;
1914

2015
import butterknife.InjectView;
2116
import butterknife.Views;
17+
import net.simonvt.menudrawer.MenuDrawer;
18+
2219

2320
/**
2421
* Activity to view the carousel and view pager indicator with fragments.
2522
*/
2623
public class CarouselActivity extends BootstrapFragmentActivity {
2724

28-
@InjectView(id.tpi_header) TitlePageIndicator indicator;
29-
@InjectView(id.vp_pages) ViewPager pager;
25+
@InjectView(R.id.tpi_header) TitlePageIndicator indicator;
26+
@InjectView(R.id.vp_pages) ViewPager pager;
27+
28+
private MenuDrawer menuDrawer;
3029

3130
@Override
3231
protected void onCreate(Bundle savedInstanceState) {
3332

3433
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
3534

3635
super.onCreate(savedInstanceState);
37-
setContentView(R.layout.carousel_view);
36+
37+
// Set up navigation drawer
38+
menuDrawer = MenuDrawer.attach(this);
39+
menuDrawer.setMenuView(R.layout.navigation_drawer);
40+
menuDrawer.setContentView(R.layout.carousel_view);
41+
menuDrawer.setSlideDrawable(R.drawable.ic_drawer);
42+
menuDrawer.setDrawerIndicatorEnabled(true);
43+
44+
Views.inject(this);
3845

3946
pager.setAdapter(new BootstrapPagerAdapter(getResources(), getSupportFragmentManager()));
4047

4148
indicator.setViewPager(pager);
4249
pager.setCurrentItem(1);
50+
51+
setNavListeners();
52+
}
53+
54+
private void setNavListeners() {
55+
56+
menuDrawer.findViewById(R.id.home).setOnClickListener(new View.OnClickListener() {
57+
@Override
58+
public void onClick(View v) {
59+
menuDrawer.toggleMenu();
60+
}
61+
});
62+
63+
menuDrawer.findViewById(R.id.timer).setOnClickListener(new View.OnClickListener() {
64+
@Override
65+
public void onClick(View v) {
66+
menuDrawer.toggleMenu();
67+
navigateToTimer();
68+
}
69+
});
70+
4371
}
4472

4573
@Override
4674
public boolean onOptionsItemSelected(MenuItem item) {
4775
switch(item.getItemId()) {
48-
case id.timer:
49-
final Intent i = new Intent(this, BootstrapTimerActivity.class);
50-
startActivity(i);
76+
case android.R.id.home:
77+
menuDrawer.toggleMenu();
78+
return true;
79+
case R.id.timer:
80+
navigateToTimer();
5181
return true;
5282
default:
5383
return super.onOptionsItemSelected(item);
5484
}
5585
}
86+
87+
private void navigateToTimer() {
88+
final Intent i = new Intent(this, BootstrapTimerActivity.class);
89+
startActivity(i);
90+
}
5691
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.donnfelker.android.bootstrap.ui.view;
2+
3+
import android.content.Context;
4+
import android.graphics.Typeface;
5+
import android.os.Build;
6+
import android.util.AttributeSet;
7+
import android.widget.Button;
8+
9+
import com.donnfelker.android.bootstrap.util.Strings;
10+
11+
import java.util.Locale;
12+
13+
/**
14+
* A button who's text is always uppercase which uses the roboto font.
15+
* Inspired by {@link com.actionbarsherlock.internal.widget.CapitalizingTextView}
16+
*/
17+
public class CapitalizedTextView extends Button {
18+
19+
private static final boolean SANS_ICE_CREAM = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
20+
private static final boolean IS_GINGERBREAD = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
21+
22+
public CapitalizedTextView(Context context) {
23+
super( context );
24+
25+
setTF( context );
26+
}
27+
28+
public CapitalizedTextView(Context context, AttributeSet attrs) {
29+
super( context, attrs );
30+
31+
setTF(context);
32+
}
33+
34+
public CapitalizedTextView(Context context, AttributeSet attrs, int defStyle) {
35+
super( context, attrs, defStyle );
36+
37+
setTF(context);
38+
39+
}
40+
41+
@Override
42+
public void setText(CharSequence text, BufferType type) {
43+
if (IS_GINGERBREAD) {
44+
try {
45+
super.setText(text.toString().toUpperCase(Locale.ROOT), type);
46+
} catch (NoSuchFieldError e) {
47+
//Some manufacturer broke Locale.ROOT. See #572.
48+
super.setText(text.toString().toUpperCase(), type);
49+
}
50+
} else {
51+
super.setText(text.toString().toUpperCase(), type);
52+
}
53+
}
54+
55+
private void setTF(Context context) {
56+
setTypeface( Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf") );
57+
}
58+
59+
60+
}

0 commit comments

Comments
 (0)