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, int width, int height, boolean focusable) 

Source Link

Document

Create a new popup window which can display the contentView.

Usage

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
public void Memstore() {
    mHandler.onEnter();//from w ww . j  a va  2s . c o  m
    String strDisplay = mHandler.getDisplayText();
    if (isValidNumber(strDisplay)) {
        final String strTemp = strDisplay;
        spMemory = ctx.getSharedPreferences(PREFNAME, 0);
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        vwLayout = inflater.inflate(R.layout.memory,
                (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));
        popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight, true);
        popmW1.setBackgroundDrawable(new BitmapDrawable());
        popmW1.setOutsideTouchable(true);
        popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
        ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
        btnCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                popmW1.dismiss();

            }
        });
        btns[0] = (Button) vwLayout.findViewById(R.id.btn1);
        btns[1] = (Button) vwLayout.findViewById(R.id.btn2);
        btns[2] = (Button) vwLayout.findViewById(R.id.btn3);
        btns[3] = (Button) vwLayout.findViewById(R.id.btn4);
        btns[4] = (Button) vwLayout.findViewById(R.id.btn5);
        btns[5] = (Button) vwLayout.findViewById(R.id.btn6);
        btns[6] = (Button) vwLayout.findViewById(R.id.btn7);
        btns[7] = (Button) vwLayout.findViewById(R.id.btn8);
        btns[8] = (Button) vwLayout.findViewById(R.id.btn9);

        for (int inI = 0; inI < 9; inI++) {

            btns[inI].setText(spMemory.getString("" + inI, "0"));

            final int inJ = inI;

            btns[inJ].setText(spMemory.getString("" + inJ, ""));

            btns[inJ].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    btns[inJ].setText(strTemp);
                    editor = spMemory.edit();
                    editor.putString("" + inJ, btns[inJ].getText().toString().equalsIgnoreCase("") ? ""
                            : btns[inJ].getText().toString());
                    editor.commit();
                    popmW1.dismiss();
                }
            });
        }
        inShift = 0;
    } else
        Toast.makeText(ctx, "Save Failed!", Toast.LENGTH_SHORT).show();
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

private void popup(@Nonnull final View anchor, @Nonnull final View contentView) {
    contentView.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0),
            MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));

    popupWindow = new PopupWindow(contentView, contentView.getMeasuredWidth(), contentView.getMeasuredHeight(),
            false);/*from   w  w  w.  j a v a  2 s  .  c om*/
    popupWindow.showAsDropDown(anchor);

    // hack
    contentView.setBackgroundResource(
            popupWindow.isAboveAnchor() ? R.drawable.popup_frame_above : R.drawable.popup_frame_below);
}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

/**
 * ?// ww w  . j a v  a  2 s .c o  m
 */
