@SuppressLint("NewApi") public void show(View item, int type, boolean bResend, boolean bSelf) { if (mPopup == null || mPopup.isShowing()) { return; } boolean showTop = true; int[] location = new int[2]; item.getLocationOnScreen(location); // 默认在item上面弹出 if (location[1] - mParentTop /* - mHeight */ <= 0) { // showTop = false; } else { // 如果不是在最顶部,显示的距离要上移10 location[1] = location[1] - 10; } if (type == 2) { speakerBtn.setVisibility(View.VISIBLE); if (MessageActivity.getAudioMode() == SysConstant.AUDIO_PLAY_MODE_NORMAL) { speakerBtn.setText(R.string.call_mode); } else { speakerBtn.setText(R.string.speaker_mode); } bspeakerShow = true; } else { speakerBtn.setVisibility(View.GONE); bspeakerShow = false; } if (bResend && bSelf) { resendBtn.setVisibility(View.VISIBLE); bresendShow = true; if (type == 1) { copyBtn.setVisibility(View.VISIBLE); bcopyShow = true; } else { copyBtn.setVisibility(View.GONE); bcopyShow = false; } } else if (!bResend && bSelf) { resendBtn.setVisibility(View.GONE); bresendShow = false; if (type != 2 && type != 3) { copyBtn.setVisibility(View.VISIBLE); bcopyShow = true; } else if (type != 2) { copyBtn.setVisibility(View.GONE); bcopyShow = false; return; } else { copyBtn.setVisibility(View.GONE); bcopyShow = false; } } else { if (type != 2 && type != 3) { copyBtn.setVisibility(View.VISIBLE); bcopyShow = true; } else if (type != 2) { copyBtn.setVisibility(View.GONE); bcopyShow = false; return; } else { copyBtn.setVisibility(View.GONE); bcopyShow = false; } } Resources resource = context.getResources(); if (bcopyShow && bresendShow) { // int nWidth = (int) resource // .getDimension(R.dimen.message_item_popup_width_double_short); mWidth = (int) resource.getDimension(R.dimen.message_item_popup_width_double_short); mPopup.setWidth(mWidth); Drawable bgLeft = resource.getDrawable(R.drawable.tt_bg_popup_left_nomal); copyBtn.setBackground(bgLeft); copyBtn.setPadding(0, 13, 0, 8); Drawable bgRight = resource.getDrawable(R.drawable.tt_bg_popup_right_nomal); resendBtn.setBackground(bgRight); resendBtn.setPadding(0, 13, 0, 8); } else if (bcopyShow || bresendShow) { if (bspeakerShow) { // int nWidth = (int) resource // .getDimension(R.dimen.message_item_popup_width_double_long); mWidth = (int) resource.getDimension(R.dimen.message_item_popup_width_double_long); mPopup.setWidth(mWidth); Drawable bgLeft = resource.getDrawable(R.drawable.tt_bg_popup_left_nomal); speakerBtn.setBackground(bgLeft); Drawable bgRight = resource.getDrawable(R.drawable.tt_bg_popup_right_nomal); speakerBtn.setPadding(0, 13, 0, 8); resendBtn.setBackground(bgRight); resendBtn.setPadding(0, 13, 0, 8); } else { // int nWidth = (int) resource // .getDimension(R.dimen.message_item_popup_width_single_short); mWidth = (int) resource.getDimension(R.dimen.message_item_popup_width_single_short); mPopup.setWidth(mWidth); Drawable bgNormal = resource.getDrawable(R.drawable.tt_bg_popup_normal); copyBtn.setBackground(bgNormal); resendBtn.setBackground(bgNormal); copyBtn.setPadding(0, 13, 0, 8); resendBtn.setPadding(0, 13, 0, 8); } } else if (bspeakerShow) { // int nWidth = (int) resource // .getDimension(R.dimen.message_item_popup_width_single_long); mWidth = (int) resource.getDimension(R.dimen.message_item_popup_width_single_long); mPopup.setWidth(mWidth); Drawable bgNormal = resource.getDrawable(R.drawable.tt_bg_popup_normal); speakerBtn.setBackground(bgNormal); speakerBtn.setPadding(0, 13, 0, 8); } else { return; } if (showTop) { if (location[1] - mParentTop /* - mHeight */ > 0) { mPopup.showAtLocation( item, Gravity.NO_GRAVITY, location[0] + (item.getWidth() / 2 - mWidth / 2), location[1] - mHeight); } else { mPopup.showAtLocation( item, Gravity.NO_GRAVITY, location[0] + (item.getWidth() / 2 - mWidth / 2), 0 + mHeight / 2); } } else { // TODO: 在下面弹出的时候需要翻转背景 mPopup.showAtLocation( item, Gravity.NO_GRAVITY, location[0] + (item.getWidth() / 2 - mWidth / 2), location[1] + item.getHeight()); } }