Example usage for android.widget PopupWindow PopupWindow

List of usage examples for android.widget PopupWindow PopupWindow

Introduction

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

Prototype

public PopupWindow(View contentView, int width, int height) 

Source Link

Document

Create a new non focusable popup window which can display the contentView.

Usage

From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;//from w  w w .j  ava  2 s . c  o m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Context wrapped = new ContextThemeWrapper(context, defStyleRes);
        mPopup = new PopupWindow(wrapped, attrs, defStyleAttr);
    } else {
        mPopup = new PopupWindow(context, attrs, defStyleAttr, defStyleRes);
    }
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
}

From source file:org.kaaproject.kaa.demo.notification.KaaNotificationApp.java

private void initPopup() {
    LinearLayout layoutOfPopup = new LinearLayout(this);
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    popup = layoutInflater.inflate(R.layout.popup_notification, layoutOfPopup);
    popup.findViewById(R.id.popup_ok).setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w.  j ava  2  s  .co  m
        public void onClick(View v) {
            if (v.getId() == R.id.popup_ok) {
                popupWindow.dismiss();
            }
        }
    });
    popupWindow = new PopupWindow(popup, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setContentView(popup);
}

From source file:com.mzs.guaji.ui.ImagePagerActivity.java

private void showPopupWindow() {
    View v = View.inflate(context, R.layout.image_pop, null);
    mPopupWindow = new PopupWindow(v, RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    TextView mDialogMessageText = (TextView) v.findViewById(R.id.dialog_message_text);
    mDialogMessageText.setText(R.string.delete_image_text);
    mPopupWindow.showAtLocation(mRootLayout, Gravity.CENTER, 0, 0);
}

From source file:com.sonvp.tooltip.Tooltip.java

private Tooltip(Builder builder) {
    this.builder = builder;
    this.anchorView = builder.anchorView;
    this.gravity = builder.tooltipGravity;

    if (builder.dismissOutsideTouch) {

        rootView = (ViewGroup) anchorView.getRootView();
        overlay = new View(builder.context);
        overlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        //        overlay.setBackgroundColor(builder.context.getResources().getColor(android.R.color.holo_green_light));
        overlay.setOnTouchListener(this);
        rootView.addView(overlay);//from w  w w  .jav  a2s.c  o  m
    }

    // TODO container should NOT capture all events
    container = new LinearLayout(builder.context);
    container.setOnClickListener(this);

    int backgroundColor = builder.backgroundColor;

    viewTooltip = getViewTooltip(builder, backgroundColor);

    rectAnchorView = getRectView(anchorView);
    changeGravityToolTip();
    if (builder.arrowDrawable == null) {
        builder.arrowDrawable = new ArrowDrawable(backgroundColor, gravity);
    }

    arrow = new ImageView(builder.context);
    // TODO supports Gravity.NO_GRAVITY
    switch (gravity) {
    case Gravity.LEFT:
        container.setOrientation(LinearLayout.HORIZONTAL);
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        break;
    case Gravity.RIGHT:
        container.setOrientation(LinearLayout.HORIZONTAL);
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        break;
    case Gravity.TOP:
        container.setOrientation(LinearLayout.VERTICAL);
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        break;
    case Gravity.BOTTOM:
        container.setOrientation(LinearLayout.VERTICAL);
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        break;
    }

    popupWindow = new PopupWindow(container, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setOnDismissListener(this);
    popupWindow.setClippingEnabled(false);
    popupWindow.setAnimationStyle(android.R.style.Animation);
    //        popupWindow.setBackgroundDrawable(builder.context.getResources().getDrawable(android.R.color.holo_blue_bright));

}

From source file:app.hanks.com.conquer.activity.MainActivity.java

/**
 * ?popupWindow//from w  w  w  . j av  a 2 s .  c  o  m
 */
private void showSelectSort() {
    View v = View.inflate(context, R.layout.pop_sort, null);
    //
    v.findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popWin.dismiss();
        }
    });
    //?
    v.findViewById(R.id.change).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (currentFragment == myTaskFragment) {
                currentFragment = otherTaskFragment;
            } else {
                currentFragment = myTaskFragment;
            }
            changeFramgnt(R.id.layout_content, currentFragment);
            popWin.dismiss();
        }
    });
    popWin = new PopupWindow(v, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
    popWin.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.card_bg));
    // popWin.setFocusable(true);
    popWin.setOutsideTouchable(true); // popWin
    // 
    // popWin.showAtLocation(iv_sort, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); // ??
    popWin.showAsDropDown(iv_sort, 0, -iv_sort.getHeight() + 10);
}

From source file:cn.zhangls.android.weibo.ui.weibo.WeiboFrameProvider.java

/**
 * ????/*from   w w w .ja  va  2s . com*/
 *
 * @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.kccomy.orgar.ui.note.NoteFragment.java

