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:com.naman14.algovisualizer.AlgoDescriptionFragment.java

private void addDescData(String algorithmKey) {
    if (descJson == null || descObject == null || getActivity() == null) {
        return;/*w  w w . jav a  2  s . c  o m*/
    }
    rootView.removeAllViews();
    try {
        JSONObject dataObject = descObject.getJSONObject(algorithmKey);

        Iterator<?> keys = dataObject.keys();

        while (keys.hasNext()) {

            View descView = LayoutInflater.from(getActivity()).inflate(R.layout.item_code_desc, rootView,
                    false);
            TextView title = (TextView) descView.findViewById(R.id.title);
            TextView desc = (TextView) descView.findViewById(R.id.desc);
            desc.setMovementMethod(LinkMovementMethod.getInstance());

            String key = (String) keys.next();
            title.setText(key);

            if (dataObject.get(key) instanceof JSONObject) {
                JSONObject jsonObject = dataObject.getJSONObject(key);
                String descString = "";

                Iterator<?> complexityKeys = jsonObject.keys();

                while (complexityKeys.hasNext()) {
                    String complexityKey = (String) complexityKeys.next();
                    descString += " - ";
                    descString += complexityKey;
                    descString += " : ";
                    descString += jsonObject.getString(complexityKey);
                    descString += "<br>";
                }
                desc.setText(Html.fromHtml(descString));

            } else if (dataObject.get(key) instanceof JSONArray) {
                JSONArray array = dataObject.getJSONArray(key);
                String descString = "";

                for (int i = 0; i < array.length(); i++) {
                    descString += " - ";
                    descString += array.getString(i);
                    descString += "<br>";
                }
                desc.setText(Html.fromHtml(descString));

            } else if (dataObject.get(key) instanceof String) {
                desc.setText(Html.fromHtml(dataObject.getString(key)));
            }

            rootView.addView(descView);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:fr.simon.marquis.preferencesmanager.ui.RestoreDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getActivity() == null) {
        return null;
    }/*ww w .  j av a2s  .com*/
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_restore, null);
    assert view != null;
    ListView listView = (ListView) view.findViewById(R.id.listView);
    listView.setAdapter(new RestoreAdapter(getActivity(), this, backups, listener, mFullPath));
    listView.setOnItemClickListener(this);
    return view;
}

From source file:audio.lisn.adapter.StoreBookViewAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_store_book, parent, false);
    view.setMinimumWidth(parent.getMeasuredWidth());

    view.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w .j  av a  2 s . c  om*/
        public void onClick(final View v) {
            releaseMediaPlayer();

            if (listener != null) {

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        listener.onStoreBookSelect(v, (AudioBook) v.getTag(),
                                AudioBook.SelectedAction.ACTION_DETAIL);
                    }
                }, 200);
            }
        }
    });

    return new ViewHolder(view);
}

From source file:android.support.design.internal.NavigationMenuPresenter.java

@Override
public void initForMenu(Context context, MenuBuilder menu) {
    mLayoutInflater = LayoutInflater.from(context);
    mMenu = menu;/*w  ww.  ja  v  a2s . c  o m*/
    Resources res = context.getResources();
    mPaddingSeparator = res.getDimensionPixelOffset(R.dimen.design_navigation_separator_vertical_padding);
}

From source file:edu.illinois.whereru.MainPageActivity.java

