List of usage examples for android.widget PopupMenu setOnMenuItemClickListener
public void setOnMenuItemClickListener(OnMenuItemClickListener listener)
From source file:com.example.search.car.pools.welcome.java
@Override public void onClick(View v) { // TODO Auto-generated method stub Fragment fragment = null;//from w ww . ja v a 2s . c om if ((v.equals(l_1) || (v.equals(sp_city)))) { String[] city = { "Delhi/NCR", "Bengaluru", "Kolkata", "Mumbai", "Pune", "Ahmedabad" }; dialog("City", city, sp_city); } else if ((v.equals(l_2) || (v.equals(sp_category)))) { String[] category = { "All", "Carpool", "Cab", "Rideshare" }; dialog("Category", category, sp_category); } else if ((v.equals(l_3) || (v.equals(sp_search_for)))) { String[] search_for = { "Seeker", "Provider", "Both" }; dialog(" Search For", search_for, sp_search_for); } else if (v.equals(close)) { promptsView.dismiss(); } else if (v.equals(rlCities)) { layout = "Cities"; fragment = new Cities(); frag_tag = "Cities"; set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Cities"); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city1); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#00ca98")); l_cities.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlDashboard)) { if (task.getString("user_id", null) != null) { // layout = "Dashboard"; // fragment = new dashboard(); // frag_tag = "Dashboard"; // // getActionBar().setTitle("My Profile"); // set_fragment(fragment); // mDrawerLayout.closeDrawer(mDrawerList); // svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard1); // iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); // rlDashboard.setBackgroundColor(Color.parseColor("#00ca98")); // l_dashboard.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); // // svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); // iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); // rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); // l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); // svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search); // iv_search.setImageDrawable(svg_search.createPictureDrawable()); // rlSearch.setBackgroundColor(Color.parseColor("#2C3E50")); // l_search.setBackground(getResources().getDrawable(R.drawable.search_blue)); Intent i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "1"); startActivity(i); mDrawerLayout.closeDrawer(mDrawerList); } else { Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); mDrawerLayout.closeDrawer(mDrawerList); } } else if (v.equals(rlSearch)) { layout = "Search"; frag_tag = "Search"; fragment = new Search(); set_fragment(fragment); mDrawerLayout.closeDrawer(mDrawerList); // getActionBar().setTitle("Search"); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard); iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable()); rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50")); l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue)); svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city); iv_cities.setImageDrawable(svg_cities.createPictureDrawable()); rlCities.setBackgroundColor(Color.parseColor("#2C3E50")); l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue)); } else if (v.equals(rlProfile_login) || v.equals(profile_login)) { if (task.getString("user_id", null) == null) { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } // else if (v.equals(rlEditProfile)) { // if (task.getString("user_id", null) != null) { // Intent i = new Intent(welcome.this, dashboard_main.class); // i.putExtra("edit", "3"); // startActivity(i); // } else { // Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show(); // } // mDrawerLayout.closeDrawer(mDrawerList); // } else if (v.equals(login) || v.equals(rlLogin)) { if (task.getString("user_id", null) != null && login.getText().toString().contentEquals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { Intent i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } mDrawerLayout.closeDrawer(mDrawerList); } else if (v.equals(b_search)) { if (sp_city.getText().toString().toUpperCase().equals("SELECT CITY")) { Toast.makeText(welcome.this, "First Select the City", Toast.LENGTH_LONG).show(); } else { Intent i = new Intent(welcome.this, search_result.class); i.putExtra("city", sp_city.getText().toString()); i.putExtra("category", sp_category.getText().toString()); i.putExtra("search_for", sp_search_for.getText().toString()); i.putExtra("from", et_from.getText().toString()); i.putExtra("to", et_to.getText().toString()); i.putExtra("frag_id", 1); i.putExtra("company_id", 0); startActivity(i); promptsView.dismiss(); } } else if (v.equals(l_nav_search) || v.equals(ib_search)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_nav_search.setBackground(a); a.start(); showSearchDialog(); } else if (v.equals(l_handle) || v.equals(ib_handle)) { final int DELAY = 200; // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_handle.setBackground(a); a.start(); if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } else if (v.equals(l_menu) || v.equals(ib_menu)) { final int DELAY = 200; // for light background // ColorDrawable f = new // ColorDrawable(Color.parseColor("#0087ca")); // ColorDrawable f1 = new // ColorDrawable(Color.parseColor("#3398ca")); AnimationDrawable a = new AnimationDrawable(); a.addFrame(d1, DELAY); a.addFrame(d2, DELAY); a.setOneShot(true); l_menu.setBackground(a); a.start(); final PopupMenu popup = new PopupMenu(welcome.this, v); popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); bedMenuItem = popup.getMenu().findItem(R.id.menu_login); final SharedPreferences task = getSharedPreferences("user", MODE_PRIVATE); popup.getMenu().findItem(R.id.menu_add_new_list).setVisible(!(task.getString("user_id", null) == null)); popup.getMenu().findItem(R.id.menu_dashboard).setVisible(!(task.getString("user_id", null) == null)); if (task.getString("user_id", null) != null) { bedMenuItem.setTitle("Logout"); login.setText("Logout"); iv_login.setImageDrawable(svg_logout.createPictureDrawable()); rlProfile.setVisibility(View.VISIBLE); rlProfile_login.setVisibility(View.GONE); rlDashboard.setVisibility(View.VISIBLE); // rlEditProfile.setVisibility(View.VISIBLE); set_data(); } else { bedMenuItem.setTitle("Login/Register"); login.setText("Login"); iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); } if (task.getString("user_id", null) != null) { popup.getMenu().findItem(R.id.menu_login).setTitle("Logout"); } else { popup.getMenu().findItem(R.id.menu_login).setTitle("Login/Register"); } popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // TODO Auto-generated method stub int id = item.getItemId(); Intent i; switch (id) { case R.id.menu_add_new_list: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, create_activity.class); startActivity(i); } else { Toast.makeText(welcome.this, "Login first", Toast.LENGTH_SHORT).show(); } return true; case R.id.menu_dashboard: if (task.getString("user_id", null) != null) { i = new Intent(welcome.this, dashboard_main.class); i.putExtra("edit", "12344"); startActivity(i); } else { Toast.makeText(welcome.this, "Please Login first", Toast.LENGTH_LONG).show(); } return true; case R.id.menu_login: if (bedMenuItem.getTitle().equals("Logout")) { SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit(); editor.clear(); editor.commit(); // bedMenuItem.setTitle("Login/Register"); login.setText("Login"); rlDashboard.setVisibility(View.GONE); // rlEditProfile.setVisibility(View.GONE); if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) { // highlight search menu on slider during on // resume // change fragment to search FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, new Search()); fragmentTransaction.commit(); SVG svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1); iv_search.setImageDrawable(svg_search.createPictureDrawable()); rlSearch.setBackgroundColor(Color.parseColor("#00ca98")); l_search.setBackground( getResources().getDrawable(R.drawable.white_circle_side_menu)); } iv_login.setImageDrawable(svg_login.createPictureDrawable()); rlProfile.setVisibility(View.GONE); rlProfile_login.setVisibility(View.VISIBLE); if (frag_id == 6) { Intent i_user = new Intent(getBaseContext(), user_login.class); i_user.putExtra("frag_id", frag_id); startActivity(i_user); } } else { i = new Intent(getBaseContext(), user_login.class); i.putExtra("frag_id", frag_id); startActivity(i); } return true; } return false; } }); popup.show(); // } else { // openOptionsMenu(); // } } }
From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java
public void onLongClickAppsTab(View v) { final PopupMenu popupMenu = new PopupMenu(this, v); final Menu menu = popupMenu.getMenu(); popupMenu.inflate(R.menu.apps_tab);/*w ww . ja v a 2 s . co m*/ AppsCustomizePagedView.SortMode sortMode = mAppsCustomizeContent.getSortMode(); AppsCustomizePagedView.SortModeFirst sortModeFirst = mAppsCustomizeContent.getSortModeFirst(); if (sortMode == AppsCustomizePagedView.SortMode.Title) { menu.findItem(R.id.apps_sort_title).setChecked(true); } else if (sortMode == AppsCustomizePagedView.SortMode.InstallDate) { menu.findItem(R.id.apps_sort_install_date).setChecked(true); } if (sortModeFirst == AppsCustomizePagedView.SortModeFirst.None) { menu.findItem(R.id.apps_sort_none_first).setChecked(true); } else if (sortModeFirst == AppsCustomizePagedView.SortModeFirst.Google) { menu.findItem(R.id.apps_sort_google_first).setChecked(true); } else if (sortModeFirst == AppsCustomizePagedView.SortModeFirst.StockApps) { menu.findItem(R.id.apps_sort_stock_apps_first).setChecked(true); } else if (sortModeFirst == AppsCustomizePagedView.SortModeFirst.DownloadedApps) { menu.findItem(R.id.apps_sort_downloaded_apps_first).setChecked(true); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.apps_sort_title: mAppsCustomizeContent.setSortMode(AppsCustomizePagedView.SortMode.Title); break; case R.id.apps_sort_install_date: mAppsCustomizeContent.setSortMode(AppsCustomizePagedView.SortMode.InstallDate); break; case R.id.apps_sort_none_first: mAppsCustomizeContent.setSortModeFirst(AppsCustomizePagedView.SortModeFirst.None); break; case R.id.apps_sort_google_first: mAppsCustomizeContent.setSortModeFirst(AppsCustomizePagedView.SortModeFirst.Google); break; case R.id.apps_sort_stock_apps_first: mAppsCustomizeContent.setSortModeFirst(AppsCustomizePagedView.SortModeFirst.StockApps); break; case R.id.apps_sort_downloaded_apps_first: mAppsCustomizeContent.setSortModeFirst(AppsCustomizePagedView.SortModeFirst.DownloadedApps); break; } return true; } }); popupMenu.show(); }
From source file:im.vector.adapters.VectorMessagesAdapter.java
/** * The user taps on the action icon.//from w w w. jav a 2 s.c om * @param event the selected event. * @param textMsg the event text * @param anchorView the popup anchor. */ @SuppressLint("NewApi") private void onMessageClick(final Event event, final String textMsg, final View anchorView) { final PopupMenu popup = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) ? new PopupMenu(mContext, anchorView, Gravity.END) : new PopupMenu(mContext, anchorView); popup.getMenuInflater().inflate(R.menu.vector_room_message_settings, popup.getMenu()); // force to display the icons try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "onMessageClick : force to display the icons failed " + e.getLocalizedMessage()); } Menu menu = popup.getMenu(); // hide entries for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); } menu.findItem(R.id.ic_action_view_source).setVisible(true); menu.findItem(R.id.ic_action_vector_permalink).setVisible(true); if (!TextUtils.isEmpty(textMsg)) { menu.findItem(R.id.ic_action_vector_copy).setVisible(true); menu.findItem(R.id.ic_action_vector_quote).setVisible(true); } if (event.isUploadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_upload).setVisible(true); } if (event.isDownloadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_download).setVisible(true); } if (event.canBeResent()) { menu.findItem(R.id.ic_action_vector_resend_message).setVisible(true); if (event.isUndeliverable()) { menu.findItem(R.id.ic_action_vector_redact_message).setVisible(true); } } else if (event.mSentState == Event.SentState.SENT) { // test if the event can be redacted boolean canBeRedacted = !mIsPreviewMode; if (canBeRedacted) { // oneself message -> can redact it if (TextUtils.equals(event.sender, mSession.getMyUserId())) { canBeRedacted = true; } else { // need the mininum power level to redact an event Room room = mSession.getDataHandler().getRoom(event.roomId); if ((null != room) && (null != room.getLiveState().getPowerLevels())) { PowerLevels powerLevels = room.getLiveState().getPowerLevels(); canBeRedacted = powerLevels.getUserPowerLevel(mSession.getMyUserId()) >= powerLevels.redact; } } } menu.findItem(R.id.ic_action_vector_redact_message).setVisible(canBeRedacted); if (Event.EVENT_TYPE_MESSAGE.equals(event.type)) { Message message = JsonUtils.toMessage(event.getContentAsJsonObject()); // share / forward the message menu.findItem(R.id.ic_action_vector_share).setVisible(true); menu.findItem(R.id.ic_action_vector_forward).setVisible(true); // save the media in the downloads directory if (Message.MSGTYPE_IMAGE.equals(message.msgtype) || Message.MSGTYPE_VIDEO.equals(message.msgtype) || Message.MSGTYPE_FILE.equals(message.msgtype)) { menu.findItem(R.id.ic_action_vector_save).setVisible(true); } // offer to report a message content menu.findItem(R.id.ic_action_vector_report) .setVisible(!mIsPreviewMode && !TextUtils.equals(event.sender, mSession.getMyUserId())); } } // display the menu popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { // warn the listener if (null != mVectorMessagesAdapterEventsListener) { mVectorMessagesAdapterEventsListener.onEventAction(event, textMsg, item.getItemId()); } // disable the selection mHighlightedEventId = null; notifyDataSetChanged(); return true; } }); popup.show(); }
From source file:im.neon.adapters.VectorMessagesAdapter.java
/** * The user taps on the action icon.//from ww w . j a va 2 s . c o m * @param event the selected event. * @param textMsg the event text * @param anchorView the popup anchor. */ @SuppressLint("NewApi") private void onMessageClick(final Event event, final String textMsg, final View anchorView) { final PopupMenu popup = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) ? new PopupMenu(mContext, anchorView, Gravity.END) : new PopupMenu(mContext, anchorView); popup.getMenuInflater().inflate(R.menu.vector_room_message_settings, popup.getMenu()); // force to display the icons try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "onMessageClick : force to display the icons failed " + e.getLocalizedMessage()); } Menu menu = popup.getMenu(); // hide entries for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); } menu.findItem(R.id.ic_action_view_source).setVisible(true); menu.findItem(R.id.ic_action_vector_permalink).setVisible(true); if (!TextUtils.isEmpty(textMsg)) { menu.findItem(R.id.ic_action_vector_copy).setVisible(true); menu.findItem(R.id.ic_action_vector_quote).setVisible(true); } if (event.isUploadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_upload).setVisible(true); } if (event.isDownloadingMedias(mMediasCache)) { menu.findItem(R.id.ic_action_vector_cancel_download).setVisible(true); } if (event.canBeResent()) { menu.findItem(R.id.ic_action_vector_resend_message).setVisible(true); if (event.isUndeliverable() || event.isUnkownDevice()) { menu.findItem(R.id.ic_action_vector_redact_message).setVisible(true); } } else if (event.mSentState == Event.SentState.SENT) { // test if the event can be redacted boolean canBeRedacted = !mIsPreviewMode && !TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE_ENCRYPTION); if (canBeRedacted) { // oneself message -> can redact it if (TextUtils.equals(event.sender, mSession.getMyUserId())) { canBeRedacted = true; } else { // need the mininum power level to redact an event Room room = mSession.getDataHandler().getRoom(event.roomId); if ((null != room) && (null != room.getLiveState().getPowerLevels())) { PowerLevels powerLevels = room.getLiveState().getPowerLevels(); canBeRedacted = powerLevels.getUserPowerLevel(mSession.getMyUserId()) >= powerLevels.redact; } } } menu.findItem(R.id.ic_action_vector_redact_message).setVisible(canBeRedacted); if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) { Message message = JsonUtils.toMessage(event.getContentAsJsonObject()); // share / forward the message menu.findItem(R.id.ic_action_vector_share).setVisible(true); menu.findItem(R.id.ic_action_vector_forward).setVisible(true); // save the media in the downloads directory if (Message.MSGTYPE_IMAGE.equals(message.msgtype) || Message.MSGTYPE_VIDEO.equals(message.msgtype) || Message.MSGTYPE_FILE.equals(message.msgtype)) { menu.findItem(R.id.ic_action_vector_save).setVisible(true); } // offer to report a message content menu.findItem(R.id.ic_action_vector_report) .setVisible(!mIsPreviewMode && !TextUtils.equals(event.sender, mSession.getMyUserId())); } } // e2e menu.findItem(R.id.ic_action_device_verification).setVisible(mE2eIconByEventId.containsKey(event.eventId)); // display the menu popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { // warn the listener if (null != mVectorMessagesAdapterEventsListener) { mVectorMessagesAdapterEventsListener.onEventAction(event, textMsg, item.getItemId()); } // disable the selection mHighlightedEventId = null; notifyDataSetChanged(); return true; } }); // fix an issue reported by GA try { popup.show(); } catch (Exception e) { Log.e(LOG_TAG, " popup.show failed " + e.getMessage()); } }