Example usage for android.view View inflate

List of usage examples for android.view View inflate

Introduction

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

Prototype

public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) 

Source Link

Document

Inflate a view from an XML resource.

Usage

From source file:com.hanyu.desheng.activity.ChatActivity.java

/**
 * ?gridview?view/*from  w  w  w  .j  av  a 2 s. c  o m*/
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        @SuppressWarnings("rawtypes")
                        Class clz = Class.forName("com.hanyu.desheng.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:pro.dbro.bart.TheActivity.java

private void showErrorDialog(String message) {
    TextView crashTv = (TextView) View.inflate(c, R.layout.tabletext, null);
    if (message.compareTo("") == 0)
        crashTv.setText(Html.fromHtml(res.getStringArray(R.array.crashCatchDialog)[1]));
    else/*w  ww  .  j  a  v  a2  s .  c om*/
        crashTv.setText(message);
    crashTv.setTextSize(18);
    crashTv.setPadding(0, 0, 0, 0);
    crashTv.setMovementMethod(LinkMovementMethod.getInstance());
    new AlertDialog.Builder(c).setTitle(res.getStringArray(R.array.crashCatchDialog)[0]).setView(crashTv)
            .setIcon(R.drawable.sad_mac).setPositiveButton("Bummer", null).show();
}

From source file:vapor.view.VaporView.java

/**
 * Inflate a view from an XML resource./*from  w w  w . j  a  va  2s  .  co m*/
 * 
 * @param context
 *            The Context object for your activity or application.
 * @param resource
 *            The resource ID to inflate
 * @param root
 *            A view group that will be the parent. Used to properly inflate
 *            the layout_* parameters.
 * @return
 */
public static VaporView<? extends View, ?> inflate(Context context, int resource,
        VaporViewGroup<? extends ViewGroup, ?> root) {
    return $.vapor(View.inflate(context, resource, (ViewGroup) root.view()));
}

From source file:maimeng.yodian.app.client.android.chat.activity.ChatActivity.java

/**
 * ?gridview?view//from   w  ww . j av  a2s. c o m
 *
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("maimeng.yodian.app.client.android.chat.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@SuppressWarnings("unused")
void addSearch() {
    final PersonaWidget info = PersonaWidget.makeSearch();
    final PersonaCellLayout.CellInfo cellInfo = mAddItemCellInfo;

    final int[] xy = mCellCoordinates;
    final int spanX = info.spanX;
    final int spanY = info.spanY;

    AlertDialog.Builder builder;/*from  ww w  .  jav  a2  s  . c o m*/
    AlertDialog alertDialog;

    final View dlg_layout = View.inflate(PersonaLauncher.this, R.layout.pr_widget_span_setup, null);
    final PersonaNumberPicker ncols = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_columns_span);
    ncols.setRange(1, mWorkspace.currentDesktopColumns());
    ncols.setCurrent(spanX);
    final PersonaNumberPicker nrows = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_rows_span);
    nrows.setRange(1, mWorkspace.currentDesktopRows());
    nrows.setCurrent(spanY);
    builder = new AlertDialog.Builder(PersonaLauncher.this);
    builder.setView(dlg_layout);
    alertDialog = builder.create();
    alertDialog.setTitle(getResources().getString(R.string.widget_config_dialog_title));
    alertDialog.setMessage(getResources().getString(R.string.widget_config_dialog_summary));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int spanX = ncols.getCurrent();
                    int spanY = nrows.getCurrent();
                    // realAddSearch(info,cellInfo,xy,spanX,spanY);
                }
            });
    alertDialog.show();
}

From source file:org.petero.droidfish.DroidFish.java

