Example usage for android.view LayoutInflater inflate

List of usage examples for android.view LayoutInflater inflate

Introduction

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

Prototype

public View inflate(XmlPullParser parser, @Nullable ViewGroup root) 

Source Link

Document

Inflate a new view hierarchy from the specified xml node.

Usage

From source file:com.andrewshu.android.reddit.common.Common.java

public static void showErrorToast(String error, int duration, Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Toast t = new Toast(context);
    t.setDuration(duration);/*from   www. j a  v  a2  s .c o  m*/
    View v = inflater.inflate(R.layout.error_toast, null);
    TextView errorMessage = (TextView) v.findViewById(R.id.errorMessage);
    errorMessage.setText(error);
    t.setView(v);
    t.show();
}

From source file:im.vector.util.BugReporter.java

/**
 * Send a bug report either with email or with Vector.
 *//*from   www .j  a  v  a 2  s . c  om*/
public static void sendBugReport() {
    final Activity currentActivity = VectorApp.getCurrentActivity();

    // no current activity so cannot display an alert
    if (null == currentActivity) {
        sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null);
        return;
    }

    final Context appContext = currentActivity.getApplicationContext();
    LayoutInflater inflater = currentActivity.getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null);

    final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity);
    dialog.setTitle(R.string.send_bug_report);
    dialog.setView(dialogLayout);

    final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text);
    final CheckBox includeLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_logs);
    final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_crash_logs);

    final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view);
    final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view);

    dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    //
    final AlertDialog bugReportDialog = dialog.show();
    final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE);

    if (null != cancelButton) {
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // check if there is no upload in progress
                if (includeLogsButton.isEnabled()) {
                    bugReportDialog.dismiss();
                } else {
                    mIsCancelled = true;
                    cancelButton.setEnabled(false);
                }
            }
        });
    }

    if (null != sendButton) {
        sendButton.setEnabled(false);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable the active area while uploading the bug report
                bugReportText.setEnabled(false);
                sendButton.setEnabled(false);
                includeLogsButton.setEnabled(false);
                includeCrashLogsButton.setEnabled(false);

                progressTextView.setVisibility(View.VISIBLE);
                progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + ""));

                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(0);

                sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(),
                        includeCrashLogsButton.isChecked(), bugReportText.getText().toString(),
                        new IMXBugReportListener() {
                            @Override
                            public void onUploadFailed(String reason) {
                                try {
                                    if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance()
                                                        .getString(R.string.send_bug_report_failed, reason),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast "
                                            + e.getMessage());
                                }

                                try {
                                    // restore the dialog if the upload failed
                                    bugReportText.setEnabled(true);
                                    sendButton.setEnabled(true);
                                    includeLogsButton.setEnabled(true);
                                    includeCrashLogsButton.setEnabled(true);
                                    cancelButton.setEnabled(true);

                                    progressTextView.setVisibility(View.GONE);
                                    progressBar.setVisibility(View.GONE);
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button "
                                            + e.getMessage());

                                    try {
                                        bugReportDialog.dismiss();
                                    } catch (Exception e2) {
                                        Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog "
                                                + e2.getMessage());
                                    }
                                }

                                mIsCancelled = false;
                            }

                            @Override
                            public void onUploadCancelled() {
                                onUploadFailed(null);
                            }

                            @Override
                            public void onProgress(int progress) {
                                if (progress > 100) {
                                    Log.e(LOG_TAG, "## onProgress() : progress > 100");
                                    progress = 100;
                                } else if (progress < 0) {
                                    Log.e(LOG_TAG, "## onProgress() : progress < 0");
                                    progress = 0;
                                }

                                progressBar.setProgress(progress);
                                progressTextView.setText(
                                        appContext.getString(R.string.send_bug_report_progress, progress + ""));
                            }

                            @Override
                            public void onUploadSucceed() {
                                try {
                                    if (null != VectorApp.getInstance()) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance().getString(
                                                        R.string.send_bug_report_sent),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast "
                                            + e.getMessage());
                                }

                                try {
                                    bugReportDialog.dismiss();
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog "
                                            + e.getMessage());
                                }
                            }
                        });
            }
        });
    }

    bugReportText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (null != sendButton) {
                sendButton.setEnabled(bugReportText.getText().toString().length() > 10);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
}

From source file:MainActivity.java

public void showToast(View view) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast_custom, null);
    ((TextView) layout.findViewById(android.R.id.message)).setText("Custom Toast");
    Toast toast = new Toast(this);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);//  w  ww.j  a  v a  2  s .com
    toast.show();
}

From source file:ca.liquidlabs.android.speedtestvisualizer.fragments.SpeedTestInfoWindowAdapter.java

public SpeedTestInfoWindowAdapter(final LayoutInflater inflater) {
    mContentsView = inflater.inflate(R.layout.speedtest_record_info, null);
}

From source file:app.hacked.WorkShopsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.workshop_fragment, null);
    workshopPayload = (TextView) view.findViewById(R.id.workshopPayload);
    progressBar = view.findViewById(R.id.progressBar);

    return view;//from w  w  w .ja va 2  s . co  m
}

From source file:org.projecthdata.ehr.viewer.fragments.WeightFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.weight, null);
}

From source file:com.chintans.venturebox.cards.SystemCard.java

public SystemCard(Context context, AttributeSet attrs, RomUpdater romUpdater, Bundle savedInstanceState) {
    super(context, attrs, savedInstanceState);
    setLayoutId(R.layout.card_system);//ww w.  j av  a2 s .c o m
    setTopTitle(getResources().getString(R.string.system_title), getResources().getColor(R.color.primary_text));
    mContext = context;
    mRomUpdater = new RomUpdater(mContext, false);

    LayoutInflater inflater = LayoutInflater.from(context);
    View view = inflater.inflate(R.layout.card_system, this);

    TextView romView = (TextView) view.findViewById(R.id.rom);
    romView.setText(getResources().getString(R.string.system_rom, romUpdater.getVersion().toString(false)));

    TextView maintainerView = (TextView) view.findViewById(R.id.maintainer);
    maintainerView.setText(getResources().getString(R.string.system_maintainer, romUpdater.getMaintainer()));

    mSeparator = view.findViewById(R.id.separator);
    mUpdateItem = (Item) view.findViewById(R.id.update_found);
    refreshCard();
}

From source file:zjut.soft.finalwork.fragment.PageFragment1.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.page1, null);
    tv = (TextView) view.findViewById(R.id.page1_textview);
    mHandler = new Handler();
    return view;/* w w w  .j a  v  a2s  .c  om*/
}

From source file:net.eledge.android.europeana.gui.fragment.RecordDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_record_details, null);
    ListView mListView = (ListView) root.findViewById(R.id.fragment_record_details_listview);
    mListView.setAdapter(mRecordViewAdapter);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setupClipboardAction(mListView);
    }//from ww  w .  j ava  2s  . co  m
    return root;
}

From source file:net.eledge.android.europeana.gui.fragment.RecordMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_record_map, null);
    inject(this, root);
    mMapView.onCreate(savedInstanceState);
    RecordObject record = recordController.record;
    text1.setText(StringUtils.join(Resource.getPreferred(record.place.prefLabel,
            ((EuropeanaApplication) getActivity().getApplication()).getLocale()), ";"));
    text2.setText(record.place.latitude + ";" + record.place.longitude);
    return root;/*from   w ww.  ja  va2 s.co m*/
}