Skip to content

Commit

Permalink
Modified sample
Browse files Browse the repository at this point in the history
Removed unnecessary casts.
Added code to close the menu when one of its elements is chosen. re #17
Added blocking content clicks when menu is opened.
  • Loading branch information
yarolegovich committed Sep 3, 2017
1 parent 93dc87b commit 4ca0182
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Expand Up @@ -13,6 +13,7 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import com.yarolegovich.slidingrootnav.SlidingRootNav;
import com.yarolegovich.slidingrootnav.SlidingRootNavBuilder;
import com.yarolegovich.slidingrootnav.sample.menu.DrawerAdapter;
import com.yarolegovich.slidingrootnav.sample.menu.DrawerItem;
Expand All @@ -37,17 +38,20 @@ public class SampleActivity extends AppCompatActivity implements DrawerAdapter.O
private String[] screenTitles;
private Drawable[] screenIcons;

private SlidingRootNav slidingRootNav;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

new SlidingRootNavBuilder(this)
slidingRootNav = new SlidingRootNavBuilder(this)
.withToolbarMenuToggle(toolbar)
.withMenuOpened(true)
.withMenuOpened(false)
.withContentClickableWhenMenuOpened(false)
.withSavedState(savedInstanceState)
.withMenuLayout(R.layout.menu_left_drawer)
.inject();
Expand All @@ -64,7 +68,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
createItemFor(POS_LOGOUT)));
adapter.setListener(this);

RecyclerView list = (RecyclerView) findViewById(R.id.list);
RecyclerView list = findViewById(R.id.list);
list.setNestedScrollingEnabled(false);
list.setLayoutManager(new LinearLayoutManager(this));
list.setAdapter(adapter);
Expand All @@ -77,6 +81,7 @@ public void onItemSelected(int position) {
if (position == POS_LOGOUT) {
finish();
}
slidingRootNav.closeMenu();
Fragment selectedScreen = CenteredTextFragment.createFor(screenTitles[position]);
showFragment(selectedScreen);
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.yarolegovich.slidingrootnav.sample.R;

Expand Down Expand Up @@ -35,8 +36,13 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
String text = getArguments().getString(EXTRA_TEXT);
TextView textView = (TextView) view.findViewById(R.id.text);
final String text = getArguments().getString(EXTRA_TEXT);
TextView textView = view.findViewById(R.id.text);
textView.setText(text);
textView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT).show();
}
});
}
}
1 change: 1 addition & 0 deletions sample/src/main/res/layout/fragment_text.xml
Expand Up @@ -9,6 +9,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-light"
android:clickable="true"
android:textColor="?android:textColorSecondary"
android:textSize="36sp" />

Expand Down

0 comments on commit 4ca0182

Please sign in to comment.