Example usage for android.view LayoutInflater from

List of usage examples for android.view LayoutInflater from

Introduction

In this page you can find the example usage for android.view LayoutInflater from.

Prototype

public static LayoutInflater from(Context context) 

Source Link

Document

Obtains the LayoutInflater from the given context.

Usage

From source file:android.support.v7.widget.ToolbarWidgetWrapper.java

public ToolbarWidgetWrapper(Toolbar toolbar, boolean style, int defaultNavigationContentDescription,
        int defaultNavigationIcon) {
    mToolbar = toolbar;//from   w  ww. ja  va2s. c om
    mTitle = toolbar.getTitle();
    mSubtitle = toolbar.getSubtitle();
    mTitleSet = mTitle != null;
    mNavIcon = toolbar.getNavigationIcon();
    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(toolbar.getContext(), null,
            R.styleable.ActionBar, R.attr.actionBarStyle, 0);
    mDefaultNavigationIcon = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
    if (style) {
        final CharSequence title = a.getText(R.styleable.ActionBar_title);
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        final CharSequence subtitle = a.getText(R.styleable.ActionBar_subtitle);
        if (!TextUtils.isEmpty(subtitle)) {
            setSubtitle(subtitle);
        }

        final Drawable logo = a.getDrawable(R.styleable.ActionBar_logo);
        if (logo != null) {
            setLogo(logo);
        }

        final Drawable icon = a.getDrawable(R.styleable.ActionBar_icon);
        if (icon != null) {
            setIcon(icon);
        }
        if (mNavIcon == null && mDefaultNavigationIcon != null) {
            setNavigationIcon(mDefaultNavigationIcon);
        }
        setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, 0));

        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            setCustomView(LayoutInflater.from(mToolbar.getContext()).inflate(customNavId, mToolbar, false));
            setDisplayOptions(mDisplayOpts | ActionBar.DISPLAY_SHOW_CUSTOM);
        }

        final int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        if (height > 0) {
            final ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
            lp.height = height;
            mToolbar.setLayoutParams(lp);
        }

        final int contentInsetStart = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetStart, -1);
        final int contentInsetEnd = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetEnd, -1);
        if (contentInsetStart >= 0 || contentInsetEnd >= 0) {
            mToolbar.setContentInsetsRelative(Math.max(contentInsetStart, 0), Math.max(contentInsetEnd, 0));
        }

        final int titleTextStyle = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
        if (titleTextStyle != 0) {
            mToolbar.setTitleTextAppearance(mToolbar.getContext(), titleTextStyle);
        }

        final int subtitleTextStyle = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
        if (subtitleTextStyle != 0) {
            mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), subtitleTextStyle);
        }

        final int popupTheme = a.getResourceId(R.styleable.ActionBar_popupTheme, 0);
        if (popupTheme != 0) {
            mToolbar.setPopupTheme(popupTheme);
        }
    } else {
        mDisplayOpts = detectDisplayOptions();
    }
    a.recycle();

    mDrawableManager = AppCompatDrawableManager.get();

    setDefaultNavigationContentDescription(defaultNavigationContentDescription);
    mHomeDescription = mToolbar.getNavigationContentDescription();

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        final ActionMenuItem mNavItem = new ActionMenuItem(mToolbar.getContext(), 0, android.R.id.home, 0, 0,
                mTitle);

        @Override
        public void onClick(View v) {
            if (mWindowCallback != null && mMenuPrepared) {
                mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mNavItem);
            }
        }
    });
}

From source file:android.support.v7ox.widget.ToolbarWidgetWrapper.java

