android.support.v4.app.ActionBarDrawerToggle Java Examples
The following examples show how to use
android.support.v4.app.ActionBarDrawerToggle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrawerLayoutActivity.java From V.FlyoutTest with MIT License | 7 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_layout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (ListView) findViewById(R.id.start_drawer); mContent = (TextView) findViewById(R.id.content_text); mDrawerLayout.setDrawerListener(new DemoDrawerListener()); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES)); mDrawer.setOnItemClickListener(new DrawerItemClickListener()); mActionBar = createActionBarHelper(); mActionBar.init(); // ActionBarDrawerToggle provides convenient helpers for tying together the // prescribed interactions between a top-level sliding drawer and the action bar. mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); }
Example #2
Source File: ComponentsActivity.java From fogger with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.components_view); Injector.inject(this); ButterKnife.inject(this); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.fragmentPlaceholder, new ComponentsFragment(), "blur").commit(); } drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); actionBarDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ drawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(ComponentsActivity.this.getTitle()); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(ComponentsActivity.this.getTitle()); } }; drawerLayout.setDrawerListener(actionBarDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); actionBarDrawerToggle.syncState(); }
Example #3
Source File: HomeACTIVITY.java From ALLGO with Apache License 2.0 | 5 votes |
/** * drawer 的初始化方法 */ private void creatdrawer() { // TODO 生成抽屉方法开始 mTitle = mDrawerTitle = getTitle(); mHomeTitles = getResources().getStringArray(R.array.home_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // 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 mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_list_item,mHomeTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setHomeButtonEnabled(true); // 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.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { mActionBar.setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 此时关闭抽屉 } public void onDrawerOpened(View drawerView) { mActionBar.setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 此时打开抽屉 View v=mDrawerList.getChildAt(position); v.setBackgroundColor(Color.GRAY); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); }
Example #4
Source File: MainActivity.java From Qshp with MIT License | 5 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); initActionBar(); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerToggle); setCategory(Utils.FORUM_CATEGORY[0]); UpdateChecker.checkForNotification(MainActivity.this); replaceFragment(R.id.left_drawer, new DrawerFragment()); }
Example #5
Source File: MainActivity.java From androiddevice.info with GNU General Public License v2.0 | 5 votes |
private void initNavigationDrawer(){ mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon */ 0, /* "open drawer" description */ 0 /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { supportInvalidateOptionsMenu(); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { drawerView.bringToFront(); supportInvalidateOptionsMenu(); } }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.list_item, new String[]{getString(R.string.action_about), getString(R.string.action_send)}); mDrawerOptions.setAdapter(adapter); mDrawerOptions.setOnItemClickListener(MainActivity.this); mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); }
Example #6
Source File: DrawerActivity.java From Fragment-Switcher with Apache License 2.0 | 5 votes |
/** * Sets up the UI for the navigation drawer. */ private void initializeDrawer() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.show, R.string.hide); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); mDrawerToggle.syncState(); }
Example #7
Source File: ActionBarDrawerToggleAssert.java From assertj-android with Apache License 2.0 | 4 votes |
public ActionBarDrawerToggleAssert(ActionBarDrawerToggle actual) { super(actual, ActionBarDrawerToggleAssert.class); }
Example #8
Source File: TestActivity.java From StickyListHeadersWithRefreshAndLoadMore with Apache License 2.0 | 4 votes |
@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 /* "close drawer" description */ ); // 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); }
Example #9
Source File: MainActivity.java From EventApp with Apache License 2.0 | 4 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = getTitle(); 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 /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ public void onDrawerClosed(View view) { setTitle(mTitle); } /** * Called when a drawer has settled in a completely open * state. */ public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle( getResources().getString(R.string.drawer_name)); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mRooms = getResources().getStringArray(R.array.rooms_array); mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mRooms)); // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); }
Example #10
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); title = getActionBar().getTitle(); mPlanetTitles = getResources().getStringArray(R.array.operating_systems); System.out.println(mPlanetTitles.length); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_item,R.id.content, mPlanetTitles)); // Set the list's click listener // TODO add new DrawerItemClickListener() as listener to the items in the list 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 /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBar().setTitle(title); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBar().setTitle("Open Drawer"); } }; // Set the drawer toggle as the DrawerListener // TODO add mDrawerToggle as DrawerListener to the mDrawerLayout // TODO Enable the home button and setDisplayHomeAsUpEnabled(true) via getActionBar() }
Example #11
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); title = getActionBar().getTitle(); mOperationsSystem = getResources().getStringArray(R.array.operating_systems); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_item,R.id.content, mOperationsSystem)); // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 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 /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBar().setTitle(title); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBar().setTitle("Open Drawer"); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); }
Example #12
Source File: NavigationDrawerActivity.java From FadingActionBar with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // 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 mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #13
Source File: BaseActivity.java From Abelana-Android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTitle = mDrawerTitle = getTitle(); mNavItems = getResources().getStringArray(R.array.nav_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); //initialize Data class to retrieve navigation drawer icons and text Data data = new Data(); /* Add the header to the navigation drawer. Pulls the user's name, email address * and photo from the Google Identity Toolkit. The photo is placed into a custom * ImageView which gives the circle effect. Image loading over the network is done * with Picasso, a library from Square. */ View header = View.inflate(this, R.layout.navdrawer_header, null); BezelImageView imageView = (BezelImageView) header.findViewById(R.id.profile_image); UserInfoStore client = new UserInfoStore(getApplicationContext()); GitkitUser user = client.getSavedGitkitUser(); Log.v("foo", "user is " + user); Picasso.with(getApplicationContext()).load(client.getSavedGitkitUser().getPhotoUrl()) .into(imageView); TextView email = (TextView) header.findViewById(R.id.profile_email_text); email.setText(Data.mEmail); TextView name = (TextView) header.findViewById(R.id.profile_name_text); name.setText(Data.mDisplayName); // set up the drawer's list view with mNavItems and click listener mDrawerList.addHeaderView(header, null, false); mDrawerList.setAdapter(new NavDrawerAdapter(getApplicationContext(), R.layout.list_item_navdrawer, data.mNavItems)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(NAVDRAWER_ITEM_HOME); } }
Example #14
Source File: FileChooserActivity.java From MFileChooser with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int main = this.getResources().getIdentifier("main", "layout", this.getPackageName()); int internal = this.getResources().getIdentifier("internal", "string", this.getPackageName()); int drawer_layout = this.getResources().getIdentifier("drawer_layout", "id", this.getPackageName()); int left_drawer = this.getResources().getIdentifier("left_drawer", "id", this.getPackageName()); int drawer_shadow = this.getResources().getIdentifier("drawer_shadow", "drawable", this.getPackageName()); int ic_navigation_drawer = this.getResources().getIdentifier("ic_navigation_drawer", "drawable", this.getPackageName()); int drawer_open = this.getResources().getIdentifier("drawer_open", "string", this.getPackageName()); int drawer_close = this.getResources().getIdentifier("drawer_close", "string", this.getPackageName()); setContentView(main); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); _context = this; Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras .getStringArrayList(Constants.KEY_FILTER_FILES_EXTENSIONS) != null) { extensions = extras .getStringArrayList(Constants.KEY_FILTER_FILES_EXTENSIONS); fileFilter = new FileFilter() { @Override public boolean accept(File pathname) { return ((pathname.isDirectory()) || (pathname.getName() .contains(".") ? extensions.contains(pathname .getName().substring( pathname.getName().lastIndexOf(".")).toLowerCase()) : false)); } }; } } currentFolder = new File(Environment.getExternalStorageDirectory() .getAbsolutePath()); currentCategory = new Category(); currentCategory.title = getString(internal); currentCategory.path = currentFolder.getAbsolutePath(); mDrawerLayout = (DrawerLayout) findViewById(drawer_layout); mDrawerLayout.setDrawerShadow(drawer_shadow,GravityCompat.START); mDrawerList = (ListView) findViewById(left_drawer); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */ drawer_open, /* "open drawer" description for accessibility */ drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { // getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { // getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } }; mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); // ActionBar. //getSupportActionBar().set fill(currentFolder); }
Example #15
Source File: MainActivity.java From NavigationDrawerSI with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); mTitle = mDrawerTitle = getTitle(); getSupportActionBar().setIcon(R.drawable.ic_action_ab_transparent); Timber.tag("LifeCycles"); Timber.d("Activity Created"); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.contentFrame, Fragment.instantiate(MainActivity.this, Fragments.ONE.getFragment())) .commit(); } else { currentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); } navigationItems = new ArrayList<>(); navigationItems.add(new NavigationDrawerItem(getString(R.string.fragment_one), true)); navigationItems.add(new NavigationDrawerItem(getString(R.string.fragment_two), true)); navigationItems.add(new NavigationDrawerItem(getString(R.string.fragment_three), true)); navigationItems.add( new NavigationDrawerItem(getString(R.string.fragment_about), R.drawable.ic_action_about, false)); mNavigationDrawerListViewWrapper.replaceWith(navigationItems); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); supportInvalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBar().setTitle(mTitle); supportInvalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); selectItem(currentSelectedPosition); }
Example #16
Source File: MainActivity.java From catnut with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApp = CatnutApp.getTingtingApp(); mActionBar = getActionBar(); mActionBar.setIcon(R.drawable.ic_title_home); setContentView(R.layout.main); // drawer specific mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.setDrawerListener(this); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.open_drawer, R.string.close_drawer); // the whole left drawer mQuickReturnDrawer = (QuickReturnScrollView) findViewById(R.id.drawer); mQuickReturnDrawer.setCallbacks(this); mQuickReturnView = findViewById(R.id.quick_return); mPlaceholderView = findViewById(R.id.place_holder); mQuickReturnDrawer.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { onScrollChanged(mQuickReturnDrawer.getScrollY()); mMaxScrollY = mQuickReturnDrawer.computeVerticalScrollRange() - mQuickReturnDrawer.getHeight(); mQuickReturnHeight = mQuickReturnView.getHeight(); } } ); // drawer customized view mProfileCover = (ImageView) findViewById(R.id.avatar_profile); mTextNick = (TextView) findViewById(R.id.nick); mDescription = (TextView) findViewById(R.id.description); prepareDrawer(); injectListeners(); if (savedInstanceState == null) { HomeTimelineFragment fragment = HomeTimelineFragment.getFragment(); mCallbacks = fragment; mRefreshCallback = fragment; getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment, HomeTimelineFragment.TAG) .commit(); } getFragmentManager().addOnBackStackChangedListener(this); if (mApp.getPreferences().getBoolean(getString(R.string.pref_enable_analytics), true)) { mTracker = EasyTracker.getInstance(this); } }
Example #17
Source File: NavActivity.java From blog-nested-fragments-backstack with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nav); mTitle = mDrawerTitle = getTitle(); mTitles = getResources().getStringArray(R.array.titles); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // 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 mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #18
Source File: NavigationDrawerActivity.java From UltimateAndroid with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fading_actionbar_activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.fading_actionbar_drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.fading_actionbar_drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.fading_actionbar_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 */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #19
Source File: NavigationDrawerActivity.java From UltimateAndroid with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fading_actionbar_activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.fading_actionbar_drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.fading_actionbar_drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.fading_actionbar_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 */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #20
Source File: NavigationDrawerActivity.java From android-NavigationDrawer with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (RecyclerView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // improve performance by indicating the list if fixed size. mDrawerList.setHasFixedSize(true); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new PlanetAdapter(mPlanetTitles, this)); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #21
Source File: MainActivity.java From loaned-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // If the available screen size is that of an average tablet (as defined // in the Android documentation) then allow the screen to rotate if(getResources().getBoolean(R.bool.lock_orientation)){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } mActionBar = getActionBar(); mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setHomeButtonEnabled(true); // Instatiate Fragments mStatsFrag = new StatsFragment(); mLoansByItemFrag = new LoansByItemFragment(); mLoansByPeopleFrag = new LoansByPersonFragment(); // Do navigation drawer things Log.d(TAG,"Creating NavigationDrawer"); mNavDrawer = (DrawerLayout)findViewById(R.id.main_navdrawer); mNavDrawerList = (ListView)findViewById(R.id.main_navdrawer_list); // Put stuff in the list Log.d(TAG, "Adding items to nav drawer list"); mNavDrawerListItems = new ArrayList<NavDrawerListItem>(); mNavDrawerListItems.add(new NavDrawerListItem(R.drawable.ic_action_person, getResources().getString(R.string.navdrawer_showbyperson))); mNavDrawerListItems.add(new NavDrawerListItem(R.drawable.ic_action_box, getResources().getString(R.string.navdrawer_showbyitem))); mNavDrawerListItems.add(new NavDrawerListItem(R.drawable.ic_action_new, getResources().getString(R.string.navdrawer_addloan))); mNavDrawerListItems.add(new NavDrawerListItem(R.drawable.ic_stats, getResources().getString(R.string.navdrawer_stats))); mNavDrawerListItems.add(new NavDrawerListItem(R.drawable.ic_action_settings, getResources().getString(R.string.navdrawer_settings))); // Change the app icon to show/hide nav drawer on click mNavDrawerToggle = new ActionBarDrawerToggle(this, mNavDrawer, R.drawable.ic_drawer, R.string.main_navdrawer_open, R.string.main_navdrawer_close); mNavDrawer.setDrawerListener(mNavDrawerToggle); // Set the adapter for the ListView mNavDrawerList.setAdapter(new NavDrawerListAdapter(this, R.layout.activity_main_navitem, mNavDrawerListItems)); mNavDrawerList.setOnItemClickListener(this); // Show the default Fragment FragmentTransaction mFragMan = getFragmentManager().beginTransaction(); // Check what the default is if(SettingsFragment.isShowingItemList(this)){ if(savedInstanceState!=null){ // Check savedInstanceState to determine is an orientation // change just happened, if so then replace instead to stop overlapping mFragMan.add(mFrameLayout, mLoansByItemFrag); } else { mFragMan.replace(mFrameLayout, mLoansByItemFrag); } } else { if(savedInstanceState!=null){ mFragMan.add(mFrameLayout, mLoansByPeopleFrag); } else { mFragMan.replace(mFrameLayout, mLoansByPeopleFrag); } } setActivityTitle(getResources().getString(R.string.app_name), null); mFragMan.commit(); }
Example #22
Source File: TodoTxtTouch.java From endpoints-codelab-android with GNU General Public License v3.0 | 4 votes |
private void updateNavigationDrawer() { m_lists = contextsAndProjects(); if (m_lists.size() == 0) { if (m_drawerLayout != null) { // No contexts or projects, disable navigation drawer m_drawerLayout.setDrawerLockMode( DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT); } else { m_drawerList.setVisibility(View.GONE); } getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); } else { if (m_drawerLayout != null) { m_drawerLayout.setDrawerLockMode( DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT); m_drawerToggle = new ActionBarDrawerToggle(this, /* * host Activity */ m_drawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.quickfilter, /* "open drawer" description */ R.string.app_label /* "close drawer" description */ ) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { // Redraw menu to show or hide menu items supportInvalidateOptionsMenu(); super.onDrawerSlide(drawerView, slideOffset); } }; // Set the drawer toggle as the DrawerListener m_drawerLayout.setDrawerListener(m_drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); m_drawerToggle.syncState(); } else { m_drawerList.setVisibility(View.VISIBLE); } m_drawerList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); m_drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, R.id.left_drawer_text, m_lists)); setDrawerChoices(); // Set the list's click listener m_drawerList.setOnItemClickListener(new DrawerItemClickListener()); } }
Example #23
Source File: NavigationDrawerActivity.java From ALLGO with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // 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 mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // 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.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example #24
Source File: AbstractPADListenerActivity.java From PADListener with GNU General Public License v2.0 | 4 votes |
private void initNavDrawer() { MyLog.entry(); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { getActionBar().setTitle(getTitle()); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(getString(getApplicationInfo().labelRes)); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; drawerLayout.setDrawerListener(drawerToggle); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); final ActionBar ab = getActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); } navDrawerItems.clear(); final ViewGroup drawerItemsListContainer = (ViewGroup) findViewById(R.id.navdrawer_items_container); drawerItemsListContainer.removeAllViews(); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.HOME); addNavDrawerSeparator(drawerItemsListContainer); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.VIEW_MONSTER_INFO); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.VIEW_CAPTURED_DATA); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.MANAGE_IGNORE_LIST); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.FILTER_FRIENDS); addNavDrawerSeparator(drawerItemsListContainer); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.SETTINGS); addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.CHANGELOG); if (new MockCaptureHelper(this).hasMockData()) { addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.MOCK_CAPTURE); } addNavDrawerItem(drawerItemsListContainer, NavigationDrawerItem.ABOUT); drawerToggle.syncState(); MyLog.exit(); }
Example #25
Source File: MXCActionBarActivity.java From matrix-android-console with Apache License 2.0 | 4 votes |
/** * Define a sliding menu * @param iconResourceIds the icons resource Ids * @param textResourceIds the text resources Ids * @param replaceUpButton The icon replaces the up button (left side) */ protected void addSlidingMenu(Integer[] iconResourceIds, Integer[] textResourceIds, Boolean replaceUpButton) { // sanity checks if ((null == iconResourceIds) || (null == textResourceIds) || (iconResourceIds.length != textResourceIds.length)) { return; } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // check if the dedicated resource exists if ((null != mDrawerLayout) && (null != mDrawerList)) { // Set the adapter for the list view DrawerAdapter adapter = new DrawerAdapter(this, R.layout.adapter_drawer_header, R.layout.adapter_drawer_item); adapter.setNotifyOnChange(false); for (int index = 0; index < iconResourceIds.length; index++) { adapter.add(iconResourceIds[index], getString(textResourceIds[index])); } adapter.setNotifyOnChange(true); mDrawerList.setAdapter(adapter); // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); if (replaceUpButton) { mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_material_menu, /* nav drawer icon to replace 'Up' caret */ R.string.action_open, /* "open drawer" description */ R.string.action_close /* "close drawer" description */ ) { public void onDrawerClosed(View view) { if (mSelectedSlidingMenuIndex >= 0) { selectDrawItem(mSelectedSlidingMenuIndex); mSelectedSlidingMenuIndex = -1; } } public void onDrawerOpened(View drawerView) { mSelectedSlidingMenuIndex = -1; //dismissKeyboard(thisApp); } }; } // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); // display the home and title button if (null != getSupportActionBar()) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); if (replaceUpButton) { getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_material_menu)); } } } }
Example #26
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 2 votes |
private void addDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.left_drawer); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Set the adapter for the list view drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, drawerListContents)); // Set the list's click listener drawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { hideKeyboard(); super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { hideKeyboard(); super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; drawerToggle.setDrawerIndicatorEnabled(true); // Set the drawer toggle as the DrawerListener drawerLayout.setDrawerListener(drawerToggle); }