Example usage for android.widget PopupWindow PopupWindow

List of usage examples for android.widget PopupWindow PopupWindow

Introduction

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

Prototype

public PopupWindow(View contentView) 

Source Link

Document

Create a new non focusable popup window which can display the contentView.

Usage

From source file:com.dycody.android.idealnote.DetailFragment.java

@SuppressWarnings("deprecation")
private void showPopup(View anchor) {
    DisplayMetrics metrics = new DisplayMetrics();
    mainActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // Inflate the popup_layout.xml
    LayoutInflater inflater = (LayoutInflater) mainActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.attachment_dialog, null);

    // Creating the PopupWindow
    attachmentDialog = new PopupWindow(mainActivity);
    attachmentDialog.setContentView(layout);
    attachmentDialog.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    attachmentDialog.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    attachmentDialog.setFocusable(true);
    attachmentDialog.setOnDismissListener(() -> {
        if (isRecording) {
            isRecording = false;//from w  w w. ja va 2s .c  o m
            stopRecording();
        }
    });

    // Clear the default translucent background
    attachmentDialog.setBackgroundDrawable(new BitmapDrawable());

    // Camera
    android.widget.TextView cameraSelection = (android.widget.TextView) layout.findViewById(R.id.camera);
    cameraSelection.setOnClickListener(new AttachmentOnClickListener());
    // Audio recording
    android.widget.TextView recordingSelection = (android.widget.TextView) layout.findViewById(R.id.recording);
    recordingSelection.setOnClickListener(new AttachmentOnClickListener());
    // Video recording
    android.widget.TextView videoSelection = (android.widget.TextView) layout.findViewById(R.id.video);
    videoSelection.setOnClickListener(new AttachmentOnClickListener());
    // Files
    android.widget.TextView filesSelection = (android.widget.TextView) layout.findViewById(R.id.files);
    filesSelection.setOnClickListener(new AttachmentOnClickListener());
    // Sketch
    android.widget.TextView sketchSelection = (android.widget.TextView) layout.findViewById(R.id.sketch);
    sketchSelection.setOnClickListener(new AttachmentOnClickListener());
    // Location
    android.widget.TextView locationSelection = (android.widget.TextView) layout.findViewById(R.id.location);
    locationSelection.setOnClickListener(new AttachmentOnClickListener());
    // Desktop note with PushBullet
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        android.widget.TextView pushbulletSelection = (android.widget.TextView) layout
                .findViewById(R.id.pushbullet);
        pushbulletSelection.setVisibility(View.VISIBLE);
        pushbulletSelection.setOnClickListener(new AttachmentOnClickListener());
    }

    try {
        attachmentDialog.showAsDropDown(anchor);
    } catch (Exception e) {
        Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show();
        //mainActivity.showMessage(R.string.error, ONStyle.ALERT);

    }
}

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);/*  w  w  w  .jav a2 s.c o  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);
}

From source file:org.telegram.ui.ChatActivity.java

private void createEmojiPopup() {
    emojiView = new EmojiView(parentActivity);
    emojiView.setListener(new EmojiView.Listener() {
        public void onBackspace() {
            messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
        }//from   w  w w . j a v a2 s. c  o m

        public void onEmojiSelected(String paramAnonymousString) {
            int i = messsageEditText.getSelectionEnd();
            CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString);
            messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
            int j = i + localCharSequence.length();
            messsageEditText.setSelection(j, j);
        }
    });
    emojiPopup = new PopupWindow(emojiView);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

public void showPreviews(final View anchor, int start, int end) {
    if (mWorkspace != null && mWorkspace.getChildCount() > 0) {
        if (newPreviews) {
            showingPreviews = true;/*  ww w  .  jav a  2s.com*/
            hideDesktop(true);
            mWorkspace.lock();
            mWorkspace.openSense(true);
        } else {
            // check first if it's already open
            final PopupWindow window = (PopupWindow) anchor.getTag(R.id.TAG_PREVIEW);
            if (window != null)
                return;
            Resources resources = getResources();

            PersonaWorkspace personaWorkspace = mWorkspace;
            PersonaCellLayout cell = ((PersonaCellLayout) personaWorkspace.getChildAt(start));
            float max;
            ViewGroup preview;
            max = personaWorkspace.getChildCount();
            preview = new LinearLayout(this);

            Rect r = new Rect();
            // ADW: seems sometimes this throws an out of memory error....
            // so...
            try {
                resources.getDrawable(R.drawable.pr_preview_background).getPadding(r);
            } catch (OutOfMemoryError e) {
            }
            int extraW = (int) ((r.left + r.right) * max);
            int extraH = r.top + r.bottom;

            int aW = cell.getWidth() - extraW;
            float w = aW / max;

            int width = cell.getWidth();
            int height = cell.getHeight();
            // width -= (x + cell.getRightPadding());
            // height -= (y + cell.getBottomPadding());
            if (width != 0 && height != 0) {
                showingPreviews = true;
                float scale = w / width;

                int count = end - start;

                final float sWidth = width * scale;
                float sHeight = height * scale;

                PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
                ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);

                for (int i = start; i < end; i++) {
                    ImageView image = new ImageView(this);
                    cell = (PersonaCellLayout) personaWorkspace.getChildAt(i);
                    Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888);
                    cell.setDrawingCacheEnabled(false);
                    Canvas c = new Canvas(bitmap);
                    c.scale(scale, scale);
                    c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
                    cell.dispatchDraw(c);

                    image.setBackgroundDrawable(resources.getDrawable(R.drawable.pr_preview_background));
                    image.setImageBitmap(bitmap);
                    image.setTag(i);
                    image.setOnClickListener(handler);
                    image.setOnFocusChangeListener(handler);
                    image.setFocusable(true);
                    if (i == mWorkspace.getCurrentScreen())
                        image.requestFocus();

                    preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT);

                    bitmaps.add(bitmap);
                }

                PopupWindow p = new PopupWindow(this);
                p.setContentView(preview);
                p.setWidth((int) (sWidth * count + extraW));
                p.setHeight((int) (sHeight + extraH));
                p.setAnimationStyle(R.style.AnimationPreview);
                p.setOutsideTouchable(true);
                p.setFocusable(true);
                p.setBackgroundDrawable(new ColorDrawable(0));
                p.showAsDropDown(anchor, 0, 0);
                p.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        dismissPreview(anchor);
                    }
                });
                anchor.setTag(R.id.TAG_PREVIEW, p);
                anchor.setTag(R.id.workspace, preview);
                anchor.setTag(R.id.icon, bitmaps);
            }
        }
    }
}