public void showLoadingDialog(String text) {

    LayoutInflater inflater = (LayoutInflater) ctxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View grid = inflater.inflate(R.layout.loading_layout, null);

    TextView tv = (TextView) grid.findViewById(R.id.textview_loading_content);
    tv.setText(text);

    ImageView iv = (ImageView) grid.findViewById(R.id.imageview_loading_pic);
    iv.startAnimation(AnimationUtils.loadAnimation(ctxt, R.anim.rotate_loading));

    int width = CommonUtils.getScreenWidth(ctxt);
    int height = CommonUtils.getScreenHeight(ctxt);

    if (dialog_loading == null) {
        dialog_loading = new PopupWindow(grid, width, height, true);
    } else {
        dialog_loading.setContentView(grid);
    }

    dialog_loading.setFocusable(true);
    dialog_loading.setOutsideTouchable(true);
    dialog_loading.setAnimationStyle(R.style.AutoDialogAnimation);
    dialog_loading.setBackgroundDrawable(new BitmapDrawable());
    if (hasFocus) {
        dialog_loading.showAtLocation(rl_activate, Gravity.NO_GRAVITY, 0, 0);
    }

}

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
public void showHistory() {
    shPref = ScientificActivity.ctx.getSharedPreferences("myHistpref", 0);
    int inSize = shPref.getInt("HistIndex", 0);
    System.out.println("" + inSize);
    String[] str = new String[inSize];
    for (int inI = 0; inI < inSize; inI++) {
        str[inI] = shPref.getString("hist" + inI, "");
        System.out.println(str[inI]);
    }//from w w w.  j  ava2s.c o  m
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    vwLayout = inflater.inflate(R.layout.pop_history,
            (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));

    popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight, true);
    popmW1.setBackgroundDrawable(new BitmapDrawable());
    popmW1.setOutsideTouchable(true);
    popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
    tblltTable = (TableLayout) vwLayout.findViewById(R.id.tablelay);
    ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
    btnCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popmW1.dismiss();

        }
    });
    txtvHistory = new TextView[inSize];
    btnHistory = new Button[inSize];
    tblrRowL = new TableRow[inSize];
    TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, 1f);
    TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, .1f);
    int inJ = 0, inL = inSize - 1;
    for (int inI = 0; inI < inSize; inI++) {
        if (!str[inI].equalsIgnoreCase("")) {
            btnHistory[inJ] = new Button(ctx);
            txtvHistory[inJ] = new TextView(ctx);
            txtvHistory[inJ].setText("" + (inJ + 1));
            txtvHistory[inJ].setGravity(Gravity.CENTER);
            txtvHistory[inJ].setTextColor(ScientificActivity.ctx.getResources().getColor(R.color.HistColor));
            txtvHistory[inJ].setLayoutParams(textParams);
            btnHistory[inJ].setText(str[inL]);
            btnHistory[inJ].setTextColor(Color.WHITE);
            btnHistory[inJ].setGravity(Gravity.LEFT);
            btnHistory[inJ].setLayoutParams(buttonParams);
            btnHistory[inJ].setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.button_effect));
            tblrRowL[inJ] = new TableRow(ctx);
            tblrRowL[inJ].addView(txtvHistory[inJ]);
            tblrRowL[inJ].addView(btnHistory[inJ]);
            tblltTable.addView(tblrRowL[inJ]);
            final int inK = inJ;
            btnHistory[inK].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // etxt.setText(btns[inK].getText().toString());
                    mHandler.insert(btnHistory[inK].getText().toString());
                    popmW1.dismiss();
                }
            });

            inJ++;
            inL--;
        }

    }
    if (inSize == 0) {
        TextView txtvHistory = new TextView(ctx);
        txtvHistory.setLayoutParams(textParams);
        txtvHistory.setGravity(Gravity.CENTER);
        txtvHistory.setTextColor(Color.WHITE);
        txtvHistory.setText("History Empty");
        TableRow tblrRowL = new TableRow(ctx);
        tblrRowL.addView(txtvHistory);
        tblltTable.addView(tblrRowL);
    }
}

From source file:androidx.media.widget.MediaControlView2.java

