Example usage for android.widget PopupWindow showAsDropDown

List of usage examples for android.widget PopupWindow showAsDropDown

Introduction

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

Prototype

public void showAsDropDown(View anchor, int xoff, int yoff) 

Source Link

Document

Display the content view in a popup window anchored to the bottom-left corner of the anchor view offset by the specified x and y coordinates.

Usage

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

protected void initView(View view) {

    /*//from w w  w .ja  va  2 s  .c  om
     *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  ww. jav a2  s . c  om*/
     *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) {
    /*// w w w .  j  a  v  a 2  s .  c om
     *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:com.lines.activitys.SettingsActivity.java

/**
 * This method creates and shows a popup to the user, displaying a relevent
 * help message.//w  w  w . j a v  a  2s  .c o  m
 * 
 * @param msg
 *            - decides which message we are displaying to the user
 * 
 */
private void showPopup(String msg) {
    // Create popup
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(R.layout.help_popup_layout, null);
    final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
    TextView text = (TextView) popupView.findViewById(R.id.text);

    // Here we decide what help message to display to the user.
    if (msg.equals("prompts")) {
        text.setText(R.string.prompt_help);
    } else {
        text.setText(R.string.auto_help);
    }

    btnDismiss.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });

    popupWindow.showAsDropDown(mPrompts, 50, -150);
}

From source file:com.lines.activitys.OptionsActivity.java

/**
 * This method creates and shows a popup to the user, displaying a relevent
 * help message./*from   w w w .j ava2 s. com*/
 * 
 * @param msg
 *            - decides which message we are displaying to the user
 * 
 */
private void showPopup(String msg) {
    // Create popup
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(R.layout.help_popup_layout, null);
    final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
    TextView text = (TextView) popupView.findViewById(R.id.text);

    // Here we decide what help message to display to the user.
    if (msg.equals("cue")) {
        text.setText(R.string.cue_help);
    } else if (msg.equals("random")) {
        text.setText(R.string.random_help);
    } else if (msg.equals("own line")) {
        text.setText(R.string.own_line_help);
    } else if (msg.equals("stage")) {
        text.setText(R.string.stage_help);
    } else if (msg.equals("mode")) {
        text.setText(R.string.mode_help);
    }

    btnDismiss.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });

    popupWindow.showAsDropDown(mCueHelp, 50, -250);
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void commonPopupWindowDisplay(PopupWindow popupWindow, View tabMenu, int x, int y) {
    popupWindow.setFocusable(true);//from   ww w.j  a  v  a 2s . c om
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setIgnoreCheekPress();
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(tabMenu, x, y);

}

From source file:com.cognizant.trumobi.PersonaLauncher.java

public void showPreviews(final View anchor, int start, int end) {
    if (mWorkspace != null && mWorkspace.getChildCount() > 0) {
        if (newPreviews) {
            showingPreviews = true;//from  ww w . java  2 s. c  om
            hideDesktop(true);
            mWorkspace.lock();
            mWorkspace.openSense(true);
        } else {
            // check first if it's already open
            final PopupWindow window = (PopupWindow) anchor.getTag(R.id.TAG_PREVIEW);
            if (window != null)
                return;
            Resources resources = getResources();

            PersonaWorkspace personaWorkspace = mWorkspace;
            PersonaCellLayout cell = ((PersonaCellLayout) personaWorkspace.getChildAt(start));
            float max;
            ViewGroup preview;
            max = personaWorkspace.getChildCount();
            preview = new LinearLayout(this);

            Rect r = new Rect();
            // ADW: seems sometimes this throws an out of memory error....
            // so...
            try {
                resources.getDrawable(R.drawable.pr_preview_background).getPadding(r);
            } catch (OutOfMemoryError e) {
            }
            int extraW = (int) ((r.left + r.right) * max);
            int extraH = r.top + r.bottom;

            int aW = cell.getWidth() - extraW;
            float w = aW / max;

            int width = cell.getWidth();
            int height = cell.getHeight();
            // width -= (x + cell.getRightPadding());
            // height -= (y + cell.getBottomPadding());
            if (width != 0 && height != 0) {
                showingPreviews = true;
                float scale = w / width;

                int count = end - start;

                final float sWidth = width * scale;
                float sHeight = height * scale;

                PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
                ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);

                for (int i = start; i < end; i++) {
                    ImageView image = new ImageView(this);
                    cell = (PersonaCellLayout) personaWorkspace.getChildAt(i);
                    Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888);
                    cell.setDrawingCacheEnabled(false);
                    Canvas c = new Canvas(bitmap);
                    c.scale(scale, scale);
                    c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
                    cell.dispatchDraw(c);

                    image.setBackgroundDrawable(resources.getDrawable(R.drawable.pr_preview_background));
                    image.setImageBitmap(bitmap);
                    image.setTag(i);
                    image.setOnClickListener(handler);
                    image.setOnFocusChangeListener(handler);
                    image.setFocusable(true);
                    if (i == mWorkspace.getCurrentScreen())
                        image.requestFocus();

                    preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT);

                    bitmaps.add(bitmap);
                }

                PopupWindow p = new PopupWindow(this);
                p.setContentView(preview);
                p.setWidth((int) (sWidth * count + extraW));
                p.setHeight((int) (sHeight + extraH));
                p.setAnimationStyle(R.style.AnimationPreview);
                p.setOutsideTouchable(true);
                p.setFocusable(true);
                p.setBackgroundDrawable(new ColorDrawable(0));
                p.showAsDropDown(anchor, 0, 0);
                p.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        dismissPreview(anchor);
                    }
                });
                anchor.setTag(R.id.TAG_PREVIEW, p);
                anchor.setTag(R.id.workspace, preview);
                anchor.setTag(R.id.icon, bitmaps);
            }
        }
    }
}