List of usage examples for android.text Html fromHtml
@Deprecated public static Spanned fromHtml(String source)
From source file:com.liato.bankdroid.banking.banks.ICABanken.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }// w w w . j a v a2 s . c o m urlopen = login(); String response = null; Matcher matcher; try { response = urlopen.open("https://mobil2.icabanken.se/account/overview.aspx"); //response = urlopen.open("http://x.x00.us/android/bankdroid/icabanken_oversikt.htm"); matcher = reBalanceSald.matcher(response); while (matcher.find()) { accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3).trim()), matcher.group(1).trim())); balance = balance.add(Helpers.parseBalance(matcher.group(3))); } matcher = reBalanceDisp.matcher(response); while (matcher.find()) { accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3).trim()), matcher.group(1).trim())); balance = balance.add(Helpers.parseBalance(matcher.group(3))); } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } }
From source file:com.blueoxfords.peacecorpstinder.activities.MainActivity.java
public void getLegalInfo(View v) { String photoId = v.getTag() + ""; ImageRestClient.get().getInfoFromImageId(photoId, new Callback<ImageService.ImageInfoWrapper>() { @Override// w w w .ja va2 s. c o m public void success(ImageService.ImageInfoWrapper imageInfoWrapper, Response response) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity); ScrollView wrapper = new ScrollView(MainActivity.activity); LinearLayout infoLayout = new LinearLayout(MainActivity.activity); infoLayout.setOrientation(LinearLayout.VERTICAL); infoLayout.setPadding(35, 35, 35, 35); TextView imageOwner = new TextView(MainActivity.activity); imageOwner.setText(Html.fromHtml("<b>Image By: </b>" + imageInfoWrapper.photo.owner.username)); if (imageInfoWrapper.photo.owner.realname.length() > 0) { imageOwner.setText(imageOwner.getText() + " (" + imageInfoWrapper.photo.owner.realname + ")"); } infoLayout.addView(imageOwner); if (getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)).length() > 0) { TextView licenseLink = new TextView(MainActivity.activity); licenseLink.setText(Html .fromHtml("<a href=\"" + getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)) + "\"><b>Licensing</b></a>")); licenseLink.setMovementMethod(LinkMovementMethod.getInstance()); infoLayout.addView(licenseLink); } if (imageInfoWrapper.photo.urls.url.size() > 0) { TextView imageLink = new TextView(MainActivity.activity); imageLink.setText(Html.fromHtml("<a href=\"" + imageInfoWrapper.photo.urls.url.get(0)._content + "\"><b>Image Link</b></a>")); imageLink.setMovementMethod(LinkMovementMethod.getInstance()); infoLayout.addView(imageLink); } if (imageInfoWrapper.photo.title._content.length() > 0) { TextView photoTitle = new TextView(MainActivity.activity); photoTitle .setText(Html.fromHtml("<b>Image Title: </b>" + imageInfoWrapper.photo.title._content)); infoLayout.addView(photoTitle); } if (imageInfoWrapper.photo.description._content.length() > 0) { TextView description = new TextView(MainActivity.activity); description.setText(Html .fromHtml("<b>Image Description: </b>" + imageInfoWrapper.photo.description._content)); infoLayout.addView(description); } TextView contact = new TextView(MainActivity.activity); contact.setText( Html.fromHtml("<br><i>To remove this photo, please email pcorpsconnect@gmail.com</i>")); infoLayout.addView(contact); wrapper.addView(infoLayout); builder.setTitle("Photo Information"); builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); builder.setView(wrapper); builder.create().show(); } @Override public void failure(RetrofitError error) { Log.i("testing", "could not retrieve legal/attribution info"); } }); }
From source file:com.adrup.saldo.bank.icabanken.IcabankenManager.java
@Override public Map<AccountHashKey, RemoteAccount> getAccounts(Map<AccountHashKey, RemoteAccount> accounts) throws BankException { Log.d(TAG, "getAccounts()"); HttpClient httpClient = new SaldoHttpClient(mContext); try {// w w w . ja v a 2 s . c o m // get login page Log.d(TAG, "getting login page"); String res = HttpHelper.get(httpClient, LOGIN_URL); Matcher matcher = Pattern.compile(VIEWSTATE_REGEX).matcher(res); if (!matcher.find()) { Log.e(TAG, "No viewstate match."); Log.d(TAG, res); throw new IcabankenException("No viewState match."); } String viewState = matcher.group(1); Log.d(TAG, "viewState= " + viewState); matcher = Pattern.compile(EVENTVALIDATION_REGEX).matcher(res); if (!matcher.find()) { Log.e(TAG, "No evenValidation match."); Log.d(TAG, res); throw new IcabankenException("No evenValidation match."); } String evenValidation = matcher.group(1); Log.d(TAG, "evenValidation= " + evenValidation); // do login post, should redirect us to the accounts page List<NameValuePair> parameters = new ArrayList<NameValuePair>(3); parameters.add(new BasicNameValuePair(VIEWSTATE_PARAM, viewState)); parameters.add(new BasicNameValuePair(EVENTVALIDATION_PARAM, evenValidation)); parameters.add(new BasicNameValuePair(USER_PARAM, mBankLogin.getUsername())); parameters.add(new BasicNameValuePair(PASS_PARAM, mBankLogin.getPassword())); parameters.add(new BasicNameValuePair(BUTTON_PARAM, "Logga in")); res = HttpHelper.post(httpClient, LOGIN_URL, parameters); if (res.contains("class=\"error\"")) { Log.d(TAG, "auth fail"); throw new AuthenticationException("auth fail"); } // get and extract account info res = HttpHelper.get(httpClient, ACCOUNT_URL); matcher = Pattern.compile(ACCOUNTS_REGEX).matcher(res); int remoteId = 1; int count = 0; while (matcher.find()) { count++; int ordinal = remoteId; String name = Html.fromHtml(matcher.group(2)).toString().trim(); long balance = Long.parseLong(matcher.group(3).replaceAll("\\,|\\.| ", "")) / 100; accounts.put(new AccountHashKey(String.valueOf(remoteId), mBankLogin.getId()), new Account(String.valueOf(remoteId), mBankLogin.getId(), ordinal, name, balance)); remoteId++; } matcher = Pattern.compile(ACCOUNTSDISP_REGEX).matcher(res); while (matcher.find()) { count++; int ordinal = remoteId; String name = Html.fromHtml(matcher.group(2)).toString().trim(); long balance = Long.parseLong(matcher.group(3).replaceAll("\\,|\\.| ", "")) / 100; accounts.put(new AccountHashKey(String.valueOf(remoteId), mBankLogin.getId()), new Account(String.valueOf(remoteId), mBankLogin.getId(), ordinal, name, balance)); remoteId++; } if (count == 0) { Log.d(TAG, "no accounts added"); Log.d(TAG, res); } } catch (IOException e) { Log.e(TAG, e.getMessage(), e); throw new IcabankenException(e.getMessage(), e); } catch (HttpException e) { Log.e(TAG, e.getMessage(), e); throw new IcabankenException(e.getMessage(), e); } finally { httpClient.getConnectionManager().shutdown(); } return accounts; }
From source file:com.armtimes.activities.SingleArticlePreviewActivity.java
private void initActionBarTitle(final Intent intent, final ActionBar actionBar) { int title = R.string.app_name; try {// w w w .j a v a 2 s.c o m title = intent.getIntExtra(EXTRA_CATEGORY_TITLE_ID, 0); } finally { actionBar.setTitle(Html.fromHtml("<small>" + getResources().getString(title) + "</small>")); actionBar.setBackgroundDrawable(new ColorDrawable(0xFFFA294C)); } }
From source file:net.olejon.mdapp.InteractionsCardsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();/*ww w. java 2 s.c o m*/ return; } // Intent final Intent intent = getIntent(); searchString = intent.getStringExtra("search"); // Layout setContentView(R.layout.activity_interactions_cards); // Toolbar mToolbar = (Toolbar) findViewById(R.id.interactions_cards_toolbar); mToolbar.setTitle(getString(R.string.interactions_cards_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.interactions_cards_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.interactions_cards_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.interactions_cards_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new InteractionsCardsAdapter(mContext, mProgressBar, new JSONArray())); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // No interactions mNoInteractionsLayout = (LinearLayout) findViewById(R.id.interactions_cards_no_interactions); Button noInteractionsButton = (Button) findViewById(R.id.interactions_cards_no_interactions_button); noInteractionsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.interactions_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "http://interaksjoner.no/analyser.asp?PreparatNavn=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&submit1=Sjekk"); mContext.startActivity(intent); } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } } }); // Search search(searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put(InteractionsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new InteractionsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(InteractionsSQLiteHelper.TABLE, InteractionsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(InteractionsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle(getString(R.string.interactions_cards_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); mNoInteractionsLayout.setVisibility(View.GONE); mSwipeRefreshLayout.setVisibility(View.VISIBLE); search(correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("InteractionsCards", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } }
From source file:ai.api.sample.AIDialogSampleActivity.java
@Override public void onResult(final AIResponse response) { runOnUiThread(new Runnable() { @Override//from w w w. j a v a 2 s . c om public void run() { Log.d(TAG, "onResult"); resultTextView.setText(gson.toJson(response)); Log.i(TAG, gson.toJson(response)); Log.i(TAG, "Received success response"); // this is example how to get different parts of result object final Status status = response.getStatus(); Log.i(TAG, "Status code: " + status.getCode()); Log.i(TAG, "Status type: " + status.getErrorType()); final Result result = response.getResult(); Log.i(TAG, "Resolved query: " + result.getResolvedQuery()); Log.i(TAG, "Action: " + result.getAction()); final String speech = result.getFulfillment().getSpeech(); Log.i(TAG, "Speech: " + speech); dialogue = dialogue + "\n\n" + Html.fromHtml("<b>User : </b>") + "\n" + result.getResolvedQuery() + "\n" + Html.fromHtml("<b>Speakbuy : </b>") + "\n" + speech; resultTextView.setText(dialogue); TTS.speak(speech); final Metadata metadata = result.getMetadata(); if (metadata != null) { Log.i(TAG, "Intent id: " + metadata.getIntentId()); Log.i(TAG, "Intent name: " + metadata.getIntentName()); } if (result.getAction().equalsIgnoreCase("app.fuking.close")) { //do exit here aiDialog.getAIService().stopListening(); AIDialogSampleActivity.this.finish(); } laptop(result); forMobile(result); forTablet(result); /*final HashMap<String, JsonElement> params = result.getParameters(); if (params != null && !params.isEmpty()) { Log.i(TAG, "Parameters: "); for (final Map.Entry<String, JsonElement> entry : params.entrySet()) { Log.i(TAG, String.format("%s: %s", entry.getKey(), entry.getValue().toString())); } }*/ if (!isDialogEnd) { handler.postDelayed(new Runnable() { @Override public void run() { waitforTTStostop(); } }, 0500); } else { handler.postDelayed(new Runnable() { @Override public void run() { waitforTTStostop(); } }, 3000); } //run ending here } }); }
From source file:net.olejon.mdapp.ClinicalTrialsCardsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();//from www .j a v a 2 s .c o m return; } // Intent final Intent intent = getIntent(); searchString = intent.getStringExtra("search"); // Layout setContentView(R.layout.activity_clinicaltrials_cards); // Toolbar mToolbar = (Toolbar) findViewById(R.id.clinicaltrials_cards_toolbar); mToolbar.setTitle(getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.clinicaltrials_cards_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.clinicaltrials_cards_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.clinicaltrials_cards_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new ClinicalTrialsCardsAdapter(mContext, new JSONArray())); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // No clinical trials mNoClinicalTrialsLayout = (LinearLayout) findViewById(R.id.clinicaltrials_cards_no_clinicaltrials); Button noClinicalTrialsButton = (Button) findViewById(R.id.clinicaltrials_cards_no_results_button); noClinicalTrialsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "https://clinicaltrials.gov/ct2/results?term=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&no_unk=Y"); mContext.startActivity(intent); } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } } }); // Search search(searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put(ClinicalTrialsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new ClinicalTrialsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(ClinicalTrialsSQLiteHelper.TABLE, ClinicalTrialsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(ClinicalTrialsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle( getString(R.string.clinicaltrials_cards_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); mNoClinicalTrialsLayout.setVisibility(View.GONE); mSwipeRefreshLayout.setVisibility(View.VISIBLE); search(correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("ClinicalTrialsCards", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("ClinicalTrialsCards", Log.getStackTraceString(e)); } }
From source file:com.starwood.anglerslong.LicenseActivity.java
private void createTextView() { if (isCreateTextViewSet) return;/*from ww w . j a va2 s . c om*/ // Get the linear layout and set the parameters LinearLayout ll = (LinearLayout) findViewById(R.id.profile_ll); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; TextView createLicense = new TextView(this); createLicense.setId(0); createLicense.setText(Html.fromHtml(getResources().getString(R.string.create_license_string))); createLicense.setPadding(70, 100, 70, 100); createLicense.setTextSize(18); ll.addView(createLicense, params); isCreateTextViewSet = true; }
From source file:cgeo.geocaching.connector.gc.GCParser.java
private static SearchResult parseSearch(final String url, final String pageContent, final boolean showCaptcha, final RecaptchaReceiver recaptchaReceiver) { if (StringUtils.isBlank(pageContent)) { Log.e("GCParser.parseSearch: No page given"); return null; }/*from ww w .j av a2 s . c o m*/ final List<String> cids = new ArrayList<String>(); String page = pageContent; final SearchResult searchResult = new SearchResult(); searchResult.setUrl(url); searchResult.viewstates = GCLogin.getViewstates(page); // recaptcha if (showCaptcha) { final String recaptchaJsParam = TextUtils.getMatch(page, GCConstants.PATTERN_SEARCH_RECAPTCHA, false, null); if (recaptchaJsParam != null) { recaptchaReceiver.setKey(recaptchaJsParam.trim()); recaptchaReceiver.fetchChallenge(); } if (recaptchaReceiver != null && StringUtils.isNotBlank(recaptchaReceiver.getChallenge())) { recaptchaReceiver.notifyNeed(); } } if (!page.contains("SearchResultsTable")) { // there are no results. aborting here avoids a wrong error log in the next parsing step return searchResult; } int startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\""); if (startPos == -1) { Log.e("GCParser.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page"); return null; } page = page.substring(startPos); // cut on <table startPos = page.indexOf('>'); final int endPos = page.indexOf("ctl00_ContentBody_UnitTxt"); if (startPos == -1 || endPos == -1) { Log.e("GCParser.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page"); return null; } page = page.substring(startPos + 1, endPos - startPos + 1); // cut between <table> and </table> final String[] rows = page.split("<tr class="); final int rows_count = rows.length; int excludedCaches = 0; final ArrayList<Geocache> caches = new ArrayList<Geocache>(); for (int z = 1; z < rows_count; z++) { final Geocache cache = new Geocache(); final String row = rows[z]; // check for cache type presence if (!row.contains("images/wpttypes")) { continue; } try { final MatcherWrapper matcherGuidAndDisabled = new MatcherWrapper( GCConstants.PATTERN_SEARCH_GUIDANDDISABLED, row); while (matcherGuidAndDisabled.find()) { if (matcherGuidAndDisabled.groupCount() > 0) { //cache.setGuid(matcherGuidAndDisabled.group(1)); if (matcherGuidAndDisabled.group(2) != null) { cache.setName(Html.fromHtml(matcherGuidAndDisabled.group(2).trim()).toString()); } if (matcherGuidAndDisabled.group(3) != null) { cache.setLocation(Html.fromHtml(matcherGuidAndDisabled.group(3).trim()).toString()); } final String attr = matcherGuidAndDisabled.group(1); if (attr != null) { cache.setDisabled(attr.contains("Strike")); cache.setArchived(attr.contains("OldWarning")); } } } } catch (final RuntimeException e) { // failed to parse GUID and/or Disabled Log.w("GCParser.parseSearch: Failed to parse GUID and/or Disabled data"); } if (Settings.isExcludeDisabledCaches() && (cache.isDisabled() || cache.isArchived())) { // skip disabled and archived caches excludedCaches++; continue; } cache.setGeocode( TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true)); // cache type cache.setType(CacheType .getByPattern(TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_TYPE, true, 1, null, true))); // cache direction - image if (Settings.getLoadDirImg()) { final String direction = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 1, null, false); if (direction != null) { cache.setDirectionImg(direction); } } // cache distance - estimated distance for basic members final String distance = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 2, null, false); if (distance != null) { cache.setDistance(DistanceParser.parseDistance(distance, !Settings.isUseImperialUnits())); } // difficulty/terrain final MatcherWrapper matcherDT = new MatcherWrapper(GCConstants.PATTERN_SEARCH_DIFFICULTY_TERRAIN, row); if (matcherDT.find()) { final Float difficulty = parseStars(matcherDT.group(1)); if (difficulty != null) { cache.setDifficulty(difficulty); } final Float terrain = parseStars(matcherDT.group(3)); if (terrain != null) { cache.setTerrain(terrain); } } // size final String container = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_CONTAINER, false, 1, null, false); cache.setSize(CacheSize.getById(container)); // date hidden, makes sorting event caches easier final String dateHidden = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_HIDDEN_DATE, false, 1, null, false); if (StringUtils.isNotBlank(dateHidden)) { try { Date date = GCLogin.parseGcCustomDate(dateHidden); if (date != null) { cache.setHidden(date); } } catch (ParseException e) { Log.e("Error parsing event date from search"); } } // cache inventory final MatcherWrapper matcherTbs = new MatcherWrapper(GCConstants.PATTERN_SEARCH_TRACKABLES, row); String inventoryPre = null; while (matcherTbs.find()) { if (matcherTbs.groupCount() > 0) { try { cache.setInventoryItems(Integer.parseInt(matcherTbs.group(1))); } catch (final NumberFormatException e) { Log.e("Error parsing trackables count", e); } inventoryPre = matcherTbs.group(2); } } if (StringUtils.isNotBlank(inventoryPre)) { final MatcherWrapper matcherTbsInside = new MatcherWrapper( GCConstants.PATTERN_SEARCH_TRACKABLESINSIDE, inventoryPre); while (matcherTbsInside.find()) { if (matcherTbsInside.groupCount() == 2 && matcherTbsInside.group(2) != null && !matcherTbsInside.group(2).equalsIgnoreCase("premium member only cache") && cache.getInventoryItems() <= 0) { cache.setInventoryItems(1); } } } // premium cache cache.setPremiumMembersOnly(row.contains("/images/icons/16/premium_only.png")); // found it cache.setFound(row.contains("/images/icons/16/found.png") || row.contains("uxUserLogDate\" class=\"Success\"")); // id String result = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_ID, null); if (null != result) { cache.setCacheId(result); cids.add(cache.getCacheId()); } // favorite count try { result = getNumberString( TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_FAVORITE, false, 1, null, true)); if (null != result) { cache.setFavoritePoints(Integer.parseInt(result)); } } catch (final NumberFormatException e) { Log.w("GCParser.parseSearch: Failed to parse favorite count"); } caches.add(cache); } searchResult.addAndPutInCache(caches); // total caches found try { final String result = TextUtils.getMatch(page, GCConstants.PATTERN_SEARCH_TOTALCOUNT, false, 1, null, true); if (null != result) { searchResult.setTotalCountGC(Integer.parseInt(result) - excludedCaches); } } catch (final NumberFormatException e) { Log.w("GCParser.parseSearch: Failed to parse cache count"); } String recaptchaText = null; if (recaptchaReceiver != null && StringUtils.isNotBlank(recaptchaReceiver.getChallenge())) { recaptchaReceiver.waitForUser(); recaptchaText = recaptchaReceiver.getText(); } if (!cids.isEmpty() && (Settings.isGCPremiumMember() || showCaptcha) && ((recaptchaReceiver == null || StringUtils.isBlank(recaptchaReceiver.getChallenge())) || StringUtils.isNotBlank(recaptchaText))) { Log.i("Trying to get .loc for " + cids.size() + " caches"); try { // get coordinates for parsed caches final Parameters params = new Parameters("__EVENTTARGET", "", "__EVENTARGUMENT", ""); GCLogin.putViewstates(params, searchResult.viewstates); for (final String cid : cids) { params.put("CID", cid); } if (StringUtils.isNotBlank(recaptchaText) && recaptchaReceiver != null) { params.put("recaptcha_challenge_field", recaptchaReceiver.getChallenge()); params.put("recaptcha_response_field", recaptchaText); } params.put("ctl00$ContentBody$uxDownloadLoc", "Download Waypoints"); final String coordinates = Network.getResponseData( Network.postRequest("http://www.geocaching.com/seek/nearest.aspx", params), false); if (StringUtils.contains(coordinates, "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { Log.i("User has not agreed to the license agreement. Can\'t download .loc file."); searchResult.setError(StatusCode.UNAPPROVED_LICENSE); return searchResult; } LocParser.parseLoc(searchResult, coordinates); } catch (final RuntimeException e) { Log.e("GCParser.parseSearch.CIDs", e); } } // get direction images if (Settings.getLoadDirImg()) { final Set<Geocache> cachesReloaded = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); for (final Geocache cache : cachesReloaded) { if (cache.getCoords() == null && StringUtils.isNotEmpty(cache.getDirectionImg())) { DirectionImage.getDrawable(cache.getDirectionImg()); } } } return searchResult; }
From source file:com.liato.bankdroid.banking.banks.Payson.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }//from ww w. j av a 2 s . c o m urlopen = login(); try { Matcher matcher; matcher = reBalance.matcher(response); if (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Balance 0,00 kr * */ accounts.add(new Account("Konto", Helpers.parseBalance(matcher.group(1)), "1")); balance = balance.add(Helpers.parseBalance(matcher.group(1))); } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); while (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Date 2010-06-03 * 2: Specification Beställning från SPELKONTROLL.SE * 3: Amount -228,00 kr * */ transactions.add(new Transaction(matcher.group(1).trim(), Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3)))); } accounts.get(0).setTransactions(transactions); } finally { super.updateComplete(); } }