Example usage for android.app Dialog setContentView

List of usage examples for android.app Dialog setContentView

Introduction

In this page you can find the example usage for android.app Dialog setContentView.

Prototype

public void setContentView(@NonNull View view) 

Source Link

Document

Set the screen content to an explicit view.

Usage

From source file:com.cettco.buycar.activity.OrderDetailActivity.java

private void initDialog() {
    final Dialog dialog = new Dialog(OrderDetailActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.popup_accept);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();/*from w ww.j  av a 2s  .  com*/
    Button cancelBtn = (Button) dialog.findViewById(R.id.popup_accept_cancel_btn);
    cancelBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    Button payBtn = (Button) dialog.findViewById(R.id.popup_accept_pay_btn);
    payBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:io.github.jhcpokemon.expressassist.fragment.SettingFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.clear:
        SharedPreferences sharedPreferences = getContext().getSharedPreferences("user_msg",
                Context.MODE_APPEND);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("email", "");
        editor.putString("password", "");
        editor.putBoolean("save", false);
        editor.putBoolean("auto", false);
        editor.apply();/*  ww w . j a  va 2 s. c  o  m*/
        ExpressLog.deleteAll(ExpressLog.class);
        getActivity().finishAffinity();
        break;
    case R.id.version:
        if (count == 0) {
            Dialog imageDialog = new Dialog(getContext());
            ViewGroup.LayoutParams params = imageDialog.getWindow().getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            imageDialog.getWindow().setAttributes((WindowManager.LayoutParams) params);
            imageDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
            imageDialog.setContentView(R.layout.image_dialog);
            imageDialog.setCancelable(true);
            imageDialog.show();
            versionBtn.setClickable(false);
        } else {
            count--;
        }
        break;
    case R.id.policy:
        Dialog policyDialog = new Dialog(getContext()) {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setTitle(R.string.policy);
                View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_policy, null, false);
                TextView policyTextView = (TextView) view.findViewById(R.id.policy);
                policyTextView.setText(policy);
                setContentView(view);
                setCancelable(true);
                ViewGroup.LayoutParams params = getWindow().getAttributes();
                params.width = WindowManager.LayoutParams.MATCH_PARENT;
                getWindow().setAttributes((WindowManager.LayoutParams) params);
            }
        };

        policyDialog.show();
        break;
    default:
        break;
    }
}

From source file:com.ibm.hellotodo.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *///from w w  w .ja  v  a 2s  .c  o m
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }

    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> cType = new ArrayList<>();
                cType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", cType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (t != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            t.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Kill dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:com.vk.sdk.dialogs.VKShareDialog.java

@NonNull
@Override/*from w w  w  .j a  v  a 2s . co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    View mInternalView = LayoutInflater.from(context).inflate(R.layout.vk_share_dialog, null);

    assert mInternalView != null;

    mSendButton = (Button) mInternalView.findViewById(R.id.sendButton);
    mSendProgress = (ProgressBar) mInternalView.findViewById(R.id.sendProgress);
    mPhotoLayout = (LinearLayout) mInternalView.findViewById(R.id.imagesContainer);
    mShareTextField = (EditText) mInternalView.findViewById(R.id.shareText);
    mPhotoScroll = (HorizontalScrollView) mInternalView.findViewById(R.id.imagesScrollView);

    LinearLayout mAttachmentLinkLayout = (LinearLayout) mInternalView.findViewById(R.id.attachmentLinkLayout);

    mSendButton.setOnClickListener(sendButtonPress);

    //Attachment text
    if (savedInstanceState != null) {
        mShareTextField.setText(savedInstanceState.getString(SHARE_TEXT_KEY));
        mAttachmentLink = savedInstanceState.getParcelable(SHARE_LINK_KEY);
        mAttachmentImages = (VKUploadImage[]) savedInstanceState.getParcelableArray(SHARE_IMAGES_KEY);
        mExistingPhotos = savedInstanceState.getParcelable(SHARE_UPLOADED_IMAGES_KEY);
    } else if (mAttachmentText != null) {
        mShareTextField.setText(mAttachmentText);
    }

    //Attachment photos
    mPhotoLayout.removeAllViews();
    if (mAttachmentImages != null) {
        for (VKUploadImage mAttachmentImage : mAttachmentImages) {
            addBitmapToPreview(mAttachmentImage.mImageData);
        }
        mPhotoLayout.setVisibility(View.VISIBLE);
    }

    if (mExistingPhotos != null) {
        processExistingPhotos();
    }
    if (mExistingPhotos == null && mAttachmentImages == null) {
        mPhotoLayout.setVisibility(View.GONE);
    }

    //Attachment link
    if (mAttachmentLink != null) {
        TextView linkTitle = (TextView) mAttachmentLinkLayout.findViewById(R.id.linkTitle),
                linkHost = (TextView) mAttachmentLinkLayout.findViewById(R.id.linkHost);

        linkTitle.setText(mAttachmentLink.linkTitle);
        linkHost.setText(VKUtil.getHost(mAttachmentLink.linkUrl));
        mAttachmentLinkLayout.setVisibility(View.VISIBLE);
    } else {
        mAttachmentLinkLayout.setVisibility(View.GONE);
    }
    Dialog result = new Dialog(context);
    result.requestWindowFeature(Window.FEATURE_NO_TITLE);
    result.setContentView(mInternalView);
    result.setCancelable(true);
    result.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            if (mListener != null) {
                mListener.onVkShareCancel();
            }
            VKShareDialog.this.dismiss();
        }
    });
    return result;
}

From source file:com.kircherelectronics.gyroscopeexplorer.activity.GyroscopeActivity.java

private void showHelpDialog() {
    Dialog helpDialog = new Dialog(this);

    helpDialog.setCancelable(true);/*from   w ww  .  j a  v a 2  s.  c  om*/
    helpDialog.setCanceledOnTouchOutside(true);
    helpDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    View view = getLayoutInflater().inflate(R.layout.layout_help_home, null);

    helpDialog.setContentView(view);

    helpDialog.show();
}

