Search in sources :

Example 41 with PopupWindow

use of android.widget.PopupWindow in project SmartMesh_Android by SmartMeshFoundation.

the class MainMessageFragmentUI method initHomePop.

/**
 * Initialize the Pop layout
 */
private void initHomePop() {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.contact_more_popup_layout, null);
    homePop = new PopupWindow(view, Utils.dip2px(getActivity(), 170), LinearLayout.LayoutParams.WRAP_CONTENT);
    homePop.setBackgroundDrawable(new BitmapDrawable());
    homePop.setOutsideTouchable(true);
    homePop.setFocusable(true);
    view.findViewById(R.id.txt_home_pop_1).setOnClickListener(this);
    view.findViewById(R.id.txt_home_pop_2).setOnClickListener(this);
    view.findViewById(R.id.txt_home_pop_3).setOnClickListener(this);
    if (homePop.isShowing()) {
        homePop.dismiss();
    } else {
        // On the coordinates of a specific display PopupWindow custom menu
        homePop.showAsDropDown(mRightBtn, Utils.dip2px(getActivity(), -110), Utils.dip2px(getActivity(), 0));
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 42 with PopupWindow

use of android.widget.PopupWindow in project MyApp by MatthewDevelop.

the class CustomPopWindow method build.

private PopupWindow build() {
    if (mContentView == null) {
        mContentView = LayoutInflater.from(mContext).inflate(mResLayoutId, null);
    }
    // 2017.3.17 add
    // 获取当前Activity的window
    Activity activity = (Activity) mContentView.getContext();
    if (activity != null && mIsBackgroundDark) {
        // 如果设置的值在0 - 1的范围内,则用设置的值,否则用默认值
        final float alpha = (mBackgroundDrakValue > 0 && mBackgroundDrakValue < 1) ? mBackgroundDrakValue : DEFAULT_ALPHA;
        mWindow = activity.getWindow();
        WindowManager.LayoutParams params = mWindow.getAttributes();
        params.alpha = alpha;
        mWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        mWindow.setAttributes(params);
    }
    if (mWidth != 0 && mHeight != 0) {
        mPopupWindow = new PopupWindow(mContentView, mWidth, mHeight);
    } else {
        mPopupWindow = new PopupWindow(mContentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    if (mAnimationStyle != -1) {
        mPopupWindow.setAnimationStyle(mAnimationStyle);
    }
    // 设置一些属性
    apply(mPopupWindow);
    if (mWidth == 0 || mHeight == 0) {
        mPopupWindow.getContentView().measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        // 如果外面没有设置宽高的情况下,计算宽高并赋值
        mWidth = mPopupWindow.getContentView().getMeasuredWidth();
        mHeight = mPopupWindow.getContentView().getMeasuredHeight();
    }
    // 添加dissmiss 监听
    mPopupWindow.setOnDismissListener(this);
    // 判断是否点击PopupWindow之外的地方关闭 popWindow
    if (!enableOutsideTouchDisMiss) {
        // 注意这三个属性必须同时设置,不然不能disMiss,以下三行代码在Android 4.4 上是可以,然后在Android 6.0以上,下面的三行代码就不起作用了,就得用下面的方法
        mPopupWindow.setFocusable(true);
        mPopupWindow.setOutsideTouchable(false);
        mPopupWindow.setBackgroundDrawable(null);
        // 注意下面这三个是contentView 不是PopupWindow
        mPopupWindow.getContentView().setFocusable(true);
        mPopupWindow.getContentView().setFocusableInTouchMode(true);
        mPopupWindow.getContentView().setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    mPopupWindow.dismiss();
                    return true;
                }
                return false;
            }
        });
        // 在Android 6.0以上 ,只能通过拦截事件来解决
        mPopupWindow.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                final int x = (int) event.getX();
                final int y = (int) event.getY();
                if ((event.getAction() == MotionEvent.ACTION_DOWN) && ((x < 0) || (x >= mWidth) || (y < 0) || (y >= mHeight))) {
                    Log.e(TAG, "out side ");
                    Log.e(TAG, "width:" + mPopupWindow.getWidth() + "height:" + mPopupWindow.getHeight() + " x:" + x + " y  :" + y);
                    return true;
                } else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    Log.e(TAG, "out side ...");
                    return true;
                }
                return false;
            }
        });
    } else {
        mPopupWindow.setFocusable(mIsFocusable);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mPopupWindow.setOutsideTouchable(mIsOutside);
    }
    // update
    mPopupWindow.update();
    return mPopupWindow;
}
Also used : PopupWindow(android.widget.PopupWindow) Activity(android.app.Activity) View(android.view.View) WindowManager(android.view.WindowManager) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) ColorDrawable(android.graphics.drawable.ColorDrawable)

