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.moonpi.tapunlock.MainActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    // Scan NFC Tag dialog, inflate image
    LayoutInflater factory = LayoutInflater.from(MainActivity.this);
    final View view = factory.inflate(R.layout.scan_tag_image, null);

    // Ask for tagTitle (tagName) in dialog
    final EditText tagTitle = new EditText(this);
    tagTitle.setHint(getResources().getString(R.string.set_tag_name_dialog_hint));
    tagTitle.setSingleLine(true);/*  ww w. j a  v a  2  s.c om*/
    tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

    // Set tagTitle maxLength
    int maxLength = 50;
    InputFilter[] array = new InputFilter[1];
    array[0] = new InputFilter.LengthFilter(maxLength);
    tagTitle.setFilters(array);

    final LinearLayout l = new LinearLayout(this);

    l.setOrientation(LinearLayout.VERTICAL);
    l.addView(tagTitle);

    // Dialog that shows scan tag image
    if (id == DIALOG_READ) {
        return new AlertDialog.Builder(this).setTitle(R.string.scan_tag_dialog_title).setView(view)
                .setCancelable(false)
                .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogCancelled = true;
                        killForegroundDispatch();
                        dialog.cancel();
                    }
                }).create();
    }

    // Dialog that asks for tagName and stores it after 'Ok' pressed
    else if (id == DIALOG_SET_TAGNAME) {
        tagTitle.requestFocus();
        return new AlertDialog.Builder(this).setTitle(R.string.set_tag_name_dialog_title).setView(l)
                .setCancelable(false)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONObject newTag = new JSONObject();

                        try {
                            newTag.put("tagName", tagTitle.getText());
                            newTag.put("tagID", tagID);

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

                        tags.put(newTag);

                        writeToJSON();

                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_added,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                        tagID = "";
                        tagTitle.setText("");
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tagID = "";
                        tagTitle.setText("");
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                        dialog.cancel();
                    }
                }).create();
    }

    return null;
}

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

public MenuItem setActionView(int resId) {
    final Context context = mMenu.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    setActionView(inflater.inflate(resId, new LinearLayout(context), false));
    return this;
}

From source file:edu.missouri.niaaa.pain.activity.AdminManageActivity.java

private Dialog assignConfirmDialog(final Context context, String str, boolean startNewWeek) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.assign_new_week);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (startNewWeek) {
        builder.setView(textEntryView);//from  www  . jav  a2 s .c  o m
    }
    builder.setCancelable(false);
    builder.setTitle(R.string.assign_confirm_title);
    builder.setMessage(str);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            editor.putString(Util.SP_LOGIN_KEY_USERID, asID.getText().toString());
            Log.d("here!!!", "id is " + asID.getText().toString());
            //format check

            editor.putString(Util.SP_LOGIN_KEY_USERPWD, "");
            editor.putString(Util.SP_LOGIN_KEY_STUDY_STARTTIME, "" + Calendar.getInstance().getTimeInMillis());
            editor.commit();

            //start new study week, if checked
            if (rm_check.isChecked()) {

                String UID = null;
                try {
                    UID = Util.encryption(context, asID.getText().toString());
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                ChangeStudyWeek changeStudyWeek = new ChangeStudyWeek();
                changeStudyWeek.execute(UID);
            }

            setHints();
            //continue with set user pin (8)
            setResult(Activity.RESULT_OK);
            finish();
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            setHints();
        }
    });
    return builder.create();
}

From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java

