List of usage examples for android.widget LinearLayout addView
public void addView(View child, int index)
From source file:chickennugget.spaceengineersdata.material.widgets.ListPopupWindow.java
/** * <p>Builds the popup window's content and returns the height the popup * should have. Returns -1 when the content already exists.</p> * * @return the content's height or -1 if content already exists *//* w w w . j av a2 s. c om*/ private int buildDropDown() { int otherHeights = 0; if (mDropDownList == null) { ViewGroup dropDownView; Context context = mContext; /** * This Runnable exists for the sole purpose of checking if the view layout has got * completed and if so call showDropDown to display the drop down. This is used to show * the drop down as soon as possible after user opens up the search dialog, without * waiting for the normal UI pipeline to do it's job which is slower than this method. */ mShowDropDownRunnable = new Runnable() { public void run() { // View layout should be all done before displaying the drop down. View view = getAnchorView(); if (view != null && view.getWindowToken() != null) { show(); } } }; mDropDownList = new DropDownListView(context, !mModal); if (mDropDownListHighlight != null) { mDropDownList.setSelector(mDropDownListHighlight); } mDropDownList.setAdapter(mAdapter); mDropDownList.setOnItemClickListener(mItemClickListener); mDropDownList.setFocusable(true); mDropDownList.setFocusableInTouchMode(true); mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != -1) { DropDownListView dropDownList = mDropDownList; if (dropDownList != null) { dropDownList.mListSelectionHidden = false; } } } public void onNothingSelected(AdapterView<?> parent) { } }); mDropDownList.setOnScrollListener(mScrollListener); if (mItemSelectedListener != null) { mDropDownList.setOnItemSelectedListener(mItemSelectedListener); } dropDownView = mDropDownList; View hintView = mPromptView; if (hintView != null) { // if a hint has been specified, we accomodate more space for it and // add a text view in the drop down menu, at the bottom of the list LinearLayout hintContainer = new LinearLayout(context); hintContainer.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f); switch (mPromptPosition) { case POSITION_PROMPT_BELOW: hintContainer.addView(dropDownView, hintParams); hintContainer.addView(hintView); break; case POSITION_PROMPT_ABOVE: hintContainer.addView(hintView); hintContainer.addView(dropDownView, hintParams); break; default: Log.e(TAG, "Invalid hint position " + mPromptPosition); break; } // measure the hint's height to find how much more vertical space // we need to add to the drop down's height int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST); int heightSpec = MeasureSpec.UNSPECIFIED; hintView.measure(widthSpec, heightSpec); hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams(); otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; dropDownView = hintContainer; } mPopup.setContentView(dropDownView); } else { final View view = mPromptView; if (view != null) { LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams(); otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; } } // getMaxAvailableHeight() subtracts the padding, so we put it back // to get the available height for the whole window int padding = 0; Drawable background = mPopup.getBackground(); if (background != null) { background.getPadding(mTempRect); padding = mTempRect.top + mTempRect.bottom; // If we don't have an explicit vertical offset, determine one from the window // background so that content will line up. if (!mDropDownVerticalOffsetSet) { mDropDownVerticalOffset = -mTempRect.top; } } else { mTempRect.setEmpty(); } int systemBarsReservedSpace = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // getMaxAvailableHeight() on Lollipop seems to ignore the system bars. systemBarsReservedSpace = Math.max(getSystemBarHeight("status_bar_height"), getSystemBarHeight("navigation_bar_height")); } // Max height available on the screen for a popup. boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; final int maxHeight = mPopup.getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset /*, ignoreBottomDecorations*/) - systemBarsReservedSpace; if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { return maxHeight + padding; } final int childWidthSpec; switch (mDropDownWidth) { case ViewGroup.LayoutParams.WRAP_CONTENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST); break; case ViewGroup.LayoutParams.MATCH_PARENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY); break; default: childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY); break; } final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0, DropDownListView.NO_POSITION, maxHeight - otherHeights, -1); // add padding only if the list has items in it, that way we don't show // the popup if it is not needed if (listContent > 0) otherHeights += padding; return listContent + otherHeights; }
From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.ListPopupWindow.java
/** * <p>Builds the popup window's content and returns the height the popup * should have. Returns -1 when the content already exists.</p> * * @return the content's height or -1 if content already exists *///from w ww.ja v a2 s . c o m @SuppressWarnings("Range") private int buildDropDown() { int otherHeights = 0; if (mDropDownList == null) { ViewGroup dropDownView; Context context = mContext; /** * This Runnable exists for the sole purpose of checking if the view layout has got * completed and if so call showDropDown to display the drop down. This is used to show * the drop down as soon as possible after user opens up the search dialog, without * waiting for the normal UI pipeline to do it's job which is slower than this method. */ mShowDropDownRunnable = new Runnable() { public void run() { // View layout should be all done before displaying the drop down. View view = getAnchorView(); if (view != null && view.getWindowToken() != null) { show(); } } }; mDropDownList = new DropDownListView(context, !mModal); if (mDropDownListHighlight != null) { mDropDownList.setSelector(mDropDownListHighlight); } mDropDownList.setAdapter(mAdapter); mDropDownList.setOnItemClickListener(mItemClickListener); mDropDownList.setFocusable(true); mDropDownList.setFocusableInTouchMode(true); mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != -1) { DropDownListView dropDownList = mDropDownList; if (dropDownList != null) { dropDownList.mListSelectionHidden = false; } } } public void onNothingSelected(AdapterView<?> parent) { } }); mDropDownList.setOnScrollListener(mScrollListener); if (mItemSelectedListener != null) { mDropDownList.setOnItemSelectedListener(mItemSelectedListener); } dropDownView = mDropDownList; View hintView = mPromptView; if (hintView != null) { // if a hint has been specified, we accomodate more space for it and // add a text view in the drop down menu, at the bottom of the list LinearLayout hintContainer = new LinearLayout(context); hintContainer.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f); switch (mPromptPosition) { case POSITION_PROMPT_BELOW: hintContainer.addView(dropDownView, hintParams); hintContainer.addView(hintView); break; case POSITION_PROMPT_ABOVE: hintContainer.addView(hintView); hintContainer.addView(dropDownView, hintParams); break; default: Timber.e("Invalid hint position " + mPromptPosition); break; } // measure the hint's height to find how much more vertical space // we need to add to the drop down's height int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST); int heightSpec = MeasureSpec.UNSPECIFIED; hintView.measure(widthSpec, heightSpec); hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams(); otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; dropDownView = hintContainer; } mPopup.setContentView(dropDownView); } else { final View view = mPromptView; if (view != null) { LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams(); otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; } } // getMaxAvailableHeight() subtracts the padding, so we put it back // to get the available height for the whole window int padding = 0; Drawable background = mPopup.getBackground(); if (background != null) { background.getPadding(mTempRect); padding = mTempRect.top + mTempRect.bottom; // If we don't have an explicit vertical offset, determine one from the window // background so that content will line up. if (!mDropDownVerticalOffsetSet) { mDropDownVerticalOffset = -mTempRect.top; } } else { mTempRect.setEmpty(); } int systemBarsReservedSpace = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // getMaxAvailableHeight() on Lollipop seems to ignore the system bars. systemBarsReservedSpace = Math.max(getSystemBarHeight("status_bar_height"), getSystemBarHeight("navigation_bar_height")); } // Max height available on the screen for a popup. boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; final int maxHeight = mPopup.getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset /*, ignoreBottomDecorations*/) - systemBarsReservedSpace; if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { return maxHeight + padding; } final int childWidthSpec; switch (mDropDownWidth) { case ViewGroup.LayoutParams.WRAP_CONTENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST); break; case ViewGroup.LayoutParams.MATCH_PARENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY); break; default: childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY); break; } final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0, DropDownListView.NO_POSITION, maxHeight - otherHeights, -1); // add padding only if the list has items in it, that way we don't show // the popup if it is not needed if (listContent > 0) otherHeights += padding; return listContent + otherHeights; }
From source file:android.support.v7ox.widget.ListPopupWindow.java
/** * <p>Builds the popup window's content and returns the height the popup * should have. Returns -1 when the content already exists.</p> * * @return the content's height or -1 if content already exists *///from w w w. j a va2 s . c o m private int buildDropDown() { ViewGroup dropDownView; int otherHeights = 0; if (mDropDownList == null) { Context context = mContext; /** * This Runnable exists for the sole purpose of checking if the view layout has got * completed and if so call showDropDown to display the drop down. This is used to show * the drop down as soon as possible after user opens up the search dialog, without * waiting for the normal UI pipeline to do it's job which is slower than this method. */ mShowDropDownRunnable = new Runnable() { public void run() { // View layout should be all done before displaying the drop down. View view = getAnchorView(); if (view != null && view.getWindowToken() != null) { show(); } } }; mDropDownList = new DropDownListView(context, !mModal); if (mDropDownListHighlight != null) { mDropDownList.setSelector(mDropDownListHighlight); } mDropDownList.setAdapter(mAdapter); mDropDownList.setOnItemClickListener(mItemClickListener); mDropDownList.setFocusable(true); mDropDownList.setFocusableInTouchMode(true); mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != -1) { DropDownListView dropDownList = mDropDownList; if (dropDownList != null) { dropDownList.mListSelectionHidden = false; } } } public void onNothingSelected(AdapterView<?> parent) { } }); mDropDownList.setOnScrollListener(mScrollListener); if (mItemSelectedListener != null) { mDropDownList.setOnItemSelectedListener(mItemSelectedListener); } dropDownView = mDropDownList; View hintView = mPromptView; if (hintView != null) { // if a hint has been specified, we accomodate more space for it and // add a text view in the drop down menu, at the bottom of the list LinearLayout hintContainer = new LinearLayout(context); hintContainer.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f); switch (mPromptPosition) { case POSITION_PROMPT_BELOW: hintContainer.addView(dropDownView, hintParams); hintContainer.addView(hintView); break; case POSITION_PROMPT_ABOVE: hintContainer.addView(hintView); hintContainer.addView(dropDownView, hintParams); break; default: Log.e(TAG, "Invalid hint position " + mPromptPosition); break; } // Measure the hint's height to find how much more vertical // space we need to add to the drop down's height. final int widthSize; final int widthMode; if (mDropDownWidth >= 0) { widthMode = MeasureSpec.AT_MOST; widthSize = mDropDownWidth; } else { widthMode = MeasureSpec.UNSPECIFIED; widthSize = 0; } final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); final int heightSpec = MeasureSpec.UNSPECIFIED; hintView.measure(widthSpec, heightSpec); hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams(); otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; dropDownView = hintContainer; } mPopup.setContentView(dropDownView); } else { dropDownView = (ViewGroup) mPopup.getContentView(); final View view = mPromptView; if (view != null) { LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams(); otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; } } // getMaxAvailableHeight() subtracts the padding, so we put it back // to get the available height for the whole window int padding = 0; Drawable background = mPopup.getBackground(); if (background != null) { background.getPadding(mTempRect); padding = mTempRect.top + mTempRect.bottom; // If we don't have an explicit vertical offset, determine one from the window // background so that content will line up. if (!mDropDownVerticalOffsetSet) { mDropDownVerticalOffset = -mTempRect.top; } } else { mTempRect.setEmpty(); } // Max height available on the screen for a popup. final boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; final int maxHeight = getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations); if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { return maxHeight + padding; } final int childWidthSpec; switch (mDropDownWidth) { case ViewGroup.LayoutParams.WRAP_CONTENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST); break; case ViewGroup.LayoutParams.MATCH_PARENT: childWidthSpec = MeasureSpec.makeMeasureSpec( mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY); break; default: childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY); break; } final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0, DropDownListView.NO_POSITION, maxHeight - otherHeights, -1); // add padding only if the list has items in it, that way we don't show // the popup if it is not needed if (listContent > 0) otherHeights += padding; return listContent + otherHeights; }
From source file:com.sft.blackcatapp.EnrollSchoolActivity.java
private void showOpenCityPopupWindow(View parent) { if (openCityPopupWindow == null) { LinearLayout popWindowLayout = (LinearLayout) View.inflate(mContext, R.layout.pop_window, null); popWindowLayout.removeAllViews(); // LinearLayout popWindowLayout = new LinearLayout(mContext); popWindowLayout.setOrientation(LinearLayout.VERTICAL); ListView OpenCityListView = new ListView(mContext); OpenCityListView.setDividerHeight(0); OpenCityListView.setCacheColorHint(android.R.color.transparent); OpenCityListView.setOnItemClickListener(new OnItemClickListener() { @Override/*from ww w . j a v a 2 s . c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { OpenCityVO selectCity = openCityList.get(position); System.out.println(selectCity.getName()); cityname = selectCity.getName(); licensetype = ""; schoolname = ""; ordertype = ""; index = 1; obtainNearBySchool(); openCityPopupWindow.dismiss(); openCityPopupWindow = null; } }); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); popWindowLayout.addView(OpenCityListView, param); OpenCityAdapter openCityAdapter = new OpenCityAdapter(mContext, openCityList); OpenCityListView.setAdapter(openCityAdapter); openCityPopupWindow = new PopupWindow(popWindowLayout, 130, LayoutParams.WRAP_CONTENT); } openCityPopupWindow.setFocusable(true); openCityPopupWindow.setOutsideTouchable(true); // Back??? openCityPopupWindow.setBackgroundDrawable(new BitmapDrawable()); openCityPopupWindow.showAsDropDown(parent); }
From source file:dentex.youtube.downloader.DashboardActivity.java
public void spawnSearchBar() { Utils.logger("d", "showing searchbar...", DEBUG_TAG); EditText inputSearch = new EditText(DashboardActivity.this); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); inputSearch.setLayoutParams(layoutParams); if (TextUtils.isEmpty(searchText)) { inputSearch.setHint(R.string.menu_search); } else {/* ww w.j a va 2 s . c o m*/ inputSearch.setText(searchText); } inputSearch.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); inputSearch.setSingleLine(); inputSearch.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); inputSearch.setId(999); LinearLayout layout = (LinearLayout) findViewById(R.id.dashboard); layout.addView(inputSearch, 0); isSearchBarVisible = true; inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { Utils.logger("d", "Text [" + s + "] - Start [" + start + "] - Before [" + before + "] - Count [" + count + "]", DEBUG_TAG); if (count < before) da.resetData(); da.getFilter().filter(s.toString()); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); }
From source file:android.support.v7.widget.AbstractXpListPopupWindow.java
/** * <p>Builds the popup window's content and returns the height the popup * should have. Returns -1 when the content already exists.</p> * * @return the content's height or -1 if content already exists *//*ww w . j a v a 2 s .c o m*/ private int buildDropDown() { ViewGroup dropDownView; int otherHeights = 0; if (mDropDownList == null) { Context context = mContext; /** * This Runnable exists for the sole purpose of checking if the view layout has got * completed and if so call showDropDown to display the drop down. This is used to show * the drop down as soon as possible after user opens up the search dialog, without * waiting for the normal UI pipeline to do it's job which is slower than this method. */ mShowDropDownRunnable = new Runnable() { public void run() { // View layout should be all done before displaying the drop down. View view = getAnchorView(); if (view != null && view.getWindowToken() != null) { show(); } } }; mDropDownList = createDropDownListView(context, !mModal); if (mDropDownListHighlight != null) { mDropDownList.setSelector(mDropDownListHighlight); } mDropDownList.setAdapter(mAdapter); mDropDownList.setOnItemClickListener(mItemClickListener); mDropDownList.setFocusable(true); mDropDownList.setFocusableInTouchMode(true); mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != -1) { XpDropDownListView dropDownList = mDropDownList; if (dropDownList != null) { dropDownList.setListSelectionHidden(false); } } } public void onNothingSelected(AdapterView<?> parent) { } }); mDropDownList.setOnScrollListener(mScrollListener); if (mItemSelectedListener != null) { mDropDownList.setOnItemSelectedListener(mItemSelectedListener); } dropDownView = mDropDownList; View hintView = mPromptView; if (hintView != null) { // if a hint has been specified, we accomodate more space for it and // add a text view in the drop down menu, at the bottom of the list LinearLayout hintContainer = new LinearLayout(context); hintContainer.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f); switch (mPromptPosition) { case POSITION_PROMPT_BELOW: hintContainer.addView(dropDownView, hintParams); hintContainer.addView(hintView); break; case POSITION_PROMPT_ABOVE: hintContainer.addView(hintView); hintContainer.addView(dropDownView, hintParams); break; default: Log.e(TAG, "Invalid hint position " + mPromptPosition); break; } // Measure the hint's height to find how much more vertical // space we need to add to the drop down's height. final int widthSize; final int widthMode; if (mDropDownWidth >= 0) { widthMode = MeasureSpec.AT_MOST; widthSize = mDropDownWidth > mDropDownMaxWidth ? mDropDownMaxWidth : mDropDownWidth; // widthSize = mDropDownWidth; } else { if (mDropDownMaxWidth >= 0) { widthMode = MeasureSpec.AT_MOST; widthSize = mDropDownMaxWidth; } else { widthMode = MeasureSpec.UNSPECIFIED; widthSize = 0; } } //noinspection Range final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); final int heightSpec = MeasureSpec.UNSPECIFIED; hintView.measure(widthSpec, heightSpec); hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams(); otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; dropDownView = hintContainer; } mPopup.setContentView(dropDownView); } else { dropDownView = (ViewGroup) mPopup.getContentView(); final View view = mPromptView; if (view != null) { LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams(); otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin; } } // getMaxAvailableHeight() subtracts the padding, so we put it back // to get the available height for the whole window int padding = 0; Drawable background = mPopup.getBackground(); if (background != null) { background.getPadding(mTempRect); padding = mTempRect.top + mTempRect.bottom; // If we don't have an explicit vertical offset, determine one from the window // background so that content will line up. // if (!mDropDownVerticalOffsetSet) { // mDropDownVerticalOffset = -mTempRect.top; // } } else { mTempRect.setEmpty(); } final int verticalMargin = mMargins.top + mMargins.bottom; // Max height available on the screen for a popup. final boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; // final int maxHeight = getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations); final int maxHeight = getMaxAvailableHeight(getAnchorView(), ignoreBottomDecorations); if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { return maxHeight - verticalMargin + padding; } final int childWidthSpec; switch (mDropDownWidth) { case ViewGroup.LayoutParams.WRAP_CONTENT: childWidthSpec = MeasureSpec.makeMeasureSpec(getAnchorView().getWidth() - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST); break; case ViewGroup.LayoutParams.MATCH_PARENT: childWidthSpec = MeasureSpec.makeMeasureSpec(mContext.getResources().getDisplayMetrics().widthPixels - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY); break; case PREFERRED: int widthSize; int widthMode; if (mDropDownMaxWidth >= 0) { widthSize = mDropDownMaxWidth - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right); widthMode = MeasureSpec.AT_MOST; childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); } else { widthMode = MeasureSpec.AT_MOST; if (mDropDownMaxWidth == WRAP_CONTENT) { widthSize = getAnchorView().getWidth() - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right); } else { // MATCH_PARENT widthSize = mContext.getResources().getDisplayMetrics().widthPixels - (mMargins.left + mMargins.right) - (mTempRect.left + mTempRect.right); } childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); } break; default: //noinspection Range childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY); break; } final int listPadding = mDropDownList.getPaddingTop() + mDropDownList.getPaddingBottom(); final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0, XpDropDownListView.NO_POSITION, maxHeight - otherHeights - verticalMargin - listPadding + padding, -1); // add padding only if the list has items in it, that way we don't show // the popup if it is not needed if (otherHeights > 0 || listContent > 0) otherHeights += padding + listPadding; return listContent + otherHeights; }
From source file:com.mobiletin.inputmethod.indic.LatinIME.java
@Override public void setInputView(final View view) { super.setInputView(view); mInputView = view;/*from w w w. j a v a2 s. c o m*/ mSuggestionStripView = (SuggestionStripView) view.findViewById(R.id.suggestion_strip_view); if (hasSuggestionStripView()) { mSuggestionStripView.setListener(this, view); } adView = (AdView) view.findViewById(R.id.adView); LinearLayout linearLayout = (LinearLayout) adView.getParent(); View frameLayout = new FrameLayout(this); frameLayout.getLayoutParams(); LayoutParams layoutParams = adView.getLayoutParams(); linearLayout.removeView(adView); linearLayout.removeView(frameLayout); final int layoutDirection = true ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR; ViewCompat.setLayoutDirection(adView, layoutDirection); linearLayout.addView(adView, layoutParams); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); /* layoutParams = this.mCustomView.getLayoutParams(); layoutParams.height = 380; this.mCustomView.setLayoutParams(layoutParams);*/ mInputLogic.setTextDecoratorUi(new TextDecoratorUi(this, view)); }
From source file:cn.hbm.superwechat.adapter.MessageAdapter.java
@SuppressWarnings("ResourceType") private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) { try {//from w w w . j a va 2 s .co m parentView.removeAllViews(); for (int i = 0; i < jsonArr.length(); i++) { final String itemStr = jsonArr.getString(i); final TextView textView = new TextView(context); textView.setText(itemStr); textView.setTextSize(15); try { XmlPullParser xrp = context.getResources().getXml(R.drawable.menu_msg_text_color); textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp)); } catch (Exception e) { e.printStackTrace(); } textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ChatActivity) context).sendText(itemStr); } }); LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llLp.bottomMargin = DensityUtil.dip2px(context, 3); llLp.topMargin = DensityUtil.dip2px(context, 3); parentView.addView(textView, llLp); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:cn.ucai.fulicenter.adapter.MessageAdapter.java
private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) { try {/*from ww w.java 2 s. c o m*/ parentView.removeAllViews(); for (int i = 0; i < jsonArr.length(); i++) { final String itemStr = jsonArr.getString(i); final TextView textView = new TextView(context); textView.setText(itemStr); textView.setTextSize(15); try { XmlPullParser xrp = context.getResources().getXml(R.drawable.menu_msg_text_color); textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp)); } catch (Exception e) { e.printStackTrace(); } textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ChatActivity) context).sendText(itemStr); } }); LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llLp.bottomMargin = DensityUtil.dip2px(context, 3); llLp.topMargin = DensityUtil.dip2px(context, 3); parentView.addView(textView, llLp); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.easemob.chatui.adapter.MessageAdapter.java
private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) { try {/*from w w w . j a va 2 s . c om*/ parentView.removeAllViews(); for (int i = 0; i < jsonArr.length(); i++) { final String itemStr = jsonArr.getString(i); final TextView textView = new TextView(context); textView.setText(itemStr); textView.setTextSize(15); try { XmlPullParser xrp = context.getResources().getXml(R.drawable.menu_msg_text_color); textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp)); } catch (Exception e) { e.printStackTrace(); } textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((ChatActivity) context).sendText(itemStr); } }); LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llLp.bottomMargin = DensityUtil.dip2px(context, 3); llLp.topMargin = DensityUtil.dip2px(context, 3); parentView.addView(textView, llLp); } } catch (JSONException e) { e.printStackTrace(); } }