android.support.v4.view.GravityCompat Java Examples
The following examples show how to use
android.support.v4.view.GravityCompat.
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 RHub with Apache License 2.0 | 7 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { //shield.addSensor(Sensors.startAcc(getApplicationContext())); } else if (id == R.id.nav_gallery) { //shield.addSensor(Sensors.startLight(getApplicationContext())); } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #2
Source File: MainActivity.java From AndroidBarUtils with Apache License 2.0 | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { // Handle the camera action } else if (id == R.id.nav_gallery) { } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #3
Source File: NavigationActivity.java From android with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch (id) { case android.R.id.home: drawerLayout.openDrawer(GravityCompat.START); return true; case R.id.action_abandon: new AlertDialog.Builder(this) .setMessage(R.string.abandon_confirmation) .setTitle(R.string.are_you_sure) .setPositiveButton(R.string.yes, (d, w) -> abandon(d)) .setNegativeButton(R.string.no, (d, w) -> d.dismiss()) .create() .show(); return true; } return super.onOptionsItemSelected(item); }
Example #4
Source File: MainActivity.java From Jreader with GNU General Public License v2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { Intent intent = new Intent(MainActivity.this,FileAcitvity.class); startActivity(intent); return true; } if (id==android.R.id.home) { drawerLayout.openDrawer(GravityCompat.START); } return super.onOptionsItemSelected(item); }
Example #5
Source File: MainActivity.java From Puff-Android with MIT License | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { Category category = CategoryHelper.getInstance(getApplicationContext()) .getCategoryByName(String.valueOf(item.getTitle())); loadAccountByCategory(category); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (headerImageView != null) Picasso.with(this).load(ResUtil.getInstance(null).getBmpUri(category.getIcon())) .config(Bitmap.Config.RGB_565) .fit() .into(headerImageView); if (headerTextView != null) headerTextView.setText(category.getName()); drawer.closeDrawer(GravityCompat.START); if (lastChecked != null) lastChecked.setChecked(false); item.setChecked(true); lastChecked = item; return true; }
Example #6
Source File: MainActivity.java From find-client-android with MIT License | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); Fragment fragment; if (id == R.id.nav_settings) { fragment = new SettingsFragment(); } else if (id == R.id.nav_track) { fragment = new TrackFragment(); } else { // Anything else is home fragment = new LearnFragment(); } // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content, fragment) .commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #7
Source File: MainActivity.java From DarkCalculator with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (drawer.isDrawerOpen(GravityCompat.END)) { drawerPager.setCurrentItem(0); drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END); drawer.closeDrawer(GravityCompat.END); } else if (drawer.isDrawerOpen(GravityCompat.START)) drawer.closeDrawer(GravityCompat.START); else drawer.openDrawer(GravityCompat.START); break; } return true; }
Example #8
Source File: MainActivity.java From FloatingActionButton with Apache License 2.0 | 6 votes |
@Override public boolean onNavigationItemSelected(MenuItem item) { mDrawerLayout.closeDrawer(GravityCompat.START); Fragment fragment = null; final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); switch (item.getItemId()) { case R.id.home: fragment = new HomeFragment(); break; case R.id.menus: fragment = new MenusFragment(); break; case R.id.progress: fragment = new ProgressFragment(); break; } ft.replace(R.id.fragment, fragment).commit(); return true; }
Example #9
Source File: MainActivity.java From cheesesquare with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_night_mode_system: setNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); break; case R.id.menu_night_mode_day: setNightMode(AppCompatDelegate.MODE_NIGHT_NO); break; case R.id.menu_night_mode_night: setNightMode(AppCompatDelegate.MODE_NIGHT_YES); break; case R.id.menu_night_mode_auto: setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); break; } return super.onOptionsItemSelected(item); }
Example #10
Source File: ActivityTelegram.java From emoji-keyboard with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_toogle: Intent intent = new Intent(ActivityTelegram.this, ActivityWhatsApp.class); ActivityTelegram.this.startActivity(intent); ActivityTelegram.this.finish(); break; case android.R.id.home: if (this.mDrawerLayout.isDrawerOpen(GravityCompat.START)) { this.mDrawerLayout.closeDrawer(GravityCompat.START); } else { this.mDrawerLayout.openDrawer(GravityCompat.START); } break; } return super.onOptionsItemSelected(item); }
Example #11
Source File: Permission.java From soundcom with Apache License 2.0 | 6 votes |
public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.receive) { initReceive(); } else if (id == R.id.transmit) { initTransmit(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #12
Source File: NavigationViewItemSelectedListenerTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void onNavigationItemSelected_shouldSelectFavourite() { setupActivity(); MenuItem item = clickMenuItem(R.id.nav_favourite); assertEquals("wrong title", labelDrawerMenuFavourite, item.getTitle()); assertEquals("invalid menu order", MENU_FAVOURITE, item.getOrder()); assertEquals("wrong title", labelApplicationName, activity.getSupportActionBar().getTitle()); assertFalse("should be hidden", activity.floatingActionButtonMain.isShown()); Fragment currentFragment = activity.getSupportFragmentManager().findFragmentById(R.id.content_frame); assertNotNull("null fragment", currentFragment); assertThat("invalid fragment", currentFragment, instanceOf(DeviceListFragment.class)); int argumentEnvironment = currentFragment.getArguments().getInt(ARG_ENVIRONMENT); assertEquals("invalid fragment", MENU_FAVOURITE, argumentEnvironment); assertFalse("should be close", activity.drawerLayout.isDrawerOpen(GravityCompat.START)); }
Example #13
Source File: MainActivity.java From BmapLite with GNU General Public License v3.0 | 6 votes |
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { int id = item.getItemId(); if (id == R.id.nav_change_map) { changeMap(item); mDrawer.closeDrawer(GravityCompat.START); } else if (id == R.id.nav_ranging) { changeModeRanging(!item.isChecked()); mDrawer.closeDrawer(GravityCompat.START); } else if (id == R.id.nav_offline_map) { openActivity(OfflineMapActivity.class); } else if (id == R.id.nav_about) { openActivity(AboutActivity.class); } else if (id == R.id.nav_favorite) { Intent intent = new Intent(MainActivity.this, FavoriteActivity.class); startActivityForResult(intent, REQUEST_SEARCH); } else if (id == R.id.nav_setting) { openActivity(SettingActivity.class); } return true; }
Example #14
Source File: MainActivity.java From Weather-Lite with Apache License 2.0 | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); // if (id == R.id.nav_camera) { // // Handle the camera action // } else if (id == R.id.nav_gallery) { // // } else if (id == R.id.nav_slideshow) { // // } else if (id == R.id.nav_manage) { // // } else if (id == R.id.nav_share) { // // } else if (id == R.id.nav_send) { // // } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #15
Source File: Activity_Main.java From FoodOrdering with Apache License 2.0 | 6 votes |
/** * 处理toolbar中各个按钮的点击事件 * * @param item * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home://HomeAsUp按钮id永远是home drawerLayout.openDrawer(GravityCompat.START);//将滑动菜单显示,GravityCompat.START和xml定义的一致 break; case R.id.scanner://扫一扫 if (!Util.checkNetwork(this)) { break; } Intent intent = new Intent(Activity_Main.this, CaptureActivity.class); startActivityForResult(intent, REQUEST_CODE_SCAN); break; default: break; } return true; }
Example #16
Source File: DrawerLayout.java From guideshow with MIT License | 6 votes |
/** * Set a simple drawable used for the left or right shadow. * The drawable provided must have a nonzero intrinsic width. * * @param shadowDrawable Shadow drawable to use at the edge of a drawer * @param gravity Which drawer the shadow should apply to */ public void setDrawerShadow(Drawable shadowDrawable, int gravity) { /* * TODO Someone someday might want to set more complex drawables here. * They're probably nuts, but we might want to consider registering callbacks, * setting states, etc. properly. */ final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)); if ((absGravity & Gravity.LEFT) == Gravity.LEFT) { mShadowLeft = shadowDrawable; invalidate(); } if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) { mShadowRight = shadowDrawable; invalidate(); } }
Example #17
Source File: MainActivity.java From LQRBiliBlili with MIT License | 6 votes |
@Override public void onBackPressedSupport() { if (mDrawer.isDrawerOpen(GravityCompat.START)) { closeDrawer(); } else { ISupportFragment topFragment = getTopFragment(); if (!(topFragment instanceof NavHomeFragment)) { mNav.setCheckedItem(R.id.nav_home); } if (getSupportFragmentManager().getBackStackEntryCount() > 1) { pop(); } else { // 放置后台 // moveTaskToBack(false); // 2秒内两次点击返回键退出应用 long nowTime = System.currentTimeMillis(); if (nowTime - mPreTime > 2000) { ArmsUtils.makeText(this, ArmsUtils.getString(this, R.string.double_click_to_exit)); mPreTime = nowTime; } else { ArmsUtils.exitApp(); } } } }
Example #18
Source File: MainActivity.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
@Override public void onBackPressed() { // 模板自动生成的,大概是说如果左侧抽屉栏被打开,按返回键的时候关闭抽屉栏而不是退出程序 DrawerLayout drawer = findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } }
Example #19
Source File: DrawerLayout.java From guideshow with MIT License | 5 votes |
/** * @param gravity the gravity of the child to return. If specified as a * relative value, it will be resolved according to the current * layout direction. * @return the drawer with the specified gravity */ View findDrawerWithGravity(int gravity) { final int absHorizGravity = GravityCompat.getAbsoluteGravity( gravity, ViewCompat.getLayoutDirection(this)) & Gravity.HORIZONTAL_GRAVITY_MASK; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int childAbsGravity = getDrawerViewAbsoluteGravity(child); if ((childAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) { return child; } } return null; }
Example #20
Source File: MainActivity.java From EvilsLive with MIT License | 5 votes |
@Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } }
Example #21
Source File: DemoActivity.java From material-menu with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setup setContentView(R.layout.demo); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); MaterialMenuDrawable materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN); toolbar.setNavigationIcon(materialMenu); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // random state actionBarMenuState = generateState(actionBarMenuState); getMaterialMenu(toolbar).animateIconState(intToState(actionBarMenuState)); } }); // Demo view initialization initViews(); drawerLayout.postDelayed(new Runnable() { @Override public void run() { drawerLayout.openDrawer(GravityCompat.START); } }, 1500); }
Example #22
Source File: ProductActivity.java From RetailStore with Apache License 2.0 | 5 votes |
@Override public void onBackPressed() { // unregisterListener(); if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.END)) { mDrawerLayout.closeDrawer(GravityCompat.END); } else { super.onBackPressed(); } }
Example #23
Source File: ActionBarDrawerToggle.java From guideshow with MIT License | 5 votes |
/** * Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout. * * <p>This should be called from your <code>Activity</code>'s * {@link Activity#onPostCreate(android.os.Bundle) onPostCreate} method to synchronize after * the DrawerLayout's instance state has been restored, and any other time when the state * may have diverged in such a way that the ActionBarDrawerToggle was not notified. * (For example, if you stop forwarding appropriate drawer events for a period of time.)</p> */ public void syncState() { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mSlider.setPosition(1); } else { mSlider.setPosition(0); } if (mDrawerIndicatorEnabled) { setActionBarUpIndicator(mSlider, mDrawerLayout.isDrawerOpen(GravityCompat.START) ? mCloseDrawerContentDescRes : mOpenDrawerContentDescRes); } }
Example #24
Source File: MainActivity.java From openwebnet-android with MIT License | 5 votes |
@Override public void onBackPressed() { if (drawerLayout.isDrawerOpen(GravityCompat.START)) { drawerLayout.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } }
Example #25
Source File: MainActivity.java From diycode with Apache License 2.0 | 5 votes |
@Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } }
Example #26
Source File: MainActivity.java From MaterialMasterDetail with Apache License 2.0 | 5 votes |
@Override public void closeDrawer() { if (drawer != null && drawer.isDrawerOpen(GravityCompat.START)) { drawer.postDelayed(new Runnable() { @Override public void run() { drawer.closeDrawer(GravityCompat.START); } }, 100); } }
Example #27
Source File: OverScrollDemoActivity.java From elasticity with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { final int id = item.getItemId(); item.setChecked(true); switch (id) { case R.id.drawer_item_recyclerview_demo: replaceMainFragment(new RecyclerViewDemoFragment(), R.string.recycler_view_demo_title); break; case R.id.drawer_item_gridview_demo: replaceMainFragment(new GridViewDemoFragment(), R.string.grid_view_demo_title); break; case R.id.drawer_item_listview_demo: replaceMainFragment(new ListViewDemoFragment(), R.string.list_view_demo_title); break; case R.id.drawer_item_recyclerview_staggered_grid_demo: replaceMainFragment(new RecyclerViewStaggeredGridDemoFragment(), R.string.recycler_view_staggered_grid_demo_title); break; case R.id.drawer_item_scrollview_demo: replaceMainFragment(new ScrollViewDemoFragment(), R.string.scroll_view_demo_title); break; case R.id.drawer_item_misc_demo: replaceMainFragment(new MiscViewsDemoFragment(), R.string.misc_views_demo_title); break; case R.id.drawer_item_viewpager_demo: replaceMainFragment(new ViewPagerDemoFragment(),R.string.viewpager_demo_title); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #28
Source File: MainActivity.java From chaoli-forum-for-android-2 with GNU General Public License v3.0 | 5 votes |
@Override public void onBackPressed() { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) mDrawerLayout.closeDrawer(GravityCompat.START); else if (clickedOnce || !needTwoClick) super.onBackPressed(); else { showToast(R.string.click_once_more_to_exit); clickedOnce = true; new Handler().postDelayed(new Runnable() { @Override public void run() { clickedOnce = false; } }, 2500); } }
Example #29
Source File: SubredditView.java From Slide with GNU General Public License v3.0 | 5 votes |
@Override public void onBackPressed() { if (drawerLayout != null && drawerLayout.isDrawerOpen(GravityCompat.START) || drawerLayout != null && drawerLayout.isDrawerOpen(GravityCompat.END)) { drawerLayout.closeDrawers(); } else if (commentPager && pager.getCurrentItem() == 2) { pager.setCurrentItem(pager.getCurrentItem() - 1); } else { super.onBackPressed(); } }
Example #30
Source File: MainActivity.java From Expense-Tracker-App with MIT License | 5 votes |
private void setUpToolbar() { mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mainDrawerLayout.openDrawer(GravityCompat.START); } }); }