Example usage for android.widget PopupWindow setWidth

List of usage examples for android.widget PopupWindow setWidth

Introduction

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

Prototype

public void setWidth(int width) 

Source Link

Document

Sets the popup's requested width.

Usage

From source file:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java

private void showPopup() {
    if (mScrollState != AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
        return;//from  w  w  w. j  a v  a  2  s .co m
    }

    if (mPopup == null) {
        PopupWindow p = new PopupWindow(this);
        p.setFocusable(false);
        p.setContentView(mPopupPosition);
        p.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        p.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        p.setAnimationStyle(android.R.style.Animation_Dialog);
        mPopup = p;
    }

    if (mNarratives.getWindowVisibility() == View.VISIBLE) {
        mPopup.showAtLocation(mNarratives, Gravity.CENTER, 0, 0);
    }
}

From source file:com.bf.zxd.zhuangxudai.my.fragment.FinancialApplyFragment.java

private void ChangeIcon() {
    //PopupWindow----START-----??PopupWindowPopupWindow???
    backgroundAlpha(0.3f);//  ww  w . j ava  2s.c o m
    View view = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.popu_window, null);
    final PopupWindow popupWindow = new PopupWindow(view, ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    //??
    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    popupWindow.setWidth(dm.widthPixels);
    popupWindow.setAnimationStyle(R.style.popuwindow);
    //?
    popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    popupWindow.setOnDismissListener(new poponDismissListener_FinancialApplyFragment());

    //PopupWindow-----END
    //PopupWindow
    Button button = (Button) view.findViewById(R.id.take_photo);//??
    Button button1 = (Button) view.findViewById(R.id.all_photo);//?
    Button button2 = (Button) view.findViewById(R.id.out);//?
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
        }
    });
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
            //,?
            allPhoto();
        }
    });
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
            //,Intent????
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            //,??
            File file = FileUitlity.getInstance(getActivity().getApplicationContext()).makeDir("head_image");
            //??
            path = file.getParent() + File.separatorChar + System.currentTimeMillis() + ".jpg";
            //?IntentIntent?
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));
            //?
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            //?Intent??RoundImageView
            startActivityForResult(intent, REQUEST_CODE);
        }
    });
}

From source file:com.bf.zxd.zhuangxudai.my.fragment.CompanyApplyFragment.java

private void ChangeIcon() {
    //PopupWindow----START-----??PopupWindowPopupWindow???
    backgroundAlpha(0.3f);//from  w  w w.j  av  a 2s  .c  o m
    View view = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.popu_window, null);
    final PopupWindow popupWindow = new PopupWindow(view, ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    //??
    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    popupWindow.setWidth(dm.widthPixels);
    popupWindow.setAnimationStyle(R.style.popuwindow);
    //?
    popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    popupWindow.setOnDismissListener(new poponDismissListener_CompanyApplyFragment());

    //PopupWindow-----END
    //PopupWindow
    Button button = (Button) view.findViewById(R.id.take_photo);//??
    Button button1 = (Button) view.findViewById(R.id.all_photo);//?
    Button button2 = (Button) view.findViewById(R.id.out);//?
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
        }
    });
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
            //,?
            Log.i("Daniel", "------");
            allPhoto();
        }
    });
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            backgroundAlpha(1f);
            popupWindow.dismiss();
            //,Intent????
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            //,??
            File file = FileUitlity.getInstance(getActivity().getApplicationContext()).makeDir("head_image");
            //??
            path = file.getParent() + File.separatorChar + System.currentTimeMillis() + ".jpg";
            //?IntentIntent?
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));
            //?
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            //?Intent??RoundImageView
            startActivityForResult(intent, REQUEST_CODE);
        }
    });
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again//from ww  w . j  a  v  a2 s .  c o m
 */
private void showCalendarPicker() {
    // Inflate the popup_layout.xml
    ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root);
    LayoutInflater layoutInflater = (LayoutInflater) getMainActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup);
    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    //or if popup is on edge display it to the left of the circle
    Display display = getMainActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point(0, 0);
    display.getSize(size);

    int OFFSET_X = 25;
    int OFFSET_Y = 25;

    final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(getMainActivity());
    popup.setAnimationStyle(android.R.style.Animation_Dialog);
    popup.setContentView(layout);

    popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    popup.setFocusable(true);
    //gets rid of default background
    popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null));
    //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu));

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y);
    Calendar minDate;
    minDate = Calendar.getInstance();
    this.tempY = minDate.get(Calendar.YEAR);
    this.tempM = minDate.get(Calendar.MONTH);
    this.tempD = minDate.get(Calendar.DAY_OF_MONTH);
    dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                // Months start from 0, so January is month 0
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    tempY = year;
                    tempM = monthOfYear;
                    tempD = dayOfMonth;
                    Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY);
                }
            });
    ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept);
    ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(tempY, tempM, tempD, 1, 0);
            Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis());
            // clear items from clustermanager and submissionMarkerList, as all new submissions
            // need to be fetched based on the selected date
            clusterManager.clearItems();
            submissionMarkerIdList.clear();
            addAdminMarkersToMap();
            setMinDateInMs(calendar.getTimeInMillis());
            popup.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setMinDateInMs(0);
            popup.dismiss();

        }
    });
}

From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java

private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
    int wid = tv.getPaddingLeft() + tv.getPaddingRight();
    int ht = tv.getPaddingTop() + tv.getPaddingBottom();

    //com.android.internal.R.dimen.textview_error_popup_default_width introduced after Gingerbread, only has one variant (240dip)
    int defaultWidthInPixels = mContext.getResources()
            .getDimensionPixelSize(R.dimen.textview_error_popup_default_width);
    Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0,
            true);//from   w w w  . jav a  2s .  c om

    float max = 0;
    for (int i = 0; i < l.getLineCount(); i++) {
        max = Math.max(max, l.getLineWidth(i));
    }

    if (DEBUG)
        Log.d(TAG, "max: " + max + ", height: " + l.getHeight());

    /*
     * Now set the popup size to be big enough for the text plus the border.
     */
    pop.setWidth(wid + (int) Math.ceil(max));
    pop.setHeight(ht + l.getHeight()); //TODO: buggy (the 2 shouldnt need to be there)
}

From source file:org.medcare.Dicom.DicomActivity.java

private void showPopup(View parent, int gravity, int x, int y, int width, int height) {
    Log.e("DicomActivity", "showPopup width = " + width + " height " + height);
    if (DicomActivity.this.mPopup == null) {
        PopupWindow p = new PopupWindow(this);
        p.setFocusable(false);/*from w  w  w. jav  a 2  s  .com*/
        p.setContentView(mPopupView);
        p.setWidth(width);
        p.setHeight(height);
        p.setBackgroundDrawable(null);

        p.setAnimationStyle(R.style.PopupAnimation);
        DicomActivity.this.mPopup = p;
    } else {
        DicomActivity.this.mPopup.setWidth(width);
        DicomActivity.this.mPopup.setHeight(height);
    }
    // coords = myImageController.getCoordinates();
    // hitTestRecr.offset(coords.getX(), coords.getY());
    DicomActivity.this.mPopup.showAtLocation(parent, gravity, x, y);
}

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();/*from  w w w. j  a  va  2 s .com*/
        }
    });

    ((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 ww w .j  a  va  2s.co  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  ww w.  ja  v a  2  s  .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  w  w w  .j av 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 + 4 * DPRatio));
    // Set the text on button in updatePreferenceSaved()

    // set the list view as pop up window content
    popupWindow.setContentView(listView);

    return popupWindow;
}