Java Code Examples for android.support.design.widget.NavigationView#getMenu()

The following examples show how to use android.support.design.widget.NavigationView#getMenu() . 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: MainActivity.java    From block-this with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Answers(), new Crashlytics());
    setContentView(R.layout.activity_main);
    Toolbar 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 = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (Build.VERSION.SDK_INT<21) {
        Menu nav_menu = navigationView.getMenu();
        nav_menu.findItem(R.id.nav_whitelist).setVisible(false);
    }

    WVersionManager versionManager = new WVersionManager(this);
    versionManager.setVersionContentUrl("https://block-this.com/version.txt");
    versionManager.setUpdateUrl("https://block-this.com/block-this-latest.apk");
    versionManager.setDialogCancelable(false);
    versionManager.setReminderTimer(720);
    versionManager.setIgnoreThisVersionLabel(""); //make button invisible
    versionManager.checkVersion();

    //Initiate shared preferences
    sharedPreferences = this.getSharedPreferences("com.savageorgiev.blockthis", Context.MODE_PRIVATE);
    displaySelectedScreen(R.id.nav_home);
}
 
Example 2
Source File: MainActivity.java    From Varis-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void updateMenuState(@Nullable String accessToken) {
    NavigationView view = findViewById(R.id.navigation_view);
    Menu menu = view.getMenu();
    if (TextUtils.isEmpty(accessToken)) {
        menu.findItem(R.id.drawer_login).setVisible(true);
        menu.findItem(R.id.drawer_logout).setVisible(false);
    } else {
        menu.findItem(R.id.drawer_login).setVisible(false);
        menu.findItem(R.id.drawer_logout).setVisible(true);
    }
}
 
Example 3
Source File: Fido2DemoActivity.java    From security-samples with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 4
Source File: Main.java    From Cook-It-Android-XML-Template with MIT License 4 votes vote down vote up
@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 5
Source File: Fido2DemoActivity.java    From android-fido with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 6
Source File: MainActivity.java    From Inspeckage with Apache License 2.0 4 votes vote down vote up
private void hideItem()
{
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu nav_Menu = navigationView.getMenu();
    nav_Menu.findItem(R.id.nav_auth).setVisible(false);
}
 
Example 7
Source File: PlayActivity.java    From firebase-android-client with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ListView messageHistory;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_play);
    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.addDrawerListener(toggle);
    toggle.syncState();

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

    GoogleSignInOptions.Builder gsoBuilder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail();

    GoogleSignInOptions gso = gsoBuilder.build();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setOnClickListener(this);
    channelLabel = findViewById(R.id.channelLabel);
    Button signOutButton = findViewById(R.id.sign_out_button);
    signOutButton.setOnClickListener(this);

    ImageButton microphoneButton = findViewById(R.id.microphone_button);
    microphoneButton.setOnClickListener(this);

    messages = new ArrayList<>();
    messageAdapter = new SimpleAdapter(this, messages, android.R.layout.simple_list_item_2,
            new String[]{"message", "meta"},
            new int[]{android.R.id.text1, android.R.id.text2});

    messageHistory = findViewById(R.id.messageHistory);
    messageHistory.setOnItemClickListener(this);
    messageHistory.setAdapter(messageAdapter);
    messageText = findViewById(R.id.messageText);
    messageText.setOnKeyListener(this);
    fmt = new SimpleDateFormat("yy.MM.dd HH:mm z", Locale.US);

    status = findViewById(R.id.status);
}
 
Example 8
Source File: MainActivity.java    From Paperwork-Android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    if (!HostPreferences.preferencesExist(this))
    {
        Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class);
        startActivity(loginIntent);
        finish();
        return;
    }

    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mUserLearnedDrawer = Boolean.valueOf(HostPreferences.readSharedSetting(this, HostPreferences.PREF_USER_LEARNED_DRAWER, "false"));
    mNavigationView.setNavigationItemSelectedListener(this);

    View header = mNavigationView.getHeaderView(0);

    String email = HostPreferences.readSharedSetting(this, "email", "");
    TextView userEmail = (TextView) header.findViewById(R.id.user_email);
    userEmail.setText(email);

    setupToolbar();
    setupNavDrawer();

    if (savedInstanceState != null)
    {
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
    }

    Menu menu = mNavigationView.getMenu();
    menu.getItem(mCurrentSelectedPosition).setChecked(true);
    onNavigationItemSelected(menu.getItem(mCurrentSelectedPosition));

    mTagMenu = menu.addSubMenu(R.string.tags);

    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, mToolbar,
            R.string.menu_open, R.string.menu_close
    );
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    getContentResolver().registerContentObserver(
            DatabaseContract.TagEntry.CONTENT_URI, true, new ContentObserver(new Handler(getMainLooper()))
            {
                @Override
                public void onChange(boolean selfChange)
                {
                    updateView();
                }
            });


    SyncAdapter.syncImmediately(this);
    updateView();
}