Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:co.nerdart.ourss.activity.EditFeedActivity.java

public void onClickSearch(View view) {
    final View dialogView = getLayoutInflater().inflate(R.layout.search_feed, null);
    final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
    final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

    new AlertDialog.Builder(EditFeedActivity.this) //
            .setIcon(R.drawable.action_search) //
            .setTitle(R.string.feed_search) //
            .setView(dialogView) //
            .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                @Override//from   w w w  . j  a  v  a  2s  .  c  o  m
                public void onClick(DialogInterface dialog, int which) {

                    if (searchText.getText().length() > 0) {
                        String tmp = searchText.getText().toString();
                        try {
                            tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }
                        final String text = tmp;

                        switch (radioGroup.getCheckedRadioButtonId()) {
                        case R.id.byWebSearch:
                            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 LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                                        @Override
                                        public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id,
                                                Bundle args) {
                                            return new GetFeedSearchResultsLoader(EditFeedActivity.this, text);
                                        }

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

                                            if (data == null) {
                                                Crouton.makeText(EditFeedActivity.this, R.string.error,
                                                        Style.INFO);
                                            } else if (data.isEmpty()) {
                                                Crouton.makeText(EditFeedActivity.this, R.string.no_result,
                                                        Style.INFO);
                                            } 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.search_result_item, from, to);
                                                builder.setAdapter(adapter,
                                                        new DialogInterface.OnClickListener() {
                                                            @Override
                                                            public void onClick(DialogInterface dialog,
                                                                    int which) {
                                                                mNameEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_TITLE));
                                                                mUrlEditText.setText(
                                                                        data.get(which).get(FEED_SEARCH_URL));
                                                            }
                                                        });
                                                builder.show();
                                            }
                                        }

                                        @Override
                                        public void onLoaderReset(
                                                Loader<ArrayList<HashMap<String, String>>> loader) {
                                        }
                                    }).forceLoad();
                            break;

                        case R.id.byTopic:
                            mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                    + "&start=1&length=10&l=en&src=news&f=rss");
                            break;

                        case R.id.byYoutube:
                            mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "")
                                    + "/videos.rss");
                            break;
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
}

From source file:com.easemob.chatuidemo.activity.ContactlistFragment.java

/**
 * user???/* ww  w  .  j a  v  a2s. c  o m*/
 */
private void moveToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    String st1 = getResources().getString(R.string.Is_moved_into_blacklist);
    final String st2 = getResources().getString(R.string.Move_into_blacklist_success);
    final String st3 = getResources().getString(R.string.Move_into_blacklist_failure);
    pd.setMessage(st1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                //???
                EMContactManager.getInstance().addUserToBlackList(username, false);
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st2, Toast.LENGTH_SHORT).show();
                        refresh();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st3, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();

}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Import data previously exported.//w  ww .  ja  v  a2  s. c  o m
 * 
 * @param context
 *            {@link Context}
 * @param uri
 *            {@link Uri}
 */
private void importData(final Context context, final Uri uri) {
    Log.d(TAG, "importData(ctx, " + uri + ")");
    final ProgressDialog d1 = new ProgressDialog(this);
    d1.setCancelable(true);
    d1.setMessage(this.getString(R.string.import_progr));
    d1.setIndeterminate(true);
    d1.show();

    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(final Void... params) {
            StringBuilder sb = new StringBuilder();
            try {
                final BufferedReader bufferedReader = // .
                        new BufferedReader(new InputStreamReader(// .
                                Preferences.this.getStream(Preferences.this.getContentResolver(), uri)),
                                BUFSIZE);
                String line = bufferedReader.readLine();
                while (line != null) {
                    sb.append(line);
                    sb.append("\n");
                    line = bufferedReader.readLine();
                }
            } catch (Exception e) {
                Log.e(TAG, "error in reading export: " + e.toString(), e);
                return null;
            }
            return sb.toString();
        }

        @Override
        protected void onPostExecute(final String result) {
            Log.d(TAG, "import:\n" + result);
            d1.dismiss();
            if (result == null || result.length() == 0) {
                Toast.makeText(Preferences.this, R.string.err_export_read, Toast.LENGTH_LONG).show();
                return;
            }
            String[] lines = result.split("\n");
            if (lines.length <= 2) {
                Toast.makeText(Preferences.this, R.string.err_export_read, Toast.LENGTH_LONG).show();
                return;
            }
            Builder builder = new Builder(Preferences.this);
            builder.setCancelable(true);
            builder.setTitle(R.string.import_rules_);
            builder.setMessage(Preferences.this.getString(R.string.import_rules_hint) + "\n"
                    + URLDecoder.decode(lines[1]));
            builder.setNegativeButton(android.R.string.cancel, null);
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    d1.setCancelable(false);
                    d1.setIndeterminate(true);
                    d1.show();
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(final Void... params) {
                            DataProvider.importData(Preferences.this, result);
                            return null;
                        }

                        @Override
                        protected void onPostExecute(final Void result) {
                            de.ub0r.android.callmeter.ui.Plans.reloadList();
                            d1.dismiss();
                        }
                    } // .
                            .execute((Void) null);
                }
            });
            builder.show();
        }
    } // .
            .execute((Void) null);
}

