Example usage for android.widget PopupWindow setBackgroundDrawable

List of usage examples for android.widget PopupWindow setBackgroundDrawable

Introduction

In this page you can find the example usage for android.widget PopupWindow setBackgroundDrawable.

Prototype

public void setBackgroundDrawable(Drawable background) 

Source Link

Document

Specifies the background drawable for this popup window.

Usage

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 ww .j  a va  2  s.  c  o  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:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//from  ww w. j a  va2  s.co m
 *
 * Editing launches a renaming process
 *
* @param longClickedFlow Flow represented by cardview longclicked
  * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
private boolean showLongClickPopUpMenu(final Flow longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("NO!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return 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();/*  www .  j  ava  2s  . co  m*/

    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.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Displays a popup window prompting the user to
 *
 * Confirm the changes to the name, saving the new name to file and updating the UI.
 *
 * Cancel the changes, returning the user back to the original state before editing
 *
 * @param newName new name to be used/*w  w  w. j  a  va2  s  .  c  om*/
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @param switcher the viewSwitcher object used to rename
 */
private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher,
        final int cardPosition) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_editing, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing);

    // Creating the PopupWindow
    final PopupWindow popupEditing = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border from appearing outside popupwindow
    popupEditing.setBackgroundDrawable(new ColorDrawable());
    popupEditing.setFocusable(false);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes);

    confirmEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Flow toChange = rvContent.get(cardPosition);
            if (newName.getText().toString().equals("")) {
                // Need to optimize this so that the dialog does NOT disappear and just display toast
                Toast.makeText(TheHubActivity.this, "This Flow needs a name!", Toast.LENGTH_LONG).show();
            } else {
                toChange.setName(newName.getText().toString());
                manager.overwrite(toChange.getUuid(), toChange);
                adapter.notifyDataSetChanged();
                switcher.showNext();
                menuState = AppConstants.MENU_ITEMS_NATIVE;
                invalidateOptionsMenu();
                popupEditing.dismiss();
                newName.clearFocus();
            }

        }
    });

    ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes);

    cancelEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switcher.showNext();
            menuState = AppConstants.MENU_ITEMS_NATIVE;
            invalidateOptionsMenu();
            popupEditing.dismiss();
        }
    });

    // Displaying the popup at the specified location, + offsets.
    popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight,
            Gravity.TOP);
    editingPopup = popupEditing;
}

From source file:mn.today.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file/* w w w  . jav  a  2  s .  com*/
 *
 * Editing launches a renaming process
 *
 * @param longClickedFlow Flow represented by cardview longclicked
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private boolean showLongClickPopUpMenu(final ToDay longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:mn.today.TheHubActivity.java

/**
 * Displays a popup window prompting the user to
 *
 * Confirm the changes to the name, saving the new name to file and updating the UI.
 *
 * Cancel the changes, returning the user back to the original state before editing
 *
 * @param newName new name to be used//  w ww.j  av a  2  s.  c  o  m
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @param switcher the viewSwitcher object used to rename
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher,
        final int cardPosition) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_editing, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing);

    // Creating the PopupWindow
    final PopupWindow popupEditing = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border from appearing outside popupwindow
    popupEditing.setBackgroundDrawable(new ColorDrawable());
    popupEditing.setFocusable(false);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes);

    confirmEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ToDay toChange = rvContent.get(cardPosition);
            if (newName.getText().toString().equals("")) {
                // Need to optimize this so that the dialog does NOT disappear and just display toast
                Toast.makeText(TheHubActivity.this, "??  !", Toast.LENGTH_LONG).show();
            } else {
                toChange.setName(newName.getText().toString());
                manager.overwrite(toChange.getUuid(), toChange);
                adapter.notifyDataSetChanged();
                switcher.showNext();
                menuState = AppConstants.MENU_ITEMS_NATIVE;
                invalidateOptionsMenu();
                popupEditing.dismiss();
                newName.clearFocus();
            }

        }
    });

    ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes);

    cancelEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switcher.showNext();
            menuState = AppConstants.MENU_ITEMS_NATIVE;
            invalidateOptionsMenu();
            popupEditing.dismiss();
        }
    });

    // Displaying the popup at the specified location, + offsets.
    popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight,
            Gravity.TOP);
    editingPopup = popupEditing;
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again// w ww .j  ava 2 s .c o  m
 */
private void showCalendarPicker() {
    // Inflate the popup_layout.xml
    ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root);
    LayoutInflater layoutInflater = (LayoutInflater) getMainActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup);
    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    //or if popup is on edge display it to the left of the circle
    Display display = getMainActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point(0, 0);
    display.getSize(size);

    int OFFSET_X = 25;
    int OFFSET_Y = 25;

    final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(getMainActivity());
    popup.setAnimationStyle(android.R.style.Animation_Dialog);
    popup.setContentView(layout);

    popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    popup.setFocusable(true);
    //gets rid of default background
    popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null));
    //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu));

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y);
    Calendar minDate;
    minDate = Calendar.getInstance();
    this.tempY = minDate.get(Calendar.YEAR);
    this.tempM = minDate.get(Calendar.MONTH);
    this.tempD = minDate.get(Calendar.DAY_OF_MONTH);
    dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                // Months start from 0, so January is month 0
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    tempY = year;
                    tempM = monthOfYear;
                    tempD = dayOfMonth;
                    Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY);
                }
            });
    ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept);
    ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(tempY, tempM, tempD, 1, 0);
            Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis());
            // clear items from clustermanager and submissionMarkerList, as all new submissions
            // need to be fetched based on the selected date
            clusterManager.clearItems();
            submissionMarkerIdList.clear();
            addAdminMarkersToMap();
            setMinDateInMs(calendar.getTimeInMillis());
            popup.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setMinDateInMs(0);
            popup.dismiss();

        }
    });
}

