Example usage for android.widget PopupWindow update

List of usage examples for android.widget PopupWindow update

Introduction

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

Prototype

public void update() 

Source Link

Document

Updates the state of the popup window, if it is currently being displayed, from the currently set state.

Usage

From source file:com.ymt.demo1.baseClasses.SimpleTestTabFragmentScrollUltraListViewFragment.java

protected void initView(View view) {

    /*/* w  ww  .j  a  v  a 2 s  . co  m*/
     *listView 
     */
    listView = (PullToRefreshListView) view.findViewById(R.id.pull_to_refresh_list_view);
    theListView = listView.getRefreshableView();
    testArray = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        testArray.add(String.valueOf(i));
    }

    /*
    ??
     */
    adapter = new SimpleTxtItemAdapter(getActivity());
    listView.setAdapter(adapter);
    adapter.setList(testArray);
    scrollView.setListView(listView); //???listView?

    /*
     *??
     */
    theListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            /*
            ???
            */
            String[] actionList = new String[] { "", "?", "" };
            PopActionUtil popActionUtil = PopActionUtil.getInstance(getActivity());
            actionListener = new PopActionListener() {
                @Override
                public void onAction(String action) {
                    switch (action) {
                    case "":
                        Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show();
                        break;
                    case "?":
                        Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT).show();
                        break;
                    case "":
                        Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show();
                        testArray.remove(atPosition);
                        adapter.setList(testArray);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void onDismiss() {

                }
            };

            popActionUtil.setActionListener(actionListener);
            popActionUtil.setActions(actionList);
            final PopupWindow itemPopMenu = popActionUtil.getSimpleTxtPopActionMenu();

            itemPopMenu.showAsDropDown(view, view.getWidth() - 20, -view.getHeight());
            itemPopMenu.update();
            atPosition = position - 1;

            return false;
        }
    });
}

From source file:com.ymt.demo1.plates.news.FileNoticeFragment.java

protected void initView(View view) {

    /*//w  w w . j  a v a2s .c  o  m
     *listView 
     */
    listView = (PullToRefreshListView) view.findViewById(R.id.pull_to_refresh_list_view);
    ListView theListView = listView.getRefreshableView();
    testArray = new ArrayList<>();
    ProgressBar progressBar = new ProgressBar(getActivity());
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    progressBar.setLayoutParams(params);
    listView.setEmptyView(progressBar);

    /*
    ??
     */
    summaryAdapter = new NewsSummaryAdapter(getActivity());
    listView.setAdapter(summaryAdapter);
    summaryAdapter.setList(testArray);
    scrollView.setListView(listView); //???listView?

    /*
     *??
     */
    theListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {

            /*
            *???
            */
            String[] actionList = new String[] { "", "?" };
            PopActionUtil popActionUtil = PopActionUtil.getInstance(getActivity());
            actionListener = new PopActionListener() {
                @Override
                public void onAction(String action) {
                    switch (action) {
                    case "":
                        Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show();
                        break;
                    case "?":
                        Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void onDismiss() {

                }
            };

            popActionUtil.setActionListener(actionListener);
            popActionUtil.setActions(actionList);
            final PopupWindow itemPopMenu = popActionUtil.getSimpleTxtPopActionMenu();

            itemPopMenu.showAsDropDown(view, view.getWidth() - 20, -view.getHeight());
            itemPopMenu.update();

            return true;
        }
    });

    /*
    listView   ?
     */
    theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //
            //todo bug
            Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
            NewsSummary summary = (NewsSummary) (parent.getAdapter()).getItem(position);
            intent.putExtra("summary", summary);
            intent.putExtra("type", "notice");
            startActivity(intent);
        }
    });

    /*
     * 
     */
    listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
        @Override
        public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
            mNews.clear();
            startPosition = 1;
            mQueue.add(summaryRequest(state, start, pagesize));
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
            startPosition++;
            mQueue.add(summaryRequest(state, start, pagesize));
        }
    });

}

From source file:com.ymt.demo1.plates.knowledge.KnowledgeItemListViewFragment.java

protected void initView(View view) {
    /*//from   w w  w.j a v a 2 s  .c o  m
     *listView 
     */
    listView = (PullToRefreshListView) view.findViewById(R.id.pull_to_refresh_list_view);
    theListView = listView.getRefreshableView();

    switch (mKnowledgeType) {
    case KNOWLEDGE_BZGF:
    case KNOWLEDGE_KYWX:
    case KNOWLEDGE_SJK:
        //??
        adapter = new KnowledgeItemAdapter(getActivity());
        listView.setAdapter(adapter);
        adapter.setKnowledgeItemList(knowledgeItemList);
        new AsyncTask<Void, Void, List<KnowledgeItem>>() {
            @Override
            protected List<KnowledgeItem> doInBackground(Void... params) {
                return DataSupport.where("type = ?", String.valueOf(mKnowledgeType)).find(KnowledgeItem.class);
            }

            @Override
            protected void onPostExecute(List<KnowledgeItem> itemList) {
                super.onPostExecute(itemList);
                knowledgeItemList.addAll(itemList);
                adapter.notifyDataSetChanged();
            }
        }.execute();
        break;
    default:
        break;

    }

    /*
     *??
     */
    theListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {

            /*
            *???
            */
            String[] actionList = new String[] { "", "?" };
            PopActionUtil popActionUtil = PopActionUtil.getInstance(getActivity());
            actionListener = new PopActionListener() {
                @Override
                public void onAction(String action) {
                    switch (action) {
                    case "":
                        Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show();
                        break;
                    case "?":
                        Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void onDismiss() {

                }
            };

            popActionUtil.setActionListener(actionListener);
            popActionUtil.setActions(actionList);
            final PopupWindow itemPopMenu = popActionUtil.getSimpleTxtPopActionMenu();

            itemPopMenu.showAsDropDown(view, view.getWidth() - 20, -view.getHeight());
            itemPopMenu.update();

            return true;
        }
    });

    /*
    listView   ?
     */
    theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //
            Intent intent = new Intent(getActivity(), KnowledgeItemDetailActivity.class);
            switch (mKnowledgeType) {
            case KNOWLEDGE_BZGF:
            case KNOWLEDGE_KYWX:
            case KNOWLEDGE_SJK:
                intent.putExtra("knowId", ((KnowledgeItem) parent.getAdapter().getItem(position)).getKnowId());
                break;
            default:
                break;
            }
            startActivity(intent);
        }
    });

    listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
        @Override
        public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
            startIndex = 1;
            switch (mKnowledgeType) {
            case KNOWLEDGE_BZGF:
            case KNOWLEDGE_KYWX:
            case KNOWLEDGE_SJK:
                if (AppContext.internetAvialable()) {
                    DataSupport.deleteAll(KnowledgeItem.class, "type = ?", String.valueOf(mKnowledgeType));
                    knowledgeItemList.clear();
                    adapter.setKnowledgeItemList(knowledgeItemList);
                    mQueue.add(getListData(pageSize, startIndex, ""));
                } else {
                    listView.onRefreshComplete();
                }
                break;
            default:
                break;
            }
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
            startIndex++;
            switch (mKnowledgeType) {
            case KNOWLEDGE_BZGF:
            case KNOWLEDGE_KYWX:
            case KNOWLEDGE_SJK:
                if (AppContext.internetAvialable()) {
                    mQueue.add(getListData(pageSize, startIndex, ""));
                }
                break;
            default:
                break;

            }
        }
    });
}

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 .c o 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;
}

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  .  jav  a 2  s .co  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;
}