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

The following examples show how to use android.support.design.widget.NavigationView#getHeaderView() . 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 Varis-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void updateUserData(User user) {
    final NavigationView view = findViewById(R.id.navigation_view);
    View header = view.getHeaderView(0);
    TextView usernameView = header.findViewById(R.id.drawer_header_username);
    TextView emailView = header.findViewById(R.id.drawer_header_email);

    if (user != null) {
        String username = user.getLogin();
        if (!TextUtils.isEmpty(user.getName())) {
            username = String.format("%1$s (%2$s)", user.getName(), user.getLogin());
        }
        usernameView.setText(username);
        emailView.setText(user.getEmail());

        // TODO Update image, when service will provide it
    } else {
        usernameView.setText(R.string.navigation_drawer_username_placeholder);
        emailView.setText(R.string.navigation_drawer_email_placeholder);
    }
}
 
Example 2
Source File: AttendanceActivity.java    From bunk with MIT License 6 votes vote down vote up
private void setupDrawer() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    Toolbar toolbar = findViewById(R.id.toolbar);
    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);
    navigationView.setNavigationItemSelectedListener(this);

    View navigationViewHeader = navigationView.getHeaderView(0);
    ((TextView) navigationViewHeader.findViewById(R.id.name)).setText(this.newStudent.name);
    ((TextView) navigationViewHeader.findViewById(R.id.username)).setText(this.newStudent.username);
    String prompts[] = {"open source?", "coding?", "programming?", "code+coffee?"};
    TextView opensource = drawer.findViewById(R.id.opensource);
    opensource.setText(prompts[new Random().nextInt(prompts.length)]);
    TextView github = drawer.findViewById(R.id.github);
    github.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
    github.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.github_url))));
        }
    });
}
 
Example 3
Source File: HomeActivity.java    From SEAL-Demo with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (!BuildConfig.DEBUG) {
        //let's avoid sending AppCenter data for dev workflows
        AppCenter.start(getApplication(), getString(R.string.app_center_secret_key),
                Analytics.class, Crashes.class, Distribute.class);
    }

    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.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View headerView = navigationView.getHeaderView(0);
    mUserName = (TextView) headerView.findViewById(R.id.username_drawer);
    mUserMail = (TextView) headerView.findViewById(R.id.email_drawer);
    View userLogo = headerView.findViewById(R.id.userLogo);
    mUserLogoText = (TextView) headerView.findViewById(R.id.user_logo_text);
    mImageDrawer = (ImageView) headerView.findViewById(R.id.user_logo_image);

    Configuration.loadConfigFile(getSharedPreferences("config", 0));
    // check the network connection
    checkNetworkConnection();
}
 
Example 4
Source File: BaseActivity.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
private void configureNavView() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(navigationViewListener);

    View headerLayout = navigationView.getHeaderView(0);
    mHeaderCity = (TextView) headerLayout.findViewById(R.id.nav_header_city);
    //mHeaderCity.setText(Utils.getCityAndCountry(this));
}
 
Example 5
Source File: MainActivity.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
public void init() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nvView);

    navHeader = navigationView.getHeaderView(0);
    txtName = (TextView) navHeader.findViewById(R.id.name);
    txtSubName = (TextView) navHeader.findViewById(R.id.subname);
    imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
    imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);

    viewPager = (ViewPager) findViewById(R.id.main_view_pager);

    quiz_layout = (LinearLayout) findViewById(R.id.quiz_layout);
    gallery_layout = (LinearLayout) findViewById(R.id.gallery_layout);
    map_layout = (LinearLayout) findViewById(R.id.map_layout);
    newsfeed_layout = (LinearLayout) findViewById(R.id.newsfeed_layout);
    coreteam_layout = (LinearLayout) findViewById(R.id.coreteam_layout);
    aboutnimbus_layout = (LinearLayout) findViewById(R.id.aboutnimbus_layout);
    teams_layout = (LinearLayout) findViewById(R.id.teams_layout);
    feedback_layout = (LinearLayout) findViewById(R.id.feedback_layout);
    contributor_layout = (LinearLayout) findViewById(R.id.contributor_layout);
    sponsor_layout = (LinearLayout) findViewById(R.id.sponsor_layout);
    workshop_layout = (LinearLayout) findViewById(R.id.workshop_layout);
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);

}
 