From source file:com.ibm.hellotodo.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 */// ww  w  . j a v a 2s .c o  m
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer pos = mListView.getPositionForView(view);
    final Dialog addDialog = new Dialog(this);

    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Edit Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    EditText et = (EditText) addDialog.findViewById(R.id.todo);

    final String name = mTodoItemList.get(pos).text;
    final boolean isDone = mTodoItemList.get(pos).isDone;
    final int id = mTodoItemList.get(pos).idNumber;
    et.setText(name);

    Button addDone = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    addDone.setOnClickListener(new View.OnClickListener() {
        // Save text inputted when done is tapped
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) addDialog.findViewById(R.id.todo);

            String newName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!newName.isEmpty()) {
                String json = "{\"text\":\"" + newName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using the IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> cType = new ArrayList<>();
                cType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", cType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (t != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            t.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            addDialog.dismiss();
        }
    });
}

From source file:com.gumgoose.app.quakebuddy.EarthquakeActivity.java

private void showWhatsNewDialog() {
    // Display the change log for QuakeBuddy on-screen
    Dialog dialog = new Dialog(this, android.R.style.Theme_Dialog);
    dialog.setCanceledOnTouchOutside(true);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.setContentView(R.layout.dialog_change_log);
    dialog.show();//from   w  w  w .  j  a v a  2  s  .  co m
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display dialog to the user for the browser bookmarks. Allow the user to add a
 * browser bookmark to an existing row or a new row.
 * //from  w w w. ja v a2 s  .  c  om
 * @param context
 */
public static void displayAddBrowserBookmark(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.add_browser_bookmarks_list);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
        }

    });

    ListView listView = (ListView) dialog.findViewById(R.id.list);
    final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context);
    Collections.sort(bookmarks, new Comparator<BookmarkInfo>() {

        @Override
        public int compare(BookmarkInfo lhs, BookmarkInfo rhs) {
            return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase());
        }

    });
    listView.setAdapter(new BookmarkAdapter(context, bookmarks));
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            // run in thread since network logic needed to get bookmark icon
            new Thread(new Runnable() {
                public void run() {
                    // if the new row radio button is selected, the user must enter
                    // a name for the new row
                    String name = nameEditText.getText().toString().trim();
                    if (newRadioButton.isChecked() && name.length() == 0) {
                        nameEditText.requestFocus();
                        displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                        return;
                    }
                    boolean currentRow = !newRadioButton.isChecked();
                    try {
                        BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position);
                        int rowId = 0;
                        int rowPosition = 0;
                        if (currentRow) {
                            rowId = context.getCurrentGalleryId();
                            ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId);
                            rowPosition = items.size(); // in last
                            // position
                            // for selected
                            // row
                        } else {
                            rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE);
                            rowPosition = 0;
                        }
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(bookmark.getUrl()));

                        Uri uri = Uri.parse(bookmark.getUrl());
                        Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost());
                        String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost());
                        Log.d(LOG_TAG, "icon1=" + icon);
                        if (icon == null) {
                            // try base host address
                            int count = StringUtils.countMatches(uri.getHost(), ".");
                            if (count > 1) {
                                int index = uri.getHost().indexOf('.');
                                String baseHost = uri.getHost().substring(index + 1);
                                icon = Utils.getWebSiteIcon(context, "http://" + baseHost);
                                Log.d(LOG_TAG, "icon2=" + icon);
                            }
                        }

                        ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon,
                                DatabaseHelper.SHORTCUT_TYPE);
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "displayAddBrowserBookmark", e);
                    }

                    // need to do this on UI thread
                    context.getHandler().post(new Runnable() {
                        public void run() {
                            context.showCover(false);
                            dialog.dismiss();
                            context.reloadAllGalleries();
                        }
                    });

                    if (currentRow) {
                        Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK);
                    } else {
                        Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW);
                    }

                }
            }).start();
        }
    });
    listView.setDrawingCacheEnabled(true);
    listView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK);
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