Example 43 with PopupWindow

use of android.widget.PopupWindow in project SmartMesh_Android by SmartMeshFoundation.

the class DropTextView method init.

private void init(Context context) {
    mPopup = new PopupWindow(mPopView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mPopup.setBackgroundDrawable(getResources().getDrawable(R.color.transparent));
    // Let popwin get focus
    mPopup.setFocusable(true);
}
Also used : PopupWindow(android.widget.PopupWindow)

Example 44 with PopupWindow

use of android.widget.PopupWindow in project GomoTest by suReZj.

the class PaintFragment method initStokeWidthPopWindow.

private void initStokeWidthPopWindow() {
    popView = LayoutInflater.from(activity).inflate(R.layout.view_set_stoke_width, null);
    setStokenWidthWindow = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    mStokenWidthSeekBar = (SeekBar) popView.findViewById(R.id.stoke_width_seekbar);
    setStokenWidthWindow.setFocusable(true);
    setStokenWidthWindow.setOutsideTouchable(true);
    setStokenWidthWindow.setBackgroundDrawable(new BitmapDrawable());
    setStokenWidthWindow.setAnimationStyle(R.style.popwin_anim_style);
    mPaintModeView.setPaintStrokeColor(Color.RED);
    mPaintModeView.setPaintStrokeWidth(10);
    updatePaintView();
}
Also used : PopupWindow(android.widget.PopupWindow) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 45 with PopupWindow

use of android.widget.PopupWindow in project BestPracticeApp by pop1234o.

the class MainPopUpWindowActivity method showPop.

private void showPop() {
    final PopupWindow popupWindow = new PopupWindow(this, null, R.style.bottomDialog);
    View view = LayoutInflater.from(this).inflate(R.layout.popup, null);
    popupWindow.setContentView(view);
    popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setTouchable(true);
    // popupWindow.setAnimationStyle(R.style.);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#88000000")));
    // popupWindow.showAsDropDown(mButton7, 0, -mButton7.getHeight());//在view下方
    // 如果是0,0的话,默认是在这个view(anchor锚)的左下角作为起始点
    // Gravity.RIGHT代表在view的右下角开始 这个是api19开始支持
    // 这种显示方式如果是和view无关,里面只是为了获得token
    popupWindow.showAtLocation(mButton7, Gravity.BOTTOM | Gravity.LEFT, 100, 200);
// 这个x y的位置是先计算重力所在的位置,然后再以那个位置为左上角,x,y是相对位置
// 如果是Gravity.BOTTOM   设置y值不能为负值
// 设置了重力后坐标系的方向就变了,如果是Gravity.BOTTOM 那么y轴的方向就是向上
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) PopupWindow(android.widget.PopupWindow) View(android.view.View)

Aggregations

PopupWindow (android.widget.PopupWindow)133 View (android.view.View)66 TextView (android.widget.TextView)48 ColorDrawable (android.graphics.drawable.ColorDrawable)27 ImageView (android.widget.ImageView)24 Paint (android.graphics.Paint)22 Key (android.inputmethodservice.Keyboard.Key)14 AdapterView (android.widget.AdapterView)14 LinearLayout (android.widget.LinearLayout)14 LayoutInflater (android.view.LayoutInflater)13 Button (android.widget.Button)13 ListView (android.widget.ListView)13 Activity (android.app.Activity)12 BitmapDrawable (android.graphics.drawable.BitmapDrawable)12 OnClickListener (android.view.View.OnClickListener)11 ViewGroup (android.view.ViewGroup)11 Context (android.content.Context)10 Resources (android.content.res.Resources)10 EditText (android.widget.EditText)10 ScrollView (android.widget.ScrollView)10