public ToolbarWidgetWrapper(Toolbar toolbar, boolean style, int defaultNavigationContentDescription,
        int defaultNavigationIcon) {
    mToolbar = toolbar;/*from   w  w w.  j  a  v a  2s  .  c om*/
    mTitle = toolbar.getTitle();
    mSubtitle = toolbar.getSubtitle();
    mTitleSet = mTitle != null;
    mNavIcon = toolbar.getNavigationIcon();

    if (style) {
        final TintTypedArray a = TintTypedArray.obtainStyledAttributes(toolbar.getContext(), null,
                R.styleable.ActionBar, R.attr.actionBarStyle_ox, 0);

        final CharSequence title = a.getText(R.styleable.ActionBar_title);
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        final CharSequence subtitle = a.getText(R.styleable.ActionBar_subtitle);
        if (!TextUtils.isEmpty(subtitle)) {
            setSubtitle(subtitle);
        }

        final Drawable logo = a.getDrawable(R.styleable.ActionBar_logo);
        if (logo != null) {
            setLogo(logo);
        }

        final Drawable icon = a.getDrawable(R.styleable.ActionBar_icon);
        if (mNavIcon == null && icon != null) {
            setIcon(icon);
        }

        final Drawable navIcon = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator_ox);
        if (navIcon != null) {
            setNavigationIcon(navIcon);
        }

        setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, 0));

        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            setCustomView(LayoutInflater.from(mToolbar.getContext()).inflate(customNavId, mToolbar, false));
            setDisplayOptions(mDisplayOpts | ActionBar.DISPLAY_SHOW_CUSTOM);
        }

        final int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        if (height > 0) {
            final ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
            lp.height = height;
            mToolbar.setLayoutParams(lp);
        }

        final int contentInsetStart = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetStart, -1);
        final int contentInsetEnd = a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetEnd, -1);
        if (contentInsetStart >= 0 || contentInsetEnd >= 0) {
            mToolbar.setContentInsetsRelative(Math.max(contentInsetStart, 0), Math.max(contentInsetEnd, 0));
        }

        final int titleTextStyle = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
        if (titleTextStyle != 0) {
            mToolbar.setTitleTextAppearance(mToolbar.getContext(), titleTextStyle);
        }

        final int subtitleTextStyle = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
        if (subtitleTextStyle != 0) {
            mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), subtitleTextStyle);
        }

        final int popupTheme = a.getResourceId(R.styleable.ActionBar_popupTheme, 0);
        if (popupTheme != 0) {
            mToolbar.setPopupTheme(popupTheme);
        }

        a.recycle();
    } else {
        mDisplayOpts = detectDisplayOptions();
    }

    mDrawableManager = AppCompatDrawableManager.get();

    setDefaultNavigationContentDescription(defaultNavigationContentDescription);
    mHomeDescription = mToolbar.getNavigationContentDescription();

    setDefaultNavigationIcon(mDrawableManager.getDrawable(getContext(), defaultNavigationIcon));

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        final ActionMenuItem mNavItem = new ActionMenuItem(mToolbar.getContext(), 0, android.R.id.home, 0, 0,
                mTitle);

        @Override
        public void onClick(View v) {
            if (mWindowCallback != null && mMenuPrepared) {
                mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mNavItem);
            }
        }
    });
}

From source file:com.knurld.dropboxdemo.KnurldActivity.java

public void updateKnurldEnrollment(View view) {
    Activity parent = (Activity) context;
    final View layoutView = LayoutInflater.from(parent).inflate(R.layout.knurld_setup, null);
    final PopupWindow loadingWindow = showLoadingPopup(layoutView);

    new Thread(new Runnable() {
        @Override/* w w  w.ja va  2 s. c  om*/
        public void run() {
            final boolean isEnrolled = knurldService.enroll();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (isEnrolled) {
                        loadingWindow.dismiss();
                        showMessage(layoutView, "Enrollment completed!");
                    } else {
                        loadingWindow.dismiss();
                        showMessage(layoutView, "Enrollment failed, please record enrollment again");
                    }
                }
            });
        }
    }).start();
}

From source file:com.sunho.nating.fragments.DetailUnivFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    FrameLayout root = (FrameLayout) view;
    context = view.getContext();//from   w  ww.ja  v a  2 s.co m
    assert context != null;
    // This is how the fragment looks at first. Since the transition is one-way, we don't need to make
    // this a Scene.
    View item = LayoutInflater.from(context).inflate(R.layout.item_gridview, root, false);
    assert item != null;
    bind(item);
    // We adjust the position of the initial image with LayoutParams using the values supplied
    // as the fragment arguments.
    Bundle args = getArguments();
    FrameLayout.LayoutParams params = null;
    if (args != null) {
        params = new FrameLayout.LayoutParams(args.getInt(ARG_WIDTH), args.getInt(ARG_HEIGHT));
        params.topMargin = args.getInt(ARG_Y);
        params.leftMargin = args.getInt(ARG_X);
    }
    root.addView(item, params);
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareUIHandler.java

