Example usage for android.app Activity getLayoutInflater

List of usage examples for android.app Activity getLayoutInflater

Introduction

In this page you can find the example usage for android.app Activity getLayoutInflater.

Prototype

@NonNull
public LayoutInflater getLayoutInflater() 

Source Link

Document

Convenience for calling android.view.Window#getLayoutInflater .

Usage

From source file:com.f16gaming.pathofexilestatistics.PoeEntry.java

public AlertDialog getInfoDialog(Activity activity, Resources res) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.info, null);
    String nameFormat = res.getString(R.string.info_name);
    String accountFormat = res.getString(R.string.info_account);
    String rankFormat = res.getString(R.string.info_rank);
    String levelFormat = res.getString(R.string.info_level);
    String classFormat = res.getString(R.string.info_class);
    String experienceFormat = res.getString(R.string.info_experience);
    ((TextView) view.findViewById(R.id.info_name)).setText(String.format(nameFormat, name));
    ((TextView) view.findViewById(R.id.info_account)).setText(String.format(accountFormat, account));
    ((TextView) view.findViewById(R.id.info_rank)).setText(String.format(rankFormat, rank));
    ((TextView) view.findViewById(R.id.info_level)).setText(String.format(levelFormat, level));
    ((TextView) view.findViewById(R.id.info_class)).setText(String.format(classFormat, className));
    ((TextView) view.findViewById(R.id.info_experience)).setText(String.format(experienceFormat, experience));

    TextView status = (TextView) view.findViewById(R.id.info_status);
    status.setText(online ? R.string.online : R.string.offline);
    status.setTextColor(online ? res.getColor(R.color.online) : res.getColor(R.color.offline));

    builder.setTitle(R.string.info_title).setView(view).setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override// w  w w  .  jav a 2 s .  co m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    return builder.create();
}

From source file:com.snt.bt.recon.adapters.LeDeviceListAdapter.java

public LeDeviceListAdapter(final Activity activity, final EasyObjectCursor<BluetoothLeDevice> cursor) {
    super(activity, com.snt.bt.recon.R.layout.list_item_device, cursor, new String[0], new int[0], 0);
    mInflator = activity.getLayoutInflater();
    mActivity = activity;/*w  w w .ja va 2s. com*/
}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param c     the Context/*from w ww.ja  v a  2s  . com*/
 * @param trace the current trace of points
 * @return the "save & share" dialog
 */
public static Dialog getSaveNShare(final Activity c, final Stack<LatLng> trace) {
    final Dialog d = new Dialog(c);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.dialog_save);
    d.findViewById(R.id.save).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final File destination;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                destination = API8Wrapper.getExternalFilesDir(c);
            } else {
                destination = c.getDir("traces", Context.MODE_PRIVATE);
            }

            d.dismiss();
            AlertDialog.Builder b = new AlertDialog.Builder(c);
            b.setTitle(R.string.save);
            final View layout = c.getLayoutInflater().inflate(R.layout.dialog_enter_filename, null);
            ((TextView) layout.findViewById(R.id.location))
                    .setText(c.getString(R.string.file_path, destination.getAbsolutePath() + "/"));
            b.setView(layout);
            b.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        String fname = ((EditText) layout.findViewById(R.id.filename)).getText().toString();
                        if (fname == null || fname.length() < 1) {
                            fname = "MapsMeasure_" + System.currentTimeMillis();
                        }
                        final File f = new File(destination, fname + ".csv");
                        Util.saveToFile(f, trace);
                        d.dismiss();
                        Toast.makeText(c, c.getString(R.string.file_saved, f.getAbsolutePath()),
                                Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        Toast.makeText(c,
                                c.getString(R.string.error,
                                        e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
            b.create().show();
        }
    });
    d.findViewById(R.id.load).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {

            File[] files = c.getDir("traces", Context.MODE_PRIVATE).listFiles();

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File ext = API8Wrapper.getExternalFilesDir(c);
                // even though we checked the external storage state, ext is still sometims null, accoring to Play Store crash reports
                if (ext != null) {
                    File[] filesExtern = ext.listFiles();
                    File[] allFiles = new File[files.length + filesExtern.length];
                    System.arraycopy(files, 0, allFiles, 0, files.length);
                    System.arraycopy(filesExtern, 0, allFiles, files.length, filesExtern.length);
                    files = allFiles;
                }
            }

            if (files.length == 0) {
                Toast.makeText(c,
                        c.getString(R.string.no_files_found,
                                c.getDir("traces", Context.MODE_PRIVATE).getAbsolutePath()),
                        Toast.LENGTH_SHORT).show();
            } else if (files.length == 1) {
                try {
                    Util.loadFromFile(Uri.fromFile(files[0]), (Map) c);
                    d.dismiss();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(c,
                            c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                d.dismiss();
                AlertDialog.Builder b = new AlertDialog.Builder(c);
                b.setTitle(R.string.select_file);
                final DeleteAdapter da = new DeleteAdapter(files, (Map) c);
                b.setAdapter(da, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Util.loadFromFile(Uri.fromFile(da.getFile(which)), (Map) c);
                            dialog.dismiss();
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(c,
                                    c.getString(R.string.error,
                                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });
                b.create().show();
            }
        }
    });
    d.findViewById(R.id.share).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            try {
                final File f = new File(c.getCacheDir(), "MapsMeasure.csv");
                Util.saveToFile(f, trace);
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                shareIntent.putExtra(Intent.EXTRA_STREAM,
                        FileProvider.getUriForFile(c, "de.j4velin.mapsmeasure.fileprovider", f));
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                shareIntent.setType("text/comma-separated-values");
                d.dismiss();
                c.startActivity(Intent.createChooser(shareIntent, null));
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(c,
                        c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                        Toast.LENGTH_LONG).show();
            }
        }
    });
    return d;
}

