Example usage for android.widget PopupWindow setTouchable

List of usage examples for android.widget PopupWindow setTouchable

Introduction

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

Prototype

public void setTouchable(boolean touchable) 

Source Link

Document

Changes the touchability of the popup window.

Usage

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

/**
 * ????//from  w ww .ja  v a2  s . c om
 *
 * @param holder
 * @param status
 */
private void setupPopupBar(final FrameHolder holder, final Status status) {
    LayoutInflater layoutInflater = LayoutInflater
            .from(holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext());
    // 
    final View popupView;
    if (status.isFavorited() && status.getUser().isFollowing()) {// ??
        popupView = layoutInflater.inflate(R.layout.popup_window_weibo_follow_save_post,
                holder.binding.flWeiboContainer, false);
    } else if (!status.isFavorited() && status.getUser().isFollowing()) {// ??
        popupView = layoutInflater.inflate(R.layout.popup_window_weibo_follow_unsave_post,
                holder.binding.flWeiboContainer, false);
    } else if (status.isFavorited() && !status.getUser().isFollowing()) {// ??
        popupView = layoutInflater.inflate(R.layout.popup_window_weibo_unfollow_save_post,
                holder.binding.flWeiboContainer, false);
    } else {// ??
        popupView = layoutInflater.inflate(R.layout.popup_window_weibo_unfollow_unsave_post,
                holder.binding.flWeiboContainer, false);
    }
    //  PopupWindow
    final PopupWindow popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    // popupWindow 
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Animation animation = AnimationUtils.loadAnimation(
                    holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext(),
                    R.anim.rotate_180_end);
            animation.setDuration(300);
            animation.setFillAfter(true);
            holder.binding.fgHomeWeiboPopupBar.startAnimation(animation);
        }
    });
    popupWindow.setAnimationStyle(R.style.PopupWindowAnimStyle);
    // popupWindow  Item ?
    if (status.isFavorited()) {// ??????
        popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_save_post)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        FavoritesAPI favoritesAPI = new FavoritesAPI(
                                mBinding.getRoot().getContext().getApplicationContext(),
                                AccessTokenKeeper.readAccessToken(
                                        mBinding.getRoot().getContext().getApplicationContext()));
                        BaseObserver<Favorite> observer = new BaseObserver<Favorite>(
                                mBinding.getRoot().getContext().getApplicationContext()) {
                            @Override
                            public void onNext(Favorite value) {
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
                            }

                            @Override
                            public void onComplete() {

                            }
                        };

                        favoritesAPI.destroy(observer, status.getId());

                        popupWindow.dismiss();
                    }
                });
    } else {
        popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_unsave_post)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        FavoritesAPI favoritesAPI = new FavoritesAPI(
                                mBinding.getRoot().getContext().getApplicationContext(),
                                AccessTokenKeeper.readAccessToken(
                                        mBinding.getRoot().getContext().getApplicationContext()));
                        BaseObserver<Favorite> observer = new BaseObserver<Favorite>(
                                mBinding.getRoot().getContext().getApplicationContext()) {
                            @Override
                            public void onNext(Favorite value) {
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
                            }

                            @Override
                            public void onComplete() {

                            }
                        };

                        favoritesAPI.create(observer, status.getId());

                        popupWindow.dismiss();
                    }
                });
    }
    if (status.getUser().isFollowing()) {// ????
        popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_follow)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        popupWindow.dismiss();
                    }
                });
    } else {
        popupWindow.getContentView().findViewById(R.id.menu_item_weibo_more_unfollow)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        popupWindow.dismiss();
                    }
                });
    }

    // ???
    holder.binding.fgHomeWeiboPopupBar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (popupWindow != null && !popupWindow.isShowing()) {
                Animation animation = AnimationUtils.loadAnimation(
                        holder.binding.fgHomeWeiboPopupBar.getContext().getApplicationContext(),
                        R.anim.rotate_180_start);
                animation.setDuration(300);
                animation.setFillAfter(true);
                holder.binding.fgHomeWeiboPopupBar.startAnimation(animation);
                popupWindow.showAsDropDown(holder.binding.fgHomeWeiboPopupBar);
            }
        }
    });
}

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

