use of android.view.ViewGroup in project cw-omnibus by commonsguy.
the class RowController method measureContentWidth.
// based on http://stackoverflow.com/a/26814964/115145
private int measureContentWidth(Context ctxt, ListAdapter listAdapter) {
ViewGroup mMeasureParent = null;
int maxWidth = 0;
View itemView = null;
int itemType = 0;
final ListAdapter adapter = listAdapter;
final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
final int positionType = adapter.getItemViewType(i);
if (positionType != itemType) {
itemType = positionType;
itemView = null;
}
if (mMeasureParent == null) {
mMeasureParent = new FrameLayout(ctxt);
}
itemView = adapter.getView(i, itemView, mMeasureParent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
final int itemWidth = itemView.getMeasuredWidth();
if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
}
return maxWidth;
}
use of android.view.ViewGroup in project philm by chrisbanes.
the class ListFragment method onCreateView.
/**
* Provide default implementation to return a simple list view. Subclasses
* can override to replace with their own layout. If doing so, the
* returned view hierarchy <em>must</em> have a ListView whose id
* is {@link android.R.id#list android.R.id.list} and can optionally
* have a sibling view id {@link android.R.id#empty android.R.id.empty}
* that is to be shown when the list is empty.
*
* <p>If you are overriding this method with your own custom content,
* consider including the standard layout {@link android.R.layout#list_content}
* in your layout file, so that you continue to retain all of the standard
* behavior of ListFragment. In particular, this is currently the only
* way to have the built-in indeterminant progress state be shown.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = getActivity();
FrameLayout contentRoot = new FrameLayout(context);
// ------------------------------------------------------------------
ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
progress.setId(INTERNAL_PROGRESS_ID);
progress.setVisibility(View.GONE);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;
contentRoot.addView(progress, lp);
// ------------------------------------------------------------------
FrameLayout lframe = new FrameLayout(context);
lframe.setId(INTERNAL_LIST_CONTAINER_ID);
FontTextView tv = new FontTextView(getActivity());
tv.setId(INTERNAL_EMPTY_ID);
tv.setGravity(Gravity.CENTER);
tv.setFont(FontTextView.FONT_ROBOTO_CONDENSED);
final int p = getResources().getDimensionPixelSize(R.dimen.spacing_major);
tv.setPadding(p, p, p, p);
lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
E lv = createListView(context, inflater);
lv.setId(android.R.id.list);
lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
contentRoot.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// ------------------------------------------------------------------
ProgressBar secondaryProgress = new SmoothProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
secondaryProgress.setId(INTERNAL_SECONDARY_PROGRESS_ID);
secondaryProgress.setVisibility(View.GONE);
secondaryProgress.setIndeterminate(true);
contentRoot.addView(secondaryProgress, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
View root;
if (getParentFragment() == null) {
final LinearLayout toolbarRoot = new LinearLayout(context);
toolbarRoot.setOrientation(LinearLayout.VERTICAL);
// Finally, add the Toolbar
inflater.inflate(R.layout.include_toolbar, toolbarRoot, true);
toolbarRoot.addView(contentRoot, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
root = toolbarRoot;
} else {
root = contentRoot;
}
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return root;
}
use of android.view.ViewGroup in project philm by chrisbanes.
the class LicencesFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mWebView = new WebView(getActivity());
mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return mWebView;
}
use of android.view.ViewGroup in project cw-omnibus by commonsguy.
the class ActionBarSherlockCompat method generateLayout.
private ViewGroup generateLayout() {
if (BuildConfig.DEBUG)
Log.d(TAG, "[generateLayout]");
// Apply data from current theme.
TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) {
throw new IllegalStateException("You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.");
}
if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) {
requestFeature(Window.FEATURE_NO_TITLE);
} else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) {
// Don't allow an action bar if there is no title.
requestFeature(Window.FEATURE_ACTION_BAR);
}
if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) {
requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
}
if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) {
requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
}
a.recycle();
int layoutResource;
if (!hasFeature(Window.FEATURE_NO_TITLE)) {
if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
layoutResource = R.layout.abs__screen_action_bar_overlay;
} else {
layoutResource = R.layout.abs__screen_action_bar;
}
} else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) {
layoutResource = R.layout.abs__screen_simple_overlay_action_mode;
} else {
layoutResource = R.layout.abs__screen_simple;
}
if (BuildConfig.DEBUG)
Log.d(TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource));
View in = mActivity.getLayoutInflater().inflate(layoutResource, null);
mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
ViewGroup contentParent = (ViewGroup) mDecor.findViewById(R.id.abs__content);
if (contentParent == null) {
throw new RuntimeException("Couldn't find content container view");
}
//Make our new child the true content view (for fragments). VERY VOLATILE!
mDecor.setId(View.NO_ID);
contentParent.setId(android.R.id.content);
if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) {
IcsProgressBar progress = getCircularProgressBar(false);
if (progress != null) {
progress.setIndeterminate(true);
}
}
return contentParent;
}
use of android.view.ViewGroup in project cw-omnibus by commonsguy.
the class ActionBarContextView method setSplitActionBar.
@Override
public void setSplitActionBar(boolean split) {
if (mSplitActionBar != split) {
if (mActionMenuPresenter != null) {
// Mode is already active; move everything over and adjust the menu itself.
final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
if (!split) {
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(null);
final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
if (oldParent != null)
oldParent.removeView(mMenuView);
addView(mMenuView, layoutParams);
} else {
// Allow full screen width in split mode.
mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
// No limit to the item count; use whatever will fit.
mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
// Span the whole width
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = mContentHeight;
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(mSplitBackground);
final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
if (oldParent != null)
oldParent.removeView(mMenuView);
mSplitView.addView(mMenuView, layoutParams);
}
}
super.setSplitActionBar(split);
}
}
Aggregations