Example usage for android.widget PopupWindow setFocusable

List of usage examples for android.widget PopupWindow setFocusable

Introduction

In this page you can find the example usage for android.widget PopupWindow setFocusable.

Prototype

public void setFocusable(boolean focusable) 

Source Link

Document

Changes the focusability of the popup window.

Usage

From source file:com.bf.zxd.zhuangxudai.my.fragment.CompanyApplyFragment.java

private void ChangeIcon() {
    //PopupWindow----START-----??PopupWindowPopupWindow???
    backgroundAlpha(0.3f);//from w  ww  .j  a  v  a2s . co 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_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: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  w w .  j av a2s . c  om*/
    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;
}

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  w  ww  . j a  va 2s  .  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.example.angel.parkpanda.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    showhideFootWindow(0);/*www. ja  v a2s  .co  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.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  ww  . j  a  v  a  2s.co 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: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 ww  w .  ja v a  2s  .co  m
 * @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

/**
 * 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//ww  w.jav a2s. co 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:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again/*from   w  ww. jav a2 s  .  c o m*/
 */
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: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  ww  w .jav  a 2s.co  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:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void commonPopupWindowDisplay(PopupWindow popupWindow, View tabMenu, int x, int y) {
    popupWindow.setFocusable(true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setIgnoreCheekPress();//w w  w . j av  a 2  s. co m
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(tabMenu, x, y);

}