/**
 * ? //from  www .ja  v  a 2  s  .co 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:bruce.kk.brucetodos.MainActivity.java

/**
 * ???//  www.java  2  s  . c o  m
 *
 * @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();
        }
    });
}

From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java

@WorkerThread
private void showPopupAt(final LineNumber lineNumber, final String msg) {
    mHandler.post(new Runnable() {
        @Override//from   www  .j  av a 2  s  .  c  o m
        public void run() {
            if (isFinishing())
                return;
            //get relative position of expression at edittext
            Point position = mCodeView.getDebugPosition(lineNumber.getLine(), lineNumber.getColumn(),
                    Gravity.TOP);
            DLog.d(TAG, "generate: " + position);
            dismissPopup();
            //create new popup
            PopupWindow window = new PopupWindow(DebugActivity.this);
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View container = inflater.inflate(R.layout.popup_expr_result, null);
            container.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            int windowHeight = container.getMeasuredHeight();
            int windowWidth = container.getMeasuredWidth();

            window.setContentView(container);
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.setTouchable(true);
            window.setSplitTouchEnabled(true);
            window.setOutsideTouchable(true);

            window.showAtLocation(mCodeView, Gravity.NO_GRAVITY, position.x - windowWidth / 3,
                    position.y + toolbar.getHeight() - windowHeight);

            TextView txtResult = container.findViewById(R.id.txt_result);
            txtResult.setText(msg);
            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);
            alphaAnimation.setDuration(1000);
            alphaAnimation.setRepeatMode(Animation.REVERSE);
            alphaAnimation.setRepeatCount(Animation.INFINITE);
            txtResult.startAnimation(alphaAnimation);
            DebugActivity.this.mPopupWindow = window;
        }
    });
}

From source file:com.quwu.xinwo.release.Release_Activity.java

/**
 * //from  w  w w  .  ja  v  a  2 s  .  c  om
 * PopupWindow
 * 
 * */
private void showPopupWindow(View view, final int i) {

    // 
    View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.release_pop, null);

    final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, true);
    popupWindow.setOnDismissListener(new OnDismissListener() {

        public void onDismiss() {
            releaseLin.setAlpha(1f);
        }
    });
    popupWindow.setTouchable(true);

    popupWindow.setTouchInterceptor(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            return false;
            // true?touch
            // ? PopupWindowonTouchEvent?dismiss
        }
    });

    // ?PopupWindowBackdismiss
    // APIbug
    popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));

    // ???show
    int[] location = new int[2];
    view.getLocationOnScreen(location);

    popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] + view.getWidth(), location[1] - 150);

    // 
    TextView year = (TextView) contentView.findViewById(R.id.release_pop_yearText);
    year.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
    TextView month = (TextView) contentView.findViewById(R.id.release_pop_monthText);
    month.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
    TextView day = (TextView) contentView.findViewById(R.id.release_pop_dayText);
    day.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
}

From source file:com.example.libwidgettv.bak.AbsListView.java

/**
 * Creates the window for the text filter and populates it with an EditText
 * field;//  w  w  w  . java  2s .  c om
 * 
 * @param animateEntrance
 *            true if the window should appear with an animation
 */
private void createTextFilter(boolean animateEntrance) {
    if (mPopup == null) {
        Context c = getContext();
        PopupWindow p = new PopupWindow(c);
        LayoutInflater layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // mTextFilter = (EditText) layoutInflater.inflate(
        // com.android.internal.R.layout.typing_filter, null);
        mTextFilter = new EditText(getContext());
        // For some reason setting this as the "real" input type changes
        // the text view in some way that it doesn't work, and I don't
        // want to figure out why this is.
        mTextFilter.setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
        mTextFilter.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        mTextFilter.addTextChangedListener(this);
        p.setFocusable(false);
        p.setTouchable(false);
        p.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        p.setContentView(mTextFilter);
        p.setWidth(LayoutParams.WRAP_CONTENT);
        p.setHeight(LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        mPopup = p;
        getViewTreeObserver().addOnGlobalLayoutListener(this);
        mGlobalLayoutListenerAddedFilter = true;
    }
    // if (animateEntrance) {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilter);
    // } else {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilterRestore);
    // }
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Creates the window for the text filter and populates it with an EditText field;
 *
 * @param animateEntrance true if the window should appear with an animation
 *///from  w w w.  j a v  a  2s  . co  m
private void createTextFilter(boolean animateEntrance) {
    if (mPopup == null) {
        Context c = getContext();
        PopupWindow p = new PopupWindow(c);
        LayoutInflater layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mTextFilter = (EditText) layoutInflater.inflate(R.layout.typing_filter, null);
        // For some reason setting this as the "real" input type changes
        // the text view in some way that it doesn't work, and I don't
        // want to figure out why this is.
        mTextFilter.setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
        mTextFilter.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        mTextFilter.addTextChangedListener(this);
        p.setFocusable(false);
        p.setTouchable(false);
        p.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        p.setContentView(mTextFilter);
        p.setWidth(LayoutParams.WRAP_CONTENT);
        p.setHeight(LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        mPopup = p;
        getViewTreeObserver().addOnGlobalLayoutListener(this);
        mGlobalLayoutListenerAddedFilter = true;
    }
    if (animateEntrance) {
        mPopup.setAnimationStyle(R.style.Animation_TypingFilter);
    } else {
        mPopup.setAnimationStyle(R.style.Animation_TypingFilterRestore);
    }
}