Java Code Examples for android.support.v7.app.ActionBarDrawerToggle#setDrawerIndicatorEnabled()

The following examples show how to use android.support.v7.app.ActionBarDrawerToggle#setDrawerIndicatorEnabled() . 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: ToolBarActivity.java    From drupalfit with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAccountAuthenticatorResponse =
            getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);

    if (mAccountAuthenticatorResponse != null) {
        mAccountAuthenticatorResponse.onRequestContinued();
    }

    setContentView(getContentView());
    ButterKnife.inject(this);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close);
        toggle.setDrawerIndicatorEnabled(true);
        drawerLayout.setDrawerListener(toggle);
    }
}
 
Example 2
Source File: DrawerHelper.java    From screenplay with MIT License 6 votes vote down vote up
private ActionBarDrawerToggle createDrawerToggle(final Activity activity) {

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                activity,
                getLayout(),
                R.string.drawer_open,
                R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                activity.invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                activity.invalidateOptionsMenu();
            }
        };
        toggle.setDrawerIndicatorEnabled(true);
        return toggle;
    }
 
Example 3
Source File: HomeActivity.java    From lockit with Apache License 2.0 5 votes vote down vote up
@AfterViews
void setupNavigationView() {
    mDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    drawer.setDrawerListener(mDrawerToggle);
    navigation.setNavigationItemSelectedListener(this::navigationItemSelected);
    navigation.getMenu().getItem(0).setChecked(true);
}
 
Example 4
Source File: MainActivity.java    From MaterialDesignColors with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close
    );

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    drawerLayout.addDrawerListener(mDrawerToggle);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment_container, new ColorPaletteFragment());
    transaction.commit();


}
 
Example 5
Source File: MainActivity.java    From citrus with Apache License 2.0 5 votes vote down vote up
private void setupNavigationView(Toolbar toolbar) {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    NavigationView navigationView = findById(this, R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switchFragment(menuItem.getItemId());
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawer(GravityCompat.START);
            return false;
        }
    });
}
 
Example 6
Source File: DrawerActivity.java    From Jager with GNU General Public License v3.0 5 votes vote down vote up
private void setupDrawer () {
	setupDrawerList ();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		mDrawer.setElevation (10);
	}
	mDrawerToggle = new ActionBarDrawerToggle (this, mDrawer,
			mToolBar, R.string.open, R.string.close);
	mDrawerToggle.setDrawerIndicatorEnabled (true);
	mDrawer.setDrawerListener (mDrawerToggle);
}
 
Example 7
Source File: MainActivity.java    From android-player with Apache License 2.0 5 votes vote down vote up
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 chaoli-forum-for-android-2 with GNU General Public License v3.0 4 votes vote down vote up
public void initUI(Bundle savedInstanceState) {
	Toolbar toolbar = (Toolbar) findViewById(R.id.tl_custom);
	configToolbar(R.string.app_name);

	mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

	actionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
	actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
	actionBarDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
	actionBarDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			mDrawerLayout.openDrawer(GravityCompat.START);
		}
	});
	actionBarDrawerToggle.syncState();
	mDrawerLayout.addDrawerListener(actionBarDrawerToggle);

	l = binding.conversationList;
	l.addItemDecoration(new android.support.v7.widget.DividerItemDecoration(mContext, android.support.v7.widget.DividerItemDecoration.VERTICAL));

	layoutManager = new LinearLayoutManager(mContext);
	l.setLayoutManager(layoutManager);
	if (NightModeHelper.getViewModel() != null) {
		layoutManager.onRestoreInstanceState(savedInstanceState.getParcelable(LAYOUTMANAGER_STATE));
	}

	swipyRefreshLayout = binding.conversationListRefreshLayout;

	if (NightModeHelper.getViewModel() != null) {
		MyUtils.setToolbarOffset(binding.cl, binding.appbar, savedInstanceState.getInt(TOOLBAR_OFFSET));
	}

	binding.appbar.addOnOffsetChangedListener(this);
	binding.conversationList.addOnScrollListener(new RecyclerView.OnScrollListener() {
		@Override
		public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
			super.onScrolled(recyclerView, dx, dy);
			//得到当前显示的最后一个item的view
               View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount()-1);
			if (lastChildView == null) return;
               //得到lastChildView的bottom坐标值
               int lastChildBottom = lastChildView.getBottom();
               //得到Recyclerview的底部坐标减去底部padding值,也就是显示内容最底部的坐标
               int recyclerBottom =  recyclerView.getBottom()-recyclerView.getPaddingBottom();
               //通过这个lastChildView得到这个view当前的position值
               int lastVisiblePosition  = layoutManager.findLastVisibleItemPosition();

               //判断lastChildView的bottom值跟recyclerBottom
               //判断lastPosition是不是最后一个position
               //如果两个条件都满足则说明是真正的滑动到了底部
			int lastPosition = recyclerView.getLayoutManager().getItemCount() - 1;
			if(lastChildBottom == recyclerBottom && lastVisiblePosition == lastPosition){
                   bottom = true;
                   viewModel.canRefresh.set(true);
               }else{
                   bottom = false;
               }
			if (lastVisiblePosition >= lastPosition - 3) viewModel.tryToLoadFromBottom();
		}
	});

	final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
	navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
		@Override
		public boolean onNavigationItemSelected(@NonNull MenuItem item) {
			if (item.getItemId()==R.id.nightMode){
				NightModeHelper.changeMode(viewModel);
				getWindow().setWindowAnimations(R.style.modechange);
				recreate();
			}else {
				selectItem(item.getOrder());
				item.setChecked(true);
			}
			return true;
		}
	});

	swipyRefreshLayout.setDirection(SwipyRefreshLayoutDirection.BOTH);

	swipyRefreshLayout.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener()
	{
		@Override
		public void onRefresh(SwipyRefreshLayoutDirection direction)
		{
			if (direction == SwipyRefreshLayoutDirection.TOP) {
				viewModel.refresh();
			} else {
				viewModel.loadMore();
			}
		}
	});

	NightModeHelper.removeViewModel();
}
 