From source file:com.example.libwidgettv.bak.AbsListView.java

/**
 * Creates the window for the text filter and populates it with an EditText
 * field;//from   w  w  w. j  a  va 2  s.  co  m
 * 
 * @param animateEntrance
 *            true if the window should appear with an animation
 */
private void createTextFilter(boolean animateEntrance) {
    if (mPopup == null) {
        Context c = getContext();
        PopupWindow p = new PopupWindow(c);
        LayoutInflater layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // mTextFilter = (EditText) layoutInflater.inflate(
        // com.android.internal.R.layout.typing_filter, null);
        mTextFilter = new EditText(getContext());
        // For some reason setting this as the "real" input type changes
        // the text view in some way that it doesn't work, and I don't
        // want to figure out why this is.
        mTextFilter.setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
        mTextFilter.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        mTextFilter.addTextChangedListener(this);
        p.setFocusable(false);
        p.setTouchable(false);
        p.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        p.setContentView(mTextFilter);
        p.setWidth(LayoutParams.WRAP_CONTENT);
        p.setHeight(LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        mPopup = p;
        getViewTreeObserver().addOnGlobalLayoutListener(this);
        mGlobalLayoutListenerAddedFilter = true;
    }
    // if (animateEntrance) {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilter);
    // } else {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilterRestore);
    // }
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Creates the window for the text filter and populates it with an EditText field;
 *
 * @param animateEntrance true if the window should appear with an animation
 *//*  w  w w.ja v a 2 s  .  co  m*/
private void createTextFilter(boolean animateEntrance) {
    if (mPopup == null) {
        Context c = getContext();
        PopupWindow p = new PopupWindow(c);
        LayoutInflater layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mTextFilter = (EditText) layoutInflater.inflate(R.layout.typing_filter, null);
        // For some reason setting this as the "real" input type changes
        // the text view in some way that it doesn't work, and I don't
        // want to figure out why this is.
        mTextFilter.setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
        mTextFilter.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        mTextFilter.addTextChangedListener(this);
        p.setFocusable(false);
        p.setTouchable(false);
        p.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        p.setContentView(mTextFilter);
        p.setWidth(LayoutParams.WRAP_CONTENT);
        p.setHeight(LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        mPopup = p;
        getViewTreeObserver().addOnGlobalLayoutListener(this);
        mGlobalLayoutListenerAddedFilter = true;
    }
    if (animateEntrance) {
        mPopup.setAnimationStyle(R.style.Animation_TypingFilter);
    } else {
        mPopup.setAnimationStyle(R.style.Animation_TypingFilterRestore);
    }
}