From source file:com.docd.purefm.ui.dialogs.PartitionInfoDialog.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Activity activity = this.getActivity();
    if (activity == null || activity.isFinishing()) {
        return null;
    }/*from  w w w .jav a2  s . co  m*/
    //noinspection InflateParams
    mView = activity.getLayoutInflater().inflate(R.layout.dialog_partition_info, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_info));
    builder.setTitle(R.string.menu_partition);
    builder.setView(mView);
    builder.setNeutralButton(R.string.close, null);
    return builder.create();

}

From source file:org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment.java

/**
 * Creates dialog/*from  w  w w . ja  v  a2  s. c  o m*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    Uri dataUri = getArguments().getParcelable(ARG_KEY_URI);

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(getActivity());
    alert.setTitle(R.string.share_qr_code_dialog_title);

    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.share_qr_code_dialog, null);
    alert.setView(view);

    mImage = (ImageView) view.findViewById(R.id.share_qr_code_dialog_image);
    mText = (TextView) view.findViewById(R.id.share_qr_code_dialog_text);

    ProviderHelper providerHelper = new ProviderHelper(getActivity());
    String content;
    try {
        alert.setPositiveButton(R.string.btn_okay, null);

        byte[] blob = (byte[]) providerHelper.getGenericData(KeyRings.buildUnifiedKeyRingUri(dataUri),
                KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
        if (blob == null) {
            Log.e(Constants.TAG, "key not found!");
            AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
            return null;
        }

        String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob);
        mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint);
        content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
        setQrCode(content);
    } catch (ProviderHelper.NotFoundException e) {
        Log.e(Constants.TAG, "key not found!", e);
        AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
        return null;
    }

    return alert.show();
}

From source file:com.murrayc.galaxyzoo.app.ZooFragment.java

private void showAbout() {
    final Activity activity = getActivity();
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    // Get the layout inflater
    final LayoutInflater inflater = activity.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View view = inflater.inflate(R.layout.about, null);
    builder.setView(view);//  w  w  w .j  a  va  2  s  .c  o m

    final TextView textView = (TextView) view.findViewById(R.id.textViewAbout);
    if (textView == null) {
        Log.error("showAbout: textView was null.");
        return;
    }

    //This voodoo makes the textviews' HTML links clickable:
    //See http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable/20647011#20647011
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    final String versionText = String.format(getString(R.string.about_version_text_format),
            BuildConfig.VERSION_NAME);

    //The about dialog's text is split into multiple strings to make translation easier,
    //so we need to concatenate them here.
    //Note that we use getText(), not getString(),
    //so we don't lose the <a href=""> links.
    //Likewise, we use SpannableStringBuilder instead of StringBuilder,
    //because we lose the links when using StringBuilder.
    final SpannableStringBuilder strBuilder = new SpannableStringBuilder();
    final String PARAGRAPH_BREAK = "\n\n";
    strBuilder.append(versionText);
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text1));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text2));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text3));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text3b));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text4));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text5));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text6));

    textView.setText(strBuilder);

    /* We used to put the version text into a separate TextView,
       but when the about text in textView is too long,
       the scroll never reaches this far.
       It does work when we add it to first regular textView.
     */
    /*
    final TextView textViewVersion = (TextView) view.findViewById(R.id.textViewVersion);
    if (textViewVersion != null) {
    textViewVersion.setText(versionText);
    }
    */

    final AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.app_name);
    dialog.setIcon(R.mipmap.ic_launcher);

    dialog.show();
}

From source file:com.swisscom.safeconnect.activity.PipeActivity.java

protected void initActionBar(Activity activity, int stringId, View.OnClickListener listener) {
    ActionBar ab = activity.getActionBar();

    //Tutorial with NoTitle Theme returns null here
    if (ab == null) {
        return;/*from www. ja v  a  2 s .c  o m*/
    }
    ab.setDisplayShowCustomEnabled(true);
    ab.setDisplayShowTitleEnabled(false);
    ab.setDisplayShowHomeEnabled(false);

    actionBarView = activity.getLayoutInflater().inflate(R.layout.actionbar, null);

    tvTitle = (TextView) actionBarView.findViewById(R.id.tv_title);
    imgBackBtn = (ImageView) actionBarView.findViewById(R.id.img_back_btn);
    if (tvTitle != null && stringId != 0) {
        tvTitle.setText(stringId);
    }

    setOnBackPressedListener(listener);

    ab.setCustomView(actionBarView);
}

