List of usage examples for android.view LayoutInflater getContext
public Context getContext()
From source file:org.tigase.mobile.roster.RosterFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (DEBUG)/*from www.j a v a2s.c o m*/ Log.d(TAG + "_rf", "onCreateView()"); if (getArguments() != null) { this.rosterLayout = getArguments().getString("layout"); } View layout; if ("groups".equals(this.rosterLayout)) { layout = inflater.inflate(R.layout.roster_list, null); } else if ("flat".equals(this.rosterLayout)) { layout = inflater.inflate(R.layout.roster_list_flat, null); } else if ("grid".equals(this.rosterLayout)) { layout = inflater.inflate(R.layout.roster_list_grid, null); } else { throw new RuntimeException("Unknown roster layout"); } listView = (AbsListView) layout.findViewById(R.id.rosterList); listView.setTextFilterEnabled(true); registerForContextMenu(listView); if (listView instanceof ExpandableListView) { if (c != null) { getActivity().stopManagingCursor(c); } this.c = inflater.getContext().getContentResolver().query(Uri.parse(RosterProvider.GROUP_URI), null, null, null, null); getActivity().startManagingCursor(c); GroupsRosterAdapter.staticContext = inflater.getContext(); this.adapter = new GroupsRosterAdapter(inflater.getContext(), c); ((ExpandableListView) listView).setAdapter((ExpandableListAdapter) adapter); ((ExpandableListView) listView).setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Log.i(TAG, "Clicked on id=" + id); Intent intent = new Intent(); intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG); intent.putExtra("id", id); getActivity().getApplicationContext().sendBroadcast(intent); return true; } }); } else if (listView instanceof ListView || listView instanceof GridView) { if (c != null) { getActivity().stopManagingCursor(c); } this.c = inflater.getContext().getContentResolver().query(Uri.parse(RosterProvider.CONTENT_URI), null, null, null, null); getActivity().startManagingCursor(c); // FlatRosterAdapter.staticContext = inflater.getContext(); if (listView instanceof ListView) { this.adapter = new FlatRosterAdapter(inflater.getContext(), c, R.layout.roster_item); ((ListView) listView).setAdapter((ListAdapter) adapter); } else if (listView instanceof GridView) { this.adapter = new FlatRosterAdapter(inflater.getContext(), c, R.layout.roster_grid_item); ((GridView) listView).setAdapter((ListAdapter) adapter); } listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i(TAG, "Clicked on id=" + id); Intent intent = new Intent(); intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG); intent.putExtra("id", id); getActivity().getApplicationContext().sendBroadcast(intent); } }); } // there can be no connection status icon - we have notifications and // accounts view in Android >= 3.0 this.connectionStatus = (ImageView) layout.findViewById(R.id.connection_status); this.progressBar = (ProgressBar) layout.findViewById(R.id.progressBar1); if (DEBUG) Log.d(TAG + "_rf", "layout created"); long[] expandedIds = savedInstanceState == null ? null : savedInstanceState.getLongArray("ExpandedIds"); if (expandedIds != null) { restoreExpandedState(expandedIds); } return layout; }
From source file:android.support.v14.preference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment, TypedArrayUtils.getAttr(mStyledContext, android.support.v7.preference.R.attr.preferenceFragmentStyle, AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE), 0);/* w ww .j a va 2s.co m*/ mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider); final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1); a.recycle(); // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } listContainer.addView(mList); mHandler.post(mRequestFocus); return view; }
From source file:edu.rutgers.winlab.crowdpp.ui.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { settings = getActivity().getSharedPreferences("config", Context.MODE_PRIVATE); editor = settings.edit();//from www .j ava2s.c om title = new String[] { "Period", "Interval", "Duration", "Location", "Upload", "Project page", "Contact me", "Version" }; content = new String[] { "Specify when you want the service run every day.", "Specify how frequently you want the service to run.", "Specify how long you want to record every time.", "Specify if you want the location data be collected.", "Specify if you want to contribute the data to the cloud.", "Brings you to the project page. Please leave a comment.", "Report a bug or send your comment via email.", "1.0" }; choice = new String[] { settings.getString("start", "").concat(" to ").concat(settings.getString("end", "")), settings.getString("interval", "").concat(" Min"), settings.getString("duration", "").concat(" Min"), settings.getString("location", ""), settings.getString("upload", ""), "", "", "" }; ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < title.length; i++) { HashMap<String, String> map = new HashMap<String, String>(); map.put("tv_settings_title", title[i]); map.put("tv_settings_content", content[i]); map.put("tv_settings_choice", choice[i]); listItem.add(map); } // bind the listview adapter with the setting content SimpleAdapter mSimpleAdapter = new SimpleAdapter(inflater.getContext(), listItem, R.layout.settings_item, new String[] { "tv_settings_title", "tv_settings_content", "tv_settings_choice" }, new int[] { R.id.tv_settings_title, R.id.tv_settings_content, R.id.tv_settings_choice }); setListAdapter(mSimpleAdapter); return super.onCreateView(inflater, container, savedInstanceState); }
From source file:android.support.v7.preference.PreferenceController.java
@Override @NonNull/*w w w . j a va 2 s .com*/ public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @Nullable Bundle savedInstanceState) { mInitDone = false; mHavePrefs = false; final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; if (theme == 0) { throw new IllegalStateException("Must specify preferenceTheme in theme"); } mStyledContext = new ContextThemeWrapper(getActivity(), theme); mPreferenceManager = new PreferenceManager(mStyledContext); final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT); onCreatePreferences(savedInstanceState, rootKey); TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat, R.attr.preferenceFragmentCompatStyle, 0); mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId); mDividerDecoration = new DividerDecoration(); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider); final int dividerHeight = a .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1); final boolean allowDividerAfterLastItem = a .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true); a.recycle(); final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem); listContainer.addView(mList); mHandler.post(mRequestFocus); onViewCreated(view, savedInstanceState); return view; }
From source file:org.dmfs.android.colorpicker.PaletteFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /*// ww w. j a v a 2 s .com * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid, container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use * a hard coded value of 8 dip. * * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); if (android.os.Build.VERSION.SDK_INT > 10) { columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } else { // Android 2 seems to add spacing around the entire gridview columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * mAdapter.getNumColumns(); } } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid unnecessary updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }
From source file:ti.org.dmfs.android.colorpicker.PaletteFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /*// w w w.jav a 2 s . c o m * TODO: build the layout programmatically to get rid of the resources, * so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater .inflate(RHelper.getLayout("org_dmfs_colorpickerdialog_palette_grid"), container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see * http://blahti.wordpress.com/2012/07/23/three * -variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced * in SDK level 16. We need to find a way to get get * the actual spacing. Until then we use a hard * coded value of 8 dip. * * One way would be to use a dimension in the * layout. That would allow us to resolve the * dimension here. However, that would be one step * away from a library without resource * dependencies. Maybe there is an Android dimension * resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); if (android.os.Build.VERSION.SDK_INT > 10) { columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } else { // Android 2 seems to add spacing around the // entire gridview columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * mAdapter.getNumColumns(); } } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the // entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid // unnecessary // updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }
From source file:cx.ring.fragments.SmartListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView"); setHasOptionsMenu(true);/*from w w w. ja v a 2s. c o m*/ View inflatedView = inflater.inflate(cx.ring.R.layout.frag_smartlist, container, false); this.mUserInputHandler = new Handler(); mFloatingActionButton = (FloatingActionButton) inflatedView.findViewById(R.id.newconv_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mSearchMenuItem != null) { mSearchMenuItem.expandActionView(); } } }); mList = (ListView) inflatedView.findViewById(cx.ring.R.id.confs_list); mList.setOnItemClickListener(conversationClickListener); mList.setOnItemLongClickListener(conversationLongClickListener); this.mEmptyTextView = (TextView) inflatedView.findViewById(R.id.emptyTextView); this.mLoader = (ProgressBar) inflatedView.findViewById(R.id.loading_indicator); if (savedInstanceState != null) { this.setLoading(savedInstanceState.getBoolean(STATE_LOADING, false)); } mNewContact = (ViewGroup) inflatedView.findViewById(R.id.newcontact_element); mNewContact.setVisibility(View.GONE); mNewContact.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CallContact c = (CallContact) v.getTag(); if (c == null) return; startConversation(c); } }); mNewContact.findViewById(R.id.quick_call).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CallContact c = (CallContact) mNewContact.getTag(); if (c != null) ((HomeActivity) getActivity()).onCallContact(c); } }); mErrorMessagePane = (ViewGroup) inflatedView.findViewById(R.id.error_msg_pane); mErrorMessageTextView = (TextView) mErrorMessagePane.findViewById(R.id.error_msg_txt); mErrorImageView = (ImageView) mErrorMessagePane.findViewById(R.id.error_image_view); LocalService service = mCallbacks.getService(); if (service != null) { bindService(inflater.getContext(), service); if (service.areConversationsLoaded()) { setLoading(false); } } return inflatedView; }
From source file:org.immopoly.android.adapter.FlatsPagerAdapter.java
private View getFlatView(final Flat flat, final int idx) { LayoutInflater inflater = LayoutInflater.from(mContext.getActivity()); int layout = inPortfolio ? R.layout.teaser_content_portfolio : R.layout.teaser_content; View teaserView = inflater.inflate(layout, null, false); ImageView stateSymbol = (ImageView) teaserView.findViewById(R.id.stateSymbol); if (!flat.owned) { if (flat.age == Flat.AGE_OLD) stateSymbol.setImageResource(R.drawable.house_old); else if (flat.age == Flat.AGE_NEW) stateSymbol.setImageResource(R.drawable.house_new); else/*from w w w.j ava 2s . co m*/ stateSymbol.setImageResource(R.drawable.house); } ((EllipsizingTextView) teaserView.findViewById(R.id.flat_desc_text)).setText(flat.name); ((TextView) teaserView.findViewById(R.id.rooms_text)) .setText(flat.numRooms > 0 ? Integer.toString(flat.numRooms) : "?"); ((TextView) teaserView.findViewById(R.id.qm_text)) .setText(flat.livingSpace > 0 ? numFmt.format(flat.livingSpace) : "?"); ((TextView) teaserView.findViewById(R.id.price_text)).setText(flat.priceValue + " "); // TODO kommt im IS24 JSON immer EUR/MONTH ? if (inPortfolio) { ((LinearLayout) teaserView.findViewById(R.id.takeover_daterow)).setVisibility(View.VISIBLE); String takeoverDate = flat.takeoverDate > 0 ? dateSDF.format(new Date(flat.takeoverDate)) : "?"; ((EllipsizingTextView) teaserView.findViewById(R.id.flat_desc_text)).setMaxLines(3); ((TextView) teaserView.findViewById(R.id.takeover_date)).setText(takeoverDate); if (flat.owned && flat.takeoverTries > 0) { ((LinearLayout) teaserView.findViewById(R.id.takeover_numrow)).setVisibility(View.VISIBLE); ((EllipsizingTextView) teaserView.findViewById(R.id.flat_desc_text)).setMaxLines(2); ((TextView) teaserView.findViewById(R.id.takeovers_text)).setText("" + flat.takeoverTries); } else { ((LinearLayout) teaserView.findViewById(R.id.takeover_numrow)).setVisibility(View.GONE); } } ((EllipsizingTextView) teaserView.findViewById(R.id.flat_desc_text)).setMaxLines(2); teaserView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((OnMapItemClickedListener) mContext.getActivity()).onFlatClicked(flat); } }); ImageView iconView = (ImageView) teaserView.findViewById(R.id.teaser_icon); if (flat.titlePictureSmall.trim().length() > 0) { imageDownloader.download(flat.titlePictureSmall, iconView); } else { iconView.clearAnimation(); iconView.setAnimation(null); iconView.setImageDrawable( inflater.getContext().getResources().getDrawable(R.drawable.portfolio_fallback)); } teaserView.setLayoutParams(new LayoutParams(270, 120)); return teaserView; }