List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Sync the remote data immediately passing along sync data to * the routines to determine how much data to sync * * @param context Activity context//from w w w.ja va 2 s . c o m * @param syncAll if true process all news items within the date range, * if false process normally by checking the timestamps * @param syncMax Max number of news items to process */ public static void syncImmediately(Context context, boolean syncAll, int syncMax) { Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(SYNC_EXTRAS_SYNC_ALL, syncAll); bundle.putInt(SYNC_EXTRAS_SYNC_MAX, syncMax); ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }
From source file:com.lillicoder.newsblurry.net.BaseTask.java
/** * Gets the user agent string for use with tasks that make web requests. * By default this returns the application name and version code. * @return User agent string for use with web requests. *///from w w w. jav a 2s .com protected String getUserAgent() { Context context = this.getContext(); Assert.assertTrue(context != null); String versionName = context.getString(R.string.default_versionName); try { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); versionName = info.versionName; } catch (NameNotFoundException e) { Log.w(TAG, String.format(WARNING_FAILED_TO_GET_PACKAGE_INFO, context.getPackageName())); } String userAgentFormat = context.getString(R.string.format_userAgent); String appName = context.getString(R.string.app_name); return String.format(userAgentFormat, appName, versionName); }
From source file:de.ub0r.android.websms.connector.fishtext.ConnectorFishtext.java
/** * {@inheritDoc}//from w w w .j a va 2s . c o m */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_fishtext_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(// . context.getString(R.string.connector_fishtext_author)); c.setAdUnitId(AD_UNITID); c.setBalance(null); c.setCapabilities(ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); c.addSubConnector("fishtext", c.getName(), SubConnectorSpec.FEATURE_NONE); return c; }
From source file:com.pursuer.reader.easyrss.network.SubscriptionDataSyncer.java
private void syncSubscriptions() throws DataSyncerException { final Context context = dataMgr.getContext(); if (!NetworkUtils.checkSyncingNetworkStatus(context, networkConfig)) { return;// ww w . j a va2 s.c om } notifyProgressChanged(context.getString(R.string.TxtSyncingSubscriptions), -1, -1); final InputStream stream = httpGetQueryStream(new SubscriptionListURL(isHttpsConnection)); final SubscriptionJSONParser parser = new SubscriptionJSONParser(stream); final long curTime = System.currentTimeMillis(); try { final SyncerSubscriptionListener listener = new SyncerSubscriptionListener(); parser.parse(listener); dataMgr.addSubscriptions(listener.getSubscriptions()); final int sAll = listener.getSubscriptions().size(); final int sAllRange = sAll / 10 * 10; GoogleAnalyticsMgr.getInstance().trackEvent(GoogleAnalyticsMgr.CATEGORY_SYNCING, GoogleAnalyticsMgr.ACTION_SYNCING_SUBSCRIPTIONS, sAllRange + "-" + (sAllRange + 9), sAll); } catch (final JsonParseException exception) { throw new DataSyncerException(exception); } catch (final IllegalStateException exception) { throw new DataSyncerException(exception); } catch (final IOException exception) { throw new DataSyncerException(exception); } finally { try { stream.close(); } catch (final IOException exception) { exception.printStackTrace(); } } dataMgr.removeOutdatedSubscriptions(curTime); }
From source file:com.nextgis.maplibui.mapui.LayerFactoryUI.java
@Override public String getLayerTypeString(Context context, int type) { switch (type) { case LAYERTYPE_GROUP: return context.getString(R.string.layer_group); case LAYERTYPE_NGW_RASTER: return context.getString(R.string.layer_ngw_raster); case LAYERTYPE_NGW_VECTOR: return context.getString(R.string.layer_ngw_vector); case LAYERTYPE_REMOTE_TMS: return context.getString(R.string.layer_tms); case LAYERTYPE_LOCAL_VECTOR: return context.getString(R.string.layer_vector); case LAYERTYPE_LOCAL_TMS: return context.getString(R.string.layer_tms); case LAYERTYPE_LOOKUPTABLE: return context.getString(R.string.layer_lookuptable); case LAYERTYPE_NGW_WEBMAP: return context.getString(R.string.web_map); default:/*from w w w . j av a 2 s . c o m*/ return context.getString(R.string.layer_na); } }
From source file:eu.gsmservice.android.websms.connector.gsmservice.ConnectorGsmService.java
/** * {@inheritDoc}/*from w ww . j a v a 2s . c o m*/ */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_gsmservice_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(context.getString(R.string.connector_gsmservice_author)); c.setBalance(BALANCE); c.setLimitLength(160); c.setAdUnitId(AD_UNITID); c.setCapabilities(ConnectorSpec.CAPABILITIES_BOOTSTRAP | ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); c.addSubConnector("GSMservice", c.getName(), SubConnectorSpec.FEATURE_MULTIRECIPIENTS); return c; }
From source file:com.owncloud.android.lib.test_project.test.GetShareesTest.java
private void initAccessToServer(Context context) { Log.v(LOG_TAG, "Setting up client instance to access OC server..."); mServerUri = context.getString(R.string.server_base_url); mServerUri2 = context.getString(R.string.server_base_url_2); mUser = context.getString(R.string.username); mPass = context.getString(R.string.password); mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager()); mClient.setDefaultTimeouts(OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); mClient.setFollowRedirects(true);//from ww w . j av a2 s.c om mClient.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUser, mPass)); Log.v(LOG_TAG, "Client instance set up."); }
From source file:net.nologin.meep.pingly.service.runner.HTTPResponseProbeRunner.java
public void doRun(Context ctx) throws ProbeRunCancelledException { HTTPResponseProbe httpProbe = (HTTPResponseProbe) getProbe(); // if everything is configured properly if (StringUtils.isBlank(httpProbe.url)) { notifyFinishedWithFailure(ctx.getString(R.string.probe_run_HTTP_RESP_err_no_url)); return;/* w w w .ja v a 2 s .c o m*/ } checkCancelled(); try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); // 'Starting request to: url' notifyUpdate(ctx.getString(R.string.probe_run_HTTP_RESP_reqstart, httpProbe.url)); request.setURI(new URI(httpProbe.url)); HttpResponse response = client.execute(request); // execute can take some time, check that the asynctask hasn't been checkCancelled in the meantime checkCancelled(); StatusLine sl = response.getStatusLine(); String statusCode = sl != null ? Integer.toString(sl.getStatusCode()) : ""; // 'Response Received (Status: 200)' notifyFinishedWithSuccess(ctx.getString(R.string.probe_run_HTTP_RESP_successmsg, statusCode)); } catch (URISyntaxException e) { // "Error parsing URL '${url}': ${exceptionmsg}" String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_invalid_url, httpProbe.url, e.getMessage()); notifyFinishedWithFailure(msg); } catch (UnknownHostException e) { // "Unknown Host: '${exceptionmsg}'" String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_unknownhost, httpProbe.url); notifyFinishedWithFailure(msg); } catch (HttpHostConnectException e) { // "Couldn't Connect: ${exceptionmsg}" (exception message is descriptive) String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_hostconnect, e.getMessage()); notifyFinishedWithFailure(msg); } catch (IOException e) { Log.w(PinglyConstants.LOG_TAG, e); String msg = ctx.getString(R.string.probe_run_general_err_io, e.getMessage()); notifyFinishedWithFailure(msg); } }
From source file:com.gruporaido.tasker_library.http.APIResponseHandler.java
public APIResponseHandler(Context context, FragmentManager fragmentManager, boolean showProgress) { super();//from w ww .ja v a 2 s. com mContext = context; mFragmentManager = fragmentManager; mShowProgress = showProgress; if (mShowProgress) { mProgressDialog = ProgressDialog.show(context, null, context.getString(R.string.loading_content)); } onRequestStart(); }
From source file:mobisocial.musubi.service.AddressBookUpdateHandler.java
public static void importFullAddressBook(Context context) { Log.d(TAG, "doing full import"); SQLiteOpenHelper db = App.getDatabaseSource(context); DatabaseManager dbm = new DatabaseManager(context); IdentitiesManager idm = dbm.getIdentitiesManager(); FeedManager fm = dbm.getFeedManager(); MyAccountManager am = dbm.getMyAccountManager(); long startTime = System.currentTimeMillis(); String musubiAccountType = context.getString(R.string.account_type); long maxDataId = -1; long maxContactId = -1; assert (SYNC_EMAIL); String account_type_selection = getAccountSelectionString(); Cursor c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.CONTACT_ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Data._ID, ContactsContract.Data.DATA_VERSION, ContactsContract.Data.DATA1, ContactsContract.Data.MIMETYPE, ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE }, "(" + ContactsContract.RawContacts.ACCOUNT_TYPE + "<>'" + musubiAccountType + "'" + ") AND (" + NAME_OR_OTHER_SELECTION + account_type_selection + ")", // All known contacts. null, null);//from w w w. ja v a 2 s. c o m if (c == null) { Log.e(TAG, "no valid cursor", new Throwable()); return; } sAddressBookTotal = c.getCount(); sAddressBookPosition = 0; Log.d(TAG, "Scanning contacts..."); final Map<String, MMyAccount> myAccounts = new HashMap<String, MMyAccount>(); final Pattern emailPattern = getEmailPattern(); final Pattern numberPattern = getNumberPattern(); while (c.moveToNext()) { sAddressBookPosition++; String identityType = c.getString(5); String identityPrincipal = c.getString(4); long contactId = c.getLong(0); long dataId = c.getLong(2); String displayName = c.getString(1); byte[] thumbnail = null; String accountName = c.getString(6); String accountType = c.getString(7); if (accountName == null) { accountName = "null-account-name"; } if (accountType == null) { accountType = "null-account-type"; } String accountKey = accountName + "-" + accountType; MMyAccount myAccount = myAccounts.get(accountKey); if (myAccount == null) { myAccount = lookupOrCreateAccount(dbm, accountName, accountType); prepareAccountWhitelistFeed(am, fm, myAccount); myAccounts.put(accountKey, myAccount); } if (displayName == null || emailPattern.matcher(displayName).matches() || numberPattern.matcher(displayName).matches()) { continue; } IBIdentity ibid = ibIdentityForData(identityType, identityPrincipal); if (ibid == null) { //TODO: better selection //Log.d(TAG, "skipping " + displayName + " // " + identityPrincipal); continue; } Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri); if (is != null) { //Log.d(TAG, "importing photo for " + displayName); try { thumbnail = IOUtils.toByteArray(is); } catch (IOException e) { thumbnail = null; //Log.e(TAG, "photo thumbnail failed to serialize", e); } finally { try { is.close(); } catch (IOException e) { } } } else { thumbnail = null; } MIdentity ident = addIdentity(context, idm, contactId, displayName, thumbnail, ibid); if (ident != null) { fm.ensureFeedMember(myAccount.feedId_, ident.id_); fm.acceptFeedsFromMember(context, ident.id_); } maxDataId = Math.max(maxDataId, dataId); maxContactId = Math.max(maxContactId, contactId); } c.close(); long timeTaken = System.currentTimeMillis() - startTime; ContactDataVersionManager cdvm = new ContactDataVersionManager(db); cdvm.setMaxDataIdSeen(maxDataId); cdvm.setMaxContactIdSeen(maxContactId); Log.d(TAG, "full import took " + timeTaken / 1000 + " secs"); context.getContentResolver().notifyChange(MusubiService.ADDRESS_BOOK_SCANNED, null); }