Example 6
Source File: HomescreenNew.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
public void init() {
    toolbar = (Toolbar) findViewById(R.id.home_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("Nimbus 2k18");

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nvView);

    navHeader = navigationView.getHeaderView(0);
    txtName = (TextView) navHeader.findViewById(R.id.name);
    txtSubName = (TextView) navHeader.findViewById(R.id.subname);
    imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
    imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);


    viewPager = (ViewPager) findViewById(R.id.main_view_pager);

    quiz_layout = (LinearLayout) findViewById(R.id.quiz_layout);
    gallery_layout = (LinearLayout) findViewById(R.id.gallery_layout);
    map_layout = (LinearLayout) findViewById(R.id.map_layout);
    newsfeed_layout = (LinearLayout) findViewById(R.id.newsfeed_layout);
    coreteam_layout = (LinearLayout) findViewById(R.id.coreteam_layout);
    aboutnimbus_layout = (LinearLayout) findViewById(R.id.aboutnimbus_layout);
    teams_layout = (LinearLayout) findViewById(R.id.teams_layout);
    feedback_layout = (LinearLayout) findViewById(R.id.feedback_layout);
    contributor_layout = (LinearLayout) findViewById(R.id.contributor_layout);
    sponsor_layout = (LinearLayout) findViewById(R.id.sponsor_layout);
    workshop_layout = (LinearLayout) findViewById(R.id.workshop_layout);
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);

}
 
Example 7
Source File: TheHubActivity.java    From ToDay with MIT License 5 votes vote down vote up
private void generateDrawerGreeting(NavigationView view) {
    View header=view.getHeaderView(0);
    TextView greeting = (TextView) header.findViewById(R.id.ndrawer_date_greeting);
    String[] array = this.getResources().getStringArray(R.array.drawer_greeting);

    switch(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)){
        case Calendar.MONDAY:
            greeting.setText(array[0]);
            break;

        case Calendar.TUESDAY:
            greeting.setText(array[1]);
            break;

        case Calendar.WEDNESDAY:
            greeting.setText(array[2]);
            break;
        case Calendar.THURSDAY:
            greeting.setText(array[3]);
            break;
        case Calendar.FRIDAY:
            greeting.setText(array[4]);
            break;
        case Calendar.SATURDAY:
            greeting.setText(array[5]);
            break;

        case Calendar.SUNDAY:
            greeting.setText(array[6]);
            break;

        default:
            greeting.setText(array[7]);
            break;

    }

}
 
Example 8
Source File: BaseActivity.java    From good-weather with GNU General Public License v3.0 5 votes vote down vote up
private void configureNavView() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(navigationViewListener);

    View headerLayout = navigationView.getHeaderView(0);
    mHeaderCity = (TextView) headerLayout.findViewById(R.id.nav_header_city);
    mHeaderCity.setText(Utils.getCityAndCountry(this));
}
 
Example 9
Source File: MainActivity.java    From RxJavaApp with Apache License 2.0 5 votes vote down vote up
private void initNavigationView() {
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    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);

    mHeadView = (LinearLayout) navigationView.getHeaderView(0);
    mNavRecyclerView = (RecyclerView) navigationView.getHeaderView(0).findViewById(R.id.index_nav_recycler);
    mHeadView.setClickable(true);
    mHeadView.setOnClickListener(this);

}
 
Example 10
Source File: NavigationViewActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_view);

    nv = (NavigationView) findViewById(R.id.nv);

    //设置icon图标 null显示实际图片
    nv.setItemIconTintList(null);

    //设置NavigationView菜单的点击事件(不包含头部)
    nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            switch (item.getItemId()){
                case R.id.menu1:{
                    Toast.makeText(NavigationViewActivity.this, "realmo test", Toast.LENGTH_SHORT).show();
                }break;
                case R.id.menu2:{}break;
                case R.id.menu3:{}break;
                case R.id.menu4:{}break;
            }
            return false;
        }
    });

    //头部点击事件
    //获取头布局文件
    View headerView = nv.getHeaderView(0);
    //headerView中的findViewById方法来查找到头部的控件,设置点击事件即可。

}
 
Example 11
Source File: MainActivity.java    From Travel-Mate with MIT License 5 votes vote down vote up
private void fillNavigationView(String emailId, String imageURL) {

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

        // Get reference to the navigation view header and email textview
        View navigationHeader = navigationView.getHeaderView(0);
        TextView emailTextView = navigationHeader.findViewById(R.id.email);
        emailTextView.setText(emailId);

        ImageView imageView = navigationHeader.findViewById(R.id.image);
        Picasso.with(MainActivity.this).load(imageURL).placeholder(R.drawable.icon_profile)
                .error(R.drawable.icon_profile).into(imageView);
        imageView.setOnClickListener(v -> startActivity(ProfileActivity.getStartIntent(MainActivity.this)));
    }
 
