List of usage examples for android.view LayoutInflater getContext
public Context getContext()
From source file:com.apptentive.android.sdk.module.messagecenter.view.AttachmentPreviewDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.apptentive_dialog_image_preview, container); previewContainer = rootView.findViewById(R.id.preview_container); progressBar = (ProgressBar) rootView.findViewById(R.id.preview_progress); previewImageView = (PreviewImageView) rootView.findViewById(R.id.preview_image); previewImageView.setGestureCallback(this); header = (ViewGroup) rootView.findViewById(R.id.header_bar); closeButton = (ImageButton) header.findViewById(R.id.close_dialog); closeButton.setOnClickListener(new View.OnClickListener() { @Override/* ww w .j av a 2s . c o m*/ public void onClick(View v) { dismiss(); } }); // show the progress bar while we load content... progressBar.setVisibility(View.VISIBLE); currentImage = getArguments().getParcelable("image"); width = inflater.getContext().getResources().getDisplayMetrics().widthPixels; height = inflater.getContext().getResources().getDisplayMetrics().heightPixels; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height); previewContainer.setLayoutParams(lp); ApptentiveAttachmentLoader.getInstance().load(currentImage.originalPath, currentImage.localCachePath, 0, previewImageView, width, height, true, new ApptentiveAttachmentLoader.LoaderCallback() { @Override public void onLoaded(ImageView view, int pos, Bitmap d) { if (progressBar != null) { progressBar.setVisibility(View.GONE); } if (previewImageView == view) { previewContainer.setVisibility(View.VISIBLE); if (!d.isRecycled()) { previewImageView.setImageBitmap(d); } } } @Override public void onLoadTerminated() { if (progressBar != null) { progressBar.setVisibility(View.GONE); } } @Override public void onDownloadStart() { if (progressBar != null) { progressBar.setVisibility(View.VISIBLE); } } @Override public void onDownloadProgress(int progress) { } }); return rootView; }
From source file:com.wit.and.dialog.ListDialog.java
/** * <p>/*from w w w .j a v a2s. c om*/ * Invoked to create dialog empty view for list view. * </p> * <p> * Here is the best place to provide custom empty view. * </p> * * @param inflater Layout inflater. * @param container Layout created in the {@link #onCreateBodyView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)} * @param savedInstanceState Saved dialog state. * @return Created empty view. */ protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View emptyView; final ListOptions options = getOptions(); if (options.getEmptyViewRes() != DEFAULT_RES) { // Inflate custom empty view. emptyView = inflater.inflate(options.getEmptyViewRes(), null, false); } else { // Create default empty text view. TextView textView = new TextView(inflater.getContext()); textView.setId(android.R.id.empty); textView.setGravity(Gravity.CENTER); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setVisibility(View.GONE); emptyView = textView; } return emptyView; }
From source file:com.wit.and.dialog.LoginDialog.java
/** * // ww w.ja va2 s. co m */ @Override protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = inflater.getContext(); RelativeLayout layout = new RelativeLayout(context); // Apply neutral layout params. layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Do not allow to apply style to body view. // layout.setId(R.id.Dialog_Layout_Body); // Create layout for loading view. LinearLayout loadingLayout = new LinearLayout(context); loadingLayout.setOrientation(LinearLayout.HORIZONTAL); loadingLayout.setGravity(Gravity.CENTER_VERTICAL); // Allow styling of loading layout as body layout. loadingLayout.setId(R.id.And_Dialog_Layout_Body); // Create text view for message. TextView msgTextView = new TextView(context); msgTextView.setId(R.id.And_Dialog_TextView_Message); // Create circle progress bar. ProgressBar circleProgressBar = new ProgressBar(context); circleProgressBar.setId(R.id.And_Dialog_ProgressBar); // Build loading view. loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.setVisibility(View.GONE); // Insert loading layout into main body layout. RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(loadingLayout, loadingLayoutParams); // Create layout for edit texts. LinearLayout editLayout = new LinearLayout(context); editLayout.setOrientation(LinearLayout.VERTICAL); editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView); // Create edit texts for username and password. EditText userEdit = new EditText(context); userEdit.setId(R.id.And_Dialog_EditText_Username); userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); EditText passEdit = new EditText(context); passEdit.setId(R.id.And_Dialog_EditText_Password); passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // Create edit texts divider. DialogDivider divider = new DialogDivider(context); divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts); // Build edit layout. editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); // Add custom layout. View customView = onCreateCustomView(inflater, editLayout, savedInstanceState); if (customView != null) { editLayout.addView(this.mCustomView = customView); } // Insert edit layout into main body layout. RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(editLayout, editLayoutParams); return layout; }
From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java
/** * Creates a view appropriate for displaying a list of GuidedActions, using the provided * inflater and container.//w w w . j a va2 s .c o m * <p> * <i>Note: Does not actually add the created view to the container; the caller should do * this.</i> * @param inflater The layout inflater to be used when constructing the view. * @param container The view group to be passed in the call to * <code>LayoutInflater.inflate</code>. * @return The view to be added to the caller's view hierarchy. */ public View onCreateView(LayoutInflater inflater, final ViewGroup container) { TypedArray ta = inflater.getContext().getTheme() .obtainStyledAttributes(R.styleable.LeanbackGuidedStepTheme); float keylinePercent = ta.getFloat(R.styleable.LeanbackGuidedStepTheme_guidedStepKeyline, 40); mMainView = (ViewGroup) inflater.inflate(onProvideLayoutId(), container, false); mContentView = mMainView .findViewById(mButtonActions ? R.id.guidedactions_content2 : R.id.guidedactions_content); mBgView = mMainView.findViewById( mButtonActions ? R.id.guidedactions_list_background2 : R.id.guidedactions_list_background); if (mMainView instanceof VerticalGridView) { mActionsGridView = (VerticalGridView) mMainView; } else { mActionsGridView = (VerticalGridView) mMainView .findViewById(mButtonActions ? R.id.guidedactions_list2 : R.id.guidedactions_list); if (mActionsGridView == null) { throw new IllegalStateException("No ListView exists."); } mActionsGridView.setWindowAlignmentOffsetPercent(keylinePercent); mActionsGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); if (!mButtonActions) { mSubActionsGridView = (VerticalGridView) mMainView.findViewById(R.id.guidedactions_sub_list); } } mActionsGridView.setFocusable(false); mActionsGridView.setFocusableInTouchMode(false); // Cache widths, chevron alpha values, max and min text lines, etc Context ctx = mMainView.getContext(); TypedValue val = new TypedValue(); mEnabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionEnabledChevronAlpha); mDisabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionDisabledChevronAlpha); mTitleMinLines = getInteger(ctx, val, R.attr.guidedActionTitleMinLines); mTitleMaxLines = getInteger(ctx, val, R.attr.guidedActionTitleMaxLines); mDescriptionMinLines = getInteger(ctx, val, R.attr.guidedActionDescriptionMinLines); mVerticalPadding = getDimension(ctx, val, R.attr.guidedActionVerticalPadding); mDisplayHeight = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getHeight(); mEnabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_text_alpha)); mDisabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_text_alpha)); mEnabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_description_text_alpha)); mDisabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_description_text_alpha)); return mMainView; }
From source file:com.rbware.github.androidcouchpotato.widget.GuidedActionsStylist.java
/** * Creates a view appropriate for displaying a list of GuidedActions, using the provided * inflater and container.//w w w . j av a 2 s .c o m * <p> * <i>Note: Does not actually add the created view to the container; the caller should do * this.</i> * @param inflater The layout inflater to be used when constructing the view. * @param container The view group to be passed in the call to * <code>LayoutInflater.inflate</code>. * @return The view to be added to the caller's view hierarchy. */ public View onCreateView(LayoutInflater inflater, final ViewGroup container) { TypedArray ta = inflater.getContext().getTheme() .obtainStyledAttributes(R.styleable.LeanbackGuidedStepTheme); float keylinePercent = ta.getFloat(R.styleable.LeanbackGuidedStepTheme_guidedStepKeyline, 40); mMainView = (ViewGroup) inflater.inflate(onProvideLayoutId(), container, false); mContentView = mMainView .findViewById(mButtonActions ? R.id.guidedactions_content2 : R.id.guidedactions_content); mBgView = mMainView.findViewById( mButtonActions ? R.id.guidedactions_list_background2 : R.id.guidedactions_list_background); if (mMainView instanceof VerticalGridView) { mActionsGridView = (VerticalGridView) mMainView; } else { mActionsGridView = (VerticalGridView) mMainView .findViewById(mButtonActions ? R.id.guidedactions_list2 : R.id.guidedactions_list); if (mActionsGridView == null) { throw new IllegalStateException("No ListView exists."); } mActionsGridView.setWindowAlignmentOffsetPercent(keylinePercent); mActionsGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); if (!mButtonActions) { mSubActionsGridView = (VerticalGridView) mMainView.findViewById(R.id.guidedactions_sub_list); mSubActionsBackground = mMainView.findViewById(R.id.guidedactions_sub_list_background); } } mActionsGridView.setFocusable(false); mActionsGridView.setFocusableInTouchMode(false); // Cache widths, chevron alpha values, max and min text lines, etc Context ctx = mMainView.getContext(); TypedValue val = new TypedValue(); mEnabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionEnabledChevronAlpha); mDisabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionDisabledChevronAlpha); mTitleMinLines = getInteger(ctx, val, R.attr.guidedActionTitleMinLines); mTitleMaxLines = getInteger(ctx, val, R.attr.guidedActionTitleMaxLines); mDescriptionMinLines = getInteger(ctx, val, R.attr.guidedActionDescriptionMinLines); mVerticalPadding = getDimension(ctx, val, R.attr.guidedActionVerticalPadding); mDisplayHeight = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getHeight(); mEnabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_text_alpha)); mDisabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_text_alpha)); mEnabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_description_text_alpha)); mDisabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_description_text_alpha)); return mMainView; }
From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java
@Override public View onCreateItemView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View returnView = inflater.inflate(R.layout.fragment_calendar_item, container, false); // TODO: don't put the progress indicator into the header view View progressView = inflater.inflate(R.layout.progress_indicator, null, false); mProgressBar = (ProgressBar) progressView.findViewById(android.R.id.progress); mListView = (ListView) returnView.findViewById(android.R.id.list); mListView.addHeaderView(progressView); mListView.setOnItemClickListener(this); mListView.setHeaderDividersEnabled(false); mListAdapter = new EventListAdapter(inflater.getContext(), null); mListView.setAdapter(mSectionAdapter = new SectionTitlesAdapter(inflater.getContext(), mListAdapter, new SectionIndexer() { @Override//from ww w.j ava2 s . com public String getSectionTitle(int index) { Time start = new Time(TimeZone.getDefault().getID()); start.set(index & 0x00ff, (index >> 8) & 0x00ff, (index >> 16) & 0x0ffff); return DateUtils.formatDateTime(getActivity(), start.toMillis(true), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY); } @Override public int getSectionIndex(Object object) { Cursor cursor = (Cursor) object; Time start = new Time( cursor.getString(cursor.getColumnIndex(WebCalReaderContract.Events.TIMZONE))); start.set(cursor.getLong(cursor.getColumnIndex(WebCalReaderContract.Events.DTSTART))); boolean allday = cursor .getInt(cursor.getColumnIndex(WebCalReaderContract.Events.IS_ALLDAY)) == 1; start.allDay = allday; // we return an encoded date as index return (start.year << 16) + (start.month << 8) + start.monthDay; } }, R.layout.events_preview_list_section_header)); FragmentManager fm = getChildFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mTitleFragment = (CalendarTitleFragment) fm.findFragmentById(R.id.calendar_title_fragment_container); if (mTitleFragment == null) { mTitleFragment = CalendarTitleFragment.newInstance(); ft.replace(R.id.calendar_title_fragment_container, mTitleFragment); } if (!ft.isEmpty()) { ft.commit(); } LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_CALENDAR_ITEM, null, this); lm.initLoader(LOADER_SUBSCRIBED_CALENDAR, null, this); lm.initLoader(LOADER_SUBSCRIPTION, null, this); // set this to true, so the menu is cleared automatically when leaving the fragment, otherwise the star icon will stay visible setHasOptionsMenu(true); return returnView; }
From source file:com.wit.and.dialog.internal.BaseDialog.java
/** * <h5><i>protected View onCreateDialogView(LayoutInflater inflater, * ViewGroup container, Bundle savedInstanceState)</i></h5> * <p>/* w w w .j ava2s . c o m*/ * Create the dialog main view into which will be placed title, body and * buttons view. * </p> * * @param inflater Layout inflater. * @param container Inflated dialog main view. * @param savedInstanceState Saved state. * @return Inflated dialog view. */ protected View onCreateDialogView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout layout = new LinearLayout(inflater.getContext()); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); return layout; }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
@Override protected void onCreateView(LayoutInflater inflater, ViewGroup container) { super.onCreateView(inflater, container); initSwipeRefreshLayout();/*from w ww . j av a 2 s . c o m*/ // Putting the header view inside a container will allow us to make // it invisible later. See checkHeaderViewVisibility() final FrameLayout headerContainer = new FrameLayout(inflater.getContext()); mSearchHeaderView = inflater.inflate(R.layout.search_header, null, false); headerContainer.addView(mSearchHeaderView); getListView().addHeaderView(headerContainer, null, false); checkHeaderViewVisibility(); mSearchProgress = getView().findViewById(R.id.search_progress); mSearchProgressText = (TextView) mSearchHeaderView.findViewById(R.id.totalContactsText); mAlertContainer = getView().findViewById(R.id.alert_container); mAlertText = (TextView) mAlertContainer.findViewById(R.id.alert_text); mAlertDismissIcon = (ImageView) mAlertContainer.findViewById(R.id.alert_dismiss_icon); mAlertText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { turnSyncOn(); } }); mAlertDismissIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); mAlertContainer.setVisibility(View.GONE); }
From source file:rikka.materialpreference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment, R.attr.preferenceFragmentStyle, 0); mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider); final int dividerHeight = a.getInt(R.styleable.PreferenceFragment_android_dividerHeight, -1); a.recycle();//w w w. j a v a2 s. com // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(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(R.id.list_container); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException( "Content has view with id attribute '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; mDividerDecoration = onCreateItemDecoration(); if (mDividerDecoration != null) { mList.addItemDecoration(mDividerDecoration); } setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } listContainer.addView(mList); mHandler.post(mRequestFocus); return view; }
From source file:android.support.v7.preference.PreferenceFragmentCompat.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat, R.attr.preferenceFragmentCompatStyle, 0); mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider); final int dividerHeight = a .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1); a.recycle();/*from w w w. j a v a 2 s . c o m*/ // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(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; }