Example usage for android.app ProgressDialog ProgressDialog

List of usage examples for android.app ProgressDialog ProgressDialog

Introduction

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

Prototype

public ProgressDialog(Context context) 

Source Link

Document

Creates a Progress dialog.

Usage

From source file:com.android.email.activity.MessageView.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.message_view);
    mHandler = new MessageViewHandler();
    mControllerCallback = new ControllerResults();

    mSubjectView = (TextView) findViewById(R.id.subject);
    mFromView = (TextView) findViewById(R.id.from);
    mToView = (TextView) findViewById(R.id.to);
    mCcView = (TextView) findViewById(R.id.cc);
    mCcContainerView = findViewById(R.id.cc_container);
    mDateView = (TextView) findViewById(R.id.date);
    mTimeView = (TextView) findViewById(R.id.time);
    mMessageContentView = (WebView) findViewById(R.id.message_content);
    mAttachments = (LinearLayout) findViewById(R.id.attachments);
    mAttachmentIcon = (ImageView) findViewById(R.id.attachment);
    mFavoriteIcon = (ImageView) findViewById(R.id.favorite);
    mShowPicturesSection = findViewById(R.id.show_pictures_section);
    mInviteSection = findViewById(R.id.invite_section);
    mSenderPresenceView = (ImageView) findViewById(R.id.presence);
    mMoveToNewer = findViewById(R.id.moveToNewer);
    mMoveToOlder = findViewById(R.id.moveToOlder);
    mScrollView = findViewById(R.id.scrollview);

    mMoveToNewer.setOnClickListener(this);
    mMoveToOlder.setOnClickListener(this);
    mFromView.setOnClickListener(this);
    mSenderPresenceView.setOnClickListener(this);
    mFavoriteIcon.setOnClickListener(this);
    findViewById(R.id.reply).setOnClickListener(this);
    findViewById(R.id.reply_all).setOnClickListener(this);
    findViewById(R.id.delete).setOnClickListener(this);
    findViewById(R.id.show_pictures).setOnClickListener(this);

    mMeetingYes = (TextView) findViewById(R.id.accept);
    mMeetingMaybe = (TextView) findViewById(R.id.maybe);
    mMeetingNo = (TextView) findViewById(R.id.decline);

    mMeetingYes.setOnClickListener(this);
    mMeetingMaybe.setOnClickListener(this);
    mMeetingNo.setOnClickListener(this);
    findViewById(R.id.invite_link).setOnClickListener(this);

    mMessageContentView.setVerticalScrollBarEnabled(false);
    mMessageContentView.getSettings().setBlockNetworkLoads(true);
    mMessageContentView.getSettings().setSupportZoom(false);
    mMessageContentView.setWebViewClient(new CustomWebViewClient());

    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    mDateFormat = android.text.format.DateFormat.getDateFormat(this); // short format
    mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format

    mFavoriteIconOn = getResources().getDrawable(R.drawable.btn_star_big_buttonless_on);
    mFavoriteIconOff = getResources().getDrawable(R.drawable.btn_star_big_buttonless_off);

    initFromIntent();/*from  w w  w.j  a  v a  2 s. c  om*/
    if (icicle != null) {
        mMessageId = icicle.getLong(STATE_MESSAGE_ID, mMessageId);
    }

    mController = Controller.getInstance(getApplication());

    // This observer is used to watch for external changes to the message list
    mCursorObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange) {
            // get a new message list cursor, but only if we already had one
            // (otherwise it's "too soon" and other pathways will cause it to be loaded)
            if (mLoadMessageListTask == null && mMessageListCursor != null) {
                mLoadMessageListTask = new LoadMessageListTask(mMailboxId);
                mLoadMessageListTask.execute();
            }
        }
    };

    messageChanged();
}

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it//from  w  ww.  j  a v a  2 s  .co m
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id"));
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = addItemToList(Main.default_study_list_id,
                            (String) item.item_node.atts.get("id"), ItemActivity.this);
                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default list

                        ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id,
                                (String) item.item_node.atts.get("id"), Main.default_study_list_id,
                                ItemActivity.this);
                        result = ItemActivity.add_sentence_list_result;
                        if (ItemActivity.add_sentence_list_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.item_node.atts.get("id"),
                                    Main.default_study_list_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this,
                                                item.item_node.atts.get("id").toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:com.odoo.addons.crm.models.CRMLead.java

public void markWonLost(final String type, final ODataRow record, final OnOperationSuccessListener listener) {
    new AsyncTask<Void, Void, Void>() {
        private ProgressDialog dialog;

        @Override/*from www.j av  a 2 s .  co  m*/
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(mContext);
            dialog.setTitle(R.string.title_please_wait);
            dialog.setMessage(OResource.string(mContext, R.string.title_working));
            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            _markWonLost(type, record);
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            dialog.dismiss();
            if (listener != null) {
                listener.OnSuccess();
            }
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            dialog.dismiss();
            if (listener != null) {
                listener.OnCancelled();
            }
        }
    }.execute();

}

