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:br.com.bioscada.apps.biotracks.fragments.ChooseActivityTypeDialogFragment.java

public static Dialog getDialog(final Activity activity, final String category,
        final ChooseActivityTypeCaller caller) {
    View view = activity.getLayoutInflater().inflate(R.layout.choose_activity_type, null);
    GridView gridView = (GridView) view.findViewById(R.id.choose_activity_type_grid_view);
    final View weightContainer = view.findViewById(R.id.choose_activity_type_weight_container);

    TextView weightLabel = (TextView) view.findViewById(R.id.choose_activity_type_weight_label);
    weightLabel.setText(PreferencesUtils.isMetricUnits(activity) ? R.string.description_weight_metric
            : R.string.description_weight_imperial);

    final TextView weight = (TextView) view.findViewById(R.id.choose_activity_type_weight);

    List<Integer> imageIds = new ArrayList<Integer>();
    for (String iconValue : TrackIconUtils.getAllIconValues()) {
        imageIds.add(TrackIconUtils.getIconDrawable(iconValue));
    }/*from   w  w  w. j  a  v a  2  s .  c  om*/

    Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_track_airplane, options);
    int padding = 32;
    int width = options.outWidth + 2 * padding;
    int height = options.outHeight + 2 * padding;
    gridView.setColumnWidth(width);

    final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(activity, imageIds,
            width, height, padding);
    gridView.setAdapter(imageAdapter);

    final String weightValue = StringUtils.formatWeight(PreferencesUtils.getWeightDisplayValue(activity));
    final AlertDialog alertDialog = new AlertDialog.Builder(activity)
            .setNegativeButton(R.string.generic_cancel, null)
            .setPositiveButton(R.string.generic_ok, new Dialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    boolean newWeight = false;
                    if (weightContainer.getVisibility() == View.VISIBLE) {
                        String newValue = weight.getText().toString();
                        if (!newValue.equals(weightValue)) {
                            newWeight = true;
                            PreferencesUtils.storeWeightValue(activity, newValue);
                        }
                    }
                    int selected = imageAdapter.getSelected();
                    caller.onChooseActivityTypeDone(TrackIconUtils.getAllIconValues().get(selected), newWeight);
                }
            }).setTitle(R.string.track_edit_activity_type_hint).setView(view).create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            int position = getPosition(activity, category);
            alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(position != -1);
            if (position != -1) {
                imageAdapter.setSelected(position);
                imageAdapter.notifyDataSetChanged();
            }
            updateWeightContainer(weightContainer, position);
            weight.setText(weightValue);
            DialogUtils.setDialogTitleDivider(activity, alertDialog);
        }
    });

    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true);
            imageAdapter.setSelected(position);
            imageAdapter.notifyDataSetChanged();
            updateWeightContainer(weightContainer, position);
        }
    });
    return alertDialog;
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void showNetworkUnavailable(Activity activity) {
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.network_not_available,
            (ViewGroup) activity.findViewById(R.id.nwunavailable));
    Toast toast = new Toast(activity);
    toast.setView(view);/* w w w .  j  a  va2 s .  c  o  m*/
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:it.feio.android.omninotes.BaseActivity.java

/**
 * Method to validate security password to protect notes.
 * It uses an interface callback./*w  ww .  j a  v  a  2s .  co m*/
 */
public static void requestPassword(final Activity mActivity, final PasswordValidator mPasswordValidator) {

    // Inflate layout
    LayoutInflater inflater = mActivity.getLayoutInflater();
    final View v = inflater.inflate(R.layout.password_request_dialog_layout, null);
    final EditText passwordEditText = (EditText) v.findViewById(R.id.password_request);

    MaterialDialog dialog = new MaterialDialog.Builder(mActivity).autoDismiss(false)
            .title(R.string.insert_security_password).customView(v, false).positiveText(R.string.ok)
            .callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    // When positive button is pressed password correctness is checked
                    String oldPassword = mActivity
                            .getSharedPreferences(Constants.PREFS_NAME, MODE_MULTI_PROCESS)
                            .getString(Constants.PREF_PASSWORD, "");
                    String password = passwordEditText.getText().toString();
                    // The check is done on password's hash stored in preferences
                    boolean result = Security.md5(password).equals(oldPassword);

                    // In case password is ok dialog is dismissed and result sent to callback
                    if (result) {
                        KeyboardUtils.hideKeyboard(passwordEditText);
                        dialog.dismiss();
                        mPasswordValidator.onPasswordValidated(true);
                        // If password is wrong the auth flow is not interrupted and simply a message is shown
                    } else {
                        passwordEditText.setError(mActivity.getString(R.string.wrong_password));
                    }
                }
            }).build();

    dialog.setOnCancelListener(dialog1 -> {
        KeyboardUtils.hideKeyboard(passwordEditText);
        dialog1.dismiss();
        mPasswordValidator.onPasswordValidated(false);
    });

    dialog.show();

    // Force focus and shows soft keyboard
    new Handler().postDelayed(() -> KeyboardUtils.showKeyboard(passwordEditText), 100);
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void makeToast(Activity activity, String Text) {
    LayoutInflater inflater = activity.getLayoutInflater();

    View toastLayout = inflater.inflate(R.layout.toast,
            (ViewGroup) activity.findViewById(R.id.toast_root_view));

    TextView header = (TextView) toastLayout.findViewById(R.id.toast_message);
    header.setText(Text);/* w  w w.j  a  va2  s .c o m*/

    Toast toast = new Toast(activity.getApplicationContext());
    toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(toastLayout);
    toast.show();
}