Example 12
Source File: MainActivity.java    From gank.io-unofficial-android-client with Apache License 2.0 5 votes vote down vote up
private void setUpDrawerContent(NavigationView navigationView) {

    View headerView = navigationView.getHeaderView(0);
    mUserAvatar = (CircleImageView) headerView.findViewById(R.id.github_user_avatar);
    mUserName = (TextView) headerView.findViewById(R.id.github_user_name);
    mUserBio = (TextView) headerView.findViewById(R.id.github_user_bio);
    mUserAvatar.setOnClickListener(this);

    setUserInfo();

    navigationView.setNavigationItemSelectedListener(
        menuItem -> {

          switch (menuItem.getItemId()) {
            case R.id.nav_home:
              changNavItem(menuItem, 0, "Gank.io", true);
              return true;

            case R.id.nav_my_focus:
              changNavItem(menuItem, 1, "Notes", false);
              return true;

            case R.id.nav_about:
              //关于我
              startActivity(new Intent(MainActivity.this, HotBitmapGGActivity.class));
              break;

            case R.id.nav_about_app:
              // 关于App
              startActivity(new Intent(MainActivity.this, AboutActivity.class));
              break;

            default:
              break;
          }
          return true;
        });
  }
 
Example 13
Source File: HomeActivity.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("SkipTutorial", true);
    editor.apply();

    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    View menuHeaderView = navigationView.getHeaderView(0);
    final TextView name = (TextView) menuHeaderView.findViewById(R.id.name);
    name.setText(String.format(" %s", prefs.getString(getString(R.string.key_user_name), "")));


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    smoothNavigationToggle = new SmoothNavigationToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            name.setText(String.format(" %s", prefs.getString(getString(R.string.key_user_name), "")));
            LoadProjectFragment f = (LoadProjectFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG_PROJECT);
            if (f != null)
                f.closeSearch();

            LoadApkFragment f2 = (LoadApkFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG_APK);
            if (f2 != null)
                f2.closeSearch();
        }
    };
    drawer.addDrawerListener(smoothNavigationToggle);
    smoothNavigationToggle.syncState();

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, new HomeFragment(), FRAGMENT_TAG_HOME).commit();
    navigationView.setCheckedItem(R.id.nav_home);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(R.string.app_name);
    }
}
 
Example 14
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 15
Source File: MainActivity.java    From AndroidBleManager with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        BleManager.setBleParamsOptions(ConstValue.getBleOptions(this));

        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();
                EventBus.getDefault().post(new UpdateEvent(UpdateEvent.Type.POP_SHOW, currentTab));
            }
        });
        fab.setVisibility(View.GONE);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, mToolbar, 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);

        //这里是获取NavigationView里面view的方法
        View headerLayout = navigationView.getHeaderView(0);
        ((TextView)headerLayout.findViewById(R.id.tv_my_version)).setText(BuildConfig.VERSION_NAME);

        fragments = new ArrayList<Fragment>();
        fragments.add(new ScanFragment());
        fragments.add(new ConnectOneFragment());
        fragments.add(new ConnectManyFragment());
        mAdapter = new FragmentPageAdapter(getSupportFragmentManager(), fragments);
//        mViewPager.setOffscreenPageLimit(fragments.size());
        mViewPager.setAdapter(mAdapter);
        mViewPager.setLocked(true);
        mViewPager.addOnPageChangeListener(listener);

        initScan();

        updateFirAppUpdate();
        String tmp = FileUtils.getOutCacheDir(getApplicationContext()).getPath()+"/result_data.txt";
        saveFile = new File(tmp);
    }
 
Example 16
Source File: MainActivity.java    From ruby-china-android 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.main_toolbar);
    setSupportActionBar(toolbar);

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

    mDrawerLayout.addDrawerListener(mDrawerToggle);

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

    View headerView = mNavigationView.getHeaderView(0);
    mUserAvatarImageView = (SimpleDraweeView) headerView.findViewById(R.id.user_avatar);
    mUserNameTextView = (TextView) headerView.findViewById(R.id.user_name);
    mUserEmailTextView = (TextView) headerView.findViewById(R.id.user_email);

    turbolinksView = (TurbolinksView) findViewById(R.id.turbolinks_view);

    TurbolinksSession.getDefault(this).setDebugLoggingEnabled(true);

    WebSettings webSettings = TurbolinksSession.getDefault(this).getWebView().getSettings();
    webSettings.setUserAgentString("turbolinks-app, ruby-china, official, android");

    location = getString(R.string.root_url) + "/topics";

    TurbolinksSession.getDefault(this)
            .activity(this)
            .adapter(this)
            .view(turbolinksView)
            .visit(location);
}
 