/**
 *  ?-?  Cloudflare.//  ww w . ja va2 s .  c om
 *    
 * @param e ? {@link CloudflareException}
 * @param chan  
 * @param activity ?,    ?  ( ?  ? ),
 *   ?   ? WebView ? Anti DDOS  ? javascript.
 * ???  ?  UI  ({@link Activity#runOnUiThread(Runnable)})
 * @param cfTask ?? 
 * @param callback ? {@link Callback}
 */
static void handleCloudflare(final CloudflareException e, final HttpChanModule chan, final Activity activity,
        final CancellableTask cfTask, final InteractiveException.Callback callback) {
    if (cfTask.isCancelled())
        return;

    if (!e.isRecaptcha()) { // ? anti DDOS 
        if (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) {
            //?  ?   ??  ,   ?  ? ?
            // ?, ?      ChanModule,    
            //  ?  ?  () cloudflare  ? ?
            //  ?  ? ? ?   ? CloudflareChecker
            while (!CloudflareChecker.getInstance().isAvaibleAntiDDOS())
                Thread.yield();
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            return;
        }

        Cookie cfCookie = CloudflareChecker.getInstance().checkAntiDDOS(e, chan.getHttpClient(), cfTask,
                activity);
        if (cfCookie != null) {
            chan.saveCookie(cfCookie);
            if (!cfTask.isCancelled()) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            }
        } else if (!cfTask.isCancelled()) {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callback.onError(activity.getString(R.string.error_cloudflare_antiddos));
                }
            });
        }
    } else { //  ? 
        final Recaptcha recaptcha;
        try {
            recaptcha = CloudflareChecker.getInstance().getRecaptcha(e, chan.getHttpClient(), cfTask);
        } catch (RecaptchaException recaptchaException) {
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onError(activity.getString(R.string.error_cloudflare_get_captcha));
                    }
                });
            return;
        }

        if (!cfTask.isCancelled())
            activity.runOnUiThread(new Runnable() {
                @SuppressLint("InflateParams")
                @Override
                public void run() {
                    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                            ? new ContextThemeWrapper(activity, R.style.Neutron_Medium)
                            : activity;
                    View view = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_cloudflare_captcha,
                            null);
                    ImageView captchaView = (ImageView) view.findViewById(R.id.dialog_captcha_view);
                    final EditText captchaField = (EditText) view.findViewById(R.id.dialog_captcha_field);
                    captchaView.setImageBitmap(recaptcha.bitmap);

                    DialogInterface.OnClickListener process = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    String answer = captchaField.getText().toString();
                                    Cookie cfCookie = CloudflareChecker.getInstance().checkRecaptcha(e,
                                            (ExtendedHttpClient) chan.getHttpClient(), cfTask,
                                            recaptcha.challenge, answer);
                                    if (cfCookie != null) {
                                        chan.saveCookie(cfCookie);
                                        if (!cfTask.isCancelled()) {
                                            activity.runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    callback.onSuccess();
                                                }
                                            });
                                        }
                                    } else {
                                        //   (?,  ,    )
                                        handleCloudflare(e, chan, activity, cfTask, callback);
                                    }
                                }
                            }).start();
                        }
                    };

                    DialogInterface.OnCancelListener onCancel = new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            callback.onError(activity.getString(R.string.error_cloudflare_cancelled));
                        }
                    };

                    if (cfTask.isCancelled())
                        return;

                    final AlertDialog recaptchaDialog = new AlertDialog.Builder(dialogContext).setView(view)
                            .setPositiveButton(R.string.dialog_cloudflare_captcha_check, process)
                            .setOnCancelListener(onCancel).create();
                    recaptchaDialog.getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    recaptchaDialog.setCanceledOnTouchOutside(false);
                    recaptchaDialog.show();

                    captchaView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            recaptchaDialog.dismiss();
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    handleCloudflare(e, chan, activity, cfTask, callback);
                                }
                            }).start();
                        }
                    });
                }
            });
    }
}