From source file:com.sxt.superqq.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CODE_SETNICK) {
            SuperQQApplication.currentUserNick = data.getStringExtra("edittext");

            progressShow = true;/* w  w w.  j a  v a2s  .  c  om*/
            final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
            pd.setCanceledOnTouchOutside(false);
            pd.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressShow = false;
                }
            });
            pd.setMessage(getString(R.string.Is_landing));
            pd.show();

            final long start = System.currentTimeMillis();
            // sdk??
            EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

                @Override
                public void onSuccess() {

                    if (!progressShow) {
                        return;
                    }
                    // ?????
                    SuperQQApplication.getInstance().setUserName(currentUsername);
                    SuperQQApplication.getInstance().setPassword(currentPassword);

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    if (!LoginActivity.this.isFinishing())
                        pd.dismiss();
                    // ?
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
                    finish();
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });

        }
    }
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Export data./*from   w ww  .j a v a  2s .  c o m*/
 * 
 * @param descr
 *            description of the exported rule set
 * @param fn
 *            one of the predefined file names from {@link DataProvider}.
 */
private void exportData(final String descr, final String fn) {
    if (descr == null) {
        final EditText et = new EditText(this);
        Builder builder = new Builder(this);
        builder.setView(et);
        builder.setCancelable(true);
        builder.setTitle(R.string.export_rules_descr);
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                Preferences.this.exportData(et.getText().toString(), fn);
            }
        });
        builder.show();
    } else {
        final ProgressDialog d = new ProgressDialog(this);
        d.setIndeterminate(true);
        d.setMessage(this.getString(R.string.export_progr));
        d.setCancelable(false);
        d.show();

        // run task in background
        final AsyncTask<Void, Void, String> task = // .
                new AsyncTask<Void, Void, String>() {
                    @Override
                    protected String doInBackground(final Void... params) {
                        if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                            return DataProvider.backupRuleSet(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                            return DataProvider.backupLogs(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                            return DataProvider.backupNumGroups(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                            return DataProvider.backupHourGroups(Preferences.this, descr);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(final String result) {
                        Log.d(TAG, "export:\n" + result);
                        System.out.println("\n" + result);
                        d.dismiss();
                        if (result != null && result.length() > 0) {
                            Uri uri = null;
                            int resChooser = -1;
                            if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                                uri = DataProvider.EXPORT_RULESET_URI;
                                resChooser = R.string.export_rules_;
                            } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                                uri = DataProvider.EXPORT_LOGS_URI;
                                resChooser = R.string.export_logs_;
                            } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_NUMGROUPS_URI;
                                resChooser = R.string.export_numgroups_;
                            } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_HOURGROUPS_URI;
                                resChooser = R.string.export_hourgroups_;
                            }
                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType(DataProvider.EXPORT_MIMETYPE);
                            intent.putExtra(Intent.EXTRA_STREAM, uri);
                            intent.putExtra(Intent.EXTRA_SUBJECT, // .
                                    "Call Meter 3G export");
                            intent.addCategory(Intent.CATEGORY_DEFAULT);

                            try {
                                final File d = Environment.getExternalStorageDirectory();
                                final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
                                f.mkdirs();
                                if (f.exists()) {
                                    f.delete();
                                }
                                f.createNewFile();
                                FileWriter fw = new FileWriter(f);
                                fw.append(result);
                                fw.close();
                                // call an exporting app with the uri to the
                                // preferences
                                Preferences.this.startActivity(
                                        Intent.createChooser(intent, Preferences.this.getString(resChooser)));
                            } catch (IOException e) {
                                Log.e(TAG, "error writing export file", e);
                                Toast.makeText(Preferences.this, R.string.err_export_write, Toast.LENGTH_LONG)
                                        .show();
                            }
                        }
                    }
                };
        task.execute((Void) null);
    }
}