private Dialog assignConfirmDialog(Context context, String str, boolean startNewWeek) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.assign_new_week);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (startNewWeek) {
        builder.setView(textEntryView);//from   w w w.j  a  va2s .com
    }
    builder.setCancelable(false);
    builder.setTitle(R.string.assign_confirm_title);
    builder.setMessage(str);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            editor.putString(Utilities.SP_KEY_LOGIN_USERID, asID.getText().toString());
            Log.d("here!!!", "id is " + asID.getText().toString());
            //format check

            editor.putString(Utilities.SP_KEY_LOGIN_USERPWD, "");
            editor.putString(Utilities.SP_KEY_LOGIN_STUDY_STARTTIME,
                    "" + Calendar.getInstance().getTimeInMillis());
            editor.commit();

            //start new study week, if checked
            if (rm_check.isChecked()) {

                String UID = null;
                try {
                    UID = Utilities.encryption(asID.getText().toString());
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                ChangeStudyWeek changeStudyWeek = new ChangeStudyWeek();
                changeStudyWeek.execute(UID);
            }

            setHints();
            //continue with set user pin (8)
            setResult(Activity.RESULT_OK);
            finish();
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            setHints();
        }
    });
    return builder.create();
}

From source file:abanoubm.dayra.main.Main.java

private void sign() {
    String inpath;//from ww  w .  j  a  v  a2  s  . c o  m
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        inpath = getApplicationContext().getApplicationInfo().dataDir + "/databases/";
    } else {
        inpath = "/data/data/" + getApplicationContext().getPackageName() + "/databases/";
    }
    File folder = new File(inpath);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        Toast.makeText(getApplicationContext(), R.string.msg_no_dayra, Toast.LENGTH_SHORT).show();
    } else {
        ArrayList<String> names = new ArrayList<>(listOfFiles.length);
        for (File file : listOfFiles) {
            if (!file.getName().contains("journal"))
                names.add(file.getName());
        }

        LayoutInflater li = LayoutInflater.from(getApplicationContext());
        View signView = li.inflate(R.layout.dialogue_signin, null, false);
        final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
        ad.setView(signView, 0, 0, 0, 0);
        ad.show();

        ListView nameslv = (ListView) signView.findViewById(R.id.databases_lv);
        nameslv.setAdapter(new ArrayAdapter<>(getApplicationContext(), R.layout.item_string, R.id.item, names));

        nameslv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String str = (String) parent.getItemAtPosition(position);
                new SignTask().execute(str);
                ad.dismiss();
            }
        });

    }

}

From source file:android.support.v7.internal.view.menu.MenuItemImpl.java

@Override
public SupportMenuItem setActionView(int resId) {
    final Context context = mMenu.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    setActionView(inflater.inflate(resId, new LinearLayout(context), false));
    return this;
}

From source file:com.android.contacts.list.ContactEntryListAdapter.java

@Override
protected View newHeaderView(Context context, int partition, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    return inflater.inflate(R.layout.directory_header, parent, false);
}

From source file:com.example.suspectedBug.myapplication.IapSampleActivity.java

/**
 * Create a button to show the user which they can click on to purchase the item.
 *
 * @param item The item that can be purchased by clicking on the button.
 *
 * @return The Button to show in the UI.
 *//*from   www .  ja  va  2  s  . c  o m*/

private View makeButton(Product item) {
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.product_item, null, false);
    String buttonText = item.getName() + " - " + item.getFormattedPrice();
    Button button = (Button) view.findViewById(R.id.purchase_product_button);
    button.setOnClickListener(new RequestPurchaseClickListener());
    button.setText(buttonText);
    button.setTag(item);
    return view;
}

From source file:org.span.manager.MainActivity.java

private void openAboutDialog() {
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.aboutview, null);
    // TextView versionName = (TextView)view.findViewById(R.id.versionName);
    // versionName.setText(this.application.getVersionName());        
    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.main_activity_about)).setView(view)
            .setNegativeButton(getString(R.string.main_activity_close), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Log.d(TAG, "Close pressed");
                }/* w w  w.  j a v  a 2 s  . c om*/
            }).show();
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void areYouSure(Context context, int explanation, final DoubtListener listener) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View view = inflater.inflate(R.layout.sure, null, false);
    TextView tvExplanation = (TextView) view.findViewById(R.id.tvExplanation);
    tvExplanation.setText(explanation);/* w w w.  j ava  2  s  .  c  o  m*/
    new AlertDialog.Builder(context).setView(view).setCancelable(true)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    listener.onSure();
                }
            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            }).create().show();
}