From source file:com.ccxt.whl.activity.LoginActivity.java

/**
 * ??//  w w w.  j  a va2  s  . c  o  m
 */
public void s_reg_login(final String username, final String pwd) {
    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("...");
        pd.show();
        new Thread(new Runnable() {
            public void run() {
                try {
                    // sdk
                    EMChatManager.getInstance().createAccountOnServer(username, pwd);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!LoginActivity.this.isFinishing())
                                pd.dismiss();
                            // ???
                            //                        DemoApplication.getInstance().setUserName(username);
                            DemoApplication.getInstance().setUser(username);
                            Toast.makeText(getApplicationContext(), "?", 0).show();
                            login(username, pwd);
                            //finish();
                        }
                    });
                } catch (final Exception e) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!LoginActivity.this.isFinishing())
                                pd.dismiss();
                            if (e != null && e.getMessage() != null) {
                                String errorMsg = e.getMessage();
                                if (errorMsg.indexOf("EMNetworkUnconnectedException") != -1) {
                                    Toast.makeText(getApplicationContext(), "?",
                                            0).show();
                                } else if (errorMsg.indexOf("conflict") != -1) {
                                    login(username, pwd);
                                    //Toast.makeText(getApplicationContext(), "?", 0).show();
                                } else if (errorMsg.indexOf("not support the capital letters") != -1) {
                                    Toast.makeText(getApplicationContext(), "??????",
                                            0).show();
                                } else {
                                    Toast.makeText(getApplicationContext(), ": " + e.getMessage(),
                                            1).show();
                                }

                            } else {
                                Toast.makeText(getApplicationContext(), ": ", 1).show();

                            }
                        }
                    });
                }
            }
        }).start();

    }
}

From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java

/**
 * ??./*from w w w  .jav  a2  s  .  co  m*/
 * ????????
 * @return ?????true??????false
 */
private synchronized boolean showProgressDialog() {
    if (mProgressDialog != null) {
        return false;
    }
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setTitle("dConnect?");
    mProgressDialog.setMessage("????????.");
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setCancelable(false);
    mProgressDialog.show();
    return true;
}

From source file:com.gimranov.zandy.app.AttachmentActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final String attachmentKey = b.getString("attachmentKey");
    final String itemKey = b.getString("itemKey");
    final String content = b.getString("content");
    final String mode = b.getString("mode");
    AlertDialog dialog;/* w  w w .j ava2 s  .  c o m*/
    switch (id) {
    case DIALOG_CONFIRM_NAVIGATE:
        dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.view_online_warning))
                .setPositiveButton(getResources().getString(R.string.view),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // The behavior for invalid URIs might be nasty, but
                                // we'll cross that bridge if we come to it.
                                try {
                                    Uri uri = Uri.parse(content);
                                    startActivity(new Intent(Intent.ACTION_VIEW).setData(uri));
                                } catch (ActivityNotFoundException e) {
                                    // There can be exceptions here; not sure what would prompt us to have
                                    // URIs that the browser can't load, but it apparently happens.
                                    Toast.makeText(getApplicationContext(), getResources()
                                            .getString(R.string.attachment_intent_failed_for_uri, content),
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_CONFIRM_DELETE:
        dialog = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.attachment_delete_confirm))
                .setPositiveButton(getResources().getString(R.string.menu_delete),
                        new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Attachment a = Attachment.load(attachmentKey, db);
                                a.delete(db);
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment at : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(at);
                                }
                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_NOTE:
        final EditText input = new EditText(this);
        input.setText(content, BufferType.EDITABLE);

        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.note)).setView(input).setPositiveButton(
                        getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Editable value = input.getText();
                                String fixed = value.toString().replaceAll("\n\n", "\n<br>");
                                if (mode != null && mode.equals("new")) {
                                    Log.d(TAG, "Attachment created with parent key: " + itemKey);
                                    Attachment att = new Attachment(getBaseContext(), "note", itemKey);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_NEW;
                                    att.save(db);
                                } else {
                                    Attachment att = Attachment.load(attachmentKey, db);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_DIRTY;
                                    att.save(db);
                                }
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment a : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(a);
                                }
                                la.notifyDataSetChanged();
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        });
        // We only want the delete option when this isn't a new note
        if (mode == null || !"new".equals(mode)) {
            builder = builder.setNegativeButton(getResources().getString(R.string.menu_delete),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Bundle b = new Bundle();
                            b.putString("attachmentKey", attachmentKey);
                            b.putString("itemKey", itemKey);
                            removeDialog(DIALOG_CONFIRM_DELETE);
                            AttachmentActivity.this.b = b;
                            showDialog(DIALOG_CONFIRM_DELETE);
                        }
                    });
        }
        dialog = builder.create();
        return dialog;
    case DIALOG_FILE_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog
                .setMessage(getResources().getString(R.string.attachment_downloading, b.getString("title")));
        mProgressDialog.setIndeterminate(true);
        return mProgressDialog;
    default:
        Log.e(TAG, "Invalid dialog requested");
        return null;
    }
}

