List of usage examples for android.widget PopupWindow dismiss
public void dismiss()
From source file:net.quduo.pixel.interfaces.android.fragment.ContactFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_contact, container, false); // 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);//from www .ja v a 2 s . c o m 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); // Set the adapter mContactListAdapter = new ContactListAdapter(this.getActivity(), mSourceDataList); mListView = (ListView) view.findViewById(R.id.contact_list_view); mListView.setAdapter(mContactListAdapter); // Set OnItemClickListener so we can be notified on item clicks mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (null != mListener) { // Notify the active callbacks interface (the activity, if the // fragment is attached to one) that an item has been selected. // mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id); } } }); mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View v, int i, long l) { // Log.e(TAG, DummyContent.ITEMS.get(i).content); Log.e(TAG, mSourceDataList.get(i).getContactName()); // ?? 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).getContactName()); 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; } }); mLetterQueryView = (LetterQueryView) view.findViewById(R.id.letter_query_view); mLetterTextDialog = (TextView) view.findViewById(R.id.letter_text_dialog); mLetterQueryView.setTextView(mLetterTextDialog); // ?? mLetterQueryView.setOnTouchingLetterChangedListener(new LetterQueryView.OnTouchingLetterChangedListener() { @Override public void onTouchingLetterChanged(String s) { // ?? int position = mContactListAdapter.getPositionForSection(s.charAt(0)); if (position != -1) { mListView.setSelection(position); } } }); return view; }
From source file:com.pressurelabs.flowopensource.TheHubActivity.java
/** * Displays a popup window prompting the user to * * Confirm the changes to the name, saving the new name to file and updating the UI. * * Cancel the changes, returning the user back to the original state before editing * * @param newName new name to be used/*from www .ja v a 2 s. c om*/ * @param cardPosition position of cardview in adapter * @param cardViewClicked the cardview view object clicked * @param switcher the viewSwitcher object used to rename */ private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher, final int cardPosition) { LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_window_editing, null); LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing); // Creating the PopupWindow final PopupWindow popupEditing = 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 from appearing outside popupwindow popupEditing.setBackgroundDrawable(new ColorDrawable()); popupEditing.setFocusable(false); // Getting a reference to Close button, and close the popup when clicked. ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes); confirmEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Flow toChange = rvContent.get(cardPosition); if (newName.getText().toString().equals("")) { // Need to optimize this so that the dialog does NOT disappear and just display toast Toast.makeText(TheHubActivity.this, "This Flow needs a name!", Toast.LENGTH_LONG).show(); } else { toChange.setName(newName.getText().toString()); manager.overwrite(toChange.getUuid(), toChange); adapter.notifyDataSetChanged(); switcher.showNext(); menuState = AppConstants.MENU_ITEMS_NATIVE; invalidateOptionsMenu(); popupEditing.dismiss(); newName.clearFocus(); } } }); ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes); cancelEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switcher.showNext(); menuState = AppConstants.MENU_ITEMS_NATIVE; invalidateOptionsMenu(); popupEditing.dismiss(); } }); // Displaying the popup at the specified location, + offsets. popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP); editingPopup = popupEditing; }
From source file:mn.today.TheHubActivity.java
/** * Displays a popup window prompting the user to * * Confirm the changes to the name, saving the new name to file and updating the UI. * * Cancel the changes, returning the user back to the original state before editing * * @param newName new name to be used//from w w w .java2s . c o m * @param cardPosition position of cardview in adapter * @param cardViewClicked the cardview view object clicked * @param switcher the viewSwitcher object used to rename */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher, final int cardPosition) { LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_window_editing, null); LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing); // Creating the PopupWindow final PopupWindow popupEditing = 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 from appearing outside popupwindow popupEditing.setBackgroundDrawable(new ColorDrawable()); popupEditing.setFocusable(false); // Getting a reference to Close button, and close the popup when clicked. ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes); confirmEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToDay toChange = rvContent.get(cardPosition); if (newName.getText().toString().equals("")) { // Need to optimize this so that the dialog does NOT disappear and just display toast Toast.makeText(TheHubActivity.this, "?? !", Toast.LENGTH_LONG).show(); } else { toChange.setName(newName.getText().toString()); manager.overwrite(toChange.getUuid(), toChange); adapter.notifyDataSetChanged(); switcher.showNext(); menuState = AppConstants.MENU_ITEMS_NATIVE; invalidateOptionsMenu(); popupEditing.dismiss(); newName.clearFocus(); } } }); ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes); cancelEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switcher.showNext(); menuState = AppConstants.MENU_ITEMS_NATIVE; invalidateOptionsMenu(); popupEditing.dismiss(); } }); // Displaying the popup at the specified location, + offsets. popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP); editingPopup = popupEditing; }
From source file:cn.zhangls.android.weibo.ui.weibo.WeiboFrameProvider.java
/** * ????/* w w w . j a va 2s .c om*/ * * @param holder * @param status */ private void setupPopupBar(final FrameHolder holder, final Status status) { LayoutInflater layoutInflater = LayoutInflater .from(holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext()); // final View popupView; if (status.isFavorited() && status.getUser().isFollowing()) {// ?? popupView = layoutInflater.inflate(R.layout.popup_window_weibo_follow_save_post, holder.binding.flWeiboContainer, false); } else if (!status.isFavorited() && status.getUser().isFollowing()) {// ?? popupView = layoutInflater.inflate(R.layout.popup_window_weibo_follow_unsave_post, holder.binding.flWeiboContainer, false); } else if (status.isFavorited() && !status.getUser().isFollowing()) {// ?? popupView = layoutInflater.inflate(R.layout.popup_window_weibo_unfollow_save_post, holder.binding.flWeiboContainer, false); } else {// ?? popupView = layoutInflater.inflate(R.layout.popup_window_weibo_unfollow_unsave_post, holder.binding.flWeiboContainer, false); } // PopupWindow final PopupWindow popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); // popupWindow popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { Animation animation = AnimationUtils.loadAnimation( holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext(), R.anim.rotate_180_end); animation.setDuration(300); animation.setFillAfter(true); holder.binding.fgHomeWeiboPopupBar.startAnimation(animation); } }); popupWindow.setAnimationStyle(R.style.PopupWindowAnimStyle); // popupWindow Item ? if (status.isFavorited()) {// ?????? popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_save_post) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FavoritesAPI favoritesAPI = new FavoritesAPI( mBinding.getRoot().getContext().getApplicationContext(), AccessTokenKeeper.readAccessToken( mBinding.getRoot().getContext().getApplicationContext())); BaseObserver<Favorite> observer = new BaseObserver<Favorite>( mBinding.getRoot().getContext().getApplicationContext()) { @Override public void onNext(Favorite value) { } @Override public void onError(Throwable e) { super.onError(e); } @Override public void onComplete() { } }; favoritesAPI.destroy(observer, status.getId()); popupWindow.dismiss(); } }); } else { popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_unsave_post) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FavoritesAPI favoritesAPI = new FavoritesAPI( mBinding.getRoot().getContext().getApplicationContext(), AccessTokenKeeper.readAccessToken( mBinding.getRoot().getContext().getApplicationContext())); BaseObserver<Favorite> observer = new BaseObserver<Favorite>( mBinding.getRoot().getContext().getApplicationContext()) { @Override public void onNext(Favorite value) { } @Override public void onError(Throwable e) { super.onError(e); } @Override public void onComplete() { } }; favoritesAPI.create(observer, status.getId()); popupWindow.dismiss(); } }); } if (status.getUser().isFollowing()) {// ???? popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_follow) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupWindow.dismiss(); } }); } else { popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_unfollow) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupWindow.dismiss(); } }); } // ??? holder.binding.fgHomeWeiboPopupBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (popupWindow != null && !popupWindow.isShowing()) { Animation animation = AnimationUtils.loadAnimation( holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext(), R.anim.rotate_180_start); animation.setDuration(300); animation.setFillAfter(true); holder.binding.fgHomeWeiboPopupBar.startAnimation(animation); popupWindow.showAsDropDown(holder.binding.fgHomeWeiboPopupBar); } } }); }
From source file:com.example.angel.parkpanda.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); showhideFootWindow(0);// w w w . j a va 2s . c o m if (id == R.id.nav_menu_findparking) { Intent intent = new Intent(getApplicationContext(), Find_Park.class); startActivityForResult(intent, 2);// Activity is started with requestCode 2 // finish(); } if (id == R.id.nav_menu_account) { initViewSetting(false); if (LOGININFO.flag == 10) { Fragment fragment = new my_account(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction FT = fragmentManager.beginTransaction(); FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left); FT.replace(R.id.flContent, fragment).commit(); } else { Fragment fragment = new log_in(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction FT = fragmentManager.beginTransaction(); FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left); FT.replace(R.id.flContent, fragment).commit(); } } if (id == R.id.nav_menu_help) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion > 21) { showhideFootWindow(0); initViewSetting(true); LayoutInflater inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.ly_my_help, null); layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.popupanim)); PopupWindow optionspu = new PopupWindow(layout, DrawerLayout.LayoutParams.WRAP_CONTENT, DrawerLayout.LayoutParams.WRAP_CONTENT); optionspu.setFocusable(true); optionspu.showAtLocation(layout, Gravity.CENTER, 0, 0); optionspu.update(0, 0, DrawerLayout.LayoutParams.WRAP_CONTENT, DrawerLayout.LayoutParams.WRAP_CONTENT); optionspu.setAnimationStyle(R.anim.popupanim); } else { // initViewSetting(false); /* Fragment fragment = new help_dialog(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction FT = fragmentManager.beginTransaction(); FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left); FT.replace(R.id.flContent, fragment).commit();*/ LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.fragment_help_dialog, null); final PopupWindow optionspu = new PopupWindow(popupView, DrawerLayout.LayoutParams.WRAP_CONTENT, DrawerLayout.LayoutParams.WRAP_CONTENT); optionspu.setFocusable(true); optionspu.showAtLocation(popupView, Gravity.CENTER, 0, 0); Button btnDismiss = (Button) popupView.findViewById(R.id.btn_help_close); btnDismiss.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // Toast.makeText(getApplicationContext(), "dsdsa", Toast.LENGTH_SHORT).show(); optionspu.dismiss(); plotMarkers(mMyMarkersArray); initViewSetting(true); } }); } } drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java
/** * Handles showing the Calendar pop up, fetching the selected date, calling to fetch * submissions again//from w w w . j ava 2s.com */ private void showCalendarPicker() { // Inflate the popup_layout.xml ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root); LayoutInflater layoutInflater = (LayoutInflater) getMainActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. //or if popup is on edge display it to the left of the circle Display display = getMainActivity().getWindowManager().getDefaultDisplay(); Point size = new Point(0, 0); display.getSize(size); int OFFSET_X = 25; int OFFSET_Y = 25; final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(getMainActivity()); popup.setAnimationStyle(android.R.style.Animation_Dialog); popup.setContentView(layout); popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); popup.setFocusable(true); //gets rid of default background popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null)); //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu)); // Displaying the popup at the specified location, + offsets. popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y); Calendar minDate; minDate = Calendar.getInstance(); this.tempY = minDate.get(Calendar.YEAR); this.tempM = minDate.get(Calendar.MONTH); this.tempD = minDate.get(Calendar.DAY_OF_MONTH); dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override // Months start from 0, so January is month 0 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { tempY = year; tempM = monthOfYear; tempD = dayOfMonth; Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY); } }); ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept); ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(tempY, tempM, tempD, 1, 0); Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis()); // clear items from clustermanager and submissionMarkerList, as all new submissions // need to be fetched based on the selected date clusterManager.clearItems(); submissionMarkerIdList.clear(); addAdminMarkersToMap(); setMinDateInMs(calendar.getTimeInMillis()); popup.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setMinDateInMs(0); popup.dismiss(); } }); }
From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java
private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor, String textColor, int textSize, JSONArray data) { LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext) .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null); final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true); popupWindow.setContentView(rootView); ///*from www . ja v a 2 s . c om*/ rootView.setBackgroundColor(Color.parseColor(bgColorStr)); popupWindow.setContentView(rootView); //popupWindow? popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); int length = data.length(); List<ItemData> itemDataList = new ArrayList<ItemData>(); try { for (int i = 0; i < length; i++) { ItemData item = new ItemData(); String icon = data.getJSONObject(i).optString("icon", ""); if (!hasIcon && !TextUtils.isEmpty(icon)) { hasIcon = true; } if (hasIcon) { item.setIcon(data.getJSONObject(i).getString("icon")); } item.setText(data.getJSONObject(i).getString("text")); itemDataList.add(item); } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < length; i++) { LinearLayout linearLayout = new LinearLayout(mContext); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (hasIcon) { ImageView imageView = new ImageView(mContext); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); String imagePath = itemDataList.get(i).getIcon(); imageView.setImageBitmap(getBitmapFromPath(imagePath)); imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0); linearLayout.addView(imageView); } TextView tvText = new TextView(mContext); LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvLayoutParams.gravity = Gravity.CENTER_VERTICAL; tvText.setLayoutParams(tvLayoutParams); tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0); tvText.setText(itemDataList.get(i).getText()); tvText.setTextColor(Color.parseColor(textColor)); tvText.setTextSize(textSize); linearLayout.addView(tvText); linearLayout.setTag(i); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag())); if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); rootView.addView(linearLayout); // View dividerLine = new View(mContext); dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(mContext, 1))); dividerLine.setBackgroundColor(Color.parseColor(dividerColor)); rootView.addView(dividerLine); } int gravityParam; switch (direction) { case 0: gravityParam = Gravity.LEFT | Gravity.TOP; break; case 1: gravityParam = Gravity.RIGHT | Gravity.TOP; break; case 2: gravityParam = Gravity.LEFT | Gravity.BOTTOM; break; case 3: gravityParam = Gravity.RIGHT | Gravity.BOTTOM; break; default: gravityParam = Gravity.LEFT | Gravity.TOP; break; } popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y); }
From source file:com.quwu.xinwo.release.Release_Activity.java
/** * //from ww w .j av a2s.c om * PopupWindow * * */ private void showPopupWindow(View view, final int i) { // View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.release_pop, null); final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); popupWindow.setOnDismissListener(new OnDismissListener() { public void onDismiss() { releaseLin.setAlpha(1f); } }); popupWindow.setTouchable(true); popupWindow.setTouchInterceptor(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return false; // true?touch // ? PopupWindowonTouchEvent?dismiss } }); // ?PopupWindowBackdismiss // APIbug popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher)); // ???show int[] location = new int[2]; view.getLocationOnScreen(location); popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] + view.getWidth(), location[1] - 150); // TextView year = (TextView) contentView.findViewById(R.id.release_pop_yearText); year.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); TextView month = (TextView) contentView.findViewById(R.id.release_pop_monthText); month.setOnClickListener(new OnClickListener() { public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); TextView day = (TextView) contentView.findViewById(R.id.release_pop_dayText); day.setOnClickListener(new OnClickListener() { public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private void dismissPreview(final View v) { final PopupWindow window = (PopupWindow) v.getTag(R.id.TAG_PREVIEW); if (window != null) { hideDesktop(false);/*w ww . j av a2 s . c o m*/ window.setOnDismissListener(new PopupWindow.OnDismissListener() { @SuppressWarnings("unchecked") public void onDismiss() { ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); int count = group.getChildCount(); for (int i = 0; i < count; i++) { ((ImageView) group.getChildAt(i)).setImageDrawable(null); } ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon); for (Bitmap bitmap : bitmaps) bitmap.recycle(); v.setTag(R.id.workspace, null); v.setTag(R.id.icon, null); window.setOnDismissListener(null); } }); window.dismiss(); showingPreviews = false; mWorkspace.unlock(); mWorkspace.invalidate(); mDesktopLocked = false; } v.setTag(R.id.TAG_PREVIEW, null); }