Example usage for android.widget PopupWindow setContentView

List of usage examples for android.widget PopupWindow setContentView

Introduction

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

Prototype

public void setContentView(View contentView) 

Source Link

Document

Change the popup's content.

Usage

From source file:cc.echonet.coolmicapp.MainActivity.java

private void goAbout() {

    Log.d("MainActivity", "goAbout() ");

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View popUpView = inflater.inflate(R.layout.popup_about, null, false);

    final PopupWindow popUp = new PopupWindow(this);

    Button close = (Button) popUpView.findViewById(R.id.cmdPopUpDismiss);
    close.setOnClickListener(new View.OnClickListener() {
        public void onClick(View popupView) {
            popUp.dismiss();/*  w  w w.j a v  a 2 s  . c  o m*/
        }
    });

    ((TextView) popUpView.findViewById(R.id.txtVersion)).setText(BuildConfig.VERSION_NAME);
    ((TextView) popUpView.findViewById(R.id.txtBuildType)).setText(BuildConfig.BUILD_TYPE);
    ((TextView) popUpView.findViewById(R.id.txtGITBranch)).setText(BuildConfig.GIT_BRANCH);
    ((TextView) popUpView.findViewById(R.id.txtGITRevision)).setText(BuildConfig.GIT_REVISION);
    ((TextView) popUpView.findViewById(R.id.txtGITAuthor)).setText(BuildConfig.GIT_AUTHOR);
    ((TextView) popUpView.findViewById(R.id.txtGITDirty)).setText(BuildConfig.GIT_DIRTY);

    popUpView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    popUp.setContentView(popUpView);

    Log.d("MainActivity", String.format("h: %s w: %s h: %s w: %s", popUp.getHeight(), popUp.getWidth(),
            popUpView.getMeasuredHeight(), popUpView.getMeasuredWidth()));

    popUp.setHeight(popUpView.getMeasuredHeight());
    popUp.setWidth(popUpView.getMeasuredWidth());

    popUp.showAtLocation(popUpView, Gravity.CENTER, 0, 0);

    Log.d("MainActivity", "goAbout() end ");
}

From source file:xj.property.activity.HXBaseActivity.ChatActivity.java

private void showPopWindow2() {

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View mMenuView = inflater.inflate(R.layout.unservice_time, null);
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setText("?"
            + MainActivity.startTime + "-" + MainActivity.endTime
            + "????");
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime))
            .setTextSize(getResources().getDimension(R.dimen.tv_unservicetime));
    final PopupWindow popupWindow = new PopupWindow();
    // ?//from w  w w  .  j  a  va2 s  . c o m
    // SelectPicPopupWindowView
    popupWindow.setContentView(mMenuView);
    // SelectPicPopupWindow
    popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
    // SelectPicPopupWindow
    popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
    // SelectPicPopupWindow?
    //        this.setFocusable(true);
    // SelectPicPopupWindow
    //  popupWindow.setAnimationStyle(R.style.AnimTop);
    TranslateAnimation translateAnimation = new TranslateAnimation(0, 0.0f, 0, 200f);
    translateAnimation.setDuration(2000);
    translateAnimation.setFillAfter(true);
    ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setAnimation(translateAnimation);
    translateAnimation.start();
    // ColorDrawable??
    ColorDrawable dw = new ColorDrawable(0xb0000000);
    // SelectPicPopupWindow
    // mMenuViewOnTouchListener??????
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // ,Animation.RELATIVE_TO_SELF,10f,Animation.RELATIVE_TO_SELF,10f
            popupWindow.showAsDropDown(findViewById(R.id.top_bar));
            //popupWindow.showAtLocation(findViewById(R.id.list),Gravity.NO_GRAVITY,0,0);
        }
    }, 200);

}

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);/*from   w  w w. j  a  v  a2s.  co 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.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);/*from  ww  w .j  a  va  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;
}

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;/*w w w .  j  a v a 2 s .c o m*/
            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 v  a 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  ww.  j  av a  2s .  c  om
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);
    }
}