private void showRegistrationDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater factory = LayoutInflater.from(this);
    // inflate dialog view
    View view = factory.inflate(R.layout.dialog_user_registration, null);
    // Setting dialog message and title
    builder.setMessage(R.string.register_dialog_message).setTitle(R.string.register_dialog_title);
    // set custom view
    builder.setView(view);//from   w  ww  . j  a  va 2 s  .  c  om

    // need to get the edittext from dialog layout
    // calling findViewById automatically searches the layout attached to this activity
    editText = (EditText) view.findViewById(R.id.dialog_username_text);
    preferenceEditor = userInfo.edit();

    builder.setPositiveButton(R.string.register_button_text, new OnClickListener() {

        public void onClick(DialogInterface dialogs, int id) {
            String userName = editText.getText().toString();
            // TODO need to figure out a way to define a user with unique id
            String deviceID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

            // Connect to DB and store a new user
            DBConnector dbConnector = new DBConnector();
            dbConnector.execute(DBConnector.ADD_USER, userName, deviceID);
            JSONObject result = null;

            // Wait for the feedback from the DB
            try {
                result = dbConnector.get();
            } catch (InterruptedException e) {
                // shouldn't be interrupted
                Log.e(DEBUG_TAG, "Interrupted, restarting");
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

            boolean successful = false;
            String userId = null;

            // Parse the response returned from DB
            if (result != null) {
                successful = JSONObjectParser.getSuccess(result);
                userId = JSONObjectParser.getUserId(result) + "";
            }

            if (successful) { // Store user info locally
                // user id returned from DB
                preferenceEditor.putString(PREF_USER_ID, userId);
                preferenceEditor.putString(PREF_USER_NAME, userName);
                preferenceEditor.putString(PREF_DEVICE_ID, deviceID);
                preferenceEditor.putBoolean(PREF_APPLICATION_STATE, false);
                preferenceEditor.commit();
                // start main tab activity
                startActivity(intent);
                finish();
            } else {
                // notify users of failure, let users press back button to exit.
                Toast.makeText(getApplicationContext(), "Failed to register, please try again later",
                        Toast.LENGTH_SHORT).show();
            }
        }

    });

    builder.setNegativeButton(R.string.register_dialog_cancel, new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // exit out of this activity
            finish();
        }

    });

    dialog = builder.create();
    dialog.show();
}

From source file:com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.java

@Override
public void initForMenu(Context context, MenuBuilder menu) {
    mContext = context;
    mInflater = LayoutInflater.from(mContext);
    mMenu = menu;
}

From source file:com.app.jdy.adapter.DetailAdapter.java

public DetailAdapter(Context context, int resource, String dataJson, Bitmap logo, Bitmap prodImage) {
    this.context = context;
    this.listContainer = LayoutInflater.from(context); // 
    this.itemViewResource = resource;
    this.dataJson = dataJson;
    this.logo = logo;
    this.prodImage = prodImage;
    initHashMap();//from  www  .  j  av  a2 s .c o m

}

From source file:br.com.moviecreator.views.home.HomeFragment.java

@Nullable
@Override//from ww  w  .j  a  v a2 s. c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.home_app_bar, container, false);

    adapter = new MoviesAdapter(new ArrayList<Movie>(), LayoutInflater.from(getActivity()),
            new ItemClickListener<Movie>() {
                @Override
                public void onItemClick(Movie movie) {
                    Bundle extra = new Bundle();
                    extra.putSerializable(DetailsActivity.DETAILS_EXTRA, movie);

                    Intent intent = new Intent(getActivity(), DetailsActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intent.putExtras(extra);

                    getActivity().startActivity(intent);
                }
            });

    gridLayoutManager = new GridLayoutManager(getActivity(), 2);
    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);

    boryLayout = (LinearLayout) rootView.findViewById(R.id.home_bory_search);
    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary,
            R.color.colorPrimaryDark);
    swipeRefreshLayout.setEnabled(false);

    RecyclerView recyclerViewMovies = (RecyclerView) rootView.findViewById(R.id.movies_result_list);
    recyclerViewMovies.setHasFixedSize(true);
    recyclerViewMovies.setLayoutManager(gridLayoutManager);
    recyclerViewMovies.setAdapter(adapter);
    recyclerViewMovies.addItemDecoration(new SpacesItemDecoration(10));

    boryLayout.setVisibility(View.VISIBLE);
    swipeRefreshLayout.setVisibility(View.GONE);

    return rootView;
}

From source file:com.google.zxing.client.android.SearchBookContentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();//from   w w w.  j  av  a2s  .co m
    if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION)
            && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) {
        finish();
        return;
    }

    mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN);

    setContentView(R.layout.search_book_contents);
    mQueryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && initialQuery.length() > 0) {
        // Populate the search box but don't trigger the search
        mQueryTextView.setText(initialQuery);
    }
    mQueryTextView.setOnKeyListener(mKeyListener);

    mQueryButton = (Button) findViewById(R.id.query_button);
    mQueryButton.setOnClickListener(mButtonListener);

    mResultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false);
    mResultListView.addHeaderView(mHeaderView);

    mUserAgent = getString(R.string.zxing_user_agent);
}

From source file:augsburg.se.alltagsguide.navigation.NavigationAdapter.java

@Override
public NavigationViewHolder onCreateViewHolder(ViewGroup parent) {
    return new NavigationViewHolder(
            LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_item, parent, false));
}