private void initPopupWindow() {
    View popupWindowView = getActivity().getLayoutInflater().inflate(R.layout.popup_window_share, null);

    //??/*from w ww.j  av  a2  s.c o m*/
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addCategory(Intent.CATEGORY_DEFAULT);
    shareIntent.setType("text/plain");

    PackageManager packageManager = getContext().getPackageManager();
    List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(shareIntent,
            PackageManager.GET_RESOLVED_FILTER);

    // RecyclerAdapter
    RecyclerView recyclerView = (RecyclerView) popupWindowView.findViewById(R.id.popup_widow_share_recycler);
    ShareAdapter shareAdapter = new ShareAdapter(packageManager);
    shareAdapter.setData(resolveInfos);
    shareAdapter.setAppIconClickListener(shareListener);

    recyclerView.setAdapter(shareAdapter);
    recyclerView
            .setLayoutManager(new GridLayoutManager(getContext(), 2, LinearLayoutManager.HORIZONTAL, false));

    // ?PopupWindow
    popupWindowView.setFocusable(true);
    popupWindowView.setFocusableInTouchMode(true);

    PopupWindow popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);

    popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));

    popupWindow.setAnimationStyle(R.style.anim_menu_bottombar);

    setWindowAlpha(0.5f);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            setWindowAlpha(1f);
        }
    });

    popupWindow.showAtLocation(getActivity().getLayoutInflater().inflate(R.layout.fragment_note, null),
            Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ? /*from   w  w  w  . j a  v a  2s.  c  o m*/
 */
private void showAddPop() {
    final EditText editText = new EditText(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(layoutParams);
    //        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint("?~");
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));
    editText.setBackgroundColor(getResources().getColor(android.R.color.black));
    final PopupWindow popupWindow = new PopupWindow(editText, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                ProgressDialogUtils.showProgressDialog();
                UnFinishItem item = new UnFinishItem();
                Date date = new Date();
                item.createDay = date;
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                dataList.add(item);
                refreshData(true);
                presenter.addItem(item);
            }
        }
    });
}

From source file:org.huxizhijian.hhcomicviewer.ui.main.MainActivity.java

private void showHistory() {
    if (mSharedPreferences == null) {
        mSharedPreferences = getSharedPreferences("history", Context.MODE_PRIVATE);
    }//from   www .  j a  v a 2  s.c  om
    String group = mSharedPreferences.getString("keys", "");
    if (!TextUtils.isEmpty(group)) {
        //?
        String[] history = group.split(":@");
        mSearchHistory = new ArrayList<>();
        if (history.length > 6) {
            //6???????6??
            for (int i = history.length - 1; i >= history.length - 6; i--) {
                mSearchHistory.add(history[i]);
            }
        } else {
            for (int i = history.length - 1; i >= 0; i--) {
                mSearchHistory.add(history[i]);
            }
        }
        if (mHistoryListView == null || mHistoryAdapter == null) {
            //?list view
            mHistoryListView = new ListView(MainActivity.this);
            mHistoryAdapter = new CommonAdapter<String>(MainActivity.this, mSearchHistory,
                    R.layout.item_search_history_white) {
                @Override
                public void convert(ViewHolder vh, String s) {
                    final TextView tv = vh.getView(R.id.tv_search_history);
                    tv.setText(s);
                    vh.getView(R.id.ll_search_history).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            String query = (String) tv.getText();
                            if (!TextUtils.isEmpty(query)) {
                                mBinding.searchView.setQuery(query, true);
                            }
                        }
                    });
                    vh.getView(R.id.btn_search_text_set).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mBinding.searchView.setQuery(tv.getText(), false);
                        }
                    });
                }
            };
            mHistoryListView.setBackgroundColor(R.color.white);
            mHistoryListView.setAdapter(mHistoryAdapter);
            if (mHistoryListView.getFooterViewsCount() == 0 && mSearchHistory.size() != 0) {
                final View footerView = LayoutInflater.from(MainActivity.this)
                        .inflate(R.layout.item_search_history_footview_white, mHistoryListView, false);
                footerView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SharedPreferences.Editor editor = mSharedPreferences.edit();
                        editor.putString("keys", "");
                        editor.apply();
                        Toast.makeText(MainActivity.this, R.string.clear_successful, Toast.LENGTH_SHORT).show();
                        mHistoryPop.dismiss();
                    }
                });
                mHistoryListView.addFooterView(footerView);
            }
            mHistoryListView.setDividerHeight(0);
            mHistoryListView.setPadding(0, 1, 0, 0);
        } else {
            mHistoryAdapter.setDatas(mSearchHistory);
            mHistoryAdapter.notifyDataSetChanged();
        }
        if (mHistoryPop == null) {
            //?popup window
            mHistoryPop = new PopupWindow(mHistoryListView, mBinding.searchView.getWidth(),
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            mHistoryPop.setFocusable(false);
            mHistoryPop.setOutsideTouchable(false);
        }
        mHistoryPop.showAsDropDown(mBinding.searchView);
    }
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ???//  www  .j ava2s.  c om
 *
 * @param position
 */
private void modifyItem(final int position) {
    final UnFinishItem item = dataList.get(position);
    LogDetails.d(item);
    LinearLayout linearLayout = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black));

    final EditText editText = new EditText(MainActivity.this);
    editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint(item.content);
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));

    linearLayout.addView(editText);

    Button btnModify = new Button(MainActivity.this);
    btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnModify.setText("");
    btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnModify.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnModify);

    Button btnDeleteItem = new Button(MainActivity.this);
    btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnDeleteItem.setText("");
    btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnDeleteItem);

    final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    btnModify.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                Date date = new Date();
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                item.finishDay = null;
                ProgressDialogUtils.showProgressDialog();
                presenter.modifyItem(item);
                dataList.set(position, item);
                refreshData(true);
                popupWindow.dismiss();
            } else {
                Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show();
            }
        }
    });
    btnDeleteItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataList.remove(position);
            presenter.deleteItem(item);
            refreshData(false);
            popupWindow.dismiss();
        }
    });
}