Java Code Examples for android.widget.PopupWindow#setHeight()
The following examples show how to use
android.widget.PopupWindow#setHeight() .
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: ViemoPlayerMenu.java From Android-VimeoPlayer with MIT License | 6 votes |
@NonNull private PopupWindow createPopupWindow() { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if(inflater == null) throw new RuntimeException("can't access LAYOUT_INFLATER_SERVICE"); View view = inflater.inflate(R.layout.player_menu, null); RecyclerView recyclerView = view.findViewById(R.id.recycler_view); setUpRecyclerView(recyclerView); PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); popupWindow.setContentView(view); return popupWindow; }
Example 2
Source File: InsertionHandleController.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
public PastePopupMenu() { mContainer = new PopupWindow(mContext, null, android.R.attr.textSelectHandleWindowStyle); mContainer.setSplitTouchEnabled(true); mContainer.setClippingEnabled(false); mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); final int[] POPUP_LAYOUT_ATTRS = { android.R.attr.textEditPasteWindowLayout, android.R.attr.textEditNoPasteWindowLayout, android.R.attr.textEditSidePasteWindowLayout, android.R.attr.textEditSideNoPasteWindowLayout, }; mPasteViews = new View[POPUP_LAYOUT_ATTRS.length]; mPasteViewLayouts = new int[POPUP_LAYOUT_ATTRS.length]; TypedArray attrs = mContext.obtainStyledAttributes(POPUP_LAYOUT_ATTRS); for (int i = 0; i < attrs.length(); ++i) { mPasteViewLayouts[i] = attrs.getResourceId(attrs.getIndex(i), 0); } attrs.recycle(); }
Example 3
Source File: LongShowPopupActivity.java From AndroidSamples with Apache License 2.0 | 6 votes |
private void showPopupWindow(int x, int y) { View contentView = LayoutInflater.from(LongShowPopupActivity.this).inflate(R.layout.show_as_drop_down_activity_popup, null); mPopWindow = new PopupWindow(contentView); mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); TextView tv1 = contentView.findViewById(R.id.pop_computer); TextView tv2 = contentView.findViewById(R.id.pop_financial); TextView tv3 = contentView.findViewById(R.id.pop_manage); tv1.setOnClickListener(this); tv2.setOnClickListener(this); tv3.setOnClickListener(this); View rootview = LayoutInflater.from(LongShowPopupActivity.this).inflate(R.layout.activity_long_show_popup, null); mPopWindow.showAtLocation(rootview, Gravity.NO_GRAVITY, x, y); }
Example 4
Source File: SelectRemindWayPopup.java From Android-AlarmManagerClock with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public SelectRemindWayPopup(Context context) { mContext = context; mPopupWindow = new PopupWindow(context); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT); mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT); mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setAnimationStyle(R.style.AnimBottom); mPopupWindow.setContentView(initViews()); mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mPopupWindow.setFocusable(false); mPopupWindow.dismiss(); return true; } }); }
Example 5
Source File: SelectRemindCyclePopup.java From Android-AlarmManagerClock with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public SelectRemindCyclePopup(Context context) { mContext = context; mPopupWindow = new PopupWindow(context); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT); mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT); mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setAnimationStyle(R.style.AnimBottom); mPopupWindow.setContentView(initViews()); mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mPopupWindow.setFocusable(false); // mPopupWindow.dismiss(); return true; } }); }
Example 6
Source File: ProgressDialog.java From XERUNG with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public void progressPopUp(final Activity context,String data){ RelativeLayout layoutId = (RelativeLayout)context.findViewById(R.id.dialog_rootView); LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.progresspopup, layoutId); txtWaiting = (TextView)layout.findViewById(R.id.txtWaiting); paymentAlert = new PopupWindow(context); paymentAlert.setContentView(layout); paymentAlert.setHeight(WindowManager.LayoutParams.MATCH_PARENT); paymentAlert.setWidth(WindowManager.LayoutParams.MATCH_PARENT); paymentAlert.setFocusable(true); paymentAlert.setBackgroundDrawable(new BitmapDrawable()); paymentAlert.showAtLocation(layout, Gravity.CENTER, 0, 0); if(data !=null) txtWaiting.setText(data); }
Example 7
Source File: ProgressDialog.java From XERUNG with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public void progressPopUp(final Activity context,String data){ RelativeLayout layoutId = (RelativeLayout)context.findViewById(R.id.dialog_rootView); LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.progresspopup, layoutId); txtWaiting = (TextView)layout.findViewById(R.id.txtWaiting); paymentAlert = new PopupWindow(context); paymentAlert.setContentView(layout); paymentAlert.setHeight(WindowManager.LayoutParams.MATCH_PARENT); paymentAlert.setWidth(WindowManager.LayoutParams.MATCH_PARENT); paymentAlert.setFocusable(true); paymentAlert.setBackgroundDrawable(new BitmapDrawable()); paymentAlert.showAtLocation(layout, Gravity.CENTER, 0, 0); if(data !=null) txtWaiting.setText(data); }
Example 8
Source File: ShoppingDetailActivity.java From ShoppingCartActivity with Apache License 2.0 | 6 votes |
/** * 弹出悬浮窗体,显示菜单 */ private void popuWindowDialog() { LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.task_detail_popupwindow, null); LinearLayout linMessage= (LinearLayout) layout.findViewById(R.id.popuMessage); LinearLayout linMain= (LinearLayout) layout.findViewById(R.id.popuMain); LinearLayout linShare= (LinearLayout) layout.findViewById(R.id.popuShare); linMessage.setOnClickListener(this); linMain.setOnClickListener(this); linShare.setOnClickListener(this); pwMyPopWindow = new PopupWindow(layout); pwMyPopWindow.setFocusable(true); // 加上这个popupwindow中的ListView才可以接收点击事件 // 控制popupwindow的宽度和高度自适应 pwMyPopWindow.setWidth(400); pwMyPopWindow.setHeight(300); // 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功,如上 pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.bg_popupwindow)); // 控制popupwindow点击屏幕其他地方消失 pwMyPopWindow.setOutsideTouchable(true); }
Example 9
Source File: MainActivity.java From UseTimeStatistic with MIT License | 6 votes |
private void showPopWindow(){ View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.popuplayout, null); mPopupWindow = new PopupWindow(contentView); mPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mRvSelectDate = contentView.findViewById(R.id.rv_select_date); SelectDateAdapter adapter = new SelectDateAdapter(mDateList); adapter.setOnItemClickListener(new SelectDateAdapter.OnRecyclerViewItemClickListener() { @Override public void onItemClick(View view, int position) { mUseTimeDataManager.refreshData(position); showView(position); mPopupWindow.dismiss(); isShowing = false; } }); mRvSelectDate.setAdapter(adapter); mRvSelectDate.setLayoutManager(new LinearLayoutManager(this)); mPopupWindow.showAsDropDown(mBtnDate); isShowing = true; }
Example 10
Source File: BootstrapDropDown.java From Android-Bootstrap with MIT License | 6 votes |
private void createDropDown() { ScrollView dropdownView = createDropDownView(); dropdownWindow = new PopupWindow(); dropdownWindow.setFocusable(true); dropdownWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); if (!isInEditMode()) { dropdownWindow.setBackgroundDrawable(DrawableUtils.resolveDrawable(android.R.drawable .dialog_holo_light_frame, getContext())); } dropdownWindow.setContentView(dropdownView); dropdownWindow.setOnDismissListener(this); dropdownWindow.setAnimationStyle(android.R.style.Animation_Activity); float longestStringWidth = measureStringWidth(getLongestString(dropdownData)) + DimenUtils.dpToPixels((baselineItemRightPadding + baselineItemLeftPadding) * bootstrapSize); if (longestStringWidth < getMeasuredWidth()) { dropdownWindow.setWidth(DimenUtils.dpToPixels(getMeasuredWidth())); } else { dropdownWindow.setWidth((int) longestStringWidth + DimenUtils.dpToPixels(8)); } }
Example 11
Source File: LegacyPastePopupMenu.java From 365browser with Apache License 2.0 | 5 votes |
public LegacyPastePopupMenu( Context context, View parent, final PastePopupMenuDelegate delegate) { mParent = parent; mDelegate = delegate; mContext = context; mContainer = new PopupWindow(mContext, null, android.R.attr.textSelectHandleWindowStyle); mContainer.setSplitTouchEnabled(true); mContainer.setClippingEnabled(false); mContainer.setAnimationStyle(0); mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); final int[] popupLayoutAttrs = { android.R.attr.textEditPasteWindowLayout, }; TypedArray attrs = mContext.getTheme().obtainStyledAttributes(popupLayoutAttrs); mPasteViewLayout = attrs.getResourceId(attrs.getIndex(0), 0); attrs.recycle(); // Convert line offset dips to pixels. mLineOffsetY = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 5.0f, mContext.getResources().getDisplayMetrics()); mWidthOffsetX = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 30.0f, mContext.getResources().getDisplayMetrics()); final int statusBarHeightResourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (statusBarHeightResourceId > 0) { mStatusBarHeight = mContext.getResources().getDimensionPixelSize(statusBarHeightResourceId); } }
Example 12
Source File: LordFragment.java From MyHearts with Apache License 2.0 | 5 votes |
private void initPopup() { View popupWindow = LayoutInflater.from(getContext()) .inflate(R.layout.lord_popup_window_layout, null); mReAddGroup = (RelativeLayout) popupWindow.findViewById(R.id.re_add_group); mReAddGroup.setOnClickListener(this); mReSearchGroup = (RelativeLayout) popupWindow.findViewById(R.id.re_search_group); mReSearchGroup.setOnClickListener(this); mPopupWindow = new PopupWindow(popupWindow); mPopupWindow.setWidth(ViewGroup.LayoutParams.FILL_PARENT); mPopupWindow.setHeight(ViewGroup.LayoutParams.FILL_PARENT); mPopupWindow.setTouchable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getContext().getResources())); mLlDismiss = (LinearLayout) popupWindow.findViewById(R.id.ll_dismiss); mLlDismiss.setOnClickListener(view -> { mPopupWindow.dismiss(); }); // // 设置背景颜色变暗 // WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes(); // lp.alpha = 0.7f; // getActivity().getWindow().setAttributes(lp); // mPopupWindow.setOnDismissListener(() -> { // WindowManager.LayoutParams lp1 = getActivity().getWindow().getAttributes(); // lp1.alpha = 1f; // getActivity().getWindow().setAttributes(lp1); // }); }
Example 13
Source File: PublicBikeActivity.java From FakeWeather with Apache License 2.0 | 5 votes |
public void showAsDropDown(PopupWindow window, View anchor) { if (Build.VERSION.SDK_INT >= 24) { Rect visibleFrame = new Rect(); anchor.getGlobalVisibleRect(visibleFrame); int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom; window.setHeight(height); } popupWindow.showAsDropDown(anchor); }
Example 14
Source File: TestActivity.java From YCDialog with Apache License 2.0 | 5 votes |
private void showPopupWindow() { //创建对象 PopupWindow popupWindow = new PopupWindow(this); View inflate = LayoutInflater.from(this).inflate(R.layout.view_pop_custom, null); //设置view布局 popupWindow.setContentView(inflate); popupWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); //设置动画的方法 popupWindow.setAnimationStyle(R.style.BottomDialog); //设置PopUpWindow的焦点,设置为true之后,PopupWindow内容区域,才可以响应点击事件 popupWindow.setTouchable(true); //设置背景透明 popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); //点击空白处的时候让PopupWindow消失 popupWindow.setOutsideTouchable(true); // true时,点击返回键先消失 PopupWindow // 但是设置为true时setOutsideTouchable,setTouchable方法就失效了(点击外部不消失,内容区域也不响应事件) // false时PopupWindow不处理返回键,默认是false popupWindow.setFocusable(false); //设置dismiss事件 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { } }); boolean showing = popupWindow.isShowing(); if (!showing){ //show,并且可以设置位置 popupWindow.showAsDropDown(mTv1); } //popupWindow.dismiss(); }
Example 15
Source File: CallActivity.java From sealrtc-android with MIT License | 5 votes |
private void showPopupWindowList(PopupWindow popupWindow, View view) { popupWindow.setOutsideTouchable(true); popupWindow.setWidth(getResources().getDimensionPixelSize(R.dimen.popup_width)); popupWindow.setHeight(getResources().getDimensionPixelSize(R.dimen.popup_width)); int[] location = new int[2]; view.getLocationInWindow(location); int x = location[0] - popupWindow.getWidth(); int y = location[1] + view.getHeight() / 2 - popupWindow.getHeight() / 2; popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, x, y); }
Example 16
Source File: WXMask.java From incubator-weex-playground with Apache License 2.0 | 4 votes |
@Override protected View initComponentHostView(@NonNull Context context) { mContainerView = new WXMaskView(context); mPopupWindow = new PopupWindow(context); mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { mPopupWindow.setAttachedInDecor(true); } //setClippingEnabled(false) will cause INPUT_ADJUST_PAN invalid. //mPopupWindow.setClippingEnabled(false); mPopupWindow.setContentView(mContainerView); mPopupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); mPopupWindow.setFocusable(true); mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { fireVisibleChangedEvent(false); } }); int y = 0; int statusBarHeight = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = context.getResources().getDimensionPixelSize(resourceId); y = statusBarHeight; } mPopupWindow.showAtLocation(((Activity) context).getWindow().getDecorView(), Gravity.TOP | Gravity.START, 0, y); fireVisibleChangedEvent(true); return mContainerView; }
Example 17
Source File: KeyboardView.java From libcommon with Apache License 2.0 | 4 votes |
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); }
Example 18
Source File: CustomKeyboardView.java From FirefoxReality with Mozilla Public License 2.0 | 4 votes |
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 19
Source File: MyKeyboardView.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
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 20
Source File: PlayerFragment.java From edx-app-android with Apache License 2.0 | 4 votes |
private void showSettingsPopup(final Point p) { try{ if(player!=null){ player.getController().setAutoHide(!getTouchExploreEnabled()); Activity context = getActivity(); float popupHeight = getResources().getDimension(R.dimen.settings_popup_height); float popupWidth = getResources().getDimension(R.dimen.settings_popup_width); // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.setting_popup); LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.panel_settings_popup, viewGroup); // Creating the PopupWindow settingPopup = new PopupWindow(context); settingPopup.setContentView(layout); settingPopup.setWidth((int)popupWidth); settingPopup.setHeight((int)popupHeight); settingPopup.setFocusable(true); settingPopup.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { hideTransparentImage(); if(player!=null){ player.getController().setSettingsBtnDrawable(false); player.getController().setAutoHide(!getTouchExploreEnabled()); } } }); // Clear the default translucent background settingPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // Displaying the popup at the specified location, + offsets. settingPopup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x-(int)popupWidth, p.y-(int)popupHeight); TextView tv_closedCaption = (TextView) layout.findViewById(R.id.tv_closedcaption); if ((langList != null) && (langList.size() > 0)) { tv_closedCaption.setBackgroundResource(R.drawable.white_rounded_selector); tv_closedCaption.setOnClickListener(new View.OnClickListener(){ public void onClick(View paramAnonymousView) { showCCFragmentPopup(); } }); }else{ tv_closedCaption.setBackgroundResource(R.drawable.grey_roundedbg); tv_closedCaption.setOnClickListener(null); } layout.findViewById(R.id.tv_video_speed).setOnClickListener(v -> showVideoSpeedFragmentPopup()); } }catch(Exception e){ logger.error(e); } }