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:Main.java

public static View showPopupWindow(Context context, int resId, View root, int paramsType) {
    View popupView;/*from www  .jav  a  2 s  .c  o  m*/
    popupView = LayoutInflater.from(context).inflate(resId, null);

    switch (paramsType) {
    case 1:
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);
        break;
    case 2:
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        break;
    case 3:
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);
        break;
    case 4:
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        break;
    default:
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);
        break;
    }
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setTouchable(true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.showAsDropDown(root);
    return popupView;
}

From source file:com.bilibili.socialize.share.utils.selector.PopWrapSharePlatformSelector.java

protected void createShareWindowIfNeed() {
    if (mShareWindow != null)
        return;//from w ww .  j  a v a  2 s.c  o m

    Context context = getContext();
    GridView grid = createShareGridView(context, getItemClickListener());
    mShareWindow = new PopupWindow(grid, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT, true);
    mShareWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    mShareWindow.setOutsideTouchable(true);
    mShareWindow.setAnimationStyle(R.style.socialize_shareboard_animation);
    mShareWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (getDismissListener() != null)
                getDismissListener().onDismiss();
        }
    });
}

From source file:com.jwork.dhammapada.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.v(this, "onCreate()");
    if (CrashHandler.getInstance().isCrashFlag()) {
        log.v(this, "Crash flag detected");
        showCrashDialog();//from  w  ww. j  a va  2  s. co m
    } else {
        //         setTheme(MainActivity.THEME);
        //         requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        mainLayout = (FrameLayout) findViewById(R.id.mainLayout);
        mainLayout.getForeground().setAlpha(0);

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        aboutWindow = new PopupWindow(inflater.inflate(R.layout.activity_about, null, false),
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
        TextView text = ((TextView) aboutWindow.getContentView().findViewById(R.id.about_text));
        text.setText(Html.fromHtml(
                getString(R.string.about_html).replaceAll("\\{0\\}", CrashHandler.getVersionName(this))
                        .replaceAll("\\{1\\}", "" + CrashHandler.getVersionCode(this))));
        text.setMovementMethod(LinkMovementMethod.getInstance());
        ImageButton button = ((ImageButton) aboutWindow.getContentView().findViewById(R.id.about_ok));
        button.setOnClickListener(this);

        controller = new DhammapadaController(this, viewHandler);

        Message message = Message.obtain();
        message.what = Constant.WHAT_DISPLAY_CHAPTER;
        controller.executeMessage(message);

        message = Message.obtain();
        message.what = Constant.WHAT_INIT;
        controller.executeMessage(message);

        //         ActionBar actionBar = getSupportActionBar();
        //         actionBar.hide();
        //         actionBar.setTitle("Dhammapada");
        //         actionBar.setSubtitle("Chapter");
        //         actionBar.setLogo(R.drawable.ic_launcher);
        //         actionBar.show();
    }
}

From source file:io.lqd.sdk.visual.SlideUp.java

private void setUpSlideUp() {
    LayoutInflater layoutInflater = (LayoutInflater) mContext
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    container = (ViewGroup) layoutInflater.inflate(R.layout.activity_slide_up, null);
    TextView mViewMessage = (TextView) container.findViewById(R.id.slideUpText);

    Typeface RegularLato = Typeface.createFromAsset(mContext.getAssets(), "fonts/Lato-Regular.ttf");

    // Set the font
    mViewMessage.setTypeface(RegularLato);

    // Set the message
    mViewMessage.setText(mSlideModel.getMessage());

    // Change Background Color
    container.findViewById(R.id.lowest_layout).setBackgroundColor(Color.parseColor(mSlideModel.getBgColor()));

    // Change Text Color
    ((TextView) container.findViewById(R.id.slideUpText))
            .setTextColor(Color.parseColor(mSlideModel.getMessageColor()));

    // Get View's height depending on device
    final ViewTreeObserver observer = container.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*w ww.ja v a2s .c  om*/
        public void onGlobalLayout() {
            height = container.getHeight();
        }
    });

    mPopupWindow = new PopupWindow(container, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, true);

    mPopupWindow.setFocusable(false);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Liquid.getInstance().showInAppMessages();
        }
    });
}

