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) 

Source Link

Document

Display the content view in a popup window anchored to the bottom-left corner of the anchor view.

Usage

From source file:Main.java

public static void toggle(PopupWindow window, View view) {
    if (null != window) {
        if (window.isShowing())
            window.dismiss();//from   w  ww. j  a  v a  2  s .co m
        else
            window.showAsDropDown(view);
    }
}

From source file:Main.java

public static PopupWindow showPopWindow(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);//from w  w w.  jav a2 s . c  o m
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(targetView);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow//from w w w .  java2  s .c  o m
 */
public static PopupWindow showPopWindow(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(targetView);
    return popupWindow;
}

From source file:com.dycody.android.idealnote.SketchFragment.java

private void showPopup(View anchor, final int eraserOrStroke) {

    boolean isErasing = eraserOrStroke == SketchView.ERASER;

    oldColor = mColorPicker.getColor();//  w  ww.  ja  v a2 s  . c  o  m

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // Creating the PopupWindow
    PopupWindow popup = new PopupWindow(getActivity());
    popup.setContentView(isErasing ? popupEraserLayout : popupLayout);
    popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setFocusable(true);
    popup.setOnDismissListener(() -> {
        if (mColorPicker.getColor() != oldColor)
            mColorPicker.setOldCenterColor(oldColor);
    });

    // Clear the default translucent background
    popup.setBackgroundDrawable(new BitmapDrawable());

    // Displaying the popup at the specified location, + offsets (transformed 
    // dp to pixel to support multiple screen sizes)
    popup.showAsDropDown(anchor);

    // Stroke size seekbar initialization and event managing
    SeekBar mSeekBar;
    mSeekBar = (SeekBar) (isErasing ? popupEraserLayout.findViewById(R.id.stroke_seekbar)
            : popupLayout.findViewById(R.id.stroke_seekbar));
    mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // When the seekbar is moved a new size is calculated and the new shape
            // is positioned centrally into the ImageView
            setSeekbarProgress(progress, eraserOrStroke);
        }
    });
    int progress = isErasing ? seekBarEraserProgress : seekBarStrokeProgress;
    mSeekBar.setProgress(progress);
}

From source file:com.zhangyp.higo.drawingboard.fragment.SketchFragment.java

private void showPopup(View anchor, final int eraserOrStroke) {

    boolean isErasing = eraserOrStroke == SketchView.ERASER;

    oldColor = mColorPicker.getColor();/*from   w w w . java  2 s .  co  m*/

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // Creating the PopupWindow
    PopupWindow popup = new PopupWindow(getActivity());
    popup.setContentView(isErasing ? popupEraserLayout : popupLayout);
    popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setFocusable(true);
    popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {

            if (mColorPicker.getColor() != oldColor)
                mColorPicker.setOldCenterColor(oldColor);
        }
    });

    // Clear the default translucent background
    popup.setBackgroundDrawable(new BitmapDrawable());

    // Displaying the popup at the specified location, + offsets (transformed 
    // dp to pixel to support multiple screen sizes)
    popup.showAsDropDown(anchor);

    // Stroke size seekbar initialization and event managing
    SeekBar mSeekBar;
    mSeekBar = (SeekBar) (isErasing ? popupEraserLayout.findViewById(R.id.stroke_seekbar)
            : popupLayout.findViewById(R.id.stroke_seekbar));
    mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // When the seekbar is moved a new size is calculated and the new shape
            // is positioned centrally into the ImageView
            setSeekbarProgress(progress, eraserOrStroke);
        }
    });
    int progress = isErasing ? seekBarEraserProgress : seekBarStrokeProgress;
    mSeekBar.setProgress(progress);
}

From source file:xj.property.activity.HXBaseActivity.ChatActivity.java

private void showPopWindow2() {

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View mMenuView = inflater.inflate(R.layout.unservice_time, null);
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setText("?"
            + MainActivity.startTime + "-" + MainActivity.endTime
            + "????");
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime))
            .setTextSize(getResources().getDimension(R.dimen.tv_unservicetime));
    final PopupWindow popupWindow = new PopupWindow();
    // ?/* w  w  w  .j a va  2 s  .  c  o  m*/
    // SelectPicPopupWindowView
    popupWindow.setContentView(mMenuView);
    // SelectPicPopupWindow
    popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
    // SelectPicPopupWindow
    popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
    // SelectPicPopupWindow?
    //        this.setFocusable(true);
    // SelectPicPopupWindow
    //  popupWindow.setAnimationStyle(R.style.AnimTop);
    TranslateAnimation translateAnimation = new TranslateAnimation(0, 0.0f, 0, 200f);
    translateAnimation.setDuration(2000);
    translateAnimation.setFillAfter(true);
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setAnimation(translateAnimation);
    translateAnimation.start();
    // ColorDrawable??
    ColorDrawable dw = new ColorDrawable(0xb0000000);
    // SelectPicPopupWindow
    // mMenuViewOnTouchListener??????
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // ,Animation.RELATIVE_TO_SELF,10f,Animation.RELATIVE_TO_SELF,10f
            popupWindow.showAsDropDown(findViewById(R.id.top_bar));
            //popupWindow.showAtLocation(findViewById(R.id.list),Gravity.NO_GRAVITY,0,0);
        }
    }, 200);

}

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

/**
 * ????/*from  w w  w.  j  av  a 2  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);
            }
        }
    });
}