List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java
private static List<Feature> geoJSONFeaturesToFeatures(JSONArray geoJSONFeatures, boolean isWGS84, Context context, ProgressDialog progressDialog) throws JSONException { List<Feature> features = new ArrayList<Feature>(); List<Field> fields = new ArrayList<Field>(); int geometryType = GTNone; progressDialog.setMessage(context.getString(R.string.message_loading_progress)); progressDialog.setMax(geoJSONFeatures.length()); for (int i = 0; i < geoJSONFeatures.length(); i++) { progressDialog.setProgress(i);//from w ww .j av a2s . com JSONObject jsonFeature = geoJSONFeatures.getJSONObject(i); //get geometry JSONObject jsonGeometry = jsonFeature.getJSONObject(GEOJSON_GEOMETRY); GeoGeometry geometry = GeoGeometry.fromJson(jsonGeometry); if (geometryType == GTNone) { geometryType = geometry.getType(); } else if (!Geo.isGeometryTypeSame(geometryType, geometry.getType())) { //skip different geometry type continue; } //reproject if needed if (isWGS84) { geometry.setCRS(CRS_WGS84); geometry.project(CRS_WEB_MERCATOR); } else { geometry.setCRS(CRS_WEB_MERCATOR); } Feature feature = new Feature(fields); feature.setGeometry(geometry); //TODO: add to RTree for fast spatial queries //normalize attributes JSONObject jsonAttributes = jsonFeature.getJSONObject(GEOJSON_PROPERTIES); Iterator<String> iter = jsonAttributes.keys(); while (iter.hasNext()) { String key = iter.next(); Object value = jsonAttributes.get(key); int nType = -1; //check type if (value instanceof Integer || value instanceof Long) { nType = FTInteger; } else if (value instanceof Double || value instanceof Float) { nType = FTReal; } else if (value instanceof Date) { nType = FTDateTime; } else if (value instanceof String) { nType = FTString; } else if (value instanceof JSONObject) { nType = -1; //the some list - need to check it type FTIntegerList, FTRealList, FTStringList } int nField = -1; for (int j = 0; j < fields.size(); j++) { if (fields.get(j).getFieldName().equals(key)) { nField = j; } } if (nField == -1) { //add new field Field field = new Field(key, key, nType); nField = fields.size(); fields.add(field); } feature.setField(nField, value); } features.add(feature); } return features; }
From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java
/** * Schedules periodic execution of the sync adapter. *//*from w ww . j av a2s. c o m*/ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { // Get account and authority. Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); // Set inexact timer for the periodic sync for KitKat and above. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority).setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
From source file:it.feio.android.omninotes.utils.StorageHelper.java
public static boolean delete(Context mContext, String name) { boolean res = false; // Checks for external storage availability if (!checkStorage()) { Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show(); return false; }/* w w w. ja v a 2 s. c o m*/ File file = new File(name); if (file.isFile()) { res = file.delete(); } else if (file.isDirectory()) { File[] files = file.listFiles(); for (File file2 : files) { res = delete(mContext, file2.getAbsolutePath()); } res = file.delete(); } return res; }
From source file:it.feio.android.omninotes.utils.StorageHelper.java
/** * Create a path where we will place our private file on external * * @param mContext//from w w w . j a v a2 s .c om * @param uri * @return */ public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) { // Checks for external storage availability if (!checkStorage()) { Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show(); return null; } File file = createNewAttachmentFile(mContext, extension); InputStream is; OutputStream os; try { is = mContext.getContentResolver().openInputStream(uri); os = new FileOutputStream(file); copyFile(is, os); } catch (IOException e) { try { is = new FileInputStream(FileHelper.getPath(mContext, uri)); os = new FileOutputStream(file); copyFile(is, os); // It's a path!! } catch (NullPointerException e1) { try { is = new FileInputStream(uri.getPath()); os = new FileOutputStream(file); copyFile(is, os); } catch (FileNotFoundException e2) { Log.e(Constants.TAG, "Error writing " + file, e2); file = null; } } catch (FileNotFoundException e2) { Log.e(Constants.TAG, "Error writing " + file, e2); file = null; } } return file; }
From source file:com.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java
private static void onAccountCreated(Account newAccount, Context context) { /*//from w w w . j a v a 2 s . co m * Since we've created an account */ Log.d(LOG_TAG, "onAccountCreated called"); MovieSyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME); /* * Without calling setSyncAutomatically, our periodic sync will not be enabled. */ ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true); /* * Finally, let's do a sync to get things started */ syncImmediately(context); }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
/** * Helper method to schedule the sync adapter periodic execution *//*from ww w .j a v a 2s . c o m*/ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority).setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
From source file:com.example.android.sunshine.app.Utility.java
public static String getPreferredLocation(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getString(context.getString(R.string.pref_location_key), context.getString(R.string.pref_location_default)); }
From source file:com.weebly.opus1269.copyeverywhere.cloud.DeviceGroups.java
private static String getGcmToken() throws IOException { final Context context = App.getContext(); // Initially this goes to the network for the token, subsequent calls are local. // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json. // See https://developers.google.com/cloud-messaging/android/start for details on this file. final InstanceID instanceID = InstanceID.getInstance(context); final String token = instanceID.getToken(context.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); AppUtils.log(TAG, "Gcm Token: " + token); return token; }
From source file:com.domuslink.communication.ApiHandler.java
/** * Prepare the internal User-Agent string for use. This requires a * {@link Context} to pull the package name and version number for this * application./*ww w. j a v a2 s . c om*/ */ public static void prepareUserAgent(Context context, String thePassword, String theHost) { sPassword = thePassword; sHost = theHost; try { // Read package name and version number from manifest PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); sUserAgent = String.format(context.getString(R.string.template_user_agent), info.packageName, info.versionName); } catch (NameNotFoundException e) { Log.e(TAG, "Couldn't find package information in PackageManager", e); } }
From source file:net.giovannicapuano.visualnovel.Memory.java
public static boolean putKeyValues(Context context, Hashtable<String, String> keyvalues) { try {//from ww w .ja v a2 s . c o m JSONObject json = new JSONObject(); for (Entry<String, String> entry : keyvalues.entrySet()) json.put(entry.getKey(), entry.getValue()); FileOutputStream fos = context.openFileOutput(KEYVALUES, Context.MODE_PRIVATE); fos.write(json.toString().getBytes()); fos.flush(); fos.close(); return true; } catch (Exception e) { Utils.error(e); Utils.error(context, context.getString(R.string.error_saving_game)); return false; } }