List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java
public static String getCommands(Context ctx, String lastSeq, String channelId) throws TransportException, InvalidDataException, NotFoundException, KurentoCommandException { if (channelId == null) { log.warn("Cannot get commands with channelId: {}", channelId); ChannelService.createChannel(ctx); return null; }// w w w . j a v a 2 s. c om String internalLastSeq = lastSeq; if (internalLastSeq == null || internalLastSeq.isEmpty()) { internalLastSeq = "0"; } log.debug("getComnands for lastSeq: {}, channelId: {}", internalLastSeq, channelId); String resource = Uri.parse(ctx.getString(R.string.url_command)).buildUpon() .appendQueryParameter(JsonKeys.LAST_SEQUENCE, internalLastSeq) .appendQueryParameter(JsonKeys.CHANNEL_ID, channelId).build().toString(); HttpResp<String> resp = HttpManager.sendGetString(ctx, resource); return resp.getBody(); }
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
private static Intent getWifiSetupIntent(Context context) { Intent intent = new Intent(CMAccount.ACTION_SETUP_WIFI); intent.putExtra(CMAccount.EXTRA_FIRST_RUN, true); intent.putExtra(CMAccount.EXTRA_ALLOW_SKIP, true); intent.putExtra(CMAccount.EXTRA_SHOW_BUTTON_BAR, true); intent.putExtra(CMAccount.EXTRA_ONLY_ACCESS_POINTS, true); intent.putExtra(CMAccount.EXTRA_SHOW_SKIP, true); intent.putExtra(CMAccount.EXTRA_AUTO_FINISH, true); intent.putExtra(CMAccount.EXTRA_PREF_BACK_TEXT, context.getString(R.string.skip)); return intent; }
From source file:com.cbsb.ftpserv.ProxyConnector.java
static public String stateToString(State s) { Context ctx = Globals.getContext(); switch (s) {//w w w .j a v a 2 s . c o m case DISCONNECTED: return ctx.getString(R.string.pst_disconnected); case CONNECTING: return ctx.getString(R.string.pst_connecting); case CONNECTED: return ctx.getString(R.string.pst_connected); case FAILED: return ctx.getString(R.string.pst_failed); case UNREACHABLE: return ctx.getString(R.string.pst_unreachable); default: return ctx.getString(R.string.unknown); } }
From source file:com.geertvanderploeg.kiekeboek.client.NetworkUtilities.java
/** * Connects to the server, authenticates the provided username and * password./*from w w w.j a va 2 s.c o m*/ * * @param username The user's username * @param password The user's password * @param handler The hander instance from the calling UI thread. * @param context The context of the calling Activity. * @return boolean The boolean result indicating whether the user was * successfully authenticated. */ public static boolean authenticate(String username, String password, Handler handler, final Context context) { final HttpResponse resp; final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("_method", "POST")); params.add(new BasicNameValuePair(PARAM_USERNAME, username)); params.add(new BasicNameValuePair(PARAM_PASSWORD, password)); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params); } catch (final UnsupportedEncodingException e) { // this should never happen. throw new AssertionError(e); } final HttpPost post = new HttpPost(context.getString(AUTH_URI_RESOURCE)); post.addHeader(new BasicHeader("Content-Type", "application/x-www-form-urlencoded")); post.setEntity(entity); HttpClient localHttpClient = getHttpClient(); Log.d(TAG, "POST-ing params to URL '" + context.getString(AUTH_URI_RESOURCE) + "': " + params); try { resp = localHttpClient.execute(post); Log.d(TAG, "Authentication response status line: " + resp.getStatusLine()); Log.d(TAG, "Authentication response headers: " + Arrays.asList(resp.getAllHeaders())); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY && resp.getHeaders("Location") != null && resp.getHeaders("Location")[0].getValue().contains("/intranet/people")) { Log.v(TAG, "Successful authentication"); sendResult(true, handler, context); resp.getEntity().consumeContent(); return true; } else { Log.v(TAG, "Error authenticating " + resp.getStatusLine()); sendResult(false, handler, context); resp.getEntity().consumeContent(); return false; } } catch (final IOException e) { Log.v(TAG, "IOException when getting authtoken", e); sendResult(false, handler, context); return false; } finally { Log.v(TAG, "getAuthtoken completing"); } }
From source file:com.bt.heliniumstudentapp.UpdateClass.java
protected static void downloadAPK() { File oldUpdate = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk"); if (oldUpdate.exists()) //noinspection ResultOfMethodCallIgnored oldUpdate.delete();//from w w w .ja v a2s. co m if (MainActivity.isOnline()) { DownloadManager.Request request; request = new DownloadManager.Request(Uri.parse(HeliniumStudentApp.URL_UPDATE_RELEASE)); request.setTitle(context.getString(R.string.app_name) + " " + versionName); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/heliniumstudentapp.apk"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); context.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType( Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk")), "application/vnd.android.package-archive"); context.startActivity(install); } }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } else { Toast.makeText(context, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } }
From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoreManager.java
private static ArrayList<Highscore> jsonToHighscoreList(Context context, String highscoreJson) throws JSONException { ArrayList<Highscore> highscores = new ArrayList<Highscore>(); JSONArray array;//from w w w. j a v a 2 s .c o m array = new JSONArray(highscoreJson); for (int i = 0; i < array.length(); i++) { JSONObject object; object = array.getJSONObject(i); int score = object.getInt(HIGHSCORE_SCORE_TAG); int exercise = object.getInt(HIGHSCORE_EXERCISE_TAG); String dateString = object.getString(HIGHSCORE_DATE_TAG); String userName = object.getString(HIGHSCORE_USERNAME_TAG); if (userName == null) { userName = context.getString(R.string.default_user_name); } highscores.add(new Highscore(score, exercise, dateString, userName)); } return highscores; }
From source file:info.papdt.blacklight.support.Utility.java
public static String addUnitToInt(Context context, int i) { String tenThousand = context.getString(R.string.ten_thousand); String million = context.getString(R.string.million); String hundredMillion = context.getString(R.string.hundred_million); String billion = context.getString(R.string.billion); if (tenThousand.equals("null")) { // English-styled number format if (i < 1000000) { return String.valueOf(i); } else if (i < 1000000000) { // million return String.valueOf(i / 1000000) + million; } else { // billion return String.valueOf(i / 1000000000) + billion; }//from w w w.ja va2s . c o m } else { // Chinese-styled number format if (i < 10000) { return String.valueOf(i); } else if (i < 100000000) { return String.valueOf(i / 10000) + tenThousand; } else { return String.valueOf(i / 100000000) + hundredMillion; } } }
From source file:de.escoand.readdaily.DownloadHandler.java
public static long startDownload(@NonNull final Context context, @NonNull final String signature, @NonNull final String responseData, @NonNull final String title, @Nullable final String mimeType) { final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); String name;/*from w w w . j av a 2 s . c o m*/ try { name = new JSONObject(responseData).getString("productId"); } catch (JSONException e) { LogHandler.log(e); return -1; } LogHandler.log(Log.WARN, "load " + name); long id = manager .enqueue(new DownloadManager.Request(Uri.parse(context.getString(R.string.product_data_url))) .addRequestHeader("App-Signature", signature) .addRequestHeader("App-ResponseData", responseData).setTitle(title) .setDescription(context.getString(R.string.app_title))); Database.getInstance(context).addDownload(name, id, mimeType); return id; }
From source file:com.dmbstream.android.util.Util.java
public static void toast(Context context, int messageId, boolean shortDuration) { toast(context, context.getString(messageId), shortDuration); }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
/** * Helper method to have the sync adapter sync immediately * * @param context The context used to access the account service *//*from w ww .j av a2s .co m*/ public static void syncImmediately(Context context) { //Log.d("Weather4USyncAdapter", "syncImmediately"); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }