use of android.support.v4.app.ActionBarDrawerToggle in project UltimateAndroid by cymcsg.
the class NavigationDrawerFragment method setUp.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param fragmentId The android:id of this fragment in its activity's layout.
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActivity().getActionBar();
// actionBar.setDisplayHomeAsUpEnabled(true);
// actionBar.setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().invalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
// calls onPrepareOptionsMenu()
getActivity().invalidateOptionsMenu();
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
use of android.support.v4.app.ActionBarDrawerToggle in project FlexibleAdapter by davideas.
the class MainActivity method initializeDrawer.
private void initializeDrawer() {
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
// Version
TextView appVersion = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.app_version);
appVersion.setText(getString(R.string.about_version, Utils.getVersionName(this), Integer.toString(Utils.getVersionCode(this))));
}
use of android.support.v4.app.ActionBarDrawerToggle in project Libraries-for-Android-Developers by eoecn.
the class MainActivity method onCreate.
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.common_title_bg));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
mContentLayout = (FrameLayout) findViewById(R.id.content_frame);
mDrawerList = (ListView) findViewById(R.id.left_drawer_list_view);
// List<Object> items = new ArrayList<Object>();
// items.add(new Category(""));
// items.add(new Item("最新的", R.drawable.star));
// items.add(new Item("热门的", R.drawable.like_me));
// items.add(new Item("收藏的", R.drawable.star));
//获取侧栏目数据 每次都更新不使用缓存
SlideFactory.getInstance(this).getSlide(false, new SlideRevHandler() {
@Override
public void onSuccess(int statusCode, LibSlides slides) {
//异步获取的,如果有缓存数据就直接返回
System.err.println(statusCode + " " + slides.getData().get(0).getItems().get(0).getTitle());
}
@Override
public void onFailure(int statusCode, Throwable throwable) {
throwable.printStackTrace();
}
});
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.app_name, /* "open drawer" description for accessibility */
R.string.app_name) {
/* "close drawer" description for accessibility */
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// creates call to onPrepareOptionsMenu()
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// creates call to onPrepareOptionsMenu()
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
use of android.support.v4.app.ActionBarDrawerToggle in project StickyListHeaders by emilsjolander.
the class TestActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
}
}, 1000);
}
});
mAdapter = new TestBaseAdapter(this);
stickyList = (StickyListHeadersListView) findViewById(R.id.list);
stickyList.setOnItemClickListener(this);
stickyList.setOnHeaderClickListener(this);
stickyList.setOnStickyHeaderChangedListener(this);
stickyList.setOnStickyHeaderOffsetChangedListener(this);
stickyList.addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null));
stickyList.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null));
stickyList.setEmptyView(findViewById(R.id.empty));
stickyList.setDrawingListUnderStickyHeader(true);
stickyList.setAreHeadersSticky(true);
stickyList.setAdapter(mAdapter);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close);
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
restoreButton = (Button) findViewById(R.id.restore_button);
restoreButton.setOnClickListener(buttonListener);
openExpandableListButton = (Button) findViewById(R.id.open_expandable_list_button);
openExpandableListButton.setOnClickListener(buttonListener);
updateButton = (Button) findViewById(R.id.update_button);
updateButton.setOnClickListener(buttonListener);
clearButton = (Button) findViewById(R.id.clear_button);
clearButton.setOnClickListener(buttonListener);
stickyCheckBox = (CheckBox) findViewById(R.id.sticky_checkBox);
stickyCheckBox.setOnCheckedChangeListener(checkBoxListener);
fadeCheckBox = (CheckBox) findViewById(R.id.fade_checkBox);
fadeCheckBox.setOnCheckedChangeListener(checkBoxListener);
drawBehindCheckBox = (CheckBox) findViewById(R.id.draw_behind_checkBox);
drawBehindCheckBox.setOnCheckedChangeListener(checkBoxListener);
fastScrollCheckBox = (CheckBox) findViewById(R.id.fast_scroll_checkBox);
fastScrollCheckBox.setOnCheckedChangeListener(checkBoxListener);
stickyList.setStickyHeaderTopOffset(-20);
}
use of android.support.v4.app.ActionBarDrawerToggle in project MaterialViewPager by florent37.
the class DrawerActivity method onStart.
@Override
protected void onStart() {
super.onStart();
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
mDrawer.setDrawerListener(mDrawerToggle);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
}
}
Aggregations