private final Dialog selectMoveDialog() {
    setAutoMode(AutoMode.OFF);//from w w w  .j  a v  a 2s .  co  m
    View content = View.inflate(this, R.layout.select_move_number, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.goto_move);
    final EditText moveNrView = (EditText) content.findViewById(R.id.selmove_number);
    moveNrView.setText("1");
    final Runnable gotoMove = new Runnable() {
        public void run() {
            try {
                int moveNr = Integer.parseInt(moveNrView.getText().toString());
                ctrl.gotoMove(moveNr);
            } catch (NumberFormatException nfe) {
                Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            gotoMove.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final AlertDialog dialog = builder.create();

    moveNrView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                gotoMove.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:org.mdc.chess.MDChess.java

private void selectPgnSaveNewFileDialog() {
    setAutoMode(AutoMode.OFF);/* w w w.  j a v  a  2  s  . co m*/
    View content = View.inflate(this, R.layout.create_pgn_file, null);

    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename);
    final TextInputLayout fileNameWrapper = (TextInputLayout) content
            .findViewById(R.id.create_pgn_filename_wrapper);
    fileNameWrapper.setHint(content.getResources().getString(R.string.filename));
    fileNameView.setText("");
    final Runnable savePGN = new Runnable() {
        public void run() {
            String pgnFile = fileNameView.getText().toString();
            if ((pgnFile.length() > 0) && !pgnFile.contains(".")) {
                pgnFile += ".pgn";
            }
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
            savePGNToFile(pathName);
        }
    };

    new MaterialDialog.Builder(this).title(R.string.select_pgn_file_save).customView(content, true)
            .positiveText(android.R.string.ok).negativeText(R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    savePGN.run();
                }
            }).onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                }
            }).show();

    fileNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                savePGN.run();
                return true;
            }
            return false;
        }
    });
}

From source file:org.mdc.chess.MDChess.java

private void moveListMenuDialog() {
    final int EDIT_HEADERS = 0;
    final int EDIT_COMMENTS = 1;
    final int REMOVE_SUBTREE = 2;
    final int MOVE_VAR_UP = 3;
    final int MOVE_VAR_DOWN = 4;
    final int ADD_NULL_MOVE = 5;

    setAutoMode(AutoMode.OFF);/*from   w ww.j  a v a2s. c  om*/
    List<CharSequence> lst = new ArrayList<>();
    List<Integer> actions = new ArrayList<>();
    lst.add(getString(R.string.edit_headers));
    actions.add(EDIT_HEADERS);
    if (ctrl.humansTurn()) {
        lst.add(getString(R.string.edit_comments));
        actions.add(EDIT_COMMENTS);
    }
    lst.add(getString(R.string.truncate_gametree));
    actions.add(REMOVE_SUBTREE);
    if (ctrl.canMoveVariationUp()) {
        lst.add(getString(R.string.move_var_up));
        actions.add(MOVE_VAR_UP);
    }
    if (ctrl.canMoveVariationDown()) {
        lst.add(getString(R.string.move_var_down));
        actions.add(MOVE_VAR_DOWN);
    }

    boolean allowNullMove = (gameMode.analysisMode()
            || (gameMode.playerWhite() && gameMode.playerBlack() && !gameMode.clocksActive()))
            && !ctrl.inCheck();
    if (allowNullMove) {
        lst.add(getString(R.string.add_null_move));
        actions.add(ADD_NULL_MOVE);
    }
    final List<Integer> finalActions = actions;

    new MaterialDialog.Builder(this).title(R.string.edit_game).items(lst)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    switch (finalActions.get(which)) {
                    case EDIT_HEADERS: {
                        final TreeMap<String, String> headers = new TreeMap<>();
                        ctrl.getHeaders(headers);

                        View content = View.inflate(MDChess.this, R.layout.edit_headers, null);

                        final TextView event, site, date, round, white, black;

                        event = (TextView) content.findViewById(R.id.ed_header_event);
                        site = (TextView) content.findViewById(R.id.ed_header_site);
                        date = (TextView) content.findViewById(R.id.ed_header_date);
                        round = (TextView) content.findViewById(R.id.ed_header_round);
                        white = (TextView) content.findViewById(R.id.ed_header_white);
                        black = (TextView) content.findViewById(R.id.ed_header_black);

                        event.setText(headers.get("Event"));
                        site.setText(headers.get("Site"));
                        date.setText(headers.get("Date"));
                        round.setText(headers.get("Round"));
                        white.setText(headers.get("White"));
                        black.setText(headers.get("Black"));

                        new MaterialDialog.Builder(MDChess.this).title(R.string.edit_headers)
                                .customView(content, true).positiveText(android.R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        headers.put("Event", event.getText().toString().trim());
                                        headers.put("Site", site.getText().toString().trim());
                                        headers.put("Date", date.getText().toString().trim());
                                        headers.put("Round", round.getText().toString().trim());
                                        headers.put("White", white.getText().toString().trim());
                                        headers.put("Black", black.getText().toString().trim());
                                        ctrl.setHeaders(headers);
                                        setBoardFlip(true);
                                    }
                                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {

                                    }
                                }).show();

                        break;
                    }
                    case EDIT_COMMENTS: {
                        View content = View.inflate(MDChess.this, R.layout.edit_comments, null);

                        MDChessController.CommentInfo commInfo = ctrl.getComments();

                        final TextView preComment, moveView, nag, postComment;
                        preComment = (TextView) content.findViewById(R.id.ed_comments_pre);
                        final TextInputLayout preCommentWrapper = (TextInputLayout) content
                                .findViewById(R.id.ed_comments_pre_wrapper);
                        preCommentWrapper.setHint(content.getResources().getString(R.string.comment_before));
                        moveView = (TextView) content.findViewById(R.id.ed_comments_move);
                        nag = (TextView) content.findViewById(R.id.ed_comments_nag);
                        postComment = (TextView) content.findViewById(R.id.ed_comments_post);
                        final TextInputLayout postCommentWrapper = (TextInputLayout) content
                                .findViewById(R.id.ed_comments_post_wrapper);
                        postCommentWrapper.setHint(content.getResources().getString(R.string.comment_after));
                        preComment.setText(commInfo.preComment);
                        postComment.setText(commInfo.postComment);
                        moveView.setText(commInfo.move);
                        String nagStr = Node.nagStr(commInfo.nag).trim();
                        if ((nagStr.length() == 0) && (commInfo.nag > 0)) {
                            nagStr = String.format(Locale.US, "%d", commInfo.nag);
                        }
                        nag.setText(nagStr);

                        new MaterialDialog.Builder(MDChess.this).title(R.string.edit_comments)
                                .customView(content, true).positiveText(android.R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        String pre = preComment.getText().toString().trim();
                                        String post = postComment.getText().toString().trim();
                                        int nagVal = Node.strToNag(nag.getText().toString());

                                        MDChessController.CommentInfo commInfo = new MDChessController.CommentInfo();
                                        commInfo.preComment = pre;
                                        commInfo.postComment = post;
                                        commInfo.nag = nagVal;
                                        ctrl.setComments(commInfo);
                                    }
                                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {

                                    }
                                }).show();

                        break;
                    }
                    case REMOVE_SUBTREE:
                        ctrl.removeSubTree();
                        break;
                    case MOVE_VAR_UP:
                        ctrl.moveVariation(-1);
                        break;
                    case MOVE_VAR_DOWN:
                        ctrl.moveVariation(1);
                        break;
                    case ADD_NULL_MOVE:
                        ctrl.makeHumanNullMove();
                        break;
                    }
                }
            }).show();
}