From source file:com.odoo.addons.crm.models.CRMLead.java

public void createQuotation(final ODataRow lead, final String partnerId, final boolean close,
        final OnOperationSuccessListener listener) {
    new AsyncTask<Void, Void, Void>() {
        private ProgressDialog dialog;

        @Override//from   ww w .  ja  v a 2  s . c  om
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(mContext);
            dialog.setTitle(R.string.title_please_wait);
            dialog.setMessage(OResource.string(mContext, R.string.title_working));
            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                odoo.Odoo odoo = getServerDataHelper().getOdoo();
                // Creating wizard record
                JSONObject values = new JSONObject();
                ResPartner resPartner = new ResPartner(mContext, getUser());
                ODataRow partner = resPartner.browse(new String[] {}, Integer.parseInt(partnerId));
                values.put("partner_id", partner.getInt("id"));
                values.put("close", close);
                JSONObject context = new JSONObject();
                context.put("stage_type", lead.getString("type"));
                context.put("active_id", lead.getInt("id"));
                context.put("active_ids", new JSONArray().put(lead.getInt("id")));
                context.put("active_model", "crm.lead");
                odoo.updateContext(context);
                JSONObject result = odoo.createNew("crm.make.sale", values);
                int quotation_wizard_id = result.getInt("result");

                // Creating quotation
                OArguments arg = new OArguments();
                arg.add(quotation_wizard_id);
                arg.add(context);
                odoo.call_kw("crm.make.sale", "makeOrder", arg.get());
                Thread.sleep(500);
                // if close = true
                if (close)
                    _markWonLost("won", lead);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);

            dialog.dismiss();
            if (listener != null) {
                listener.OnSuccess();
            }
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            dialog.dismiss();
            if (listener != null) {
                listener.OnCancelled();
            }
        }
    }.execute();
}

From source file:net.fred.feedex.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*w  ww.j a  v a  2  s.c  o  m*/
        return true;
    case R.id.menu_validate: // only in insert mode
        final String name = mNameEditText.getText().toString().trim();
        final String urlOrSearch = mUrlEditText.getText().toString().trim();
        if (urlOrSearch.isEmpty()) {
            UiUtils.showMessage(EditFeedActivity.this, R.string.error_feed_error);
        }

        if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) {
            final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
            pd.setMessage(getString(R.string.loading));
            pd.setCancelable(true);
            pd.setIndeterminate(true);
            pd.show();

            getLoaderManager().restartLoader(1, null,
                    new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                        @Override
                        public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) {
                            String encodedSearchText = urlOrSearch;
                            try {
                                encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }

                            return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText);
                        }

                        @Override
                        public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader,
                                final ArrayList<HashMap<String, String>> data) {
                            pd.cancel();

                            if (data == null) {
                                UiUtils.showMessage(EditFeedActivity.this, R.string.error);
                            } else if (data.isEmpty()) {
                                UiUtils.showMessage(EditFeedActivity.this, R.string.no_result);
                            } else {
                                AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this);
                                builder.setTitle(R.string.feed_search);

                                // create the grid item mapping
                                String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC };
                                int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                                // fill in the grid_item layout
                                SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data,
                                        R.layout.item_search_result, from, to);
                                builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        FeedDataContentProvider.addFeed(EditFeedActivity.this,
                                                data.get(which).get(FEED_SEARCH_URL),
                                                name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name,
                                                mRetrieveFulltextCb.isChecked());

                                        setResult(RESULT_OK);
                                        finish();
                                    }
                                });
                                builder.show();
                            }
                        }

                        @Override
                        public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) {
                        }
                    });
        } else {
            FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name,
                    mRetrieveFulltextCb.isChecked());

            setResult(RESULT_OK);
            finish();
        }
        return true;
    case R.id.menu_add_filter: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null);

        new AlertDialog.Builder(this) //
                .setTitle(R.string.filter_add_title) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText()
                                .toString();
                        if (filterText.length() != 0) {
                            String feedId = getIntent().getData().getLastPathSegment();

                            ContentValues values = new ContentValues();
                            values.put(FilterColumns.FILTER_TEXT, filterText);
                            values.put(FilterColumns.IS_REGEX,
                                    ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked());
                            values.put(FilterColumns.IS_APPLIED_TO_TITLE,
                                    ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked());
                            values.put(FilterColumns.IS_ACCEPT_RULE,
                                    ((RadioButton) dialogView.findViewById(R.id.acceptRadio)).isChecked());

                            ContentResolver cr = getContentResolver();
                            cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}