Example 17
Source File: SilentActivity.java    From KUAS-AP-Material with MIT License 4 votes vote down vote up
public void setUpMenuDrawer(int selectItem) {
	drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	navigationView = (NavigationView) findViewById(R.id.nav_view);
	headerView = navigationView.getHeaderView(0);
	if (headerView.findViewById(R.id.layout_user) != null) {
		final boolean isLogin = Memory.getBoolean(this, Constant.PREF_IS_LOGIN, false);
		headerView.findViewById(R.id.layout_user)
				.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						drawer.closeDrawers();
						if (mLayoutID == R.layout.activity_messages ||
								mLayoutID == R.layout.activity_about) {
							if (isLogin) {
								showUserInfo();
							} else {
								startActivity(
										new Intent(SilentActivity.this, LoginActivity.class));
							}
						} else if (mLayoutID == R.layout.activity_login) {
							Toast.makeText(SilentActivity.this, R.string.login_first,
									Toast.LENGTH_SHORT).show();
						} else {
							showUserInfo();
						}
					}
				});
	}

	drawer.setDrawerShadow(R.drawable.shadow_right, GravityCompat.START);
	drawer.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.main_theme_dark));

	mDrawerToggle = new AnimationActionBarDrawerToggle(this, drawer, R.string.open_drawer,
			R.string.close_drawer) {

		@Override
		public void onDrawerSlide(View drawerView, float slideOffset) {
			if (drawerView == navigationView) {
				super.onDrawerSlide(drawerView, slideOffset);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely closed state. */
		public void onDrawerClosed(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerClosed(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely open state. */
		public void onDrawerOpened(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerOpened(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}
	};

	// Set the drawer toggle as the DrawerListener
	drawer.setDrawerListener(mDrawerToggle);
	navigationView.setNavigationItemSelectedListener(this);

	mSelectedItem = -1;
	if (-1 < selectItem && selectItem < navigationView.getMenu().size()) {
		selectedMenuItem = navigationView.getMenu().getItem(selectItem);
		selectedMenuItem.setChecked(true);
		mSelectedItem = selectItem;
	}
}
 
Example 18
Source File: HomeActivity.java    From AndroidDemo with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        dbManager = DBManager.getInstance(HomeActivity.this);
        toolbar = (Toolbar)findViewById(R.id.home_activity_toolbar);
        setSupportActionBar(toolbar);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        navView = (NavigationView) findViewById(R.id.nav_view);
        View headerView = navView.getHeaderView(0);
        navHeadIv = (ImageView)headerView.findViewById(R.id.nav_head_bg_iv);
        loadBingPic();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.drawer_menu);
        }
        refreshNightModeTitle();
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                mDrawerLayout.closeDrawers();
                switch (item.getItemId()){
                    case R.id.nav_theme:
                        isStartTheme = true;
                        Intent intentTheme = new Intent(HomeActivity.this,ThemeActivity.class);
                        startActivity(intentTheme);
                        break;
                    case R.id.nav_night_mode:
                        int preTheme = 0;
                        if(MyMusicUtil.getNightMode(HomeActivity.this)){
                            //当前为夜间模式,则恢复之前的主题
                            MyMusicUtil.setNightMode(HomeActivity.this,false);
                            preTheme = MyMusicUtil.getPreTheme(HomeActivity.this);
                            MyMusicUtil.setTheme(HomeActivity.this,preTheme);
                        }else {
                            //当前为白天模式,则切换到夜间模式
                            MyMusicUtil.setNightMode(HomeActivity.this,true);
                            MyMusicUtil.setTheme(HomeActivity.this,ThemeActivity.THEME_SIZE-1);
                        }
//                        Intent intentNight = new Intent(HomeActivity.this,HomeActivity.class);
//                        startActivity(intentNight);
                        recreate();
                        refreshNightModeTitle();
//                        overridePendingTransition(R.anim.start_anim,R.anim.out_anim);
                        break;
                    case R.id.nav_about_me:
                        Intent aboutTheme = new Intent(HomeActivity.this,AboutActivity.class);
                        startActivity(aboutTheme);
                        break;
                    case R.id.nav_logout:
                        finish();
                        Intent intentBroadcast = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
                        intentBroadcast.putExtra(Constant.COMMAND, Constant.COMMAND_RELEASE);
                        sendBroadcast(intentBroadcast);
                        Intent stopIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
                        stopService(stopIntent);
                        break;
                }
                return true;
            }
        });
        init();

        Intent startIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
        startService(startIntent);

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