From source file:com.bilibili.socialize.share.utils.selector.PopFullScreenSharePlatformSelector.java

private void createShareWindowIfNeed() {
    if (mShareWindow != null)
        return;//ww w.  j  a v a 2 s  .  c  om

    Context context = getContext();

    grid = createShareGridView(context, getItemClickListener());
    RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    gridParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    grid.setLayoutParams(gridParams);

    mContainerView = new RelativeLayout(getContext());
    mContainerView.setBackgroundColor(getContext().getResources().getColor(R.color.bili_socialize_black_trans));
    RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    mContainerView.setLayoutParams(containerParams);
    mContainerView.addView(grid);
    mContainerView.setOnClickListener(this);

    mShareWindow = new PopupWindow(mContainerView, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT, true);
    grid.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    mShareWindow.setOutsideTouchable(true);
    mShareWindow.setAnimationStyle(-1);
    mShareWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (getDismissListener() != null)
                getDismissListener().onDismiss();
        }
    });
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

/**
  * Afficher sur la map un popup qui affiche les
  * informations de l'utilisateur connect.
  */// w  ww  .j a v  a  2s .c  o  m
public final void popupDisplayUserInfos() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;

    int popupWidth = (int) (width * 0.75);
    //int popupHeight = height / 2;

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupAccount);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_account, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupUserInfos = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupUserInfos.setBackgroundDrawable(new BitmapDrawable());
    popupUserInfos.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupUserInfos.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton pour se dconnecter
    Button close = (Button) layout.findViewById(R.id.close);
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            popupUserInfos.dismiss();
        }
    });
}

From source file:com.p_alex.happinesstracker.TodayFragment.java

public void openSamplesPopup(View view) {
    Log.d("Popup", "show popup");

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(R.layout.activity_popup, null);

    ImageButton sadButton = (ImageButton) popupView.findViewById(R.id.button_smile_sad);
    sadButton.setOnClickListener(new View.OnClickListener() {
        @Override// w ww . j a v  a 2s  . co m
        public void onClick(View v) {
            clickButtonSad(v);
        }
    });

    ImageButton normalButton = (ImageButton) popupView.findViewById(R.id.button_smile_normal);
    normalButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            clickButtonNormal(v);
        }
    });

    ImageButton happyButton = (ImageButton) popupView.findViewById(R.id.button_smile_happy);
    happyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            clickButtonHappy(v);
        }
    });

    popup = new PopupWindow(popupView, 800, 300, true);
    popup.setOutsideTouchable(true);
    popup.setBackgroundDrawable(new BitmapDrawable());
    popup.showAsDropDown((FloatingActionButton) getView().findViewById(R.id.fab), -400, 40);
}

From source file:org.app.enjoy.musicplayer.FileExplorerActivity.java

protected void initPopupWindow(final List<MusicData> list) {
    // TODO: 15/10/9
    //?activity_pop_left.xml 
    final View popipWindow_view = getLayoutInflater().inflate(R.layout.music_list, null, false);
    //Popupwindow 200LayoutParams.MATCH_PARENT 
    popupWindow = new PopupWindow(popipWindow_view, ViewGroup.LayoutParams.MATCH_PARENT - 150,
            ViewGroup.LayoutParams.MATCH_PARENT - 150, true);
    ///*from w  ww .j  a v  a  2 s.  com*/
    //        popupWindow.setAnimationStyle(R.style.AnimationFade);
    //
    popipWindow_view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (popipWindow_view != null && popipWindow_view.isShown()) {

                popupWindow.dismiss();
                popupWindow = null;
            }
            return false;
        }
    });
    popupWindow.setBackgroundDrawable(new ColorDrawable(0));
    ListView listView = (ListView) popipWindow_view.findViewById(R.id.local_music_list);
    MusicListAdapter musicListAdapter = new MusicListAdapter(FileExplorerActivity.this, listView);
    musicListAdapter.setDatas(list);
    listView.setAdapter(musicListAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable(Contsant.MUSIC_LIST_KEY, (Serializable) list);
            bundle.putInt(Contsant.POSITION_KEY, position);
            intent.putExtras(bundle);
            intent.setAction("com.app.media.MUSIC_SERVICE");
            intent.putExtra("op", Contsant.PlayStatus.PLAY);// ???
            intent.setPackage(getPackageName());
            startService(intent);
        }
    });
}

