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) 

Source Link

Document

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

Usage

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//from  w  w  w.j a v  a  2  s.co m
 * @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

/**
 * 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//from w w w  .  j  av  a2 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
 */
@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.example.angel.parkpanda.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    showhideFootWindow(0);/*  w  w  w . ja va2  s. c  om*/
    if (id == R.id.nav_menu_findparking) {
        Intent intent = new Intent(getApplicationContext(), Find_Park.class);
        startActivityForResult(intent, 2);// Activity is started with requestCode 2
        // finish();
    }
    if (id == R.id.nav_menu_account) {
        initViewSetting(false);
        if (LOGININFO.flag == 10) {
            Fragment fragment = new my_account();
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction FT = fragmentManager.beginTransaction();
            FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
            FT.replace(R.id.flContent, fragment).commit();
        } else {
            Fragment fragment = new log_in();
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction FT = fragmentManager.beginTransaction();
            FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
            FT.replace(R.id.flContent, fragment).commit();
        }

    }
    if (id == R.id.nav_menu_help) {
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;

        if (currentapiVersion > 21) {
            showhideFootWindow(0);
            initViewSetting(true);

            LayoutInflater inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.ly_my_help, null);
            layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.popupanim));
            PopupWindow optionspu = new PopupWindow(layout, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);

            optionspu.setFocusable(true);
            optionspu.showAtLocation(layout, Gravity.CENTER, 0, 0);
            optionspu.update(0, 0, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);
            optionspu.setAnimationStyle(R.anim.popupanim);
        } else {

            // initViewSetting(false);

            /*                Fragment fragment = new help_dialog();
                            FragmentManager fragmentManager = getSupportFragmentManager();
                            FragmentTransaction FT = fragmentManager.beginTransaction();
                            FT.setCustomAnimations(R.anim.enter_from_right,
                R.anim.exit_to_left);
                            FT.replace(R.id.flContent, fragment).commit();*/

            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.fragment_help_dialog, null);
            final PopupWindow optionspu = new PopupWindow(popupView, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);

            optionspu.setFocusable(true);
            optionspu.showAtLocation(popupView, Gravity.CENTER, 0, 0);
            Button btnDismiss = (Button) popupView.findViewById(R.id.btn_help_close);

            btnDismiss.setOnClickListener(new Button.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Toast.makeText(getApplicationContext(), "dsdsa", Toast.LENGTH_SHORT).show();
                    optionspu.dismiss();
                    plotMarkers(mMyMarkersArray);
                    initViewSetting(true);
                }

            });
        }

    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:tv.piratemedia.lightcontroler.controller.java

public void popupMenu() {
    MenuView = View.inflate(this, R.layout.menu, null);
    TextView settings = (TextView) MenuView.findViewById(R.id.settings_menu_item);
    TextView DeviceSetup = (TextView) MenuView.findViewById(R.id.setup_menu_item);

    if (DeviceMac.toLowerCase().equals(Utils.GetWifiMac().replace(":", "").toLowerCase())) {
        DeviceSetup.setVisibility(View.VISIBLE);
    } else {/*from   w  ww.j  av  a 2  s.c o  m*/
        DeviceSetup.setVisibility(View.GONE);
    }

    settings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closeMenu();
            Intent intent = new Intent(getApplicationContext(), controlPreferences.class);
            startActivity(intent);
            finish();
        }
    });

    DeviceSetup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Controller.getWifiNetworks();
            closeMenu();
        }
    });

    MenuView.setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_corner));

    mMenu = new PopupWindow(MenuView, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    mMenu.setContentView(MenuView);
    mMenu.setTouchable(true);
    if (Build.VERSION.SDK_INT == 21) {
        mMenu.setElevation((int) dipToPixels(this, 10));
    }

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    mMenu.setAnimationStyle(R.anim.abc_slide_in_top);
    mMenu.setBackgroundDrawable(new BitmapDrawable());
    mMenu.setFocusable(true);
    mMenu.setOutsideTouchable(false);
    mMenu.showAtLocation(findViewById(R.id.container), 0, size.x - (int) dipToPixels(this, 208),
            (int) dipToPixels(this, 32));
    mMenu.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            MenuView.setAnimation(
                    AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_corner));
        }
    });
}

From source file:com.uddchina.youdingdan.MyDateActivity.java

/**
 * popupWindow//from w w  w .  j  a  va  2s.  c  o  m
 *
 * @param linearLayout
 */