@SuppressWarnings("deprecation")
private void initControllerView(ViewGroup v) {
    // Relating to Title Bar View
    mTitleBar = v.findViewById(R.id.title_bar);
    mTitleView = v.findViewById(R.id.title_text);
    mAdExternalLink = v.findViewById(R.id.ad_external_link);
    mBackButton = v.findViewById(R.id.back);
    if (mBackButton != null) {
        mBackButton.setOnClickListener(mBackListener);
        mBackButton.setVisibility(View.GONE);
    }// w ww.  jav  a2s.com
    // TODO (b/77158231) revive
    // mRouteButton = v.findViewById(R.id.cast);

    // Relating to Center View
    mCenterView = v.findViewById(R.id.center_view);
    mTransportControls = inflateTransportControls(R.layout.embedded_transport_controls);
    mCenterView.addView(mTransportControls);

    // Relating to Minimal Extra View
    mMinimalExtraView = (LinearLayout) v.findViewById(R.id.minimal_extra_view);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mMinimalExtraView.getLayoutParams();
    int iconSize = mResources.getDimensionPixelSize(R.dimen.mcv2_embedded_icon_size);
    int marginSize = mResources.getDimensionPixelSize(R.dimen.mcv2_icon_margin);
    params.setMargins(0, (iconSize + marginSize * 2) * (-1), 0, 0);
    mMinimalExtraView.setLayoutParams(params);
    mMinimalExtraView.setVisibility(View.GONE);

    // Relating to Progress Bar View
    mProgress = v.findViewById(R.id.progress);
    if (mProgress != null) {
        if (mProgress instanceof SeekBar) {
            SeekBar seeker = (SeekBar) mProgress;
            seeker.setOnSeekBarChangeListener(mSeekListener);
            seeker.setProgressDrawable(mResources.getDrawable(R.drawable.custom_progress));
            seeker.setThumb(mResources.getDrawable(R.drawable.custom_progress_thumb));
        }
        mProgress.setMax(MAX_PROGRESS);
    }
    mProgressBuffer = v.findViewById(R.id.progress_buffer);

    // Relating to Bottom Bar View
    mBottomBar = v.findViewById(R.id.bottom_bar);

    // Relating to Bottom Bar Left View
    mBottomBarLeftView = v.findViewById(R.id.bottom_bar_left);
    mTimeView = v.findViewById(R.id.time);
    mEndTime = v.findViewById(R.id.time_end);
    mCurrentTime = v.findViewById(R.id.time_current);
    mAdSkipView = v.findViewById(R.id.ad_skip_time);
    mFormatBuilder = new StringBuilder();
    mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());

    // Relating to Bottom Bar Right View
    mBottomBarRightView = v.findViewById(R.id.bottom_bar_right);
    mBasicControls = v.findViewById(R.id.basic_controls);
    mExtraControls = v.findViewById(R.id.extra_controls);
    mCustomButtons = v.findViewById(R.id.custom_buttons);
    mSubtitleButton = v.findViewById(R.id.subtitle);
    if (mSubtitleButton != null) {
        mSubtitleButton.setOnClickListener(mSubtitleListener);
    }
    mFullScreenButton = v.findViewById(R.id.fullscreen);
    if (mFullScreenButton != null) {
        mFullScreenButton.setOnClickListener(mFullScreenListener);
        // TODO: Show Fullscreen button when only it is possible.
    }
    mOverflowButtonRight = v.findViewById(R.id.overflow_right);
    if (mOverflowButtonRight != null) {
        mOverflowButtonRight.setOnClickListener(mOverflowRightListener);
    }
    mOverflowButtonLeft = v.findViewById(R.id.overflow_left);
    if (mOverflowButtonLeft != null) {
        mOverflowButtonLeft.setOnClickListener(mOverflowLeftListener);
    }
    mMuteButton = v.findViewById(R.id.mute);
    if (mMuteButton != null) {
        mMuteButton.setOnClickListener(mMuteButtonListener);
    }
    mSettingsButton = v.findViewById(R.id.settings);
    if (mSettingsButton != null) {
        mSettingsButton.setOnClickListener(mSettingsButtonListener);
    }
    mVideoQualityButton = v.findViewById(R.id.video_quality);
    if (mVideoQualityButton != null) {
        mVideoQualityButton.setOnClickListener(mVideoQualityListener);
    }
    mAdRemainingView = v.findViewById(R.id.ad_remaining);

    // Relating to Settings List View
    initializeSettingsLists();
    mSettingsListView = (ListView) inflateLayout(getContext(), R.layout.settings_list);
    mSettingsAdapter = new SettingsAdapter(mSettingsMainTextsList, mSettingsSubTextsList, mSettingsIconIdsList);
    mSubSettingsAdapter = new SubSettingsAdapter(null, 0);
    mSettingsListView.setAdapter(mSettingsAdapter);
    mSettingsListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mSettingsListView.setOnItemClickListener(mSettingsItemClickListener);

    mEmbeddedSettingsItemWidth = mResources.getDimensionPixelSize(R.dimen.mcv2_embedded_settings_width);
    mFullSettingsItemWidth = mResources.getDimensionPixelSize(R.dimen.mcv2_full_settings_width);
    mEmbeddedSettingsItemHeight = mResources.getDimensionPixelSize(R.dimen.mcv2_embedded_settings_height);
    mFullSettingsItemHeight = mResources.getDimensionPixelSize(R.dimen.mcv2_full_settings_height);
    mSettingsWindowMargin = (-1) * mResources.getDimensionPixelSize(R.dimen.mcv2_settings_offset);
    mSettingsWindow = new PopupWindow(mSettingsListView, mEmbeddedSettingsItemWidth, LayoutParams.WRAP_CONTENT,
            true);
}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

/**
 * ?/*from w w w .  j av  a  2s  .c o  m*/
 *
 * @param msg:
 * @param result:-1->? 0-???
 */