From source file:xj.property.activity.HXBaseActivity.ChatActivity.java

/**
 * ?gridview?view//from ww  w.  ja  v  a 2  s .c o  m
 *
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);/// 20/27//34
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, 40));
    } else if (i == 3) {
        list.addAll(reslist.subList(40, 60));
    } else if (i == 4) {
        list.addAll(reslist.subList(60, 80));
    } else if (i == 5) {
        list.addAll(reslist.subList(80, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("xj.property.utils.SmileUtils");

                        Field field = clz.getField(filename);

                        int selectionStart = mEditTextContent.getSelectionStart();// ??
                        Spannable smiledText = SmileUtils.getSmiledText(getmContext(),
                                (String) field.get(null));
                        Editable editableText = mEditTextContent.getEditableText();
                        editableText.insert(selectionStart, smiledText);

                        //                        mEditTextContent.append(SmileUtils.getSmiledText(getmContext(), (String) field.get(null)));

                    } else {
                        // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??

                            if (selectionStart > 0) {

                                String body = mEditTextContent.getText().toString();

                                String tempStr = body.substring(0, selectionStart);

                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    /// ??
                                    CharSequence cs = tempStr.substring(i, selectionStart);

                                    if (SmileUtils.containsKey(cs.toString()))
                                        /// ???
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {

                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

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

        }
    });
    return view;
}

From source file:org.petero.droidfish.DroidFish.java

private final Dialog selectPgnSaveNewFileDialog() {
    setAutoMode(AutoMode.OFF);/*  w  w w  . j a va  2s.  c o  m*/
    View content = View.inflate(this, R.layout.create_pgn_file, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.select_pgn_file_save);
    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename);
    fileNameView.setText("");
    final Runnable savePGN = new Runnable() {
        public void run() {
            String pgnFile = fileNameView.getText().toString();
            if ((pgnFile.length() > 0) && !pgnFile.contains("."))
                pgnFile += ".pgn";
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
            savePGNToFile(pathName, false);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            savePGN.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final Dialog dialog = builder.create();
    fileNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                savePGN.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}