From source file:net.gerosyab.dailylog.activity.MainActivity.java

private void importCategory() {
    DialogProperties properties = new DialogProperties();
    properties.selection_mode = DialogConfigs.SINGLE_MODE;
    properties.selection_type = DialogConfigs.FILE_SELECT;
    properties.root = new File(DialogConfigs.DEFAULT_DIR);
    properties.extensions = null;//from ww  w . j  av a  2s  . c o m

    dialog = new FilePickerDialog(MainActivity.this, properties);

    dialog.setDialogSelectionListener(new DialogSelectionListener() {
        @Override
        public void onSelectedFilePaths(String[] files) {

            ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.setTitle("Importing data [" + files[0] + "]");
            progressDialog.show();

            //files is the array of the paths of files selected by the Application User.
            try {
                String newCategoryUUID = UUID.randomUUID().toString();
                //                    CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(files[0]), "UTF-8"), '\t');
                CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(files[0]), "UTF-8"),
                        ',');
                String[] nextLine;
                long lineNum = 0;

                boolean dbVersionCheck = false, categoryNameCheck = false, categoryUnitCheck = false;
                boolean categoryTypeCheck = false, defaultValueCheck = false, headerCheck = false;
                boolean isCategoryNameExists = false, rowDataCheck = false, dataCheck = false;
                String dbVersion = null, categoryName = null, categoryUnit = null;
                long categoryType = -1, defaultValue = -1;

                //                    Category category = null;
                List<Record> records = new ArrayList<Record>();

                while ((nextLine = reader.readNext()) != null) {
                    // nextLine[] is an array of values from the line
                    String temp2 = "";
                    for (int i = 0; i < nextLine.length; i++) {
                        temp2 += nextLine[i] + ", ";
                    }
                    MyLog.d("opencsv", temp2);

                    if (lineNum == 0) {
                        //header
                        MyLog.d("opencsv", "nextLine.length : " + nextLine.length);
                        for (int i = 0; i < nextLine.length; i++) {
                            String[] split2 = nextLine[i].split(":");
                            MyLog.d("opencsv", "split2.length : " + split2.length);
                            MyLog.d("opencsv", "split2[0] : " + split2[0]);
                            if (split2[0].replaceAll("\\s+", "").equals("Version")) {
                                if (split2[1] != null && !split2[1].equals("")) {
                                    dbVersion = split2[1];
                                    dbVersionCheck = true;
                                }
                            } else if (split2[0].replaceAll("\\s+", "").equals("Name")) {
                                if (split2[1] != null && !split2[1].equals("")) {
                                    categoryName = split2[1];
                                    if (categoryName.length() <= Category.getMaxCategoryNameLength()) {
                                        categoryNameCheck = true;
                                    }
                                }
                            } else if (split2[0].replaceAll("\\s+", "").equals("Unit")) {
                                if (split2.length == 1) {
                                    categoryUnitCheck = true;
                                } else if (split2[1] != null && !split2[1].equals("")) {
                                    categoryUnit = split2[1];
                                    categoryUnitCheck = true;
                                }
                            } else if (split2[0].replaceAll("\\s+", "").equals("Type")) {
                                if (split2[1] != null && !split2[1].equals("")) {
                                    if (split2[1].equals("0") || split2[1].equals("1")
                                            || split2[1].equals("2")) {
                                        categoryType = Long.parseLong(split2[1]);
                                        categoryTypeCheck = true;
                                    }
                                }
                            } else if (split2[0].replaceAll("\\s+", "").equals("DefaultValue")) {
                                if (split2.length == 1) {
                                    defaultValueCheck = true;
                                } else if (split2[1] != null && !split2[1].equals("")) {
                                    if (NumberUtils.isDigits(split2[1]) && NumberUtils.isNumber(split2[1])) {
                                        defaultValue = Long.parseLong(split2[1]);
                                        MyLog.d("opencsv", "split2[1] : " + split2[1]);
                                        if (defaultValue >= 0) {
                                            defaultValueCheck = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (dbVersionCheck && categoryNameCheck && categoryTypeCheck) {
                            if (categoryType == 1) {
                                //number
                                if (categoryUnitCheck && defaultValueCheck) {
                                    headerCheck = true;
                                }
                            } else {
                                //boolean, string
                                headerCheck = true;
                            }
                        }

                        if (!headerCheck) {
                            break; //header parsing, data checking failed
                        } else if (Category.isCategoryNameExists(realm, categoryName)) {
                            isCategoryNameExists = true;
                            break;
                        } else {
                            //                                category = new Category(categoryName, categoryUnit, Category.getLastOrderNum(realm), categoryType);
                        }
                    } else {
                        //data
                        Record record;
                        rowDataCheck = true;
                        if (nextLine.length != 2) {
                            rowDataCheck = false;
                            break;
                        } else {
                            record = new Record();
                            record.setRecordType(categoryType);
                            DateTime dateTime = StaticData.fmtForBackup.parseDateTime(nextLine[0]);
                            if (dateTime != null) {
                                record.setDate(new java.sql.Date(dateTime.toDate().getTime()));
                            } else {
                                rowDataCheck = false;
                                break;
                            }

                            if (categoryType == StaticData.RECORD_TYPE_BOOLEAN) {
                                if (nextLine[1].equals("true")) {
                                    record.setBool(true);
                                } else {
                                    rowDataCheck = false;
                                    break;
                                }
                            } else if (categoryType == StaticData.RECORD_TYPE_NUMBER) {
                                if (NumberUtils.isNumber(nextLine[1]) && NumberUtils.isDigits(nextLine[1])) {
                                    long value = Long.parseLong(nextLine[1]);
                                    if (value > Category.getMaxValue()) {
                                        rowDataCheck = false;
                                        break;
                                    } else {
                                        record.setNumber(value);
                                    }
                                } else {
                                    dataCheck = false;
                                    break;
                                }

                            } else if (categoryType == StaticData.RECORD_TYPE_MEMO) {
                                String value = nextLine[1];
                                if (value.length() > Category.getMaxMemoLength()) {
                                    rowDataCheck = false;
                                    break;
                                } else {
                                    record.setString(nextLine[1]);
                                }
                            }
                        }
                        if (record != null && rowDataCheck == true) {
                            record.setCategoryId(newCategoryUUID);
                            record.setRecordId(UUID.randomUUID().toString());
                            records.add(record);
                        }
                    }
                    lineNum++;
                }

                if (!headerCheck) {
                    Toast.makeText(context, "Data file's header context/value is not correct",
                            Toast.LENGTH_LONG).show();
                } else if (isCategoryNameExists) {
                    Toast.makeText(context, "Category Name [" + categoryName + "] is already exists",
                            Toast.LENGTH_LONG).show();
                } else if (!rowDataCheck) {
                    Toast.makeText(context, "Data file's record data is not correct", Toast.LENGTH_LONG).show();
                } else {
                    long newOrder = Category.getNewOrderNum(realm);
                    realm.beginTransaction();
                    Category category = realm.createObject(Category.class, newCategoryUUID);
                    category.setName(categoryName);
                    category.setUnit(categoryUnit);
                    category.setOrder(newOrder);
                    category.setRecordType(categoryType);
                    realm.insert(category);
                    realm.insertOrUpdate(records);
                    realm.commitTransaction();
                    Toast.makeText(context, "Data import [ " + categoryName + " ] is completed!!",
                            Toast.LENGTH_LONG).show();
                    //                        refreshList();
                    //                        categoryHolderList.add(getHolderFromCategory(category));
                    //                        mDragListView.getAdapter().notifyDataSetChanged();
                    //                        mDragListView.getAdapter().notifyItemInserted((int) newOrder);
                    //                        setCategoryHolderList();
                    //                        mDragListView.getAdapter().setItemList(categoryHolderList);
                    adapter.notifyDataSetChanged();
                }
            } catch (FileNotFoundException e) {
                Toast.makeText(context, "Selected file is not found", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            } catch (IOException e) {
                Toast.makeText(context, "File I/O exception occured", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            } finally {
                progressDialog.dismiss();
            }
        }
    });

    dialog.show();
}

From source file:com.carlrice.reader.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from  w ww .ja va 2s .  co  m*/
        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;
    }
    case R.id.menu_search_feed: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
        final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
        if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME)
                && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) {
            searchText.setText(mUrlEditText.getText());
        }
        final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

        new AlertDialog.Builder(EditFeedActivity.this) //
                .setIcon(R.drawable.action_search) //
                .setTitle(R.string.feed_search) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (searchText.getText().length() > 0) {
                            String tmp = searchText.getText().toString();
                            try {
                                tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }
                            final String text = tmp;

                            switch (radioGroup.getCheckedRadioButtonId()) {
                            case R.id.byWebSearch:
                                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) {
                                                return new GetFeedSearchResultsLoader(EditFeedActivity.this,
                                                        text);
                                            }

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

                                                if (data == null) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.error,
                                                            Toast.LENGTH_SHORT).show();
                                                } else if (data.isEmpty()) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.no_result,
                                                            Toast.LENGTH_SHORT).show();
                                                } 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) {
                                                                    mNameEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_TITLE));
                                                                    mUrlEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_URL));
                                                                }
                                                            });
                                                    builder.show();
                                                }
                                            }

                                            @Override
                                            public void onLoaderReset(
                                                    Loader<ArrayList<HashMap<String, String>>> loader) {
                                            }
                                        });
                                break;

                            case R.id.byTopic:
                                mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                        + "&start=1&length=10&l=en&src=news&f=rss");
                                break;

                            case R.id.byYoutube:
                                mUrlEditText.setText("http://www.youtube.com/rss/user/"
                                        + text.replaceAll("\\+", "") + "/videos.rss");
                                break;
                            }
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.app.uafeed.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();//from   ww  w.j  a v  a 2s  .c o  m
        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());

                            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;
    }
    case R.id.menu_search_feed: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
        final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
        if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME)
                && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) {
            searchText.setText(mUrlEditText.getText());
        }
        final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

        new AlertDialog.Builder(EditFeedActivity.this) //
                .setIcon(R.drawable.action_search) //
                .setTitle(R.string.feed_search) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (searchText.getText().length() > 0) {
                            String tmp = searchText.getText().toString();
                            try {
                                tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }
                            final String text = tmp;

                            switch (radioGroup.getCheckedRadioButtonId()) {
                            case R.id.byWebSearch:
                                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) {
                                                return new GetFeedSearchResultsLoader(EditFeedActivity.this,
                                                        text);
                                            }

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

                                                if (data == null) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.error,
                                                            Toast.LENGTH_SHORT).show();
                                                } else if (data.isEmpty()) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.no_result,
                                                            Toast.LENGTH_SHORT).show();
                                                } 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) {
                                                                    mNameEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_TITLE));
                                                                    mUrlEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_URL));
                                                                }
                                                            });
                                                    builder.show();
                                                }
                                            }

                                            @Override
                                            public void onLoaderReset(
                                                    Loader<ArrayList<HashMap<String, String>>> loader) {
                                            }
                                        });
                                break;

                            case R.id.byTopic:
                                mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                        + "&start=1&length=10&l=en&src=news&f=rss");
                                break;

                            case R.id.byYoutube:
                                mUrlEditText.setText("http://www.youtube.com/rss/user/"
                                        + text.replaceAll("\\+", "") + "/videos.rss");
                                break;
                            }
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.sxt.superqq.activity.LoginActivity.java