public void showDialogError(String msg, final int result) {
    LayoutInflater inflater = (LayoutInflater) ctxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View grid = inflater.inflate(R.layout.dialog_show_error_one_option, null);

    TextView tvContent = (TextView) grid.findViewById(R.id.tv_dialog_error_content);
    final Button btn_close = (Button) grid.findViewById(R.id.btn_dialog_error_close);

    tvContent.setText(msg);

    OnClickListener ocl = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (v.getId() == btn_close.getId()) {
                if (dialog_show_error != null) {
                    if (dialog_show_error.isShowing()) {
                        dialog_show_error.dismiss();
                    }
                }
                if (result == -1) {
                    finishWithNextActivity(LoginActivity.class);
                }
            }
        }
    };
    btn_close.setOnClickListener(ocl);

    int width = CommonUtils.getScreenWidth(ctxt);
    int height = CommonUtils.getScreenHeight(ctxt);

    if (dialog_show_error == null) {
        dialog_show_error = new PopupWindow(grid, width, height, true);
    }

    dialog_show_error.setBackgroundDrawable(new BitmapDrawable());
    dialog_show_error.setContentView(grid);
    dialog_show_error.setFocusable(true);
    dialog_show_error.setOutsideTouchable(true);
    dialog_show_error.setAnimationStyle(R.style.AutoDialogAnimation);
    try {
        dialog_show_error.showAtLocation(rl_activate, Gravity.NO_GRAVITY, 0, 0);
    } catch (Exception e) {

    }

}

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override//from  w ww  . jav a2s.c om
public void onClick(View vwView) {
    vibrate();
    ctx = PalmCalcActivity.ctx;
    int id = vwView.getId();
    ScientificActivity.txtvShift.setText("");
    switch (id) {

    case R.id.buttonDel:
        mHandler.onDelete();
        break;
    case R.id.button3:
        if (inShift == 0)
            mHandler.insert("3");
        else {
            mHandler.insert(",");
            inShift = 0;
        }
        break;
    case R.id.buttonDot:
        if (inShift == 0)
            mHandler.insert(".");
        else {
            showD();
            inShift = 0;
        }
        break;
    case R.id.buttonAC:
        mHandler.onClear();
        break;

    case R.id.ButtonEqual:
        String strDisplayEq = mHandler.getDisplayText();
        if (!strDisplayEq.equalsIgnoreCase(""))
            mHandler.onEnter();
        break;

    case R.id.ButtonAns:
        if (inShift == 0)
            mHandler.onShow();
        else {
            showHistory();
            inShift = 0;
        }
        break;
    case R.id.buttonDeg:
        mHandler.onDegChange();
        break;
    case R.id.buttonAlt:

        if (inShift == 0) {
            String[] strMode = new String[] { "Floatpt", "FIX", "SCI" };
            int inSizeM = 3;

            LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            vwLayout = inflater.inflate(R.layout.pop_history,
                    (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));
            TextView txtvHeaderPop = (TextView) vwLayout.findViewById(R.id.txtvHeaderPop);
            txtvHeaderPop.setText("MODE");
            popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight,
                    true);
            popmW1.setBackgroundDrawable(new BitmapDrawable());
            popmW1.setOutsideTouchable(true);
            popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
            tblltTable = (TableLayout) vwLayout.findViewById(R.id.tablelay);
            ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
            btnCancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    popmW1.dismiss();

                }
            });
            txtvHistory = new TextView[inSizeM];
            btnHistory = new Button[inSizeM];
            tblrRowL = new TableRow[inSizeM];
            TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                    TableRow.LayoutParams.WRAP_CONTENT, 1f);
            TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                    TableRow.LayoutParams.WRAP_CONTENT, .1f);
            int inJ = 0;
            for (int inI = 0; inI < inSizeM; inI++) {
                btnHistory[inJ] = new Button(ctx);
                txtvHistory[inJ] = new TextView(ctx);
                txtvHistory[inJ].setText("" + (inJ + 1));
                txtvHistory[inJ].setLayoutParams(textParams);
                btnHistory[inJ].setText(strMode[inI]);
                txtvHistory[inJ].setGravity(Gravity.CENTER);
                txtvHistory[inJ]
                        .setTextColor(ScientificActivity.ctx.getResources().getColor(R.color.HistColor));
                btnHistory[inJ].setTextColor(Color.WHITE);
                btnHistory[inJ].setGravity(Gravity.LEFT);
                btnHistory[inJ].setLayoutParams(buttonParams);
                btnHistory[inJ].setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.button_effect));
                tblrRowL[inJ] = new TableRow(ctx);
                tblrRowL[inJ].addView(txtvHistory[inJ]);
                tblrRowL[inJ].addView(btnHistory[inJ]);
                tblltTable.addView(tblrRowL[inJ]);
                final int inK = inJ;
                btnHistory[inK].setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // etxt.setText(btns[inK].getText().toString());
                        ScientificActivity.txtvFSE.setText(btnHistory[inK].getText().toString());
                        popmW1.dismiss();
                    }
                });

                inJ++;

            }

        } else {
            setFSE();
            inShift = 0;
        }
        mHandler.onFSEChange();
        break;
    case R.id.buttonShift:
        if (inShift == 0) {
            inShift = 1;
            mHandler.onShiftPress();
        } else
            inShift = 0;

        break;
    case R.id.buttonHyp:
        if (inHyp == 0) {
            inHyp = 1;
            mHandler.onHypPress();
        } else {
            inHyp = 0;
            ScientificActivity.txtvHyp.setText("");
        }
        break;
    case R.id.buttonMS:
        mHandler.onEnter();
        String strDisplay = mHandler.getDisplayText();
        if (inShift == 0) {

            if (isValidNumber(strDisplay)) {

                PreferenceClass.setMyStringPref(ctx, strDisplay);
                Toast.makeText(ctx, "Memory Saved!", Toast.LENGTH_SHORT).show();
                mHandler.onClear();
            } else
                Toast.makeText(ctx, "Save Failed!", Toast.LENGTH_SHORT).show();

        } else {
            Memstore();
        }

        break;
    case R.id.buttonMR:
        if (inShift == 0) {
            String strPref = PreferenceClass.getMyStringPref(ctx);
            if (!strPref.equalsIgnoreCase("")) {
                mHandler.insert(strPref);
            } else
                Toast.makeText(ctx, "Empty", Toast.LENGTH_SHORT).show();
        } else {
            Memread();
            inShift = 0;

        }
        break;
    case R.id.buttonMp:
        mHandler.onEnter();
        String strDisplay2 = mHandler.getDisplayText();
        if (isValidNumber(strDisplay2)) {
            String strPref2 = PreferenceClass.getMyStringPref(ctx);
            if (!strPref2.equalsIgnoreCase("")) {
                if (inShift == 0) {
                    try {
                        PreferenceClass.setMyStringPref(ctx, "" + mSymbols.eval(strPref2 + "+" + strDisplay2));
                        mHandler.onClear();
                    } catch (SyntaxException e) {

                        e.printStackTrace();
                    }
                    Toast.makeText(ctx, "Value added", Toast.LENGTH_SHORT).show();
                } else {
                    Memplus();

                    inShift = 0;
                }
            }
        }
        break;

    default:
        if (vwView instanceof Button) {
            String strText = ((Button) vwView).getTag().toString();
            if (strText.contains(",")) {
                int inInComa = strText.lastIndexOf(",");
                if (inShift == 1) {
                    strText = strText.substring(inInComa + 1, strText.length());
                    inShift = 0;
                } else {
                    strText = strText.substring(0, inInComa);
                }

            }

            if (inHyp == 1) {

                if (strText.contains("sin(")) {
                    strText = strText.replace("sin(", "sinh(");
                }
                if (strText.contains("cos(")) {
                    strText = strText.replace("cos(", "cosh(");
                }
                if (strText.contains("tan(")) {
                    strText = strText.replace("tan(", "tanh(");
                }
                ScientificActivity.txtvHyp.setText("");
                inHyp = 0;
            }
            mHandler.insert(strText);

        }
    }
}

