@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.ui_connection_menu, menu); super.onCreateOptionsMenu(menu, inflater); MenuItem helpMenu = menu.findItem(R.id.ui_menu_help); helpMenu.setOnMenuItemClickListener(new HelpMenuClickListener()); MenuItem settingMenu = menu.findItem(R.id.ui_menu_setting); settingMenu.setOnMenuItemClickListener(new SettingMenuClickListener()); MenuItem exitMenu = menu.findItem(R.id.ui_menu_exit); exitMenu.setOnMenuItemClickListener(new ExitMenuClickListener()); // refresh button stopButton = (MenuItem) menu.findItem(R.id.ui_menu_stop); if (stopUpdate) stopButton.setIcon(R.drawable.ic_action_start); else stopButton.setIcon(R.drawable.ic_action_stop); stopButton.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { stopUpdate = !stopUpdate; if (stopUpdate) stopButton.setIcon(R.drawable.ic_action_start); else stopButton.setIcon(R.drawable.ic_action_stop); return false; } }); return; }
/** Updates the 'muted' and 'deafened' action bar icons to reflect the audio status. */ private void updateMuteDeafenMenuItems(boolean muted, boolean deafened) { if (mutedButton == null || deafenedButton == null) return; mutedButton.setIcon( !muted ? R.drawable.ic_action_microphone : R.drawable.ic_microphone_muted_strike); deafenedButton.setIcon( !deafened ? R.drawable.ic_action_audio_on : R.drawable.ic_action_audio_muted); }
@Override public boolean onCreateOptionsMenu(Menu menu) { final MainActivity that = this; SearchView searchView = new SearchView(this); searchView.setQueryHint("Search"); searchView.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mBus.post(new SearchEvent(query)); return true; } @Override public boolean onQueryTextChange(String newText) { if ("".equals(newText)) mBus.post(new SearchEvent(true)); return true; // To change body of implemented methods use File | Settings | File // Templates. } }); // Used to put dark icons on light action bar mMenueSearch = menu.add("Search"); mMenueSearch .setIcon(R.drawable.ic_search) .setActionView(searchView) .setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); mMenueRefresh = menu.add("refresh"); mMenueRefresh .setIcon(R.drawable.ic_refresh) .setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { mBus.post(new RefreshEvent()); return true; } }) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); menu.add("Settings") .setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Intent settingsIntent = new Intent(that, SettingsActivity.class); that.startActivity(settingsIntent); return true; } }) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); return true; }
/** Toggles visibility of chart/data UI parts. */ protected void toggleChartData(MenuItem item) { if (View.VISIBLE == chartframe.getVisibility()) { chartframe.setVisibility(View.GONE); dataframe.setVisibility(View.VISIBLE); item.setIcon(this.getResources().getDrawable(R.drawable.icon_graph)); } else { chartframe.setVisibility(View.VISIBLE); dataframe.setVisibility(View.GONE); item.setIcon(this.getResources().getDrawable(R.drawable.icon_data)); } }
public void toggleSatelliteView(MenuItem item) { int mapType = googleMap.getMapType(); if (mapType == MAP_TYPE_NORMAL) { setSatelliteView(true); item.setTitle("Map view"); item.setIcon(R.drawable.location_map); } else { setSatelliteView(false); item.setTitle("Satellite view"); item.setIcon(R.drawable.da_layer_satellite); } }
private void setReloadingState(boolean reloading) { LinearLayout llContent = (LinearLayout) getActivity().findViewById(R.id.llContent); RelativeLayout rlSplashScreen = (RelativeLayout) getActivity().findViewById(R.id.rlSplashScreen); ImageButton btnRefresh = (ImageButton) getActivity().findViewById(R.id.btnRefresh); ProgressBar pbRefreshing = (ProgressBar) getActivity().findViewById(R.id.pbRefreshing); _menuReload.setVisible(!reloading); _menuReloading.setVisible(reloading); if (reloading) { btnRefresh.setVisibility(View.INVISIBLE); llContent.setVisibility(View.INVISIBLE); pbRefreshing.setVisibility(View.VISIBLE); rlSplashScreen.setVisibility(View.VISIBLE); _menuReloading.setActionView(R.layout.menu_progress); } else { pbRefreshing.setVisibility(View.INVISIBLE); rlSplashScreen.setVisibility(View.GONE); btnRefresh.setVisibility(View.VISIBLE); llContent.setVisibility(View.VISIBLE); _menuReload.setIcon(R.drawable.ic_action_refresh); _menuReloading.setActionView(null); View control = null; for (int i = 0; i < llContent.getChildCount(); i++) { control = llContent.getChildAt(i); control.setVisibility(View.VISIBLE); } } }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem refresh = menu.add(0, 1, 1, "Joomla"); refresh.setIcon(R.drawable.ic_action_overflow); refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); refresh.setOnMenuItemClickListener(this); return true; }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem create = menu.add("Create"); create.setIcon(R.drawable.ic_menu_add2); create.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case Menu.FIRST + 1: if (BluetoothUtils.isBluetoothEnabled()) { item.setIcon(R.drawable.btn_connect_indicator_on); } else { item.setIcon(R.drawable.btn_connect_indicator_off); } startActivity(new Intent(ChatActivity.this, BluetoothSettingActivity.class)); break; case Menu.FIRST + 2: mShakeSensor.setIsMultiGame(false); mShakeSensor.unRegisterListener(); singleChat.sendMsg(friendName, Const.Game.REQUESTCMD + Const.Game.DISCONNECTCMD); singleChatRl.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); try { LinkcubeApplication.toyServiceCall.cacheSexPositionMode(0); } catch (RemoteException e) { e.printStackTrace(); } chatPanelView.stopGame(); ChatMsgEntity lastEntity = UserUtils.sendToFriendMsg( getResources().getString(R.string.you_stop_this_game), friendName); mDataArrays.add(lastEntity); mAdapter.notifyDataSetChanged(); singleChatLv.setSelection(singleChatLv.getCount() - 1); UserManager.getInstance().setMultiPlaying(false); UserManager.getInstance().setPlayingTarget(null); isStartGame = false; ischatPopupRlPop = false; supportInvalidateOptionsMenu(); Toast.makeText(this, R.string.toast_close_game, Toast.LENGTH_LONG).show(); break; case android.R.id.home: // chatForFriendMap.put(friendName, countDowmList); this.finish(); break; default: break; } return false; }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem saveItem = menu.add(0, 10001, 0, "确定"); saveItem.setIcon(android.R.drawable.ic_menu_save); saveItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_IF_ROOM); return true; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub MenuItem changeBtn = menu.add(5, 6, 7, "帐号管理"); changeBtn .setIcon(R.drawable.home_action_icon_person) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return super.onCreateOptionsMenu(menu); }
@Override public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.weibo, menu); loveItem = menu.findItem(R.id.menu_favorite); if (status.isFavorited()) { loveItem.setIcon(R.drawable.rating_favorite_r); } loveItem.setVisible(false); return super.onCreateOptionsMenu(menu); }
@Override public void onPrepareOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean isDrawerOpen = ((BaseNavDrawerActivity) getActivity()).isDrawerOpen(); MenuItem filter = menu.findItem(R.id.menu_action_shows_filter); filter.setVisible(!isDrawerOpen); filter.setIcon( mIsFilterFavorites || mIsFilterUnwatched || mIsFilterUpcoming || mIsFilterHidden ? R.drawable.ic_action_filter_selected : R.drawable.ic_action_filter); }
// オプションメニューの追加 @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); /* //ツイッターログイン MenuItem tw_login = menu.add(0, tw_login_menu_id, Menu.NONE, getString(R.string.tw_setting)); tw_login.setIcon(android.R.drawable.ic_menu_preferences); tw_login.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); */ // IPPログイン MenuItem ipp_login = menu.add(0, ipp_login_menu_id, Menu.NONE, getString(R.string.ipp_login)); ipp_login.setIcon(android.R.drawable.ic_menu_preferences); ipp_login.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); // リロード MenuItem reload = menu.add(0, reload_menu_id, Menu.NONE, getString(R.string.comment_reload)); reload.setIcon(android.R.drawable.ic_menu_preferences); reload.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); // 追加読み込み MenuItem addget = menu.add(0, addget_menu_id, Menu.NONE, getString(R.string.additionalGet)); addget.setIcon(android.R.drawable.ic_menu_preferences); addget.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); // ストレス変更 /* MenuItem stress_change = menu.add(0, stress_change_menu_id, Menu.NONE, getString(R.string.stress_change)); stress_change.setIcon(android.R.drawable.ic_menu_preferences); stress_change.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); */ // 近くに限る nearMenu = menu.add(0, near_menu_id, Menu.NONE, getString(R.string.near)); nearMenu.setIcon(android.R.drawable.ic_menu_compass); // near.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); アクションバー上にアイコンで表示 nearMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); // ドロップダウンのメニューに表示 }
@Override public boolean onCreateOptionsMenu(Menu menu) { mainMenu = menu; subMenu1 = menu.addSubMenu("Options"); MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.main, subMenu1); MenuItem subMenu1Item = subMenu1.getItem(); subMenu1Item.setIcon(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return super.onCreateOptionsMenu(menu); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // use the App Icon for Navigation getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Add actions to the action bar refreshItem = menu.add(Menu.NONE, ID_AB_REFRESH, Menu.NONE, R.string.r_ab_refresh); refreshItem .setIcon(R.drawable.ic_action_refresh) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); refreshItem.setActionView(R.layout.actionbar_indeterminate_progress); // settings menu.add(Menu.NONE, ID_AB_SETTINGS, Menu.NONE, R.string.ab_settings) .setIcon(R.drawable.ic_action_settings) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); return super.onCreateOptionsMenu(menu); }
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.add("Search") .setIcon(R.drawable.ic_action_search) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); SubMenu subMenu1 = menu.addSubMenu("Action Item"); subMenu1.add("My Topics"); subMenu1.add("Review"); subMenu1.add("Config"); MenuItem subMenu1Item = subMenu1.getItem(); subMenu1Item.setIcon(R.drawable.ic_action_options); subMenu1Item.setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return super.onCreateOptionsMenu(menu); }
@Override public boolean onPrepareOptionsMenu(Menu menu) { mFavoriteAccountMenu = menu.findItem(R.id.menu_favorite_account); MenuItem favoriteAccountMenuItem = menu.findItem(R.id.menu_favorite_account); if (favoriteAccountMenuItem == null) // when the activity is used to edit a transaction return super.onPrepareOptionsMenu(menu); AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(this); boolean isFavoriteAccount = accountsDbAdapter.isFavoriteAccount(mAccountId); accountsDbAdapter.close(); int favoriteIcon = isFavoriteAccount ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off; favoriteAccountMenuItem.setIcon(favoriteIcon); return super.onPrepareOptionsMenu(menu); }
// Options @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); int actionRoom = getResources().getBoolean(R.bool.menu_in_bar) ? MenuItem.SHOW_AS_ACTION_IF_ROOM : MenuItem.SHOW_AS_ACTION_NEVER; MenuItem addContactMenu = menu.add(R.string.menu_add_to_contacts); addContactMenu.setIcon(R.drawable.ic_add_contact_holo_dark).setShowAsAction(actionRoom); addContactMenu.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Intent it = ContactsWrapper.getInstance().getAddContactIntent(null, remoteFrom); startActivity(it); return true; } }); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.add(Menu.NONE, R.id.action_bar_invite, 0, "Search") .setIcon(R.drawable.ic_menu_invite) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); MenuItem refreshItem = menu.add(Menu.NONE, R.id.action_bar_refresh, 1, "Refresh"); refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); if (refresh) refreshItem.setActionView(flProgress); else refreshItem.setIcon(R.drawable.ic_menu_refresh); if (username != null && u != null && !username.equals(u.getUsername())) { menu.add(Menu.NONE, R.id.action_bar_delete, Menu.NONE, "Delete") .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } menu.add(Menu.NONE, R.id.action_bar_about, Menu.NONE, "About") .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); }
/* (non-Javadoc) * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_mute_button: if (!mService.isMuted()) { // Switching to muted updateMuteDeafenMenuItems(true, mService.isDeafened()); } else { // Switching to unmuted updateMuteDeafenMenuItems(false, false); } mService.setMuted(!mService.isMuted()); return true; case R.id.menu_deafen_button: updateMuteDeafenMenuItems(!mService.isDeafened(), !mService.isDeafened()); mService.setDeafened(!mService.isDeafened()); return true; case R.id.menu_fullscreen_chat: rightSplit.setVisibility( rightSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); leftSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen); return true; case R.id.menu_fullscreen_channel: leftSplit.setVisibility( leftSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); rightSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen); return true; case R.id.menu_fullscreen: if (leftSplit.getVisibility() == View.GONE || rightSplit.getVisibility() == View.GONE) { leftSplit.setVisibility(View.VISIBLE); rightSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_fullscreen); } return true; case R.id.menu_view_favorites_button: showFavouritesDialog(); return true; case R.id.menu_user_register: new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mService.registerSelf(); return null; } protected void onPostExecute(Void result) { Toast.makeText(ChannelActivity.this, R.string.registerSelfSuccess, Toast.LENGTH_SHORT) .show(); }; }.execute(); return true; case R.id.menu_user_comment: // TODO Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show(); return true; case R.id.menu_user_information: // TODO Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show(); return true; case R.id.menu_clear_chat: mService.clearChat(); chatFragment.clear(); return true; case R.id.menu_search: return false; case R.id.menu_access_tokens_button: TokenDialogFragment dialogFragment = TokenDialogFragment.newInstance(); dialogFragment.setShowsDialog(mViewPager == null); dialogFragment.show(getSupportFragmentManager(), "tokens"); return true; case R.id.menu_bluetooth: item.setChecked(!item.isChecked()); if (item.isChecked()) mService.enableBluetooth(); else mService.disableBluetooth(); break; case R.id.menu_amplifier: AmplifierDialogFragment amplifierDialogFragment = AmplifierDialogFragment.newInstance(); amplifierDialogFragment.show(getSupportFragmentManager(), "amplifier"); return true; case R.id.menu_preferences: Intent intent = new Intent(this, Preferences.class); startActivity(intent); return true; case R.id.menu_disconnect_item: disconnect(); return true; } return super.onOptionsItemSelected(item); }
/** * Adding collapsible search menu item to the menu. * * @param menu * @param isLightTheme - true if use light them for ActionBar, else false * @return */ public static MenuItem addSearchMenuItem( Menu menu, boolean isLightTheme, final TextWatcher textWatcher) { final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go); menuItem .setIcon( isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark) .setActionView( isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark) .setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); final View searchView = menuItem.getActionView(); final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text); menuItem.setOnActionExpandListener( new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { editText.addTextChangedListener(textWatcher); editText.requestFocus(); showKeyboard(editText); return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { editText.setText(null); editText.removeTextChangedListener(textWatcher); // editText.clearFocus(); hideKeyboard(editText); return true; } }); final View searchPlate = searchView.findViewById(R.id.search_plate); editText.setOnFocusChangeListener( new OnFocusChangeListener() { @Override public void onFocusChange(View v, final boolean hasFocus) { searchView.post( new Runnable() { public void run() { searchPlate .getBackground() .setState( hasFocus ? new int[] {android.R.attr.state_focused} : new int[] {android.R.attr.state_empty}); searchView.invalidate(); } }); } }); final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn); closeBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(editText.getText())) { editText.setText(null); } else { menuItem.collapseActionView(); } } }); return menuItem; }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { OsmandApplication app = (OsmandApplication) getActivity().getApplication(); boolean light = app.getSettings().isLightActionBar(); com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.get_directions) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(NAVIGATE_TO); return true; } }); TargetPointsHelper targets = app.getTargetPointsHelper(); if (targets.getPointToNavigate() != null) { menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark); } else { menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark); } menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(ADD_WAYPOINT); return true; } }); // } menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(SHOW_ON_MAP); return true; } }); menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(ADD_TO_FAVORITE); return true; } }); }
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case android.R.id.home: onBackPressed(); return true; case R.id.menu_back: position = viewpager.getCurrentItem(); position--; if (position < 0) { position = 0; } viewpager.setCurrentItem(position); return true; case R.id.menu_next: position = viewpager.getCurrentItem(); position++; if (position == TOTAL_IMAGE) { position = TOTAL_IMAGE; } viewpager.setCurrentItem(position); return true; case R.id.menu_play: if (Play_Flag) { handler.removeCallbacks(Update); menuItem.setIcon(getResources().getDrawable(R.drawable.play)); Play_Flag = false; ShowMenu(); } else { /* * when Play_Flag false then Play but when image is last not * start auto play now hide all menu when auto play start */ if (viewpager.getCurrentItem() == TOTAL_IMAGE) { Toast.makeText( getApplicationContext(), "Currently Last Image!! Not Start Auto Play", Toast.LENGTH_SHORT) .show(); } else { AutoPlay(); menuItem.setIcon(getResources().getDrawable(R.drawable.stop)); Play_Flag = true; HideMenu(); } } return true; case R.id.menu_fav: position = viewpager.getCurrentItem(); Image_Url = mAllImages[position]; List<Pojo> pojolist = db.getFavRow(Image_Url); if (pojolist.size() == 0) { AddtoFav(position); // if size is zero i.e means that record not // in database show add to favorite } else { if (pojolist.get(0).getImageurl().equals(Image_Url)) { RemoveFav(position); } } return true; case R.id.menu_overflow: // just override click return true; case R.id.menu_make_meme: String ImgURL = Constant.SERVER_IMAGE_UPFOLDER_CATEGORY + mAllImageCatName[position] + "/" + mAllImages[viewpager.getCurrentItem()]; Intent i = new Intent(this, MemeActivity.class); i.putExtra("URL", ImgURL); startActivity(i); return true; case R.id.menu_share: position = viewpager.getCurrentItem(); (new ShareTask(SlideImageActivity.this)) .execute( Constant.SERVER_IMAGE_UPFOLDER_CATEGORY + mAllImageCatName[position] + "/" + mAllImages[position]); return true; case R.id.menu_save: position = viewpager.getCurrentItem(); (new SaveTask(SlideImageActivity.this, false)) .execute( Constant.SERVER_IMAGE_UPFOLDER_CATEGORY + mAllImageCatName[position] + "/" + mAllImages[position]); return true; case R.id.menu_setaswallaper: position = viewpager.getCurrentItem(); Intent intwall = new Intent(getApplicationContext(), SetAsWallpaperActivity.class); intwall.putExtra("WALLPAPER_IMAGE_URL", mAllImages); intwall.putExtra("WALLPAPER_IMAGE_CATEGORY", mAllImageCatName); intwall.putExtra("POSITION_ID", position); startActivity(intwall); return true; case R.id.menu_editbyapp: position = viewpager.getCurrentItem(); (new SaveTask(SlideImageActivity.this, true)) .execute( Constant.SERVER_IMAGE_UPFOLDER_CATEGORY + mAllImageCatName[position] + "/" + mAllImages[position]); return true; case R.id.menu_zoom: position = viewpager.getCurrentItem(); Intent intzoom = new Intent(getApplicationContext(), PinchZoom.class); intzoom.putExtra("ZOOM_IMAGE_URL", mAllImages); intzoom.putExtra("ZOOM_IMAGE_CATEGORY", mAllImageCatName); intzoom.putExtra("POSITION_ID", position); startActivity(intzoom); return true; default: return super.onOptionsItemSelected(menuItem); } }