private Dialog signOutDialog() {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override/* w  w  w.  j  ava  2  s  .  c o  m*/
        public void onClick(View view) {
            switch (view.getId()) {
            case R.id.close_app:

                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_confirm);
                dismiss();
                break;
            case R.id.stay_here:
                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_cancel);
                dismiss();
                break;
            default:
                break;
            }
        }
    };
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.view_sign_out_dialog, null);
    TextView signOutButton = (TextView) convertView.findViewById(R.id.stay_here);
    TextView closeAppButton = (TextView) convertView.findViewById(R.id.close_app);

    signOutButton.setOnClickListener(listener);
    closeAppButton.setOnClickListener(listener);
    Dialog dialog = new Dialog(mContext, R.style.CustomDialog);
    dialog.setContentView(convertView);
    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    return dialog;
}

From source file:com.smsc.usuario.ui.MapaActivity.java

public void getDetalle(int posicion) {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);//from  w  w  w .j  a v  a  2 s.  c o m
    dialog.setContentView(R.layout.dialog_incidente);

    TextView lblAsunto = (TextView) dialog.findViewById(R.id.lblAsunto);
    lblAsunto.setText(lista.get(posicion).getStr_detalle());

    TextView lblNombreInciente = (TextView) dialog.findViewById(R.id.lblNombreInciente);
    lblNombreInciente.setText(lista.get(posicion).getStr_tipo_incidente_nombre());

    TextView lblEstado = (TextView) dialog.findViewById(R.id.lblEstado);
    lblEstado.setText("Enviado");
    if (lista.get(posicion).getInt_estado() == 1)
        lblEstado.setText("En Progreso");
    else if (lista.get(posicion).getInt_estado() == 2)
        lblEstado.setText("Valido");
    else if (lista.get(posicion).getInt_estado() == 3)
        lblEstado.setText("Invalido");
    SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat hora = new SimpleDateFormat("h:mm a");

    TextView lblFecha = (TextView) dialog.findViewById(R.id.lblFecha);
    lblFecha.setText(fecha.format(lista.get(posicion).getDat_fecha_registro()));

    TextView lblHora = (TextView) dialog.findViewById(R.id.lblHora);
    lblHora.setText(hora.format(lista.get(posicion).getDat_fecha_registro()));

    View ViewFoto = (View) dialog.findViewById(R.id.ViewFoto);
    if (lista.get(posicion).getByte_foto() == null) {
        ViewFoto.setVisibility(View.GONE);
    } else {
        ImageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageBitmap(Funciones.getBitmap(lista.get(posicion).getByte_foto()));
    }

    View ViewCalificacion = (View) dialog.findViewById(R.id.ViewCalificacion);
    if (lista.get(posicion).getInt_rapides() == 0 && lista.get(posicion).getInt_conformidad() == 0) {
        ViewCalificacion.setVisibility(View.GONE);
    } else {
        RatingBar ratingRapides = (RatingBar) dialog.findViewById(R.id.ratingRapides);
        ratingRapides.setRating(lista.get(posicion).getInt_rapides());

        RatingBar ratingConformidad = (RatingBar) dialog.findViewById(R.id.ratingConformidad);
        ratingConformidad.setRating(lista.get(posicion).getInt_conformidad());
    }

    Button btnAceptar = (Button) dialog.findViewById(R.id.btnAceptar);
    btnAceptar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();

}