/**
 * ?//from  w ww.j a va  2s . com
 */
private void setLoginClickListener() {
    findViewById(R.id.btnLogin).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!CommonUtils.isNetWorkConnected(LoginActivity.this)) {
                Toast.makeText(LoginActivity.this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
                return;
            }
            currentUsername = usernameEditText.getText().toString().trim();
            currentPassword = passwordEditText.getText().toString().trim();

            /*
             * ????
             */
            if (TextUtils.isEmpty(currentUsername)) {
                Toast.makeText(LoginActivity.this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            if (TextUtils.isEmpty(currentPassword)) {
                Toast.makeText(LoginActivity.this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            //?
            progressShow = true;
            final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
            pd.setCanceledOnTouchOutside(false);
            pd.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressShow = false;
                }
            });
            pd.setMessage(getString(R.string.Is_landing));
            pd.show();

            final long start = System.currentTimeMillis();
            // sdk??
            EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {
                @Override
                public void onSuccess() {

                    if (!progressShow) {
                        return;
                    }

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {

                        //?
                        boolean isSuccess = loginAppServer(currentUsername, currentPassword);
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, "", 2000).show();
                                    return;
                                }
                            });
                        }
                        final String userName = SuperQQApplication.getInstance().getUserName();
                        //?
                        isSuccess = NetUtils.downloadAvatar(LoginActivity.this, userName);

                        if (SuperQQApplication.getInstance().getContacts().size() == 0) {
                            //,20userName??
                            new DownloadContactsTask(LoginActivity.this, userName, 0, 20)
                                    .execute(I.SERVER_ROOT);
                        }
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, userName + "?", 3000)
                                            .show();
                                }
                            });
                        }
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    if (!LoginActivity.this.isFinishing())
                        pd.dismiss();
                    // ?
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
                    finish();
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
            //                Intent intent = new Intent(LoginActivity.this, com.sxt.superqq.activity.AlertDialogActivity.class);
            //                intent.putExtra("editTextShow", true);
            //                intent.putExtra("titleIsCancel", true);
            //                intent.putExtra("msg", getResources().getString(R.string.please_set_the_current));
            //                intent.putExtra("edit_text", currentUsername);
            //                startActivityForResult(intent, REQUEST_CODE_SETNICK);
        }
    });
}