From source file:com.github.michalbednarski.intentslab.AppComponentsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mInflater = activity.getLayoutInflater();
}

From source file:de.spiritcroc.ownlog.ui.fragment.TagItemEditFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final View view = activity.getLayoutInflater().inflate(R.layout.tag_edit_item, null);

    mEditTagName = (EditText) view.findViewById(R.id.name_edit);
    mEditTagDescription = (EditText) view.findViewById(R.id.description_edit);

    boolean restoredValues = restoreValues(savedInstanceState);

    builder.setTitle(mAddItem ? R.string.title_tag_item_add : R.string.title_tag_item_edit).setView(view)
            .setPositiveButton(R.string.dialog_ok, null)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override/*from w  w  w  .j  av  a 2 s  .c  o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    // Only dismiss (and hide keyboard)
                    hideKeyboard();
                }
            });
    if (!mAddItem) {
        builder.setNeutralButton(R.string.dialog_delete, null);
    }
    final AlertDialog alertDialog = builder.create();

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    saveChanges();
                }
            });
            if (!mAddItem) {
                alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                promptDelete();
                            }
                        });
            }
        }
    });

    if (!restoredValues) {
        // Edit text requires user interaction, so show keyboard
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

        if (mAddItem) {
            initValues();
        } else {
            loadContent();
        }
    }

    return alertDialog;
}

From source file:com.normsstuff.maps4norm.Dialogs.java

/**
 * @param c     the Context//from   ww  w.ja  va 2  s.  c o m
 * @param trace the current trace of points
 * @return the "save & share" dialog
 */
public static Dialog getSaveNShare(final Activity c, final Stack<LatLng> trace) {
    final Dialog d = new Dialog(c);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.dialog_save);
    d.findViewById(R.id.saveMarks).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View vX) {
            final File destination;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                destination = API8Wrapper.getExternalFilesDir(c);
            } else {
                destination = c.getDir("traces", Context.MODE_PRIVATE);
            }

            d.dismiss();
            AlertDialog.Builder b = new AlertDialog.Builder(c);
            b.setTitle(R.string.save);
            final View layout = c.getLayoutInflater().inflate(R.layout.dialog_enter_filename, null);
            ((TextView) layout.findViewById(R.id.location))
                    .setText(c.getString(R.string.file_path, destination.getAbsolutePath() + "/"));
            b.setView(layout);
            b.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        String fname = ((EditText) layout.findViewById(R.id.filename)).getText().toString();
                        if (fname == null || fname.length() < 1) {
                            fname = "MapsMeasure_" + System.currentTimeMillis();
                        }
                        final File f = new File(destination, fname + ".csv");
                        Util.saveToFile(f, trace);
                        d.dismiss();
                        Toast.makeText(c, c.getString(R.string.file_saved, f.getAbsolutePath()),
                                Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        Toast.makeText(c,
                                c.getString(R.string.error,
                                        e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
            b.create().show();
        }
    });
    d.findViewById(R.id.loadMarks).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {

            File[] files = c.getDir("traces", Context.MODE_PRIVATE).listFiles();

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File ext = API8Wrapper.getExternalFilesDir(c);
                // even though we checked the external storage state, ext is still sometimes null, accoring to Play Store crash reports
                if (ext != null) {
                    File[] filesExtern = ext.listFiles();
                    File[] allFiles = new File[files.length + filesExtern.length];
                    System.arraycopy(files, 0, allFiles, 0, files.length);
                    System.arraycopy(filesExtern, 0, allFiles, files.length, filesExtern.length);
                    files = allFiles;
                }
            }

            if (files.length == 0) {
                Toast.makeText(c,
                        c.getString(R.string.no_files_found,
                                c.getDir("traces", Context.MODE_PRIVATE).getAbsolutePath()),
                        Toast.LENGTH_SHORT).show();
            } else if (files.length == 1) {
                try {
                    Util.loadFromFile(Uri.fromFile(files[0]), (MyMapActivity) c);
                    d.dismiss();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(c,
                            c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                d.dismiss();
                AlertDialog.Builder b = new AlertDialog.Builder(c);
                b.setTitle(R.string.select_file);
                final DeleteAdapter da = new DeleteAdapter(files, (MyMapActivity) c);
                b.setAdapter(da, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Util.loadFromFile(Uri.fromFile(da.getFile(which)), (MyMapActivity) c);
                            dialog.dismiss();
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(c,
                                    c.getString(R.string.error,
                                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });
                b.create().show();
            }
        }
    });
    /*        
            d.findViewById(R.id.share).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(final View v) {
        try {
            final File f = new File(c.getCacheDir(), "MapsMeasure.csv");
            Util.saveToFile(f, trace);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, FileProvider
                    .getUriForFile(c, "de.j4velin.mapsmeasure.fileprovider", f));
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            shareIntent.setType("text/comma-separated-values");
            d.dismiss();
            c.startActivity(Intent.createChooser(shareIntent, null));
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(c, c.getString(R.string.error,
                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
        }
    }
            });
    */
    return d;
}