List of usage examples for android.widget PopupWindow PopupWindow
public PopupWindow(View contentView)
Create a new non focusable popup window which can display the contentView.
From source file:de.timroes.swipetodismiss.SwipeDismissList.java
/** * Constructs a new swipe-to-dismiss touch listener for the given list view. * * @param listView The list view whose items should be dismissable. * @param callback The callback to trigger when the user has indicated that * she would like to dismiss one or more list items. * @param mode The mode this list handles multiple undos. *///from w w w. j av a 2 s .co m public SwipeDismissList(AbsListView listView, OnDismissCallback callback, UndoMode mode) { if (listView == null) { throw new IllegalArgumentException("listview must not be null."); } mHandler = new HideUndoPopupHandler(this); mListView = listView; mCallback = callback; mMode = mode; ViewConfiguration vc = ViewConfiguration.get(listView.getContext()); mSlop = vc.getScaledTouchSlop(); mMinFlingVelocity = vc.getScaledMinimumFlingVelocity(); mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mAnimationTime = listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime); mDensity = mListView.getResources().getDisplayMetrics().density; // -- Load undo popup -- LayoutInflater inflater = (LayoutInflater) mListView.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.undo_popup, null); mUndoButton = (Button) v.findViewById(R.id.undo); mUndoButton.setOnClickListener(new UndoHandler()); mUndoButton.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // If user tabs "undo" button, reset delay time to remove popup mDelayedMsgId++; return false; } }); mUndoText = (TextView) v.findViewById(R.id.text); mUndoPopup = new PopupWindow(v); mUndoPopup.setAnimationStyle(R.style.fade_animation); // Get scren width in dp and set width respectively int xdensity = (int) (mListView.getContext().getResources().getDisplayMetrics().widthPixels / mDensity); if (xdensity < 300) { mUndoPopup.setWidth((int) (mDensity * 280)); } else if (xdensity < 350) { mUndoPopup.setWidth((int) (mDensity * 300)); } else if (xdensity < 500) { mUndoPopup.setWidth((int) (mDensity * 330)); } else { mUndoPopup.setWidth((int) (mDensity * 450)); } mUndoPopup.setHeight((int) (mDensity * 56)); // -- END Load undo popu -- listView.setOnTouchListener(this); listView.setOnScrollListener(this.makeScrollListener()); mEnabled = true; switch (mode) { case SINGLE_UNDO: mUndoActions = new ArrayList<Undoable>(1); break; default: mUndoActions = new ArrayList<Undoable>(10); break; } }
From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java
@WorkerThread private void showPopupAt(final LineNumber lineNumber, final String msg) { mHandler.post(new Runnable() { @Override//from w w w .j a v a2s . co m public void run() { if (isFinishing()) return; //get relative position of expression at edittext Point position = mCodeView.getDebugPosition(lineNumber.getLine(), lineNumber.getColumn(), Gravity.TOP); DLog.d(TAG, "generate: " + position); dismissPopup(); //create new popup PopupWindow window = new PopupWindow(DebugActivity.this); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View container = inflater.inflate(R.layout.popup_expr_result, null); container.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); int windowHeight = container.getMeasuredHeight(); int windowWidth = container.getMeasuredWidth(); window.setContentView(container); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setTouchable(true); window.setSplitTouchEnabled(true); window.setOutsideTouchable(true); window.showAtLocation(mCodeView, Gravity.NO_GRAVITY, position.x - windowWidth / 3, position.y + toolbar.getHeight() - windowHeight); TextView txtResult = container.findViewById(R.id.txt_result); txtResult.setText(msg); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); alphaAnimation.setDuration(1000); alphaAnimation.setRepeatMode(Animation.REVERSE); alphaAnimation.setRepeatCount(Animation.INFINITE); txtResult.startAnimation(alphaAnimation); DebugActivity.this.mPopupWindow = window; } }); }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private void showColorChoosePop() { LinearLayout linearLayout = new LinearLayout(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int margin = EUExUtil.dipToPixels(8); lp.setMargins(margin / 2, margin, margin / 2, margin); linearLayout.setLayoutParams(lp);/*from w ww . j av a 2s . c om*/ linearLayout.setOrientation(LinearLayout.HORIZONTAL); for (int color : colors) { linearLayout.addView(getColorImageView(color)); } HorizontalScrollView scrollView = new HorizontalScrollView(this); LinearLayout.LayoutParams scrollLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); scrollView.setLayoutParams(scrollLp); scrollView.addView(linearLayout); int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); scrollView.measure(w, h); PopupWindow popupWindow = new PopupWindow(scrollView); popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setWidth(mImageContentLayout.getWidth()); popupWindow.setHeight(scrollView.getMeasuredHeight()); popupWindow.showAtLocation(mImageContentLayout, Gravity.BOTTOM, 0, mCloseLayout.getHeight() + mBrushLayout.getHeight() + popupWindow.getHeight()); }
From source file:com.layer.atlas.AtlasMessageComposer.java
private void initAttachmentMenu(Context context, AttributeSet attrs, int defStyle) { if (mAttachmentMenu != null) throw new IllegalStateException("Already initialized menu"); if (attrs == null) { mAttachmentMenu = new PopupWindow(context); } else {/*w w w .j a v a2 s. c o m*/ mAttachmentMenu = new PopupWindow(context, attrs, defStyle); } mAttachmentMenu.setContentView( LayoutInflater.from(context).inflate(R.layout.atlas_message_composer_attachment_menu, null)); mAttachmentMenu.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mAttachmentMenu.setOutsideTouchable(true); }
From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java
private void onTooltipIconClicked() { // Don't show the popup if there's already one showing (or one has been dismissed // recently). This prevents a tap on the (?) from hiding and then immediately re-showing // the popup. if (mStoreLocallyTooltipPopup != null) return;/*from w ww. j av a2 s.co m*/ mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext()); TextView text = new TextView(mDialog.getContext()); text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip); // Width is the dialog's width less the margins and padding around the checkbox and // icon. text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mStoreLocallyCheckbox) - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon) - MarginLayoutParamsCompat .getMarginStart((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLayoutParams()) - MarginLayoutParamsCompat .getMarginEnd((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.getLayoutParams())); text.setTextColor(Color.WHITE); Resources resources = mDialog.getContext().getResources(); int hPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_horizontal_padding); int vPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_vertical_padding); text.setPadding(hPadding, vPadding, hPadding, vPadding); mStoreLocallyTooltipPopup.setContentView(text); mStoreLocallyTooltipPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mStoreLocallyTooltipPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mStoreLocallyTooltipPopup.setOutsideTouchable(true); mStoreLocallyTooltipPopup.setBackgroundDrawable( ApiCompatibilityUtils.getDrawable(resources, R.drawable.store_locally_tooltip_background)); mStoreLocallyTooltipPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { Handler h = new Handler(); h.postDelayed(new Runnable() { @Override public void run() { mStoreLocallyTooltipPopup = null; } }, 200); } }); mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox, ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0); text.announceForAccessibility(text.getText()); }
From source file:com.example.okano.simpleroutesearch.MapsActivity.java
private void showMapInfo() { mPopupWindow = new PopupWindow(MapsActivity.this); // // ww w . j av a 2 s . com // View popupView = getLayoutInflater().inflate(R.layout.popup_route_info, null); View popupView = getLayoutInflater().inflate(R.layout.popup_route_info, null); // TextView textt = (TextView) popupView.findViewById(R.id.routeText); TextView textt = (TextView) popupView.findViewById(R.id.routeText); CharSequence htmlRoute = Html.fromHtml(routeDataText); // textt.setText(routeDataText); textt.setText(htmlRoute); mPopupWindow.setWindowLayoutMode(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT); mPopupWindow.setContentView(popupView); // mPopupWindow.showAsDropDown(popupView, 10,-10); mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); mPopupWindow.setFocusable(true); }
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();// w w w . java2s . c om 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:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java
public PopupWindow popupMenuCreate(String[] popUpContents, int resId) { // initialize a pop up window type PopupWindow popupWindow = new PopupWindow(this); // the drop down list is a list view ListView listView = new ListView(this); // set our adapter and pass our pop up window contents ArrayAdapter<String> aa = popupMenuAdapter(popUpContents); listView.setAdapter(aa);// w ww . j a v a 2 s . c o m // set the item click listener listView.setOnItemClickListener(this); listView.setTag(resId); // button res ID, so we can trace back which button is pressed // get max text width Paint mTestPaint = new Paint(); mTestPaint.setTextSize(listItemTextSize); float w = 0; float wi; // max text width in pixel for (int i = 0; i < popUpContents.length; i++) { String sts[] = popUpContents[i].split("::"); String st = sts[0]; if (sts.length == 2 && sts[1].equals("0")) { mTestPaint.setTextSize(listItemTitleTextSize); wi = mTestPaint.measureText(st); mTestPaint.setTextSize(listItemTextSize); } else { wi = mTestPaint.measureText(st); } if (w < wi) { w = wi; } } // left and right padding, at least +7, or the whole app will stop respond, don't know why w = w + 20 * DPRatio; if (w < 60) { w = 60; } // some other visual settings popupWindow.setFocusable(true); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); // Set window width according to max text width popupWindow.setWidth((int) w); // also set button width ((Button) findViewById(resId)).setWidth((int) (w + 2 * DPRatio)); // Set the text on button in updatePreferenceSaved() // set the list view as pop up window content popupWindow.setContentView(listView); return popupWindow; }
From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java
private void initAttachmentMenu(Context context, AttributeSet attrs, int defStyle) { if (mAttachmentMenu != null) throw new IllegalStateException("Already initialized menu"); if (attrs == null) { mAttachmentMenu = new PopupWindow(context); } else {//w ww .j a v a2s. co m mAttachmentMenu = new PopupWindow(context, attrs, defStyle); } mAttachmentMenu.setContentView(LayoutInflater.from(context) .inflate(com.layer.atlas.R.layout.atlas_message_composer_attachment_menu, null)); mAttachmentMenu.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mAttachmentMenu.setOutsideTouchable(true); mAttachmentMenu.setBackgroundDrawable(mAttachmentSendersBackground); mAttachmentMenu.setFocusable(true); }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
public PopupWindow popupMenuCreate(String[] popUpContents, int resId) { // initialize a pop up window type PopupWindow popupWindow = new PopupWindow(this); // the drop down list is a list view ListView listView = new ListView(this); // set our adapter and pass our pop up window contents ArrayAdapter<String> aa = popupMenuAdapter(popUpContents); listView.setAdapter(aa);/*w w w. j a v a 2 s . c o m*/ // set the item click listener listView.setOnItemClickListener(this); listView.setTag(resId); // button res ID, so we can trace back which button is pressed // get max text width Paint mTestPaint = new Paint(); mTestPaint.setTextSize(listItemTextSize); float w = 0; float wi; // max text width in pixel for (int i = 0; i < popUpContents.length; i++) { String sts[] = popUpContents[i].split("::"); String st = sts[0]; if (sts.length == 2 && sts[1].equals("0")) { mTestPaint.setTextSize(listItemTitleTextSize); wi = mTestPaint.measureText(st); mTestPaint.setTextSize(listItemTextSize); } else { wi = mTestPaint.measureText(st); } if (w < wi) { w = wi; } } // left and right padding, at least +7, or the whole app will stop respond, don't know why w = w + 20 * DPRatio; if (w < 60) { w = 60; } // some other visual settings popupWindow.setFocusable(true); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); // Set window width according to max text width popupWindow.setWidth((int) w); // also set button width ((Button) findViewById(resId)).setWidth((int) (w + 4 * DPRatio)); // Set the text on button in updatePreferenceSaved() // set the list view as pop up window content popupWindow.setContentView(listView); return popupWindow; }