Example usage for android.widget PopupWindow showAtLocation

List of usage examples for android.widget PopupWindow showAtLocation

Introduction

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

Prototype

@UnsupportedAppUsage
public void showAtLocation(IBinder token, int gravity, int x, int y) 

Source Link

Document

Display the content view in a popup window at the specified location.

Usage

From source file:com.ymt.demo1.plates.exportConsult.ExportConsultMainActivity.java

protected void initTitle() {
    final MyTitle title = (MyTitle) findViewById(R.id.my_title);
    title.setTitleStyle(MyTitle.TitleStyle.RIGHT_ICON_L_R);
    title.setOnLeftActionClickListener(new MyTitle.OnLeftActionClickListener() {
        @Override//from w  w w  .ja va 2  s .  c  o  m
        public void onClick() {
            finish();
        }
    });

    actionListener = new PopActionListener() {
        @Override
        public void onAction(String action) {
            switch (action) {
            case "?":
                if (!(TextUtils.isEmpty(AppContext.now_session_id))) {
                    Intent intent = new Intent(ExportConsultMainActivity.this, ConsultNowActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(ExportConsultMainActivity.this, SignInUpActivity.class);
                    intent.putExtra("isFromConsult", true);
                    startActivity(intent);
                }
                break;
            case "":
                if (TextUtils.isEmpty(AppContext.now_session_id)) {
                    //
                    Intent intent = new Intent(ExportConsultMainActivity.this, SignInUpActivity.class);
                    intent.putExtra("is_back_to_main", false);
                    startActivityForResult(intent, 1024);
                } else {
                    //
                    startActivity(new Intent(ExportConsultMainActivity.this, MyConsultActivity.class));
                }
                break;
            case "?":
                startActivity(new Intent(ExportConsultMainActivity.this, MyHistoryConsultActivity.class));
                break;
            default:
                break;
            }
        }

        @Override
        public void onDismiss() {

        }
    };

    title.setOnRightActionClickListener(new MyTitle.OnRightActionClickListener() {
        @Override
        public void onRightLClick() {
            startActivity(new Intent(ExportConsultMainActivity.this, FullSearchActivity.class));
        }

        @Override
        public void onRightRClick() {
            PopActionUtil popActionUtil = PopActionUtil.getInstance(ExportConsultMainActivity.this);
            if (TextUtils.isEmpty(AppContext.user_type)) {
                popActionUtil.setActions(new String[] { "?", "", "?" });
            } else {
                switch (AppContext.user_type) {
                case "003": //
                case "004": //
                    popActionUtil.setActions(new String[] { "" });
                    break;
                default: //
                    popActionUtil.setActions(new String[] { "?", "", "?" });
                    break;
                }
            }

            PopupWindow popupWindow = popActionUtil.getSimpleTxtPopActionMenu();
            popupWindow.showAtLocation(title.getRootView(), Gravity.TOP | Gravity.END, 10, 100);
            popActionUtil.setActionListener(actionListener);
        }
    });
}

From source file:ab.util.AbDialogUtil.java

/**
 * //from  ww  w  .  j  a v a  2s .  co m
 */
public static MyPop showDatePopWindowHour(Context context, View contentView, View targetView) {
    // 
    hourArrayString = getHMArray(24);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);

    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    // ?
    hourWV.setVisibleItems(5);
    // 
    hourWV.setLabel(":00");
    hourWV.setCyclic(true);
    setHourData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow/*  w ww .j  a v a 2s.c om*/
 */
public static PopupWindow showPopWindow2(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow/*from   w ww . j  a va 2  s .  c  o  m*/
 */
public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

public static MyPop showDatePopWindow(Context context, View contentView, View targetView) {
    // //from   w ww.j a  va 2s  .  c om
    yearArrayString = getYEARArray(2016, 30);
    monthArrayString = getDayArray(12);
    hourArrayString = getHMArray(24);
    minuteArrayString = getHMArray(60);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    yearWV = (WheelView) contentView.findViewById(R.id.time_year);
    monthWV = (WheelView) contentView.findViewById(R.id.time_month);
    dayWV = (WheelView) contentView.findViewById(R.id.time_day);
    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    minuteWV = (WheelView) contentView.findViewById(R.id.time_minute);

    // ?
    yearWV.setVisibleItems(5);
    monthWV.setVisibleItems(5);
    dayWV.setVisibleItems(5);
    hourWV.setVisibleItems(5);
    minuteWV.setVisibleItems(5);

    // 
    yearWV.setLabel("");
    monthWV.setLabel("");
    dayWV.setLabel("");
    hourWV.setLabel("");
    minuteWV.setLabel("");
    yearWV.setCyclic(true);
    monthWV.setCyclic(true);
    dayWV.setCyclic(true);
    hourWV.setCyclic(true);
    minuteWV.setCyclic(true);
    setData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:ab.util.AbDialogUtil.java

/**
 * //w  w w . ja  v  a  2s. c om
 */
public static MyPop showDatePopWindowDate(Context context, View contentView, View targetView) {
    // 
    yearArrayString = getYEARArray(2016, 36);
    monthArrayString = getDayArray(12);
    hourArrayString = getHMArray(24);
    minuteArrayString = getHMArray(60);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    yearWV = (WheelView) contentView.findViewById(R.id.time_year);
    monthWV = (WheelView) contentView.findViewById(R.id.time_month);
    dayWV = (WheelView) contentView.findViewById(R.id.time_day);
    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    minuteWV = (WheelView) contentView.findViewById(R.id.time_minute);
    hourWV.setVisibility(View.GONE);
    minuteWV.setVisibility(View.GONE);
    // ?
    yearWV.setVisibleItems(5);
    monthWV.setVisibleItems(5);
    dayWV.setVisibleItems(5);
    hourWV.setVisibleItems(5);
    minuteWV.setVisibleItems(5);

    // 
    yearWV.setLabel("");
    monthWV.setLabel("");
    dayWV.setLabel("");
    hourWV.setLabel("");
    minuteWV.setLabel("");
    yearWV.setCyclic(true);
    monthWV.setCyclic(true);
    dayWV.setCyclic(true);
    hourWV.setCyclic(true);
    minuteWV.setCyclic(true);
    setData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:com.imagine.BaseActivity.java

void makeErrorPopup(String text) {
    TextView view = new TextView(this);
    view.setText(text);/*w  w  w .j  a v a 2  s . co m*/
    final PopupWindow win = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    final View contentView = findViewById(android.R.id.content);
    contentView.post(new Runnable() {
        public void run() {
            win.showAtLocation(contentView, Gravity.CENTER, 0, 0);
        }
    });
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ? //from  w ww.  j ava  2s  .co m
 */
private void showAddPop() {
    final EditText editText = new EditText(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(layoutParams);
    //        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint("?~");
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));
    editText.setBackgroundColor(getResources().getColor(android.R.color.black));
    final PopupWindow popupWindow = new PopupWindow(editText, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                ProgressDialogUtils.showProgressDialog();
                UnFinishItem item = new UnFinishItem();
                Date date = new Date();
                item.createDay = date;
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                dataList.add(item);
                refreshData(true);
                presenter.addItem(item);
            }
        }
    });
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ???/* w w w.j a v  a  2s .c o m*/
 *
 * @param position
 */
private void modifyItem(final int position) {
    final UnFinishItem item = dataList.get(position);
    LogDetails.d(item);
    LinearLayout linearLayout = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black));

    final EditText editText = new EditText(MainActivity.this);
    editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint(item.content);
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));

    linearLayout.addView(editText);

    Button btnModify = new Button(MainActivity.this);
    btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnModify.setText("");
    btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnModify.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnModify);

    Button btnDeleteItem = new Button(MainActivity.this);
    btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnDeleteItem.setText("");
    btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnDeleteItem);

    final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    btnModify.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                Date date = new Date();
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                item.finishDay = null;
                ProgressDialogUtils.showProgressDialog();
                presenter.modifyItem(item);
                dataList.set(position, item);
                refreshData(true);
                popupWindow.dismiss();
            } else {
                Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show();
            }
        }
    });
    btnDeleteItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataList.remove(position);
            presenter.deleteItem(item);
            refreshData(false);
            popupWindow.dismiss();
        }
    });
}

From source file:com.andfchat.frontend.activities.ChatScreen.java

public void showDescription() {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.popup_description, null);

    int height = (int) (this.height * 0.8f);
    int width = (int) (this.width * 0.8f);

    final PopupWindow descriptionPopup = new FListPopupWindow(layout, width, height);
    descriptionPopup.showAtLocation(chatFragment.getView(), Gravity.CENTER, 0, 0);

    final TextView descriptionText = (TextView) layout.findViewById(R.id.descriptionText);
    descriptionText.setText(SmileyReader.addSmileys(this, chatroomManager.getActiveChat().getDescription()));
    // Enable touching/clicking links in text
    descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
}