From source file:de.wikilab.android.friendica01.Max.java

/**
 * displays the login form (layout/loginscreen.xml) as a modal dialog and calls tryLogin
  * when user confirms the form/*  ww  w  .j  a va  2  s  . c o  m*/
 * @param ctx     MUST IMPLEMENT LoginListener !!!
 * @param errmes  message which is displayed above the Login form (e.g. "wrong password entered")
 */
public static void showLoginForm(final Activity ctx, String errmes) {
    Log.v(TAG, "... showLoginForm");
    View myView = ctx.getLayoutInflater().inflate(R.layout.loginscreen, null, false);
    final AlertDialog alert = new AlertDialog.Builder(ctx).setTitle("Login to Friendica").setView(myView)
            .setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    ctx.finish();
                }
            }).show();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String protocol = prefs.getString("login_protocol", "https");
    String server = prefs.getString("login_server", null);
    String userName = prefs.getString("login_user", null);

    if (errmes != null) {
        ((TextView) myView.findViewById(R.id.lblInfo)).setText(errmes);
    }

    final Spinner selProtocol = (Spinner) myView.findViewById(R.id.selProtocol);
    selProtocol.setSelection(protocol.equals("https") ? 1 : 0); //HACK !!!

    final EditText edtServer = (EditText) myView.findViewById(R.id.edtServer);
    edtServer.setText(server);

    final EditText edtUser = (EditText) myView.findViewById(R.id.edtUser);
    edtUser.setText(userName);

    final EditText edtPassword = (EditText) myView.findViewById(R.id.edtPassword);

    ((TextView) myView.findViewById(R.id.proxy_settings)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ctx.startActivity(new Intent(ctx, PreferencesActivity.class));
        }
    });

    ((Button) myView.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
            prefs.putString("login_protocol", selProtocol.getSelectedItem().toString());
            String server = edtServer.getText().toString();
            server = server.replaceAll("^https?://", "");
            prefs.putString("login_server", server);
            prefs.putString("login_user", edtUser.getText().toString());
            prefs.putString("login_password", edtPassword.getText().toString());
            prefs.commit();

            alert.dismiss();

            tryLogin(ctx);
        }
    });
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void showCopyBubble(final Activity context, final View v, final View t) {
    try {//w  ww . j  a  v  a2 s .co m
        if (context == null)
            return;
        if (v != null)
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (copy == null)
                        copy = context.getLayoutInflater().inflate(R.layout.copy, null);
                    if (copy == null)
                        return;
                    final RelativeLayout root = (RelativeLayout) context.findViewById(R.id.main_layout);
                    root.removeView(copy);
                    copy.setClickable(true);
                    copy.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            try {
                                if (t != null) {
                                    BRClipboardManager.copyToClipboard(context,
                                            ((TextView) t).getText().toString());
                                    Log.e(TAG, "clicked copy: " + ((TextView) t).getText().toString());
                                }
                                hideCopyBubble(context);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    root.addView(copy);
                    copy.setY(getRelativeTop(v));
                    copy.setX(MainActivity.screenParametersPoint.x / 2 - 40);
                }
            });
        if (t != null)
            t.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    View parent = (View) t.getParent();
                    if (parent != null)
                        parent.performClick();
                }
            });
    } catch (Exception e) {
        e.printStackTrace();
    }

}

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

public static void saveMarks(final Activity c, final Stack<LatLng> trace) {
    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 {//from   ww w. ja  v  a  2s.  c  o  m
        destination = c.getDir("traces", Context.MODE_PRIVATE);
    }

    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);

                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();

}

From source file:nf.frex.android.FrexActivity.java

static void setMenuBackground(final Activity activity) {
    activity.getLayoutInflater().setFactory(new LayoutInflater.Factory() {
        @Override/*from   www  . j  a  va  2s  .c  om*/
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater inflater = activity.getLayoutInflater();
                    final View view = inflater.createView(name, null, attrs);
                    new Handler().post(new Runnable() {
                        public void run() {
                            view.setBackgroundColor(Color.argb(127, 0, 0, 0));
                        }
                    });
                    return view;
                } catch (InflateException e) {
                    // :(
                } catch (ClassNotFoundException e) {
                    // :(
                }
            }
            return null;
        }
    });
}

From source file:org.nuxeo.android.simpleclient.listing.ui.TaskItemViewWrapper.java

@Override
protected View createNewView(Activity activity, JSONObject businessObjectClass) {
    return activity.getLayoutInflater().inflate(R.layout.taskitem_view, null);
}

From source file:org.ubicollab.nomad.home.RssListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Activity activity = (Activity) getContext();
    LayoutInflater inflater = activity.getLayoutInflater();

    // Inflate the views from XML
    View rowView = inflater.inflate(R.layout.image_text_layout, null);
    JSONObject jsonImageText = getItem(position);

    TextView textView = (TextView) rowView.findViewById(R.id.row_text);

    try {// ww  w  .j a  v a2 s  . c  o  m
        Spanned text = (Spanned) jsonImageText.get("text");
        textView.setText(text);

    } catch (JSONException e) {
        textView.setText("JSON Exception");
    }

    return rowView;

}