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:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java
private void showPopup() { if (mScrollState != AbsListView.OnScrollListener.SCROLL_STATE_FLING) { return;//from ww w . j a va2 s . c o 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:im.afterclass.android.fragment.ChatHistoryFragment.java
private void showRightPopupWindow(View v) { LayoutInflater inflater = LayoutInflater.from(getActivity()); View parent = getActivity().findViewById(R.id.main_button); View view = inflater.inflate(R.layout.half_popupwindow, null); String[] themes = new String[] { "?", "??", "" }; List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < themes.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("theme", themes[i]); listItems.add(listItem);// w ww . j a v a 2s . c om } SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems, R.layout.theme_simple_item, new String[] { "theme" }, new int[] { R.id.theme }); ListView themelist = (ListView) view.findViewById(R.id.themeListView); themelist.setAdapter(simpleAdapter); themelist.setOnItemClickListener(new ItemClickListener()); mPopupWindow = new PopupWindow(view); view.startAnimation(animSlideRightin); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); int screenHeight = dm.heightPixels; int[] location = new int[2]; parent.getLocationInWindow(location); Rect frame = new Rect(); getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = frame.width(); mPopupWindow.setHeight(location[1] - getActivity().getActionBar().getHeight() - statusBarHeight); mPopupWindow.setWidth(width / 2); mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.showAtLocation(getActivity().findViewById(R.id.main_bottom), Gravity.BOTTOM | Gravity.RIGHT, 0, screenHeight - location[1]); }
From source file:im.afterclass.android.fragment.ChatHistoryFragment.java
private void showLeftPopupWindow(View v) { LayoutInflater inflater = LayoutInflater.from(getActivity()); View parent = getActivity().findViewById(R.id.main_button); View view = inflater.inflate(R.layout.half_popupwindow, null); String[] themes = new String[] { "?", "??", "" }; List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < themes.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("theme", themes[i]); listItems.add(listItem);//ww w.j av a 2 s .c o m } SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems, R.layout.theme_simple_item, new String[] { "theme" }, new int[] { R.id.theme }); ListView themelist = (ListView) view.findViewById(R.id.themeListView); themelist.setAdapter(simpleAdapter); themelist.setOnItemClickListener(new ItemClickListener()); mPopupWindow = new PopupWindow(view); view.startAnimation(animSlideLeftin); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); int screenHeight = dm.heightPixels; int[] location = new int[2]; parent.getLocationInWindow(location); Rect frame = new Rect(); getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = frame.width(); mPopupWindow.setHeight(location[1] - getActivity().getActionBar().getHeight() - statusBarHeight); mPopupWindow.setWidth(width / 2); mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.showAtLocation(getActivity().findViewById(R.id.main_bottom), Gravity.BOTTOM | Gravity.LEFT, 0, screenHeight - location[1]); }
From source file:net.toload.main.hd.candidate.CandidateView.java
public void doUpdateCandidatePopup() { if (DEBUG)//from w w w . j a v a2 s . co m Log.i(TAG, "doUpdateCandidatePopup(), mHeight:" + mHeight); //Jeremy '11,8.27 do vibrate and sound on candidateview expand button pressed. if (!candidateExpanded) mService.doVibrateSound(0); candidateExpanded = true; requestLayout(); checkHasMoreRecords(); if (mCandidatePopupWindow == null) { mCandidatePopupWindow = new PopupWindow(mContext); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mCandidatePopupContainer = inflater.inflate(R.layout.candidatepopup, (ViewGroup) this.getRootView(), false); mCandidatePopupContainer.setBackgroundColor(mColorBackground); mCandidatePopupWindow.setContentView(mCandidatePopupContainer); ImageButton btnClose = (ImageButton) mCandidatePopupContainer.findViewById(R.id.closeButton); if (btnClose != null) { btnClose.setOnClickListener(this); btnClose.setImageDrawable(mDrawableCloseButton); btnClose.setBackgroundColor(mColorBackground); btnClose.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mCloseButtonHeight = btnClose.getMeasuredHeight(); } mPopupScrollView = (ScrollView) mCandidatePopupContainer.findViewById(R.id.sv); CandidateExpandedView popupCandidate = (CandidateExpandedView) mCandidatePopupContainer .findViewById(R.id.candidatePopup); popupCandidate.setParentCandidateView(this); popupCandidate.setParentScrollView(mPopupScrollView); popupCandidate.setService(mService); mPopupCandidateView = popupCandidate; } if (mSuggestions.size() == 0) return; mCandidatePopupWindow.setContentView(mCandidatePopupContainer); int[] offsetOnScreen = new int[2]; this.getLocationOnScreen(offsetOnScreen); mPopupCandidateView.setSuggestions(mSuggestions); mPopupCandidateView.prepareLayout(); mPopupCandidateView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int popHeight = mScreenHeight - offsetOnScreen[1]; if (mPopupCandidateView.getMeasuredHeight() + mCloseButtonHeight < popHeight) popHeight = mPopupCandidateView.getMeasuredHeight() + mCloseButtonHeight; if (!hasRoomForExpanding()) { popHeight = 3 * (configHeight + mVerticalPadding) + mCloseButtonHeight; if (DEBUG) Log.i(TAG, "doUpdateCandidatePopup(), " + "no enough room for expanded view, expand self first. newHeight:" + popHeight); if (mPopupCandidateView.getMeasuredHeight() + mCloseButtonHeight < popHeight) popHeight = mPopupCandidateView.getMeasuredHeight() + mCloseButtonHeight; this.setLayoutParams(new LinearLayout.LayoutParams(mScreenWidth - mExpandButtonWidth, popHeight)); } if (DEBUG) Log.i(TAG, "doUpdateCandidatePopup(), mHeight=" + mHeight + ", getHeight() = " + getHeight() + ", mPopupCandidateView.getHeight() = " + mPopupCandidateView.getHeight() + ", mPopupScrollView.getHeight() = " + mPopupScrollView.getHeight() + ", offsetOnScreen[1] = " + offsetOnScreen[1] + ", popHeight = " + popHeight + ", CandidateExpandedView.measureHeight = " + mPopupCandidateView.getMeasuredHeight() + ", btnClose.getMeasuredHeight() = " + mCloseButtonHeight); if (mCandidatePopupWindow.isShowing()) { if (DEBUG) Log.i(TAG, "doUpdateCandidatePopup(),mCandidatePopup.isShowing "); mCandidatePopupWindow.update(mScreenWidth, popHeight); } else { mCandidatePopupWindow.setWidth(mScreenWidth); mCandidatePopupWindow.setHeight(popHeight); mCandidatePopupWindow.showAsDropDown(this, 0, -getHeight()); mPopupScrollView.scrollTo(0, 0); } //Jeremy '12,5,31 do update layoutparams after popupWindow update or creation. mPopupCandidateView.setLayoutParams( new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, popHeight - mCloseButtonHeight)); mPopupScrollView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, popHeight - mCloseButtonHeight)); }
From source file:com.vanisty.ui.MenuActivity.java
private void showPopup(final Activity context, Point p) { int popupWidth = 200; int popupHeight = 150; // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup); LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(context); popup.setContentView(layout);//from w w w .j a va 2 s. c o m popup.setWidth(popupWidth); popup.setHeight(popupHeight); popup.setFocusable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. int OFFSET_X = 30; int OFFSET_Y = 30; // Clear the default translucent background popup.setBackgroundDrawable(new BitmapDrawable()); // Displaying the popup at the specified location, + offsets. popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y); // Getting a reference to Close button, and close the popup when clicked. Button close = (Button) layout.findViewById(R.id.close); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); } }); }
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 w w w. j a v a2 s .co 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:net.toload.main.hd.candidate.CandidateView.java
/** * Jeremy '12,6,2 separated from doupdateComposing *//*from w w w . ja v a2 s . c om*/ public void doSetComposing(String composingText) { if (DEBUG) Log.i(TAG, "doSetComposing():" + composingText + "; this.isShown()" + this.isShown() + "(mComposingTextView == null):" + (mComposingTextView == null) + ";(embeddedComposing == null):" + (embeddedComposing != null)); // Initialize mComposingTextView as embedding composing or popup window for fixed candidate mode. Jeremy '15,6,4 if (embeddedComposing != null) { if (mComposingTextView != embeddedComposing) { mComposingTextView = embeddedComposing; mComposingTextView.setBackgroundColor(mColorComposingBackground); mComposingTextView.setTextColor(mColorComposingText); } } else { if (mComposingPopupTextView == null) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mComposingPopupTextView = (TextView) inflater.inflate(R.layout.composingtext, (ViewGroup) getRootView(), false); if (mComposingTextPopup == null) { mComposingTextPopup = new PopupWindow(mContext); mComposingTextPopup.setTouchable(false); } //mComposingTextPopup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //Deprecated in API 23. Jeremy '16,7,16 mComposingTextPopup.setWidth(LayoutParams.WRAP_CONTENT); mComposingTextPopup.setHeight(LayoutParams.WRAP_CONTENT); mComposingTextPopup.setContentView(mComposingPopupTextView); mComposingTextPopup.setBackgroundDrawable(null); } if (mComposingTextView != mComposingPopupTextView) { mComposingTextView = mComposingPopupTextView; mComposingTextView.setBackgroundColor(mColorComposingBackground); mComposingTextView.setTextColor(mColorComposingText); } } if (composingText != null) { mComposingTextView.setText(composingText); //The textsize got is coverted into PX already. Thus force setup the setTextSize in unit of PX. float scaledTextSize = mContext.getResources().getDimensionPixelSize(R.dimen.composing_text_size) * mLIMEPref.getFontSize(); mComposingTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, scaledTextSize); } else return; mComposingTextView.invalidate(); //Jeremy '12,6,2 invalidate and measure so as to get correct height and width later. mComposingTextView.setVisibility(VISIBLE); //Jeremy '15,6, 4 bypass updating popup when composing view is embedded in candidate container if (embeddedComposing == null) doUpdateComposing(); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
public AnyKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //creating the KeyDrawableStateProvider, as it suppose to be backward compatible int keyTypeFunctionAttrId = R.attr.key_type_function; int keyActionAttrId = R.attr.key_type_action; int keyActionTypeDoneAttrId = R.attr.action_done; int keyActionTypeSearchAttrId = R.attr.action_search; int keyActionTypeGoAttrId = R.attr.action_go; LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // int previewLayout = 0; mPreviewKeyTextSize = -1;/*www.j a v a 2s. c om*/ mPreviewLabelTextSize = -1; mPreviewKeyBackground = null; mPreviewKeyTextColor = 0xFFF; final int[] padding = new int[] { 0, 0, 0, 0 }; KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); final int keyboardThemeStyleResId = getKeyboardStyleResId(theme); Log.d(TAG, "Will use keyboard theme " + theme.getName() + " id " + theme.getId() + " res " + keyboardThemeStyleResId); //creating a mapping from the remote Attribute IDs to my local attribute ID. //this is required in order to backward support any build-system (which may cause the attribute IDs to change) final SparseIntArray attributeIdMap = new SparseIntArray(R.styleable.AnyKeyboardViewTheme.length + R.styleable.AnyKeyboardViewIconsTheme.length + ACTION_KEY_TYPES.length + KEY_TYPES.length); final int[] remoteKeyboardThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewTheme, context, theme.getPackageContext(), attributeIdMap); final int[] remoteKeyboardIconsThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewIconsTheme, context, theme.getPackageContext(), attributeIdMap); HashSet<Integer> doneLocalAttributeIds = new HashSet<Integer>(); TypedArray a = theme.getPackageContext().obtainStyledAttributes(keyboardThemeStyleResId, remoteKeyboardThemeStyleable); final int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardThemeStyleable[remoteIndex]); if (setValueFromTheme(a, padding, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.keyBackground) { //keyTypeFunctionAttrId and keyActionAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable(KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyTypeFunctionAttrId = keyStateAttributes[0]; keyActionAttrId = keyStateAttributes[1]; } } } a.recycle(); // taking icons int iconSetStyleRes = theme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard icons theme " + theme.getName() + " id " + theme.getId() + " res " + iconSetStyleRes); if (iconSetStyleRes != 0) { a = theme.getPackageContext().obtainStyledAttributes(iconSetStyleRes, remoteKeyboardIconsThemeStyleable); final int iconsCount = a.getIndexCount(); for (int i = 0; i < iconsCount; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardIconsThemeStyleable[remoteIndex]); if (setKeyIconValueFromTheme(theme, a, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.iconKeyAction) { //keyActionTypeDoneAttrId and keyActionTypeSearchAttrId and keyActionTypeGoAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable( ACTION_KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyActionTypeDoneAttrId = keyStateAttributes[0]; keyActionTypeSearchAttrId = keyStateAttributes[1]; keyActionTypeGoAttrId = keyStateAttributes[2]; } } } a.recycle(); } // filling what's missing KeyboardTheme fallbackTheme = KeyboardThemeFactory.getFallbackTheme(context.getApplicationContext()); final int keyboardFallbackThemeStyleResId = getKeyboardStyleResId(fallbackTheme); Log.d(TAG, "Will use keyboard fallback theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + keyboardFallbackThemeStyleResId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(keyboardFallbackThemeStyleResId, R.styleable.AnyKeyboardViewTheme); final int fallbackCount = a.getIndexCount(); for (int i = 0; i < fallbackCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back theme res ID " + index); setValueFromTheme(a, padding, attrId, index); } a.recycle(); // taking missing icons int fallbackIconSetStyleId = fallbackTheme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard fallback icons theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + fallbackIconSetStyleId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(fallbackIconSetStyleId, R.styleable.AnyKeyboardViewIconsTheme); final int fallbackIconsCount = a.getIndexCount(); for (int i = 0; i < fallbackIconsCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewIconsTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back icon res ID " + index); setKeyIconValueFromTheme(fallbackTheme, a, attrId, index); } a.recycle(); //creating the key-drawable state provider, as we suppose to have the entire data now mDrawableStatesProvider = new KeyDrawableStateProvider(keyTypeFunctionAttrId, keyActionAttrId, keyActionTypeDoneAttrId, keyActionTypeSearchAttrId, keyActionTypeGoAttrId); // settings. // don't forget that there are TWO paddings, the theme's and the // background image's padding! Drawable keyboardBabground = super.getBackground(); if (keyboardBabground != null) { Rect backgroundPadding = new Rect(); keyboardBabground.getPadding(backgroundPadding); padding[0] += backgroundPadding.left; padding[1] += backgroundPadding.top; padding[2] += backgroundPadding.right; padding[3] += backgroundPadding.bottom; } super.setPadding(padding[0], padding[1], padding[2], padding[3]); final Resources res = getResources(); mKeyboardDimens.setKeyboardMaxWidth(res.getDisplayMetrics().widthPixels - padding[0] - padding[2]); mPreviewPopup = new PopupWindow(context); if (mPreviewKeyTextSize > 0) { if (mPreviewLabelTextSize <= 0) mPreviewLabelTextSize = mPreviewKeyTextSize; mPreviewLayut = inflatePreviewWindowLayout(inflate); mPreviewText = (TextView) mPreviewLayut.findViewById(R.id.key_preview_text); mPreviewText.setTextColor(mPreviewKeyTextColor); mPreviewText.setTypeface(mKeyTextStyle); mPreviewIcon = (ImageView) mPreviewLayut.findViewById(R.id.key_preview_icon); mPreviewPopup.setBackgroundDrawable(mPreviewKeyBackground); mPreviewPopup.setContentView(mPreviewLayut); mShowPreview = mPreviewLayut != null; } else { mPreviewLayut = null; mPreviewText = null; mShowPreview = false; } mPreviewPopup.setTouchable(false); mPreviewPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.KeyPreviewAnimation); mDelayBeforePreview = 0; mDelayAfterPreview = 10; mMiniKeyboardParent = this; mMiniKeyboardPopup = new PopupWindow(context.getApplicationContext()); mMiniKeyboardPopup.setBackgroundDrawable(null); mMiniKeyboardPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.MiniKeyboardAnimation); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(mKeyTextSize); mPaint.setTextAlign(Align.CENTER); mPaint.setAlpha(255); mKeyBackgroundPadding = new Rect(0, 0, 0, 0); mKeyBackground.getPadding(mKeyBackgroundPadding); reloadSwipeThresholdsSettings(res); mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance); AskOnGestureListener listener = new AskGestureEventsListener(this); mGestureDetector = AnyApplication.getDeviceSpecific().createGestureDetector(getContext(), listener); mGestureDetector.setIsLongpressEnabled(false); MultiTouchSupportLevel multiTouchSupportLevel = AnyApplication.getDeviceSpecific() .getMultiTouchSupportLevel(getContext()); mHasDistinctMultitouch = multiTouchSupportLevel == MultiTouchSupportLevel.Distinct; mKeyRepeatInterval = 50; AnyApplication.getConfig().addChangedListener(this); }
From source file:net.smartpager.android.activity.MainActivity.java
private void showPopup(View view) { int[] location = new int[2]; view.getLocationOnScreen(location);//w ww . j a v a 2s .c o m Point p = new Point(); p.x = location[0]; p.y = location[1]; int popupWidth = (int) (140 * getResources().getDisplayMetrics().density); int popupHeight = (int) (110 * getResources().getDisplayMetrics().density); // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) this.findViewById(R.id.popup_container); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_status, viewGroup); // Creating the PopupWindow mPopup = new PopupWindow(this); mPopup.setBackgroundDrawable(getResources().getDrawable(R.drawable.def_bg_popup_attachment_static)); mPopup.setContentView(layout); mPopup.setWidth(popupWidth); mPopup.setHeight(popupHeight); mPopup.setFocusable(true); int OFFSET_X = 30; int OFFSET_Y = -popupHeight; layout.findViewById(R.id.popup_set_offline_layout).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!NetworkUtils.isInternetConnectedAsync()) { mPopup.dismiss(); showDialogUnableToChangeStatus(); } else { setStatusService(ContactStatus.DO_NOT_DISTURB, true); } } }); layout.findViewById(R.id.popup_set_online_layout).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!NetworkUtils.isInternetConnectedAsync()) { mPopup.dismiss(); showDialogUnableToChangeStatus(); } else if (SmartPagerApplication.getInstance().getPreferences() .getSyncState() != SyncState.Syncronized) { mPopup.dismiss(); startSyncronization(); showSyncInProgressDialog(); } else { setStatusService(ContactStatus.ONLINE, true); } } }); mPopup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y); }
From source file:it.feio.android.omninotes.DetailFragment.java
@SuppressWarnings("deprecation") private void showPopup(View anchor) { DisplayMetrics metrics = new DisplayMetrics(); mainActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); // Inflate the popup_layout.xml LayoutInflater inflater = (LayoutInflater) mainActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.attachment_dialog, null); // Creating the PopupWindow attachmentDialog = new PopupWindow(mainActivity); attachmentDialog.setContentView(layout); attachmentDialog.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); attachmentDialog.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); attachmentDialog.setFocusable(true); attachmentDialog.setOnDismissListener(() -> { if (isRecording) { isRecording = false;//from w ww . j a v a 2 s .c o m stopRecording(); } }); // Clear the default translucent background attachmentDialog.setBackgroundDrawable(new BitmapDrawable()); // Camera android.widget.TextView cameraSelection = (android.widget.TextView) layout.findViewById(R.id.camera); cameraSelection.setOnClickListener(new AttachmentOnClickListener()); // Audio recording android.widget.TextView recordingSelection = (android.widget.TextView) layout.findViewById(R.id.recording); recordingSelection.setOnClickListener(new AttachmentOnClickListener()); // Video recording android.widget.TextView videoSelection = (android.widget.TextView) layout.findViewById(R.id.video); videoSelection.setOnClickListener(new AttachmentOnClickListener()); // Files android.widget.TextView filesSelection = (android.widget.TextView) layout.findViewById(R.id.files); filesSelection.setOnClickListener(new AttachmentOnClickListener()); // Sketch android.widget.TextView sketchSelection = (android.widget.TextView) layout.findViewById(R.id.sketch); sketchSelection.setOnClickListener(new AttachmentOnClickListener()); // Location android.widget.TextView locationSelection = (android.widget.TextView) layout.findViewById(R.id.location); locationSelection.setOnClickListener(new AttachmentOnClickListener()); // Desktop note with PushBullet if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { android.widget.TextView pushbulletSelection = (android.widget.TextView) layout .findViewById(R.id.pushbullet); pushbulletSelection.setVisibility(View.VISIBLE); pushbulletSelection.setOnClickListener(new AttachmentOnClickListener()); } try { attachmentDialog.showAsDropDown(anchor); } catch (Exception e) { mainActivity.showMessage(R.string.error, ONStyle.ALERT); } }