Example 9
Source File: FileActivity.java    From Cirrus_depricated with GNU General Public License v2.0 4 votes vote down vote up
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 10
Source File: MainActivity.java    From journaldev with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    findViewById(R.id.drawer_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // open right drawer

            if (drawer.isDrawerOpen(GravityCompat.END)) {
                drawer.closeDrawer(GravityCompat.END);
            }
            else
            drawer.openDrawer(GravityCompat.END);
        }
    });

    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();
        }
    });

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    toggle.setDrawerIndicatorEnabled(false);
    drawer.addDrawerListener(toggle);

    toggle.syncState();


    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example 11
Source File: MainActivity.java    From ShapeRipple with Apache License 2.0 4 votes vote down vote up
private void setupToolbar() {
    AppCompatActivity activity = this;
    activity.setSupportActionBar(mToolbar);

    if (activity.getSupportActionBar() != null) {
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.ripples, R.string.ripple_circle) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    NavigationView navigationView = (NavigationView) findViewById(R.id.main_navigation_view);
    navigationView.setCheckedItem(R.id.nav_circle);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            switch (item.getItemId()) {
                case R.id.nav_circle:
                    ripple.setRippleShape(new Circle());
                    break;
                case R.id.nav_square:
                    ripple.setRippleShape(new Square());
                    break;
                case R.id.nav_triangle:
                    ripple.setRippleShape(new Triangle());
                    break;
                case R.id.nav_star:
                    ripple.setRippleShape(new Star());
                    break;
                case R.id.nav_image:
                    ripple.setRippleShape(new Image(R.drawable.dodge));
                    break;
                case R.id.nav_github:
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/poldz123/ShapeRipple"));
                    startActivity(browserIntent);
                    break;
                case R.id.nav_about:

                    View layout = LayoutInflater.from(MainActivity.this).inflate(R.layout.about_dialog, null, false);
                    TextView version = (TextView) layout.findViewById(R.id.version);

                    version.setText(String.format("Version %s", MainActivity.this.getString(R.string.version)));
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setPositiveButton("Ok", null);
                    builder.setView(layout);

                    final AlertDialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.setCancelable(true);
                    dialog.show();

                    break;

            }

            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
}
 
Example 12
Source File: MainActivity.java    From secrecy with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    int versionNumber =  PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(Config.APP_VERSION_NUMBER, 1);
    mNavigation = (NavListView) findViewById(R.id.left_drawer_list);
    mDrawer = findViewById(R.id.left_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    Storage.deleteTemp();                                           //Start clean
    VaultHolder.getInstance().clear();
    fragmentManager = getFragmentManager();
    switchFragment(0);
    setSupportActionBar(mToolbar);
    if (PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean(Config.SHOW_STEALTH_MODE_TUTORIAL, false)) {
        onFirstLaunch();
    }
    PackageInfo pInfo;
    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        Util.log("Cannot get package info, abort.");
        return;
    }
    if (pInfo != null) {
        if (pInfo.versionCode != versionNumber)
            addFragment(new UpdateManager(), android.R.animator.fade_in, android.R.animator.fade_out);
    }
    mNavigation.addNavigationItem(
            CustomApp.context.getString(R.string.Page_header__vaults),
            R.drawable.ic_vault,
            false);
    mNavigation.addNavigationItem(
            CustomApp.context.getString(R.string.Page_header__settings),
            R.drawable.ic_setting,
            false);
    mNavigation.addNavigationItem(
            CustomApp.context.getString(R.string.action__donate),
            R.drawable.ic_love,
            false);
    mNavigation.addNavigationItem(
            CustomApp.context.getString(R.string.action__about),
            R.drawable.ic_about,
            false);
    mNavigation.addNavigationItem(
            CustomApp.context.getString(R.string.action__support),
            R.drawable.ic_help,
            false);
    mNavigation.setNavigationItemClickListener(new NavListView.NavigationItemClickListener() {
        @Override
        public void onNavigationItemSelected(String item, ArrayList<NavItem> items, int position) {
            Util.log(position, "Clicked");
            switchFragment(position);
            mDrawerLayout.closeDrawers();
        }
    });

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            mToolbar, 0, 0) {

        /**
         * Called when a drawer has settled in a completely closed state.
         */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /**
         * Called when a drawer has settled in a completely open state.
         */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    Util.loadSelectedImageSize(PreferenceManager.getDefaultSharedPreferences(context)
            .getString(Config.IMAGE_SIZE, Config.IMAGE_SIZE_DEFAULT));
    showHelpDeskTutorial();
}
 
Example 13
Source File: PhotosListActivity.java    From soas with Apache License 2.0 4 votes vote down vote up
@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.

}