List of usage examples for android.app Dialog setTitle
public void setTitle(@StringRes int titleId)
From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java
@Nullable @Override// ww w . ja v a 2 s. c om public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false); databaseHandler = new DatabaseHandler(getContext()); sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view); emptyTV = (TextView) root.findViewById(R.id.empty); arrow = (ImageView) root.findViewById(R.id.arrow); setRecyclerViewAdapter(); FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab); addPurchaseFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); List<String> nseList = ShareUtils.getNseList(getContext()); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, nseList); name.setAdapter(arrayAdapter); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); if (shares.size() == 0) existingRB.setVisibility(View.GONE); (newRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } }); (existingRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(this); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Share share = new Share(); share.setId(databaseHandler.getNextKey("share")); share.setPurchases(new RealmList<Purchase>()); Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); if (newRB.isChecked()) { String sName = name.getText().toString().trim(); if (sName.equals("")) { Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show(); return; } else { share.setName(sName); purchase.setName(sName); } } String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); share.setDateOfInitialPurchase(date); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.buying_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("buy"); if (newRB.isChecked()) { if (!databaseHandler.addShare(share, purchase)) { Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show(); return; } } else { purchase.setName(spinner.getSelectedItem().toString()); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); } setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }
From source file:com.pericstudio.drawit.activities.DashboardMainActivity.java
/** * Sets up the toolbar and the FAB.// w w w. jav a 2 s.c om */ private void setUpToolbar() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { TextView tvName; TextView tvDes; @Override public void onClick(View view) { final Dialog testDialog = new Dialog(DashboardMainActivity.this); testDialog.setTitle("TEST TITLE!"); testDialog.setContentView(R.layout.dialog_test); tvName = (TextView) testDialog.findViewById(R.id.et_dialog_name); tvDes = (TextView) testDialog.findViewById(R.id.et_dialog_desciption); Button button = (Button) testDialog.findViewById(R.id.dialog_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String tvNameContent = tvName.getText().toString().trim(); final String tvDesContent = tvDes.getText().toString().trim(); final Drawing drawing = new Drawing(tvNameContent, tvDesContent); drawing.save(getApplicationContext(), new Response.Listener<ObjectModificationResponse>() { @Override public void onResponse(ObjectModificationResponse modificationResponse) { //code List<String> idList = modificationResponse.getCreatedObjectIds(); final String drawingID = idList.get(0); LocallySavableCMObject.searchObjects(getApplicationContext(), SearchQuery.filter("ownerID").equal(MyApplication.userID).searchQuery(), new Response.Listener<CMObjectResponse>() { @Override public void onResponse(CMObjectResponse response) { List<CMObject> userObject = response.getObjects(); UserObjectIDs ids = (UserObjectIDs) userObject.get(0); ids.addInProgress(drawingID); MyApplication.setUserDataObject(ids); ids.save(); T.showShortDebug(getApplicationContext(), "Refresh for update"); testDialog.dismiss(); } }); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { //code } }); } }); testDialog.show(); } }); }
From source file:com.orange.datavenue.DatasourceListFragment.java
/** * *//* w w w.jav a 2 s . co m*/ private void deleteDatasource() { final android.app.Dialog dialog = new android.app.Dialog(getActivity()); dialog.setContentView(R.layout.delete_dialog); dialog.setTitle(R.string.delete); TextView info = (TextView) dialog.findViewById(R.id.info_label); info.setText( String.format(getString(R.string.delete_datasource), Model.instance.currentDatasource.getId())); Button deleteButton = (Button) dialog.findViewById(R.id.delete_button); deleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId()); DeleteDatasourceOperation deleteDatasourceOperation = new DeleteDatasourceOperation( Model.instance.oapiKey, Model.instance.key, Model.instance.currentDatasource, new OperationCallback() { @Override public void process(Object object, Exception exception) { if (exception == null) { getDatasources(); // reload } else { Errors.displayError(getActivity(), exception); } } }); deleteDatasourceOperation.execute(""); dialog.dismiss(); } }); Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button); cancelDeleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.setCancelable(false); dialog.show(); }
From source file:us.cboyd.android.dicom.DcmBrowser.java
/** onMenuItemSelected handles if something from the options menu is selected */ @Override//www. jav a2 s . c o m public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case R.id.app_about: Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_about); dialog.setTitle(getResources().getString(R.string.app_name)); dialog.show(); return true; case R.id.show_hidden: item.setChecked(!item.isChecked()); mListFragment.setHidden(item.isChecked()); return true; case R.id.show_info: item.setChecked(!item.isChecked()); mInfoFragment.refreshTagList(item.isChecked()); return true; case R.id.debug_mode: item.setChecked(!item.isChecked()); mInfoFragment.changeMode(item.isChecked()); return true; default: return super.onMenuItemSelected(featureId, item); } }
From source file:org.dvbviewer.controller.ui.fragments.StreamConfig.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dia = super.onCreateDialog(savedInstanceState); dia.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dia.setTitle(R.string.streamConfig); return dia;/* w ww .j a v a2 s . c o m*/ }
From source file:com.androzic.track.TrackSave.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.act_save, container); filename = (TextView) rootView.findViewById(R.id.filename_text); if (track.filepath != null) { File file = new File(track.filepath); filename.setText(file.getName()); } else {/* w w w . j a va2s .c o m*/ filename.setText(FileUtils.sanitizeFilename(track.name) + ".plt"); } final Dialog dialog = getDialog(); Button cancelButton = (Button) rootView.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); Button saveButton = (Button) rootView.findViewById(R.id.save_button); saveButton.setOnClickListener(saveOnClickListener); dialog.setTitle(R.string.savetrack_name); dialog.setCanceledOnTouchOutside(false); return rootView; }
From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_NEW_PAPER: final Dialog newPaper = new Dialog(this); newPaper.setTitle(R.string.new_paper_dialog_title); newPaper.setContentView(R.layout.new_paper_dialog); newPaper.setCancelable(true);// w w w.jav a 2 s .c om final EditText painterName = (EditText) newPaper.findViewById(R.id.painter_name_input_text); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/schoolbell.ttf"); painterName.setTypeface(tf); final Gallery colors = (Gallery) newPaper.findViewById(R.id.colors_list); colors.setAdapter(new PaperColorListAdapter(getApplicationContext())); colors.setOnItemSelectedListener(new OnItemSelectedListener() { private View mSelectedItem = null; @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); mSelectedItem = v; if (mSelectedItem != null) mSelectedItem.setBackgroundResource(R.drawable.selected_color_background); } @Override public void onNothingSelected(AdapterView<?> arg0) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); } }); colors.setSelection(2); View createButton = newPaper.findViewById(R.id.new_paper_create_button); createButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Editor e = sp.edit(); final CharSequence painterNameFromUI = painterName.getText().toString(); final String newPainterName = TextUtils.isEmpty(painterNameFromUI) ? getString(R.string.settings_key_painter_name_default_value) : painterNameFromUI.toString(); e.putString(getString(R.string.settings_key_painter_name), newPainterName); e.commit(); PaperBackground paper = (PaperBackground) colors.getSelectedItem(); newPaper.dismiss(); createNewPaper(paper); } }); View cancelButton = newPaper.findViewById(R.id.new_paper_cancel_button); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { newPaper.dismiss(); if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); newPaper.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); return newPaper; default: return super.onCreateDialog(id); } }
From source file:com.android.nobadgift.DashboardActivity.java
private void displayConfirmationDialog() { try {/*from www. j av a2 s.c o m*/ Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Successfully Scanned!"); dialog.setCanceledOnTouchOutside(true); dialog.setCancelable(true); dialog.setOnDismissListener(new OnDismissListener() { public void onDismiss(DialogInterface dialog) { displayInfoDialog(); } }); TextView text = (TextView) dialog.findViewById(R.id.dialogText); text.setText("\"" + itemName + "\""); ImageView image = (ImageView) dialog.findViewById(R.id.dialogImage); image.setImageBitmap(retrievedImage); dialog.show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.orange.datavenue.DatasourceListFragment.java
private void createDatasource() { final android.app.Dialog dialog = new android.app.Dialog(getActivity()); dialog.setContentView(R.layout.create_datasource_dialog); dialog.setTitle(R.string.add_datasource); final LinearLayout callbackLayout = (LinearLayout) dialog.findViewById(R.id.callback_layout); final EditText name = (EditText) dialog.findViewById(R.id.name); final EditText description = (EditText) dialog.findViewById(R.id.description); final EditText serial = (EditText) dialog.findViewById(R.id.serial); final EditText callback = (EditText) dialog.findViewById(R.id.callback); final CheckBox status = (CheckBox) dialog.findViewById(R.id.status); status.setChecked(true); // by default status is activated Button actionButton = (Button) dialog.findViewById(R.id.add_button); actionButton.setOnClickListener(new View.OnClickListener() { @Override// w w w . j av a 2s . c o m public void onClick(View view) { Log.d(TAG_NAME, "name : " + name.getText().toString()); Log.d(TAG_NAME, "description : " + description.getText().toString()); Log.d(TAG_NAME, "serial : " + serial.getText().toString()); Log.d(TAG_NAME, "status : " + status.isChecked()); Datasource newDatasource = new Datasource(); newDatasource.setName(name.getText().toString()); newDatasource.setDescription(description.getText().toString()); newDatasource.setSerial(serial.getText().toString()); String callbackUrl = callback.getText().toString(); if ("".equals(callbackUrl)) { newDatasource.setCallback(null); } else { try { URL url = new URL(callbackUrl); Callback newCallback = new Callback(); newCallback.setUrl(url.toString()); newCallback.setStatus("activated"); newCallback.setName("Callback"); newCallback.setDescription("application callback"); newDatasource.setCallback(newCallback); } catch (MalformedURLException e) { Log.e(TAG_NAME, e.toString()); newDatasource.setCallback(null); callback.setText(""); } } if (status.isChecked()) { newDatasource.setStatus("activated"); } else { newDatasource.setStatus("deactivated"); } CreateDatasourceOperation createDatasourceOperation = new CreateDatasourceOperation( Model.instance.oapiKey, Model.instance.key, newDatasource, new OperationCallback() { @Override public void process(Object object, Exception exception) { if (exception == null) { getDatasources(); } else { Errors.displayError(getActivity(), exception); } } }); createDatasourceOperation.execute(""); dialog.dismiss(); } }); Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.setCancelable(false); dialog.show(); }
From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java
@Override public void handle(final Activity activity, final CancellableTask task, final Callback callback) { try {//from ww w. j a va 2s .co m final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName)) .getHttpClient(); final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : ""); String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) }; String htmlChallenge; if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) { htmlChallenge = lastChallenge.getRight(); } else { htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task, false); } lastChallenge = null; Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge); if (challengeMatcher.find()) { final String challenge = challengeMatcher.group(1); HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl( scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task); try { InputStream imageStream = responseModel.stream; final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream); final String message; Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>") .matcher(htmlChallenge); if (messageMatcher.find()) message = RegexUtils.removeHtmlTags(messageMatcher.group(1)); else message = null; final Bitmap candidateBitmap; Matcher candidateMatcher = Pattern .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"") .matcher(htmlChallenge); if (candidateMatcher.find()) { Bitmap bmp = null; try { byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); } catch (Exception e) { } candidateBitmap = bmp; } else candidateBitmap = null; activity.runOnUiThread(new Runnable() { final int maxX = 3; final int maxY = 3; final boolean[] isSelected = new boolean[maxX * maxY]; @SuppressLint("InlinedApi") @Override public void run() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setOrientation(LinearLayout.VERTICAL); if (candidateBitmap != null) { ImageView candidateView = new ImageView(activity); candidateView.setImageBitmap(candidateBitmap); int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50 + 0.5f); candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize)); candidateView.setScaleType(ImageView.ScaleType.FIT_XY); rootLayout.addView(candidateView); } if (message != null) { TextView textView = new TextView(activity); textView.setText(message); CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance); textView.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); rootLayout.addView(textView); } FrameLayout frame = new FrameLayout(activity); frame.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(challengeBitmap); frame.addView(imageView); final LinearLayout selector = new LinearLayout(activity); selector.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); AppearanceUtils.callWhenLoaded(imageView, new Runnable() { @Override public void run() { selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(), imageView.getHeight())); } }); selector.setOrientation(LinearLayout.VERTICAL); selector.setWeightSum(maxY); for (int y = 0; y < maxY; ++y) { LinearLayout subSelector = new LinearLayout(activity); subSelector.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); subSelector.setOrientation(LinearLayout.HORIZONTAL); subSelector.setWeightSum(maxX); for (int x = 0; x < maxX; ++x) { FrameLayout switcher = new FrameLayout(activity); switcher.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); switcher.setTag(new int[] { x, y }); switcher.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int[] coord = (int[]) v.getTag(); int index = coord[1] * maxX + coord[0]; isSelected[index] = !isSelected[index]; v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0) : Color.TRANSPARENT); } }); subSelector.addView(switcher); } selector.addView(subSelector); } frame.addView(selector); rootLayout.addView(frame); Button checkButton = new Button(activity); checkButton.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); checkButton.setText(android.R.string.ok); rootLayout.addView(checkButton); ScrollView dlgView = new ScrollView(activity); dlgView.addView(rootLayout); final Dialog dialog = new Dialog(activity); dialog.setTitle("Recaptcha"); dialog.setContentView(dlgView); dialog.setCanceledOnTouchOutside(false); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!task.isCancelled()) { callback.onError("Cancelled"); } } }); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dialog.show(); checkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (task.isCancelled()) return; Async.runAsync(new Runnable() { @Override public void run() { try { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("c", challenge)); for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) pairs.add(new BasicNameValuePair("response", Integer.toString(i))); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")) .setCustomHeaders(new Header[] { new BasicHeader(HttpHeaders.REFERER, usingURL) }) .build(); String response = HttpStreamer.getInstance().getStringFromUrl( usingURL, request, httpClient, null, task, false); String hash = ""; Matcher matcher = Pattern.compile( "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<", Pattern.DOTALL).matcher(response); if (matcher.find()) hash = matcher.group(1); if (hash.length() > 0) { Recaptcha2solved.push(publicKey, hash); activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } else { lastChallenge = Pair.of(usingURL, response); throw new RecaptchaException( "incorrect answer (hash is empty)"); } } catch (final Exception e) { Logger.e(TAG, e); if (task.isCancelled()) return; handle(activity, task, callback); } } }); } }); } }); } finally { responseModel.release(); } } else throw new Exception("can't parse recaptcha challenge answer"); } catch (final Exception e) { Logger.e(TAG, e); if (!task.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(e.getMessage() != null ? e.getMessage() : e.toString()); } }); } } }