Java Code Examples for android.support.v4.widget.DrawerLayout#setDrawerListener()
The following examples show how to use
android.support.v4.widget.DrawerLayout#setDrawerListener() .
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: OverScrollDemoActivity.java From elasticity with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_overscroll_demo); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(R.string.recycler_view_demo_title); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.drawer_nav); navigationView.setNavigationItemSelectedListener(this); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.fragment_placeholder, new RecyclerViewDemoFragment()) .commit(); } }
Example 2
Source File: NavigationActivity.java From AndroidMaterialDesign with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_layout); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar ab = getSupportActionBar(); ab.setDisplayHomeAsUpEnabled(true); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark)); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer); mDrawerLayout.setDrawerListener(toggle); setupDrawerContent(navigationView); }
Example 3
Source File: TrivialActivity.java From OPFIab with Apache License 2.0 | 6 votes |
@Override public void setContentView(final int layoutResID) { super.setContentView(R.layout.activity_trivial); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); drawerLayout = (DrawerLayout) findViewById(R.id.drawer); final View view = getLayoutInflater().inflate(layoutResID, drawerLayout, false); drawerLayout.addView(view, 0); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0); drawerLayout.setDrawerListener(drawerToggle); recyclerView = (RecyclerView) findViewById(R.id.recycler); adapter = new Adapter(recyclerView); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); }
Example 4
Source File: MainActivity.java From styT with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); if (navigationView != null) { setupDrawerContent(navigationView); } ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); if (viewPager != null) { setupViewPager(viewPager); } FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); }
Example 5
Source File: MainActivity.java From android-app with The Unlicense | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Set the fragment initially MainFragment fragment = new MainFragment(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
Example 6
Source File: GameSelector.java From Simple-Solitaire with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game_selector); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setItemIconTintList(null); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); tableLayout = findViewById(R.id.tableLayoutGameChooser); if (!prefs.getSavedStartWithMenu()) { int savedGame = prefs.getSavedCurrentGame(); if (savedGame != DEFAULT_CURRENT_GAME) { Intent intent = new Intent(getApplicationContext(), GameManager.class); intent.putExtra(GAME, savedGame); startActivityForResult(intent, 0); } } else { prefs.saveCurrentGame(DEFAULT_CURRENT_GAME); } }
Example 7
Source File: MainActivity.java From android-player with Apache License 2.0 | 5 votes |
private void initDrawerLayout() { final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ActionBar supportActionBar = getSupportActionBar(); final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.activityMainDrawerLayout); final ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.abc_toolbar_collapse_description, R.string.abc_toolbar_collapse_description); drawerToggle.setDrawerIndicatorEnabled(true); supportActionBar.setDisplayHomeAsUpEnabled(true); supportActionBar.setHomeButtonEnabled(true); supportActionBar.setDisplayShowTitleEnabled(false); drawerToggle.syncState(); drawerLayout.setDrawerListener(drawerToggle); }
Example 8
Source File: MainActivity.java From AndResGuard with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics(), new CrashlyticsNdk()); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close ); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
Example 9
Source File: Main.java From kute with Apache License 2.0 | 5 votes |
/*********************** Overrides ************************/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); route_request_number = (TextView) findViewById(R.id.numberRouteRequests); route_request=(ImageButton)findViewById(R.id.routeRequests); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); /****************************** Drawer Layout Setup ************************/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); /******************************* End Of Drawer Setup **************************/ /********************* Load Home Base Fragment**********/ setupHomeFragment(); navigationView.setCheckedItem(R.id.Home); final SharedPreferences pref = getApplicationContext().getSharedPreferences("user_credentials", 0); // 0 - for private mode Log.d("SharedPreference", pref.getString("Profile_Image", null)); }
Example 10
Source File: PhotosListActivity.java From soas with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer); drawerLayout.setStatusBarBackground(R.color.material_color_primary_dark); // Tie the DrawerLayout with the Toolbar. mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, getToolbar(), R.string.drawer_open, R.string.drawer_close); mDrawerToggle.setDrawerIndicatorEnabled(true); drawerLayout.setDrawerListener(mDrawerToggle); mFragmentManager = getFragmentManager(); mPhotosListFragment = (PhotosListFragment) mFragmentManager.findFragmentById(R.id.photosList); if (findViewById(R.id.photoDetailContainer) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mIsTwoPane = true; // In two-pane mode, list items should be given the // 'activated' state when touched. mPhotosListFragment.setActivateOnItemClick(true); } // Clear Back Stack on recreate. // mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // Or do nothing and make onBackPressed is handled normally. if (mIsTwoPane && mFragmentManager.getBackStackEntryCount() > 0) { findViewById(R.id.photosNoItemSelected).setVisibility(View.GONE); } // Initiate tasks. mPhotosListTaskFragment = (PhotosListTaskFragment) mFragmentManager.findFragmentByTag(TAG_TASK_FRAGMENT_PHOTOS_LIST); // If the Fragment is non-null, then it is currently being // retained across a configuration change. if (mPhotosListTaskFragment == null) { mPhotosListTaskFragment = new PhotosListTaskFragment(); mFragmentManager.beginTransaction(). add(mPhotosListTaskFragment, TAG_TASK_FRAGMENT_PHOTOS_LIST).commit(); } else { mPhotosListFragment.setPhotos( mPhotosListTaskFragment.getLastRequestedPhotosStatusCode(), mPhotosListTaskFragment.getLastRequestedPhotos()); } // TODO: If exposing deep links into your app, handle intents here. }
Example 11
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 12
Source File: NavigationActivity.java From AvI with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); Intent intent = getIntent(); if (intent != null) { handleIntentExtras(intent); } fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); //instantiate the fragmentManager and set the default view to profile fragmentManager = getFragmentManager(); if(fragmentManager.findFragmentByTag(fragmentTag) == null) { currentFragment = new ProfileFragment(); fragmentManager.beginTransaction() .replace(R.id.content_frame, (Fragment) currentFragment, fragmentTag) .commit(); }else{ currentFragment = (INavigationFragment) fragmentManager.findFragmentByTag(fragmentTag); } //initialize the default application settings PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Create an instance of GoogleAPIClient. if (googleApiClient == null) { googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); } }
Example 13
Source File: AppHome.java From android-open-project-demo with Apache License 2.0 | 4 votes |
private void initView() { toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); dlHome = (DrawerLayout) findViewById(R.id.dl_home); getSupportActionBar().setDisplayHomeAsUpEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, dlHome, toolbar, 0, 0); drawerToggle.syncState(); dlHome.setDrawerListener(drawerToggle); fm = getSupportFragmentManager(); //添加菜单 fm.beginTransaction().add(R.id.dl_menu, new DrawerMenuFragment()).commit(); }
Example 14
Source File: MainActivity.java From Weather-Lite with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); if (fab != null) { fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, AddCityActivity.class); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, fab, "aaaaa"); startActivityForResult(intent, SEARCH_CITY_CODE, options.toBundle()); } }); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); weatherService = MyApplication.getInstance().getWeatherService(); if (isNetWorkAccess()) { if (!MyApplication.getInstance().isInitCities()) { //初始化城市列表 weatherService.initCities(WeatherConstant.CITY_SEARCH_TYPE_ALL_CHINA, new HeWeatherPickerImpl.InitCitiesCallback() { @Override public void initSuccess() { MyApplication.getInstance().setInitCities(true); } @Override public void initFailure() { MyApplication.getInstance().setInitCities(false); } }); } } else { toast("无网络,2秒后自动退出"); handler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, 2000); } initView(); initWeather(); }
Example 15
Source File: UnitCategoryActivity.java From ncalc with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_unit_converter_acitvity); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); ArrayList<Integer> arrayList = new ArrayList<>(); arrayList.add(R.drawable.ic_temp); arrayList.add(R.drawable.ic_weight); arrayList.add(R.drawable.ic_length); arrayList.add(R.drawable.ic_power); arrayList.add(R.drawable.ic_power); arrayList.add(R.drawable.ic_speed); arrayList.add(R.drawable.ic_area); arrayList.add(R.drawable.ic_cubic); arrayList.add(R.drawable.ic_bitrate); arrayList.add(R.drawable.ic_time); RecyclerView recyclerView = findViewById(R.id.rcview); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)); CategoryAdapter adapter = new CategoryAdapter(arrayList, UnitCategoryActivity.this); adapter.setListener(new CategoryAdapter.OnItemClickListener() { @Override public void onItemClick(int pos, String text) { startActivity(pos, text); } @Override public void onItemLongClick() { } }); recyclerView.setAdapter(adapter); }
Example 16
Source File: Main.java From Cook-It-Android-XML-Template with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupToolbar(R.id.toolbar, "COOK IT", R.color.colorPink, R.color.colorWhiteTrans, R.drawable.ic_burger); FragmentTransaction ft; FragmentHome fragmentHome = new FragmentHome(); ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.frameLayout, fragmentHome).commit(); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); Menu m = navigationView.getMenu(); for (int i=0;i<m.size();i++) { MenuItem mi = m.getItem(i); SubMenu subMenu = mi.getSubMenu(); if (subMenu!=null && subMenu.size() >0 ) { for (int j=0; j <subMenu.size();j++) { MenuItem subMenuItem = subMenu.getItem(j); applyFontToMenuItem(subMenuItem); } } applyFontToMenuItem(mi); } View header = navigationView.getHeaderView(0); ImageView imageView = (ImageView) header.findViewById(R.id.imageView); Glide.with(this) .load(Uri.parse("https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg")) .transform(new CircleGlide(this)) .into(imageView); }
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: MainActivity.java From NoiseCapture with GNU General Public License v3.0 | 4 votes |
void initDrawer(Integer recordId) { try { // List view mMenuLeft = getResources().getStringArray(R.array.dm_list_array); 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_list_item, mMenuLeft)); // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener(recordId)); // Display the List view into the action bar mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ 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) { super.onDrawerClosed(view); getSupportActionBar().setTitle(getTitle()); } /** * Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBar().setTitle(getString(R.string.title_menu)); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } catch (Exception e) { MAINLOGGER.error(e.getLocalizedMessage(), e); } }
Example 19
Source File: FileActivity.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
protected void initDrawer() { // constant settings for action bar when navigation drawer is inited mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Notification Drawer final NavigationView navigationDrawerLayout = (NavigationView) findViewById(R.id.left_drawer); mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list); // Display username in drawer setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())); // load slide menu items mDrawerTitles = getResources().getStringArray(R.array.drawer_items); // nav drawer content description from resources mDrawerContentDescriptions = getResources(). getStringArray(R.array.drawer_content_descriptions); // nav drawer items mDrawerItems = new ArrayList<>(); // All Files mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0], R.drawable.ic_home)); // Sync mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1], R.drawable.ic_refresh)); // Sort mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2], R.drawable.ic_sort)); // Settings mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3], mDrawerContentDescriptions[3], R.drawable.ic_settings)); // Logs if (BuildConfig.DEBUG) { mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[4], mDrawerContentDescriptions[4], R.drawable.ic_debug)); } // setting the nav drawer list adapter mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this, mDrawerItems); mDrawerList.setAdapter(mNavigationDrawerAdapter); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); updateActionBarTitleAndHomeButton(null); invalidateOptionsMenu(); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBar().setTitle(R.string.drawer_item_all_files); mDrawerToggle.setDrawerIndicatorEnabled(true); // Display username in drawer setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())); invalidateOptionsMenu(); } }; // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.setDrawerIndicatorEnabled(false); }
Example 20
Source File: Fido2DemoActivity.java From security-samples with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation); // START Google sign in API client // configure sign-in to request user info GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestIdToken(Constants.SERVER_CLIENT_ID) .build(); // build client with access to Google Sign-In API and the options specified by gso googleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); // END Google sign in API client // START prepare main layout Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); progressBar = findViewById(R.id.progressBar); swipeRefreshLayout = findViewById(R.id.swipe_container); swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorAccent)); swipeRefreshLayout.setRefreshing(true); swipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { updateAndDisplayRegisteredKeys(); } }); recyclerView = findViewById(R.id.list); recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new SecurityTokenAdapter( new ArrayList<Map<String, String>>(), R.layout.row_token, Fido2DemoActivity.this); // END prepare main layout // START prepare drawer layout DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.setItemIconTintList(null); View header = navigationView.getHeaderView(0); userEmailTextView = header.findViewById(R.id.userEmail); displayNameTextView = header.findViewById(R.id.displayName); Menu menu = navigationView.getMenu(); operationMenuItem = menu.findItem(R.id.nav_fido2Operations); signInMenuItem = menu.findItem(R.id.nav_signin); signOutMenuItem = menu.findItem(R.id.nav_signout); signInButton = findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_WIDE); signInButton.setScopes(gso.getScopeArray()); signInButton.setOnClickListener(this); // END prepare drawer layout // request SignIn or load registered tokens updateUI(); }