From source file:com.segma.trim.MainActivity.java

private void showAbout() {
    final View view = ((LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.popup_about, null);

    if (popupWindowAbout == null) {
        float height = ((ImageView) view.findViewById(R.id.imv)).getDrawable().getIntrinsicHeight();
        float width = ((ImageView) view.findViewById(R.id.imv)).getDrawable().getIntrinsicWidth();
        float ratio = height / (2 * width);
        width = Math.round(screenWidth * 0.9f);
        height = width * ratio;//from   w w  w .  j a v  a2  s.co m
        popupWindowAbout = new PopupWindow(view, Math.round(width), Math.round(height), true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
            popupWindowAbout.setOutsideTouchable(true);
        } else {
            popupWindowAbout.setTouchInterceptor(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    popupWindowAbout.dismiss();
                    return false;
                }
            });
        }
        popupWindowAbout.setBackgroundDrawable(new BitmapDrawable());
        popupWindowAbout.setAnimationStyle(R.style.AnimationFade);
        //((TextView) view.findViewById(R.id.about_values)).setLinksClickable(true);
        //((TextView) view.findViewById(R.id.about_values)).setTextIsSelectable(false);
        view.setFocusable(true);
        view.setSelected(false);
        //((TextView) view.findViewById(R.id.about_values)).setText(Html.fromHtml("&#160;&#160;&#160;&#160;&#160; Developer: Edward Yung <p> &#160;&#160;&#160;&#160;&#160; Github: <a href='https://github.com/Edward-Yung'>github.com/Edward-Yung</a>"));
        //((TextView) view.findViewById(R.id.about_values)).setMovementMethod(LinkMovementMethod.getInstance());
    }

    popupWindowAbout.showAtLocation(view, Gravity.CENTER, 0, -findViewById(R.id.tv_density_tag).getHeight());
}

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
private void Memread() {
    spMemory = ctx.getSharedPreferences(PREFNAME, 0);

    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    vwLayout = inflater.inflate(R.layout.memory, (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));

    popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight, true);
    popmW1.setBackgroundDrawable(new BitmapDrawable());
    popmW1.setOutsideTouchable(true);//  ww w. j a  v a  2s.  c  o m

    popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
    ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
    btnCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popmW1.dismiss();

        }
    });
    btns[0] = (Button) vwLayout.findViewById(R.id.btn1);
    btns[1] = (Button) vwLayout.findViewById(R.id.btn2);
    btns[2] = (Button) vwLayout.findViewById(R.id.btn3);
    btns[3] = (Button) vwLayout.findViewById(R.id.btn4);
    btns[4] = (Button) vwLayout.findViewById(R.id.btn5);
    btns[5] = (Button) vwLayout.findViewById(R.id.btn6);
    btns[6] = (Button) vwLayout.findViewById(R.id.btn7);
    btns[7] = (Button) vwLayout.findViewById(R.id.btn8);
    btns[8] = (Button) vwLayout.findViewById(R.id.btn9);
    for (int inI = 0; inI < 9; inI++) {
        btns[inI].setText(spMemory.getString("" + inI, ""));
        final int inK = inI;
        btns[inK].setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mHandler.insert(btns[inK].getText().toString());
                popmW1.dismiss();
            }
        });

    }

}

From source file:com.quwu.xinwo.release.Release_Activity.java

/**
 * //from w w  w.  ja  va 2s  .c  om
 * PopupWindow
 * 
 * */
private void showPopupWindow(View view, final int i) {

    // 
    View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.release_pop, null);

    final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, true);
    popupWindow.setOnDismissListener(new OnDismissListener() {

        public void onDismiss() {
            releaseLin.setAlpha(1f);
        }
    });
    popupWindow.setTouchable(true);

    popupWindow.setTouchInterceptor(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            return false;
            // true?touch
            // ? PopupWindowonTouchEvent?dismiss
        }
    });

    // ?PopupWindowBackdismiss
    // APIbug
    popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));

    // ???show
    int[] location = new int[2];
    view.getLocationOnScreen(location);

    popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] + view.getWidth(), location[1] - 150);

    // 
    TextView year = (TextView) contentView.findViewById(R.id.release_pop_yearText);
    year.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
    TextView month = (TextView) contentView.findViewById(R.id.release_pop_monthText);
    month.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
    TextView day = (TextView) contentView.findViewById(R.id.release_pop_dayText);
    day.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            handler.sendMessage(handler.obtainMessage(i, "/"));
            popupWindow.dismiss();
        }
    });
}