@Override public boolean onOptionsItemSelected(MenuItem item) { if (drawerToggle != null && drawerToggle.onOptionsItemSelected(item)) return true; if (android.R.id.home == item.getItemId()) { if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) mDrawerLayout.closeDrawers(); else mDrawerLayout.openDrawer(GravityCompat.START); return true; } // 关于 // if (item.getItemId() == R.id.about) // AboutWebFragment.launchAbout(this); // 意见反馈 // else if (item.getItemId() == R.id.feedback) // PublishActivity.publishFeedback(this); // 退出 if (item.getItemId() == R.id.exitapp) { finish(); MobclickAgent.onEvent(this, "exitapp"); } // 新微博 else if (item.getItemId() == R.id.publish) PublishActivity.publishStatus(this, null); // 开始离线 else if (item.getItemId() == R.id.toggle_offline) { OfflineUtils.toggleOffline(this); MobclickAgent.onEvent(this, "toggle_offline"); } // 停止离线 else if (item.getItemId() == R.id.stop_offline) { OfflineService.stopOffline(); MobclickAgent.onEvent(this, "stop_offline"); } // 通知设置 else if (item.getItemId() == R.id.notification_settings) NotificationSettingsFragment.launch(this); // 搜索 else if (item.getItemId() == R.id.search) { new IAction( MainActivity.this, new WebLoginAction(MainActivity.this, BizFragment.createBizFragment(this))) { @Override public void doAction() { SearchFragment.launch(MainActivity.this, ""); MobclickAgent.onEvent(MainActivity.this, "toggle_search"); } }.run(); } return super.onOptionsItemSelected(item); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ui_main); CacheClearFragment.clearCompress(); BizFragment bizFragment = BizFragment.createBizFragment(this); bizFragment.createFabAnimator(fabBtn); fabBtn.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // 触发一次刷新 ((AsToolbar) getToolbar()).performDoublcClick(); appBarLayout.setExpanded(true); return true; } }); bizFragment.getFabAnimator().setDuration(200); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); setupDrawer(savedInstanceState); setupMenu(savedInstanceState); setupFab(savedInstanceState); setupAppBarLayout(savedInstanceState); if (savedInstanceState != null) { toolbarTitle = savedInstanceState.getString("toolbarTitle"); if (!TextUtils.isEmpty(toolbarTitle)) getSupportActionBar().setTitle(toolbarTitle); } mInstance = this; OtherItemFragment.checkPhotoPermission(this, true); }
/** * 选择了侧边栏,切换侧边栏菜单 * * @param item * @return */ @Override public void onMenuClicked(MenuFragment.NavMenuItem item, boolean closeDrawer) { invalidateOptionsMenu(); ABaseFragment fragment = null; // 切换ContentFragment,或者跳转到新的界面 switch (item.id) { // 首页 case MenuFragment.MENU_MAIN: fabGroupsFragment.triggerLastPosition(); break; // 通知 case MenuFragment.MENU_NOTIFICATION: fragment = NotificationPagerFragment.newInstance(newIntentNotificationIndex); newIntentNotificationIndex = -1; break; // 提及 case MenuFragment.MENU_MENTION: fragment = MentionPagerFragment.newInstance(); break; // 评论 case MenuFragment.MENU_CMT: fragment = CommentPagerFragment.newInstance(); break; // 私信 case MenuFragment.MENU_MD: new IAction( MainActivity.this, new WebLoginAction(MainActivity.this, BizFragment.createBizFragment(this))) { @Override public void doAction() { WeiboClientActivity.launchDM(MainActivity.this); } }.run(); MobclickAgent.onEvent(MainActivity.this, "md"); break; // 热门微博 case MenuFragment.MENU_HOT_STATUS: WeiboClientActivity.launchHotStatuses(this); MobclickAgent.onEvent(MainActivity.this, "hot_status"); break; // 草稿箱 case MenuFragment.MENU_DRAT: fragment = DraftFragment.newInstance(); break; // 设置 case MenuFragment.MENU_SETTINGS: SettingsPagerFragment.launch(this); break; // 轻松一刻 case MenuFragment.MENU_JOKE: fragment = JokesPagerFragment.newInstance(); MobclickAgent.onEvent(this, "menu_joke"); break; // 精美壁纸 case MenuFragment.MENU_WALLPAPER: fragment = WallpaperFragment.newInstance(); MobclickAgent.onEvent(this, "menu_wallpaper"); break; } if (fragment != null) { setFragemnt(fragment, getString(item.toolbarRes)); } // 隐藏Fab按钮 if (item.id == 1) { fabBtn.setVisibility(View.VISIBLE); // 显示Fab BizFragment.createBizFragment(this).getFabAnimator().show(); } else { fabBtn.setVisibility(View.GONE); } // 关闭侧边栏 if (closeDrawer) { mHandler.postDelayed( new Runnable() { @Override public void run() { closeDrawer(); } }, 300); } }