List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:net.openwatch.acluaz.fragment.FormFragment.java
/** * maps json fields to orm object fields * @param json//from ww w.j a v a2 s . c om */ private static int jsonToDatabase(Context c, JSONObject json, int existing_db_id) { String TAG = "FormFragment-jsonToDatabase"; Incident incident = null; if (existing_db_id == -1) { incident = new Incident(); incident.uuid.set(Constants.generateUUID()); } else incident = Incident.objects(c).get(existing_db_id); try { JSONObject user_json; if (json.has(c.getString(R.string.user_tag))) { user_json = json.getJSONObject(c.getString(R.string.user_tag)); if (user_json.has(c.getString(R.string.first_name_tag))) incident.first_name.set(user_json.getString(c.getString(R.string.first_name_tag))); if (user_json.has(c.getString(R.string.last_name_tag))) incident.last_name.set(user_json.getString(c.getString(R.string.last_name_tag))); if (user_json.has(c.getString(R.string.address1_tag))) incident.address_1.set(user_json.getString(c.getString(R.string.address1_tag))); if (user_json.has(c.getString(R.string.address2_tag))) incident.address_2.set(user_json.getString(c.getString(R.string.address2_tag))); if (user_json.has(c.getString(R.string.city_tag))) incident.city.set(user_json.getString(c.getString(R.string.city_tag))); if (user_json.has(c.getString(R.string.state_tag))) incident.state.set(user_json.getString(c.getString(R.string.state_tag))); if (user_json.has(c.getString(R.string.zipcode_tag))) incident.zip.set(user_json.getInt(c.getString(R.string.zipcode_tag))); if (user_json.has(c.getString(R.string.phone_tag))) incident.phone.set(user_json.getString(c.getString(R.string.phone_tag))); if (user_json.has(c.getString(R.string.email_tag))) incident.email.set(user_json.getString(c.getString(R.string.email_tag))); } else { Log.e(TAG, "no user object present"); } JSONObject report_json; if (json.has(c.getString(R.string.report_tag))) { report_json = json.getJSONObject(c.getString(R.string.report_tag)); if (report_json.has(c.getString(R.string.agency_tag))) incident.agency.set(report_json.getString(c.getString(R.string.agency_tag))); if (report_json.has(c.getString(R.string.location_tag))) incident.location.set(report_json.getString(c.getString(R.string.location_tag))); if (report_json.has(c.getString(R.string.date_tag))) incident.date.set(report_json.getString(c.getString(R.string.date_tag))); if (report_json.has(c.getString(R.string.narrative_tag))) incident.description.set(report_json.getString(c.getString(R.string.narrative_tag))); if (report_json.has(c.getString(R.string.device_location_tag))) { incident.device_lat.set(report_json.getDouble(c.getString(R.string.device_lat))); incident.device_lon.set(report_json.getDouble(c.getString(R.string.device_lon))); } } else { Log.e(TAG, "no report object present"); } incident.save(c); return incident.getId(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return -1; }
From source file:de.ub0r.android.websms.connector.innosend.ConnectorInnosend.java
/** * Check return code from innosend.de.//from w w w . j av a 2 s . c o m * * @param context * Context * @param connector * ConnectorSpec * @param ret * return code * @param more * more text * @param failOnError * fail if return code is not 10* * @return true if no error code */ private static boolean checkReturnCode(final Context context, final ConnectorSpec connector, final int ret, final String more, final boolean failOnError) { switch (ret) { case 100: case 101: // this.pushMessage(WebSMS.MESSAGE_LOG, more + " " // + context.getString(R.string.log_remain_free)); return true; case 161: if (!failOnError) { String balance = connector.getBalance(); if (balance.length() > 0) { balance += "/"; } balance += context.getString(R.string.innosend_next_free) + " " + more; connector.setBalance(balance); return true; } throw new WebSMSException(context, R.string.error_innosend_161, " " + more); default: throw new WebSMSException(context, R.string.error, " code: " + ret + " " + more); } }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java
public static boolean sendCommandTransaction(Context ctx, List<CommandObject> cmdList) throws InvalidDataException, KurentoCommandException, NotFoundException { String prefix = ""; StringBuilder b = new StringBuilder("["); for (CommandObject cmd : cmdList) { b.append(prefix);/*from ww w. ja v a 2s . c o m*/ prefix = ", "; b.append("[").append(cmd.getJson()).append("]"); } b.append("]"); String json = b.toString(); for (CommandObject cmd : cmdList) { PerformanceMonitor.monitor(ctx, PerformanceMonitor.Type.CMD_SEND_REQUEST_START, cmd.getJson()); } HttpResp<Void> resp; try { resp = HttpManager.sendPostVoid(ctx, ctx.getString(R.string.url_command_transaction), json); } catch (TransportException e) { log.error("Cannot send command", e); return false; } for (CommandObject cmd : cmdList) { PerformanceMonitor.monitor(ctx, PerformanceMonitor.Type.CMD_SEND_REQUEST_FINISH, cmd.getJson()); } return resp.getCode() == HttpStatus.SC_CREATED; }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account./*from w ww.ja v a2 s . co m*/ */ public static Account getSyncAccount(Context context) { //Log.d("Weather4USyncAdapter", "getSyncAccount"); // 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 if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.mail163.email.LegacyConversions.java
/** * Infer mailbox type from mailbox name. Used by MessagingController (for live folder sync) * and for legacy account upgrades./*from w ww . j ava 2 s. co m*/ */ public static synchronized int inferMailboxTypeFromName(Context context, String mailboxName) { if (sServerMailboxNames.size() == 0) { // preload the hashmap, one time only sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_inbox).toLowerCase(), Mailbox.TYPE_INBOX); // type0 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_outbox).toLowerCase(), Mailbox.TYPE_OUTBOX);// type4 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_drafts).toLowerCase(), Mailbox.TYPE_DRAFTS); // type3 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_trash).toLowerCase(), Mailbox.TYPE_TRASH); // type6 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_sent).toLowerCase(), Mailbox.TYPE_SENT); // type5 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_junk).toLowerCase(), Mailbox.TYPE_JUNK); // TYPE_JUNK 7 sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_nexbox).toLowerCase(), Mailbox.TYPE_NEWBOX); // 8 } if (mailboxName == null || mailboxName.length() == 0) { return EmailContent.Mailbox.TYPE_MAIL; } String lowerCaseName = mailboxName.toLowerCase(); Integer type = sServerMailboxNames.get(lowerCaseName); if (type != null) { return type; } return EmailContent.Mailbox.TYPE_MAIL; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java
private static String registerInServer(Context ctx, String regId, String userId) throws TransportException, InvalidDataException, NotFoundException, KurentoCommandException { JSONObject jsonObject = new JSONObject(); try {//from www . j av a 2s. c o m jsonObject.put(JsonKeys.REGISTER_ID, regId); jsonObject.put(JsonKeys.REGISTER_USER_ID, userId); jsonObject.put(JsonKeys.REGISTER_TYPE, "gcm"); jsonObject.put(JsonKeys.INSTANCE_ID, Preferences.getInstanceId(ctx)); jsonObject.put(JsonKeys.LOCAL, Locale.getDefault().getLanguage()); } catch (JSONException e) { log.error("Cannot create JSON", e); return null; } HttpResp<String> resp = HttpManager.sendPostString(ctx, ctx.getString(R.string.url_get_channel), jsonObject.toString()); int code = resp.getCode(); if (code != HttpStatus.SC_OK && code != HttpStatus.SC_CREATED) { return null; } return resp.getBody(); }
From source file:at.wada811.utils.CameraUtils.java
/** * ???/*from w ww . j a va 2 s. com*/ */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean isFaceDetectionSupported(Context context, Camera camera) { boolean isFaceDetectionSupported = false; int maxNumDetectedFaces = 0; if (AndroidUtils.isMoreThanBuildVersion(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { maxNumDetectedFaces = camera.getParameters().getMaxNumDetectedFaces(); isFaceDetectionSupported = maxNumDetectedFaces > 0; } PreferenceUtils.putBoolean(context, context.getString(R.string.keySupportFaceDetection), isFaceDetectionSupported); PreferenceUtils.putInt(context, context.getString(R.string.keyMaxNumDetectedFaces), maxNumDetectedFaces); return isFaceDetectionSupported; }
From source file:info.schnatterer.nusic.android.util.TextUtil.java
/** * Tries to load an asset file as text. If <code>assetPath</code> ends in * <code>.html</code>, the HTML code is rendered into "displayable styled" * text./*from w ww. j a v a2 s .c om*/ * * @param context * context to load asset and (potential resources) from * @param assetPath * path of the asset to load * @param replaceResources * if <code>true</code>, resources such as * <code>@string/abc</code> are replaced with their localized * values from the app's resource strings (e.g. * <code>strings.xml</code>). Set to <code>false</code> for * better performance. * @return (potentially styled) text from asset */ public static CharSequence loadTextFromAsset(Context context, String assetPath, boolean replaceResources) { if (assetPath != null) { InputStream is = null; try { is = context.getResources().getAssets().open(assetPath); String assetText = IOUtils.toString(is); if (assetPath.matches(REGEX_ENDING_HTML)) { return fromHtml(replaceResourceStrings(assetText)); } else { return assetText; } } catch (IOException e) { Log.w(Constants.LOG, "Unable to load asset from path \"" + assetPath + "\"", e); return context.getString(R.string.TextAssetActivity_errorLoadingFile); } finally { IOUtils.closeQuietly(is); } } return null; }
From source file:com.grarak.romswitcher.Utils.Utils.java
public static void setupPassword(final Context context) { LayoutInflater factory = LayoutInflater.from(context); final View btn = factory.inflate(R.layout.password, null); mOldPasstext = (TextView) btn.findViewById(R.id.oldpass_text); mOldPassword = (EditText) btn.findViewById(R.id.oldpass); mNewPassword = (EditText) btn.findViewById(R.id.newpass); mConfirmPassword = (EditText) btn.findViewById(R.id.confirmpass); if (!mPassfile.exists()) { mOldPassword.setVisibility(View.GONE); mOldPasstext.setVisibility(View.GONE); }/*ww w .j ava 2 s .c om*/ Builder builder = new Builder(context); builder.setView(btn).setTitle(context.getString(R.string.setuppass)) .setNegativeButton(context.getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { checkOldPass(context); } }).show(); }
From source file:com.wms.opensource.images3android.manager.MenuManager.java
public static void displayImageProcessOptionsMenu(final Context context, final Image image, final Bitmap bitmap, final ReviewImageManager manager) { IconContextMenu cm = new IconContextMenu(context, R.menu.image_process_options_menu); cm.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() { @SuppressWarnings("deprecation") @Override// www. ja v a 2 s .com public void onIconContextItemSelected(MenuItem item, Object info) { if (item.getItemId() == R.id.action_hint) { // Position 0 is the indication for selecting a template, so we do nothing } else if (item.getItemId() == R.id.action_save_to_gallery) { MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, image.getId(), ""); Toast.makeText(context, context.getString(R.string.saveToGallaryCompleted), Toast.LENGTH_LONG) .show(); } else if (item.getItemId() == R.id.action_set_as_wall_paper) { try { context.setWallpaper(bitmap); Toast.makeText(context, context.getString(R.string.setWallPaperCompleted), Toast.LENGTH_LONG).show(); } catch (IOException e) { } } else if (item.getItemId() == R.id.action_delete) { manager.dismiss(); // Delete image DeleteImageTask task = new DeleteImageTask(context, image.getBaseUrl(), image.getImagePlantId(), image.getId()); task.execute(); } } }); cm.show(); }