List of usage examples for android.widget PopupWindow dismiss
public void dismiss()
From source file:ren.qinc.markdowneditors.base.BaseActivity.java
/** * ???ActionMode??/*from ww w. j av a2 s .co m*/ * * @param activity * @param mode */ private void fixActionModeCallback(AppCompatActivity activity, ActionMode mode) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; if (!(mode instanceof StandaloneActionMode)) return; try { final Field mCallbackField = mode.getClass().getDeclaredField("mCallback"); mCallbackField.setAccessible(true); final Object mCallback = mCallbackField.get(mode); final Field mWrappedField = mCallback.getClass().getDeclaredField("mWrapped"); mWrappedField.setAccessible(true); final ActionMode.Callback mWrapped = (ActionMode.Callback) mWrappedField.get(mCallback); final Field mDelegateField = AppCompatActivity.class.getDeclaredField("mDelegate"); mDelegateField.setAccessible(true); final Object mDelegate = mDelegateField.get(activity); mCallbackField.set(mode, new ActionMode.Callback() { @Override public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onCreateActionMode(mode, menu); } @Override public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onPrepareActionMode(mode, menu); } @Override public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) { return mWrapped.onActionItemClicked(mode, item); } @Override public void onDestroyActionMode(final android.support.v7.view.ActionMode mode) { Class mDelegateClass = mDelegate.getClass().getSuperclass(); Window mWindow = null; PopupWindow mActionModePopup = null; Runnable mShowActionModePopup = null; ActionBarContextView mActionModeView = null; AppCompatCallback mAppCompatCallback = null; ViewPropertyAnimatorCompat mFadeAnim = null; android.support.v7.view.ActionMode mActionMode = null; Field mFadeAnimField = null; Field mActionModeField = null; while (mDelegateClass != null) { try { if (TextUtils.equals("AppCompatDelegateImplV7", mDelegateClass.getSimpleName())) { Field mActionModePopupField = mDelegateClass.getDeclaredField("mActionModePopup"); mActionModePopupField.setAccessible(true); mActionModePopup = (PopupWindow) mActionModePopupField.get(mDelegate); Field mShowActionModePopupField = mDelegateClass .getDeclaredField("mShowActionModePopup"); mShowActionModePopupField.setAccessible(true); mShowActionModePopup = (Runnable) mShowActionModePopupField.get(mDelegate); Field mActionModeViewField = mDelegateClass.getDeclaredField("mActionModeView"); mActionModeViewField.setAccessible(true); mActionModeView = (ActionBarContextView) mActionModeViewField.get(mDelegate); mFadeAnimField = mDelegateClass.getDeclaredField("mFadeAnim"); mFadeAnimField.setAccessible(true); mFadeAnim = (ViewPropertyAnimatorCompat) mFadeAnimField.get(mDelegate); mActionModeField = mDelegateClass.getDeclaredField("mActionMode"); mActionModeField.setAccessible(true); mActionMode = (android.support.v7.view.ActionMode) mActionModeField.get(mDelegate); } else if (TextUtils.equals("AppCompatDelegateImplBase", mDelegateClass.getSimpleName())) { Field mAppCompatCallbackField = mDelegateClass .getDeclaredField("mAppCompatCallback"); mAppCompatCallbackField.setAccessible(true); mAppCompatCallback = (AppCompatCallback) mAppCompatCallbackField.get(mDelegate); Field mWindowField = mDelegateClass.getDeclaredField("mWindow"); mWindowField.setAccessible(true); mWindow = (Window) mWindowField.get(mDelegate); } mDelegateClass = mDelegateClass.getSuperclass(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } if (mActionModePopup != null) { mWindow.getDecorView().removeCallbacks(mShowActionModePopup); } if (mActionModeView != null) { if (mFadeAnim != null) { mFadeAnim.cancel(); } mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0.0F); final PopupWindow mActionModePopupFinal = mActionModePopup; final ActionBarContextView mActionModeViewFinal = mActionModeView; final ViewPropertyAnimatorCompat mFadeAnimFinal = mFadeAnim; final AppCompatCallback mAppCompatCallbackFinal = mAppCompatCallback; final android.support.v7.view.ActionMode mActionModeFinal = mActionMode; final Field mFadeAnimFieldFinal = mFadeAnimField; final Field mActionModeFieldFinal = mActionModeField; mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() { public void onAnimationEnd(View view) { mActionModeViewFinal.setVisibility(View.GONE); if (mActionModePopupFinal != null) { mActionModePopupFinal.dismiss(); } else if (mActionModeViewFinal.getParent() instanceof View) { ViewCompat.requestApplyInsets((View) mActionModeViewFinal.getParent()); } mActionModeViewFinal.removeAllViews(); mFadeAnimFinal.setListener((ViewPropertyAnimatorListener) null); try { if (mFadeAnimFieldFinal != null) { mFadeAnimFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } mWrapped.onDestroyActionMode(mode); if (mAppCompatCallbackFinal != null) { mAppCompatCallbackFinal.onSupportActionModeFinished(mActionModeFinal); } try { if (mActionModeFieldFinal != null) { mActionModeFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } } }); } } }); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:bruce.kk.brucetodos.MainActivity.java
/** * ???//w w w. ja v a2 s .com * * @param position */ private void modifyItem(final int position) { final UnFinishItem item = dataList.get(position); LogDetails.d(item); LinearLayout linearLayout = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black)); final EditText editText = new EditText(MainActivity.this); editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); editText.setTextColor(getResources().getColor(android.R.color.holo_green_light)); editText.setHint(item.content); editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark)); linearLayout.addView(editText); Button btnModify = new Button(MainActivity.this); btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnModify.setText(""); btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnModify.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnModify); Button btnDeleteItem = new Button(MainActivity.this); btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnDeleteItem.setText(""); btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnDeleteItem); final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ? popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0); btnModify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LogDetails.d(": " + editText.getText().toString()); if (!TextUtils.isEmpty(editText.getText().toString().trim())) { Date date = new Date(); item.content = editText.getText().toString().trim(); item.modifyDay = date; item.finishDay = null; ProgressDialogUtils.showProgressDialog(); presenter.modifyItem(item); dataList.set(position, item); refreshData(true); popupWindow.dismiss(); } else { Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show(); } } }); btnDeleteItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dataList.remove(position); presenter.deleteItem(item); refreshData(false); popupWindow.dismiss(); } }); }
From source file:com.vanisty.ui.MenuActivity.java
private void showPopup(final Activity context, Point p) { int popupWidth = 200; int popupHeight = 150; // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup); LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(context); popup.setContentView(layout);/*from w w w. ja v a 2 s .c o m*/ popup.setWidth(popupWidth); popup.setHeight(popupHeight); popup.setFocusable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. int OFFSET_X = 30; int OFFSET_Y = 30; // Clear the default translucent background popup.setBackgroundDrawable(new BitmapDrawable()); // Displaying the popup at the specified location, + offsets. popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y); // Getting a reference to Close button, and close the popup when clicked. Button close = (Button) layout.findViewById(R.id.close); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); } }); }
From source file:fr.univsavoie.ltp.client.map.Popup.java
/** * Afficher sur la map un popup qui propose a l'utilisateur * de mettre a jours son status//from w ww . j av a2s .c om */ public final void popupPublishStatus() { DisplayMetrics dm = new DisplayMetrics(); this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm); //final int height = dm.heightPixels; final int width = dm.widthPixels; int popupWidth = (int) (width * 0.75); //int popupHeight = height / 2; // Inflate the popup_layout.xml ScrollView viewGroup = (ScrollView) this.activity.findViewById(R.id.popupStatus); LayoutInflater layoutInflater = (LayoutInflater) this.activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(R.layout.popup_set_status, viewGroup); layout.setBackgroundResource(R.drawable.popup_gradient); // Crer le PopupWindow final PopupWindow popupPublishStatus = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true); popupPublishStatus.setBackgroundDrawable(new BitmapDrawable()); popupPublishStatus.setOutsideTouchable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. final int OFFSET_X = 0; final int OFFSET_Y = 0; // Displaying the popup at the specified location, + offsets. this.activity.findViewById(R.id.layoutMain).post(new Runnable() { public void run() { popupPublishStatus.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y); } }); /* * Evenements composants du PopupWindow */ // Ecouteur d'vnement sur le bouton pour se dconnecter Button publish = (Button) layout.findViewById(R.id.btStatusPublish); publish.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText userStatus = (EditText) layout.findViewById(R.id.fieldUserStatus); if (userStatus.getText().toString().length() == 0) { Toast.makeText(activity, "Impossible de publi ton status !", Toast.LENGTH_LONG).show(); popupPublishStatus.dismiss(); } else if (userStatus.getText().toString().length() < 3) { Toast.makeText(activity, "Impossible de publi ton status !", Toast.LENGTH_LONG).show(); popupPublishStatus.dismiss(); } else { String json = "{\"ltp\":{\"application\":\"Client LTP\",\"status\":{\"lon\" : \"" + String.valueOf(activity.getLongitude()) + "\",\"lat\" : \"" + String.valueOf(activity.getLatitude()) + "\",\"content\" : \"" + userStatus.getText().toString() + "\"}}}"; activity.getSession().postJSON("https://jibiki.univ-savoie.fr/ltpdev/rest.php/api/1/statuses", "STATUSES", json); Toast.makeText(activity, "Status mise a jours !", Toast.LENGTH_LONG).show(); popupPublishStatus.dismiss(); // Actualise les marqueurs activity.displayFriends(); } } }); }
From source file:fr.univsavoie.ltp.client.map.Popup.java
/** * Afficher une boite au milieu de la carte si aucun utilisateur est connects * pour proposer a l'invit, de se connecter ou s'incrire aupres du service LTP. *///w ww . j av a 2 s . c om public final void popupGuest() { DisplayMetrics dm = new DisplayMetrics(); this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm); //final int height = dm.heightPixels; final int width = dm.widthPixels; //final int height = dm.heightPixels; int popupWidth = (int) (width * 0.75); //int popupHeight = height / 2; // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupGuest); LayoutInflater layoutInflater = (LayoutInflater) this.activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(R.layout.popup_guest, viewGroup); layout.setBackgroundResource(R.drawable.popup_gradient); // Crer le PopupWindow final PopupWindow popupGuest = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true); popupGuest.setBackgroundDrawable(new BitmapDrawable()); popupGuest.setOutsideTouchable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. final int OFFSET_X = 0; final int OFFSET_Y = 0; // Displaying the popup at the specified location, + offsets. this.activity.findViewById(R.id.layoutMain).post(new Runnable() { public void run() { popupGuest.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y); } }); /* * Evenements composants du PopupWindow */ // Ecouteur d'vnement sur le bouton des paramtres Button btLogin = (Button) layout.findViewById(R.id.btnPopupLogin); btLogin.setOnClickListener(new OnClickListener() { public void onClick(View view) { // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte // (requestCode) qui sera utilis plus tard pour identifier lactivit // renvoyant la valeur de retour. Intent i = new Intent(activity, LoginActivity.class); activity.startActivityForResult(i, 1); popupGuest.dismiss(); } }); // Ecouteur d'vnement sur le bouton des paramtres Button btSignup = (Button) layout.findViewById(R.id.btnPopupSignup); btSignup.setOnClickListener(new OnClickListener() { public void onClick(View view) { // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte // (requestCode) qui sera utilis plus tard pour identifier lactivit // renvoyant la valeur de retour. Intent i = new Intent(activity, SignupActivity.class); activity.startActivityForResult(i, 3); popupGuest.dismiss(); } }); // Ecouteur d'vnement sur le bouton pour fermer l'application Button close = (Button) layout.findViewById(R.id.btnPopupClose); close.setOnClickListener(new OnClickListener() { public void onClick(View v) { popupGuest.dismiss(); } }); }
From source file:com.bf.zxd.zhuangxudai.my.fragment.FinancialApplyFragment.java
private void ChangeIcon() { //PopupWindow----START-----??PopupWindowPopupWindow??? backgroundAlpha(0.3f);/*from ww w . jav a2s . c o m*/ View view = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.popu_window, null); final PopupWindow popupWindow = new PopupWindow(view, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); //?? DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); popupWindow.setWidth(dm.widthPixels); popupWindow.setAnimationStyle(R.style.popuwindow); //? popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); popupWindow.setOnDismissListener(new poponDismissListener_FinancialApplyFragment()); //PopupWindow-----END //PopupWindow Button button = (Button) view.findViewById(R.id.take_photo);//?? Button button1 = (Button) view.findViewById(R.id.all_photo);//? Button button2 = (Button) view.findViewById(R.id.out);//? button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,? allPhoto(); } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,Intent???? Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //,?? File file = FileUitlity.getInstance(getActivity().getApplicationContext()).makeDir("head_image"); //?? path = file.getParent() + File.separatorChar + System.currentTimeMillis() + ".jpg"; //?IntentIntent? intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path))); //? intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); //?Intent??RoundImageView startActivityForResult(intent, REQUEST_CODE); } }); }
From source file:com.bf.zxd.zhuangxudai.my.fragment.CompanyApplyFragment.java
private void ChangeIcon() { //PopupWindow----START-----??PopupWindowPopupWindow??? backgroundAlpha(0.3f);/*from www . j a v a 2 s .com*/ View view = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.popu_window, null); final PopupWindow popupWindow = new PopupWindow(view, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); //?? DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); popupWindow.setWidth(dm.widthPixels); popupWindow.setAnimationStyle(R.style.popuwindow); //? popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); popupWindow.setOnDismissListener(new poponDismissListener_CompanyApplyFragment()); //PopupWindow-----END //PopupWindow Button button = (Button) view.findViewById(R.id.take_photo);//?? Button button1 = (Button) view.findViewById(R.id.all_photo);//? Button button2 = (Button) view.findViewById(R.id.out);//? button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,? Log.i("Daniel", "------"); allPhoto(); } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,Intent???? Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //,?? File file = FileUitlity.getInstance(getActivity().getApplicationContext()).makeDir("head_image"); //?? path = file.getParent() + File.separatorChar + System.currentTimeMillis() + ".jpg"; //?IntentIntent? intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path))); //? intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); //?Intent??RoundImageView startActivityForResult(intent, REQUEST_CODE); } }); }
From source file:com.pressurelabs.flowopensource.TheHubActivity.java
/** * Generates a Popup Menu with Two Actions Edit and Delete. * * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to * delete from file/*from w w w .ja v a 2 s.c o m*/ * * Editing launches a renaming process * * @param longClickedFlow Flow represented by cardview longclicked * @param cardPosition position of cardview in adapter * @param cardViewClicked the cardview view object clicked * @return */ private boolean showLongClickPopUpMenu(final Flow longClickedFlow, final int cardPosition, final View cardViewClicked) { LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null); LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT); int dividerMargin = viewGroup.getDividerPadding(); // Top bottom int popupPadding = layout.getPaddingBottom(); int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding); // Prevents border popup.setBackgroundDrawable(new ColorDrawable()); popup.setFocusable(true); // Getting a reference to Close button, and close the popup when clicked. ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item); delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Deletes current Flow from file and UI */ rvContent.remove(cardPosition); manager.delete(longClickedFlow.getUuid()); adapter.notifyItemRemoved(cardPosition); adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount()); popup.dismiss(); Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG) .setAction("NO!!!", new View.OnClickListener() { @Override public void onClick(View v) { rvContent.add(cardPosition, longClickedFlow); manager.save(longClickedFlow.getUuid(), longClickedFlow); adapter.notifyItemInserted(cardPosition); } }); bar.show(); } }); ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item); edit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); renameFlow(cardPosition, cardViewClicked); } }); // Displaying the popup at the specified location, + offsets. popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP); longClickPopup = popup; return true; }
From source file:mn.today.TheHubActivity.java
/** * Generates a Popup Menu with Two Actions Edit and Delete. * * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to * delete from file/*from w w w . j a v a2s . c o m*/ * * Editing launches a renaming process * * @param longClickedFlow Flow represented by cardview longclicked * @param cardPosition position of cardview in adapter * @param cardViewClicked the cardview view object clicked * @return */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) private boolean showLongClickPopUpMenu(final ToDay longClickedFlow, final int cardPosition, final View cardViewClicked) { LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null); LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT); int dividerMargin = viewGroup.getDividerPadding(); // Top bottom int popupPadding = layout.getPaddingBottom(); int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding); // Prevents border popup.setBackgroundDrawable(new ColorDrawable()); popup.setFocusable(true); // Getting a reference to Close button, and close the popup when clicked. ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item); delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Deletes current Flow from file and UI */ rvContent.remove(cardPosition); manager.delete(longClickedFlow.getUuid()); adapter.notifyItemRemoved(cardPosition); adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount()); popup.dismiss(); Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG) .setAction("!!!", new View.OnClickListener() { @Override public void onClick(View v) { rvContent.add(cardPosition, longClickedFlow); manager.save(longClickedFlow.getUuid(), longClickedFlow); adapter.notifyItemInserted(cardPosition); } }); bar.show(); } }); ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item); edit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); renameFlow(cardPosition, cardViewClicked); } }); // Displaying the popup at the specified location, + offsets. popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP); longClickPopup = popup; return true; }
From source file:net.quduo.pixel.interfaces.android.fragment.ChatFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.inflater = inflater; View v = inflater.inflate(R.layout.fragment_chat, container, false); mChatListView = (ListView) v.findViewById(R.id.chat_list_view); // TODO: ?//from w ww . j av a 2 s. co m mSourceDataList = new ArrayList<ChatListDataModel>(); ChatListDataModel sourceData = new ChatListDataModel(); sourceData.setChatAvatar(R.drawable.default_contact_action_01); sourceData.setChatTitle("?"); sourceData.setChatSummary(":?, ..."); mSourceDataList.add(sourceData); ChatListDataModel sourceData1 = new ChatListDataModel(); sourceData1.setChatAvatar(R.drawable.default_contact_action_04); sourceData1.setChatTitle(""); sourceData1.setChatSummary("?"); mSourceDataList.add(sourceData1); ChatListDataModel sourceData2 = new ChatListDataModel(); sourceData2.setChatAvatar(R.drawable.default_contact_action_03); sourceData2.setChatTitle(""); sourceData2.setChatSummary("?..."); mSourceDataList.add(sourceData2); ChatListDataModel sourceData3 = new ChatListDataModel(); sourceData3.setChatAvatar(R.drawable.default_contact_action_02); sourceData3.setChatTitle(""); sourceData3.setChatSummary("?"); mSourceDataList.add(sourceData3); // TODO ContextMenu final ArrayList<HashMap<String, Object>> mPopupWindowListItem = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map1 = new HashMap<String, Object>(); // map1.put("item_image", R.drawable.icon_message); map1.put("item_icon", R.string.icon_chat_add_group); // map1.put("item_text", "" + i + ""); map1.put("item_title", "??"); mPopupWindowListItem.add(map1); HashMap<String, Object> map2 = new HashMap<String, Object>(); // map2.put("item_image", R.drawable.icon_message); map2.put("item_icon", R.string.icon_chat_add_group); // map2.put("item_text", "" + i + ""); map2.put("item_title", ""); mPopupWindowListItem.add(map2); mChatListAdapter = new ChatListAdapter(this.getActivity(), mSourceDataList); mChatListView.setAdapter(mChatListAdapter); mChatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (DEBUG) Log.d(TAG, mSourceDataList.get(i).getChatTitle()); Intent intent = new Intent(getActivity(), ChatFormActivity.class); getActivity().startActivity(intent); getActivity().finish(); // ? getActivity().overridePendingTransition(R.anim.activity_open_enter, R.anim.activity_close_exit); } }); mChatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View v, int i, long l) { if (DEBUG) Log.d(TAG, mSourceDataList.get(i).getChatTitle()); // ?? View contextMenuView = inflater.inflate(R.layout.layout_common_context_menu, null); // PopupWindow final PopupWindow popupWindow = new PopupWindow(contextMenuView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, false); // ??? // new ColorDrawable(0) getResources().getDrawable(R.drawable.popup_window_background) popupWindow.setBackgroundDrawable(new ColorDrawable(0x90000000)); // ?? // popupWindow.setOutsideTouchable(true); // ?? popupWindow.setFocusable(true); // ? // popupWindow.setAnimationStyle(R.style.PopupAnimation); // ? // popupWindow.setOnDismissListenerd(new PopupWindow.OnDismissListener(){}); /* // PopupWindow,PopupWindow popupWindow.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { popupWindow.dismiss(); return true; } return false; } }); */ popupWindow.getContentView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popupWindow.dismiss(); } }); if (popupWindow.isShowing()) { // ??????????? popupWindow.dismiss(); } else { // SimpleAdapter mSimpleAdapter = new SimpleAdapter(getApplicationContext(), mPopupWindowListItem, R.layout.main_popup_menu_item, new String[]{"item_icon", "item_title"}, new int[]{R.id.popup_menu_item_icon, R.id.popup_menu_item_title}); BaseAdapter mSimpleAdapter = new BaseAdapter() { @Override public int getCount() { return mPopupWindowListItem.size(); } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(getActivity()); convertView = inflater.inflate(R.layout.list_item_common_context_menu, parent, false); } // TextView popupMenuItemIcon = (TextView) convertView.findViewById(R.id.popup_menu_item_icon); // if (DEBUG) Log.d(TAG, "item_icon:" + mPopupWindowListItem.get(position).get("item_icon")); // popupMenuItemIcon.setTypeface(typeface); // if (popupMenuItemIcon.getTypeface() != typeface) { // popupMenuItemIcon.setTypeface(typeface); // } // popupMenuItemIcon.setText(Integer.valueOf(mPopupWindowListItem.get(position).get("item_icon").toString())); TextView popupMenuItemTitle = (TextView) convertView .findViewById(R.id.context_menu_action_text_view); popupMenuItemTitle .setText(mPopupWindowListItem.get(position).get("item_title").toString()); return convertView; } }; TextView contextMenuTitle = (TextView) contextMenuView.findViewById(R.id.context_menu_title); contextMenuTitle.setText(mSourceDataList.get(i).getChatTitle()); ListView mPopupMenuListView = (ListView) contextMenuView .findViewById(R.id.context_menu_list_view); mPopupMenuListView.setAdapter(mSimpleAdapter); // ? // PopupWindow??View?x,y????? // popupWindow.showAsDropDown(v, -460, 0); // ?View?,?parent????-90 // Gravity.TOP|Gravity.LEFT, 0, 150 popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0); popupWindow.update(); } return true; } }); // mChatListView.setOnItemSelectedListener(); // #ContextMenu // this.unregisterForContextMenu(mChatListView); // mChatListView.setOnCreateContextMenuListener(null); // this.registerForContextMenu(mChatListView); return v; }