From source file:org.onebusaway.android.ui.ArrivalsListHeader.java

/**
 * Sets the popup for the status/*from   w ww  . j a  va2  s .  co m*/
 *
 * @param index      0 if this is for the top ETA row, 1 if it is for the second
 * @param color      color resource id to use for the popup background
 * @param statusText text to show in the status popup
 * @return a new PopupWindow initialized based on the provided parameters
 */
private PopupWindow setupPopup(final int index, int color, String statusText) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    TextView statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large,
            null);
    statusView.setBackgroundResource(R.drawable.round_corners_style_b_status);
    GradientDrawable d = (GradientDrawable) statusView.getBackground();
    if (color != R.color.stop_info_ontime) {
        // Show early/late color
        d.setColor(mResources.getColor(color));
    } else {
        // For on-time, use header default color
        d.setColor(mResources.getColor(R.color.theme_primary));
    }
    d.setStroke(UIUtils.dpToPixels(mContext, 1), mResources.getColor(R.color.header_text_color));
    int pSides = UIUtils.dpToPixels(mContext, 5);
    int pTopBottom = UIUtils.dpToPixels(mContext, 2);
    statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom);
    statusView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    statusView.measure(TextView.MeasureSpec.UNSPECIFIED, TextView.MeasureSpec.UNSPECIFIED);
    statusView.setText(statusText);
    PopupWindow p = new PopupWindow(statusView, statusView.getWidth(), statusView.getHeight());
    p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    p.setBackgroundDrawable(new ColorDrawable(mResources.getColor(android.R.color.transparent)));
    p.setOutsideTouchable(true);
    p.setTouchInterceptor(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            boolean touchInView;
            if (index == 0) {
                touchInView = UIUtils.isTouchInView(mEtaAndMin1, event);
            } else {
                touchInView = UIUtils.isTouchInView(mEtaAndMin2, event);
            }
            return touchInView;
        }
    });
    return p;
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void commonPopupWindowDisplay(PopupWindow popupWindow, View tabMenu, int x, int y) {
    popupWindow.setFocusable(true);//from w w  w.  jav a2s  .c  om
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setIgnoreCheekPress();
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(tabMenu, x, y);

}

From source file:org.medcare.Dicom.DicomActivity.java

private void showPopup(View parent, int gravity, int x, int y, int width, int height) {
    Log.e("DicomActivity", "showPopup width = " + width + " height " + height);
    if (DicomActivity.this.mPopup == null) {
        PopupWindow p = new PopupWindow(this);
        p.setFocusable(false);/*from  w ww . j a v a2  s.co m*/
        p.setContentView(mPopupView);
        p.setWidth(width);
        p.setHeight(height);
        p.setBackgroundDrawable(null);

        p.setAnimationStyle(R.style.PopupAnimation);
        DicomActivity.this.mPopup = p;
    } else {
        DicomActivity.this.mPopup.setWidth(width);
        DicomActivity.this.mPopup.setHeight(height);
    }
    // coords = myImageController.getCoordinates();
    // hitTestRecr.offset(coords.getX(), coords.getY());
    DicomActivity.this.mPopup.showAtLocation(parent, gravity, x, y);
}