Java Code Examples for android.widget.PopupWindow#update()

The following examples show how to use android.widget.PopupWindow#update() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverflowHelper.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
public OverflowHelper(Context ctx) {
    mContext = ctx;
    mNormalColor = mContext.getResources().getColor(R.color.white);
    mDisabledColor = mContext.getResources().getColor(R.color.text_disabled);
    mPopupLayout = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.comm_popup_menu, null, true);
    mListView = (PopupMenuListView) mPopupLayout.findViewById(R.id.comm_popup_list);
    mAdapter = new OverflowAdapter(this, ctx);
    mListView.setAdapter(mAdapter);
    mListView.setOnKeyListener(mOnKeyListener);
    mPopupWindow = new PopupWindow(mPopupLayout, -2, -2, true);
    mPopupWindow.setContentView(mPopupLayout);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setWidth(414);
    mPopupWindow.getContentView().setOnTouchListener(mOnTouchListener);
    mPopupWindow.update();
}
 
Example 2
Source File: ImitateTaobaoRetractionActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
private PopupWindow shwoPop(int witch, int hight_bottom, boolean isDown, int gravity, View... views) {
    PopupWindow popWindow = new PopupWindow(views[0], witch, LinearLayout.LayoutParams.MATCH_PARENT);
    popWindow.setOutsideTouchable(true);
    popWindow.setFocusable(true);
    popWindow.setTouchable(true);
    popWindow.setBackgroundDrawable(new BitmapDrawable());// 点击空白时popupwindow关闭
    int[] location = new int[2];
    try {
        views[1].getLocationOnScreen(location);
        popWindow.showAtLocation(views[1], gravity, 10, hight_bottom);
        popWindow.update();
    } catch (Exception e) {
        Logger.e(e);
    }
    return popWindow;
}
 
Example 3
Source File: DropPopMenu.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
private void initList() {
	View popupWindow_view = LayoutInflater.from(context).inflate(
			R.layout.droppopmenu, null);
	popupWindow_view.setFocusableInTouchMode(true);
	// 设置popupWindow的布局
	popupWindow = new PopupWindow(popupWindow_view,
			WindowManager.LayoutParams.WRAP_CONTENT,
			WindowManager.LayoutParams.WRAP_CONTENT);
	popupWindow.setTouchable(true);
	popupWindow.setFocusable(true);
	// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
	popupWindow.setBackgroundDrawable(new ColorDrawable(
			android.R.color.transparent));
	// 设置允许在外点击消失
	popupWindow.setOutsideTouchable(true);
	listView = (ListView) popupWindow_view
			.findViewById(R.id.droppopmenu_listView);
	popupWindow.update();
}
 
Example 4
Source File: PopWindowImg.java    From Android with MIT License 5 votes vote down vote up
private void touchLong() {
    LogManager.getLogger().d(Tag, "touchLong");

    View gifView = LayoutInflater.from(getContext()).inflate(R.layout.view_popupimg, null);
    GifView gif = (GifView) gifView.findViewById(R.id.gif);
    gif.setGifResource(filePath);
    gif.play();

    int[] location = SystemUtil.locationOnScreen(this);
    window = new PopupWindow(gifView, SystemUtil.dipToPx(100), SystemUtil.dipToPx(100));
    window.setAnimationStyle(R.style.Dialog);
    window.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_trans_while));
    window.setFocusable(true);
    window.setOutsideTouchable(true);
    window.update();

    //location[1] = location[1] - getHeight();

    if ((location[0] - SystemUtil.dipToPx(25) - SystemUtil.dipToPx(10)) <= SystemUtil.dipToPx(10)) {
        location[0] = SystemUtil.dipToPx(10);
    } else if ((location[0] - SystemUtil.dipToPx(25) + SystemUtil.dipToPx(100) + SystemUtil.dipToPx(20)) >= SystemDataUtil.getScreenWidth()) {
        location[0] = SystemDataUtil.getScreenWidth() - SystemUtil.dipToPx(10) - SystemUtil.dipToPx(100);
    } else {
        location[0] = location[0] - SystemUtil.dipToPx(25);
    }
    window.showAtLocation(this, Gravity.TOP | Gravity.START, location[0], location[1] - SystemUtil.dipToPx(100));
}
 
Example 5
Source File: KeyboardView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length) return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null,
                key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width
            + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = - mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero

    // Set the preview background state
    mPreviewText.getBackground().setState(
            key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];

    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // If the key you're pressing is on the left side of the keyboard, show the popup on
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }

    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY,
                popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
                mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
 
Example 6
Source File: MyKeyboardView.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length) return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null,
                key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width
            + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = -mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero

    // Set the preview background state
    mPreviewText.getBackground().setState(
            key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];

    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // If the key you're pressing is on the left side of the keyboard, show the popup on
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }

    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY,
                popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
                mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
 
Example 7
Source File: CustomKeyboardView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length) return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null,
                key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width
            + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft();
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = - mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero

    // Set the preview background state
    mPreviewText.getBackground().setState(
            key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];

    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // If the key you're pressing is on the left side of the keyboard, show the popup on
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }

    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY,
                popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
                mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
 