From source file:eu.operando.proxy.filters.domain.DomainFiltersActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(MainContext.INSTANCE.getSettings().getThemeStyle().themeAppCompatStyle());
    updateFiltersList();//  ww  w  . j  a  va  2s  .c o  m
    super.onCreate(savedInstanceState);
    setContentView(R.layout.filters_content);
    ButterKnife.inject(this);

    userDomainFiltersAdapter = new UserDomainFiltersAdapter();
    externalDomainFiltersAdapter = new ExternalDomainFiltersAdapter();

    recyclerView = new RecyclerView(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    //recyclerView.setAdapter(userDomainFiltersAdapter);
    //recyclerViewHolder.addView(recyclerView);

    //Setup Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        View spinnerContainer = LayoutInflater.from(this).inflate(R.layout.toolbar_spinner, toolbar, false);
        ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        toolbar.addView(spinnerContainer, lp);

        DomainFiltersSpinnerAdapter spinnerAdapter = new DomainFiltersSpinnerAdapter();

        Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.toolbar_spinner);
        spinner.setAdapter(spinnerAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                viewSelected = position;
                recyclerViewHolder.removeAllViews();
                //recyclerViewHolder.invalidate();
                switch (position) {
                case 0:
                    recyclerView.setAdapter(userDomainFiltersAdapter);
                    break;
                case 1:
                    recyclerView.setAdapter(externalDomainFiltersAdapter);
                    break;
                default:
                    recyclerView.setAdapter(userDomainFiltersAdapter);
                    break;
                }
                recyclerViewHolder.addView(recyclerView);
                inValidateSelections();

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

    }
}

From source file:eu.operando.operandoapp.filters.domain.DomainFiltersActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(MainContext.INSTANCE.getSettings().getThemeStyle().themeAppCompatStyle());
    updateFiltersList();/*  w  w w  . j  a v a  2s  . c  o  m*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.filters_content);
    ButterKnife.inject(this);

    userDomainFiltersAdapter = new UserDomainFiltersAdapter();
    externalDomainFiltersAdapter = new ExternalDomainFiltersAdapter();

    recyclerView = new RecyclerView(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    //recyclerView.setAdapter(userDomainFiltersAdapter);
    //recyclerViewHolder.addView(recyclerView);

    //region Setup Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        View spinnerContainer = LayoutInflater.from(this).inflate(R.layout.toolbar_spinner, toolbar, false);
        ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        toolbar.addView(spinnerContainer, lp);

        DomainFiltersSpinnerAdapter spinnerAdapter = new DomainFiltersSpinnerAdapter();

        Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.toolbar_spinner);
        spinner.setAdapter(spinnerAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                viewSelected = position;
                recyclerViewHolder.removeAllViews();
                //recyclerViewHolder.invalidate();
                switch (position) {
                case 0:
                    recyclerView.setAdapter(userDomainFiltersAdapter);
                    break;
                case 1:
                    recyclerView.setAdapter(externalDomainFiltersAdapter);
                    break;
                default:
                    recyclerView.setAdapter(userDomainFiltersAdapter);
                    break;
                }
                recyclerViewHolder.addView(recyclerView);
                inValidateSelections();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

    }
    //endregion
}

From source file:android.support.v7.widget.BaseRecyclerViewInstrumentationTest.java

protected WrappedRecyclerView inflateWrappedRV() {
    return (WrappedRecyclerView) LayoutInflater.from(getActivity()).inflate(R.layout.wrapped_test_rv,
            getRecyclerViewContainer(), false);
}

From source file:net.e_fas.oss.tabijiman.MapsActivity.java

private View getActionBarView() {

    // ?layout??//  ww  w .j  a v  a2 s .  c  o  m
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.titlebar, null);

    // CustomView??
    ImageButton info = (ImageButton) view.findViewById(R.id.imageButton);
    info.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent info = new Intent(getApplicationContext(), Credit.class);
            startActivity(info);
        }
    });
    return view;
}

From source file:org.flakor.androidtool.net.net.HistoryTask.java

private void showDialog(String text) {
    dialog = new Dialog(context, R.style.dialogStyle);
    View view = LayoutInflater.from(context).inflate(R.layout.progress_dialog, null);
    TextView textView = (TextView) view.findViewById(R.id.progress_text);
    textView.setText(text);//from ww w.  j  a  v  a  2s.com

    dialog.setContentView(view);
    dialog.show();
}