private void show(LinearLayout linearLayout) {
    popupwindowShow = new PopupWindow(linearLayout, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.picture_popupwindow_layout, null);
    popupwindowShow.setContentView(view);
    popupwindowShow.setFocusable(true);
    popupwindowShow.setOutsideTouchable(true);
    popupwindowShow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));
    popupwindowShow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0);
    TextView doPhoto = (TextView) view.findViewById(R.id.doPhoto);
    TextView choicePicture = (TextView) view.findViewById(R.id.choicePicture);
    TextView cansol = (TextView) view.findViewById(R.id.cansol);
    //?
    doPhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            doPhoto();
            popupwindowShow.dismiss();
        }
    });
    //
    choicePicture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            doPicture();
            popupwindowShow.dismiss();
        }
    });
    //?
    cansol.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupwindowShow.dismiss();
        }
    });
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
        mActionMode.finish();/*from w  ww.  ja  v a2s .c o m*/
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
    final Context context = getActionBarThemedContext();

    if (mActionModeView == null) {
        if (mIsFloating) {
            mActionModeView = new ActionBarContextView(context);
            mActionModePopup = new PopupWindow(context, null, R.attr.actionModePopupWindowStyle);
            mActionModePopup.setContentView(mActionModeView);
            mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

            TypedValue heightValue = new TypedValue();
            mContext.getTheme().resolveAttribute(R.attr.actionBarSize, heightValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(heightValue.data,
                    mContext.getResources().getDisplayMetrics());
            mActionModeView.setContentHeight(height);
            mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            mShowActionModePopup = new Runnable() {
                public void run() {
                    mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0,
                            0);
                }
            };
        } else {
            ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                // Set the layout inflater so that it is inflated with the action bar's context
                stub.setLayoutInflater(LayoutInflater.from(context));
                mActionModeView = (ActionBarContextView) stub.inflate();
            }
        }
    }

    if (mActionModeView != null) {
        mActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(context, mActionModeView, wrappedCallback,
                mActionModePopup == null);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
            mode.invalidate();
            mActionModeView.initForMode(mode);
            mActionModeView.setVisibility(View.VISIBLE);
            mActionMode = mode;
            if (mActionModePopup != null) {
                mWindow.getDecorView().post(mShowActionModePopup);
            }
            mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

            if (mActionModeView.getParent() != null) {
                ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
            }
        } else {
            mActionMode = null;
        }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void showPopupWindow(View parent) {
    if (popupWindow == null) {
        View view = View.inflate(mContext, R.layout.pop_window, null);

        TextView c1Car = (TextView) view.findViewById(R.id.pop_window_one);
        c1Car.setText(R.string.c1_automatic_gear_car);
        TextView c2Car = (TextView) view.findViewById(R.id.pop_window_two);
        c2Car.setText(R.string.c2_manual_gear_car);
        c1Car.setOnClickListener(this);
        c2Car.setOnClickListener(this);

        popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }/*from  w  w w.  j  av a 2s  .  c om*/
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    // Back???
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    // WindowManager windowManager = (WindowManager)
    // getSystemService(Context.WINDOW_SERVICE);
    // int xPos = -popupWindow.getWidth() / 2
    // + getCustomTitle().getCenter().getWidth() / 2;

    popupWindow.showAsDropDown(parent);

}

From source file:com.uddchina.youdingdan.MyDateActivity.java

/**
 * popupWindow/*from w w  w  . ja  va2s . c  o  m*/
 *
 * @param linearLayout
 */
private void showArea(LinearLayout linearLayout) {
    popuwindowArea = new PopupWindow(linearLayout, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.editone_changeaddress_pop_layout, null);
    popuwindowArea.setContentView(view);
    popuwindowArea.setFocusable(true);
    popuwindowArea.setOutsideTouchable(true);
    popuwindowArea.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));
    popuwindowArea.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0);
    TextView btn_myinfo_cancel = (TextView) view.findViewById(R.id.btn_myinfo_cancel);
    TextView btn_myinfo_sure = (TextView) view.findViewById(R.id.btn_myinfo_sure);
    wv_address_province = (ListView) view.findViewById(R.id.wv_address_province);
    wv_address_city = (ListView) view.findViewById(R.id.wv_address_city);
    wv_address_area = (ListView) view.findViewById(R.id.wv_address_area);
    listenter();
    //?
    btn_myinfo_cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popuwindowArea.dismiss();
        }
    });
    //?
    btn_myinfo_sure.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!dictid.equals("")) {
                mSotreareaContent.setText(pri + ci + ar);
                popuwindowArea.dismiss();
            } else {
                ShowToast.ToToast(MyDateActivity.this, "");
            }
        }
    });
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.ItemListActivity.java

private void buildUserActionsPopup() {
    ListView listView = new ListView(self);
    listView.setBackgroundColor(Color.WHITE);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from   w  w w. java  2s .c  o m*/
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            userActionsPopup.dismiss();
        }
    });

    userActionsPopup = new PopupWindow(listView, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    userActionsPopup.setOutsideTouchable(true);
    userActionsPopup.setFocusable(true);
    userActionsPopup.setBackgroundDrawable(new BitmapDrawable());

    View v = userActionsPopup.getContentView();
    v.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                userActionsPopup.dismiss();
            }
            return false;
        }
    });
}

From source file:com.sft.fragment.SchoolsFragment.java

private void showPopupWindow(View parent) {
    if (popupWindow == null) {
        View view = View.inflate(mContext, R.layout.pop_window, null);

        TextView c1Car = (TextView) view.findViewById(R.id.pop_window_one);
        c1Car.setText(R.string.c1_automatic_gear_car);
        TextView c2Car = (TextView) view.findViewById(R.id.pop_window_two);
        c2Car.setText(R.string.c2_manual_gear_car);
        TextView other = (TextView) view.findViewById(R.id.pop_window_three);
        other.setText(R.string.other);// w w  w.j  av  a2s  .  c  o m
        other.setOnClickListener(this);
        c1Car.setOnClickListener(this);
        c2Car.setOnClickListener(this);

        popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    // Back???
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    // WindowManager windowManager = (WindowManager)
    // getSystemService(Context.WINDOW_SERVICE);
    // int xPos = -popupWindow.getWidth() / 2
    // + getCustomTitle().getCenter().getWidth() / 2;

    popupWindow.showAsDropDown(parent);

}