From source file:org.ubicollab.nomad.home.HomeScreen.java

private void editPic(final int fileName) {
    // get the instance of the LayoutInflater
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // inflate our view from the corresponding XML file
    View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_menu_root), false);

    Button button_ok = (Button) layout.findViewById(R.id.popup_menu_ok);
    Button button_cancel = (Button) layout.findViewById(R.id.popup_menu_cancel);
    current_picture_popup = (ImageView) findViewById(R.id.popup_currentspace_image);

    // create a 100px width and 200px height popup window
    Display display = getWindowManager().getDefaultDisplay();

    pw = new PopupWindow(layout, display.getWidth() / 4 + display.getWidth() / 2,
            display.getWidth() / 4 + display.getHeight() / 2, true);
    // set actions to buttons we have in our popup

    FileInputStream in = null;//from   w  ww.j a v a  2  s  .com
    BufferedInputStream buf = null;
    try {
        in = new FileInputStream("/sdcard/" + fileName + ".jpg");
        buf = new BufferedInputStream(in);
        Bitmap bMap = BitmapFactory.decodeStream(buf);
        current_picture_popup.setImageBitmap(bMap);
        if (in != null) {
            in.close();
        }
        if (buf != null) {
            buf.close();
        }
    } catch (Exception e) {
        Log.e("Error reading file", e.toString());
    }

    button_ok.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vv) {
            takePicture(fileName);
        }
    });
    button_cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vv) {
            pw.dismiss();
        }
    });
    // finally show the popup in the center of the window
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
}

From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java

private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor,
        String textColor, int textSize, JSONArray data) {
    LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext)
            .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null);

    final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, true);

    popupWindow.setContentView(rootView);
    ///*from  w  w w .j a  va 2s .  com*/
    rootView.setBackgroundColor(Color.parseColor(bgColorStr));
    popupWindow.setContentView(rootView);
    //popupWindow?
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setOutsideTouchable(true);

    int length = data.length();
    List<ItemData> itemDataList = new ArrayList<ItemData>();
    try {
        for (int i = 0; i < length; i++) {
            ItemData item = new ItemData();
            String icon = data.getJSONObject(i).optString("icon", "");
            if (!hasIcon && !TextUtils.isEmpty(icon)) {
                hasIcon = true;
            }
            if (hasIcon) {
                item.setIcon(data.getJSONObject(i).getString("icon"));
            }
            item.setText(data.getJSONObject(i).getString("text"));
            itemDataList.add(item);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < length; i++) {
        LinearLayout linearLayout = new LinearLayout(mContext);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        if (hasIcon) {
            ImageView imageView = new ImageView(mContext);
            imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            String imagePath = itemDataList.get(i).getIcon();
            imageView.setImageBitmap(getBitmapFromPath(imagePath));
            imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0);
            linearLayout.addView(imageView);
        }
        TextView tvText = new TextView(mContext);
        LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvLayoutParams.gravity = Gravity.CENTER_VERTICAL;
        tvText.setLayoutParams(tvLayoutParams);

        tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0);
        tvText.setText(itemDataList.get(i).getText());
        tvText.setTextColor(Color.parseColor(textColor));
        tvText.setTextSize(textSize);
        linearLayout.addView(tvText);
        linearLayout.setTag(i);
        linearLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag()));
                if (popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
        rootView.addView(linearLayout);

        //
        View dividerLine = new View(mContext);
        dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                DensityUtil.dip2px(mContext, 1)));
        dividerLine.setBackgroundColor(Color.parseColor(dividerColor));
        rootView.addView(dividerLine);
    }
    int gravityParam;
    switch (direction) {
    case 0:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    case 1:
        gravityParam = Gravity.RIGHT | Gravity.TOP;
        break;
    case 2:
        gravityParam = Gravity.LEFT | Gravity.BOTTOM;
        break;
    case 3:
        gravityParam = Gravity.RIGHT | Gravity.BOTTOM;
        break;
    default:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    }
    popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y);
}