List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.doplgangr.secrecy.Util.java
public static void alert(final Context context, final String title, final String message, final DialogInterface.OnClickListener positive, final DialogInterface.OnClickListener negative) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//from ww w . j a v a2 s . c o m public void run() { AlertDialog.Builder a = new AlertDialog.Builder(context); if (title != null) a.setTitle(title); if (message != null) a.setMessage(message); if (positive != null) a.setPositiveButton(context.getString(R.string.OK), positive); if (negative != null) a.setNegativeButton(context.getString(R.string.CANCEL), negative); a.setCancelable(false); a.show(); } }); }
From source file:com.twitt4droid.Twitt4droid.java
/** * Gets the current twitter4j configuration with consumer and access tokens pre-initialized. You * can use this method to build a Twitter objects. * //from w w w . j a v a 2 s .c om * @param context the application context. * @return an Configuration object. */ private static Configuration getCurrentConfig(Context context) { SharedPreferences preferences = Resources.getPreferences(context); return new ConfigurationBuilder() .setOAuthConsumerKey(Resources.getMetaData(context, context.getString(R.string.twitt4droid_consumer_key_metadata), null)) .setOAuthConsumerSecret(Resources.getMetaData(context, context.getString(R.string.twitt4droid_consumer_secret_metadata), null)) .setOAuthAccessToken( preferences.getString(context.getString(R.string.twitt4droid_oauth_token_key), null)) .setOAuthAccessTokenSecret( preferences.getString(context.getString(R.string.twitt4droid_oauth_secret_key), null)) .build(); }
From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java
/** * Gets the fictitious account to be used with the sync adapter, or makes a new one * if the fictitious account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. *///from w w w. jav a 2 s . c o m public static Account getSyncAccount(Context context) { // Get an instance of the android account manager. AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account. Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist. Add the account. if (null == accountManager.getPassword(newAccount)) { // Add the account and account type, no password or user data. if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.ada.utils.Log.java
public static void initialize(Context context, String tag, String url, boolean enabled) { if (tag != null) { mTag = tag;//from w ww. j av a 2s. c om } mEnabled = enabled; mRemoteUrl = url; if (context != null) { try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); mPackageName = pi.packageName; mPackageVersion = pi.versionName; if (tag == null && pi.applicationInfo.labelRes > 0) { mTag = context.getString(pi.applicationInfo.labelRes); } } catch (NameNotFoundException e) { } } }
From source file:com.akop.bach.parser.Parser.java
public static String getErrorMessage(Context context, Exception e) { if (e instanceof SocketTimeoutException) return context.getString(R.string.error_timed_out); else if (e instanceof UnknownHostException) return context.getString(R.string.error_dns_error); else if (e instanceof ClientProtocolException) return context.getString(R.string.error_redirecting); else if (e instanceof IOException) return context.getString(R.string.error_network_error); else if (e instanceof AuthenticationException) { if (e.getMessage() == null) return context.getString(R.string.error_invalid_credentials); else//w ww . j av a 2 s.c om return e.getMessage(); } else if (e instanceof ParserException) return e.getMessage(); // All other cases failed if (e.getMessage() != null) { return context.getString(R.string.error_unexpected_f, e.getMessage()); } else { return context.getString(R.string.error_unexpected_f, e.getClass().getName()); } }
From source file:net.giovannicapuano.galax.util.Utils.java
/** * Perform a HTTP GET request.// w w w. j a v a 2 s . c om */ public static HttpData get(String path, Context context) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 10000); int status = HttpStatus.SC_INTERNAL_SERVER_ERROR; String body = ""; HttpClient httpClient = new DefaultHttpClient(httpParameters); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context)); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); try { HttpGet httpGet = new HttpGet(context.getString(R.string.server) + path); HttpResponse response = httpClient.execute(httpGet, localContext); status = response.getStatusLine().getStatusCode(); body = EntityUtils.toString(response.getEntity()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return new HttpData(status, body); }
From source file:net.giovannicapuano.galax.util.Utils.java
/** * Perform a HTTP POST request./*from w w w . j a v a2 s . co m*/ */ public static HttpData postData(String path, List<NameValuePair> post, Context context) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 10000); int status = HttpStatus.SC_INTERNAL_SERVER_ERROR; String body = ""; HttpClient httpClient = new DefaultHttpClient(httpParameters); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context)); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); try { HttpPost httpPost = new HttpPost(context.getString(R.string.server) + path); httpPost.setEntity(new UrlEncodedFormEntity(post)); HttpResponse response = httpClient.execute(httpPost, localContext); status = response.getStatusLine().getStatusCode(); body = EntityUtils.toString(response.getEntity()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return new HttpData(status, body); }
From source file:com.pdftron.pdf.utils.Utils.java
public static String encryptIt(Context context, String value) { String cryptoPass = context.getString(context.getApplicationInfo().labelRes); try {// w w w . j ava 2 s .c o m DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(keySpec); byte[] clearText = value.getBytes("UTF8"); // Cipher is not thread safe Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, key); String encrypedValue = Base64.encodeToString(cipher.doFinal(clearText), Base64.DEFAULT); Log.d("MiscUtils", "Encrypted: " + value + " -> " + encrypedValue); return encrypedValue; } catch (Exception e) { Log.d(e.getClass().getName(), e.getMessage()); } return value; }
From source file:com.pdftron.pdf.utils.Utils.java
public static String decryptIt(Context context, String value) { String cryptoPass = context.getString(context.getApplicationInfo().labelRes); try {/*from w w w.j a v a 2 s .co m*/ DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(keySpec); byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT); // cipher is not thread safe Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes)); String decrypedValue = new String(decrypedValueBytes); Log.d("MiscUtils", "Decrypted: " + value + " -> " + decrypedValue); return decrypedValue; } catch (Exception e) { Log.e(e.getClass().getName(), e.getMessage()); } return value; }
From source file:no.digipost.android.api.ApiAccess.java
public static String delete(Context context, final String uri) throws DigipostClientException, DigipostApiException, DigipostAuthenticationException { Client client = Client.create();//from ww w. j av a 2 s. c o m ClientResponse cr; try { cr = client.resource(uri).header(ApiConstants.ACCEPT, ApiConstants.APPLICATION_VND_DIGIPOST_V2_JSON) .header(ApiConstants.AUTHORIZATION, ApiConstants.BEARER + TokenStore.getAccess()) .delete(ClientResponse.class); } catch (Exception e) { throw new DigipostClientException(context.getString(R.string.error_your_network)); } if (cr.getStatus() == NetworkUtilities.HTTP_STATUS_BAD_REQUEST) { try { String output = cr.getEntity(String.class); JSONObject jsonObject = new JSONObject(output); if (jsonObject.get(ApiConstants.ERROR_CODE).equals(ApiConstants.FOLDER_NOT_EMPTY)) { return null; } } catch (JSONException e) { Log.e(TAG, e.getMessage()); } } try { NetworkUtilities.checkHttpStatusCode(context, cr.getStatus()); } catch (DigipostInvalidTokenException e) { Log.e(TAG, context.getString(R.string.error_invalid_token)); OAuth.updateAccessTokenWithRefreshToken(context); delete(context, uri); } return "" + cr.getStatus(); }