Example 8
Source File: PlayActivity.java    From Yuan-SxMusic with Apache License 2.0 4 votes vote down vote up
private void changePlayMode() {
    View playModeView = LayoutInflater.from(this).inflate(R.layout.play_mode, null);
    ConstraintLayout orderLayout = playModeView.findViewById(R.id.orderLayout);
    ConstraintLayout randomLayout = playModeView.findViewById(R.id.randomLayout);
    ConstraintLayout singleLayout = playModeView.findViewById(R.id.singleLayout);
    TextView orderTv = playModeView.findViewById(R.id.orderTv);
    TextView randomTv = playModeView.findViewById(R.id.randomTv);
    TextView singleTv = playModeView.findViewById(R.id.singleTv);

    //显示弹窗
    PopupWindow popupWindow = new PopupWindow(playModeView, ScreenUtil.dip2px(this, 130), ScreenUtil.dip2px(this, 150));
    //设置背景色
    popupWindow.setBackgroundDrawable(getDrawable(R.color.transparent));
    //设置焦点
    popupWindow.setFocusable(true);
    //设置可以触摸框以外的地方
    popupWindow.setOutsideTouchable(true);
    popupWindow.update();
    //设置弹出的位置
    popupWindow.showAsDropDown(mPlayModeBtn, 0, -50);


    //显示播放模式
    int mode = mPresenter.getPlayMode();
    if (mode == Constant.PLAY_ORDER) {
        orderTv.setSelected(true);
        randomTv.setSelected(false);
        singleTv.setSelected(false);
    } else if (mode == Constant.PLAY_RANDOM) {
        randomTv.setSelected(true);
        orderTv.setSelected(false);
        singleTv.setSelected(false);
    } else {
        singleTv.setSelected(true);
        randomTv.setSelected(false);
        orderTv.setSelected(false);
    }


    //顺序播放
    orderLayout.setOnClickListener(view -> {
        mPlayStatusBinder.setPlayMode(Constant.PLAY_ORDER); //通知服务
        mPresenter.setPlayMode(Constant.PLAY_ORDER);
        popupWindow.dismiss();
        mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_order));

    });
    //随机播放
    randomLayout.setOnClickListener(view -> {
        mPlayStatusBinder.setPlayMode(Constant.PLAY_RANDOM);
        mPresenter.setPlayMode(Constant.PLAY_RANDOM);
        popupWindow.dismiss();
        mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_random));
    });
    //单曲循环
    singleLayout.setOnClickListener(view -> {
        mPlayStatusBinder.setPlayMode(Constant.PLAY_SINGLE);
        mPresenter.setPlayMode(Constant.PLAY_SINGLE);
        popupWindow.dismiss();
        mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_single));
    });


}
 
Example 9
Source File: KeyboardView.java    From libcommon with Apache License 2.0 4 votes vote down vote up
private void showKey(final int keyIndex) {
	final PopupWindow previewPopup = mPreviewPopup;
	final Keyboard.Key[] keys = mKeys;
	if (keyIndex < 0 || keyIndex >= mKeys.length) return;
	Keyboard.Key key = keys[keyIndex];
	if (key.icon != null) {
		mPreviewText.setCompoundDrawables(null, null, null,
			key.iconPreview != null ? key.iconPreview : key.icon);
		mPreviewText.setText(null);
	} else {
		mPreviewText.setCompoundDrawables(null, null, null, null);
		mPreviewText.setText(getPreviewText(key));
		if (key.label.length() > 1 && key.codes.length < 2) {
			mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
			mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
		} else {
			mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
			mPreviewText.setTypeface(Typeface.DEFAULT);
		}
	}
	mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
		MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
	int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width
		+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
	final int popupHeight = mPreviewHeight;
	ViewGroup.LayoutParams lp = mPreviewText.getLayoutParams();
	if (lp != null) {
		lp.width = popupWidth;
		lp.height = popupHeight;
	}
	int popupPreviewX;
	int popupPreviewY;
	if (!mPreviewCentered) {
		popupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft();
		popupPreviewY = key.y - popupHeight + mPreviewOffset;
	} else {
		// TODO: Fix this if centering is brought back
		popupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
		popupPreviewY = -mPreviewText.getMeasuredHeight();
	}
	mHandler.removeMessages(MSG_REMOVE_PREVIEW);
	getLocationInWindow(mCoordinates);
	mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero
	mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero

	// Set the preview background state
	mPreviewText.getBackground().setState(
		key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
	popupPreviewX += mCoordinates[0];
	popupPreviewY += mCoordinates[1];

	// If the popup cannot be shown above the key, put it on the side
	getLocationOnScreen(mCoordinates);
	if (popupPreviewY + mCoordinates[1] < 0) {
		// If the key you're pressing is on the left side of the keyboard, show the popup on
		// the right, offset by enough to see at least one key to the left/right.
		if (key.x + key.width <= getWidth() / 2) {
			popupPreviewX += (int) (key.width * 2.5);
		} else {
			popupPreviewX -= (int) (key.width * 2.5);
		}
		popupPreviewY += popupHeight;
	}

	if (previewPopup.isShowing()) {
		previewPopup.update(popupPreviewX, popupPreviewY,
			popupWidth, popupHeight);
	} else {
		previewPopup.setWidth(popupWidth);
		previewPopup.setHeight(popupHeight);
		previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
			popupPreviewX, popupPreviewY);
	}
	mPreviewText.setVisibility(VISIBLE);
}