List of usage examples for android.widget PopupWindow PopupWindow
public PopupWindow(View contentView)
Create a new non focusable popup window which can display the contentView.
From source file:com.jhk.whysoformal.activity.musiclist.fragment.MusicListFragment.java
private void showItemWeightPopUp() { if (mItemWeight == null) { mItemWeight = new PopupWindow(getListView()); View view = getActivity().getLayoutInflater().inflate(R.layout.popup_weight_distribution, null); LinearLayout distributionLayout = (LinearLayout) view.findViewById(R.id.distributionLayout); Context ctx = mItemWeight.getContentView().getContext(); BaseSeries data = new BaseSeries(getString(R.string.weight_distribution), new float[][] { new float[] { 0.0f, 2.0f }, new float[] { 1.0f, 1.0f }, new float[] { 2.0f, 1.0f }, new float[] { 3.0f, 1.0f }, new float[] { 4.0f, 1.0f } }, 10, new GraphStyleAttributes(Color.BLUE, 20f, 3f)); List<BaseSeries> entries = new LinkedList<BaseSeries>(); entries.add(data);/*from w w w. j a v a2 s . com*/ distributionLayout.addView(new GraphView(ctx, entries, getString(R.string.distribute_me), new BaseAxis(0, 4, 1, 10, GraphStyleAttributes.sDEFAULT_X_AXIS_LABEL_STYLE_ATTRIBUTES), new BaseAxis(0, 2, 1, 10, GraphStyleAttributes.sDEFAULT_Y_AXIS_LABEL_STYLE_ATTRIBUTES))); view.invalidate(); Button okayButton = (Button) view.findViewById(R.id.weight_distribution_ok_button); okayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mItemWeight.dismiss(); } }); mItemWeight.setFocusable(true); mItemWeight.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); mItemWeight.setHeight(600); mItemWeight.setContentView(view); } mItemWeight.showAtLocation(getListView(), Gravity.CENTER, 0, 0); }
From source file:me.jreilly.JamesTweet.Dashboard.DashFragment.java
/** * Initializes many of the data structures needed for this fragment to work. *//*from w ww . j ava 2 s.c om*/ public void setupTimeline() { try { //Initialize the Realm Helper Functions mRealmHelper = new RealmHelper(this.getActivity(), null); //Initialize the layout to a LinearLayout mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); //Initialize Compose Tweet Window popUp = new PopupWindow(getActivity()); //Instantiate the RealmAdpater for the Recyclerview mTweetAdapter = new RealmAdapter(mDataset, fragView, mShortAnimationDuration, mFragment, null, false); //apply the adapter to the timeline view //this will make it populate the new update data in the view mRecyclerView.setAdapter(mTweetAdapter); //Instantiate the Timeline Updater mTimelineUpdater = new TimelineUpdater(); //Instantiate General Use CallBack the inserts Tweets into the database mCallBack = generateCallback(); mDataset = mRealmHelper.getTweets(50); //Run to get the current tweeets mTimelineUpdater.run(); //Instantiate the RealmAdpater for the Recyclerview mTweetAdapter = new RealmAdapter(mDataset, fragView, mShortAnimationDuration, mFragment, null, false); //apply the adapter to the timeline view //this will make it populate the new update data in the view mRecyclerView.setAdapter(mTweetAdapter); //Instantiate the Timeline Updater mTimelineUpdater = new TimelineUpdater(); Log.e(LOG_TAG, "Finished Setup!"); } catch (Exception te) { Log.e(LOG_TAG, "Failed to fetch timeline: " + te.getMessage()); } }
From source file:com.timothy.android.api.fragment.LeftFragment.java
public void showPopupWindow(int x, int y) { layout = (LinearLayout) LayoutInflater.from(activity).inflate(R.layout.popup, null); listView = (ListView) layout.findViewById(R.id.lv_dialog); listView.setAdapter(new ArrayAdapter<String>(activity, R.layout.popup_item, R.id.tv_text, branchNames)); popupWindow = new PopupWindow(activity); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setWidth(activity.getWindowManager().getDefaultDisplay().getWidth() * 3 / 5); popupWindow.setHeight(activity.getWindowManager().getDefaultDisplay().getHeight() * 4 / 5); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true);// ww w .jav a 2 s . co m popupWindow.setContentView(layout); // popupWindow.showAtLocation(activity.findViewById(R.id.view_pagers), Gravity.LEFT| Gravity.TOP, x, y); popupWindow.showAtLocation(activity.findViewById(R.id.slidingMenu), Gravity.LEFT | Gravity.TOP, x, y); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // String[] contentsArray = activity.filterBranch(arg2+1); contentsArray = activity.filterBranch(arg2 + 1); refreshList(1, contentsArray); SPUtil.save2SP(SPUtil.CURRENT_BRANCH_INDEX, arg2 + 1, sp); String[] branchNameArr = branchNames[arg2].split(","); String branchIndex = branchNameArr[0]; String branchName = branchNameArr[1]; title.setText(branchIndex + " " + branchName); SPUtil.save2SP(SPUtil.BRANCH_PATH_NAME, StringUtil.rmvSpace(branchName), sp); popupWindow.dismiss(); } }); }
From source file:com.survivingwithandroid.pegboard.DreamPinsActivity.java
public void onBackgroundSelected() { LayoutInflater inf = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inf.inflate(R.layout.popbkg_layout, null, false); final PopupWindow pw = new PopupWindow(v); pw.setFocusable(true);/* ww w. jav a2s. c o m*/ pw.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT); pw.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT); TextView changeTxt = (TextView) v.findViewById(R.id.dlgChange); TextView resetTxt = (TextView) v.findViewById(R.id.dlgReset); TextView cancelTxt = (TextView) v.findViewById(R.id.dlgCancel); cancelTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); } }); resetTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); pinTableFrag.setBackground(R.drawable.tilebkg); } }); changeTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); // Start a new Intent to get the picture from the Gallery Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, SELECT_PICTURE); } }); pw.showAtLocation(v, Gravity.CENTER, 0, 0); }
From source file:com.jaredrummler.materialspinner.MaterialSpinner.java
private void init(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner); int defaultColor = getTextColors().getDefaultColor(); backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE); textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor); arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor); hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false); typedArray.recycle();/*from w w w. j a v a 2 s.com*/ setGravity(Gravity.CENTER_VERTICAL | Gravity.START); boolean rtl = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Configuration config = getResources().getConfiguration(); rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; if (rtl) { setLayoutDirection(View.LAYOUT_DIRECTION_RTL); setTextDirection(View.TEXT_DIRECTION_RTL); } } Resources resources = getResources(); int left, right, bottom, top; left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top); if (rtl) { right = resources.getDimensionPixelSize(R.dimen.ms__padding_left); } else { left = resources.getDimensionPixelSize(R.dimen.ms__padding_left); } setClickable(true); setPadding(left, top, right, bottom); setBackgroundResource(R.drawable.ms__selector); if (!hideArrow) { arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow)); DrawableCompat.setTint(arrowDrawable, arrowColor); if (rtl) { setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null); } else { setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null); } } listView = new ListView(context); listView.setId(getId()); listView.setDivider(null); listView.setItemsCanFocus(true); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position >= selectedIndex && position < adapter.getCount()) { position++; } selectedIndex = position; nothingSelected = false; Object item = adapter.get(position); adapter.notifyItemSelected(position); setText(item.toString()); collapse(); if (onItemSelectedListener != null) { //noinspection unchecked onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item); } } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(16); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow)); } if (backgroundColor != Color.WHITE) { // default color is white setBackgroundColor(backgroundColor); } if (textColor != defaultColor) { setTextColor(textColor); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (nothingSelected && onNothingSelectedListener != null) { onNothingSelectedListener.onNothingSelected(MaterialSpinner.this); } if (!hideArrow) { animateArrow(false); } } }); }
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();// w ww . ja va 2 s . c o m } }); ((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:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java
private void init(Context context, AttributeSet attrs) { Resources resources = getResources(); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner); int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit); setGravity(Gravity.CENTER_VERTICAL | Gravity.START); setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding, defaultPadding);//from ww w .j a v a2 s. co m setClickable(true); backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector); setBackgroundResource(backgroundSelector); textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context)); setTextColor(textColor); listView = new ListView(context); // Set the spinner's id into the listview to make it pretend to be the right parent in // onItemClick listView.setId(getId()); listView.setDivider(new ColorDrawable(Color.GRAY)); listView.setDividerHeight(1); listView.setItemsCanFocus(true); //hide vertical and horizontal scrollbars listView.setVerticalScrollBarEnabled(false); listView.setHorizontalScrollBarEnabled(false); listView.setOverScrollMode(OVER_SCROLL_NEVER); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedIndex = position; if (onItemClickListener != null) { onItemClickListener.onItemClick(parent, view, position, id); } if (onItemSelectedListener != null) { onItemSelectedListener.onItemSelected(parent, view, position, id); } adapter.setSelectedIndex(position); setTextInternal(adapter.getItemInDataset(position).toString()); dismissDropDown(); } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(DEFAULT_ELEVATION); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow)); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (!isArrowHidden) { animateArrow(false); } } }); isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false); arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE); arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow); dropDownListPaddingBottom = typedArray .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0); typedArray.recycle(); measureDisplayHeight(); }
From source file:com.tfc.webviewer.ui.WebViewerActivity.java
private void initPopupMenu() { @SuppressLint("InflateParams") View view = LayoutInflater.from(this).inflate(R.layout.popup_menu, null); mPopupMenu = new PopupWindow(this); mPopupMenu.setContentView(view);//from www .j a v a2s.c o m mPopupMenu.setOutsideTouchable(true); mPopupMenu.setFocusable(true); mLlControlButtons = (RelativeLayout) view.findViewById(R.id.popup_menu_rl_arrows); mBtnBack = (AppCompatImageButton) view.findViewById(R.id.popup_menu_btn_back); mBtnFoward = (AppCompatImageButton) view.findViewById(R.id.popup_menu_btn_forward); mBtnBack.setOnClickListener(this); mBtnFoward.setOnClickListener(this); view.findViewById(R.id.popup_menu_btn_refresh).setOnClickListener(this); view.findViewById(R.id.popup_menu_btn_copy_link).setOnClickListener(this); view.findViewById(R.id.popup_menu_btn_open_with_other_browser).setOnClickListener(this); view.findViewById(R.id.popup_menu_btn_share).setOnClickListener(this); }
From source file:com.dycody.android.idealnote.SketchFragment.java
private void showPopup(View anchor, final int eraserOrStroke) { boolean isErasing = eraserOrStroke == SketchView.ERASER; oldColor = mColorPicker.getColor();//ww w. ja v a2 s .c o m DisplayMetrics metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Creating the PopupWindow PopupWindow popup = new PopupWindow(getActivity()); popup.setContentView(isErasing ? popupEraserLayout : popupLayout); popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); popup.setFocusable(true); popup.setOnDismissListener(() -> { if (mColorPicker.getColor() != oldColor) mColorPicker.setOldCenterColor(oldColor); }); // Clear the default translucent background popup.setBackgroundDrawable(new BitmapDrawable()); // Displaying the popup at the specified location, + offsets (transformed // dp to pixel to support multiple screen sizes) popup.showAsDropDown(anchor); // Stroke size seekbar initialization and event managing SeekBar mSeekBar; mSeekBar = (SeekBar) (isErasing ? popupEraserLayout.findViewById(R.id.stroke_seekbar) : popupLayout.findViewById(R.id.stroke_seekbar)); mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // When the seekbar is moved a new size is calculated and the new shape // is positioned centrally into the ImageView setSeekbarProgress(progress, eraserOrStroke); } }); int progress = isErasing ? seekBarEraserProgress : seekBarStrokeProgress; mSeekBar.setProgress(progress); }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private void showPopWindow(SeekBar seekBar, View relativeView) { int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); seekBar.measure(w, h);/* www .ja v a 2 s.com*/ PopupWindow popupWindow = new PopupWindow(seekBar); popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setWidth(seekBar.getMeasuredWidth()); popupWindow.setHeight(EUExUtil.dipToPixels(120)); popupWindow.showAtLocation(mImageContentLayout, Gravity.BOTTOM, relativeView.getLeft() - mImageContentLayout.getWidth() / 2 + relativeView.getWidth() / 2, mCloseLayout.getHeight() + relativeView.getHeight() + 50); }