From source file:com.example.prasadnr.traquad.TraQuad.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tra_quad);
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    Builder alert = new AlertDialog.Builder(TraQuad.this);

    WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = managerWifi.getClass().getDeclaredMethods();
    for (Method method : wmMethods) {
        if (method.getName().equals("isWifiApEnabled")) {

            try {
                isWifiAPenabled = (boolean) method.invoke(managerWifi);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();//w w  w .  j ava2  s  . co m
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    final ProgressDialog pDialog;
    MediaController mediaController = new MediaController(this);

    pDialog = new ProgressDialog(TraQuad.this);
    pDialog.setTitle("TraQuad app (Connecting...)");
    pDialog.setMessage("Buffering...Please wait...");
    pDialog.setCancelable(true);

    if (!isWifiAPenabled) {

        alert.setTitle("WiFi Hotspot Settings");
        alert.setMessage("Can you please connect WiFi-hotspot?");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                irritation = true;
                startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                pDialog.show();
            }
        });
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //Dismiss AlertDialog
                pDialog.show();
                Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show();
            }
        });
        alert.setCancelable(false);
        AlertDialog alertDialog = alert.create();
        alertDialog.show();
    }

    WebView webView = (WebView) findViewById(R.id.webView);

    if (irritation == true | isWifiAPenabled) {
        pDialog.show();
    }

    mediaController.setAnchorView(webView);
    mediaController.setVisibility(View.GONE);

    extra = getIntent().getStringExtra("VideosId");
    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    final String IPaddressNew = globalVariable.getIP();
    final String httpString = "http://";
    final String commandPort = String.valueOf(1500);
    final String streamPort = String.valueOf(8080);
    final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort;
    final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort;
    TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter);

    try {
        webView.loadUrl(IPaddressStream);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show();
    }

    webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            pDialog.dismiss();
        }
    });

    final Button switchact = (Button) findViewById(R.id.btn2);
    switchact.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent act1 = new Intent(view.getContext(), Joypad.class);
            startActivity(act1);

        }
    });

    final Button hometraquad = (Button) findViewById(R.id.button5);

    hometraquad.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class);
            startActivity(acthometraquad);
        }
    });

}